Commit 76224b0e authored by Cheng Chen's avatar Cheng Chen

LPF_SB: cleanup unused functions and code path

Since we've decided to use guess filter levels for lpf_sb, I remove
unused searching functions and coding paths to make codebase clean
and easy to manage.

Change-Id: I3497add59fc1eaf36acdd0acb85e3bcb6486d01d
parent c683bf9b
......@@ -1746,11 +1746,6 @@ void av1_average_tile_intra_cdfs(FRAME_CONTEXT *fc, FRAME_CONTEXT *ec_ctxs[],
#if CONFIG_EXT_INTRA_MOD
AVERAGE_TILE_CDFS(angle_delta_cdf)
#endif // CONFIG_EXT_INTRA_MOD
#if CONFIG_LPF_SB
AVERAGE_TILE_CDFS(lpf_reuse_cdf);
AVERAGE_TILE_CDFS(lpf_delta_cdf);
AVERAGE_TILE_CDFS(lpf_sign_cdf);
#endif // CONFIG_LPF_SB
#if CONFIG_SPATIAL_SEGMENTATION
int j;
for (j = 0; j < SPATIAL_PREDICTION_PROBS; j++) {
......@@ -1804,11 +1799,6 @@ void av1_average_tile_inter_cdfs(AV1_COMMON *cm, FRAME_CONTEXT *fc,
AVERAGE_TILE_CDFS(intra_inter_cdf)
AVERAGE_TILE_CDFS(motion_mode_cdf)
AVERAGE_TILE_CDFS(obmc_cdf)
#if CONFIG_LPF_SB
AVERAGE_TILE_CDFS(lpf_reuse_cdf);
AVERAGE_TILE_CDFS(lpf_delta_cdf);
AVERAGE_TILE_CDFS(lpf_sign_cdf);
#endif // CONFIG_LPF_SB
#if CONFIG_JNT_COMP
AVERAGE_TILE_CDFS(compound_index_cdf);
#endif // CONFIG_JNT_COMP
......
......@@ -2816,86 +2816,6 @@ const aom_cdf_prob
};
#endif // CONFIG_KF_CTX
#if CONFIG_LPF_SB
#if CONFIG_LOOPFILTER_LEVEL
static const aom_cdf_prob
default_lpf_reuse_cdf[4][LPF_REUSE_CONTEXT][CDF_SIZE(2)] = {
{ { AOM_CDF2(4259) }, { AOM_CDF2(728) } },
{ { AOM_CDF2(4259) }, { AOM_CDF2(728) } },
{ { AOM_CDF2(4259) }, { AOM_CDF2(728) } },
{ { AOM_CDF2(4259) }, { AOM_CDF2(728) } },
};
static const aom_cdf_prob
default_lpf_delta_cdf[4][LPF_DELTA_CONTEXT][CDF_SIZE(DELTA_RANGE)] = {
{ { AOM_CDF8(100, 688, 2128, 4642, 7895, 11851, 17050) },
{ AOM_CDF8(100, 1291, 4358, 7425, 10654, 13559, 18563) },
{ AOM_CDF8(100, 1086, 4982, 9134, 13031, 16991, 23123) },
{ AOM_CDF8(100, 1068, 3395, 7973, 12512, 17967, 22812) },
{ AOM_CDF8(100, 442, 2809, 7178, 12535, 17450, 22417) },
{ AOM_CDF8(100, 561, 2246, 6050, 11103, 16592, 21353) },
{ AOM_CDF8(100, 345, 2399, 5559, 9682, 13992, 20126) },
{ AOM_CDF8(100, 337, 1540, 3573, 6438, 10196, 16320) } },
{ { AOM_CDF8(100, 688, 2128, 4642, 7895, 11851, 17050) },
{ AOM_CDF8(100, 1291, 4358, 7425, 10654, 13559, 18563) },
{ AOM_CDF8(100, 1086, 4982, 9134, 13031, 16991, 23123) },
{ AOM_CDF8(100, 1068, 3395, 7973, 12512, 17967, 22812) },
{ AOM_CDF8(100, 442, 2809, 7178, 12535, 17450, 22417) },
{ AOM_CDF8(100, 561, 2246, 6050, 11103, 16592, 21353) },
{ AOM_CDF8(100, 345, 2399, 5559, 9682, 13992, 20126) },
{ AOM_CDF8(100, 337, 1540, 3573, 6438, 10196, 16320) } },
{ { AOM_CDF8(100, 688, 2128, 4642, 7895, 11851, 17050) },
{ AOM_CDF8(100, 1291, 4358, 7425, 10654, 13559, 18563) },
{ AOM_CDF8(100, 1086, 4982, 9134, 13031, 16991, 23123) },
{ AOM_CDF8(100, 1068, 3395, 7973, 12512, 17967, 22812) },
{ AOM_CDF8(100, 442, 2809, 7178, 12535, 17450, 22417) },
{ AOM_CDF8(100, 561, 2246, 6050, 11103, 16592, 21353) },
{ AOM_CDF8(100, 345, 2399, 5559, 9682, 13992, 20126) },
{ AOM_CDF8(100, 337, 1540, 3573, 6438, 10196, 16320) } },
{ { AOM_CDF8(100, 688, 2128, 4642, 7895, 11851, 17050) },
{ AOM_CDF8(100, 1291, 4358, 7425, 10654, 13559, 18563) },
{ AOM_CDF8(100, 1086, 4982, 9134, 13031, 16991, 23123) },
{ AOM_CDF8(100, 1068, 3395, 7973, 12512, 17967, 22812) },
{ AOM_CDF8(100, 442, 2809, 7178, 12535, 17450, 22417) },
{ AOM_CDF8(100, 561, 2246, 6050, 11103, 16592, 21353) },
{ AOM_CDF8(100, 345, 2399, 5559, 9682, 13992, 20126) },
{ AOM_CDF8(100, 337, 1540, 3573, 6438, 10196, 16320) } },
};
static const aom_cdf_prob
default_lpf_sign_cdf[4][LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT][CDF_SIZE(2)] =
{
{ { { AOM_CDF2(100) }, { AOM_CDF2(11932) } },
{ { AOM_CDF2(14785) }, { AOM_CDF2(8145) } } },
{ { { AOM_CDF2(100) }, { AOM_CDF2(11932) } },
{ { AOM_CDF2(14785) }, { AOM_CDF2(8145) } } },
{ { { AOM_CDF2(100) }, { AOM_CDF2(11932) } },
{ { AOM_CDF2(14785) }, { AOM_CDF2(8145) } } },
{ { { AOM_CDF2(100) }, { AOM_CDF2(11932) } },
{ { AOM_CDF2(14785) }, { AOM_CDF2(8145) } } },
};
#else
static const aom_cdf_prob default_lpf_reuse_cdf[LPF_REUSE_CONTEXT][CDF_SIZE(
2)] = { { AOM_CDF2(4259) }, { AOM_CDF2(728) } };
static const aom_cdf_prob default_lpf_delta_cdf[LPF_DELTA_CONTEXT][CDF_SIZE(
DELTA_RANGE)] = { { AOM_CDF8(100, 688, 2128, 4642, 7895, 11851, 17050) },
{ AOM_CDF8(100, 1291, 4358, 7425, 10654, 13559, 18563) },
{ AOM_CDF8(100, 1086, 4982, 9134, 13031, 16991, 23123) },
{ AOM_CDF8(100, 1068, 3395, 7973, 12512, 17967, 22812) },
{ AOM_CDF8(100, 442, 2809, 7178, 12535, 17450, 22417) },
{ AOM_CDF8(100, 561, 2246, 6050, 11103, 16592, 21353) },
{ AOM_CDF8(100, 345, 2399, 5559, 9682, 13992, 20126) },
{ AOM_CDF8(100, 337, 1540, 3573, 6438, 10196, 16320) } };
static const aom_cdf_prob
default_lpf_sign_cdf[LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT][CDF_SIZE(2)] = {
{ { AOM_CDF2(100) }, { AOM_CDF2(11932) } },
{ { AOM_CDF2(14785) }, { AOM_CDF2(8145) } }
};
#endif // CONFIG_LOOPFILTER_LEVEL
#endif // CONFIG_LPF_SB
#if CONFIG_EXT_INTRA_MOD
static const aom_cdf_prob default_angle_delta_cdf[DIRECTIONAL_MODES][CDF_SIZE(
2 * MAX_ANGLE_DELTA + 1)] = {
......@@ -3011,11 +2931,6 @@ static void init_mode_probs(FRAME_CONTEXT *fc) {
#if CONFIG_INTRABC
av1_copy(fc->intrabc_cdf, default_intrabc_cdf);
#endif
#if CONFIG_LPF_SB
av1_copy(fc->lpf_reuse_cdf, default_lpf_reuse_cdf);
av1_copy(fc->lpf_delta_cdf, default_lpf_delta_cdf);
av1_copy(fc->lpf_sign_cdf, default_lpf_sign_cdf);
#endif // CONFIG_LPF_SB
}
void av1_adapt_inter_frame_probs(AV1_COMMON *cm) {
......
......@@ -318,18 +318,6 @@ typedef struct frame_contexts {
aom_cdf_prob cfl_sign_cdf[CDF_SIZE(CFL_JOINT_SIGNS)];
aom_cdf_prob cfl_alpha_cdf[CFL_ALPHA_CONTEXTS][CDF_SIZE(CFL_ALPHABET_SIZE)];
#endif
#if CONFIG_LPF_SB
#if CONFIG_LOOPFILTER_LEVEL
aom_cdf_prob lpf_reuse_cdf[4][LPF_REUSE_CONTEXT][CDF_SIZE(2)];
aom_cdf_prob lpf_delta_cdf[4][LPF_DELTA_CONTEXT][CDF_SIZE(DELTA_RANGE)];
aom_cdf_prob lpf_sign_cdf[4][LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT]
[CDF_SIZE(2)];
#else
aom_cdf_prob lpf_reuse_cdf[LPF_REUSE_CONTEXT][CDF_SIZE(2)];
aom_cdf_prob lpf_delta_cdf[LPF_DELTA_CONTEXT][CDF_SIZE(DELTA_RANGE)];
aom_cdf_prob lpf_sign_cdf[LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT][CDF_SIZE(2)];
#endif
#endif // CONFIG_LPF_SB
} FRAME_CONTEXT;
typedef struct FRAME_COUNTS {
......@@ -435,17 +423,6 @@ typedef struct FRAME_COUNTS {
unsigned int filter_intra_mode_ctx[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS]
[FILTER_INTRA_MODES];
#endif // CONFIG_FILTER_INTRA
#if CONFIG_LPF_SB
#if CONFIG_LOOPFILTER_LEVEL
unsigned int lpf_reuse[4][LPF_REUSE_CONTEXT][2];
unsigned int lpf_delta[4][LPF_DELTA_CONTEXT][DELTA_RANGE];
unsigned int lpf_sign[4][LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT][2];
#else
unsigned int lpf_reuse[LPF_REUSE_CONTEXT][2];
unsigned int lpf_delta[LPF_DELTA_CONTEXT][DELTA_RANGE];
unsigned int lpf_sign[LPF_REUSE_CONTEXT][LPF_SIGN_CONTEXT][2];
#endif // CONFIG_LOOPFILTER_LEVEL
#endif // CONFIG_LPF_SB
} FRAME_COUNTS;
#if CONFIG_KF_CTX
......
......@@ -93,21 +93,9 @@ extern "C" {
#endif // CONFIG_LOOPFILTER_LEVEL
#if CONFIG_LPF_SB
#define LPF_DELTA_BITS 3
#define LPF_STEP 2
#define DELTA_RANGE (1 << LPF_DELTA_BITS)
#define MAX_LPF_OFFSET (LPF_STEP * ((1 << LPF_DELTA_BITS) - 1))
#define LPF_REUSE_CONTEXT 2
#define LPF_DELTA_CONTEXT DELTA_RANGE
#define LPF_SIGN_CONTEXT 2
// Half of maximum loop filter length (15-tap)
#define FILT_BOUNDARY_OFFSET 0
#define FILT_BOUNDARY_MI_OFFSET (FILT_BOUNDARY_OFFSET >> MI_SIZE_LOG2)
#define USE_GUESS_LEVEL 1
#define USE_LOOP_FILTER_SUPERBLOCK 1
#endif // CONFIG_LPF_SB
#if CONFIG_JNT_COMP
......
......@@ -566,9 +566,6 @@ typedef struct AV1Common {
#if CONFIG_LV_MAP
LV_MAP_CTX_TABLE coeff_ctx_table;
#endif
#if CONFIG_LPF_SB
int final_lpf_encode;
#endif
#if CONFIG_ADAPT_SCAN
int use_adapt_scan;
#endif
......
......@@ -767,135 +767,6 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd,
update_partition_context(xd, mi_row, mi_col, subsize, bsize);
#endif // CONFIG_EXT_PARTITION_TYPES
#if CONFIG_LPF_SB
#if CONFIG_LOOPFILTER_LEVEL
if (bsize == cm->sb_size && !USE_GUESS_LEVEL) {
int lvl_idx;
int filt_lvl[4];
if (mi_row == 0 && mi_col == 0) {
filt_lvl[0] = aom_read_literal(r, 6, ACCT_STR);
filt_lvl[1] = aom_read_literal(r, 6, ACCT_STR);
if (filt_lvl[0] || filt_lvl[1]) {
filt_lvl[2] = aom_read_literal(r, 6, ACCT_STR);
filt_lvl[3] = aom_read_literal(r, 6, ACCT_STR);
}
for (lvl_idx = 0; lvl_idx < 4; ++lvl_idx) {
cm->mi_grid_visible[0]->mbmi.reuse_sb_lvl[lvl_idx] = 0;
cm->mi_grid_visible[0]->mbmi.delta[lvl_idx] = 0;
cm->mi_grid_visible[0]->mbmi.sign[lvl_idx] = 0;
}
} else {
int prev_mi_row, prev_mi_col;
if (mi_col - MAX_MIB_SIZE < 0) {
prev_mi_row = mi_row - MAX_MIB_SIZE;
prev_mi_col = mi_col;
} else {
prev_mi_row = mi_row;
prev_mi_col = mi_col - MAX_MIB_SIZE;
}
MB_MODE_INFO *curr_mbmi =
&cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi;
MB_MODE_INFO *prev_mbmi =
&cm->mi_grid_visible[prev_mi_row * cm->mi_stride + prev_mi_col]->mbmi;
for (lvl_idx = 0; lvl_idx < 4; ++lvl_idx) {
const uint8_t prev_lvl = prev_mbmi->filt_lvl[lvl_idx];
const int reuse_ctx = prev_mbmi->reuse_sb_lvl[lvl_idx];
const int reuse_prev_lvl = aom_read_symbol(
r, xd->tile_ctx->lpf_reuse_cdf[lvl_idx][reuse_ctx], 2, ACCT_STR);
curr_mbmi->reuse_sb_lvl[lvl_idx] = reuse_prev_lvl;
if (reuse_prev_lvl) {
filt_lvl[lvl_idx] = prev_lvl;
curr_mbmi->delta[lvl_idx] = 0;
curr_mbmi->sign[lvl_idx] = 0;
} else {
const int delta_ctx = prev_mbmi->delta[lvl_idx];
unsigned int delta = aom_read_symbol(
r, xd->tile_ctx->lpf_delta_cdf[lvl_idx][delta_ctx], DELTA_RANGE,
ACCT_STR);
curr_mbmi->delta[lvl_idx] = delta;
delta *= LPF_STEP;
if (delta) {
const int sign_ctx = prev_mbmi->sign[lvl_idx];
const int sign = aom_read_symbol(
r, xd->tile_ctx->lpf_sign_cdf[lvl_idx][reuse_ctx][sign_ctx], 2,
ACCT_STR);
curr_mbmi->sign[lvl_idx] = sign;
filt_lvl[lvl_idx] = sign ? prev_lvl + delta : prev_lvl - delta;
} else {
filt_lvl[lvl_idx] = prev_lvl;
curr_mbmi->sign[lvl_idx] = 0;
}
}
}
}
av1_loop_filter_sb_level_init(cm, mi_row, mi_col, 0, 0, filt_lvl[0]);
av1_loop_filter_sb_level_init(cm, mi_row, mi_col, 0, 1, filt_lvl[1]);
av1_loop_filter_sb_level_init(cm, mi_row, mi_col, 1, 0, filt_lvl[2]);
av1_loop_filter_sb_level_init(cm, mi_row, mi_col, 2, 0, filt_lvl[3]);
}
#else
if (bsize == cm->sb_size && !USE_GUESS_LEVEL) {
int filt_lvl;
if (mi_row == 0 && mi_col == 0) {
filt_lvl = aom_read_literal(r, 6, ACCT_STR);
cm->mi_grid_visible[0]->mbmi.reuse_sb_lvl = 0;
cm->mi_grid_visible[0]->mbmi.delta = 0;
cm->mi_grid_visible[0]->mbmi.sign = 0;
} else {
int prev_mi_row, prev_mi_col;
if (mi_col - MAX_MIB_SIZE < 0) {
prev_mi_row = mi_row - MAX_MIB_SIZE;
prev_mi_col = mi_col;
} else {
prev_mi_row = mi_row;
prev_mi_col = mi_col - MAX_MIB_SIZE;
}
MB_MODE_INFO *curr_mbmi =
&cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi;
MB_MODE_INFO *prev_mbmi =
&cm->mi_grid_visible[prev_mi_row * cm->mi_stride + prev_mi_col]->mbmi;
const uint8_t prev_lvl = prev_mbmi->filt_lvl;
const int reuse_ctx = prev_mbmi->reuse_sb_lvl;
const int reuse_prev_lvl = aom_read_symbol(
r, xd->tile_ctx->lpf_reuse_cdf[reuse_ctx], 2, ACCT_STR);
curr_mbmi->reuse_sb_lvl = reuse_prev_lvl;
if (reuse_prev_lvl) {
filt_lvl = prev_lvl;
curr_mbmi->delta = 0;
curr_mbmi->sign = 0;
} else {
const int delta_ctx = prev_mbmi->delta;
unsigned int delta = aom_read_symbol(
r, xd->tile_ctx->lpf_delta_cdf[delta_ctx], DELTA_RANGE, ACCT_STR);
curr_mbmi->delta = delta;
delta *= LPF_STEP;
if (delta) {
const int sign_ctx = prev_mbmi->sign;
const int sign = aom_read_symbol(
r, xd->tile_ctx->lpf_sign_cdf[reuse_ctx][sign_ctx], 2, ACCT_STR);
curr_mbmi->sign = sign;
filt_lvl = sign ? prev_lvl + delta : prev_lvl - delta;
} else {
filt_lvl = prev_lvl;
curr_mbmi->sign = 0;
}
}
}
av1_loop_filter_sb_level_init(cm, mi_row, mi_col, filt_lvl);
}
#endif // CONFIG_LOOPFILTER_LEVEL
#endif // CONFIG_LPF_SB
#if CONFIG_LOOP_RESTORATION
for (int plane = 0; plane < av1_num_planes(cm); ++plane) {
int rcol0, rcol1, rrow0, rrow1, tile_tl_idx;
......@@ -1171,26 +1042,16 @@ static void setup_loopfilter(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
#endif // CONFIG_INTRABC && !CONFIG_LPF_SB
struct loopfilter *lf = &cm->lf;
#if CONFIG_LOOPFILTER_LEVEL
#if CONFIG_LPF_SB
if (USE_GUESS_LEVEL) {
#endif // CONFIG_LPF_SB
lf->filter_level[0] = aom_rb_read_literal(rb, 6);
lf->filter_level[1] = aom_rb_read_literal(rb, 6);
if (av1_num_planes(cm) > 1) {
if (lf->filter_level[0] || lf->filter_level[1]) {
lf->filter_level_u = aom_rb_read_literal(rb, 6);
lf->filter_level_v = aom_rb_read_literal(rb, 6);
}
lf->filter_level[0] = aom_rb_read_literal(rb, 6);
lf->filter_level[1] = aom_rb_read_literal(rb, 6);
if (av1_num_planes(cm) > 1) {
if (lf->filter_level[0] || lf->filter_level[1]) {
lf->filter_level_u = aom_rb_read_literal(rb, 6);
lf->filter_level_v = aom_rb_read_literal(rb, 6);
}
#if CONFIG_LPF_SB
}
#endif // CONFIG_LPF_SB
#else
#if CONFIG_LPF_SB
if (USE_GUESS_LEVEL) lf->filter_level = aom_rb_read_literal(rb, 6);
#else
lf->filter_level = aom_rb_read_literal(rb, 6);
#endif // CONFIG_LPF_SB
#endif
lf->sharpness_level = aom_rb_read_literal(rb, 3);
......@@ -2280,23 +2141,19 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
decode_partition(pbi, &td->xd, mi_row, mi_col, &td->bit_reader,
cm->sb_size);
#if CONFIG_LPF_SB
if (USE_LOOP_FILTER_SUPERBLOCK) {
if (cm->allow_screen_content_tools) {
#if CONFIG_LOOPFILTER_LEVEL
if (USE_GUESS_LEVEL) {
if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) {
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level[0],
cm->lf.filter_level[1], 0, 1, mi_row,
mi_col);
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level_u,
cm->lf.filter_level_u, 1, 1, mi_row,
mi_col);
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level_v,
cm->lf.filter_level_v, 2, 1, mi_row,
mi_col);
}
if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) {
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level[0],
cm->lf.filter_level[1], 0, 1, mi_row,
mi_col);
av1_loop_filter_frame(
get_frame_new_buffer(cm), cm, &pbi->mb, cm->lf.filter_level_u,
cm->lf.filter_level_u, 1, 1, mi_row, mi_col);
av1_loop_filter_frame(
get_frame_new_buffer(cm), cm, &pbi->mb, cm->lf.filter_level_v,
cm->lf.filter_level_v, 2, 1, mi_row, mi_col);
}
#else
// apply deblocking filtering right after each superblock is decoded
......
......@@ -2269,118 +2269,6 @@ static void write_modes_sb(AV1_COMP *const cpi, const TileInfo *const tile,
update_partition_context(xd, mi_row, mi_col, subsize, bsize);
#endif // CONFIG_EXT_PARTITION_TYPES
#if CONFIG_LPF_SB
// send filter level for each superblock (64x64)
if (bsize == cm->sb_size && !USE_GUESS_LEVEL) {
int lvl_idx;
if (mi_row == 0 && mi_col == 0) {
#if CONFIG_LOOPFILTER_LEVEL
aom_write_literal(w, cm->mi[0].mbmi.filt_lvl[0], 6);
aom_write_literal(w, cm->mi[0].mbmi.filt_lvl[1], 6);
if (cm->mi[0].mbmi.filt_lvl[0] || cm->mi[0].mbmi.filt_lvl[1]) {
aom_write_literal(w, cm->mi[0].mbmi.filt_lvl[2], 6);
aom_write_literal(w, cm->mi[0].mbmi.filt_lvl[3], 6);
}
for (lvl_idx = 0; lvl_idx < 4; ++lvl_idx) {
cm->mi_grid_visible[0]->mbmi.reuse_sb_lvl[lvl_idx] = 0;
cm->mi_grid_visible[0]->mbmi.delta[lvl_idx] = 0;
cm->mi_grid_visible[0]->mbmi.sign[lvl_idx] = 0;
}
#else
aom_write_literal(w, cm->mi[0].mbmi.filt_lvl, 6);
cm->mi_grid_visible[0]->mbmi.reuse_sb_lvl = 0;
cm->mi_grid_visible[0]->mbmi.delta = 0;
cm->mi_grid_visible[0]->mbmi.sign = 0;
#endif
} else {
int prev_mi_row, prev_mi_col;
if (mi_col - MAX_MIB_SIZE < 0) {
prev_mi_row = mi_row - MAX_MIB_SIZE;
prev_mi_col = mi_col;
} else {
prev_mi_row = mi_row;
prev_mi_col = mi_col - MAX_MIB_SIZE;
}
MB_MODE_INFO *curr_mbmi =
&cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi;
MB_MODE_INFO *prev_mbmi =
&cm->mi_grid_visible[prev_mi_row * cm->mi_stride + prev_mi_col]->mbmi;
#if CONFIG_LOOPFILTER_LEVEL
for (lvl_idx = 0; lvl_idx < 4; ++lvl_idx) {
const uint8_t curr_lvl = curr_mbmi->filt_lvl[lvl_idx];
const uint8_t prev_lvl = prev_mbmi->filt_lvl[lvl_idx];
const int reuse_prev_lvl = curr_lvl == prev_lvl;
const int reuse_ctx = prev_mbmi->reuse_sb_lvl[lvl_idx];
curr_mbmi->reuse_sb_lvl[lvl_idx] = reuse_prev_lvl;
aom_write_symbol(w, reuse_prev_lvl,
xd->tile_ctx->lpf_reuse_cdf[lvl_idx][reuse_ctx], 2);
cpi->td.counts->lpf_reuse[lvl_idx][reuse_ctx][reuse_prev_lvl]++;
if (reuse_prev_lvl) {
curr_mbmi->delta[lvl_idx] = 0;
curr_mbmi->sign[lvl_idx] = 0;
} else {
const unsigned int delta = abs(curr_lvl - prev_lvl) / LPF_STEP;
const int delta_ctx = prev_mbmi->delta[lvl_idx];
curr_mbmi->delta[lvl_idx] = delta;
aom_write_symbol(w, delta,
xd->tile_ctx->lpf_delta_cdf[lvl_idx][delta_ctx],
DELTA_RANGE);
cpi->td.counts->lpf_delta[lvl_idx][delta_ctx][delta]++;
if (delta) {
const int sign = curr_lvl > prev_lvl;
const int sign_ctx = prev_mbmi->sign[lvl_idx];
curr_mbmi->sign[lvl_idx] = sign;
aom_write_symbol(
w, sign,
xd->tile_ctx->lpf_sign_cdf[lvl_idx][reuse_ctx][sign_ctx], 2);
cpi->td.counts->lpf_sign[lvl_idx][reuse_ctx][sign_ctx][sign]++;
} else {
curr_mbmi->sign[lvl_idx] = 0;
}
}
}
#else
const uint8_t curr_lvl = curr_mbmi->filt_lvl;
const uint8_t prev_lvl = prev_mbmi->filt_lvl;
const int reuse_prev_lvl = curr_lvl == prev_lvl;
const int reuse_ctx = prev_mbmi->reuse_sb_lvl;
curr_mbmi->reuse_sb_lvl = reuse_prev_lvl;
aom_write_symbol(w, reuse_prev_lvl,
xd->tile_ctx->lpf_reuse_cdf[reuse_ctx], 2);
cpi->td.counts->lpf_reuse[reuse_ctx][reuse_prev_lvl]++;
if (reuse_prev_lvl) {
curr_mbmi->delta = 0;
curr_mbmi->sign = 0;
} else {
const unsigned int delta = abs(curr_lvl - prev_lvl) / LPF_STEP;
const int delta_ctx = prev_mbmi->delta;
curr_mbmi->delta = delta;
aom_write_symbol(w, delta, xd->tile_ctx->lpf_delta_cdf[delta_ctx],
DELTA_RANGE);
cpi->td.counts->lpf_delta[delta_ctx][delta]++;
if (delta) {
const int sign = curr_lvl > prev_lvl;
const int sign_ctx = prev_mbmi->sign;
curr_mbmi->sign = sign;
aom_write_symbol(w, sign,
xd->tile_ctx->lpf_sign_cdf[reuse_ctx][sign_ctx], 2);
cpi->td.counts->lpf_sign[reuse_ctx][sign_ctx][sign]++;
} else {
curr_mbmi->sign = 0;
}
}
#endif // CONFIG_LOOPFILTER_LEVEL
}
}
#endif
#if CONFIG_LOOP_RESTORATION
for (int plane = 0; plane < av1_num_planes(cm); ++plane) {
int rcol0, rcol1, rrow0, rrow1, tile_tl_idx;
......@@ -2614,26 +2502,16 @@ static void encode_loopfilter(AV1_COMMON *cm, struct aom_write_bit_buffer *wb) {
// Encode the loop filter level and type
#if CONFIG_LOOPFILTER_LEVEL
#if CONFIG_LPF_SB
if (USE_GUESS_LEVEL) {
#endif // CONFIG_LPF_SB
aom_wb_write_literal(wb, lf->filter_level[0], 6);
aom_wb_write_literal(wb, lf->filter_level[1], 6);
if (av1_num_planes(cm) > 1) {
if (lf->filter_level[0] || lf->filter_level[1]) {
aom_wb_write_literal(wb, lf->filter_level_u, 6);
aom_wb_write_literal(wb, lf->filter_level_v, 6);
}
aom_wb_write_literal(wb, lf->filter_level[0], 6);
aom_wb_write_literal(wb, lf->filter_level[1], 6);
if (av1_num_planes(cm) > 1) {
if (lf->filter_level[0] || lf->filter_level[1]) {
aom_wb_write_literal(wb, lf->filter_level_u, 6);
aom_wb_write_literal(wb, lf->filter_level_v, 6);
}
#if CONFIG_LPF_SB
}
#endif // CONFIG_LPF_SB
#else
#if CONFIG_LPF_SB
if (USE_GUESS_LEVEL) aom_wb_write_literal(wb, lf->filter_level, 6);
#else
aom_wb_write_literal(wb, lf->filter_level, 6);
#endif // CONFIG_LPF_SB
#endif // CONFIG_LOOPFILTER_LEVEL
aom_wb_write_literal(wb, lf->sharpness_level, 3);
......
......@@ -3223,46 +3223,28 @@ static void encode_rd_sb_row(AV1_COMP *cpi, ThreadData *td,
&dummy_rdc, INT64_MAX, pc_root, NULL);
}
#if CONFIG_LPF_SB
if (USE_LOOP_FILTER_SUPERBLOCK) {
// TODO(chengchen): change to allow intraBC. It requires to store the
// unfiltered frame to a buffer and process later.
if (cm->allow_screen_content_tools) {
#if CONFIG_LOOPFILTER_LEVEL
int filter_lvl[4];
if (USE_GUESS_LEVEL) {
struct loopfilter *lf = &cpi->common.lf;
filter_lvl[0] = lf->filter_level[0];
filter_lvl[1] = lf->filter_level[1];
filter_lvl[2] = lf->filter_level_u;
filter_lvl[3] = lf->filter_level_v;
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[0],
filter_lvl[1], 0, 1, mi_row, mi_col);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[2],
filter_lvl[2], 1, 1, mi_row, mi_col);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[3],
filter_lvl[3], 2, 1, mi_row, mi_col);
}
struct loopfilter *lf = &cpi->common.lf;
filter_lvl[0] = lf->filter_level[0];
filter_lvl[1] = lf->filter_level[1];
filter_lvl[2] = lf->filter_level_u;
filter_lvl[3] = lf->filter_level_v;
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[0],
filter_lvl[1], 0, 1, mi_row, mi_col);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[2],
filter_lvl[2], 1, 1, mi_row, mi_col);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, filter_lvl[3],
filter_lvl[3], 2, 1, mi_row, mi_col);
#else
int filter_lvl;
if (USE_GUESS_LEVEL) {
struct loopfilter *lf = &cpi->common.lf;
filter_lvl = lf->filter_level;
} else {
// apply deblocking filtering right after each superblock is encoded.
int last_lvl;
if (mi_row == 0 && mi_col == 0) {
last_lvl = 0;
} else {
if (mi_col == 0) {
last_lvl =
cm->mi[(mi_row - MAX_MIB_SIZE) * cm->mi_stride].mbmi.filt_lvl;
} else {
last_lvl = cm->mi[mi_row * cm->mi_stride + mi_col - MAX_MIB_SIZE]
.mbmi.filt_lvl;
}
}
filter_lvl = av1_search_filter_level(cpi->source, cpi, 1, NULL, mi_row,
mi_col, last_lvl);
}
struct loopfilter *lf = &cpi->common.lf;
filter_lvl = lf->filter_level;
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, xd, filter_lvl, 0, 1,
mi_row, mi_col);
// if filter_lvl is 0, we still need to set mi info
......
......@@ -4617,7 +4617,7 @@ static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
#endif // CONFIG_EXT_TILE
) {
#if CONFIG_LPF_SB
if (!USE_LOOP_FILTER_SUPERBLOCK) no_loopfilter = 1;
if (!cm->allow_screen_content_tools) no_loopfilter = 1;
#else
no_loopfilter = 1;
#endif // CONFIG_LPF_SB
......
......@@ -27,73 +27,6 @@
#include "av1/encoder/encoder.h"
#include "av1/encoder/picklpf.h"
#if CONFIG_LPF_SB && !CONFIG_LOOPFILTER_LEVEL
#if CONFIG_HIGHBITDEPTH
static int compute_sb_y_sse_highbd(const YV12_BUFFER_CONFIG *src,
const YV12_BUFFER_CONFIG *frame,
AV1_COMMON *const cm, int mi_row,
int mi_col) {
int sse = 0;
const int mi_row_start = AOMMAX(0, mi_row - FILT_BOUNDARY_MI_OFFSET);
const int mi_col_start = AOMMAX(0, mi_col - FILT_BOUNDARY_MI_OFFSET);
const int mi_row_range = mi_row - FILT_BOUNDARY_MI_OFFSET + MAX_MIB_SIZE;
const int mi_col_range = mi_col - FILT_BOUNDARY_MI_OFFSET + MAX_MIB_SIZE;
const int mi_row_end = AOMMIN(mi_row_range, cm->mi_rows);
const int mi_col_end = AOMMIN(mi_col_range, cm->mi_cols);
const int row = mi_row_start * MI_SIZE;
const int col = mi_col_start * MI_SIZE;
const uint16_t *src_y =
CONVERT_TO_SHORTPTR(src->y_buffer) + row * src->y_stride + col;