Commit efd8af25 authored by Sarah Parker's avatar Sarah Parker

Refactor decode_palette_tokens to read general color map

This will allow mrc-tx to use this function to read a signalled
mask. No change in coding performance.

Change-Id: I02103ad908086ba93129abf355c2dbc37121c076
parent 04808938
......@@ -1666,6 +1666,24 @@ static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x;
}
/* clang-format off */
typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
[CDF_SIZE(PALETTE_COLORS)];
typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
[PALETTE_COLORS];
/* clang-format on */
typedef struct {
int rows;
int cols;
int n_colors;
int plane_width;
int plane_height;
uint8_t *color_map;
MapCdf map_cdf;
ColorCost color_cost;
} Av1ColorMapParam;
#if CONFIG_GLOBAL_MOTION
static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) {
const MODE_INFO *mi = xd->mi[0];
......
......@@ -218,22 +218,15 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
}
#endif // !CONFIG_PVQ
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
aom_reader *r) {
const MODE_INFO *const mi = xd->mi[0];
const MB_MODE_INFO *const mbmi = &mi->mbmi;
static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
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;
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;
int plane_block_width, plane_block_height, rows, cols;
assert(mbmi->sb_type >= BLOCK_8X8);
av1_get_block_dimensions(mbmi->sb_type, plane, xd, &plane_block_width,
&plane_block_height, &rows, &cols);
assert(plane == 0 || plane == 1);
const int n = param->n_colors;
uint8_t *const color_map = param->color_map;
MapCdf color_map_cdf = param->map_cdf;
int plane_block_width = param->plane_width;
int plane_block_height = param->plane_height;
int rows = param->rows;
int cols = param->cols;
// The first color index.
color_map[0] = av1_read_uniform(r, n);
......@@ -246,7 +239,7 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, (i - j), j, n, color_order, NULL);
const int color_idx = aom_read_symbol(
r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
assert(color_idx >= 0 && color_idx < n);
color_map[(i - j) * plane_block_width + j] = color_order[color_idx];
}
......@@ -265,7 +258,7 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
const int color_ctx = av1_get_palette_color_index_context(
color_map, plane_block_width, i, j, n, color_order, NULL);
const int color_idx = aom_read_symbol(
r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
assert(color_idx >= 0 && color_idx < n);
color_map[i * plane_block_width + j] = color_order[color_idx];
}
......@@ -281,6 +274,50 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
}
}
static void get_palette_params(const MACROBLOCKD *const xd, int plane,
BLOCK_SIZE bsize, Av1ColorMapParam *params) {
assert(plane == 0 || plane == 1);
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
params->color_map = xd->plane[plane].color_index_map;
params->map_cdf = plane ? xd->tile_ctx->palette_uv_color_index_cdf
: xd->tile_ctx->palette_y_color_index_cdf;
params->n_colors = pmi->palette_size[plane];
av1_get_block_dimensions(bsize, plane, xd, &params->plane_width,
&params->plane_height, &params->rows, &params->cols);
}
#if CONFIG_MRC_TX
static void get_mrc_params(const MACROBLOCKD *const xd, int plane,
BLOCK_SIZE bsize, Av1ColorMapParam *params) {
// TODO(sarahparker)
(void)xd;
(void)plane;
(void)bsize;
memset(params, 0, sizeof(*params));
}
#endif // CONFIG_MRC_TX
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
aom_reader *r) {
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
assert(plane == 0 || plane == 1);
assert(mbmi->sb_type >= BLOCK_8X8);
Av1ColorMapParam color_map_params;
memset(&color_map_params, 0, sizeof(color_map_params));
get_palette_params(xd, plane, mbmi->sb_type, &color_map_params);
decode_color_map_tokens(&color_map_params, r);
}
#if CONFIG_MRC_TX
void av1_decode_mrc_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r) {
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
Av1ColorMapParam color_map_params;
get_mrc_params(xd, plane, mbmi->sb_type, &color_map_params);
decode_color_map_tokens(&color_map_params, r);
}
#endif // CONFIG_MRC_TX
#if !CONFIG_PVQ || CONFIG_VAR_TX
int av1_decode_block_tokens(AV1_COMMON *cm, MACROBLOCKD *const xd, int plane,
const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
......
......@@ -24,6 +24,10 @@ extern "C" {
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
#if CONFIG_MRC_TX
void av1_decode_mrc_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
#endif // CONFIG_MRC_TX
#if !CONFIG_PVQ || CONFIG_VAR_TX
int av1_decode_block_tokens(AV1_COMMON *cm, MACROBLOCKD *const xd, int plane,
const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
......
......@@ -264,23 +264,6 @@ const av1_extra_bit av1_extra_bits[ENTROPY_TOKENS] = {
};
#endif
/* clang-format off */
typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS]
[CDF_SIZE(PALETTE_COLORS)];
typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
[PALETTE_COLORS];
/* clang-format on */
typedef struct {
int rows;
int cols;
int n_colors;
int plane_width;
uint8_t *color_map;
MapCdf map_cdf;
ColorCost color_cost;
} ColorMapParam;
#if !CONFIG_PVQ || CONFIG_VAR_TX
static void cost_coeffs_b(int plane, int block, int blk_row, int blk_col,
BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) {
......@@ -346,7 +329,7 @@ static INLINE void add_token(TOKENEXTRA **t,
}
#endif // !CONFIG_PVQ || CONFIG_VAR_TX
static int cost_and_tokenize_map(ColorMapParam *param, TOKENEXTRA **t,
static int cost_and_tokenize_map(Av1ColorMapParam *param, TOKENEXTRA **t,
int calc_rate) {
const uint8_t *const color_map = param->color_map;
MapCdf map_cdf = param->map_cdf;
......@@ -385,7 +368,7 @@ static int cost_and_tokenize_map(ColorMapParam *param, TOKENEXTRA **t,
}
static void get_palette_params(const MACROBLOCK *const x, int plane,
BLOCK_SIZE bsize, ColorMapParam *params) {
BLOCK_SIZE bsize, Av1ColorMapParam *params) {
const MACROBLOCKD *const xd = &x->e_mbd;
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
......@@ -401,7 +384,7 @@ static void get_palette_params(const MACROBLOCK *const x, int plane,
#if CONFIG_MRC_TX
static void get_mrc_params(const MACROBLOCK *const x, int plane,
BLOCK_SIZE bsize, ColorMapParam *params) {
BLOCK_SIZE bsize, Av1ColorMapParam *params) {
// TODO(sarahparker)
(void)x;
(void)plane;
......@@ -412,7 +395,7 @@ static void get_mrc_params(const MACROBLOCK *const x, int plane,
static void get_color_map_params(const MACROBLOCK *const x, int plane,
BLOCK_SIZE bsize, COLOR_MAP_TYPE type,
ColorMapParam *params) {
Av1ColorMapParam *params) {
memset(params, 0, sizeof(*params));
switch (type) {
case PALETTE_MAP: get_palette_params(x, plane, bsize, params); break;
......@@ -426,7 +409,7 @@ static void get_color_map_params(const MACROBLOCK *const x, int plane,
int av1_cost_color_map(const MACROBLOCK *const x, int plane, BLOCK_SIZE bsize,
COLOR_MAP_TYPE type) {
assert(plane == 0 || plane == 1);
ColorMapParam color_map_params;
Av1ColorMapParam color_map_params;
get_color_map_params(x, plane, bsize, type, &color_map_params);
return cost_and_tokenize_map(&color_map_params, NULL, 1);
}
......@@ -435,7 +418,7 @@ void av1_tokenize_color_map(const MACROBLOCK *const x, int plane,
TOKENEXTRA **t, BLOCK_SIZE bsize,
COLOR_MAP_TYPE type) {
assert(plane == 0 || plane == 1);
ColorMapParam color_map_params;
Av1ColorMapParam color_map_params;
get_color_map_params(x, plane, bsize, type, &color_map_params);
// The first color index does not use context or entropy.
(*t)->token = color_map_params.color_map[0];
......
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