loopfilter.c 18.3 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
10
11
 */


Attila Nagy's avatar
Attila Nagy committed
12
#include "vpx_config.h"
John Koleszar's avatar
John Koleszar committed
13
#include "vpx_rtcd.h"
John Koleszar's avatar
John Koleszar committed
14
15
#include "loopfilter.h"
#include "onyxc_int.h"
Attila Nagy's avatar
Attila Nagy committed
16
#include "vpx_mem/vpx_mem.h"
John Koleszar's avatar
John Koleszar committed
17
18
19

typedef unsigned char uc;

Attila Nagy's avatar
Attila Nagy committed
20
static void lf_init_lut(loop_filter_info_n *lfi)
John Koleszar's avatar
John Koleszar committed
21
{
Attila Nagy's avatar
Attila Nagy committed
22
    int filt_lvl;
John Koleszar's avatar
John Koleszar committed
23

Attila Nagy's avatar
Attila Nagy committed
24
    for (filt_lvl = 0; filt_lvl <= MAX_LOOP_FILTER; filt_lvl++)
John Koleszar's avatar
John Koleszar committed
25
    {
Attila Nagy's avatar
Attila Nagy committed
26
        if (filt_lvl >= 40)
John Koleszar's avatar
John Koleszar committed
27
        {
Attila Nagy's avatar
Attila Nagy committed
28
29
30
31
32
33
34
35
36
37
38
39
            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 2;
            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 3;
        }
        else if (filt_lvl >= 20)
        {
            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 2;
        }
        else if (filt_lvl >= 15)
        {
            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 1;
John Koleszar's avatar
John Koleszar committed
40
41
42
        }
        else
        {
Attila Nagy's avatar
Attila Nagy committed
43
44
            lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 0;
            lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 0;
John Koleszar's avatar
John Koleszar committed
45
        }
Attila Nagy's avatar
Attila Nagy committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    }

    lfi->mode_lf_lut[DC_PRED] = 1;
    lfi->mode_lf_lut[V_PRED] = 1;
    lfi->mode_lf_lut[H_PRED] = 1;
    lfi->mode_lf_lut[TM_PRED] = 1;
    lfi->mode_lf_lut[B_PRED]  = 0;

    lfi->mode_lf_lut[ZEROMV]  = 1;
    lfi->mode_lf_lut[NEARESTMV] = 2;
    lfi->mode_lf_lut[NEARMV] = 2;
    lfi->mode_lf_lut[NEWMV] = 2;
    lfi->mode_lf_lut[SPLITMV] = 3;

}

void vp8_loop_filter_update_sharpness(loop_filter_info_n *lfi,
                                      int sharpness_lvl)
{
    int i;

    /* For each possible value for the loop filter fill out limits */
    for (i = 0; i <= MAX_LOOP_FILTER; i++)
    {
        int filt_lvl = i;
        int block_inside_limit = 0;
John Koleszar's avatar
John Koleszar committed
72

73
        /* Set loop filter paramaeters that control sharpness. */
John Koleszar's avatar
John Koleszar committed
74
75
76
77
78
79
80
81
82
83
84
85
        block_inside_limit = filt_lvl >> (sharpness_lvl > 0);
        block_inside_limit = block_inside_limit >> (sharpness_lvl > 4);

        if (sharpness_lvl > 0)
        {
            if (block_inside_limit > (9 - sharpness_lvl))
                block_inside_limit = (9 - sharpness_lvl);
        }

        if (block_inside_limit < 1)
            block_inside_limit = 1;

Attila Nagy's avatar
Attila Nagy committed
86
87
88
89
90
        vpx_memset(lfi->lim[i], block_inside_limit, SIMD_WIDTH);
        vpx_memset(lfi->blim[i], (2 * filt_lvl + block_inside_limit),
                SIMD_WIDTH);
        vpx_memset(lfi->mblim[i], (2 * (filt_lvl + 2) + block_inside_limit),
                SIMD_WIDTH);
John Koleszar's avatar
John Koleszar committed
91
    }
Attila Nagy's avatar
Attila Nagy committed
92
}
John Koleszar's avatar
John Koleszar committed
93

Attila Nagy's avatar
Attila Nagy committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
void vp8_loop_filter_init(VP8_COMMON *cm)
{
    loop_filter_info_n *lfi = &cm->lf_info;
    int i;

    /* init limits for given sharpness*/
    vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
    cm->last_sharpness_level = cm->sharpness_level;

    /* init LUT for lvl  and hev thr picking */
    lf_init_lut(lfi);

    /* init hev threshold const vectors */
    for(i = 0; i < 4 ; i++)
John Koleszar's avatar
John Koleszar committed
108
    {
Attila Nagy's avatar
Attila Nagy committed
109
        vpx_memset(lfi->hev_thr[i], i, SIMD_WIDTH);
John Koleszar's avatar
John Koleszar committed
110
111
112
    }
}

Attila Nagy's avatar
Attila Nagy committed
113
114
void vp8_loop_filter_frame_init(VP8_COMMON *cm,
                                MACROBLOCKD *mbd,
Johann's avatar
Johann committed
115
                                int default_filt_lvl)
John Koleszar's avatar
John Koleszar committed
116
{
Attila Nagy's avatar
Attila Nagy committed
117
118
119
    int seg,  /* segment number */
        ref,  /* index in ref_lf_deltas */
        mode; /* index in mode_lf_deltas */
John Koleszar's avatar
John Koleszar committed
120

Attila Nagy's avatar
Attila Nagy committed
121
122
123
    loop_filter_info_n *lfi = &cm->lf_info;

    /* update limits if sharpness has changed */
Johann's avatar
Johann committed
124
    if(cm->last_sharpness_level != cm->sharpness_level)
John Koleszar's avatar
John Koleszar committed
125
    {
Johann's avatar
Johann committed
126
127
        vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
        cm->last_sharpness_level = cm->sharpness_level;
Attila Nagy's avatar
Attila Nagy committed
128
    }
John Koleszar's avatar
John Koleszar committed
129

Attila Nagy's avatar
Attila Nagy committed
130
131
132
133
134
135
136
    for(seg = 0; seg < MAX_MB_SEGMENTS; seg++)
    {
        int lvl_seg = default_filt_lvl;
        int lvl_ref, lvl_mode;

        /* Note the baseline filter values for each segment */
        if (mbd->segmentation_enabled)
John Koleszar's avatar
John Koleszar committed
137
        {
Attila Nagy's avatar
Attila Nagy committed
138
139
140
141
142
143
144
145
146
147
            /* Abs value */
            if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
            {
                lvl_seg = mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
            }
            else  /* Delta Value */
            {
                lvl_seg += mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
                lvl_seg = (lvl_seg > 0) ? ((lvl_seg > 63) ? 63: lvl_seg) : 0;
            }
John Koleszar's avatar
John Koleszar committed
148
149
        }

Attila Nagy's avatar
Attila Nagy committed
150
        if (!mbd->mode_ref_lf_delta_enabled)
John Koleszar's avatar
John Koleszar committed
151
        {
Attila Nagy's avatar
Attila Nagy committed
152
153
154
155
156
            /* we could get rid of this if we assume that deltas are set to
             * zero when not in use; encoder always uses deltas
             */
            vpx_memset(lfi->lvl[seg][0], lvl_seg, 4 * 4 );
            continue;
John Koleszar's avatar
John Koleszar committed
157
158
        }

Attila Nagy's avatar
Attila Nagy committed
159
        lvl_ref = lvl_seg;
John Koleszar's avatar
John Koleszar committed
160

Attila Nagy's avatar
Attila Nagy committed
161
162
        /* INTRA_FRAME */
        ref = INTRA_FRAME;
John Koleszar's avatar
John Koleszar committed
163

164
        /* Apply delta for reference frame */
Attila Nagy's avatar
Attila Nagy committed
165
        lvl_ref += mbd->ref_lf_deltas[ref];
John Koleszar's avatar
John Koleszar committed
166

Attila Nagy's avatar
Attila Nagy committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
        /* Apply delta for Intra modes */
        mode = 0; /* B_PRED */
        /* Only the split mode BPRED has a further special case */
        lvl_mode = lvl_ref +  mbd->mode_lf_deltas[mode];
        lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */

        lfi->lvl[seg][ref][mode] = lvl_mode;

        mode = 1; /* all the rest of Intra modes */
        lvl_mode = (lvl_ref > 0) ? (lvl_ref > 63 ? 63 : lvl_ref)  : 0; /* clamp */
        lfi->lvl[seg][ref][mode] = lvl_mode;

        /* LAST, GOLDEN, ALT */
        for(ref = 1; ref < MAX_REF_FRAMES; ref++)
John Koleszar's avatar
John Koleszar committed
181
        {
Attila Nagy's avatar
Attila Nagy committed
182
            int lvl_ref = lvl_seg;
John Koleszar's avatar
John Koleszar committed
183

Attila Nagy's avatar
Attila Nagy committed
184
185
            /* Apply delta for reference frame */
            lvl_ref += mbd->ref_lf_deltas[ref];
John Koleszar's avatar
John Koleszar committed
186

Attila Nagy's avatar
Attila Nagy committed
187
188
189
190
191
            /* Apply delta for Inter modes */
            for (mode = 1; mode < 4; mode++)
            {
                lvl_mode = lvl_ref + mbd->mode_lf_deltas[mode];
                lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0; /* clamp */
John Koleszar's avatar
John Koleszar committed
192

Attila Nagy's avatar
Attila Nagy committed
193
194
195
                lfi->lvl[seg][ref][mode] = lvl_mode;
            }
        }
John Koleszar's avatar
John Koleszar committed
196
197
198
    }
}

199
200
201
void vp8_loop_filter_frame(VP8_COMMON *cm,
                           MACROBLOCKD *mbd,
                           int frame_type)
John Koleszar's avatar
John Koleszar committed
202
203
{
    YV12_BUFFER_CONFIG *post = cm->frame_to_show;
Attila Nagy's avatar
Attila Nagy committed
204
205
206
    loop_filter_info_n *lfi_n = &cm->lf_info;
    loop_filter_info lfi;

John Koleszar's avatar
John Koleszar committed
207
208
    int mb_row;
    int mb_col;
Scott LaVarnway's avatar
Scott LaVarnway committed
209
210
    int mb_rows = cm->mb_rows;
    int mb_cols = cm->mb_cols;
John Koleszar's avatar
John Koleszar committed
211
212
213
214
215

    int filter_level;

    unsigned char *y_ptr, *u_ptr, *v_ptr;

Attila Nagy's avatar
Attila Nagy committed
216
217
    /* Point at base of Mb MODE_INFO list */
    const MODE_INFO *mode_info_context = cm->mi;
Scott LaVarnway's avatar
Scott LaVarnway committed
218
219
    int post_y_stride = post->y_stride;
    int post_uv_stride = post->uv_stride;
John Koleszar's avatar
John Koleszar committed
220

221
    /* Initialize the loop filter for this frame. */
Johann's avatar
Johann committed
222
    vp8_loop_filter_frame_init(cm, mbd, cm->filter_level);
John Koleszar's avatar
John Koleszar committed
223

224
    /* Set up the buffer pointers */
John Koleszar's avatar
John Koleszar committed
225
226
227
228
    y_ptr = post->y_buffer;
    u_ptr = post->u_buffer;
    v_ptr = post->v_buffer;

229
    /* vp8_filter each macro block */
Scott LaVarnway's avatar
Scott LaVarnway committed
230
    if (cm->filter_type == NORMAL_LOOPFILTER)
John Koleszar's avatar
John Koleszar committed
231
    {
Scott LaVarnway's avatar
Scott LaVarnway committed
232
        for (mb_row = 0; mb_row < mb_rows; mb_row++)
John Koleszar's avatar
John Koleszar committed
233
        {
Scott LaVarnway's avatar
Scott LaVarnway committed
234
235
236
237
238
            for (mb_col = 0; mb_col < mb_cols; mb_col++)
            {
                int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
                                mode_info_context->mbmi.mode != SPLITMV &&
                                mode_info_context->mbmi.mb_skip_coeff);
John Koleszar's avatar
John Koleszar committed
239

Scott LaVarnway's avatar
Scott LaVarnway committed
240
241
242
                const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
                const int seg = mode_info_context->mbmi.segment_id;
                const int ref_frame = mode_info_context->mbmi.ref_frame;
John Koleszar's avatar
John Koleszar committed
243

Scott LaVarnway's avatar
Scott LaVarnway committed
244
                filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
John Koleszar's avatar
John Koleszar committed
245

Scott LaVarnway's avatar
Scott LaVarnway committed
246
                if (filter_level)
Attila Nagy's avatar
Attila Nagy committed
247
248
249
250
251
252
253
254
                {
                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
                    lfi.mblim = lfi_n->mblim[filter_level];
                    lfi.blim = lfi_n->blim[filter_level];
                    lfi.lim = lfi_n->lim[filter_level];
                    lfi.hev_thr = lfi_n->hev_thr[hev_index];

                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
255
                        vp8_loop_filter_mbv
Scott LaVarnway's avatar
Scott LaVarnway committed
256
                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
Attila Nagy's avatar
Attila Nagy committed
257
258

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
259
                        vp8_loop_filter_bv
Scott LaVarnway's avatar
Scott LaVarnway committed
260
                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
Attila Nagy's avatar
Attila Nagy committed
261
262
263

                    /* don't apply across umv border */
                    if (mb_row > 0)
John Koleszar's avatar
John Koleszar committed
264
                        vp8_loop_filter_mbh
Scott LaVarnway's avatar
Scott LaVarnway committed
265
                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
Attila Nagy's avatar
Attila Nagy committed
266
267

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
268
                        vp8_loop_filter_bh
Scott LaVarnway's avatar
Scott LaVarnway committed
269
                        (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
Attila Nagy's avatar
Attila Nagy committed
270
                }
Scott LaVarnway's avatar
Scott LaVarnway committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

                y_ptr += 16;
                u_ptr += 8;
                v_ptr += 8;

                mode_info_context++;     /* step to next MB */
            }
            y_ptr += post_y_stride  * 16 - post->y_width;
            u_ptr += post_uv_stride *  8 - post->uv_width;
            v_ptr += post_uv_stride *  8 - post->uv_width;

            mode_info_context++;         /* Skip border mb */

        }
    }
    else /* SIMPLE_LOOPFILTER */
    {
        for (mb_row = 0; mb_row < mb_rows; mb_row++)
        {
            for (mb_col = 0; mb_col < mb_cols; mb_col++)
            {
                int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
                                mode_info_context->mbmi.mode != SPLITMV &&
                                mode_info_context->mbmi.mb_skip_coeff);

                const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
                const int seg = mode_info_context->mbmi.segment_id;
                const int ref_frame = mode_info_context->mbmi.ref_frame;

                filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
                if (filter_level)
Attila Nagy's avatar
Attila Nagy committed
302
                {
Scott LaVarnway's avatar
Scott LaVarnway committed
303
304
305
                    const unsigned char * mblim = lfi_n->mblim[filter_level];
                    const unsigned char * blim = lfi_n->blim[filter_level];

Attila Nagy's avatar
Attila Nagy committed
306
                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
307
                        vp8_loop_filter_simple_mbv
Scott LaVarnway's avatar
Scott LaVarnway committed
308
                        (y_ptr, post_y_stride, mblim);
Attila Nagy's avatar
Attila Nagy committed
309
310

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
311
                        vp8_loop_filter_simple_bv
Scott LaVarnway's avatar
Scott LaVarnway committed
312
                        (y_ptr, post_y_stride, blim);
Attila Nagy's avatar
Attila Nagy committed
313
314
315

                    /* don't apply across umv border */
                    if (mb_row > 0)
John Koleszar's avatar
John Koleszar committed
316
                        vp8_loop_filter_simple_mbh
Scott LaVarnway's avatar
Scott LaVarnway committed
317
                        (y_ptr, post_y_stride, mblim);
Attila Nagy's avatar
Attila Nagy committed
318
319

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
320
                        vp8_loop_filter_simple_bh
Scott LaVarnway's avatar
Scott LaVarnway committed
321
                        (y_ptr, post_y_stride, blim);
Attila Nagy's avatar
Attila Nagy committed
322
                }
John Koleszar's avatar
John Koleszar committed
323

Scott LaVarnway's avatar
Scott LaVarnway committed
324
325
326
                y_ptr += 16;
                u_ptr += 8;
                v_ptr += 8;
John Koleszar's avatar
John Koleszar committed
327

Scott LaVarnway's avatar
Scott LaVarnway committed
328
329
330
331
332
                mode_info_context++;     /* step to next MB */
            }
            y_ptr += post_y_stride  * 16 - post->y_width;
            u_ptr += post_uv_stride *  8 - post->uv_width;
            v_ptr += post_uv_stride *  8 - post->uv_width;
John Koleszar's avatar
John Koleszar committed
333

Scott LaVarnway's avatar
Scott LaVarnway committed
334
            mode_info_context++;         /* Skip border mb */
John Koleszar's avatar
John Koleszar committed
335

Scott LaVarnway's avatar
Scott LaVarnway committed
336
        }
John Koleszar's avatar
John Koleszar committed
337
338
339
340
341
342
343
    }
}

void vp8_loop_filter_frame_yonly
(
    VP8_COMMON *cm,
    MACROBLOCKD *mbd,
Johann's avatar
Johann committed
344
    int default_filt_lvl
John Koleszar's avatar
John Koleszar committed
345
346
347
348
349
350
351
352
)
{
    YV12_BUFFER_CONFIG *post = cm->frame_to_show;

    unsigned char *y_ptr;
    int mb_row;
    int mb_col;

Attila Nagy's avatar
Attila Nagy committed
353
354
355
    loop_filter_info_n *lfi_n = &cm->lf_info;
    loop_filter_info lfi;

John Koleszar's avatar
John Koleszar committed
356
    int filter_level;
357
    FRAME_TYPE frame_type = cm->frame_type;
John Koleszar's avatar
John Koleszar committed
358

Attila Nagy's avatar
Attila Nagy committed
359
360
    /* Point at base of Mb MODE_INFO list */
    const MODE_INFO *mode_info_context = cm->mi;
John Koleszar's avatar
John Koleszar committed
361

Attila Nagy's avatar
Attila Nagy committed
362
363
364
365
#if 0
    if(default_filt_lvl == 0) /* no filter applied */
        return;
#endif
John Koleszar's avatar
John Koleszar committed
366

367
    /* Initialize the loop filter for this frame. */
Johann's avatar
Johann committed
368
    vp8_loop_filter_frame_init( cm, mbd, default_filt_lvl);
John Koleszar's avatar
John Koleszar committed
369

370
    /* Set up the buffer pointers */
John Koleszar's avatar
John Koleszar committed
371
372
    y_ptr = post->y_buffer;

373
    /* vp8_filter each macro block */
John Koleszar's avatar
John Koleszar committed
374
375
376
377
    for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
    {
        for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
        {
Attila Nagy's avatar
Attila Nagy committed
378
379
380
            int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
                            mode_info_context->mbmi.mode != SPLITMV &&
                            mode_info_context->mbmi.mb_skip_coeff);
381

Attila Nagy's avatar
Attila Nagy committed
382
383
384
            const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
            const int seg = mode_info_context->mbmi.segment_id;
            const int ref_frame = mode_info_context->mbmi.ref_frame;
John Koleszar's avatar
John Koleszar committed
385

Attila Nagy's avatar
Attila Nagy committed
386
            filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
John Koleszar's avatar
John Koleszar committed
387
388
389

            if (filter_level)
            {
Attila Nagy's avatar
Attila Nagy committed
390
391
392
393
394
395
396
397
398
                if (cm->filter_type == NORMAL_LOOPFILTER)
                {
                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
                    lfi.mblim = lfi_n->mblim[filter_level];
                    lfi.blim = lfi_n->blim[filter_level];
                    lfi.lim = lfi_n->lim[filter_level];
                    lfi.hev_thr = lfi_n->hev_thr[hev_index];

                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
399
                        vp8_loop_filter_mbv
Attila Nagy's avatar
Attila Nagy committed
400
401
402
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
403
                        vp8_loop_filter_bv
Attila Nagy's avatar
Attila Nagy committed
404
405
406
407
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

                    /* don't apply across umv border */
                    if (mb_row > 0)
John Koleszar's avatar
John Koleszar committed
408
                        vp8_loop_filter_mbh
Attila Nagy's avatar
Attila Nagy committed
409
410
411
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
412
                        vp8_loop_filter_bh
Attila Nagy's avatar
Attila Nagy committed
413
414
415
416
417
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
                }
                else
                {
                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
418
                        vp8_loop_filter_simple_mbv
Attila Nagy's avatar
Attila Nagy committed
419
420
421
                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
422
                        vp8_loop_filter_simple_bv
Attila Nagy's avatar
Attila Nagy committed
423
424
425
426
                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);

                    /* don't apply across umv border */
                    if (mb_row > 0)
John Koleszar's avatar
John Koleszar committed
427
                        vp8_loop_filter_simple_mbh
Attila Nagy's avatar
Attila Nagy committed
428
429
430
                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
431
                        vp8_loop_filter_simple_bh
Attila Nagy's avatar
Attila Nagy committed
432
433
                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
                }
John Koleszar's avatar
John Koleszar committed
434
435
436
            }

            y_ptr += 16;
Attila Nagy's avatar
Attila Nagy committed
437
            mode_info_context ++;        /* step to next MB */
John Koleszar's avatar
John Koleszar committed
438
439
440
441

        }

        y_ptr += post->y_stride  * 16 - post->y_width;
Attila Nagy's avatar
Attila Nagy committed
442
        mode_info_context ++;            /* Skip border mb */
John Koleszar's avatar
John Koleszar committed
443
444
445
446
447
448
449
450
    }

}

void vp8_loop_filter_partial_frame
(
    VP8_COMMON *cm,
    MACROBLOCKD *mbd,
Johann's avatar
Johann committed
451
    int default_filt_lvl
John Koleszar's avatar
John Koleszar committed
452
453
454
455
456
457
458
)
{
    YV12_BUFFER_CONFIG *post = cm->frame_to_show;

    unsigned char *y_ptr;
    int mb_row;
    int mb_col;
459
460
    int mb_cols = post->y_width >> 4;
    int mb_rows = post->y_height >> 4;
John Koleszar's avatar
John Koleszar committed
461

Attila Nagy's avatar
Attila Nagy committed
462
463
464
465
    int linestocopy, i;

    loop_filter_info_n *lfi_n = &cm->lf_info;
    loop_filter_info lfi;
John Koleszar's avatar
John Koleszar committed
466
467
468

    int filter_level;
    int alt_flt_enabled = mbd->segmentation_enabled;
469
    FRAME_TYPE frame_type = cm->frame_type;
John Koleszar's avatar
John Koleszar committed
470

Attila Nagy's avatar
Attila Nagy committed
471
472
473
474
    const MODE_INFO *mode_info_context;

    int lvl_seg[MAX_MB_SEGMENTS];

475
476
477
    /* number of MB rows to use in partial filtering */
    linestocopy = mb_rows / PARTIAL_FRAME_FRACTION;
    linestocopy = linestocopy ? linestocopy << 4 : 16;     /* 16 lines per MB */
John Koleszar's avatar
John Koleszar committed
478

479
    /* Note the baseline filter values for each segment */
Johann's avatar
Johann committed
480
481
482
    /* See vp8_loop_filter_frame_init. Rather than call that for each change
     * to default_filt_lvl, copy the relevant calculation here.
     */
John Koleszar's avatar
John Koleszar committed
483
484
485
    if (alt_flt_enabled)
    {
        for (i = 0; i < MAX_MB_SEGMENTS; i++)
Attila Nagy's avatar
Attila Nagy committed
486
        {    /* Abs value */
John Koleszar's avatar
John Koleszar committed
487
            if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
Attila Nagy's avatar
Attila Nagy committed
488
489
490
            {
                lvl_seg[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
            }
491
            /* Delta Value */
John Koleszar's avatar
John Koleszar committed
492
493
            else
            {
Attila Nagy's avatar
Attila Nagy committed
494
495
496
497
                lvl_seg[i] = default_filt_lvl
                        + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
                lvl_seg[i] = (lvl_seg[i] > 0) ?
                        ((lvl_seg[i] > 63) ? 63: lvl_seg[i]) : 0;
John Koleszar's avatar
John Koleszar committed
498
499
500
501
            }
        }
    }

502
503
504
    /* Set up the buffer pointers; partial image starts at ~middle of frame */
    y_ptr = post->y_buffer + ((post->y_height >> 5) * 16) * post->y_stride;
    mode_info_context = cm->mi + (post->y_height >> 5) * (mb_cols + 1);
John Koleszar's avatar
John Koleszar committed
505

506
    /* vp8_filter each macro block */
John Koleszar's avatar
John Koleszar committed
507
508
509
510
    for (mb_row = 0; mb_row<(linestocopy >> 4); mb_row++)
    {
        for (mb_col = 0; mb_col < mb_cols; mb_col++)
        {
Attila Nagy's avatar
Attila Nagy committed
511
512
513
            int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
                           mode_info_context->mbmi.mode != SPLITMV &&
                           mode_info_context->mbmi.mb_skip_coeff);
514

Attila Nagy's avatar
Attila Nagy committed
515
516
517
            if (alt_flt_enabled)
                filter_level = lvl_seg[mode_info_context->mbmi.segment_id];
            else
Johann's avatar
Johann committed
518
                filter_level = default_filt_lvl;
John Koleszar's avatar
John Koleszar committed
519
520
521

            if (filter_level)
            {
Attila Nagy's avatar
Attila Nagy committed
522
523
524
525
526
527
528
529
530
                if (cm->filter_type == NORMAL_LOOPFILTER)
                {
                    const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
                    lfi.mblim = lfi_n->mblim[filter_level];
                    lfi.blim = lfi_n->blim[filter_level];
                    lfi.lim = lfi_n->lim[filter_level];
                    lfi.hev_thr = lfi_n->hev_thr[hev_index];

                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
531
                        vp8_loop_filter_mbv
Attila Nagy's avatar
Attila Nagy committed
532
533
534
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
535
                        vp8_loop_filter_bv
Attila Nagy's avatar
Attila Nagy committed
536
537
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

John Koleszar's avatar
John Koleszar committed
538
                    vp8_loop_filter_mbh
Attila Nagy's avatar
Attila Nagy committed
539
540
541
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
542
                        vp8_loop_filter_bh
Attila Nagy's avatar
Attila Nagy committed
543
544
545
546
547
                        (y_ptr, 0, 0, post->y_stride, 0, &lfi);
                }
                else
                {
                    if (mb_col > 0)
John Koleszar's avatar
John Koleszar committed
548
                        vp8_loop_filter_simple_mbv
Attila Nagy's avatar
Attila Nagy committed
549
550
551
                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
552
                        vp8_loop_filter_simple_bv
Attila Nagy's avatar
Attila Nagy committed
553
554
                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);

John Koleszar's avatar
John Koleszar committed
555
                    vp8_loop_filter_simple_mbh
Attila Nagy's avatar
Attila Nagy committed
556
557
558
                        (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);

                    if (!skip_lf)
John Koleszar's avatar
John Koleszar committed
559
                        vp8_loop_filter_simple_bh
Attila Nagy's avatar
Attila Nagy committed
560
561
                        (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
                }
John Koleszar's avatar
John Koleszar committed
562
563
564
            }

            y_ptr += 16;
Attila Nagy's avatar
Attila Nagy committed
565
            mode_info_context += 1;      /* step to next MB */
John Koleszar's avatar
John Koleszar committed
566
567
568
        }

        y_ptr += post->y_stride  * 16 - post->y_width;
Attila Nagy's avatar
Attila Nagy committed
569
        mode_info_context += 1;          /* Skip border mb */
John Koleszar's avatar
John Koleszar committed
570
571
    }
}