From ed9538ecc5dcc96562f0a5e03bfa6295aafb6fc7 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 5 Nov 2022 18:02:00 -0700 Subject: [PATCH] force white also this leaves us with only two new colors per row but gives more dither possibilities --- dither4.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dither4.js b/dither4.js index 9cff868..f0f38e5 100644 --- a/dither4.js +++ b/dither4.js @@ -398,6 +398,12 @@ function decimate(input, palette, n) { let least = Infinity; let pick = -1; for (let i = 1; i < decimated.length; i++) { + if (i == 0) { + continue; // keep black always + } + if (decimated[i].r == 255 && decimated[i].g == 255 && decimated[i].b == 255) { + continue; // keep white always + } if (popularity[i] < least) { pick = i; least = popularity[i]; @@ -405,9 +411,6 @@ function decimate(input, palette, n) { } let old = decimated.length; decimated = decimated.filter((rgb, i) => { - if (i == 0) { - return true; // keep black always - } if (i == pick) { return false; } @@ -417,6 +420,8 @@ function decimate(input, palette, n) { return true; }); if (decimated.length >= old) { + console.log(decimated); + debugger; throw new Error('logic error'); } }