cap rgb input before doing comparisons for error dithering

This commit is contained in:
Brooke Vibber 2023-03-18 19:48:07 -07:00
parent 63ae0e8cff
commit 7c4b118bed

View file

@ -430,6 +430,7 @@ function decimate(input, palette, n, inputError) {
if (inputError) {
rgb.inc(inputError[x]);
}
rgb.cap();
// find the closest possible color
// @todo consider doing the difference scoring in luminance and hue spaces
@ -476,6 +477,15 @@ function decimate(input, palette, n, inputError) {
let decimated = palette.slice();
// force to grayscale
//decimated = [0, 5, 10, 15];
// force to rgb
//decimated = [0, 0x36, 0xb6, 0x86];
// force to rWb
//decimated = [0, 0x36, 0x0f, 0x86];
while (decimated.length > n) {
let {popularity, fitness, output} = dither(decimated);