Bring palette back to nextgenv2

It was removed by the master branch merge.

Change-Id: I4b2a524c9e052e41063359afcb4ba22bf78344cf
This commit is contained in:
hui su
2015-12-07 18:18:57 -08:00
parent 69f4930041
commit c93e5cc3e9
23 changed files with 1225 additions and 9 deletions

View File

@@ -49,6 +49,20 @@ static const struct vp10_token partition_encodings[PARTITION_TYPES] =
{{0, 1}, {2, 2}, {6, 3}, {7, 3}};
static const struct vp10_token inter_mode_encodings[INTER_MODES] =
{{2, 2}, {6, 3}, {0, 1}, {7, 3}};
static const struct vp10_token palette_size_encodings[] = {
{0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {63, 6},
};
static const struct vp10_token
palette_color_encodings[PALETTE_MAX_SIZE - 1][PALETTE_MAX_SIZE] = {
{{0, 1}, {1, 1}}, // 2 colors
{{0, 1}, {2, 2}, {3, 2}}, // 3 colors
{{0, 1}, {2, 2}, {6, 3}, {7, 3}}, // 4 colors
{{0, 1}, {2, 2}, {6, 3}, {14, 4}, {15, 4}}, // 5 colors
{{0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {31, 5}}, // 6 colors
{{0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {63, 6}}, // 7 colors
{{0, 1}, {2, 2}, {6, 3}, {14, 4},
{30, 5}, {62, 6}, {126, 7}, {127, 7}}, // 8 colors
};
static INLINE void write_uniform(vpx_writer *w, int n, int v) {
int l = get_unsigned_bits(n);
@@ -283,6 +297,22 @@ static void update_ext_tx_probs(VP10_COMMON *cm, vpx_writer *w) {
}
#endif // CONFIG_EXT_TX
static void pack_palette_tokens(vpx_writer *w, TOKENEXTRA **tp,
BLOCK_SIZE bsize, int n) {
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
int i;
TOKENEXTRA *p = *tp;
for (i = 0; i < rows * cols -1; ++i) {
vp10_write_token(w, vp10_palette_color_tree[n - 2], p->context_tree,
&palette_color_encodings[n - 2][p->token]);
++p;
}
*tp = p;
}
static void pack_mb_tokens(vpx_writer *w,
TOKENEXTRA **tp, const TOKENEXTRA *const stop,
vpx_bit_depth_t bit_depth, const TX_SIZE tx) {
@@ -712,6 +742,36 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi,
#endif // CONFIG_EXT_TX
}
static void write_palette_mode_info(const VP10_COMMON *cm,
const MACROBLOCKD *xd,
const MODE_INFO *const mi,
vpx_writer *w) {
const MB_MODE_INFO *const mbmi = &mi->mbmi;
const MODE_INFO *const above_mi = xd->above_mi;
const MODE_INFO *const left_mi = xd->left_mi;
const BLOCK_SIZE bsize = mbmi->sb_type;
const PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info;
int palette_ctx = 0;
int n, i;
n = pmi->palette_size[0];
if (above_mi)
palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0);
if (left_mi)
palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0);
vpx_write(w, n > 0,
vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx]);
if (n > 0) {
vp10_write_token(w, vp10_palette_size_tree,
vp10_default_palette_y_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - 2]);
for (i = 0; i < n; ++i)
vpx_write_literal(w, pmi->palette_colors[i],
cm->bit_depth);
write_uniform(w, n, pmi->palette_first_color_idx[0]);
}
}
static void write_mb_modes_kf(const VP10_COMMON *cm, const MACROBLOCKD *xd,
MODE_INFO **mi_8x8, vpx_writer *w) {
const struct segmentation *const seg = &cm->seg;
@@ -760,6 +820,10 @@ static void write_mb_modes_kf(const VP10_COMMON *cm, const MACROBLOCKD *xd,
MAX_ANGLE_DELTAS + mbmi->angle_delta[1]);
#endif // CONFIG_EXT_INTRA
if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools &&
mbmi->mode == DC_PRED)
write_palette_mode_info(cm, xd, mi, w);
#if CONFIG_EXT_TX
if (get_ext_tx_types(mbmi->tx_size, bsize, 0) > 1 &&
@@ -809,6 +873,13 @@ static void write_modes_b(VP10_COMP *cpi, const TileInfo *const tile,
pack_inter_mode_mvs(cpi, m, w);
}
if (m->mbmi.palette_mode_info.palette_size[0] > 0) {
assert(*tok < tok_end);
pack_palette_tokens(w, tok, m->mbmi.sb_type,
m->mbmi.palette_mode_info.palette_size[0]);
assert(*tok < tok_end);
}
if (!m->mbmi.skip) {
assert(*tok < tok_end);
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
@@ -1572,6 +1643,8 @@ static void write_uncompressed_header(VP10_COMP *cpi,
write_sync_code(wb);
write_bitdepth_colorspace_sampling(cm, wb);
write_frame_size(cm, wb);
if (frame_is_intra_only(cm))
vpx_wb_write_bit(wb, cm->allow_screen_content_tools);
} else {
if (!cm->show_frame)
vpx_wb_write_bit(wb, cm->intra_only);