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