From 7c4b118bedbb3e087be4acd81969b205e37e15a2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 18 Mar 2023 19:48:07 -0700 Subject: [PATCH] cap rgb input before doing comparisons for error dithering --- dither-image.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dither-image.js b/dither-image.js index d8ae0c4..e39b5ea 100644 --- a/dither-image.js +++ b/dither-image.js @@ -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 @@ -475,6 +476,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);