Commit 23a61117 authored by Urvang Joshi's avatar Urvang Joshi

Palette code: add comments and rename some variables.

- Added comments for some tables and #defines for clarity.
- Renamed some variables to ensure we use "color_index" instead of
"color" for palette color index related variables.

Change-Id: Ica95a26e0f171a41a3259c8e6b3b891b8cd10151
parent d0d3bccf
...@@ -776,6 +776,9 @@ static const aom_prob default_single_ref_p[REF_CONTEXTS][SINGLE_REFS - 1] = { ...@@ -776,6 +776,9 @@ static const aom_prob default_single_ref_p[REF_CONTEXTS][SINGLE_REFS - 1] = {
}; };
#if CONFIG_PALETTE #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)] = { const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)] = {
-TWO_COLORS, 2, -THREE_COLORS, 4, -FOUR_COLORS, 6, -TWO_COLORS, 2, -THREE_COLORS, 4, -FOUR_COLORS, 6,
-FIVE_COLORS, 8, -SIX_COLORS, 10, -SEVEN_COLORS, -EIGHT_COLORS, -FIVE_COLORS, 8, -SIX_COLORS, 10, -SEVEN_COLORS, -EIGHT_COLORS,
...@@ -808,6 +811,9 @@ const aom_prob ...@@ -808,6 +811,9 @@ const aom_prob
#endif // CONFIG_EXT_PARTITION #endif // CONFIG_EXT_PARTITION
}; };
// When palette mode is enabled, following probability tables indicate the
// probabilities to code the "is_palette" bit (i.e. the bit that indicates
// if this block uses palette mode or DC_PRED mode).
const aom_prob const aom_prob
av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES] av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
[PALETTE_Y_MODE_CONTEXTS] = { [PALETTE_Y_MODE_CONTEXTS] = {
...@@ -822,10 +828,15 @@ const aom_prob ...@@ -822,10 +828,15 @@ const aom_prob
#endif // CONFIG_EXT_PARTITION #endif // CONFIG_EXT_PARTITION
}; };
const aom_prob av1_default_palette_uv_mode_prob[2] = { 253, 229 }; 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 const aom_tree_index
av1_palette_color_tree[PALETTE_MAX_SIZE - 1][TREE_SIZE(PALETTE_COLORS)] = { av1_palette_color_index_tree[PALETTE_MAX_SIZE -
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
...@@ -852,8 +863,8 @@ const aom_tree_index ...@@ -852,8 +863,8 @@ const aom_tree_index
// Note: Has to be non-zero to avoid any asserts triggering. // Note: Has to be non-zero to avoid any asserts triggering.
#define UNUSED_PROB 128 #define UNUSED_PROB 128
const aom_prob av1_default_palette_y_color_prob const aom_prob av1_default_palette_y_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = { [PALETTE_MAX_SIZE - 1][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,
...@@ -922,8 +933,8 @@ const aom_prob av1_default_palette_y_color_prob ...@@ -922,8 +933,8 @@ const aom_prob av1_default_palette_y_color_prob
}, },
}; };
const aom_prob av1_default_palette_uv_color_prob const aom_prob av1_default_palette_uv_color_index_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = { [PALETTE_MAX_SIZE - 1][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,
...@@ -996,9 +1007,9 @@ const aom_prob av1_default_palette_uv_color_prob ...@@ -996,9 +1007,9 @@ const aom_prob av1_default_palette_uv_color_prob
#define MAX_COLOR_CONTEXT_HASH 8 #define MAX_COLOR_CONTEXT_HASH 8
// Negative values are invalid // Negative values are invalid
static const int palette_color_context_lookup[MAX_COLOR_CONTEXT_HASH + 1] = { static const int palette_color_index_context_lookup[MAX_COLOR_CONTEXT_HASH +
-1, -1, 0, -1, -1, 4, 3, 2, 1 1] = { -1, -1, 0, -1, -1,
}; 4, 3, 2, 1 };
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
...@@ -1064,10 +1075,10 @@ static const aom_prob ...@@ -1064,10 +1075,10 @@ static const aom_prob
#endif // CONFIG_LOOP_RESTORATION #endif // CONFIG_LOOP_RESTORATION
#if CONFIG_PALETTE #if CONFIG_PALETTE
#define NUM_PALETTE_NEIGHBORS 3 #define NUM_PALETTE_NEIGHBORS 3 // left, top-left and top.
int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r, int av1_get_palette_color_index_context(const uint8_t *color_map, int stride,
int c, int palette_size, uint8_t *color_order, int r, int c, int palette_size,
int *color_idx) { uint8_t *color_order, int *color_idx) {
int i; int i;
// The +10 below should not be needed. But we get a warning "array subscript // The +10 below should not be needed. But we get a warning "array subscript
// is above array bounds [-Werror=array-bounds]" without it, possibly due to // is above array bounds [-Werror=array-bounds]" without it, possibly due to
...@@ -1075,8 +1086,8 @@ int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r, ...@@ -1075,8 +1086,8 @@ int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r,
int scores[PALETTE_MAX_SIZE + 10]; int scores[PALETTE_MAX_SIZE + 10];
const int weights[NUM_PALETTE_NEIGHBORS] = { 2, 1, 2 }; const int weights[NUM_PALETTE_NEIGHBORS] = { 2, 1, 2 };
const int hash_multipliers[NUM_PALETTE_NEIGHBORS] = { 1, 2, 2 }; const int hash_multipliers[NUM_PALETTE_NEIGHBORS] = { 1, 2, 2 };
int color_ctx_hash; int color_index_ctx_hash;
int color_ctx; int color_index_ctx;
int color_neighbors[NUM_PALETTE_NEIGHBORS]; int color_neighbors[NUM_PALETTE_NEIGHBORS];
int inverse_color_order[PALETTE_MAX_SIZE]; int inverse_color_order[PALETTE_MAX_SIZE];
assert(palette_size <= PALETTE_MAX_SIZE); assert(palette_size <= PALETTE_MAX_SIZE);
...@@ -1128,22 +1139,22 @@ int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r, ...@@ -1128,22 +1139,22 @@ int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r,
} }
// Get hash value of context. // Get hash value of context.
color_ctx_hash = 0; color_index_ctx_hash = 0;
for (i = 0; i < NUM_PALETTE_NEIGHBORS; ++i) { for (i = 0; i < NUM_PALETTE_NEIGHBORS; ++i) {
color_ctx_hash += scores[i] * hash_multipliers[i]; color_index_ctx_hash += scores[i] * hash_multipliers[i];
} }
assert(color_ctx_hash > 0); assert(color_index_ctx_hash > 0);
assert(color_ctx_hash <= MAX_COLOR_CONTEXT_HASH); assert(color_index_ctx_hash <= MAX_COLOR_CONTEXT_HASH);
// Lookup context from hash. // Lookup context from hash.
color_ctx = palette_color_context_lookup[color_ctx_hash]; color_index_ctx = palette_color_index_context_lookup[color_index_ctx_hash];
assert(color_ctx >= 0); assert(color_index_ctx >= 0);
assert(color_ctx < PALETTE_COLOR_CONTEXTS); assert(color_index_ctx < PALETTE_COLOR_INDEX_CONTEXTS);
if (color_idx != NULL) { if (color_idx != NULL) {
*color_idx = inverse_color_order[color_map[r * stride + c]]; *color_idx = inverse_color_order[color_map[r * stride + c]];
} }
return color_ctx; return color_index_ctx;
} }
#undef NUM_PALETTE_NEIGHBORS #undef NUM_PALETTE_NEIGHBORS
#undef MAX_COLOR_CONTEXT_HASH #undef MAX_COLOR_CONTEXT_HASH
......
...@@ -32,10 +32,32 @@ extern "C" { ...@@ -32,10 +32,32 @@ extern "C" {
#endif // CONFIG_EXT_INTER #endif // CONFIG_EXT_INTER
#if CONFIG_PALETTE #if CONFIG_PALETTE
#define PALETTE_COLOR_CONTEXTS 5 // Number of possible contexts for a color index.
// As can be seen from av1_get_palette_color_index_context(), the possible
// contexts are (2,0,0), (2,2,1), (3,2,0), (4,1,0), (5,0,0). These are mapped to
// a value from 0 to 4 using 'palette_color_index_context_lookup' table.
#define PALETTE_COLOR_INDEX_CONTEXTS 5
// Maximum number of colors in a palette.
#define PALETTE_MAX_SIZE 8 #define PALETTE_MAX_SIZE 8
// 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)
// Palette Y mode context for a block is determined by number of neighboring
// blocks (top and/or left) using a palette for Y plane. So, possible Y mode'
// context values are:
// 0 if neither left nor top block uses palette for Y plane,
// 1 if exactly one of left or top block uses palette for Y plane, and
// 2 if both left and top blocks use palette for Y plane.
#define PALETTE_Y_MODE_CONTEXTS 3 #define PALETTE_Y_MODE_CONTEXTS 3
// Palette UV mode context for a block is determined by whether this block uses
// palette for the Y plane. So, possible values are:
// 0 if this block doesn't use palette for Y plane.
// 1 if this block uses palette for Y plane (i.e. Y palette size > 0).
#define PALETTE_UV_MODE_CONTEXTS 2
#define PALETTE_MAX_BLOCK_SIZE (64 * 64) #define PALETTE_MAX_BLOCK_SIZE (64 * 64)
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
...@@ -344,17 +366,20 @@ extern aom_cdf_prob av1_kf_y_mode_cdf[INTRA_MODES][INTRA_MODES][INTRA_MODES]; ...@@ -344,17 +366,20 @@ extern aom_cdf_prob av1_kf_y_mode_cdf[INTRA_MODES][INTRA_MODES][INTRA_MODES];
#if CONFIG_PALETTE #if CONFIG_PALETTE
extern const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES] extern const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
[PALETTE_Y_MODE_CONTEXTS]; [PALETTE_Y_MODE_CONTEXTS];
extern const aom_prob av1_default_palette_uv_mode_prob[2]; 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] extern const aom_prob av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES]
[PALETTE_SIZES - 1]; [PALETTE_SIZES - 1];
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_prob[PALETTE_MAX_SIZE - 1] extern const aom_prob
[PALETTE_COLOR_CONTEXTS] av1_default_palette_y_color_index_prob[PALETTE_MAX_SIZE - 1]
[PALETTE_COLORS - 1]; [PALETTE_COLOR_INDEX_CONTEXTS]
extern const aom_prob av1_default_palette_uv_color_prob[PALETTE_MAX_SIZE - 1] [PALETTE_COLORS - 1];
[PALETTE_COLOR_CONTEXTS] extern const aom_prob
[PALETTE_COLORS - 1]; av1_default_palette_uv_color_index_prob[PALETTE_MAX_SIZE - 1]
[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)];
...@@ -381,8 +406,9 @@ extern const aom_tree_index ...@@ -381,8 +406,9 @@ extern const aom_tree_index
av1_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)]; av1_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
#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 av1_palette_color_tree[PALETTE_MAX_SIZE - 1] extern const aom_tree_index
[TREE_SIZE(PALETTE_COLORS)]; av1_palette_color_index_tree[PALETTE_MAX_SIZE - 1]
[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
...@@ -439,9 +465,9 @@ static INLINE int av1_ceil_log2(int n) { ...@@ -439,9 +465,9 @@ static INLINE int av1_ceil_log2(int n) {
// Returns the context for palette color index at row 'r' and column 'c', // Returns the context for palette color index at row 'r' and column 'c',
// along with the 'color_order' of neighbors and the 'color_idx'. // along with the 'color_order' of neighbors and the 'color_idx'.
// The 'color_map' is a 2D array with the given 'stride'. // The 'color_map' is a 2D array with the given 'stride'.
int av1_get_palette_color_context(const uint8_t *color_map, int stride, int r, int av1_get_palette_color_index_context(const uint8_t *color_map, int stride,
int c, int palette_size, uint8_t *color_order, int r, int c, int palette_size,
int *color_idx); uint8_t *color_order, int *color_idx);
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -574,17 +574,20 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -574,17 +574,20 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const MODE_INFO *const above_mi = xd->above_mi; const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi; const MODE_INFO *const left_mi = xd->left_mi;
const BLOCK_SIZE bsize = mbmi->sb_type; const BLOCK_SIZE bsize = mbmi->sb_type;
int i, n, palette_ctx = 0; int i, n;
PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
if (mbmi->mode == DC_PRED) { if (mbmi->mode == DC_PRED) {
int palette_y_mode_ctx = 0;
if (above_mi) if (above_mi)
palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi) if (left_mi)
palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx +=
if (aom_read( (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], if (aom_read(r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8]
ACCT_STR)) { [palette_y_mode_ctx],
ACCT_STR)) {
pmi->palette_size[0] = pmi->palette_size[0] =
aom_read_tree(r, av1_palette_size_tree, aom_read_tree(r, av1_palette_size_tree,
av1_default_palette_y_size_prob[bsize - BLOCK_8X8], av1_default_palette_y_size_prob[bsize - BLOCK_8X8],
...@@ -600,7 +603,8 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -600,7 +603,8 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
} }
if (mbmi->uv_mode == DC_PRED) { if (mbmi->uv_mode == DC_PRED) {
if (aom_read(r, av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0], const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx],
ACCT_STR)) { ACCT_STR)) {
pmi->palette_size[1] = pmi->palette_size[1] =
aom_read_tree(r, av1_palette_size_tree, aom_read_tree(r, av1_palette_size_tree,
......
...@@ -318,9 +318,10 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, ...@@ -318,9 +318,10 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
const int n = mbmi->palette_mode_info.palette_size[plane]; const int n = mbmi->palette_mode_info.palette_size[plane];
int i, j; int i, j;
uint8_t *const color_map = xd->plane[plane].color_index_map; uint8_t *const color_map = xd->plane[plane].color_index_map;
const aom_prob(*const prob)[PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = const aom_prob(*const prob)[PALETTE_COLOR_INDEX_CONTEXTS]
plane ? av1_default_palette_uv_color_prob [PALETTE_COLORS - 1] =
: av1_default_palette_y_color_prob; plane ? av1_default_palette_uv_color_index_prob
: av1_default_palette_y_color_index_prob;
int plane_block_width, plane_block_height, rows, cols; int plane_block_width, plane_block_height, rows, cols;
av1_get_block_dimensions(mbmi->sb_type, plane, xd, &plane_block_width, av1_get_block_dimensions(mbmi->sb_type, plane, xd, &plane_block_width,
&plane_block_height, &rows, &cols); &plane_block_height, &rows, &cols);
...@@ -328,10 +329,11 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, ...@@ -328,10 +329,11 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
for (i = 0; i < rows; ++i) { for (i = 0; i < rows; ++i) {
for (j = (i == 0 ? 1 : 0); j < cols; ++j) { for (j = (i == 0 ? 1 : 0); j < cols; ++j) {
const int color_ctx = av1_get_palette_color_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 = aom_read_tree(r, av1_palette_color_tree[n - 2], const int color_idx =
prob[n - 2][color_ctx], ACCT_STR); aom_read_tree(r, av1_palette_color_index_tree[n - 2],
prob[n - 2][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];
} }
......
...@@ -77,8 +77,8 @@ static const struct av1_token ...@@ -77,8 +77,8 @@ 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_MAX_SIZE - 1];
static struct av1_token palette_color_encodings[PALETTE_MAX_SIZE - 1] static struct av1_token palette_color_index_encodings[PALETTE_MAX_SIZE - 1]
[PALETTE_MAX_SIZE]; [PALETTE_MAX_SIZE];
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
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] = {
{ { 0, 1 }, { 1, 1 } }, // Max tx_size is 8X8 { { 0, 1 }, { 1, 1 } }, // Max tx_size is 8X8
...@@ -160,7 +160,8 @@ void av1_encode_token_init(void) { ...@@ -160,7 +160,8 @@ 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_MAX_SIZE - 1; ++s) {
av1_tokens_from_tree(palette_color_encodings[s], av1_palette_color_tree[s]); av1_tokens_from_tree(palette_color_index_encodings[s],
av1_palette_color_index_tree[s]);
} }
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
...@@ -726,8 +727,8 @@ static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n, ...@@ -726,8 +727,8 @@ 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_tree[n - 2], p->context_tree, av1_write_token(w, av1_palette_color_index_tree[n - 2], p->context_tree,
&palette_color_encodings[n - 2][p->token]); &palette_color_index_encodings[n - 2][p->token]);
++p; ++p;
} }
...@@ -1137,17 +1138,19 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1137,17 +1138,19 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const MODE_INFO *const left_mi = xd->left_mi; const MODE_INFO *const left_mi = xd->left_mi;
const BLOCK_SIZE bsize = mbmi->sb_type; const BLOCK_SIZE bsize = mbmi->sb_type;
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
int palette_ctx = 0; int i;
int n, i;
if (mbmi->mode == DC_PRED) { if (mbmi->mode == DC_PRED) {
n = pmi->palette_size[0]; const int n = pmi->palette_size[0];
int palette_y_mode_ctx = 0;
if (above_mi) if (above_mi)
palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi) if (left_mi)
palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx +=
aom_write(w, n > 0, (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx]); aom_write(w, n > 0, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8]
[palette_y_mode_ctx]);
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],
...@@ -1159,9 +1162,9 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -1159,9 +1162,9 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
} }
if (mbmi->uv_mode == DC_PRED) { if (mbmi->uv_mode == DC_PRED) {
n = pmi->palette_size[1]; const int n = pmi->palette_size[1];
aom_write(w, n > 0, const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0);
av1_default_palette_uv_mode_prob[pmi->palette_size[0] > 0]); aom_write(w, n > 0, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx]);
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],
......
...@@ -568,9 +568,9 @@ typedef struct AV1_COMP { ...@@ -568,9 +568,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_CONTEXTS] int palette_y_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_INDEX_CONTEXTS]
[PALETTE_COLORS]; [PALETTE_COLORS];
int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][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];
......
...@@ -102,13 +102,13 @@ static void fill_mode_costs(AV1_COMP *cpi) { ...@@ -102,13 +102,13 @@ static void fill_mode_costs(AV1_COMP *cpi) {
} }
for (i = 0; i < PALETTE_MAX_SIZE - 1; ++i) { for (i = 0; i < PALETTE_MAX_SIZE - 1; ++i) {
for (j = 0; j < PALETTE_COLOR_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_prob[i][j], av1_default_palette_y_color_index_prob[i][j],
av1_palette_color_tree[i]); av1_palette_color_index_tree[i]);
av1_cost_tokens(cpi->palette_uv_color_cost[i][j], av1_cost_tokens(cpi->palette_uv_color_cost[i][j],
av1_default_palette_uv_color_prob[i][j], av1_default_palette_uv_color_index_prob[i][j],
av1_palette_color_tree[i]); av1_palette_color_index_tree[i]);
} }
} }
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
......
...@@ -2428,7 +2428,7 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -2428,7 +2428,7 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
for (i = 0; i < rows; ++i) { for (i = 0; i < rows; ++i) {
for (j = (i == 0 ? 1 : 0); j < cols; ++j) { for (j = (i == 0 ? 1 : 0); j < cols; ++j) {
int color_idx; int color_idx;
const int color_ctx = av1_get_palette_color_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 +=
...@@ -3511,7 +3511,7 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -3511,7 +3511,7 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
cpi->common.allow_screen_content_tools cpi->common.allow_screen_content_tools
? x->palette_buffer->best_palette_color_map ? x->palette_buffer->best_palette_color_map
: NULL; : NULL;
int palette_ctx = 0; int palette_y_mode_ctx = 0;
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
const MODE_INFO *above_mi = xd->above_mi; const MODE_INFO *above_mi = xd->above_mi;
const MODE_INFO *left_mi = xd->left_mi; const MODE_INFO *left_mi = xd->left_mi;
...@@ -3544,9 +3544,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -3544,9 +3544,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
#if CONFIG_PALETTE #if CONFIG_PALETTE
pmi->palette_size[0] = 0; pmi->palette_size[0] = 0;
if (above_mi) if (above_mi)
palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx +=
(above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi) if (left_mi)
palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); palette_y_mode_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
if (cpi->sf.tx_type_search.fast_intra_tx_type_search) if (cpi->sf.tx_type_search.fast_intra_tx_type_search)
...@@ -3608,8 +3609,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -3608,8 +3609,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
} }
#if CONFIG_PALETTE #if CONFIG_PALETTE
if (cpi->common.allow_screen_content_tools && mbmi->mode == DC_PRED) if (cpi->common.allow_screen_content_tools && mbmi->mode == DC_PRED)
this_rate += av1_cost_bit( this_rate +=
av1_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx], 0); av1_cost_bit(av1_default_palette_y_mode_prob[bsize - BLOCK_8X8]
[palette_y_mode_ctx],
0);
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
#if CONFIG_FILTER_INTRA #if CONFIG_FILTER_INTRA
if (mbmi->mode == DC_PRED) if (mbmi->mode == DC_PRED)
...@@ -3658,10 +3661,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -3658,10 +3661,10 @@ static int64_t rd_pick_intra_sby_mode(const AV1_COMP *const cpi, MACROBLOCK *x,
#if CONFIG_PALETTE #if CONFIG_PALETTE
if (cpi->common.allow_screen_content_tools) { if (cpi->common.allow_screen_content_tools) {
rd_pick_palette_intra_sby(cpi, x, bsize, palette_ctx, bmode_costs[DC_PRED], rd_pick_palette_intra_sby(cpi, x, bsize, palette_y_mode_ctx,
&best_mbmi, best_palette_color_map, &best_rd, bmode_costs[DC_PRED], &best_mbmi,
&best_model_rd, rate, rate_tokenonly, distortion, best_palette_color_map, &best_rd, &best_model_rd,
skippable); rate, rate_tokenonly, distortion, skippable);
} }
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
...@@ -4510,7 +4513,7 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -4510,7 +4513,7 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
for (i = 0; i < rows; ++i) { for (i = 0; i < rows; ++i) {
for (j = (i == 0 ? 1 : 0); j < cols; ++j) { for (j = (i == 0 ? 1 : 0); j < cols; ++j) {
int color_idx; int color_idx;
const int color_ctx = av1_get_palette_color_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 - 2][color_ctx][color_idx];
......
...@@ -397,9 +397,11 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi, ...@@ -397,9 +397,11 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi,
int i, j; int i, j;
int this_rate = 0; int this_rate = 0;
uint8_t color_order[PALETTE_MAX_SIZE]; uint8_t color_order[PALETTE_MAX_SIZE];
const aom_prob(*const probs)[PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = const aom_prob(*const probs)[PALETTE_COLOR_INDEX_CONTEXTS]
plane == 0 ? av1_default_palette_y_color_prob [PALETTE_COLORS - 1] =
: av1_default_palette_uv_color_prob; plane == 0
? av1_default_palette_y_color_index_prob
: av1_default_palette_uv_color_index_prob;
int plane_block_width, rows, cols; int plane_block_width, rows, cols;
av1_get_block_dimensions(bsize, plane, xd, &plane_block_width, NULL, &rows, av1_get_block_dimensions(bsize, plane, xd, &plane_block_width, NULL, &rows,
&cols); &cols);
...@@ -408,7 +410,7 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi, ...@@ -408,7 +410,7 @@ void av1_tokenize_palette_sb(const AV1_COMP *cpi,
for (i = 0; i < rows; ++i) { for (i = 0; i < rows; ++i) {
for (j = (i == 0 ? 1 : 0); j < cols; ++j) { for (j = (i == 0 ? 1 : 0); j < cols; ++j) {
int color_new_idx; int color_new_idx;
const int color_ctx = av1_get_palette_color_context( const int color_ctx = av1_get_palette_color_index_context(
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)
......
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