get_palette_color_context: Make code more readable.
For clarity, use separate variables for 'color_ctx_hash' and
'color_ctx' instead of reusing same variables for both.
BUG=webm:1324
Change-Id: I3a516ea54353e1f0737822c613a68da252e30c6e
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index 52dc8f1..f23ac96 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -911,11 +911,13 @@
// this (or similar) bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
int scores[PALETTE_MAX_SIZE + 10];
const int weights[4] = { 3, 2, 3, 2 };
- int color_ctx = 0;
+ int color_ctx_hash;
+ int color_ctx;
int color_neighbors[4];
int inverse_color_order[PALETTE_MAX_SIZE];
assert(n <= PALETTE_MAX_SIZE);
+ // Get color indices of neighbors.
color_neighbors[0] = (c - 1 >= 0) ? color_map[r * cols + c - 1] : -1;
color_neighbors[1] =
(c - 1 >= 0 && r - 1 >= 0) ? color_map[(r - 1) * cols + c - 1] : -1;
@@ -960,15 +962,19 @@
}
}
- for (i = 0; i < 4; ++i) color_ctx = color_ctx * 11 + scores[i];
+ // Get hash value of context.
+ color_ctx_hash = 0;
+ for (i = 0; i < 4; ++i) color_ctx_hash = color_ctx_hash * 11 + scores[i];
- for (i = 0; i < PALETTE_COLOR_CONTEXTS; ++i)
- if (color_ctx == palette_color_context_lookup[i]) {
+ // Lookup context from hash.
+ color_ctx = 0; // Default.
+ for (i = 0; i < PALETTE_COLOR_CONTEXTS; ++i) {
+ if (color_ctx_hash == palette_color_context_lookup[i]) {
color_ctx = i;
break;
}
+ }
- if (color_ctx >= PALETTE_COLOR_CONTEXTS) color_ctx = 0;
if (color_idx != NULL) {
*color_idx = inverse_color_order[color_map[r * cols + c]];
}