Palette high bit depth functionality

Changes to allow high bit depth and palette to be enabled at the
same time by using a 16 bit (instead of 8bit) palette when high
bit depth is enabled and modifying related functions accordingly.

Change-Id: I97d30b4d9338d3a51db02c94bc568eba60a8905d
This commit is contained in:
Julia Robson 2015-06-02 14:31:38 +01:00 committed by Peter de Rivaz
parent c96afa256f
commit 84d0da63d0
10 changed files with 351 additions and 84 deletions

View File

@ -248,12 +248,17 @@ typedef struct {
int palette_literal_size; int palette_literal_size;
int current_palette_size; int current_palette_size;
int palette_delta_bitdepth; int palette_delta_bitdepth;
uint8_t palette_colors[3 * PALETTE_MAX_SIZE];
uint8_t palette_indexed_colors[PALETTE_MAX_SIZE]; uint8_t palette_indexed_colors[PALETTE_MAX_SIZE];
int8_t palette_color_delta[PALETTE_MAX_SIZE]; int8_t palette_color_delta[PALETTE_MAX_SIZE];
uint8_t palette_literal_colors[PALETTE_MAX_SIZE];
uint8_t *palette_color_map; uint8_t *palette_color_map;
uint8_t *palette_uv_color_map; uint8_t *palette_uv_color_map;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
uint16_t palette_literal_colors[PALETTE_MAX_SIZE];
#else
uint8_t palette_colors[3 * PALETTE_MAX_SIZE];
uint8_t palette_literal_colors[PALETTE_MAX_SIZE];
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
} MB_MODE_INFO; } MB_MODE_INFO;

View File

@ -223,7 +223,11 @@ typedef struct VP9Common {
ENTROPY_CONTEXT *above_context; ENTROPY_CONTEXT *above_context;
#if CONFIG_PALETTE #if CONFIG_PALETTE
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t current_palette_colors[PALETTE_BUF_SIZE];
#else
uint8_t current_palette_colors[PALETTE_BUF_SIZE]; uint8_t current_palette_colors[PALETTE_BUF_SIZE];
#endif
int current_palette_size; int current_palette_size;
int current_palette_count[PALETTE_BUF_SIZE]; int current_palette_count[PALETTE_BUF_SIZE];
int allow_palette_mode; int allow_palette_mode;

View File

@ -59,12 +59,47 @@ int vp9_count_colors(const uint8_t *src, int stride, int rows, int cols) {
return n; return n;
} }
#if CONFIG_VP9_HIGHBITDEPTH
int vp9_count_colors_highbd(const uint8_t *src8, int stride, int rows, int cols,
int bit_depth) {
int n = 0, r, c, i;
uint16_t val;
uint16_t *src = CONVERT_TO_SHORTPTR(src8);
int* val_count = vpx_calloc(1 << bit_depth, sizeof(*val_count));
for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) {
val = src[r * stride + c];
val_count[val]++;
}
}
for (i = 0; i < (1 << bit_depth); i++) {
if (val_count[i]) {
n++;
}
}
vpx_free(val_count);
return n;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
#if CONFIG_VP9_HIGHBITDEPTH
void vp9_palette_color_insertion(uint16_t *old_colors, int *m, int *count,
const MB_MODE_INFO *mbmi) {
const uint16_t *new_colors = mbmi->palette_literal_colors;
uint16_t val;
#else
void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count, void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count,
const MB_MODE_INFO *mbmi) { const MB_MODE_INFO *mbmi) {
int k = *m, n = mbmi->palette_literal_size;
int i, j, l, min_idx = -1;
const uint8_t *new_colors = mbmi->palette_literal_colors; const uint8_t *new_colors = mbmi->palette_literal_colors;
uint8_t val; uint8_t val;
#endif // CONFIG_VP9_HIGHBITDEPTH
int k = *m, n = mbmi->palette_literal_size;
int i, j, l, min_idx = -1;
if (mbmi->palette_indexed_size > 0) { if (mbmi->palette_indexed_size > 0) {
for (i = 0; i < mbmi->palette_indexed_size; i++) for (i = 0; i < mbmi->palette_indexed_size; i++)
@ -108,7 +143,11 @@ void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count,
*m = k; *m = k;
} }
#if CONFIG_VP9_HIGHBITDEPTH
int vp9_palette_color_lookup(uint16_t *dic, int n, uint16_t val, int bits) {
#else
int vp9_palette_color_lookup(uint8_t *dic, int n, uint8_t val, int bits) { int vp9_palette_color_lookup(uint8_t *dic, int n, uint8_t val, int bits) {
#endif // CONFIG_VP9_HIGHBITDEPTH
int j, min, arg_min = 0, i = 1; int j, min, arg_min = 0, i = 1;
if (n < 1) if (n < 1)

View File

@ -16,10 +16,18 @@
#if CONFIG_PALETTE #if CONFIG_PALETTE
int vp9_count_colors(const uint8_t *src, int stride, int rows, int cols); int vp9_count_colors(const uint8_t *src, int stride, int rows, int cols);
void vp9_insertion_sort(double *data, int n); #if CONFIG_VP9_HIGHBITDEPTH
int vp9_count_colors_highbd(const uint8_t *src8, int stride, int rows, int cols,
int bit_depth);
void vp9_palette_color_insertion(uint16_t *old_colors, int *m, int *count,
const MB_MODE_INFO *mbmi);
int vp9_palette_color_lookup(uint16_t *dic, int n, uint16_t val, int bits);
#else
void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count, void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count,
const MB_MODE_INFO *mbmi); const MB_MODE_INFO *mbmi);
int vp9_palette_color_lookup(uint8_t *dic, int n, uint8_t val, int bits); int vp9_palette_color_lookup(uint8_t *dic, int n, uint8_t val, int bits);
#endif // CONFIG_VP9_HIGHBITDEPTH
void vp9_insertion_sort(double *data, int n);
int vp9_ceil_log2(int n); int vp9_ceil_log2(int n);
int vp9_k_means(const double *data, double *centroids, int *indices, int vp9_k_means(const double *data, double *centroids, int *indices,
int n, int k, int dim, int max_itr); int n, int k, int dim, int max_itr);

View File

@ -1359,37 +1359,22 @@ void vp9_predict_intra_block(const MACROBLOCKD *xd, int block_idx, int bwl_in,
#endif // CONFIG_FILTERINTRA #endif // CONFIG_FILTERINTRA
assert(bwl >= 0); assert(bwl >= 0);
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
#if CONFIG_FILTERINTRA
if (!filterflag) {
#endif
build_intra_predictors_highbd(xd, ref, ref_stride, dst, dst_stride,
mode, tx_size, have_top,
have_left, have_right, x, y,
plane, xd->bd);
#if CONFIG_FILTERINTRA
} else {
build_filter_intra_predictors_highbd(xd, ref, ref_stride, dst, dst_stride,
mode, tx_size, have_top,
have_left, have_right, x, y,
plane, xd->bd);
}
#endif
return;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
#if CONFIG_FILTERINTRA #if CONFIG_FILTERINTRA
if (!filterflag) { if (!filterflag) {
#endif // CONFIG_FILTERINTRA #endif // CONFIG_FILTERINTRA
#if CONFIG_PALETTE #if CONFIG_PALETTE
if (xd->mi[0].src_mi->mbmi.palette_enabled[plane !=0]) { if (xd->mi[0].src_mi->mbmi.palette_enabled[plane !=0]) {
uint8_t *palette = xd->mi[0].src_mi->mbmi.palette_colors +
plane * PALETTE_MAX_SIZE;
int bs = 4 * (1 << tx_size); int bs = 4 * (1 << tx_size);
int stride = 4 * (1 << bwl_in); int stride = 4 * (1 << bwl_in);
int r, c; int r, c;
uint8_t *map = NULL; uint8_t *map = NULL;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t *palette = xd->mi[0].src_mi->mbmi.palette_colors +
plane * PALETTE_MAX_SIZE;
#else
uint8_t *palette = xd->mi[0].src_mi->mbmi.palette_colors +
plane * PALETTE_MAX_SIZE;
#endif // CONFIG_VP9_HIGHBITDEPTH
if (xd->plane[1].subsampling_x || xd->plane[1].subsampling_y) if (xd->plane[1].subsampling_x || xd->plane[1].subsampling_y)
map = xd->plane[plane != 0].color_index_map; map = xd->plane[plane != 0].color_index_map;
@ -1398,16 +1383,43 @@ void vp9_predict_intra_block(const MACROBLOCKD *xd, int block_idx, int bwl_in,
for (r = 0; r < bs; r++) { for (r = 0; r < bs; r++) {
for (c = 0; c < bs; c++) { for (c = 0; c < bs; c++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
dst16[r * dst_stride + c] = palette[map[(r + y) * stride + c + x]];
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
dst[r * dst_stride + c] = palette[map[(r + y) * stride + c + x]]; dst[r * dst_stride + c] = palette[map[(r + y) * stride + c + x]];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
} }
} }
return; return;
} }
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
build_intra_predictors_highbd(xd, ref, ref_stride, dst, dst_stride,
mode, tx_size, have_top,
have_left, have_right, x, y,
plane, xd->bd);
return;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
build_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode, tx_size, build_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode, tx_size,
have_top, have_left, have_right, x, y, plane); have_top, have_left, have_right, x, y, plane);
#if CONFIG_FILTERINTRA #if CONFIG_FILTERINTRA
} else { } else {
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
build_filter_intra_predictors_highbd(xd, ref, ref_stride, dst, dst_stride,
mode, tx_size, have_top,
have_left, have_right, x, y,
plane, xd->bd);
return;
}
#endif // CONFIG_VP9_HIGHBITDEPTH
build_filter_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode, build_filter_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode,
tx_size, have_top, have_left, have_right, tx_size, have_top, have_left, have_right,
x, y, plane); x, y, plane);

View File

@ -363,7 +363,7 @@ static void read_intra_frame_mode_info(VP9_COMMON *const cm,
} }
if (m2 > 0) { if (m2 > 0) {
for (i = 0; i < m2; i++) { for (i = 0; i < m2; i++) {
mbmi->palette_literal_colors[i] = vp9_read_literal(r, 8); mbmi->palette_literal_colors[i] = vp9_read_literal(r, cm->bit_depth);
mbmi->palette_colors[m1 + i] = mbmi->palette_literal_colors[i]; mbmi->palette_colors[m1 + i] = mbmi->palette_literal_colors[i];
} }
} }
@ -407,9 +407,11 @@ static void read_intra_frame_mode_info(VP9_COMMON *const cm,
} }
for (i = 0; i < mbmi->palette_size[1]; i++) for (i = 0; i < mbmi->palette_size[1]; i++)
mbmi->palette_colors[PALETTE_MAX_SIZE + i] = vp9_read_literal(r, 8); mbmi->palette_colors[PALETTE_MAX_SIZE + i] =
vp9_read_literal(r, cm->bit_depth);
for (i = 0; i < mbmi->palette_size[1]; i++) for (i = 0; i < mbmi->palette_size[1]; i++)
mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = vp9_read_literal(r, 8); mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
vp9_read_literal(r, cm->bit_depth);
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) { if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
int color_idx = 0, color_ctx = 0; int color_idx = 0, color_ctx = 0;
@ -1406,7 +1408,7 @@ static void read_inter_frame_mode_info(VP9_COMMON *const cm,
n = mbmi->palette_size[0]; n = mbmi->palette_size[0];
for (i = 0; i < mbmi->palette_size[0]; i++) for (i = 0; i < mbmi->palette_size[0]; i++)
mbmi->palette_colors[i] = vp9_read_literal(r, 8); mbmi->palette_colors[i] = vp9_read_literal(r, cm->bit_depth);
color_map[0] = vp9_read_literal(r, color_map[0] = vp9_read_literal(r,
vp9_ceil_log2(mbmi->palette_size[0])); vp9_ceil_log2(mbmi->palette_size[0]));
@ -1448,9 +1450,11 @@ static void read_inter_frame_mode_info(VP9_COMMON *const cm,
} }
for (i = 0; i < mbmi->palette_size[1]; i++) for (i = 0; i < mbmi->palette_size[1]; i++)
mbmi->palette_colors[PALETTE_MAX_SIZE + i] = vp9_read_literal(r, 8); mbmi->palette_colors[PALETTE_MAX_SIZE + i] =
vp9_read_literal(r, cm->bit_depth);
for (i = 0; i < mbmi->palette_size[1]; i++) for (i = 0; i < mbmi->palette_size[1]; i++)
mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = vp9_read_literal(r, 8); mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
vp9_read_literal(r, cm->bit_depth);
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) { if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
int color_idx = 0, color_ctx = 0; int color_idx = 0, color_ctx = 0;

View File

@ -531,7 +531,7 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi,
cm->fc.palette_size_prob[bsize - BLOCK_8X8], cm->fc.palette_size_prob[bsize - BLOCK_8X8],
&palette_size_encodings[n - 2]); &palette_size_encodings[n - 2]);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
vp9_write_literal(w, mbmi->palette_colors[i], 8); vp9_write_literal(w, mbmi->palette_colors[i], cm->bit_depth);
memcpy(buffer, mbmi->palette_color_map, memcpy(buffer, mbmi->palette_color_map,
rows * cols * sizeof(buffer[0])); rows * cols * sizeof(buffer[0]));
@ -566,9 +566,11 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi,
} }
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
vp9_write_literal(w, mbmi->palette_colors[PALETTE_MAX_SIZE + i], 8); vp9_write_literal(w, mbmi->palette_colors[PALETTE_MAX_SIZE + i],
cm->bit_depth);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i], 8); vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i],
cm->bit_depth);
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) { if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
memcpy(buffer, mbmi->palette_uv_color_map, memcpy(buffer, mbmi->palette_uv_color_map,
@ -945,7 +947,7 @@ static void write_mb_modes_kf(const VP9_COMMON *cm,
} }
if (m2 > 0) { if (m2 > 0) {
for (i = 0; i < m2; i++) for (i = 0; i < m2; i++)
vp9_write_literal(w, mbmi->palette_literal_colors[i], 8); vp9_write_literal(w, mbmi->palette_literal_colors[i], cm->bit_depth);
} }
memcpy(buffer, mbmi->palette_color_map, memcpy(buffer, mbmi->palette_color_map,
@ -981,9 +983,11 @@ static void write_mb_modes_kf(const VP9_COMMON *cm,
} }
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
vp9_write_literal(w, mbmi->palette_colors[PALETTE_MAX_SIZE + i], 8); vp9_write_literal(w, mbmi->palette_colors[PALETTE_MAX_SIZE + i],
cm->bit_depth);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i], 8); vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i],
cm->bit_depth);
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) { if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
memcpy(buffer, mbmi->palette_uv_color_map, memcpy(buffer, mbmi->palette_uv_color_map,

View File

@ -32,10 +32,14 @@ typedef struct {
uint16_t *eobs_pbuf[MAX_MB_PLANE][3]; uint16_t *eobs_pbuf[MAX_MB_PLANE][3];
#if CONFIG_PALETTE #if CONFIG_PALETTE
uint8_t *color_index_map[2]; uint8_t *color_index_map[2];
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t palette_colors_buf[PALETTE_BUF_SIZE];
#else
uint8_t palette_colors_buf[PALETTE_BUF_SIZE]; uint8_t palette_colors_buf[PALETTE_BUF_SIZE];
#endif // CONFIG_VP9_HIGHBITDEPTH
int palette_buf_size; int palette_buf_size;
int palette_count_buf[PALETTE_BUF_SIZE]; int palette_count_buf[PALETTE_BUF_SIZE];
#endif #endif // CONFIG_PALETTE
int is_coded; int is_coded;
int num_4x4_blk; int num_4x4_blk;
@ -92,4 +96,4 @@ typedef struct PC_TREE {
void vp9_setup_pc_tree(struct VP9Common *cm, struct VP9_COMP *cpi); void vp9_setup_pc_tree(struct VP9Common *cm, struct VP9_COMP *cpi);
void vp9_free_pc_tree(struct VP9_COMP *cpi); void vp9_free_pc_tree(struct VP9_COMP *cpi);
#endif /* VP9_ENCODER_VP9_CONTEXT_TREE_H_ */ #endif // VP9_ENCODER_VP9_CONTEXT_TREE_H_

View File

@ -1439,8 +1439,12 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile,
if (frame_is_intra_only(cm)) { if (frame_is_intra_only(cm)) {
#if CONFIG_PALETTE #if CONFIG_PALETTE
int n = cpi->common.current_palette_size; int n = cpi->common.current_palette_size;
uint8_t palette[PALETTE_BUF_SIZE];
int count[PALETTE_BUF_SIZE]; int count[PALETTE_BUF_SIZE];
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t palette[PALETTE_BUF_SIZE];
#else
uint8_t palette[PALETTE_BUF_SIZE];
#endif // CONFIG_VP9_HIGHBITDEPTH
vpx_memcpy(palette, cpi->common.current_palette_colors, vpx_memcpy(palette, cpi->common.current_palette_colors,
n * sizeof(palette[0])); n * sizeof(palette[0]));
@ -1540,7 +1544,6 @@ static void update_stats(VP9_COMMON *cm, const MACROBLOCK *x) {
const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id,
SEG_LVL_REF_FRAME); SEG_LVL_REF_FRAME);
if (!seg_ref_active) { if (!seg_ref_active) {
counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++;
// If the segment reference feature is enabled we have only a single // If the segment reference feature is enabled we have only a single
@ -3211,8 +3214,12 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile,
#if CONFIG_PALETTE #if CONFIG_PALETTE
PICK_MODE_CONTEXT *c, *p; PICK_MODE_CONTEXT *c, *p;
int previous_size, previous_count[PALETTE_BUF_SIZE]; int previous_size, previous_count[PALETTE_BUF_SIZE];
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t previous_colors[PALETTE_BUF_SIZE];
#else
uint8_t previous_colors[PALETTE_BUF_SIZE]; uint8_t previous_colors[PALETTE_BUF_SIZE];
#endif #endif // CONFIG_VP9_HIGHBITDEPTH
#endif // CONFIG_PALETTE
(void) *tp_orig; (void) *tp_orig;
assert(num_8x8_blocks_wide_lookup[bsize] == assert(num_8x8_blocks_wide_lookup[bsize] ==
@ -5539,7 +5546,7 @@ static void sum_intra_stats(FRAME_COUNTS *counts,
#if CONFIG_FILTERINTRA #if CONFIG_FILTERINTRA
const MACROBLOCKD* xd, const MACROBLOCKD* xd,
#endif #endif
const MODE_INFO *mi) { const MODE_INFO *mi) {
const PREDICTION_MODE y_mode = mi->mbmi.mode; const PREDICTION_MODE y_mode = mi->mbmi.mode;
const PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; const PREDICTION_MODE uv_mode = mi->mbmi.uv_mode;
const BLOCK_SIZE bsize = mi->mbmi.sb_type; const BLOCK_SIZE bsize = mi->mbmi.sb_type;

View File

@ -1784,9 +1784,15 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
int src_stride = x->plane[0].src.stride; int src_stride = x->plane[0].src.stride;
uint8_t *src = x->plane[0].src.buf; uint8_t *src = x->plane[0].src.buf;
uint8_t best_palette[PALETTE_MAX_SIZE];
uint8_t best_index[PALETTE_MAX_SIZE], best_literal[PALETTE_MAX_SIZE];
int8_t palette_color_delta[PALETTE_MAX_SIZE]; int8_t palette_color_delta[PALETTE_MAX_SIZE];
uint8_t best_index[PALETTE_MAX_SIZE];
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t best_palette[PALETTE_MAX_SIZE];
uint16_t best_literal[PALETTE_MAX_SIZE];
#else
uint8_t best_palette[PALETTE_MAX_SIZE];
uint8_t best_literal[PALETTE_MAX_SIZE];
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // CONFIG_PALETTE #endif // CONFIG_PALETTE
#if CONFIG_INTRABC #if CONFIG_INTRABC
if (is_intrabc_mode(A)) A = DC_PRED; if (is_intrabc_mode(A)) A = DC_PRED;
@ -1939,6 +1945,12 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
#if CONFIG_PALETTE #if CONFIG_PALETTE
mic->mbmi.current_palette_size = cpi->common.current_palette_size; mic->mbmi.current_palette_size = cpi->common.current_palette_size;
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
colors = vp9_count_colors_highbd(src, src_stride, rows, cols,
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
colors = vp9_count_colors(src, src_stride, rows, cols); colors = vp9_count_colors(src, src_stride, rows, cols);
if (colors > 1 && colors <= 64 && cpi->common.allow_palette_mode) { if (colors > 1 && colors <= 64 && cpi->common.allow_palette_mode) {
int n, r, c, i, j, temp, max_itr = 200, k; int n, r, c, i, j, temp, max_itr = 200, k;
@ -1948,13 +1960,25 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
int color_order[PALETTE_MAX_SIZE]; int color_order[PALETTE_MAX_SIZE];
int palette_size_cost[PALETTE_SIZES]; int palette_size_cost[PALETTE_SIZES];
double centroids[PALETTE_MAX_SIZE]; double centroids[PALETTE_MAX_SIZE];
double lb = src[0], ub = src[0], val;
int64_t local_tx_cache[TX_MODES]; int64_t local_tx_cache[TX_MODES];
uint8_t *color_map; uint8_t *color_map;
#if CONFIG_TX_SKIP #if CONFIG_TX_SKIP
int this_rate_tokenonly_s, s_s; int this_rate_tokenonly_s, s_s;
int64_t this_distortion_s; int64_t this_distortion_s;
#endif // CONFIG_TX_SKIP #endif // CONFIG_TX_SKIP
double lb, ub, val;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
if (cpi->common.use_highbitdepth) {
lb = src16[0];
ub = src16[0];
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
lb = src[0];
ub = src[0];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
vpx_memset(x->kmeans_data_buffer, 0, vpx_memset(x->kmeans_data_buffer, 0,
sizeof(x->kmeans_data_buffer[0] * 4096)); sizeof(x->kmeans_data_buffer[0] * 4096));
@ -1970,6 +1994,12 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
mic->mbmi.mode = DC_PRED; mic->mbmi.mode = DC_PRED;
for (r = 0; r < rows; r++) { for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
val = src16[r * src_stride + c];
else
#endif // CONFIG_VP9_HIGHBITDEPTH
val = src[r * src_stride + c]; val = src[r * src_stride + c];
x->kmeans_data_buffer[r * cols + c] = val; x->kmeans_data_buffer[r * cols + c] = val;
if (val < lb) if (val < lb)
@ -2001,8 +2031,15 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
} }
} }
for (i = 0; i < k; i++) for (i = 0; i < k; i++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
mic->mbmi.palette_colors[i] = clip_pixel_highbd(round(centroids[i]),
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
mic->mbmi.palette_colors[i] = clip_pixel(round(centroids[i])); mic->mbmi.palette_colors[i] = clip_pixel(round(centroids[i]));
}
best_total_bits = INT_MAX; best_total_bits = INT_MAX;
for (bits = 0; bits < 1 << PALETTE_DELTA_BIT; bits++) { for (bits = 0; bits < 1 << PALETTE_DELTA_BIT; bits++) {
@ -2025,7 +2062,7 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
} }
} }
total_bits = m1 * vp9_ceil_log2(cpi->common.current_palette_size) + total_bits = m1 * vp9_ceil_log2(cpi->common.current_palette_size) +
m1 * (bits == 0 ? 0 : bits + 1) + m2 * 8; m1 * (bits == 0 ? 0 : bits + 1) + m2 * cpi->common.bit_depth;
if (total_bits <= best_total_bits) { if (total_bits <= best_total_bits) {
best_total_bits = total_bits; best_total_bits = total_bits;
best_bits = bits; best_bits = bits;
@ -2115,7 +2152,8 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
this_rate = this_rate_tokenonly + this_rate = this_rate_tokenonly +
(1 + vp9_encode_uniform_cost(MIN(k + 1, 8), m1) + PALETTE_DELTA_BIT (1 + vp9_encode_uniform_cost(MIN(k + 1, 8), m1) + PALETTE_DELTA_BIT
+ vp9_ceil_log2(mic->mbmi.current_palette_size) * m1 + + vp9_ceil_log2(mic->mbmi.current_palette_size) * m1 +
best_bits * m1 + 8 * m2) * vp9_cost_bit(128, 0) + best_bits * m1 +
cpi->common.bit_depth * m2) * vp9_cost_bit(128, 0) +
palette_size_cost[k - 2]; palette_size_cost[k - 2];
color_map = xd->plane[0].color_index_map; color_map = xd->plane[0].color_index_map;
this_rate += vp9_ceil_log2(k) * vp9_cost_bit(128, 0); this_rate += vp9_ceil_log2(k) * vp9_cost_bit(128, 0);
@ -2169,7 +2207,7 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
} }
} }
} }
#endif #endif // CONFIG_PALETTE
mic->mbmi.mode = mode_selected; mic->mbmi.mode = mode_selected;
#if CONFIG_FILTERINTRA #if CONFIG_FILTERINTRA
@ -2375,7 +2413,11 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
int cols = (4 * num_4x4_blocks_wide_lookup[bsize]) >> int cols = (4 * num_4x4_blocks_wide_lookup[bsize]) >>
(xd->plane[1].subsampling_y); (xd->plane[1].subsampling_y);
int src_stride = x->plane[1].src.stride; int src_stride = x->plane[1].src.stride;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t best_palette[2 * PALETTE_MAX_SIZE];
#else
uint8_t best_palette[2 * PALETTE_MAX_SIZE]; uint8_t best_palette[2 * PALETTE_MAX_SIZE];
#endif
uint8_t *src_u = x->plane[1].src.buf; uint8_t *src_u = x->plane[1].src.buf;
uint8_t *src_v = x->plane[2].src.buf; uint8_t *src_v = x->plane[2].src.buf;
MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
@ -2513,9 +2555,22 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
if (xd->mi[0].src_mi->mbmi.sb_type >= BLOCK_8X8 && if (xd->mi[0].src_mi->mbmi.sb_type >= BLOCK_8X8 &&
(xd->plane[1].subsampling_x || xd->plane[1].subsampling_y) && (xd->plane[1].subsampling_x || xd->plane[1].subsampling_y) &&
cpi->common.allow_palette_mode) { cpi->common.allow_palette_mode) {
int colors_u = vp9_count_colors(src_u, src_stride, rows, cols); int colors_u, colors_v, colors;
int colors_v = vp9_count_colors(src_v, src_stride, rows, cols); #if CONFIG_VP9_HIGHBITDEPTH
int colors = colors_u > colors_v ? colors_u : colors_v; if (cpi->common.use_highbitdepth) {
colors_u = vp9_count_colors_highbd(src_u, src_stride, rows, cols,
cpi->common.bit_depth);
colors_v = vp9_count_colors_highbd(src_v, src_stride, rows, cols,
cpi->common.bit_depth);
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
colors_u = vp9_count_colors(src_u, src_stride, rows, cols);
colors_v = vp9_count_colors(src_v, src_stride, rows, cols);
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
colors = colors_u > colors_v ? colors_u : colors_v;
if (colors > 1 && colors <= 64) { if (colors > 1 && colors <= 64) {
int n, r, c, i, j, max_itr = 200; int n, r, c, i, j, max_itr = 200;
@ -2523,14 +2578,32 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
int color_order[PALETTE_MAX_SIZE]; int color_order[PALETTE_MAX_SIZE];
int palette_size_cost[PALETTE_SIZES]; int palette_size_cost[PALETTE_SIZES];
double centroids[2 * PALETTE_MAX_SIZE]; double centroids[2 * PALETTE_MAX_SIZE];
double lb_u = src_u[0], ub_u = src_u[0];
double lb_v = src_v[0], ub_v = src_v[0], val;
BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, &xd->plane[1]); BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, &xd->plane[1]);
uint8_t *color_map; uint8_t *color_map;
#if CONFIG_TX_SKIP #if CONFIG_TX_SKIP
int this_rate_tokenonly_s, s_s; int this_rate_tokenonly_s, s_s;
int64_t this_distortion_s; int64_t this_distortion_s;
#endif // CONFIG_TX_SKIP #endif // CONFIG_TX_SKIP
double lb_u, ub_u, val_u;
double lb_v, ub_v, val_v;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t *src_u16 = CONVERT_TO_SHORTPTR(src_u);
uint16_t *src_v16 = CONVERT_TO_SHORTPTR(src_v);
if (cpi->common.use_highbitdepth) {
lb_u = src_u16[0];
ub_u = src_u16[0];
lb_v = src_v16[0];
ub_v = src_v16[0];
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
lb_u = src_u[0];
ub_u = src_u[0];
lb_v = src_v[0];
ub_v = src_v[0];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
i = uv_bsize - BLOCK_4X4; i = uv_bsize - BLOCK_4X4;
vp9_cost_tokens(palette_size_cost, vp9_cost_tokens(palette_size_cost,
@ -2544,22 +2617,35 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
for (r = 0; r < rows; r++) { for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
x->kmeans_data_buffer[(r * cols + c) * 2 ] = #if CONFIG_VP9_HIGHBITDEPTH
src_u[r * src_stride + c]; if (cpi->common.use_highbitdepth) {
x->kmeans_data_buffer[(r * cols + c) * 2 + 1] = x->kmeans_data_buffer[(r * cols + c) * 2 ] =
src_v[r * src_stride + c]; src_u16[r * src_stride + c];
val = src_u[r * src_stride + c]; x->kmeans_data_buffer[(r * cols + c) * 2 + 1] =
if (val < lb_u) src_v16[r * src_stride + c];
lb_u = val; val_u = src_u16[r * src_stride + c];
else if (val > ub_u) val_v = src_v16[r * src_stride + c];
ub_u = val; } else {
val = src_v[r * src_stride + c]; #endif // CONFIG_VP9_HIGHBITDEPTH
if (val < lb_v) x->kmeans_data_buffer[(r * cols + c) * 2 ] =
lb_v = val; src_u[r * src_stride + c];
else if (val > ub_v) x->kmeans_data_buffer[(r * cols + c) * 2 + 1] =
ub_v = val; src_v[r * src_stride + c];
} val_u = src_u[r * src_stride + c];
} val_v = src_v[r * src_stride + c];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
if (val_u < lb_u)
lb_u = val_u;
else if (val_u > ub_u)
ub_u = val_u;
if (val_v < lb_v)
lb_v = val_v;
else if (val_v > ub_v)
ub_v = val_v;
}
}
for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors;
n >= 2; n--) { n >= 2; n--) {
@ -2573,9 +2659,17 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
mbmi->palette_size[1] = n; mbmi->palette_size[1] = n;
for (i = 1; i < 3; i++) { for (i = 1; i < 3; i++) {
for (j = 0; j < n; j++) for (j = 0; j < n; j++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] =
clip_pixel_highbd(round(centroids[j * 2 + i - 1]),
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] = mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] =
clip_pixel(round(centroids[j * 2 + i - 1])); clip_pixel(round(centroids[j * 2 + i - 1]));
}
} }
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
@ -2624,7 +2718,7 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
color_map = xd->plane[1].color_index_map; color_map = xd->plane[1].color_index_map;
this_rate = this_rate_tokenonly + this_rate = this_rate_tokenonly +
(1 + 2 * 8 * n) * vp9_cost_bit(128, 0) + (1 + 2 * cpi->common.bit_depth * n) * vp9_cost_bit(128, 0) +
palette_size_cost[n - 2]; palette_size_cost[n - 2];
this_rate += vp9_ceil_log2(n) * vp9_cost_bit(128, 0); this_rate += vp9_ceil_log2(n) * vp9_cost_bit(128, 0);
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
@ -5462,12 +5556,25 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
int src_stride_y = x->plane[0].src.stride; int src_stride_y = x->plane[0].src.stride;
int src_stride_uv = x->plane[1].src.stride; int src_stride_uv = x->plane[1].src.stride;
int colors = vp9_count_colors(src_y, src_stride_y, rows, cols); int colors;
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
colors = vp9_count_colors_highbd(src_y, src_stride_y, rows, cols,
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
colors = vp9_count_colors(src_y, src_stride_y, rows, cols);
if (colors >= 2 && colors <= 64 && cm->allow_palette_mode) { if (colors >= 2 && colors <= 64 && cm->allow_palette_mode) {
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t best_palette[PALETTE_MAX_SIZE * 3];
uint16_t best_literal[PALETTE_MAX_SIZE];
#else
uint8_t best_palette[PALETTE_MAX_SIZE * 3]; uint8_t best_palette[PALETTE_MAX_SIZE * 3];
uint8_t best_index[PALETTE_MAX_SIZE], best_literal[PALETTE_MAX_SIZE]; uint8_t best_literal[PALETTE_MAX_SIZE];
#endif // CONFIG_VP9_HIGHBITDEPTH
int8_t palette_color_delta[PALETTE_MAX_SIZE]; int8_t palette_color_delta[PALETTE_MAX_SIZE];
uint8_t best_index[PALETTE_MAX_SIZE];
int64_t local_tx_cache[TX_MODES], sse; int64_t local_tx_cache[TX_MODES], sse;
int m1, m2, n, best_bits, best_n = 0; int m1, m2, n, best_bits, best_n = 0;
int r, c, i, j, max_itr = 200; int r, c, i, j, max_itr = 200;
@ -5476,7 +5583,6 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
int color_ctx = 0, color_idx = 0; int color_ctx = 0, color_idx = 0;
int color_order[PALETTE_MAX_SIZE]; int color_order[PALETTE_MAX_SIZE];
double centroids[3 * PALETTE_MAX_SIZE]; double centroids[3 * PALETTE_MAX_SIZE];
double lb = src_y[0], ub = src_y[0];
MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
MB_MODE_INFO mbmi_copy; MB_MODE_INFO mbmi_copy;
RD_COST palette_rd, palette_best_rd; RD_COST palette_rd, palette_best_rd;
@ -5489,6 +5595,22 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
int tx_skipped = 0, tx_skipped_uv = 0; int tx_skipped = 0, tx_skipped_uv = 0;
int64_t this_distortion_s; int64_t this_distortion_s;
#endif // CONFIG_TX_SKIP #endif // CONFIG_TX_SKIP
double lb = src_y[0], ub = src_y[0];
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t *src_y16 = CONVERT_TO_SHORTPTR(src_y);
uint16_t *src_u16 = CONVERT_TO_SHORTPTR(src_u);
uint16_t *src_v16 = CONVERT_TO_SHORTPTR(src_v);
if (cpi->common.use_highbitdepth) {
lb = src_y16[0];
ub = src_y16[0];
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
lb = src_y[0];
ub = src_y[0];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
palette_best_rd.rate = INT_MAX; palette_best_rd.rate = INT_MAX;
palette_best_rd.dist = INT64_MAX; palette_best_rd.dist = INT64_MAX;
@ -5512,11 +5634,25 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
#endif // CONFIG_FILTERINTRA #endif // CONFIG_FILTERINTRA
for (r = 0; r < rows; r++) { for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth) {
x->kmeans_data_buffer[(r * cols + c) * 3] =
src_y16[r * src_stride_y + c];
x->kmeans_data_buffer[(r * cols + c) * 3 + 1] =
src_u16[r * src_stride_uv + c];
x->kmeans_data_buffer[(r * cols + c) * 3 + 2] =
src_v16[r * src_stride_uv + c];
} else {
#endif // CONFIG_VP9_HIGHBITDEPTH
x->kmeans_data_buffer[(r * cols + c) * 3] = src_y[r * src_stride_y + c]; x->kmeans_data_buffer[(r * cols + c) * 3] = src_y[r * src_stride_y + c];
x->kmeans_data_buffer[(r * cols + c) * 3 + 1] = x->kmeans_data_buffer[(r * cols + c) * 3 + 1] =
src_u[r * src_stride_uv + c]; src_u[r * src_stride_uv + c];
x->kmeans_data_buffer[(r * cols + c) * 3 + 2] = x->kmeans_data_buffer[(r * cols + c) * 3 + 2] =
src_v[r * src_stride_uv + c]; src_v[r * src_stride_uv + c];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif // CONFIG_VP9_HIGHBITDEPTH
} }
} }
@ -5530,9 +5666,17 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
r = vp9_k_means(x->kmeans_data_buffer, centroids, r = vp9_k_means(x->kmeans_data_buffer, centroids,
x->kmeans_indices_buffer, rows * cols, n, 3, max_itr); x->kmeans_indices_buffer, rows * cols, n, 3, max_itr);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
for (j = 0; j < n; j++) for (j = 0; j < n; j++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] =
clip_pixel_highbd(round(centroids[j * 3 + i]),
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] = mbmi->palette_colors[i * PALETTE_MAX_SIZE + j] =
clip_pixel(round(centroids[j * 3 + i])); clip_pixel(round(centroids[j * 3 + i]));
}
} }
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
for (c = 0; c < cols; c++) for (c = 0; c < cols; c++)
@ -5609,7 +5753,8 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
continue; continue;
rate_y = rate_y_tokenonly + rate_y = rate_y_tokenonly +
(1 + PALETTE_DELTA_BIT + n * m2) * vp9_cost_bit(128, 0) + (1 + PALETTE_DELTA_BIT + cpi->common.bit_depth * m2) *
vp9_cost_bit(128, 0) +
palette_size_cost[n - 2]; palette_size_cost[n - 2];
color_map = xd->plane[0].color_index_map; color_map = xd->plane[0].color_index_map;
rate_y += vp9_ceil_log2(n) * vp9_cost_bit(128, 0); rate_y += vp9_ceil_log2(n) * vp9_cost_bit(128, 0);
@ -5626,7 +5771,8 @@ static void rd_pick_palette_444(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost,
rate_y += cpi->palette_color_costs[n - 2][color_ctx][color_idx]; rate_y += cpi->palette_color_costs[n - 2][color_ctx][color_idx];
} }
} }
rate_uv = rate_uv_tokenonly + (1 + 8 * 2 * n) * vp9_cost_bit(128, 0); rate_uv = rate_uv_tokenonly +
(1 + cpi->common.bit_depth * 2 * n) * vp9_cost_bit(128, 0);
#if CONFIG_INTRABC #if CONFIG_INTRABC
if (cm->allow_intrabc_mode) if (cm->allow_intrabc_mode)
rate_y += vp9_cost_bit(INTRABC_PROB, 0); rate_y += vp9_cost_bit(INTRABC_PROB, 0);
@ -5929,9 +6075,15 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int palette_enabled_uv[TX_SIZES]; int palette_enabled_uv[TX_SIZES];
int palette_size_uv[TX_SIZES]; int palette_size_uv[TX_SIZES];
uint8_t *src = x->plane[0].src.buf; uint8_t *src = x->plane[0].src.buf;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t best_palette[PALETTE_MAX_SIZE];
uint16_t palette_colors_uv[TX_SIZES][2 * PALETTE_MAX_SIZE];
uint16_t palette_color_map_uv[TX_SIZES][4096];
#else
uint8_t best_palette[PALETTE_MAX_SIZE]; uint8_t best_palette[PALETTE_MAX_SIZE];
uint8_t palette_colors_uv[TX_SIZES][2 * PALETTE_MAX_SIZE]; uint8_t palette_colors_uv[TX_SIZES][2 * PALETTE_MAX_SIZE];
uint8_t palette_color_map_uv[TX_SIZES][4096]; uint8_t palette_color_map_uv[TX_SIZES][4096];
#endif // CONFIG_VP9_HIGHBITDEPTH
const MODE_INFO *above_mi = xd->up_available ? const MODE_INFO *above_mi = xd->up_available ?
xd->mi[-xd->mi_stride].src_mi : NULL; xd->mi[-xd->mi_stride].src_mi : NULL;
const MODE_INFO *left_mi = xd->left_available ? const MODE_INFO *left_mi = xd->left_available ?
@ -7140,6 +7292,12 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
!is_inter_block(mbmi)) { !is_inter_block(mbmi)) {
MB_MODE_INFO mbmi_copy = *mbmi; MB_MODE_INFO mbmi_copy = *mbmi;
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
colors = vp9_count_colors_highbd(src, src_stride, rows, cols,
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
colors = vp9_count_colors(src, src_stride, rows, cols); colors = vp9_count_colors(src, src_stride, rows, cols);
x->skip = 0; x->skip = 0;
if (colors > 1 && colors <= 64) { if (colors > 1 && colors <= 64) {
@ -7148,7 +7306,6 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int color_order[PALETTE_MAX_SIZE]; int color_order[PALETTE_MAX_SIZE];
int palette_size_cost[PALETTE_SIZES]; int palette_size_cost[PALETTE_SIZES];
double centroids[PALETTE_MAX_SIZE]; double centroids[PALETTE_MAX_SIZE];
double lb = src[0], ub = src[0], val;
int64_t this_rd = INT64_MAX, this_rd_y, best_rd_y; int64_t this_rd = INT64_MAX, this_rd_y, best_rd_y;
int rate2, rate_y , rate_uv, best_token_rate_y = INT_MAX; int rate2, rate_y , rate_uv, best_token_rate_y = INT_MAX;
@ -7165,7 +7322,19 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int64_t tx_cache_s[TX_MODES]; int64_t tx_cache_s[TX_MODES];
int tx_skipped_y = 0; int tx_skipped_y = 0;
#endif // CONFIG_TX_SKIP #endif // CONFIG_TX_SKIP
double lb, ub, val;
#if CONFIG_VP9_HIGHBITDEPTH
uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
if (cpi->common.use_highbitdepth) {
lb = src16[0];
ub = src16[0];
} else {
#endif
lb = src[0];
ub = src[0];
#if CONFIG_VP9_HIGHBITDEPTH
}
#endif
vpx_memset(x->kmeans_data_buffer, 0, vpx_memset(x->kmeans_data_buffer, 0,
sizeof(x->kmeans_data_buffer[0] * 4096)); sizeof(x->kmeans_data_buffer[0] * 4096));
vpx_memset(x->kmeans_indices_buffer, 0, vpx_memset(x->kmeans_indices_buffer, 0,
@ -7178,6 +7347,11 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
mbmi->mode = DC_PRED; mbmi->mode = DC_PRED;
for (r = 0; r < rows; r++) { for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
val = src16[r * src_stride + c];
else
#endif
val = src[r * src_stride + c]; val = src[r * src_stride + c];
x->kmeans_data_buffer[r * cols + c] = val; x->kmeans_data_buffer[r * cols + c] = val;
if (val < lb) if (val < lb)
@ -7218,6 +7392,12 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
mbmi->palette_size[0] = k; mbmi->palette_size[0] = k;
for (i = 0; i < k; i++) { for (i = 0; i < k; i++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (cpi->common.use_highbitdepth)
mbmi->palette_colors[i] = clip_pixel_highbd(round(centroids[i]),
cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
mbmi->palette_colors[i] = clip_pixel(round(centroids[i])); mbmi->palette_colors[i] = clip_pixel(round(centroids[i]));
centroids[i] = (double) mbmi->palette_colors[i]; centroids[i] = (double) mbmi->palette_colors[i];
} }
@ -7263,7 +7443,7 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
} }
total_rate_y = rate_y + palette_size_cost[k - 2] + total_rate_y = rate_y + palette_size_cost[k - 2] +
8 * k * vp9_cost_bit(128, 0) + cpi->common.bit_depth * k * vp9_cost_bit(128, 0) +
vp9_cost_bit(cm->fc.palette_enabled_prob vp9_cost_bit(cm->fc.palette_enabled_prob
[bsize - BLOCK_8X8][palette_ctx], 1); [bsize - BLOCK_8X8][palette_ctx], 1);
color_map = xd->plane[0].color_index_map; color_map = xd->plane[0].color_index_map;