This commit is contained in:
Brooke Vibber 2022-11-05 20:08:47 -07:00
parent e3e1dd7c6e
commit 9725a1402a

View file

@ -415,15 +415,20 @@ function decimate(input, palette, n) {
*/ */
/* /*
error.red[x] += nextError.r;
error.green[x] += nextError.g;
error.blue[x] += nextError.b;
*/
error.right.r = nextError.r / 2; error.right.r = nextError.r / 2;
error.right.g = nextError.g / 2; error.right.g = nextError.g / 2;
error.right.b = nextError.b / 2; error.right.b = nextError.b / 2;
error.red[x + 1] += nextError.r / 2; error.red[x] += nextError.r / 2;
error.green[x + 1] += nextError.g / 2; error.green[x] += nextError.g / 2;
error.blue[x + 1] += nextError.b / 2; error.blue[x] += nextError.b / 2;
*/
/*
error.right.r = nextError.r / 2; error.right.r = nextError.r / 2;
error.right.g = nextError.g / 2; error.right.g = nextError.g / 2;
error.right.b = nextError.b / 2; error.right.b = nextError.b / 2;
@ -439,8 +444,28 @@ function decimate(input, palette, n) {
error.red[x + 1] += nextError.r / 8; error.red[x + 1] += nextError.r / 8;
error.green[x + 1] += nextError.g / 8; error.green[x + 1] += nextError.g / 8;
error.blue[x + 1] += nextError.b / 8; error.blue[x + 1] += nextError.b / 8;
*/
fitness[x] = 1 - (nextError.magnitude() / 442); /*
error.right.r = nextError.r / 4;
error.right.g = nextError.g / 4;
error.right.b = nextError.b / 4;
error.red[x - 1] += nextError.r / 4;
error.green[x - 1] += nextError.g / 4;
error.blue[x - 1] += nextError.b / 4;
error.red[x] += nextError.r / 4;
error.green[x] += nextError.g / 4;
error.blue[x] += nextError.b / 4;
error.red[x + 1] += nextError.r / 4;
error.green[x + 1] += nextError.g / 4;
error.blue[x + 1] += nextError.b / 4;
*/
// 442 is the 3d distance across the rgb cube
fitness[x] = 442 - (nextError.magnitude());
} }
return { return {
output, output,
@ -466,14 +491,20 @@ function decimate(input, palette, n) {
if (decimated[i].r == 255 && decimated[i].g == 255 && decimated[i].b == 255) { if (decimated[i].r == 255 && decimated[i].g == 255 && decimated[i].b == 255) {
continue; // keep white always continue; // keep white always
} }
let coolFactor = popularity[i]; let coolFactor = popularity[i];
/* /*
let coolFactor = 0;
for (let x = 0; x < line.length; x++) { for (let x = 0; x < line.length; x++) {
if (output[x] == i) { if (output[x] == i) {
coolFactor *= fitness[x]; coolFactor += fitness[x];
} }
} }
coolFactor /= Math.sqrt(popularity[i]);
*/ */
if (coolFactor < least) { if (coolFactor < least) {
pick = i; pick = i;
least = coolFactor; least = coolFactor;