From 9725a1402afa9ab8f45dd329357ca5c719c8e8fa Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 5 Nov 2022 20:08:47 -0700 Subject: [PATCH] wip --- dither4.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/dither4.js b/dither4.js index 2641aa1..f74101d 100644 --- a/dither4.js +++ b/dither4.js @@ -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.g = nextError.g / 2; error.right.b = nextError.b / 2; - error.red[x + 1] += nextError.r / 2; - error.green[x + 1] += nextError.g / 2; - error.blue[x + 1] += nextError.b / 2; - */ + error.red[x] += nextError.r / 2; + error.green[x] += nextError.g / 2; + error.blue[x] += nextError.b / 2; + /* error.right.r = nextError.r / 2; error.right.g = nextError.g / 2; error.right.b = nextError.b / 2; @@ -439,8 +444,28 @@ function decimate(input, palette, n) { error.red[x + 1] += nextError.r / 8; error.green[x + 1] += nextError.g / 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 { output, @@ -466,14 +491,20 @@ function decimate(input, palette, n) { if (decimated[i].r == 255 && decimated[i].g == 255 && decimated[i].b == 255) { continue; // keep white always } + let coolFactor = popularity[i]; + /* + + let coolFactor = 0; for (let x = 0; x < line.length; x++) { if (output[x] == i) { - coolFactor *= fitness[x]; + coolFactor += fitness[x]; } } + coolFactor /= Math.sqrt(popularity[i]); */ + if (coolFactor < least) { pick = i; least = coolFactor;