Commit e6579113 authored by Frederic Barbier's avatar Frederic Barbier Committed by Sebastien Alaiwan
Browse files

Remove experimental flag of PALETTE_DELTA_ENCODING

This experiment has been adopted, we can simplify the code
by dropping the associated preprocessor conditionals.

Change-Id: Idec45a597398ff4fddc6a040c3d7cb3a3c0029d6
parent f0463bb8
......@@ -100,7 +100,6 @@ int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
}
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
static void palette_add_to_cache(uint16_t *cache, int *n, uint16_t val) {
// Do not add an already existing value
if (*n > 0 && val == cache[*n - 1]) return;
......@@ -153,7 +152,6 @@ int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
assert(n <= 2 * PALETTE_MAX_SIZE);
return n;
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
// The mode info data structure has a one element border above and to the
// left of the entries corresponding to real macroblocks.
......
......@@ -177,14 +177,12 @@ int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir);
int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd);
#endif
#if CONFIG_PALETTE_DELTA_ENCODING
// Get a list of palette base colors that are used in the above and left blocks,
// referred to as "color cache". The return value is the number of colors in the
// cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
// in ascending order.
int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
uint16_t *cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
int av1_get_intra_inter_context(const MACROBLOCKD *xd);
......
......@@ -706,7 +706,6 @@ static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
}
}
#if CONFIG_PALETTE_DELTA_ENCODING
// Merge the sorted list of cached colors(cached_colors[0...n_cached_colors-1])
// and the sorted list of transmitted colors(colors[n_cached_colors...n-1]) into
// one single sorted list(colors[...]).
......@@ -814,7 +813,6 @@ static void read_palette_colors_uv(MACROBLOCKD *const xd, int bit_depth,
}
}
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
aom_reader *r) {
......@@ -847,12 +845,7 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
xd->tile_ctx->palette_y_size_cdf[block_palette_idx],
PALETTE_SIZES, ACCT_STR) +
2;
#if CONFIG_PALETTE_DELTA_ENCODING
read_palette_colors_y(xd, cm->bit_depth, pmi, r);
#else
for (int i = 0; i < pmi->palette_size[0]; ++i)
pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR);
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
}
if (mbmi->uv_mode == UV_DC_PRED) {
......@@ -865,16 +858,7 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
xd->tile_ctx->palette_uv_size_cdf[block_palette_idx],
PALETTE_SIZES, ACCT_STR) +
2;
#if CONFIG_PALETTE_DELTA_ENCODING
read_palette_colors_uv(xd, cm->bit_depth, pmi, r);
#else
for (int i = 0; i < pmi->palette_size[1]; ++i) {
pmi->palette_colors[PALETTE_MAX_SIZE + i] =
aom_read_literal(r, cm->bit_depth, ACCT_STR);
pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] =
aom_read_literal(r, cm->bit_depth, ACCT_STR);
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
}
}
......
......@@ -48,9 +48,7 @@
#include "av1/encoder/cost.h"
#include "av1/encoder/encodemv.h"
#include "av1/encoder/mcomp.h"
#if CONFIG_PALETTE_DELTA_ENCODING
#include "av1/encoder/palette.h"
#endif // CONFIG_PALETTE_DELTA_ENCODING
#include "av1/encoder/segmentation.h"
#include "av1/encoder/subexp.h"
#include "av1/encoder/tokenize.h"
......@@ -901,7 +899,6 @@ static void write_mb_interp_filter(AV1_COMP *cpi, const MACROBLOCKD *xd,
}
}
#if CONFIG_PALETTE_DELTA_ENCODING
// Transmit color values with delta encoding. Write the first value as
// literal, and the deltas between each value and the previous one. "min_val" is
// the smallest possible value of the deltas.
......@@ -1019,7 +1016,6 @@ static void write_palette_colors_uv(const MACROBLOCKD *const xd,
}
}
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const MODE_INFO *const mi, aom_writer *w) {
......@@ -1050,14 +1046,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
aom_write_symbol(w, n - PALETTE_MIN_SIZE,
xd->tile_ctx->palette_y_size_cdf[block_palette_idx],
PALETTE_SIZES);
#if CONFIG_PALETTE_DELTA_ENCODING
write_palette_colors_y(xd, pmi, cm->bit_depth, w);
#else
for (int i = 0; i < n; ++i) {
assert(pmi->palette_colors[i] < (1 << cm->bit_depth));
aom_write_literal(w, pmi->palette_colors[i], cm->bit_depth);
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
}
......@@ -1075,20 +1064,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
aom_write_symbol(w, n - PALETTE_MIN_SIZE,
xd->tile_ctx->palette_uv_size_cdf[block_palette_idx],
PALETTE_SIZES);
#if CONFIG_PALETTE_DELTA_ENCODING
write_palette_colors_uv(xd, pmi, cm->bit_depth, w);
#else
for (int i = 0; i < n; ++i) {
assert(pmi->palette_colors[PALETTE_MAX_SIZE + i] <
(1 << cm->bit_depth));
assert(pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] <
(1 << cm->bit_depth));
aom_write_literal(w, pmi->palette_colors[PALETTE_MAX_SIZE + i],
cm->bit_depth);
aom_write_literal(w, pmi->palette_colors[2 * PALETTE_MAX_SIZE + i],
cm->bit_depth);
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
}
}
......
......@@ -43,7 +43,6 @@ int av1_remove_duplicates(float *centroids, int num_centroids) {
return num_unique;
}
#if CONFIG_PALETTE_DELTA_ENCODING
static int delta_encode_cost(const int *colors, int num, int bit_depth,
int min_val) {
if (num <= 0) return 0;
......@@ -116,15 +115,11 @@ int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi,
}
return AOMMAX(av1_ceil_log2(max_d + 1), *min_bits);
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t *color_cache, int n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
int bit_depth) {
const int n = pmi->palette_size[0];
#if CONFIG_PALETTE_DELTA_ENCODING
int out_cache_colors[PALETTE_MAX_SIZE];
uint8_t cache_color_found[2 * PALETTE_MAX_SIZE];
const int n_out_cache =
......@@ -133,18 +128,12 @@ int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
const int total_bits =
n_cache + delta_encode_cost(out_cache_colors, n_out_cache, bit_depth, 1);
return total_bits * av1_cost_bit(128, 0);
#else
return bit_depth * n * av1_cost_bit(128, 0);
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t *color_cache, int n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
int bit_depth) {
const int n = pmi->palette_size[1];
#if CONFIG_PALETTE_DELTA_ENCODING
int total_bits = 0;
// U channel palette color cost.
int out_cache_colors[PALETTE_MAX_SIZE];
......@@ -164,7 +153,4 @@ int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
const int bits_using_raw = bit_depth * n;
total_bits += 1 + AOMMIN(bits_using_delta, bits_using_raw);
return total_bits * av1_cost_bit(128, 0);
#else
return 2 * bit_depth * n * av1_cost_bit(128, 0);
#endif // CONFIG_PALETTE_DELTA_ENCODING
}
......@@ -68,7 +68,6 @@ static INLINE void av1_k_means(const float *data, float *centroids,
// method.
int av1_remove_duplicates(float *centroids, int num_centroids);
#if CONFIG_PALETTE_DELTA_ENCODING
// Given a color cache and a set of base colors, find if each cache color is
// present in the base colors, record the binary results in "cache_color_found".
// Record the colors that are not in the color cache in "out_cache_colors".
......@@ -80,20 +79,14 @@ int av1_index_color_cache(const uint16_t *color_cache, int n_cache,
// assign zero_count with the number of deltas being 0.
int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi,
int bit_depth, int *zero_count, int *min_bits);
#endif // CONFIG_PALETTE_DELTA_ENCODING
// Return the rate cost for transmitting luma palette color values.
int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t *color_cache, int n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
int bit_depth);
uint16_t *color_cache, int n_cache, int bit_depth);
// Return the rate cost for transmitting chroma palette color values.
int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t *color_cache, int n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
int bit_depth);
#ifdef __cplusplus
......
......@@ -2793,7 +2793,6 @@ static void extend_palette_color_map(uint8_t *const color_map, int orig_width,
}
}
#if CONFIG_PALETTE_DELTA_ENCODING
// Bias toward using colors in the cache.
// TODO(huisu): Try other schemes to improve compression.
static void optimize_palette_colors(uint16_t *color_cache, int n_cache,
......@@ -2813,17 +2812,13 @@ static void optimize_palette_colors(uint16_t *color_cache, int n_cache,
if (min_diff < 1.5) centroids[i] = color_cache[idx];
}
}
#endif // CONFIG_PALETTE_DELTA_ENCODING
// Given the base colors as specified in centroids[], calculate the RD cost
// of palette mode.
static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
MB_MODE_INFO *mbmi, BLOCK_SIZE bsize, int palette_ctx,
int dc_mode_cost, const float *data, float *centroids,
int n,
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t *color_cache, int n_cache,
#endif
int n, uint16_t *color_cache, int n_cache,
MB_MODE_INFO *best_mbmi,
uint8_t *best_palette_color_map, int64_t *best_rd,
int64_t *best_model_rd, int *rate, int *rate_tokenonly,
......@@ -2835,9 +2830,7 @@ static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
assert(!isnan(centroids[i]));
}
#endif // NDEBUG
#if CONFIG_PALETTE_DELTA_ENCODING
optimize_palette_colors(color_cache, n_cache, n, 1, centroids);
#endif // CONFIG_PALETTE_DELTA_ENCODING
int k = av1_remove_duplicates(centroids, n);
if (k < PALETTE_MIN_SIZE) {
// Too few unique colors to create a palette. And DC_PRED will work
......@@ -2867,10 +2860,7 @@ static void palette_rd_y(const AV1_COMP *const cpi, MACROBLOCK *x,
x->palette_y_size_cost[bsize - BLOCK_8X8][k - PALETTE_MIN_SIZE] +
write_uniform_cost(k, color_map[0]) +
x->palette_y_mode_cost[bsize - BLOCK_8X8][palette_ctx][1];
palette_mode_cost += av1_palette_color_cost_y(pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
color_cache, n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
palette_mode_cost += av1_palette_color_cost_y(pmi, color_cache, n_cache,
cpi->common.bit_depth);
palette_mode_cost +=
av1_cost_color_map(x, 0, bsize, mbmi->tx_size, PALETTE_MAP);
......@@ -2986,10 +2976,8 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
if (rows * cols > MAX_PALETTE_SQUARE) return 0;
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
// Find the dominant colors, stored in top_colors[].
int top_colors[PALETTE_MAX_SIZE] = { 0 };
......@@ -3011,12 +2999,9 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
for (n = AOMMIN(colors, PALETTE_MAX_SIZE); n >= 2; --n) {
for (i = 0; i < n; ++i) centroids[i] = (float)(top_colors[i]);
palette_rd_y(cpi, x, mbmi, bsize, palette_ctx, dc_mode_cost, data,
centroids, n,
#if CONFIG_PALETTE_DELTA_ENCODING
color_cache, n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
best_mbmi, best_palette_color_map, best_rd, best_model_rd,
rate, rate_tokenonly, &rate_overhead, distortion, skippable);
centroids, n, color_cache, n_cache, best_mbmi,
best_palette_color_map, best_rd, best_model_rd, rate,
rate_tokenonly, &rate_overhead, distortion, skippable);
}
// K-means clustering.
......@@ -3035,12 +3020,9 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
av1_k_means(data, centroids, color_map, rows * cols, n, 1, max_itr);
}
palette_rd_y(cpi, x, mbmi, bsize, palette_ctx, dc_mode_cost, data,
centroids, n,
#if CONFIG_PALETTE_DELTA_ENCODING
color_cache, n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
best_mbmi, best_palette_color_map, best_rd, best_model_rd,
rate, rate_tokenonly, &rate_overhead, distortion, skippable);
centroids, n, color_cache, n_cache, best_mbmi,
best_palette_color_map, best_rd, best_model_rd, rate,
rate_tokenonly, &rate_overhead, distortion, skippable);
}
}
......@@ -5191,10 +5173,8 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
}
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_PALETTE_DELTA_ENCODING
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
colors = colors_u > colors_v ? colors_u : colors_v;
if (colors > 1 && colors <= 64) {
......@@ -5265,7 +5245,6 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
assert(!isnan(centroids[i]));
}
#endif // NDEBUG
#if CONFIG_PALETTE_DELTA_ENCODING
optimize_palette_colors(color_cache, n_cache, n, 2, centroids);
// Sort the U channel colors in ascending order.
for (i = 0; i < 2 * (n - 1); i += 2) {
......@@ -5281,7 +5260,6 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
}
}
av1_calc_indices(data, centroids, color_map, rows * cols, n, 2);
#endif // CONFIG_PALETTE_DELTA_ENCODING
extend_palette_color_map(color_map, cols, rows, plane_block_width,
plane_block_height);
pmi->palette_size[1] = n;
......@@ -5305,10 +5283,7 @@ static void rd_pick_palette_intra_sbuv(const AV1_COMP *const cpi, MACROBLOCK *x,
x->palette_uv_size_cost[bsize - BLOCK_8X8][n - PALETTE_MIN_SIZE] +
write_uniform_cost(n, color_map[0]) +
x->palette_uv_mode_cost[pmi->palette_size[0] > 0][1];
this_rate += av1_palette_color_cost_uv(pmi,
#if CONFIG_PALETTE_DELTA_ENCODING
color_cache, n_cache,
#endif // CONFIG_PALETTE_DELTA_ENCODING
this_rate += av1_palette_color_cost_uv(pmi, color_cache, n_cache,
cpi->common.bit_depth);
this_rate += av1_cost_color_map(x, 1, bsize, mbmi->tx_size, PALETTE_MAP);
this_rd = RDCOST(x->rdmult, this_rate, tokenonly_rd_stats.dist);
......
......@@ -171,7 +171,6 @@ set(CONFIG_NO_FRAME_CONTEXT_SIGNALING 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_OBU 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_OBU_NO_IVF 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_OPT_REF_MV 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_PALETTE_DELTA_ENCODING 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_PALETTE_THROUGHPUT 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_PARALLEL_DEBLOCKING 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_Q_ADAPT_PROBS 1 CACHE NUMBER "AV1 experiment flag.")
......
......@@ -268,7 +268,6 @@ EXPERIMENT_LIST="
ext_tile
q_adapt_probs
inter_stats_only
palette_delta_encoding
kf_ctx
cfl
xiphrc
......@@ -520,7 +519,6 @@ post_process_cmdline() {
soft_enable kf_ctx
soft_enable striped_loop_restoration
soft_enable ext_intra_mod
soft_enable palette_delta_encoding
soft_enable frame_size
soft_enable segment_globalmv
soft_enable short_filter
......
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