force white also

this leaves us with only two new colors per row
but gives more dither possibilities
This commit is contained in:
Brooke Vibber 2022-11-05 18:02:00 -07:00
parent e5a9c68d05
commit ed9538ecc5

View file

@ -398,6 +398,12 @@ function decimate(input, palette, n) {
let least = Infinity; let least = Infinity;
let pick = -1; let pick = -1;
for (let i = 1; i < decimated.length; i++) { 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) { if (popularity[i] < least) {
pick = i; pick = i;
least = popularity[i]; least = popularity[i];
@ -405,9 +411,6 @@ function decimate(input, palette, n) {
} }
let old = decimated.length; let old = decimated.length;
decimated = decimated.filter((rgb, i) => { decimated = decimated.filter((rgb, i) => {
if (i == 0) {
return true; // keep black always
}
if (i == pick) { if (i == pick) {
return false; return false;
} }
@ -417,6 +420,8 @@ function decimate(input, palette, n) {
return true; return true;
}); });
if (decimated.length >= old) { if (decimated.length >= old) {
console.log(decimated);
debugger;
throw new Error('logic error'); throw new Error('logic error');
} }
} }