static inline int av1_fast_palette_color_index_context_on_edge( const uint8_t *color_map, int stride, int r, int c, int *color_idx) { constbool has_left = (c - 1 >= 0); constbool has_above = (r - 1 >= 0);
assert(r > 0 || c > 0);
assert(has_above ^ has_left);
assert(color_idx);
(void)has_left;
const uint8_t color_neighbor = has_above
? color_map[(r - 1) * stride + (c - 0)]
: color_map[(r - 0) * stride + (c - 1)]; // If the neighbor color has higher index than current color index, then we // move up by 1. const uint8_t current_color = *color_idx = color_map[r * stride + c];
if (color_neighbor > current_color) {
(*color_idx)++;
} else if (color_neighbor == current_color) {
*color_idx = 0;
}
// Get hash value of context. // The non-diagonal neighbors get a weight of 2. const uint8_t color_score = 2; const uint8_t hash_multiplier = 1; const uint8_t color_index_ctx_hash = color_score * hash_multiplier;
// Lookup context from hash. const int color_index_ctx =
av1_palette_color_index_context_lookup[color_index_ctx_hash];
assert(color_index_ctx == 0);
(void)color_index_ctx; return0;
}
// A faster version of av1_get_palette_color_index_context used by the encoder // exploiting the fact that the encoder does not need to maintain a color order. static inline int av1_fast_palette_color_index_context(const uint8_t *color_map,
int stride, int r, int c,
int *color_idx) {
assert(r > 0 || c > 0);
// This goes in the order of left, top, and top-left. This has the advantage // that unless anything here are not distinct or invalid, this will already // be in sorted order. Furthermore, if either of the first two is // invalid, we know the last one is also invalid.
uint8_t color_neighbors[NUM_PALETTE_NEIGHBORS];
color_neighbors[0] = color_map[(r - 0) * stride + (c - 1)];
color_neighbors[1] = color_map[(r - 1) * stride + (c - 0)];
color_neighbors[2] = color_map[(r - 1) * stride + (c - 1)];
// Aggregate duplicated values. // Since our array is so small, using a couple if statements is faster
uint8_t scores[NUM_PALETTE_NEIGHBORS] = { 2, 2, 1 };
uint8_t num_invalid_colors = 0;
if (color_neighbors[0] == color_neighbors[1]) {
scores[0] += scores[1];
color_neighbors[1] = INVALID_COLOR_IDX;
num_invalid_colors += 1;
// Sort everything
if (num_valid_colors > 1) {
if (color_neighbors[1] == INVALID_COLOR_IDX) {
scores[1] = scores[2];
color_neighbors[1] = color_neighbors[2];
}
// We need to swap the first two elements if they have the same score but // the color indices are not in the right order
if (score_rank[0] < score_rank[1] ||
(score_rank[0] == score_rank[1] && color_rank[0] > color_rank[1])) {
SWAP(0, 1);
}
if (num_valid_colors > 2) {
if (score_rank[0] < score_rank[2]) {
SWAP(0, 2);
}
if (score_rank[1] < score_rank[2]) {
SWAP(1, 2);
}
}
}
// If any of the neighbor colors has higher index than current color index, // then we move up by 1 unless the current color is the same as one of the // neighbors. const uint8_t current_color = *color_idx = color_map[r * stride + c];
for (int idx = 0; idx < num_valid_colors; idx++) {
if (color_rank[idx] > current_color) {
(*color_idx)++;
} else if (color_rank[idx] == current_color) {
*color_idx = idx; break;
}
}
static int cost_and_tokenize_map(Av1ColorMapParam *param, TokenExtra **t,
int plane, int calc_rate, int allow_update_cdf,
FRAME_COUNTS *counts) { const uint8_t *const color_map = param->color_map;
MapCdf map_cdf = param->map_cdf;
ColorCost color_cost = param->color_cost; const int plane_block_width = param->plane_width; const int rows = param->rows; const int cols = param->cols; const int n = param->n_colors; const int palette_size_idx = n - PALETTE_MIN_SIZE;
int this_rate = 0;
(void)plane;
(void)counts;
for (int k = 1; k < rows + cols - 1; ++k) {
for (int j = AOMMIN(k, cols - 1); j >= AOMMAX(0, k - rows + 1); --j) {
int i = k - j;
int color_new_idx; const int color_ctx = av1_fast_palette_color_index_context(
color_map, plane_block_width, i, j, &color_new_idx);
assert(color_new_idx >= 0 && color_new_idx < n);
if (calc_rate) {
this_rate += color_cost[palette_size_idx][color_ctx][color_new_idx];
} else {
(*t)->token = color_new_idx;
(*t)->color_ctx = color_ctx;
++(*t);
if (allow_update_cdf)
update_cdf(map_cdf[palette_size_idx][color_ctx], color_new_idx, n); #if CONFIG_ENTROPY_STATS
if (plane) {
++counts->palette_uv_color_index[palette_size_idx][color_ctx]
[color_new_idx];
} else {
++counts->palette_y_color_index[palette_size_idx][color_ctx]
[color_new_idx];
} #endif
}
}
}
if (calc_rate) return this_rate; return0;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.