Commit d278d018 authored by Yaowu Xu's avatar Yaowu Xu
Browse files

minor loop filter refactoring and cleanup

This commit did a couple of minor cleanup/refactoring to prepare for
futher loop filter experiments. It merged y_only version of loop filter
function into the regular one, which makes sure that same logic is used
for functions for picking level and for actual loop filtering.

Change-Id: Id10c94dccd45f58e5310bacfdf6ee63cbb60b86f
parent c13d9fef
......@@ -176,49 +176,52 @@ void vp9_loop_filter_frame_init(VP9_COMMON *cm,
}
}
void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd) {
static int mb_lf_skip(const MB_MODE_INFO *const mbmi) {
const MB_PREDICTION_MODE mode = mbmi->mode;
const int skip_coef = mbmi->mb_skip_coeff;
const int tx_size = mbmi->txfm_size;
return mode != B_PRED && mode != I8X8_PRED && mode != SPLITMV &&
tx_size >= TX_16X16 && skip_coef;
}
void vp9_loop_filter_frame(VP9_COMMON *cm,
MACROBLOCKD *xd,
int frame_filter_level,
int y_only) {
YV12_BUFFER_CONFIG *post = cm->frame_to_show;
loop_filter_info_n *lfi_n = &cm->lf_info;
struct loop_filter_info lfi;
FRAME_TYPE frame_type = cm->frame_type;
int mb_row;
int mb_col;
int filter_level;
const FRAME_TYPE frame_type = cm->frame_type;
int mb_row, mb_col;
uint8_t *y_ptr, *u_ptr, *v_ptr;
/* Point at base of Mb MODE_INFO list */
const MODE_INFO *mode_info_context = cm->mi;
#if CONFIG_SUPERBLOCKS
const int mis = cm->mode_info_stride;
#endif
/* Initialize the loop filter for this frame. */
vp9_loop_filter_frame_init(cm, xd, cm->filter_level);
vp9_loop_filter_frame_init(cm, xd, frame_filter_level);
/* Set up the buffer pointers */
y_ptr = post->y_buffer;
u_ptr = post->u_buffer;
v_ptr = post->v_buffer;
if (y_only) {
u_ptr = 0;
v_ptr = 0;
} else {
u_ptr = post->u_buffer;
v_ptr = post->v_buffer;
}
/* vp9_filter each macro block */
for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) {
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
mode_info_context->mbmi.mode != I8X8_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;
int tx_type = mode_info_context->mbmi.txfm_size;
filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
const int filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
if (filter_level) {
const int skip_lf = mb_lf_skip(&mode_info_context->mbmi);
const int tx_size = mode_info_context->mbmi.txfm_size;
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];
......@@ -229,19 +232,17 @@ void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd) {
if (mb_col > 0
#if CONFIG_SUPERBLOCKS
&& !((mb_col & 1) && mode_info_context->mbmi.sb_type &&
((mode_info_context[0].mbmi.mb_skip_coeff &&
mode_info_context[-1].mbmi.mb_skip_coeff)
((skip_lf && mb_lf_skip(&mode_info_context[-1].mbmi))
#if CONFIG_TX32X32
|| mode_info_context[-1].mbmi.txfm_size == TX_32X32
|| tx_size == TX_32X32
#endif
))
))
#endif
)
vp9_loop_filter_mbv(y_ptr, u_ptr, v_ptr, post->y_stride,
post->uv_stride, &lfi);
if (!skip_lf && tx_type < TX_16X16) {
if (tx_type == TX_8X8)
if (!skip_lf) {
if (tx_size >= TX_8X8)
vp9_loop_filter_bv8x8(y_ptr, u_ptr, v_ptr, post->y_stride,
post->uv_stride, &lfi);
else
......@@ -249,24 +250,21 @@ void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd) {
post->uv_stride, &lfi);
}
/* don't apply across umv border */
if (mb_row > 0
#if CONFIG_SUPERBLOCKS
&& !((mb_row & 1) && mode_info_context->mbmi.sb_type &&
((mode_info_context[0].mbmi.mb_skip_coeff &&
mode_info_context[-mis].mbmi.mb_skip_coeff)
((skip_lf && mb_lf_skip(&mode_info_context[-mis].mbmi))
#if CONFIG_TX32X32
|| mode_info_context[-mis].mbmi.txfm_size == TX_32X32
|| tx_size == TX_32X32
#endif
))
#endif
)
vp9_loop_filter_mbh(y_ptr, u_ptr, v_ptr, post->y_stride,
post->uv_stride, &lfi);
if (!skip_lf && tx_type < TX_16X16) {
if (tx_type == TX_8X8)
if (!skip_lf) {
if (tx_size >= TX_8X8)
vp9_loop_filter_bh8x8(y_ptr, u_ptr, v_ptr, post->y_stride,
post->uv_stride, &lfi);
else
......@@ -275,151 +273,48 @@ void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd) {
}
} else {
// FIXME: Not 8x8 aware
if (mb_col > 0
if (mb_col > 0 &&
!(skip_lf && mb_lf_skip(&mode_info_context[-1].mbmi))
#if CONFIG_SUPERBLOCKS
&& !((mb_col & 1) && mode_info_context->mbmi.sb_type &&
mode_info_context[0].mbmi.mb_skip_coeff &&
mode_info_context[-1].mbmi.mb_skip_coeff)
&& !((mb_col & 1) && mode_info_context->mbmi.sb_type)
#endif
)
vp9_loop_filter_simple_mbv(y_ptr, post->y_stride,
lfi_n->mblim[filter_level]);
if (!skip_lf)
vp9_loop_filter_simple_bv(y_ptr, post->y_stride,
lfi_n->blim[filter_level]);
/* don't apply across umv border */
if (mb_row > 0
if (mb_row > 0 &&
!(skip_lf && mb_lf_skip(&mode_info_context[-mis].mbmi))
#if CONFIG_SUPERBLOCKS
&& !((mb_row & 1) && mode_info_context->mbmi.sb_type &&
mode_info_context[0].mbmi.mb_skip_coeff &&
mode_info_context[-cm->mode_info_stride].mbmi.mb_skip_coeff)
&& !((mb_row & 1) && mode_info_context->mbmi.sb_type)
#endif
)
vp9_loop_filter_simple_mbh(y_ptr, post->y_stride,
lfi_n->mblim[filter_level]);
if (!skip_lf)
vp9_loop_filter_simple_bh(y_ptr, post->y_stride,
lfi_n->blim[filter_level]);
}
}
y_ptr += 16;
u_ptr += 8;
v_ptr += 8;
if (!y_only) {
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;
if (!y_only) {
u_ptr += post->uv_stride * 8 - post->uv_width;
v_ptr += post->uv_stride * 8 - post->uv_width;
}
mode_info_context++; /* Skip border mb */
}
}
void vp9_loop_filter_frame_yonly(VP9_COMMON *cm, MACROBLOCKD *xd,
int default_filt_lvl) {
YV12_BUFFER_CONFIG *post = cm->frame_to_show;
uint8_t *y_ptr;
int mb_row;
int mb_col;
loop_filter_info_n *lfi_n = &cm->lf_info;
struct loop_filter_info lfi;
int filter_level;
FRAME_TYPE frame_type = cm->frame_type;
/* Point at base of Mb MODE_INFO list */
const MODE_INFO *mode_info_context = cm->mi;
#if 0
if (default_filt_lvl == 0) /* no filter applied */
return;
#endif
/* Initialize the loop filter for this frame. */
vp9_loop_filter_frame_init(cm, xd, default_filt_lvl);
/* Set up the buffer pointers */
y_ptr = post->y_buffer;
/* vp9_filter each macro block */
for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) {
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
int skip_lf = (mode_info_context->mbmi.mode != B_PRED &&
mode_info_context->mbmi.mode != I8X8_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;
int tx_type = mode_info_context->mbmi.txfm_size;
filter_level = lfi_n->lvl[seg][ref_frame][mode_index];
if (filter_level) {
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)
vp9_loop_filter_mbv(y_ptr, 0, 0, post->y_stride, 0, &lfi);
if (!skip_lf && tx_type != TX_16X16) {
if (tx_type == TX_8X8)
vp9_loop_filter_bv8x8(y_ptr, 0, 0, post->y_stride, 0, &lfi);
else
vp9_loop_filter_bv(y_ptr, 0, 0, post->y_stride, 0, &lfi);
}
/* don't apply across umv border */
if (mb_row > 0)
vp9_loop_filter_mbh(y_ptr, 0, 0, post->y_stride, 0, &lfi);
if (!skip_lf && tx_type != TX_16X16) {
if (tx_type == TX_8X8)
vp9_loop_filter_bh8x8(y_ptr, 0, 0, post->y_stride, 0, &lfi);
else
vp9_loop_filter_bh(y_ptr, 0, 0, post->y_stride, 0, &lfi);
}
} else {
// FIXME: Not 8x8 aware
if (mb_col > 0)
vp9_loop_filter_simple_mbv(y_ptr, post->y_stride,
lfi_n->mblim[filter_level]);
if (!skip_lf)
vp9_loop_filter_simple_bv(y_ptr, post->y_stride,
lfi_n->blim[filter_level]);
/* don't apply across umv border */
if (mb_row > 0)
vp9_loop_filter_simple_mbh(y_ptr, post->y_stride,
lfi_n->mblim[filter_level]);
if (!skip_lf)
vp9_loop_filter_simple_bh(y_ptr, post->y_stride,
lfi_n->blim[filter_level]);
}
}
y_ptr += 16;
mode_info_context++; /* step to next MB */
}
y_ptr += post->y_stride * 16 - post->y_width;
mode_info_context++; /* Skip border mb */
}
}
void vp9_loop_filter_partial_frame(VP9_COMMON *cm, MACROBLOCKD *xd,
int default_filt_lvl) {
......
......@@ -80,16 +80,15 @@ void vp9_loop_filter_frame_init(struct VP9Common *cm,
struct macroblockd *mbd,
int default_filt_lvl);
void vp9_loop_filter_frame(struct VP9Common *cm, struct macroblockd *mbd);
void vp9_loop_filter_frame(struct VP9Common *cm,
struct macroblockd *mbd,
int filter_level,
int y_only);
void vp9_loop_filter_partial_frame(struct VP9Common *cm,
struct macroblockd *mbd,
int default_filt_lvl);
void vp9_loop_filter_frame_yonly(struct VP9Common *cm,
struct macroblockd *mbd,
int default_filt_lvl);
void vp9_loop_filter_update_sharpness(loop_filter_info_n *lfi,
int sharpness_lvl);
......
......@@ -382,7 +382,7 @@ int vp9_receive_compressed_data(VP9D_PTR ptr, unsigned long size,
if (cm->filter_level) {
/* Apply the loop filter if appropriate. */
vp9_loop_filter_frame(cm, &pbi->mb);
vp9_loop_filter_frame(cm, &pbi->mb, cm->filter_level, 0);
}
vp8_yv12_extend_frame_borders(cm->frame_to_show);
}
......
......@@ -2820,7 +2820,7 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) {
if (cm->filter_level > 0) {
vp9_set_alt_lf_level(cpi, cm->filter_level);
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd);
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, cm->filter_level, 0);
}
vp8_yv12_extend_frame_borders(cm->frame_to_show);
......
......@@ -268,7 +268,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
// Get baseline error score
vp9_set_alt_lf_level(cpi, filt_mid);
vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_mid);
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_mid, 1);
best_err = vp9_calc_ss_err(sd, cm->frame_to_show);
filt_best = filt_mid;
......@@ -293,7 +293,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
if ((filt_direction <= 0) && (filt_low != filt_mid)) {
// Get Low filter error score
vp9_set_alt_lf_level(cpi, filt_low);
vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_low);
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_low, 1);
filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
......@@ -313,7 +313,7 @@ void vp9_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi) {
// Now look at filt_high
if ((filt_direction >= 0) && (filt_high != filt_mid)) {
vp9_set_alt_lf_level(cpi, filt_high);
vp9_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_high);
vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_high, 1);
filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment