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'); } }