Commit db68555e authored by Hui Su's avatar Hui Su

Add av1_get_palette_mode_ctx()

Change-Id: I6cd366d929d689217f292db07cbeaf1fd35c2055
parent cdef3b38
......@@ -188,6 +188,15 @@ static INLINE int av1_get_palette_bsize_ctx(BLOCK_SIZE bsize) {
return num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_4X4];
}
static INLINE int av1_get_palette_mode_ctx(const MACROBLOCKD *xd) {
const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi;
int ctx = 0;
if (above_mi) ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi) ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
return ctx;
}
int av1_get_intra_inter_context(const MACROBLOCKD *xd);
int av1_get_reference_mode_context(const AV1_COMMON *cm, const MACROBLOCKD *xd);
......
......@@ -786,27 +786,16 @@ static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
int mi_row, int mi_col, aom_reader *r) {
MODE_INFO *const mi = xd->mi[0];
MB_MODE_INFO *const mbmi = &mi->mbmi;
const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi;
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const BLOCK_SIZE bsize = mbmi->sb_type;
assert(av1_allow_palette(cm->allow_screen_content_tools, bsize));
PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
const int bsize_ctx = av1_get_palette_bsize_ctx(bsize);
if (mbmi->mode == DC_PRED) {
int palette_y_mode_ctx = 0;
if (above_mi) {
palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
if (left_mi) {
palette_y_mode_ctx +=
(left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
const int palette_mode_ctx = av1_get_palette_mode_ctx(xd);
const int modev = aom_read_symbol(
r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx][palette_y_mode_ctx], 2,
r, xd->tile_ctx->palette_y_mode_cdf[bsize_ctx][palette_mode_ctx], 2,
ACCT_STR);
if (modev) {
pmi->palette_size[0] =
......
......@@ -977,8 +977,6 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const MODE_INFO *const mi, int mi_row,
int mi_col, aom_writer *w) {
const MB_MODE_INFO *const mbmi = &mi->mbmi;
const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi;
const BLOCK_SIZE bsize = mbmi->sb_type;
assert(av1_allow_palette(cm->allow_screen_content_tools, bsize));
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
......@@ -986,15 +984,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
if (mbmi->mode == DC_PRED) {
const int n = pmi->palette_size[0];
int palette_y_mode_ctx = 0;
if (above_mi) {
palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
if (left_mi) {
palette_y_mode_ctx +=
(left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
const int palette_y_mode_ctx = av1_get_palette_mode_ctx(xd);
aom_write_symbol(
w, n > 0,
xd->tile_ctx->palette_y_mode_cdf[bsize_ctx][palette_y_mode_ctx], 2);
......
......@@ -881,24 +881,15 @@ static void sum_intra_stats(FRAME_COUNTS *counts, MACROBLOCKD *xd,
static void update_palette_cdf(MACROBLOCKD *xd, const MODE_INFO *mi) {
FRAME_CONTEXT *fc = xd->tile_ctx;
const MB_MODE_INFO *const mbmi = &mi->mbmi;
const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi;
const BLOCK_SIZE bsize = mbmi->sb_type;
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
const int bsize_ctx = av1_get_palette_bsize_ctx(bsize);
if (mbmi->mode == DC_PRED) {
const int n = pmi->palette_size[0];
int palette_y_mode_ctx = 0;
if (above_mi) {
palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
if (left_mi) {
palette_y_mode_ctx +=
(left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
update_cdf(fc->palette_y_mode_cdf[bsize_ctx][palette_y_mode_ctx], n > 0, 2);
const int palette_mode_ctx = av1_get_palette_mode_ctx(xd);
const int palette_bsize_ctx = av1_get_palette_bsize_ctx(bsize);
update_cdf(fc->palette_y_mode_cdf[palette_bsize_ctx][palette_mode_ctx],
n > 0, 2);
}
if (mbmi->uv_mode == UV_DC_PRED) {
......
......@@ -2613,16 +2613,14 @@ static void optimize_palette_colors(uint16_t *color_cache, int n_cache,
// Given the base colors as specified in centroids[], calculate the RD cost
// of palette mode.
static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
MB_MODE_INFO *mbmi, BLOCK_SIZE bsize, int palette_ctx,
int dc_mode_cost, const int *data, int *centroids,
int n, uint16_t *color_cache, int n_cache,
MB_MODE_INFO *best_mbmi,
uint8_t *best_palette_color_map, int64_t *best_rd,
int64_t *best_model_rd, int *rate, int *rate_tokenonly,
int *rate_overhead, int64_t *distortion,
int *skippable, PICK_MODE_CONTEXT *ctx,
uint8_t *blk_skip) {
static void palette_rd_y(
const AV1_COMP *const cpi, MACROBLOCK *x, MB_MODE_INFO *mbmi,
BLOCK_SIZE bsize, int palette_mode_ctx, int dc_mode_cost, const int *data,
int *centroids, int n, uint16_t *color_cache, int n_cache,
MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map, int64_t *best_rd,
int64_t *best_model_rd, int *rate, int *rate_tokenonly, int *rate_overhead,
int64_t *distortion, int *skippable, PICK_MODE_CONTEXT *ctx,
uint8_t *blk_skip) {
optimize_palette_colors(color_cache, n_cache, n, 1, centroids);
int k = av1_remove_duplicates(centroids, n);
if (k < PALETTE_MIN_SIZE) {
......@@ -2650,7 +2648,7 @@ static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
int palette_mode_cost =
dc_mode_cost + x->palette_y_size_cost[bsize_ctx][k - PALETTE_MIN_SIZE] +
write_uniform_cost(k, color_map[0]) +
x->palette_y_mode_cost[bsize_ctx][palette_ctx][1];
x->palette_y_mode_cost[bsize_ctx][palette_mode_ctx][1];
palette_mode_cost += av1_palette_color_cost_y(pmi, color_cache, n_cache,
cpi->common.bit_depth);
palette_mode_cost +=
......@@ -2684,11 +2682,11 @@ static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
}
static int rd_pick_palette_intra_sby(
const AV1_COMP *const cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int palette_ctx,
int dc_mode_cost, MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map,
int64_t *best_rd, int64_t *best_model_rd, int *rate, int *rate_tokenonly,
int64_t *distortion, int *skippable, PICK_MODE_CONTEXT *ctx,
uint8_t *best_blk_skip) {
const AV1_COMP *const cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
int palette_mode_ctx, int dc_mode_cost, MB_MODE_INFO *best_mbmi,
uint8_t *best_palette_color_map, int64_t *best_rd, int64_t *best_model_rd,
int *rate, int *rate_tokenonly, int64_t *distortion, int *skippable,
PICK_MODE_CONTEXT *ctx, uint8_t *best_blk_skip) {
int rate_overhead = 0;
MACROBLOCKD *const xd = &x->e_mbd;
MODE_INFO *const mic = xd->mi[0];
......@@ -2776,7 +2774,7 @@ static int rd_pick_palette_intra_sby(
// where the dominant colors and the k-means results are similar.
for (n = AOMMIN(colors, PALETTE_MAX_SIZE); n >= 2; --n) {
for (i = 0; i < n; ++i) centroids[i] = top_colors[i];
palette_rd_y(cpi, x, mbmi, bsize, palette_ctx, dc_mode_cost, data,
palette_rd_y(cpi, x, mbmi, bsize, palette_mode_ctx, dc_mode_cost, data,
centroids, n, color_cache, n_cache, best_mbmi,
best_palette_color_map, best_rd, best_model_rd, rate,
rate_tokenonly, &rate_overhead, distortion, skippable, ctx,
......@@ -2797,7 +2795,7 @@ static int rd_pick_palette_intra_sby(
}
av1_k_means(data, centroids, color_map, rows * cols, n, 1, max_itr);
}
palette_rd_y(cpi, x, mbmi, bsize, palette_ctx, dc_mode_cost, data,
palette_rd_y(cpi, x, mbmi, bsize, palette_mode_ctx, dc_mode_cost, data,
centroids, n, color_cache, n_cache, best_mbmi,
best_palette_color_map, best_rd, best_model_rd, rate,
rate_tokenonly, &rate_overhead, distortion, skippable, ctx,
......@@ -3287,9 +3285,11 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
#endif // CONFIG_FILTER_INTRA
const int *bmode_costs;
PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
int palette_y_mode_ctx = 0;
const int try_palette =
av1_allow_palette(cpi->common.allow_screen_content_tools, mbmi->sb_type);
const int palette_mode_ctx = try_palette ? av1_get_palette_mode_ctx(xd) : 0;
const int palette_bsize_ctx =
try_palette ? av1_get_palette_bsize_ctx(bsize) : 0;
uint8_t *best_palette_color_map =
try_palette ? x->palette_buffer->best_palette_color_map : NULL;
const MODE_INFO *above_mi = xd->above_mi;
......@@ -3318,16 +3318,6 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
mbmi->filter_intra_mode_info.use_filter_intra = 0;
#endif // CONFIG_FILTER_INTRA
pmi->palette_size[0] = 0;
if (try_palette) {
if (above_mi) {
palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
if (left_mi) {
palette_y_mode_ctx +=
(left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
}
if (cpi->sf.tx_type_search.fast_intra_tx_type_search)
x->use_default_intra_tx_type = 1;
......@@ -3380,8 +3370,8 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
tx_size_cost(&cpi->common, x, bsize, mbmi->tx_size);
}
if (try_palette && mbmi->mode == DC_PRED) {
const int bsize_ctx = av1_get_palette_bsize_ctx(bsize);
this_rate += x->palette_y_mode_cost[bsize_ctx][palette_y_mode_ctx][0];
this_rate +=
x->palette_y_mode_cost[palette_bsize_ctx][palette_mode_ctx][0];
}
#if CONFIG_FILTER_INTRA
if (mbmi->mode == DC_PRED && av1_filter_intra_allowed_txsize(mbmi->tx_size))
......@@ -3424,7 +3414,7 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
if (try_palette) {
rd_pick_palette_intra_sby(
cpi, x, bsize, palette_y_mode_ctx, bmode_costs[DC_PRED], &best_mbmi,
cpi, x, bsize, palette_mode_ctx, bmode_costs[DC_PRED], &best_mbmi,
best_palette_color_map, &best_rd, &best_model_rd, rate, rate_tokenonly,
distortion, skippable, ctx, ctx->blk_skip[0]);
}
......@@ -3444,7 +3434,7 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
if (x->use_default_intra_tx_type) {
*mbmi = best_mbmi;
x->use_default_intra_tx_type = 0;
intra_block_yrd(cpi, x, bsize, bmode_costs, palette_y_mode_ctx, &best_rd,
intra_block_yrd(cpi, x, bsize, bmode_costs, palette_mode_ctx, &best_rd,
rate, rate_tokenonly, distortion, skippable, &best_mbmi,
ctx);
}
......@@ -9064,6 +9054,9 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const int try_palette =
av1_allow_palette(cm->allow_screen_content_tools, mbmi->sb_type);
const int palette_mode_ctx = try_palette ? av1_get_palette_mode_ctx(xd) : 0;
const int palette_bsize_ctx =
try_palette ? av1_get_palette_bsize_ctx(bsize) : 0;
PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
MB_MODE_INFO_EXT *const mbmi_ext = x->mbmi_ext;
const struct segmentation *const seg = &cm->seg;
......@@ -9140,9 +9133,6 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
const int rows = block_size_high[bsize];
const int cols = block_size_wide[bsize];
int palette_ctx = 0;
const MODE_INFO *above_mi = xd->above_mi;
const MODE_INFO *left_mi = xd->left_mi;
int dst_width1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
int dst_width2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
int dst_height1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE };
......@@ -9176,14 +9166,7 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
}
av1_zero(best_mbmode);
av1_zero(pmi_uv);
if (try_palette) {
if (above_mi)
palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi)
palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
}
estimate_ref_frame_costs(cm, xd, x, segment_id, ref_costs_single,
ref_costs_comp);
......@@ -9781,10 +9764,8 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
x->intra_uv_mode_cost[mbmi->mode][mbmi->uv_mode];
#endif
if (try_palette && mbmi->mode == DC_PRED) {
const int bsize_ctx = av1_get_palette_bsize_ctx(bsize);
rate2 += x->palette_y_mode_cost[bsize_ctx][palette_ctx][0];
}
if (try_palette && mbmi->mode == DC_PRED)
rate2 += x->palette_y_mode_cost[palette_bsize_ctx][palette_mode_ctx][0];
if (!xd->lossless[mbmi->segment_id] && block_signals_txsize(bsize)) {
// super_block_yrd above includes the cost of the tx_size in the
......@@ -10359,7 +10340,7 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
mbmi->ref_frame[0] = INTRA_FRAME;
mbmi->ref_frame[1] = NONE_FRAME;
rate_overhead_palette = rd_pick_palette_intra_sby(
cpi, x, bsize, palette_ctx, intra_mode_cost[DC_PRED],
cpi, x, bsize, palette_mode_ctx, intra_mode_cost[DC_PRED],
&best_mbmi_palette, best_palette_color_map, &best_rd_palette,
&best_model_rd_palette, NULL, NULL, NULL, NULL, ctx, best_blk_skip);
......
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