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

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
......@@ -1421,29 +1421,7 @@ static const aom_prob default_comp_inter_mode_p[COMP_INTER_MODE_CONTEXTS] = {
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
#if CONFIG_PALETTE
// Tree to code palette size (number of colors in a palette) and the
// corresponding probabilities for Y and UV planes.
const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)] = {
-TWO_COLORS, 2, -THREE_COLORS, 4, -FOUR_COLORS, 6,
-FIVE_COLORS, 8, -SIX_COLORS, 10, -SEVEN_COLORS, -EIGHT_COLORS,
};
// TODO(huisu): tune these probs
const aom_prob
av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1] = {
{ 96, 89, 100, 64, 77, 130 }, { 22, 15, 44, 16, 34, 82 },
{ 30, 19, 57, 18, 38, 86 }, { 94, 36, 104, 23, 43, 92 },
{ 116, 76, 107, 46, 65, 105 }, { 112, 82, 94, 40, 70, 112 },
{ 147, 124, 123, 58, 69, 103 }, { 180, 113, 136, 49, 45, 114 },
{ 107, 70, 87, 49, 154, 156 }, { 98, 105, 142, 63, 64, 152 },
#if CONFIG_EXT_PARTITION
{ 98, 105, 142, 63, 64, 152 }, { 98, 105, 142, 63, 64, 152 },
{ 98, 105, 142, 63, 64, 152 },
#endif // CONFIG_EXT_PARTITION
};
#if CONFIG_NEW_MULTISYMBOL
// TODO(huisu): tune these cdfs
const aom_cdf_prob
default_palette_y_size_cdf[PALETTE_BLOCK_SIZES][CDF_SIZE(PALETTE_SIZES)] = {
{ AOM_ICDF(12288), AOM_ICDF(19408), AOM_ICDF(24627), AOM_ICDF(26662),
......@@ -1475,22 +1453,7 @@ const aom_cdf_prob
AOM_ICDF(29763), AOM_ICDF(31546), AOM_ICDF(32768), 0 },
#endif
};
#endif // CONFIG_NEW_MULTISYMBOL
const aom_prob
av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1] = {
{ 160, 196, 228, 213, 175, 230 }, { 87, 148, 208, 141, 166, 163 },
{ 72, 151, 204, 139, 155, 161 }, { 78, 135, 171, 104, 120, 173 },
{ 59, 92, 131, 78, 92, 142 }, { 75, 118, 149, 84, 90, 128 },
{ 89, 87, 92, 66, 66, 128 }, { 67, 53, 54, 55, 66, 93 },
{ 120, 130, 83, 171, 75, 214 }, { 72, 55, 66, 68, 79, 107 },
#if CONFIG_EXT_PARTITION
{ 72, 55, 66, 68, 79, 107 }, { 72, 55, 66, 68, 79, 107 },
{ 72, 55, 66, 68, 79, 107 },
#endif // CONFIG_EXT_PARTITION
};
#if CONFIG_NEW_MULTISYMBOL
const aom_cdf_prob default_palette_uv_size_cdf[PALETTE_BLOCK_SIZES][CDF_SIZE(
PALETTE_SIZES)] = {
{ AOM_ICDF(20480), AOM_ICDF(29888), AOM_ICDF(32453), AOM_ICDF(32715),
......@@ -1522,7 +1485,6 @@ const aom_cdf_prob default_palette_uv_size_cdf[PALETTE_BLOCK_SIZES][CDF_SIZE(
AOM_ICDF(25799), AOM_ICDF(28712), AOM_ICDF(32768), 0 },
#endif
};
#endif // CONFIG_NEW_MULTISYMBOL
// When palette mode is enabled, following probability tables indicate the
// probabilities to code the "is_palette" bit (i.e. the bit that indicates
......@@ -1542,107 +1504,6 @@ const aom_prob av1_default_palette_uv_mode_prob[PALETTE_UV_MODE_CONTEXTS] = {
253, 229
};
// Trees to code palette color indices (for various palette sizes), and the
// corresponding probability tables for Y and UV planes.
const aom_tree_index
av1_palette_color_index_tree[PALETTE_SIZES][TREE_SIZE(PALETTE_COLORS)] = {
{ // 2 colors
-PALETTE_COLOR_ONE, -PALETTE_COLOR_TWO },
{ // 3 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, -PALETTE_COLOR_THREE },
{ // 4 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE,
-PALETTE_COLOR_FOUR },
{ // 5 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, -PALETTE_COLOR_FIVE },
{ // 6 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, -PALETTE_COLOR_SIX },
{ // 7 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, 10, -PALETTE_COLOR_SIX,
-PALETTE_COLOR_SEVEN },
{ // 8 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, 10, -PALETTE_COLOR_SIX, 12,
-PALETTE_COLOR_SEVEN, -PALETTE_COLOR_EIGHT },
};
// Note: Has to be non-zero to avoid any asserts triggering.
#define UNUSED_PROB 128
const aom_prob av1_default_palette_y_color_index_prob
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = {
{
// 2 colors
{ 231, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ 69, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 224, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ 249, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
},
{
// 3 colors
{ 219, 124, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 91, 191, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 34, 237, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 184, 118, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 252, 124, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
},
{
// 4 colors
{ 204, 87, 97, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 74, 144, 129, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 52, 191, 134, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 151, 85, 147, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 248, 60, 115, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
},
{
// 5 colors
{ 218, 69, 62, 106, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 76, 143, 89, 127, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 21, 233, 94, 131, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 172, 72, 89, 112, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 253, 66, 65, 128, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
},
{
// 6 colors
{ 190, 60, 47, 54, 74, UNUSED_PROB, UNUSED_PROB },
{ 62, 106, 51, 95, 110, UNUSED_PROB, UNUSED_PROB },
{ 52, 180, 69, 72, 107, UNUSED_PROB, UNUSED_PROB },
{ 156, 83, 72, 83, 101, UNUSED_PROB, UNUSED_PROB },
{ 245, 45, 37, 52, 91, UNUSED_PROB, UNUSED_PROB },
},
{
// 7 colors
{ 206, 56, 42, 42, 53, 85, UNUSED_PROB },
{ 70, 100, 45, 68, 77, 94, UNUSED_PROB },
{ 57, 169, 51, 62, 74, 119, UNUSED_PROB },
{ 172, 76, 71, 40, 59, 76, UNUSED_PROB },
{ 248, 47, 36, 53, 61, 110, UNUSED_PROB },
},
{
// 8 colors
{ 208, 52, 38, 34, 34, 44, 66 },
{ 52, 107, 34, 73, 69, 82, 87 },
{ 28, 208, 53, 43, 62, 70, 102 },
{ 184, 64, 45, 37, 37, 69, 105 },
{ 251, 18, 31, 45, 47, 61, 104 },
},
};
#if CONFIG_NEW_MULTISYMBOL
const aom_cdf_prob default_palette_y_color_index_cdf
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)] = {
{
......@@ -1730,79 +1591,7 @@ const aom_cdf_prob default_palette_y_color_index_cdf
0 },
},
};
#endif
const aom_prob av1_default_palette_uv_color_index_prob
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = {
{
// 2 colors
{ 233, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ 69, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 240, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
{ 248, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB, UNUSED_PROB },
},
{
// 3 colors
{ 216, 128, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 110, 171, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 40, 239, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 191, 104, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
{ 247, 134, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
UNUSED_PROB },
},
{
// 4 colors
{ 202, 89, 132, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 90, 132, 136, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 63, 195, 149, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 152, 84, 152, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 241, 87, 136, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
},
{
// 5 colors
{ 209, 54, 82, 134, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 94, 173, 180, 93, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 10, 251, 127, 84, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 183, 20, 150, 47, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
{ 252, 73, 111, 150, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB },
},
{
// 6 colors
{ 192, 67, 59, 46, 184, UNUSED_PROB, UNUSED_PROB },
{ 59, 92, 61, 100, 130, UNUSED_PROB, UNUSED_PROB },
{ 49, 162, 68, 91, 150, UNUSED_PROB, UNUSED_PROB },
{ 133, 29, 36, 153, 101, UNUSED_PROB, UNUSED_PROB },
{ 247, 71, 44, 90, 129, UNUSED_PROB, UNUSED_PROB },
},
{
// 7 colors
{ 182, 62, 80, 78, 46, 116, UNUSED_PROB },
{ 59, 62, 39, 81, 65, 99, UNUSED_PROB },
{ 54, 177, 48, 58, 93, 104, UNUSED_PROB },
{ 137, 79, 54, 55, 44, 134, UNUSED_PROB },
{ 239, 82, 79, 44, 69, 71, UNUSED_PROB },
},
{
// 8 colors
{ 172, 53, 27, 67, 30, 79, 113 },
{ 63, 57, 45, 81, 62, 35, 47 },
{ 51, 200, 36, 47, 82, 165, 129 },
{ 141, 100, 47, 29, 33, 37, 129 },
{ 236, 42, 50, 91, 24, 154, 65 },
},
};
#if CONFIG_NEW_MULTISYMBOL
const aom_cdf_prob default_palette_uv_color_index_cdf
[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)] = {
{
......@@ -1890,8 +1679,6 @@ const aom_cdf_prob default_palette_uv_color_index_cdf
0 },
}
};
#endif // CONFIG_NEW_MULTISYMBOL
#undef UNUSED_PROB
#define MAX_COLOR_CONTEXT_HASH 8
// Negative values are invalid
......@@ -5122,14 +4909,14 @@ static void init_mode_probs(FRAME_CONTEXT *fc) {
av1_copy(fc->partition_prob, default_partition_probs);
av1_copy(fc->intra_inter_prob, default_intra_inter_p);
av1_copy(fc->comp_inter_prob, default_comp_inter_p);
#if CONFIG_NEW_MULTISYMBOL
av1_copy(fc->comp_inter_cdf, default_comp_inter_cdf);
#if CONFIG_PALETTE
av1_copy(fc->palette_y_size_cdf, default_palette_y_size_cdf);
av1_copy(fc->palette_uv_size_cdf, default_palette_uv_size_cdf);
av1_copy(fc->palette_y_color_index_cdf, default_palette_y_color_index_cdf);
av1_copy(fc->palette_uv_color_index_cdf, default_palette_uv_color_index_cdf);
#endif
#endif // CONFIG_PALETTE
#if CONFIG_NEW_MULTISYMBOL
av1_copy(fc->comp_inter_cdf, default_comp_inter_cdf);
#endif // CONFIG_NEW_MULTISYMBOL
#if CONFIG_EXT_COMP_REFS
av1_copy(fc->comp_ref_type_prob, default_comp_ref_type_p);
......
......@@ -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