From 0ea766a5a6abbb9e83a6a4b50b316039a673348e Mon Sep 17 00:00:00 2001 From: Brooke Vibber Date: Tue, 27 Aug 2024 19:09:28 -0700 Subject: [PATCH] use the raw luma --- dither-image.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/dither-image.js b/dither-image.js index 8db870a..ababc3c 100644 --- a/dither-image.js +++ b/dither-image.js @@ -247,21 +247,13 @@ function colorize(input) { // Try dithering with this palette. for (let x = 0; x < width; x++) { let rgb = inputPixel(x, error); + let luma = Math.round(rgb.luma() / 15); + let pick = luma; - // find the closest possible color - // @todo consider doing the difference scoring in luminance and hue spaces - shortest = Infinity; - let pick = 1; - - for (let i = 0; i < palette.length; i++) { - let diff = rgb.difference(atariRGB[palette[i]]); - let dist = diff.magnitude(); - if (dist < shortest) { - nextError = diff; - shortest = dist; - pick = i; - } - } + let diff = rgb.difference(atariRGB[palette[pick]]); + let dist = diff.magnitude(); + nextError = diff; + shortest = dist; output[x] = pick; distance += shortest;