1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  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.
9  */
10 
11 
12 #include "vpx_config.h"
13 #include "vp8_rtcd.h"
14 #include "loopfilter.h"
15 #include "onyxc_int.h"
16 #include "vpx_mem/vpx_mem.h"
17 
18 
lf_init_lut(loop_filter_info_n * lfi)19 static void lf_init_lut(loop_filter_info_n *lfi)
20 {
21     int filt_lvl;
22 
23     for (filt_lvl = 0; filt_lvl <= MAX_LOOP_FILTER; filt_lvl++)
24     {
25         if (filt_lvl >= 40)
26         {
27             lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 2;
28             lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 3;
29         }
30         else if (filt_lvl >= 20)
31         {
32             lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
33             lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 2;
34         }
35         else if (filt_lvl >= 15)
36         {
37             lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 1;
38             lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 1;
39         }
40         else
41         {
42             lfi->hev_thr_lut[KEY_FRAME][filt_lvl] = 0;
43             lfi->hev_thr_lut[INTER_FRAME][filt_lvl] = 0;
44         }
45     }
46 
47     lfi->mode_lf_lut[DC_PRED] = 1;
48     lfi->mode_lf_lut[V_PRED] = 1;
49     lfi->mode_lf_lut[H_PRED] = 1;
50     lfi->mode_lf_lut[TM_PRED] = 1;
51     lfi->mode_lf_lut[B_PRED]  = 0;
52 
53     lfi->mode_lf_lut[ZEROMV]  = 1;
54     lfi->mode_lf_lut[NEARESTMV] = 2;
55     lfi->mode_lf_lut[NEARMV] = 2;
56     lfi->mode_lf_lut[NEWMV] = 2;
57     lfi->mode_lf_lut[SPLITMV] = 3;
58 
59 }
60 
vp8_loop_filter_update_sharpness(loop_filter_info_n * lfi,int sharpness_lvl)61 void vp8_loop_filter_update_sharpness(loop_filter_info_n *lfi,
62                                       int sharpness_lvl)
63 {
64     int i;
65 
66     /* For each possible value for the loop filter fill out limits */
67     for (i = 0; i <= MAX_LOOP_FILTER; i++)
68     {
69         int filt_lvl = i;
70         int block_inside_limit = 0;
71 
72         /* Set loop filter paramaeters that control sharpness. */
73         block_inside_limit = filt_lvl >> (sharpness_lvl > 0);
74         block_inside_limit = block_inside_limit >> (sharpness_lvl > 4);
75 
76         if (sharpness_lvl > 0)
77         {
78             if (block_inside_limit > (9 - sharpness_lvl))
79                 block_inside_limit = (9 - sharpness_lvl);
80         }
81 
82         if (block_inside_limit < 1)
83             block_inside_limit = 1;
84 
85         vpx_memset(lfi->lim[i], block_inside_limit, SIMD_WIDTH);
86         vpx_memset(lfi->blim[i], (2 * filt_lvl + block_inside_limit),
87                 SIMD_WIDTH);
88         vpx_memset(lfi->mblim[i], (2 * (filt_lvl + 2) + block_inside_limit),
89                 SIMD_WIDTH);
90     }
91 }
92 
vp8_loop_filter_init(VP8_COMMON * cm)93 void vp8_loop_filter_init(VP8_COMMON *cm)
94 {
95     loop_filter_info_n *lfi = &cm->lf_info;
96     int i;
97 
98     /* init limits for given sharpness*/
99     vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
100     cm->last_sharpness_level = cm->sharpness_level;
101 
102     /* init LUT for lvl  and hev thr picking */
103     lf_init_lut(lfi);
104 
105     /* init hev threshold const vectors */
106     for(i = 0; i < 4 ; i++)
107     {
108         vpx_memset(lfi->hev_thr[i], i, SIMD_WIDTH);
109     }
110 }
111 
vp8_loop_filter_frame_init(VP8_COMMON * cm,MACROBLOCKD * mbd,int default_filt_lvl)112 void vp8_loop_filter_frame_init(VP8_COMMON *cm,
113                                 MACROBLOCKD *mbd,
114                                 int default_filt_lvl)
115 {
116     int seg,  /* segment number */
117         ref,  /* index in ref_lf_deltas */
118         mode; /* index in mode_lf_deltas */
119 
120     loop_filter_info_n *lfi = &cm->lf_info;
121 
122     /* update limits if sharpness has changed */
123     if(cm->last_sharpness_level != cm->sharpness_level)
124     {
125         vp8_loop_filter_update_sharpness(lfi, cm->sharpness_level);
126         cm->last_sharpness_level = cm->sharpness_level;
127     }
128 
129     for(seg = 0; seg < MAX_MB_SEGMENTS; seg++)
130     {
131         int lvl_seg = default_filt_lvl;
132         int lvl_ref, lvl_mode;
133 
134         /* Note the baseline filter values for each segment */
135         if (mbd->segmentation_enabled)
136         {
137             /* Abs value */
138             if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
139             {
140                 lvl_seg = mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
141             }
142             else  /* Delta Value */
143             {
144                 lvl_seg += mbd->segment_feature_data[MB_LVL_ALT_LF][seg];
145                 lvl_seg = (lvl_seg > 0) ? ((lvl_seg > 63) ? 63: lvl_seg) : 0;
146             }
147         }
148 
149         if (!mbd->mode_ref_lf_delta_enabled)
150         {
151             /* we could get rid of this if we assume that deltas are set to
152              * zero when not in use; encoder always uses deltas
153              */
154             vpx_memset(lfi->lvl[seg][0], lvl_seg, 4 * 4 );
155             continue;
156         }
157 
158         /* INTRA_FRAME */
159         ref = INTRA_FRAME;
160 
161         /* Apply delta for reference frame */
162         lvl_ref = lvl_seg + mbd->ref_lf_deltas[ref];
163 
164         /* Apply delta for Intra modes */
165         mode = 0; /* B_PRED */
166         /* Only the split mode BPRED has a further special case */
167         lvl_mode = lvl_ref + mbd->mode_lf_deltas[mode];
168         /* clamp */
169         lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0;
170 
171         lfi->lvl[seg][ref][mode] = lvl_mode;
172 
173         mode = 1; /* all the rest of Intra modes */
174         /* clamp */
175         lvl_mode = (lvl_ref > 0) ? (lvl_ref > 63 ? 63 : lvl_ref) : 0;
176         lfi->lvl[seg][ref][mode] = lvl_mode;
177 
178         /* LAST, GOLDEN, ALT */
179         for(ref = 1; ref < MAX_REF_FRAMES; ref++)
180         {
181             /* Apply delta for reference frame */
182             lvl_ref = lvl_seg + mbd->ref_lf_deltas[ref];
183 
184             /* Apply delta for Inter modes */
185             for (mode = 1; mode < 4; mode++)
186             {
187                 lvl_mode = lvl_ref + mbd->mode_lf_deltas[mode];
188                 /* clamp */
189                 lvl_mode = (lvl_mode > 0) ? (lvl_mode > 63 ? 63 : lvl_mode) : 0;
190 
191                 lfi->lvl[seg][ref][mode] = lvl_mode;
192             }
193         }
194     }
195 }
196 
197 
vp8_loop_filter_row_normal(VP8_COMMON * cm,MODE_INFO * mode_info_context,int mb_row,int post_ystride,int post_uvstride,unsigned char * y_ptr,unsigned char * u_ptr,unsigned char * v_ptr)198 void vp8_loop_filter_row_normal(VP8_COMMON *cm, MODE_INFO *mode_info_context,
199                          int mb_row, int post_ystride, int post_uvstride,
200                          unsigned char *y_ptr, unsigned char *u_ptr,
201                          unsigned char *v_ptr)
202 {
203     int mb_col;
204     int filter_level;
205     loop_filter_info_n *lfi_n = &cm->lf_info;
206     loop_filter_info lfi;
207     FRAME_TYPE frame_type = cm->frame_type;
208 
209     for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
210     {
211         int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
212                         mode_info_context->mbmi.mode != SPLITMV &&
213                         mode_info_context->mbmi.mb_skip_coeff);
214 
215         const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
216         const int seg = mode_info_context->mbmi.segment_id;
217         const int ref_frame = mode_info_context->mbmi.ref_frame;
218 
219         filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
220 
221         if (filter_level)
222         {
223             const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
224             lfi.mblim = lfi_n->mblim[filter_level];
225             lfi.blim = lfi_n->blim[filter_level];
226             lfi.lim = lfi_n->lim[filter_level];
227             lfi.hev_thr = lfi_n->hev_thr[hev_index];
228 
229             if (mb_col > 0)
230                 vp8_loop_filter_mbv
231                 (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
232 
233             if (!skip_lf)
234                 vp8_loop_filter_bv
235                 (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
236 
237             /* don't apply across umv border */
238             if (mb_row > 0)
239                 vp8_loop_filter_mbh
240                 (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
241 
242             if (!skip_lf)
243                 vp8_loop_filter_bh
244                 (y_ptr, u_ptr, v_ptr, post_ystride, post_uvstride, &lfi);
245         }
246 
247         y_ptr += 16;
248         u_ptr += 8;
249         v_ptr += 8;
250 
251         mode_info_context++;     /* step to next MB */
252     }
253 
254 }
255 
vp8_loop_filter_row_simple(VP8_COMMON * cm,MODE_INFO * mode_info_context,int mb_row,int post_ystride,int post_uvstride,unsigned char * y_ptr,unsigned char * u_ptr,unsigned char * v_ptr)256 void vp8_loop_filter_row_simple(VP8_COMMON *cm, MODE_INFO *mode_info_context,
257                          int mb_row, int post_ystride, int post_uvstride,
258                          unsigned char *y_ptr, unsigned char *u_ptr,
259                          unsigned char *v_ptr)
260 {
261     int mb_col;
262     int filter_level;
263     loop_filter_info_n *lfi_n = &cm->lf_info;
264 
265     for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
266     {
267         int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
268                         mode_info_context->mbmi.mode != SPLITMV &&
269                         mode_info_context->mbmi.mb_skip_coeff);
270 
271         const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
272         const int seg = mode_info_context->mbmi.segment_id;
273         const int ref_frame = mode_info_context->mbmi.ref_frame;
274 
275         filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
276 
277         if (filter_level)
278         {
279             if (mb_col > 0)
280                 vp8_loop_filter_simple_mbv
281                 (y_ptr, post_ystride, lfi_n->mblim[filter_level]);
282 
283             if (!skip_lf)
284                 vp8_loop_filter_simple_bv
285                 (y_ptr, post_ystride, lfi_n->blim[filter_level]);
286 
287             /* don't apply across umv border */
288             if (mb_row > 0)
289                 vp8_loop_filter_simple_mbh
290                 (y_ptr, post_ystride, lfi_n->mblim[filter_level]);
291 
292             if (!skip_lf)
293                 vp8_loop_filter_simple_bh
294                 (y_ptr, post_ystride, lfi_n->blim[filter_level]);
295         }
296 
297         y_ptr += 16;
298         u_ptr += 8;
299         v_ptr += 8;
300 
301         mode_info_context++;     /* step to next MB */
302     }
303 
304 }
vp8_loop_filter_frame(VP8_COMMON * cm,MACROBLOCKD * mbd,int frame_type)305 void vp8_loop_filter_frame(VP8_COMMON *cm,
306                            MACROBLOCKD *mbd,
307                            int frame_type)
308 {
309     YV12_BUFFER_CONFIG *post = cm->frame_to_show;
310     loop_filter_info_n *lfi_n = &cm->lf_info;
311     loop_filter_info lfi;
312 
313     int mb_row;
314     int mb_col;
315     int mb_rows = cm->mb_rows;
316     int mb_cols = cm->mb_cols;
317 
318     int filter_level;
319 
320     unsigned char *y_ptr, *u_ptr, *v_ptr;
321 
322     /* Point at base of Mb MODE_INFO list */
323     const MODE_INFO *mode_info_context = cm->mi;
324     int post_y_stride = post->y_stride;
325     int post_uv_stride = post->uv_stride;
326 
327     /* Initialize the loop filter for this frame. */
328     vp8_loop_filter_frame_init(cm, mbd, cm->filter_level);
329 
330     /* Set up the buffer pointers */
331     y_ptr = post->y_buffer;
332     u_ptr = post->u_buffer;
333     v_ptr = post->v_buffer;
334 
335     /* vp8_filter each macro block */
336     if (cm->filter_type == NORMAL_LOOPFILTER)
337     {
338         for (mb_row = 0; mb_row < mb_rows; mb_row++)
339         {
340             for (mb_col = 0; mb_col < mb_cols; mb_col++)
341             {
342                 int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
343                                 mode_info_context->mbmi.mode != SPLITMV &&
344                                 mode_info_context->mbmi.mb_skip_coeff);
345 
346                 const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
347                 const int seg = mode_info_context->mbmi.segment_id;
348                 const int ref_frame = mode_info_context->mbmi.ref_frame;
349 
350                 filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
351 
352                 if (filter_level)
353                 {
354                     const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
355                     lfi.mblim = lfi_n->mblim[filter_level];
356                     lfi.blim = lfi_n->blim[filter_level];
357                     lfi.lim = lfi_n->lim[filter_level];
358                     lfi.hev_thr = lfi_n->hev_thr[hev_index];
359 
360                     if (mb_col > 0)
361                         vp8_loop_filter_mbv
362                         (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
363 
364                     if (!skip_lf)
365                         vp8_loop_filter_bv
366                         (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
367 
368                     /* don't apply across umv border */
369                     if (mb_row > 0)
370                         vp8_loop_filter_mbh
371                         (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
372 
373                     if (!skip_lf)
374                         vp8_loop_filter_bh
375                         (y_ptr, u_ptr, v_ptr, post_y_stride, post_uv_stride, &lfi);
376                 }
377 
378                 y_ptr += 16;
379                 u_ptr += 8;
380                 v_ptr += 8;
381 
382                 mode_info_context++;     /* step to next MB */
383             }
384             y_ptr += post_y_stride  * 16 - post->y_width;
385             u_ptr += post_uv_stride *  8 - post->uv_width;
386             v_ptr += post_uv_stride *  8 - post->uv_width;
387 
388             mode_info_context++;         /* Skip border mb */
389 
390         }
391     }
392     else /* SIMPLE_LOOPFILTER */
393     {
394         for (mb_row = 0; mb_row < mb_rows; mb_row++)
395         {
396             for (mb_col = 0; mb_col < mb_cols; mb_col++)
397             {
398                 int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
399                                 mode_info_context->mbmi.mode != SPLITMV &&
400                                 mode_info_context->mbmi.mb_skip_coeff);
401 
402                 const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
403                 const int seg = mode_info_context->mbmi.segment_id;
404                 const int ref_frame = mode_info_context->mbmi.ref_frame;
405 
406                 filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
407                 if (filter_level)
408                 {
409                     const unsigned char * mblim = lfi_n->mblim[filter_level];
410                     const unsigned char * blim = lfi_n->blim[filter_level];
411 
412                     if (mb_col > 0)
413                         vp8_loop_filter_simple_mbv
414                         (y_ptr, post_y_stride, mblim);
415 
416                     if (!skip_lf)
417                         vp8_loop_filter_simple_bv
418                         (y_ptr, post_y_stride, blim);
419 
420                     /* don't apply across umv border */
421                     if (mb_row > 0)
422                         vp8_loop_filter_simple_mbh
423                         (y_ptr, post_y_stride, mblim);
424 
425                     if (!skip_lf)
426                         vp8_loop_filter_simple_bh
427                         (y_ptr, post_y_stride, blim);
428                 }
429 
430                 y_ptr += 16;
431                 u_ptr += 8;
432                 v_ptr += 8;
433 
434                 mode_info_context++;     /* step to next MB */
435             }
436             y_ptr += post_y_stride  * 16 - post->y_width;
437             u_ptr += post_uv_stride *  8 - post->uv_width;
438             v_ptr += post_uv_stride *  8 - post->uv_width;
439 
440             mode_info_context++;         /* Skip border mb */
441 
442         }
443     }
444 }
445 
vp8_loop_filter_frame_yonly(VP8_COMMON * cm,MACROBLOCKD * mbd,int default_filt_lvl)446 void vp8_loop_filter_frame_yonly
447 (
448     VP8_COMMON *cm,
449     MACROBLOCKD *mbd,
450     int default_filt_lvl
451 )
452 {
453     YV12_BUFFER_CONFIG *post = cm->frame_to_show;
454 
455     unsigned char *y_ptr;
456     int mb_row;
457     int mb_col;
458 
459     loop_filter_info_n *lfi_n = &cm->lf_info;
460     loop_filter_info lfi;
461 
462     int filter_level;
463     FRAME_TYPE frame_type = cm->frame_type;
464 
465     /* Point at base of Mb MODE_INFO list */
466     const MODE_INFO *mode_info_context = cm->mi;
467 
468 #if 0
469     if(default_filt_lvl == 0) /* no filter applied */
470         return;
471 #endif
472 
473     /* Initialize the loop filter for this frame. */
474     vp8_loop_filter_frame_init( cm, mbd, default_filt_lvl);
475 
476     /* Set up the buffer pointers */
477     y_ptr = post->y_buffer;
478 
479     /* vp8_filter each macro block */
480     for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
481     {
482         for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
483         {
484             int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
485                             mode_info_context->mbmi.mode != SPLITMV &&
486                             mode_info_context->mbmi.mb_skip_coeff);
487 
488             const int mode_index = lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
489             const int seg = mode_info_context->mbmi.segment_id;
490             const int ref_frame = mode_info_context->mbmi.ref_frame;
491 
492             filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
493 
494             if (filter_level)
495             {
496                 if (cm->filter_type == NORMAL_LOOPFILTER)
497                 {
498                     const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
499                     lfi.mblim = lfi_n->mblim[filter_level];
500                     lfi.blim = lfi_n->blim[filter_level];
501                     lfi.lim = lfi_n->lim[filter_level];
502                     lfi.hev_thr = lfi_n->hev_thr[hev_index];
503 
504                     if (mb_col > 0)
505                         vp8_loop_filter_mbv
506                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
507 
508                     if (!skip_lf)
509                         vp8_loop_filter_bv
510                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
511 
512                     /* don't apply across umv border */
513                     if (mb_row > 0)
514                         vp8_loop_filter_mbh
515                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
516 
517                     if (!skip_lf)
518                         vp8_loop_filter_bh
519                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
520                 }
521                 else
522                 {
523                     if (mb_col > 0)
524                         vp8_loop_filter_simple_mbv
525                         (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
526 
527                     if (!skip_lf)
528                         vp8_loop_filter_simple_bv
529                         (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
530 
531                     /* don't apply across umv border */
532                     if (mb_row > 0)
533                         vp8_loop_filter_simple_mbh
534                         (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
535 
536                     if (!skip_lf)
537                         vp8_loop_filter_simple_bh
538                         (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
539                 }
540             }
541 
542             y_ptr += 16;
543             mode_info_context ++;        /* step to next MB */
544 
545         }
546 
547         y_ptr += post->y_stride  * 16 - post->y_width;
548         mode_info_context ++;            /* Skip border mb */
549     }
550 
551 }
552 
vp8_loop_filter_partial_frame(VP8_COMMON * cm,MACROBLOCKD * mbd,int default_filt_lvl)553 void vp8_loop_filter_partial_frame
554 (
555     VP8_COMMON *cm,
556     MACROBLOCKD *mbd,
557     int default_filt_lvl
558 )
559 {
560     YV12_BUFFER_CONFIG *post = cm->frame_to_show;
561 
562     unsigned char *y_ptr;
563     int mb_row;
564     int mb_col;
565     int mb_cols = post->y_width >> 4;
566     int mb_rows = post->y_height >> 4;
567 
568     int linestocopy;
569 
570     loop_filter_info_n *lfi_n = &cm->lf_info;
571     loop_filter_info lfi;
572 
573     int filter_level;
574     FRAME_TYPE frame_type = cm->frame_type;
575 
576     const MODE_INFO *mode_info_context;
577 
578 #if 0
579     if(default_filt_lvl == 0) /* no filter applied */
580         return;
581 #endif
582 
583     /* Initialize the loop filter for this frame. */
584     vp8_loop_filter_frame_init( cm, mbd, default_filt_lvl);
585 
586     /* number of MB rows to use in partial filtering */
587     linestocopy = mb_rows / PARTIAL_FRAME_FRACTION;
588     linestocopy = linestocopy ? linestocopy << 4 : 16;     /* 16 lines per MB */
589 
590     /* Set up the buffer pointers; partial image starts at ~middle of frame */
591     y_ptr = post->y_buffer + ((post->y_height >> 5) * 16) * post->y_stride;
592     mode_info_context = cm->mi + (post->y_height >> 5) * (mb_cols + 1);
593 
594     /* vp8_filter each macro block */
595     for (mb_row = 0; mb_row<(linestocopy >> 4); mb_row++)
596     {
597         for (mb_col = 0; mb_col < mb_cols; mb_col++)
598         {
599             int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
600                            mode_info_context->mbmi.mode != SPLITMV &&
601                            mode_info_context->mbmi.mb_skip_coeff);
602 
603             const int mode_index =
604                 lfi_n->mode_lf_lut[mode_info_context->mbmi.mode];
605             const int seg = mode_info_context->mbmi.segment_id;
606             const int ref_frame = mode_info_context->mbmi.ref_frame;
607 
608             filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
609 
610             if (filter_level)
611             {
612                 if (cm->filter_type == NORMAL_LOOPFILTER)
613                 {
614                     const int hev_index = lfi_n->hev_thr_lut[frame_type][filter_level];
615                     lfi.mblim = lfi_n->mblim[filter_level];
616                     lfi.blim = lfi_n->blim[filter_level];
617                     lfi.lim = lfi_n->lim[filter_level];
618                     lfi.hev_thr = lfi_n->hev_thr[hev_index];
619 
620                     if (mb_col > 0)
621                         vp8_loop_filter_mbv
622                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
623 
624                     if (!skip_lf)
625                         vp8_loop_filter_bv
626                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
627 
628                     vp8_loop_filter_mbh
629                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
630 
631                     if (!skip_lf)
632                         vp8_loop_filter_bh
633                         (y_ptr, 0, 0, post->y_stride, 0, &lfi);
634                 }
635                 else
636                 {
637                     if (mb_col > 0)
638                         vp8_loop_filter_simple_mbv
639                         (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
640 
641                     if (!skip_lf)
642                         vp8_loop_filter_simple_bv
643                         (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
644 
645                     vp8_loop_filter_simple_mbh
646                         (y_ptr, post->y_stride, lfi_n->mblim[filter_level]);
647 
648                     if (!skip_lf)
649                         vp8_loop_filter_simple_bh
650                         (y_ptr, post->y_stride, lfi_n->blim[filter_level]);
651                 }
652             }
653 
654             y_ptr += 16;
655             mode_info_context += 1;      /* step to next MB */
656         }
657 
658         y_ptr += post->y_stride  * 16 - post->y_width;
659         mode_info_context += 1;          /* Skip border mb */
660     }
661 }
662