diff options
author | hui su <huisu@google.com> | 2015-12-03 12:30:47 -0800 |
---|---|---|
committer | hui su <huisu@google.com> | 2015-12-03 12:30:47 -0800 |
commit | 5d3327e891da9b8163f0150d3e52cc9f89016353 (patch) | |
tree | cea87b859f6609733bffb43ff25f7958c1931cff /vp10/encoder | |
parent | 623e988addfa8add7a21c69aa893ba42f7d5236e (diff) | |
download | libvpx-5d3327e891da9b8163f0150d3e52cc9f89016353.tar libvpx-5d3327e891da9b8163f0150d3e52cc9f89016353.tar.gz libvpx-5d3327e891da9b8163f0150d3e52cc9f89016353.tar.bz2 libvpx-5d3327e891da9b8163f0150d3e52cc9f89016353.zip |
Remove palette from VP10
Store it in nextgenv2 for now.
Change-Id: Iab0af0e15246758e3b6e8bde4a74b13c410576fc
Diffstat (limited to 'vp10/encoder')
-rw-r--r-- | vp10/encoder/bitstream.c | 73 | ||||
-rw-r--r-- | vp10/encoder/block.h | 9 | ||||
-rw-r--r-- | vp10/encoder/encodeframe.c | 19 | ||||
-rw-r--r-- | vp10/encoder/encoder.c | 14 | ||||
-rw-r--r-- | vp10/encoder/encoder.h | 6 | ||||
-rw-r--r-- | vp10/encoder/ethread.c | 7 | ||||
-rw-r--r-- | vp10/encoder/palette.c | 194 | ||||
-rw-r--r-- | vp10/encoder/palette.h | 35 | ||||
-rw-r--r-- | vp10/encoder/rd.c | 19 | ||||
-rw-r--r-- | vp10/encoder/rdopt.c | 197 | ||||
-rw-r--r-- | vp10/encoder/tokenize.c | 33 | ||||
-rw-r--r-- | vp10/encoder/tokenize.h | 3 |
12 files changed, 0 insertions, 609 deletions
diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c index d9b4be4e5..32275d4ae 100644 --- a/vp10/encoder/bitstream.c +++ b/vp10/encoder/bitstream.c @@ -44,20 +44,6 @@ 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); @@ -147,22 +133,6 @@ static void update_switchable_interp_probs(VP10_COMMON *cm, vpx_writer *w, counts->switchable_interp[j], SWITCHABLE_FILTERS, w); } -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) { @@ -402,36 +372,6 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi, } } -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; @@ -472,10 +412,6 @@ static void write_mb_modes_kf(const VP10_COMMON *cm, const MACROBLOCKD *xd, } write_intra_mode(w, mbmi->uv_mode, cm->fc->uv_mode_prob[mbmi->mode]); - - if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools && - mbmi->mode == DC_PRED) - write_palette_mode_info(cm, xd, mi, w); } static void write_modes_b(VP10_COMP *cpi, const TileInfo *const tile, @@ -502,13 +438,6 @@ 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) { @@ -1259,8 +1188,6 @@ 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); diff --git a/vp10/encoder/block.h b/vp10/encoder/block.h index df3830cb5..cb2a234c9 100644 --- a/vp10/encoder/block.h +++ b/vp10/encoder/block.h @@ -52,13 +52,6 @@ typedef struct { uint8_t mode_context[MAX_REF_FRAMES]; } MB_MODE_INFO_EXT; -typedef struct { - uint8_t best_palette_color_map[4096]; - double kmeans_data_buf[4096]; - uint8_t kmeans_indices_buf[4096]; - uint8_t kmeans_pre_indices_buf[4096]; -} PALETTE_BUFFER; - typedef struct macroblock MACROBLOCK; struct macroblock { struct macroblock_plane plane[MAX_MB_PLANE]; @@ -99,8 +92,6 @@ struct macroblock { int *nmvsadcost_hp[2]; int **mvsadcost; - PALETTE_BUFFER *palette_buffer; - // These define limits to motion vector components to prevent them // from extending outside the UMV borders int mv_col_min; diff --git a/vp10/encoder/encodeframe.c b/vp10/encoder/encodeframe.c index f303b01fc..f050905e7 100644 --- a/vp10/encoder/encodeframe.c +++ b/vp10/encoder/encodeframe.c @@ -1140,15 +1140,6 @@ static void rd_pick_sb_modes(VP10_COMP *cpi, p[i].eobs = ctx->eobs_pbuf[i][0]; } - if (cm->current_video_frame == 0 && cm->allow_screen_content_tools) { - for (i = 0; i < 2; ++i) { - if (ctx->color_index_map[i] == 0) { - CHECK_MEM_ERROR(cm, ctx->color_index_map[i], - vpx_memalign(16, (ctx->num_4x4_blk << 4) * - sizeof(*ctx->color_index_map[i]))); - } - } - } for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i]; @@ -2984,16 +2975,6 @@ static void encode_superblock(VP10_COMP *cpi, ThreadData *td, if (output_enabled) sum_intra_stats(td->counts, mi, xd->above_mi, xd->left_mi, frame_is_intra_only(cm)); - - if (bsize >= BLOCK_8X8 && output_enabled) { - if (mbmi->palette_mode_info.palette_size[0] > 0) { - mbmi->palette_mode_info.palette_first_color_idx[0] = - xd->plane[0].color_index_map[0]; - // TODO(huisu): this increases the use of token buffer. Needs stretch - // test to verify. - vp10_tokenize_palette_sb(td, bsize, 0, t); - } - } vp10_tokenize_sb(cpi, td, t, !output_enabled, VPXMAX(bsize, BLOCK_8X8)); } else { int ref; diff --git a/vp10/encoder/encoder.c b/vp10/encoder/encoder.c index 5b646a2f4..630f35e78 100644 --- a/vp10/encoder/encoder.c +++ b/vp10/encoder/encoder.c @@ -390,9 +390,6 @@ static void dealloc_compressor_data(VP10_COMP *cpi) { vp10_free_pc_tree(&cpi->td); - if (cpi->common.allow_screen_content_tools) - vpx_free(cpi->td.mb.palette_buffer); - if (cpi->source_diff_var != NULL) { vpx_free(cpi->source_diff_var); cpi->source_diff_var = NULL; @@ -1435,15 +1432,6 @@ void vp10_change_config(struct VP10_COMP *cpi, const VP10EncoderConfig *oxcf) { : REFRESH_FRAME_CONTEXT_BACKWARD; cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; - cm->allow_screen_content_tools = (cpi->oxcf.content == VP9E_CONTENT_SCREEN); - if (cm->allow_screen_content_tools) { - MACROBLOCK *x = &cpi->td.mb; - if (x->palette_buffer == 0) { - CHECK_MEM_ERROR(cm, x->palette_buffer, - vpx_memalign(16, sizeof(*x->palette_buffer))); - } - } - vp10_reset_segment_features(cm); vp10_set_high_precision_mv(cpi, 0); @@ -1949,8 +1937,6 @@ void vp10_remove_compressor(VP10_COMP *cpi) { // Deallocate allocated thread data. if (t < cpi->num_workers - 1) { - if (cpi->common.allow_screen_content_tools) - vpx_free(thread_data->td->mb.palette_buffer); vpx_free(thread_data->td->counts); vp10_free_pc_tree(thread_data->td); vpx_free(thread_data->td); diff --git a/vp10/encoder/encoder.h b/vp10/encoder/encoder.h index 7028803a6..8519c27a6 100644 --- a/vp10/encoder/encoder.h +++ b/vp10/encoder/encoder.h @@ -460,12 +460,6 @@ typedef struct VP10_COMP { int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; - int palette_y_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] - [PALETTE_COLORS]; - int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] - [PALETTE_COLORS]; int multi_arf_allowed; int multi_arf_enabled; diff --git a/vp10/encoder/ethread.c b/vp10/encoder/ethread.c index e20d532c3..ea491058a 100644 --- a/vp10/encoder/ethread.c +++ b/vp10/encoder/ethread.c @@ -128,13 +128,6 @@ void vp10_encode_tiles_mt(VP10_COMP *cpi) { memcpy(thread_data->td->counts, &cpi->common.counts, sizeof(cpi->common.counts)); } - - // Allocate buffers used by palette coding mode. - if (cpi->common.allow_screen_content_tools && i < num_workers - 1) { - MACROBLOCK *x = &thread_data->td->mb; - CHECK_MEM_ERROR(cm, x->palette_buffer, - vpx_memalign(16, sizeof(*x->palette_buffer))); - } } // Encode a frame diff --git a/vp10/encoder/palette.c b/vp10/encoder/palette.c deleted file mode 100644 index 522e1850e..000000000 --- a/vp10/encoder/palette.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2015 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include <math.h> -#include "vp10/encoder/palette.h" - -static double calc_dist(const double *p1, const double *p2, int dim) { - double dist = 0; - int i = 0; - - for (i = 0; i < dim; ++i) { - dist = dist + (p1[i] - round(p2[i])) * (p1[i] - round(p2[i])); - } - return dist; -} - -void vp10_calc_indices(const double *data, const double *centroids, - uint8_t *indices, int n, int k, int dim) { - int i, j; - double min_dist, this_dist; - - for (i = 0; i < n; ++i) { - min_dist = calc_dist(data + i * dim, centroids, dim); - indices[i] = 0; - for (j = 1; j < k; ++j) { - this_dist = calc_dist(data + i * dim, centroids + j * dim, dim); - if (this_dist < min_dist) { - min_dist = this_dist; - indices[i] = j; - } - } - } -} - -// Generate a random number in the range [0, 32768). -static unsigned int lcg_rand16(unsigned int *state) { - *state = *state * 1103515245 + 12345; - return *state / 65536 % 32768; -} - -static void calc_centroids(const double *data, double *centroids, - const uint8_t *indices, int n, int k, int dim) { - int i, j, index; - int count[PALETTE_MAX_SIZE]; - unsigned int rand_state = (unsigned int)data[0]; - - assert(n <= 32768); - - memset(count, 0, sizeof(count[0]) * k); - memset(centroids, 0, sizeof(centroids[0]) * k * dim); - - for (i = 0; i < n; ++i) { - index = indices[i]; - assert(index < k); - ++count[index]; - for (j = 0; j < dim; ++j) { - centroids[index * dim + j] += data[i * dim + j]; - } - } - - for (i = 0; i < k; ++i) { - if (count[i] == 0) { - memcpy(centroids + i * dim, data + (lcg_rand16(&rand_state) % n) * dim, - sizeof(centroids[0]) * dim); - } else { - const double norm = 1.0 / count[i]; - for (j = 0; j < dim; ++j) - centroids[i * dim + j] *= norm; - } - } -} - -static double calc_total_dist(const double *data, const double *centroids, - const uint8_t *indices, int n, int k, int dim) { - double dist = 0; - int i; - (void) k; - - for (i = 0; i < n; ++i) - dist += calc_dist(data + i * dim, centroids + indices[i] * dim, dim); - - return dist; -} - -int vp10_k_means(const double *data, double *centroids, uint8_t *indices, - uint8_t *pre_indices, int n, int k, int dim, int max_itr) { - int i = 0; - double pre_dist, this_dist; - double pre_centroids[PALETTE_MAX_SIZE]; - - vp10_calc_indices(data, centroids, indices, n, k, dim); - pre_dist = calc_total_dist(data, centroids, indices, n, k, dim); - memcpy(pre_centroids, centroids, sizeof(pre_centroids[0]) * k * dim); - memcpy(pre_indices, indices, sizeof(pre_indices[0]) * n); - while (i < max_itr) { - calc_centroids(data, centroids, indices, n, k, dim); - vp10_calc_indices(data, centroids, indices, n, k, dim); - this_dist = calc_total_dist(data, centroids, indices, n, k, dim); - - if (this_dist > pre_dist) { - memcpy(centroids, pre_centroids, sizeof(pre_centroids[0]) * k * dim); - memcpy(indices, pre_indices, sizeof(pre_indices[0]) * n); - break; - } - if (!memcmp(centroids, pre_centroids, sizeof(pre_centroids[0]) * k * dim)) - break; - - memcpy(pre_centroids, centroids, sizeof(pre_centroids[0]) * k * dim); - memcpy(pre_indices, indices, sizeof(pre_indices[0]) * n); - pre_dist = this_dist; - ++i; - } - - return i; -} - -void vp10_insertion_sort(double *data, int n) { - int i, j, k; - double val; - - if (n <= 1) - return; - - for (i = 1; i < n; ++i) { - val = data[i]; - j = 0; - while (val > data[j] && j < i) - ++j; - - if (j == i) - continue; - - for (k = i; k > j; --k) - data[k] = data[k - 1]; - data[j] = val; - } -} - -int vp10_count_colors(const uint8_t *src, int stride, int rows, int cols) { - int n = 0, r, c, i, val_count[256]; - uint8_t val; - memset(val_count, 0, 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 < 256; ++i) { - if (val_count[i]) { - ++n; - } - } - - return n; -} - -#if CONFIG_VP9_HIGHBITDEPTH -int vp10_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[1 << 12]; - - assert(bit_depth <= 12); - memset(val_count, 0, (1 << 12) * sizeof(val_count[0])); - 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; - } - } - - return n; -} -#endif // CONFIG_VP9_HIGHBITDEPTH - - diff --git a/vp10/encoder/palette.h b/vp10/encoder/palette.h deleted file mode 100644 index 124cf7447..000000000 --- a/vp10/encoder/palette.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2015 The WebM project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef VP10_ENCODER_PALETTE_H_ -#define VP10_ENCODER_PALETTE_H_ - -#include "vp10/common/blockd.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void vp10_insertion_sort(double *data, int n); -void vp10_calc_indices(const double *data, const double *centroids, - uint8_t *indices, int n, int k, int dim); -int vp10_k_means(const double *data, double *centroids, uint8_t *indices, - uint8_t *pre_indices, int n, int k, int dim, int max_itr); -int vp10_count_colors(const uint8_t *src, int stride, int rows, int cols); -#if CONFIG_VP9_HIGHBITDEPTH -int vp10_count_colors_highbd(const uint8_t *src8, int stride, int rows, - int cols, int bit_depth); -#endif // CONFIG_VP9_HIGHBITDEPTH - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* VP10_ENCODER_PALETTE_H_ */ diff --git a/vp10/encoder/rd.c b/vp10/encoder/rd.c index 4ed1ae2be..5623a7202 100644 --- a/vp10/encoder/rd.c +++ b/vp10/encoder/rd.c @@ -83,25 +83,6 @@ static void fill_mode_costs(VP10_COMP *cpi) { for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) vp10_cost_tokens(cpi->switchable_interp_costs[i], fc->switchable_interp_prob[i], vp10_switchable_interp_tree); - - for (i = 0; i < PALETTE_BLOCK_SIZES; ++i) { - vp10_cost_tokens(cpi->palette_y_size_cost[i], - vp10_default_palette_y_size_prob[i], - vp10_palette_size_tree); - vp10_cost_tokens(cpi->palette_uv_size_cost[i], - vp10_default_palette_uv_size_prob[i], - vp10_palette_size_tree); - } - - for (i = 0; i < PALETTE_MAX_SIZE - 1; ++i) - for (j = 0; j < PALETTE_COLOR_CONTEXTS; ++j) { - vp10_cost_tokens(cpi->palette_y_color_cost[i][j], - vp10_default_palette_y_color_prob[i][j], - vp10_palette_color_tree[i]); - vp10_cost_tokens(cpi->palette_uv_color_cost[i][j], - vp10_default_palette_uv_color_prob[i][j], - vp10_palette_color_tree[i]); - } } static void fill_token_costs(vp10_coeff_cost *c, diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c index d87d16418..974700e19 100644 --- a/vp10/encoder/rdopt.c +++ b/vp10/encoder/rdopt.c @@ -36,7 +36,6 @@ #include "vp10/encoder/encodemv.h" #include "vp10/encoder/encoder.h" #include "vp10/encoder/mcomp.h" -#include "vp10/encoder/palette.h" #include "vp10/encoder/quantize.h" #include "vp10/encoder/ratectrl.h" #include "vp10/encoder/rd.h" @@ -760,163 +759,6 @@ static int conditional_skipintra(PREDICTION_MODE mode, return 0; } -void rd_pick_palette_intra_sby(VP10_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, - int palette_ctx, int dc_mode_cost, - PALETTE_MODE_INFO *palette_mode_info, - uint8_t *best_palette_color_map, - TX_SIZE *best_tx, PREDICTION_MODE *mode_selected, - int64_t *best_rd) { - MACROBLOCKD *const xd = &x->e_mbd; - MODE_INFO *const mic = xd->mi[0]; - int rows = 4 * num_4x4_blocks_high_lookup[bsize]; - int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; - int this_rate, this_rate_tokenonly, s; - int64_t this_distortion, this_rd; - int colors, n; - int src_stride = x->plane[0].src.stride; - uint8_t *src = x->plane[0].src.buf; - -#if CONFIG_VP9_HIGHBITDEPTH - if (cpi->common.use_highbitdepth) - colors = vp10_count_colors_highbd(src, src_stride, rows, cols, - cpi->common.bit_depth); - else -#endif // CONFIG_VP9_HIGHBITDEPTH - colors = vp10_count_colors(src, src_stride, rows, cols); - palette_mode_info->palette_size[0] = 0; - - if (colors > 1 && colors <= 64 && cpi->common.allow_screen_content_tools) { - int r, c, i, j, k; - int max_itr = 50; - int color_ctx, color_idx = 0; - int color_order[PALETTE_MAX_SIZE]; - double *data = x->palette_buffer->kmeans_data_buf; - uint8_t *indices = x->palette_buffer->kmeans_indices_buf; - uint8_t *pre_indices = x->palette_buffer->kmeans_pre_indices_buf; - double centroids[PALETTE_MAX_SIZE]; - uint8_t *color_map; - double lb, ub, val; - PALETTE_MODE_INFO *pmi = &mic->mbmi.palette_mode_info; -#if CONFIG_VP9_HIGHBITDEPTH - uint16_t *src16 = CONVERT_TO_SHORTPTR(src); - if (cpi->common.use_highbitdepth) - lb = ub = src16[0]; - else -#endif // CONFIG_VP9_HIGHBITDEPTH - lb = ub = src[0]; - -#if CONFIG_VP9_HIGHBITDEPTH - if (cpi->common.use_highbitdepth) { - for (r = 0; r < rows; ++r) { - for (c = 0; c < cols; ++c) { - val = src16[r * src_stride + c]; - data[r * cols + c] = val; - if (val < lb) - lb = val; - else if (val > ub) - ub = val; - } - } - } else { -#endif // CONFIG_VP9_HIGHBITDEPTH - for (r = 0; r < rows; ++r) { - for (c = 0; c < cols; ++c) { - val = src[r * src_stride + c]; - data[r * cols + c] = val; - if (val < lb) - lb = val; - else if (val > ub) - ub = val; - } - } -#if CONFIG_VP9_HIGHBITDEPTH - } -#endif // CONFIG_VP9_HIGHBITDEPTH - - mic->mbmi.mode = DC_PRED; - - for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; - n >= 2; --n) { - for (i = 0; i < n; ++i) - centroids[i] = lb + (2 * i + 1) * (ub - lb) / n / 2; - vp10_k_means(data, centroids, indices, pre_indices, rows * cols, - n, 1, max_itr); - vp10_insertion_sort(centroids, n); - for (i = 0; i < n; ++i) - centroids[i] = round(centroids[i]); - // remove duplicates - i = 1; - k = n; - while (i < k) { - if (centroids[i] == centroids[i - 1]) { - j = i; - while (j < k - 1) { - centroids[j] = centroids[j + 1]; - ++j; - } - --k; - } else { - ++i; - } - } - -#if CONFIG_VP9_HIGHBITDEPTH - if (cpi->common.use_highbitdepth) - for (i = 0; i < k; ++i) - mic->mbmi.palette_mode_info.palette_colors[i] = - clip_pixel_highbd(round(centroids[i]), cpi->common.bit_depth); - else -#endif // CONFIG_VP9_HIGHBITDEPTH - for (i = 0; i < k; ++i) - pmi->palette_colors[i] = clip_pixel((int)round(centroids[i])); - pmi->palette_size[0] = k; - - vp10_calc_indices(data, centroids, indices, rows * cols, k, 1); - for (r = 0; r < rows; ++r) - for (c = 0; c < cols; ++c) - xd->plane[0].color_index_map[r * cols + c] = indices[r * cols + c]; - - super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, - &s, NULL, bsize, *best_rd); - if (this_rate_tokenonly == INT_MAX) - continue; - - this_rate = this_rate_tokenonly + dc_mode_cost + - cpi->common.bit_depth * k * vp10_cost_bit(128, 0) + - cpi->palette_y_size_cost[bsize - BLOCK_8X8][k - 2]; - this_rate += - vp10_cost_bit(vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8] - [palette_ctx], 1); - color_map = xd->plane[0].color_index_map; - this_rate += write_uniform_cost(k, xd->plane[0].color_index_map[0]); - for (i = 0; i < rows; ++i) { - for (j = (i == 0 ? 1 : 0); j < cols; ++j) { - color_ctx = vp10_get_palette_color_context(color_map, cols, i, j, - k, color_order); - for (r = 0; r < k; ++r) - if (color_map[i * cols + j] == color_order[r]) { - color_idx = r; - break; - } - assert(color_idx < k); - this_rate += - cpi->palette_y_color_cost[k - 2][color_ctx][color_idx]; - } - } - this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); - - if (this_rd < *best_rd) { - *best_rd = this_rd; - *palette_mode_info = mic->mbmi.palette_mode_info; - memcpy(best_palette_color_map, xd->plane[0].color_index_map, - rows * cols * sizeof(xd->plane[0].color_index_map[0])); - *mode_selected = DC_PRED; - *best_tx = mic->mbmi.tx_size; - } - } - } -} - static int64_t rd_pick_intra4x4block(VP10_COMP *cpi, MACROBLOCK *x, int row, int col, PREDICTION_MODE *best_mode, @@ -947,7 +789,6 @@ static int64_t rd_pick_intra4x4block(VP10_COMP *cpi, MACROBLOCK *x, memcpy(ta, a, sizeof(ta)); memcpy(tl, l, sizeof(tl)); xd->mi[0]->mbmi.tx_size = TX_4X4; - xd->mi[0]->mbmi.palette_mode_info.palette_size[0] = 0; #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { @@ -1225,12 +1066,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, int64_t this_distortion, this_rd; TX_SIZE best_tx = TX_4X4; int *bmode_costs; - PALETTE_MODE_INFO palette_mode_info; - uint8_t *best_palette_color_map = cpi->common.allow_screen_content_tools ? - x->palette_buffer->best_palette_color_map : NULL; - int rows = 4 * num_4x4_blocks_high_lookup[bsize]; - int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; - int palette_ctx = 0; const MODE_INFO *above_mi = xd->above_mi; const MODE_INFO *left_mi = xd->left_mi; const PREDICTION_MODE A = vp10_above_block_mode(mic, above_mi, 0); @@ -1238,12 +1073,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, bmode_costs = cpi->y_mode_costs[A][L]; memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); - palette_mode_info.palette_size[0] = 0; - mic->mbmi.palette_mode_info.palette_size[0] = 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); /* Y Search for intra prediction mode */ for (mode = DC_PRED; mode <= TM_PRED; mode++) { @@ -1256,10 +1085,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, continue; this_rate = this_rate_tokenonly + bmode_costs[mode]; - if (cpi->common.allow_screen_content_tools && mode == DC_PRED) - this_rate += - vp10_cost_bit(vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8] - [palette_ctx], 0); this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); if (this_rd < best_rd) { @@ -1273,22 +1098,8 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, } } - if (cpi->common.allow_screen_content_tools) - rd_pick_palette_intra_sby(cpi, x, bsize, palette_ctx, bmode_costs[DC_PRED], - &palette_mode_info, best_palette_color_map, - &best_tx, &mode_selected, &best_rd); - mic->mbmi.mode = mode_selected; mic->mbmi.tx_size = best_tx; - mic->mbmi.palette_mode_info.palette_size[0] = - palette_mode_info.palette_size[0]; - if (palette_mode_info.palette_size[0] > 0) { - memcpy(mic->mbmi.palette_mode_info.palette_colors, - palette_mode_info.palette_colors, - PALETTE_MAX_SIZE * sizeof(palette_mode_info.palette_colors[0])); - memcpy(xd->plane[0].color_index_map, best_palette_color_map, - rows * cols * sizeof(best_palette_color_map[0])); - } return best_rd; } @@ -1359,7 +1170,6 @@ static int64_t rd_pick_intra_sbuv_mode(VP10_COMP *cpi, MACROBLOCK *x, int64_t this_distortion, this_sse; memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); - xd->mi[0]->mbmi.palette_mode_info.palette_size[1] = 0; for (mode = DC_PRED; mode <= TM_PRED; ++mode) { if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) continue; @@ -3292,8 +3102,6 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi, midx = end_pos; } - mbmi->palette_mode_info.palette_size[0] = 0; - mbmi->palette_mode_info.palette_size[1] = 0; for (midx = 0; midx < MAX_MODES; ++midx) { int mode_index = mode_map[midx]; int mode_excluded = 0; @@ -3773,8 +3581,6 @@ void vp10_rd_pick_inter_mode_sb_seg_skip(VP10_COMP *cpi, assert(segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)); - mbmi->palette_mode_info.palette_size[0] = 0; - mbmi->palette_mode_info.palette_size[1] = 0; mbmi->mode = ZEROMV; mbmi->uv_mode = DC_PRED; mbmi->ref_frame[0] = LAST_FRAME; @@ -3922,9 +3728,6 @@ void vp10_rd_pick_inter_mode_sub8x8(VP10_COMP *cpi, frame_mv[ZEROMV][ref_frame].as_int = 0; } - mbmi->palette_mode_info.palette_size[0] = 0; - mbmi->palette_mode_info.palette_size[1] = 0; - for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { int mode_excluded = 0; int64_t this_rd = INT64_MAX; diff --git a/vp10/encoder/tokenize.c b/vp10/encoder/tokenize.c index e568c0ba5..1b94190b7 100644 --- a/vp10/encoder/tokenize.c +++ b/vp10/encoder/tokenize.c @@ -487,39 +487,6 @@ static INLINE int get_tx_eob(const struct segmentation *seg, int segment_id, return segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; } -void vp10_tokenize_palette_sb(struct ThreadData *const td, - BLOCK_SIZE bsize, int plane, - TOKENEXTRA **t) { - MACROBLOCK *const x = &td->mb; - MACROBLOCKD *const xd = &x->e_mbd; - MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; - uint8_t *color_map = xd->plane[0].color_index_map; - PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info; - int n = pmi->palette_size[plane != 0]; - int i, j, k; - int color_new_idx = -1, color_ctx, color_order[PALETTE_MAX_SIZE]; - int rows = 4 * num_4x4_blocks_high_lookup[bsize]; - int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; - - for (i = 0; i < rows; ++i) { - for (j = (i == 0 ? 1 : 0); j < cols; ++j) { - color_ctx = vp10_get_palette_color_context(color_map, cols, i, j, n, - color_order); - for (k = 0; k < n; ++k) - if (color_map[i * cols + j] == color_order[k]) { - color_new_idx = k; - break; - } - assert(color_new_idx >= 0 && color_new_idx < n); - - (*t)->token = color_new_idx; - (*t)->context_tree = vp10_default_palette_y_color_prob[n - 2][color_ctx]; - (*t)->skip_eob_node = 0; - ++(*t); - } - } -} - static void tokenize_b(int plane, int block, int blk_row, int blk_col, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg) { diff --git a/vp10/encoder/tokenize.h b/vp10/encoder/tokenize.h index 1614add98..5bad415a9 100644 --- a/vp10/encoder/tokenize.h +++ b/vp10/encoder/tokenize.h @@ -51,9 +51,6 @@ int vp10_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane); struct VP10_COMP; struct ThreadData; -void vp10_tokenize_palette_sb(struct ThreadData *const td, - BLOCK_SIZE bsize, int plane, - TOKENEXTRA **t); void vp10_tokenize_sb(struct VP10_COMP *cpi, struct ThreadData *td, TOKENEXTRA **t, int dry_run, BLOCK_SIZE bsize); |