Commit 92109818 authored by Alex Converse's avatar Alex Converse
Browse files

palette: Use some enums / defines

Change-Id: If5d4f6d261276d9cfdd59fd7779467d92f56c395
parent e580092b
...@@ -833,8 +833,7 @@ const aom_prob av1_default_palette_uv_mode_prob[PALETTE_UV_MODE_CONTEXTS] = { ...@@ -833,8 +833,7 @@ const aom_prob av1_default_palette_uv_mode_prob[PALETTE_UV_MODE_CONTEXTS] = {
// Trees to code palette color indices (for various palette sizes), and the // Trees to code palette color indices (for various palette sizes), and the
// corresponding probability tables for Y and UV planes. // corresponding probability tables for Y and UV planes.
const aom_tree_index const aom_tree_index
av1_palette_color_index_tree[PALETTE_MAX_SIZE - av1_palette_color_index_tree[PALETTE_SIZES][TREE_SIZE(PALETTE_COLORS)] = {
1][TREE_SIZE(PALETTE_COLORS)] = {
{ // 2 colors { // 2 colors
-PALETTE_COLOR_ONE, -PALETTE_COLOR_TWO }, -PALETTE_COLOR_ONE, -PALETTE_COLOR_TWO },
{ // 3 colors { // 3 colors
...@@ -862,7 +861,7 @@ const aom_tree_index ...@@ -862,7 +861,7 @@ const aom_tree_index
#define UNUSED_PROB 128 #define UNUSED_PROB 128
const aom_prob av1_default_palette_y_color_index_prob const aom_prob av1_default_palette_y_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = { [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = {
{ {
// 2 colors // 2 colors
{ 231, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, { 231, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
...@@ -932,7 +931,7 @@ const aom_prob av1_default_palette_y_color_index_prob ...@@ -932,7 +931,7 @@ const aom_prob av1_default_palette_y_color_index_prob
}; };
const aom_prob av1_default_palette_uv_color_index_prob const aom_prob av1_default_palette_uv_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = { [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = {
{ {
// 2 colors // 2 colors
{ 233, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, { 233, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB, UNUSED_PROB,
......
...@@ -40,6 +40,8 @@ extern "C" { ...@@ -40,6 +40,8 @@ extern "C" {
// Maximum number of colors in a palette. // Maximum number of colors in a palette.
#define PALETTE_MAX_SIZE 8 #define PALETTE_MAX_SIZE 8
// Minimum number of colors in a palette.
#define PALETTE_MIN_SIZE 2
// Palette mode is available for block sizes >= 8x8. // Palette mode is available for block sizes >= 8x8.
#define PALETTE_BLOCK_SIZES (BLOCK_LARGEST - BLOCK_8X8 + 1) #define PALETTE_BLOCK_SIZES (BLOCK_LARGEST - BLOCK_8X8 + 1)
...@@ -390,9 +392,9 @@ extern const aom_prob av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES] ...@@ -390,9 +392,9 @@ extern const aom_prob av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES]
extern const aom_prob av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES] extern const aom_prob av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES]
[PALETTE_SIZES - 1]; [PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_y_color_index_prob extern const aom_prob av1_default_palette_y_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1]; [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
extern const aom_prob av1_default_palette_uv_color_index_prob extern const aom_prob av1_default_palette_uv_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1]; [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
extern const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)]; extern const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
...@@ -420,8 +422,7 @@ extern const aom_tree_index ...@@ -420,8 +422,7 @@ extern const aom_tree_index
#if CONFIG_PALETTE #if CONFIG_PALETTE
extern const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)]; extern const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
extern const aom_tree_index extern const aom_tree_index
av1_palette_color_index_tree[PALETTE_MAX_SIZE - 1] av1_palette_color_index_tree[PALETTE_SIZES][TREE_SIZE(PALETTE_COLORS)];
[TREE_SIZE(PALETTE_COLORS)];
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
extern const aom_tree_index av1_tx_size_tree[MAX_TX_DEPTH][TREE_SIZE(TX_SIZES)]; extern const aom_tree_index av1_tx_size_tree[MAX_TX_DEPTH][TREE_SIZE(TX_SIZES)];
#if CONFIG_EXT_INTRA #if CONFIG_EXT_INTRA
......
...@@ -466,8 +466,8 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, ...@@ -466,8 +466,8 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
const int color_ctx = av1_get_palette_color_index_context( const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, i, j, n, color_order, NULL); color_map, plane_block_width, i, j, n, color_order, NULL);
const int color_idx = const int color_idx =
aom_read_tree(r, av1_palette_color_index_tree[n - 2], aom_read_tree(r, av1_palette_color_index_tree[n - PALETTE_MIN_SIZE],
prob[n - 2][color_ctx], ACCT_STR); prob[n - PALETTE_MIN_SIZE][color_ctx], ACCT_STR);
assert(color_idx >= 0 && color_idx < n); assert(color_idx >= 0 && color_idx < n);
color_map[i * plane_block_width + j] = color_order[color_idx]; color_map[i * plane_block_width + j] = color_order[color_idx];
} }
......
...@@ -74,9 +74,9 @@ static const struct av1_token ...@@ -74,9 +74,9 @@ static const struct av1_token
}; };
#endif // CONFIG_EXT_INTER #endif // CONFIG_EXT_INTER
#if CONFIG_PALETTE #if CONFIG_PALETTE
static struct av1_token palette_size_encodings[PALETTE_MAX_SIZE - 1]; static struct av1_token palette_size_encodings[PALETTE_SIZES];
static struct av1_token palette_color_index_encodings[PALETTE_MAX_SIZE - 1] static struct av1_token palette_color_index_encodings[PALETTE_SIZES]
[PALETTE_MAX_SIZE]; [PALETTE_COLORS];
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
#if !CONFIG_EC_MULTISYMBOL #if !CONFIG_EC_MULTISYMBOL
static const struct av1_token tx_size_encodings[MAX_TX_DEPTH][TX_SIZES] = { static const struct av1_token tx_size_encodings[MAX_TX_DEPTH][TX_SIZES] = {
...@@ -159,7 +159,7 @@ void av1_encode_token_init(void) { ...@@ -159,7 +159,7 @@ void av1_encode_token_init(void) {
#if CONFIG_PALETTE #if CONFIG_PALETTE
av1_tokens_from_tree(palette_size_encodings, av1_palette_size_tree); av1_tokens_from_tree(palette_size_encodings, av1_palette_size_tree);
for (s = 0; s < PALETTE_MAX_SIZE - 1; ++s) { for (s = 0; s < PALETTE_SIZES; ++s) {
av1_tokens_from_tree(palette_color_index_encodings[s], av1_tokens_from_tree(palette_color_index_encodings[s],
av1_palette_color_index_tree[s]); av1_palette_color_index_tree[s]);
} }
...@@ -741,8 +741,9 @@ static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n, ...@@ -741,8 +741,9 @@ static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n,
const TOKENEXTRA *p = *tp; const TOKENEXTRA *p = *tp;
for (i = 0; i < num; ++i) { for (i = 0; i < num; ++i) {
av1_write_token(w, av1_palette_color_index_tree[n - 2], p->context_tree, av1_write_token(
&palette_color_index_encodings[n - 2][p->token]); w, av1_palette_color_index_tree[n - PALETTE_MIN_SIZE], p->context_tree,
&palette_color_index_encodings[n - PALETTE_MIN_SIZE][p->token]);
++p; ++p;
} }
...@@ -1246,7 +1247,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1246,7 +1247,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
if (n > 0) { if (n > 0) {
av1_write_token(w, av1_palette_size_tree, av1_write_token(w, av1_palette_size_tree,
av1_default_palette_y_size_prob[bsize - BLOCK_8X8], av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - 2]); &palette_size_encodings[n - PALETTE_MIN_SIZE]);
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
aom_write_literal(w, pmi->palette_colors[i], cm->bit_depth); aom_write_literal(w, pmi->palette_colors[i], cm->bit_depth);
write_uniform(w, n, pmi->palette_first_color_idx[0]); write_uniform(w, n, pmi->palette_first_color_idx[0]);
...@@ -1260,7 +1261,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1260,7 +1261,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
if (n > 0) { if (n > 0) {
av1_write_token(w, av1_palette_size_tree, av1_write_token(w, av1_palette_size_tree,
av1_default_palette_uv_size_prob[bsize - BLOCK_8X8], av1_default_palette_uv_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - 2]); &palette_size_encodings[n - PALETTE_MIN_SIZE]);
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
aom_write_literal(w, pmi->palette_colors[PALETTE_MAX_SIZE + i], aom_write_literal(w, pmi->palette_colors[PALETTE_MAX_SIZE + i],
cm->bit_depth); cm->bit_depth);
......
...@@ -577,9 +577,9 @@ typedef struct AV1_COMP { ...@@ -577,9 +577,9 @@ typedef struct AV1_COMP {
#if CONFIG_PALETTE #if CONFIG_PALETTE
int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
int palette_y_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS] int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
[PALETTE_COLORS]; [PALETTE_COLORS];
int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS] int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
[PALETTE_COLORS]; [PALETTE_COLORS];
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES]; int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
......
...@@ -101,7 +101,7 @@ static void fill_mode_costs(AV1_COMP *cpi) { ...@@ -101,7 +101,7 @@ static void fill_mode_costs(AV1_COMP *cpi) {
av1_default_palette_uv_size_prob[i], av1_palette_size_tree); av1_default_palette_uv_size_prob[i], av1_palette_size_tree);
} }
for (i = 0; i < PALETTE_MAX_SIZE - 1; ++i) { for (i = 0; i < PALETTE_SIZES; ++i) {
for (j = 0; j < PALETTE_COLOR_INDEX_CONTEXTS; ++j) { for (j = 0; j < PALETTE_COLOR_INDEX_CONTEXTS; ++j) {
av1_cost_tokens(cpi->palette_y_color_cost[i][j], av1_cost_tokens(cpi->palette_y_color_cost[i][j],
av1_default_palette_y_color_index_prob[i][j], av1_default_palette_y_color_index_prob[i][j],
......
...@@ -2442,7 +2442,7 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -2442,7 +2442,7 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
block_height); block_height);
palette_mode_cost = palette_mode_cost =
dc_mode_cost + cpi->common.bit_depth * k * av1_cost_bit(128, 0) + dc_mode_cost + cpi->common.bit_depth * k * av1_cost_bit(128, 0) +
cpi->palette_y_size_cost[bsize - BLOCK_8X8][k - 2] + cpi->palette_y_size_cost[bsize - BLOCK_8X8][k - PALETTE_MIN_SIZE] +
write_uniform_cost(k, color_map[0]) + write_uniform_cost(k, color_map[0]) +
av1_cost_bit( av1_cost_bit(
av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx],
...@@ -2453,8 +2453,8 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -2453,8 +2453,8 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
const int color_ctx = av1_get_palette_color_index_context( const int color_ctx = av1_get_palette_color_index_context(
color_map, block_width, i, j, k, color_order, &color_idx); color_map, block_width, i, j, k, color_order, &color_idx);
assert(color_idx >= 0 && color_idx < k); assert(color_idx >= 0 && color_idx < k);
palette_mode_cost += palette_mode_cost += cpi->palette_y_color_cost[k - PALETTE_MIN_SIZE]
cpi->palette_y_color_cost[k - 2][color_ctx][color_idx]; [color_ctx][color_idx];
} }
} }
this_model_rd = intra_model_yrd(cpi, x, bsize, palette_mode_cost); this_model_rd = intra_model_yrd(cpi, x, bsize, palette_mode_cost);
...@@ -4543,7 +4543,7 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -4543,7 +4543,7 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
this_rate = this_rate =
tokenonly_rd_stats.rate + dc_mode_cost + tokenonly_rd_stats.rate + dc_mode_cost +
2 * cpi->common.bit_depth * n * av1_cost_bit(128, 0) + 2 * cpi->common.bit_depth * n * av1_cost_bit(128, 0) +
cpi->palette_uv_size_cost[bsize - BLOCK_8X8][n - 2] + cpi->palette_uv_size_cost[bsize - BLOCK_8X8][n - PALETTE_MIN_SIZE] +
write_uniform_cost(n, color_map[0]) + write_uniform_cost(n, color_map[0]) +
av1_cost_bit( av1_cost_bit(
av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0], 1); av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0], 1);
...@@ -4554,7 +4554,8 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -4554,7 +4554,8 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
const int color_ctx = av1_get_palette_color_index_context( const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, i, j, n, color_order, &color_idx); color_map, plane_block_width, i, j, n, color_order, &color_idx);
assert(color_idx >= 0 && color_idx < n); assert(color_idx >= 0 && color_idx < n);
this_rate += cpi->palette_uv_color_cost[n - 2][color_ctx][color_idx]; this_rate += cpi->palette_uv_color_cost[n - PALETTE_MIN_SIZE]
[color_ctx][color_idx];
} }
} }
......
...@@ -429,9 +429,10 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi, ...@@ -429,9 +429,10 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi,
color_map, plane_block_width, i, j, n, color_order, &color_new_idx); color_map, plane_block_width, i, j, n, color_order, &color_new_idx);
assert(color_new_idx >= 0 && color_new_idx < n); assert(color_new_idx >= 0 && color_new_idx < n);
if (dry_run == DRY_RUN_COSTCOEFFS) if (dry_run == DRY_RUN_COSTCOEFFS)
this_rate += cpi->palette_y_color_cost[n - 2][color_ctx][color_new_idx]; this_rate += cpi->palette_y_color_cost[n - PALETTE_MIN_SIZE][color_ctx]
[color_new_idx];
(*t)->token = color_new_idx; (*t)->token = color_new_idx;
(*t)->context_tree = probs[n - 2][color_ctx]; (*t)->context_tree = probs[n - PALETTE_MIN_SIZE][color_ctx];
(*t)->skip_eob_node = 0; (*t)->skip_eob_node = 0;
++(*t); ++(*t);
} }
......
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