Commit 773e3542 authored by Urvang Joshi's avatar Urvang Joshi

Palette: Special case for 2 unique colors.

When a block only contains 2 unique colors, there's no need to run
K-means, as 'lb' and 'ub' can directly be used as the centroids.

Two benefits:
1. Encoding will be faster for this special case, and
2. Can potentially avoid sub-optimal/duplicate centroids generation
(due to integer rounding) when 'ub' and 'lb' values are very close.

Change-Id: Ice04fc8577e3cc8c74f87d623a16ac8de3257cdd
parent b72ab8fe
...@@ -2497,14 +2497,24 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x, ...@@ -2497,14 +2497,24 @@ static int rd_pick_palette_intra_sby(const AV1_COMP *const cpi, MACROBLOCK *x,
for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; n >= 2; for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; n >= 2;
--n) { --n) {
for (i = 0; i < n; ++i) if (colors == PALETTE_MIN_SIZE) {
centroids[i] = lb + (2 * i + 1) * (ub - lb) / n / 2; // Special case: These colors automatically become the centroids.
av1_k_means(data, centroids, color_map, rows * cols, n, 1, max_itr); assert(colors == n);
k = av1_remove_duplicates(centroids, n); assert(colors == 2);
if (k < PALETTE_MIN_SIZE) { centroids[0] = lb;
// Too few unique colors to create a palette. And DC_PRED will work well centroids[1] = ub;
// for that case anyway. So skip. k = 2;
continue; } else {
for (i = 0; i < n; ++i) {
centroids[i] = lb + (2 * i + 1) * (ub - lb) / n / 2;
}
av1_k_means(data, centroids, color_map, rows * cols, n, 1, max_itr);
k = av1_remove_duplicates(centroids, n);
if (k < PALETTE_MIN_SIZE) {
// Too few unique colors to create a palette. And DC_PRED will work
// well for that case anyway. So skip.
continue;
}
} }
#if CONFIG_HIGHBITDEPTH #if CONFIG_HIGHBITDEPTH
......
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