Commit 466ae062 authored by hui su's avatar hui su Committed by Hui Su

Palette: use CDF to encode palette size and color indices

Around 0.9% improvement on screen_content set (encoding 30 frames).

Change-Id: Ic4c9333c9af5993bc41e513b9e766450b3a951eb
parent 1b4ffc44
This diff is collapsed.
......@@ -234,7 +234,6 @@ typedef struct frame_contexts {
#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
aom_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
aom_prob comp_inter_prob[COMP_INTER_CONTEXTS];
#if CONFIG_NEW_MULTISYMBOL
#if CONFIG_PALETTE
aom_cdf_prob palette_y_size_cdf[PALETTE_BLOCK_SIZES][CDF_SIZE(PALETTE_SIZES)];
aom_cdf_prob palette_uv_size_cdf[PALETTE_BLOCK_SIZES]
......@@ -245,7 +244,8 @@ typedef struct frame_contexts {
aom_cdf_prob palette_uv_color_index_cdf[PALETTE_SIZES]
[PALETTE_COLOR_INDEX_CONTEXTS]
[CDF_SIZE(PALETTE_COLORS)];
#endif
#endif // CONFIG_PALETTE
#if CONFIG_NEW_MULTISYMBOL
aom_cdf_prob comp_inter_cdf[COMP_INTER_CONTEXTS][CDF_SIZE(2)];
aom_cdf_prob single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)];
#endif
......@@ -520,14 +520,6 @@ extern const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
[PALETTE_Y_MODE_CONTEXTS];
extern const aom_prob
av1_default_palette_uv_mode_prob[PALETTE_UV_MODE_CONTEXTS];
extern const aom_prob av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES]
[PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES]
[PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_y_color_index_prob
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
extern const aom_prob av1_default_palette_uv_color_index_prob
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
#endif // CONFIG_PALETTE
extern const int av1_intra_mode_ind[INTRA_MODES];
......@@ -560,7 +552,6 @@ extern const aom_tree_index
extern const aom_tree_index
av1_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
#if CONFIG_PALETTE
extern const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
extern const aom_tree_index
av1_palette_color_index_tree[PALETTE_SIZES][TREE_SIZE(PALETTE_COLORS)];
#endif // CONFIG_PALETTE
......
......@@ -812,17 +812,10 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
[palette_y_mode_ctx],
ACCT_STR)) {
pmi->palette_size[0] =
#if CONFIG_NEW_MULTISYMBOL
aom_read_symbol(r,
xd->tile_ctx->palette_y_size_cdf[bsize - BLOCK_8X8],
PALETTE_SIZES, ACCT_STR) +
2;
#else
aom_read_tree(r, av1_palette_size_tree,
av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
ACCT_STR) +
2;
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
read_palette_colors_y(xd, cm->bit_depth, pmi, r);
#else
......@@ -837,17 +830,10 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx],
ACCT_STR)) {
pmi->palette_size[1] =
#if CONFIG_NEW_MULTISYMBOL
aom_read_symbol(r,
xd->tile_ctx->palette_uv_size_cdf[bsize - BLOCK_8X8],
PALETTE_SIZES, ACCT_STR) +
2;
#else
aom_read_tree(r, av1_palette_size_tree,
av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
ACCT_STR) +
2;
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
read_palette_colors_uv(xd, cm->bit_depth, pmi, r);
#else
......
......@@ -226,18 +226,10 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
uint8_t color_order[PALETTE_MAX_SIZE];
const int n = mbmi->palette_mode_info.palette_size[plane];
uint8_t *const color_map = xd->plane[plane].color_index_map;
#if CONFIG_NEW_MULTISYMBOL
aom_cdf_prob(
*palette_cdf)[PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)] =
plane ? xd->tile_ctx->palette_uv_color_index_cdf
: xd->tile_ctx->palette_y_color_index_cdf;
#else
const aom_prob(
*const prob)[PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] =
plane ? av1_default_palette_uv_color_index_prob
: av1_default_palette_y_color_index_prob;
#endif
int plane_block_width, plane_block_height, rows, cols;
av1_get_block_dimensions(mbmi->sb_type, plane, xd, &plane_block_width,
&plane_block_height, &rows, &cols);
......@@ -253,14 +245,8 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
for (int j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) {
const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, (i - j), j, n, color_order, NULL);
#if CONFIG_NEW_MULTISYMBOL
const int color_idx = aom_read_symbol(
r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
#else
const int color_idx =
aom_read_tree(r, av1_palette_color_index_tree[n - 2],
prob[n - 2][color_ctx], ACCT_STR);
#endif
assert(color_idx >= 0 && color_idx < n);
color_map[(i - j) * plane_block_width + j] = color_order[color_idx];
}
......@@ -278,14 +264,8 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
for (int j = (i == 0 ? 1 : 0); j < cols; ++j) {
const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, i, j, n, color_order, NULL);
#if CONFIG_NEW_MULTISYMBOL
const int color_idx = aom_read_symbol(
r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
#else
const int color_idx =
aom_read_tree(r, av1_palette_color_index_tree[n - PALETTE_MIN_SIZE],
prob[n - PALETTE_MIN_SIZE][color_ctx], ACCT_STR);
#endif
assert(color_idx >= 0 && color_idx < n);
color_map[i * plane_block_width + j] = color_order[color_idx];
}
......
......@@ -66,11 +66,6 @@
static struct av1_token
inter_singleref_comp_mode_encodings[INTER_SINGLEREF_COMP_MODES];
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
#if CONFIG_PALETTE
static struct av1_token palette_size_encodings[PALETTE_SIZES];
static struct av1_token palette_color_index_encodings[PALETTE_SIZES]
[PALETTE_COLORS];
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE
static INLINE void write_uniform(aom_writer *w, int n, int v) {
......@@ -123,9 +118,9 @@ static int remux_tiles(const AV1_COMMON *const cm, uint8_t *dst,
int *const tile_col_size_bytes);
void av1_encode_token_init(void) {
#if CONFIG_EXT_TX || CONFIG_PALETTE
#if CONFIG_EXT_TX
int s;
#endif // CONFIG_EXT_TX || CONFIG_PALETTE
#endif // CONFIG_EXT_TX
#if CONFIG_EXT_TX
for (s = 1; s < EXT_TX_SETS_INTER; ++s) {
av1_tokens_from_tree(ext_tx_inter_encodings[s], av1_ext_tx_inter_tree[s]);
......@@ -137,14 +132,6 @@ void av1_encode_token_init(void) {
av1_tokens_from_tree(ext_tx_encodings, av1_ext_tx_tree);
#endif // CONFIG_EXT_TX
#if CONFIG_PALETTE
av1_tokens_from_tree(palette_size_encodings, av1_palette_size_tree);
for (s = 0; s < PALETTE_SIZES; ++s) {
av1_tokens_from_tree(palette_color_index_encodings[s],
av1_palette_color_index_tree[s]);
}
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
av1_tokens_from_tree(intra_filter_encodings, av1_intra_filter_tree);
#endif // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
......@@ -640,13 +627,7 @@ static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n,
++p;
--num;
for (int i = 0; i < num; ++i) {
#if CONFIG_NEW_MULTISYMBOL
aom_write_symbol(w, p->token, p->palette_cdf, n);
#else
av1_write_token(
w, av1_palette_color_index_tree[n - PALETTE_MIN_SIZE], p->context_tree,
&palette_color_index_encodings[n - PALETTE_MIN_SIZE][p->token]);
#endif
++p;
}
*tp = p;
......@@ -1497,15 +1478,9 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
w, n > 0,
av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_y_mode_ctx]);
if (n > 0) {
#if CONFIG_NEW_MULTISYMBOL
aom_write_symbol(w, n - PALETTE_MIN_SIZE,
xd->tile_ctx->palette_y_size_cdf[bsize - BLOCK_8X8],
PALETTE_SIZES);
#else
av1_write_token(w, av1_palette_size_tree,
av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - PALETTE_MIN_SIZE]);
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
write_palette_colors_y(xd, pmi, cm->bit_depth, w);
#else
......@@ -1522,15 +1497,9 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
aom_write(w, n > 0, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx]);
if (n > 0) {
#if CONFIG_NEW_MULTISYMBOL
aom_write_symbol(w, n - PALETTE_MIN_SIZE,
xd->tile_ctx->palette_uv_size_cdf[bsize - BLOCK_8X8],
PALETTE_SIZES);
#else
av1_write_token(w, av1_palette_size_tree,
av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - PALETTE_MIN_SIZE]);
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
write_palette_colors_uv(xd, pmi, cm->bit_depth, w);
#else
......
......@@ -84,20 +84,18 @@ static void fill_mode_costs(AV1_COMP *cpi) {
#if CONFIG_PALETTE
for (i = 0; i < PALETTE_BLOCK_SIZES; ++i) {
av1_cost_tokens(cpi->palette_y_size_cost[i],
av1_default_palette_y_size_prob[i], av1_palette_size_tree);
av1_cost_tokens(cpi->palette_uv_size_cost[i],
av1_default_palette_uv_size_prob[i], av1_palette_size_tree);
av1_cost_tokens_from_cdf(cpi->palette_y_size_cost[i],
fc->palette_y_size_cdf[i], NULL);
av1_cost_tokens_from_cdf(cpi->palette_uv_size_cost[i],
fc->palette_uv_size_cdf[i], NULL);
}
for (i = 0; i < PALETTE_SIZES; ++i) {
for (j = 0; j < PALETTE_COLOR_INDEX_CONTEXTS; ++j) {
av1_cost_tokens(cpi->palette_y_color_cost[i][j],
av1_default_palette_y_color_index_prob[i][j],
av1_palette_color_index_tree[i]);
av1_cost_tokens(cpi->palette_uv_color_cost[i][j],
av1_default_palette_uv_color_index_prob[i][j],
av1_palette_color_index_tree[i]);
av1_cost_tokens_from_cdf(cpi->palette_y_color_cost[i][j],
fc->palette_y_color_index_cdf[i][j], NULL);
av1_cost_tokens_from_cdf(cpi->palette_uv_color_cost[i][j],
fc->palette_uv_color_index_cdf[i][j], NULL);
}
}
#endif // CONFIG_PALETTE
......
......@@ -329,29 +329,17 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi,
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const uint8_t *const color_map = xd->plane[plane].color_index_map;
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
#if CONFIG_NEW_MULTISYMBOL
aom_cdf_prob(
*palette_cdf)[PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)] =
plane ? xd->tile_ctx->palette_uv_color_index_cdf
: xd->tile_ctx->palette_y_color_index_cdf;
#else
const aom_prob(
*const probs)[PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] =
plane == 0 ? av1_default_palette_y_color_index_prob
: av1_default_palette_uv_color_index_prob;
#endif
int plane_block_width, rows, cols;
av1_get_block_dimensions(bsize, plane, xd, &plane_block_width, NULL, &rows,
&cols);
// The first color index does not use context or entropy.
(*t)->token = color_map[0];
#if CONFIG_NEW_MULTISYMBOL
(*t)->palette_cdf = NULL;
#else
(*t)->context_tree = NULL;
#endif
(*t)->skip_eob_node = 0;
++(*t);
......@@ -376,11 +364,7 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi,
[color_new_idx];
}
(*t)->token = color_new_idx;
#if CONFIG_NEW_MULTISYMBOL
(*t)->palette_cdf = palette_cdf[n - PALETTE_MIN_SIZE][color_ctx];
#else
(*t)->context_tree = probs[n - PALETTE_MIN_SIZE][color_ctx];
#endif
(*t)->skip_eob_node = 0;
++(*t);
}
......
......@@ -37,9 +37,9 @@ typedef struct {
typedef struct {
aom_cdf_prob (*tail_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
aom_cdf_prob (*head_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
#if CONFIG_NEW_MULTISYMBOL && CONFIG_PALETTE
#if CONFIG_PALETTE
aom_cdf_prob *palette_cdf;
#endif
#endif // CONFIG_PALETTE
int eob_val;
int first_val;
const aom_prob *context_tree;
......
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