Commit 88c1c3f4 authored by Sebastien Alaiwan's avatar Sebastien Alaiwan Committed by Frédéric BARBIER

pred_common.c: extract func 'palette_add_to_cache'

Change-Id: Ie6f6f5405cfe4c59dec1dc6dabc9ef5bcf2fb756
parent 09191ca2
...@@ -101,6 +101,13 @@ int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd) { ...@@ -101,6 +101,13 @@ int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd) {
#endif #endif
#if CONFIG_PALETTE_DELTA_ENCODING #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;
cache[(*n)++] = val;
}
int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane, int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
uint16_t *cache) { uint16_t *cache) {
const int row = -xd->mb_to_top_edge >> 3; const int row = -xd->mb_to_top_edge >> 3;
...@@ -127,21 +134,21 @@ int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane, ...@@ -127,21 +134,21 @@ int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
uint16_t v_above = above_colors[above_idx]; uint16_t v_above = above_colors[above_idx];
uint16_t v_left = left_colors[left_idx]; uint16_t v_left = left_colors[left_idx];
if (v_left < v_above) { if (v_left < v_above) {
if (n == 0 || v_left != cache[n - 1]) cache[n++] = v_left; palette_add_to_cache(cache, &n, v_left);
++left_idx, --left_n; ++left_idx, --left_n;
} else { } else {
if (n == 0 || v_above != cache[n - 1]) cache[n++] = v_above; palette_add_to_cache(cache, &n, v_above);
++above_idx, --above_n; ++above_idx, --above_n;
if (v_left == v_above) ++left_idx, --left_n; if (v_left == v_above) ++left_idx, --left_n;
} }
} }
while (above_n-- > 0) { while (above_n-- > 0) {
uint16_t val = above_colors[above_idx++]; uint16_t val = above_colors[above_idx++];
if (n == 0 || val != cache[n - 1]) cache[n++] = val; palette_add_to_cache(cache, &n, val);
} }
while (left_n-- > 0) { while (left_n-- > 0) {
uint16_t val = left_colors[left_idx++]; uint16_t val = left_colors[left_idx++];
if (n == 0 || val != cache[n - 1]) cache[n++] = val; palette_add_to_cache(cache, &n, val);
} }
assert(n <= 2 * PALETTE_MAX_SIZE); assert(n <= 2 * PALETTE_MAX_SIZE);
return n; return n;
......
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