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,
for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; n >= 2;
--n) {
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 (colors == PALETTE_MIN_SIZE) {
// Special case: These colors automatically become the centroids.
assert(colors == n);
assert(colors == 2);
centroids[0] = lb;
centroids[1] = ub;
k = 2;
} 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
......
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