Palette code: remove the use of same if condition twice.
rd_pick_palette_intra_sby() method is called only when,
cpi->common.allow_screen_content_tools is on. So, no need to check that
again. We just use an assert() instead to still be safe.
Change-Id: I19785c2aac016798c8d331bbe91971b3806b73a8
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index b060878..31583a9 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -1722,140 +1722,139 @@
uint8_t *best_palette_color_map, TX_SIZE *best_tx, TX_TYPE *best_tx_type,
PREDICTION_MODE *mode_selected, int64_t *best_rd) {
int rate_overhead = 0;
- if (cpi->common.allow_screen_content_tools) {
- MACROBLOCKD *const xd = &x->e_mbd;
- MODE_INFO *const mic = xd->mi[0];
- const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
- const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
- int this_rate, this_rate_tokenonly, s, colors, n;
- int64_t this_distortion, this_rd;
- const int src_stride = x->plane[0].src.stride;
- const uint8_t *const src = x->plane[0].src.buf;
+ MACROBLOCKD *const xd = &x->e_mbd;
+ MODE_INFO *const mic = xd->mi[0];
+ const int rows = 4 * num_4x4_blocks_high_lookup[bsize];
+ const int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
+ int this_rate, this_rate_tokenonly, s, colors, n;
+ int64_t this_distortion, this_rd;
+ const int src_stride = x->plane[0].src.stride;
+ const uint8_t *const src = x->plane[0].src.buf;
+
+ assert(cpi->common.allow_screen_content_tools);
#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 CONFIG_EXT_INTRA
+ mic->mbmi.ext_intra_mode_info.use_ext_intra_mode[0] = 0;
+#endif // CONFIG_EXT_INTRA
+
+ if (colors > 1 && colors <= 64) {
+ int r, c, i, j, k;
+ const int max_itr = 50;
+ int color_ctx, color_idx = 0;
+ int color_order[PALETTE_MAX_SIZE];
+ float *const data = x->palette_buffer->kmeans_data_buf;
+ float centroids[PALETTE_MAX_SIZE];
+ uint8_t *const color_map = xd->plane[0].color_index_map;
+ float lb, ub, val;
+ MB_MODE_INFO *const mbmi = &mic->mbmi;
+ PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
+#if CONFIG_VP9_HIGHBITDEPTH
+ uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
if (cpi->common.use_highbitdepth)
- colors = vp10_count_colors_highbd(src, src_stride, rows, cols,
- cpi->common.bit_depth);
+ lb = ub = src16[0];
else
#endif // CONFIG_VP9_HIGHBITDEPTH
- colors = vp10_count_colors(src, src_stride, rows, cols);
- palette_mode_info->palette_size[0] = 0;
+ 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
+
+ mbmi->mode = DC_PRED;
#if CONFIG_EXT_INTRA
- mic->mbmi.ext_intra_mode_info.use_ext_intra_mode[0] = 0;
+ mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
#endif // CONFIG_EXT_INTRA
- if (colors > 1 && colors <= 64) {
- int r, c, i, j, k;
- const int max_itr = 50;
- int color_ctx, color_idx = 0;
- int color_order[PALETTE_MAX_SIZE];
- float *const data = x->palette_buffer->kmeans_data_buf;
- float centroids[PALETTE_MAX_SIZE];
- uint8_t *const color_map = xd->plane[0].color_index_map;
- float lb, ub, val;
- MB_MODE_INFO *const mbmi = &mic->mbmi;
- PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
+ if (rows * cols > PALETTE_MAX_BLOCK_SIZE) return 0;
+
+ 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, color_map, rows * cols, n, 1, max_itr);
+ k = vp10_remove_duplicates(centroids, n);
+
#if CONFIG_VP9_HIGHBITDEPTH
- uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
if (cpi->common.use_highbitdepth)
- lb = ub = src16[0];
+ for (i = 0; i < k; ++i)
+ pmi->palette_colors[i] =
+ clip_pixel_highbd((int)centroids[i], cpi->common.bit_depth);
else
#endif // CONFIG_VP9_HIGHBITDEPTH
- lb = ub = src[0];
+ for (i = 0; i < k; ++i)
+ pmi->palette_colors[i] = clip_pixel((int)centroids[i]);
+ pmi->palette_size[0] = k;
-#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;
- }
+ vp10_calc_indices(data, centroids, color_map, rows * cols, k, 1);
+
+ 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] +
+ write_uniform_cost(k, color_map[0]) +
+ vp10_cost_bit(
+ vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx],
+ 1);
+ 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 >= 0 && color_idx < k);
+ this_rate += cpi->palette_y_color_cost[k - 2][color_ctx][color_idx];
}
- } 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
+ this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
- mbmi->mode = DC_PRED;
-#if CONFIG_EXT_INTRA
- mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
-#endif // CONFIG_EXT_INTRA
-
- if (rows * cols > PALETTE_MAX_BLOCK_SIZE) return 0;
-
- 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, color_map, rows * cols, n, 1, max_itr);
- k = vp10_remove_duplicates(centroids, n);
-
-#if CONFIG_VP9_HIGHBITDEPTH
- if (cpi->common.use_highbitdepth)
- for (i = 0; i < k; ++i)
- pmi->palette_colors[i] =
- clip_pixel_highbd((int)centroids[i], cpi->common.bit_depth);
- else
-#endif // CONFIG_VP9_HIGHBITDEPTH
- for (i = 0; i < k; ++i)
- pmi->palette_colors[i] = clip_pixel((int)centroids[i]);
- pmi->palette_size[0] = k;
-
- vp10_calc_indices(data, centroids, color_map, rows * cols, k, 1);
-
- 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] +
- write_uniform_cost(k, color_map[0]) +
- vp10_cost_bit(
- vp10_default_palette_y_mode_prob[bsize -
- BLOCK_8X8][palette_ctx],
- 1);
- 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 >= 0 && 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 = *pmi;
- memcpy(best_palette_color_map, color_map,
- rows * cols * sizeof(color_map[0]));
- *mode_selected = DC_PRED;
- *best_tx = mbmi->tx_size;
- *best_tx_type = mbmi->tx_type;
- rate_overhead = this_rate - this_rate_tokenonly;
- }
+ if (this_rd < *best_rd) {
+ *best_rd = this_rd;
+ *palette_mode_info = *pmi;
+ memcpy(best_palette_color_map, color_map,
+ rows * cols * sizeof(color_map[0]));
+ *mode_selected = DC_PRED;
+ *best_tx = mbmi->tx_size;
+ *best_tx_type = mbmi->tx_type;
+ rate_overhead = this_rate - this_rate_tokenonly;
}
}
}