From 2cc9198e2cf9f1c291281df6d4e6faf0aea3e433 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 21 Mar 2023 18:09:23 -0700 Subject: [PATCH] not bad --- dither-image.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/dither-image.js b/dither-image.js index 2aac164..a0eda76 100644 --- a/dither-image.js +++ b/dither-image.js @@ -540,9 +540,9 @@ function decimate(input, palette, n, inputError, y) { // Median cut! // https://en.wikipedia.org/wiki/Median_cut - let buckets = [input.slice()]; - //let initial = dither(palette); - //let buckets = [initial.output.map((i) => atariRGB[palette[i]])]; + //let buckets = [input.slice()]; + let initial = dither(palette); + let buckets = [initial.output.map((i) => atariRGB[palette[i]])]; let medianCut = (bucket, range) => { if (bucket.length < 2) { console.log(bucket); @@ -587,23 +587,18 @@ function decimate(input, palette, n, inputError, y) { // .divide(bucket.length); // scale to the max luma + // kinda nice but really aggressive with the colors let lumas = bucket.map((rgb) => rgb.luma()); - console.log(lumas); let luma = Math.max(...lumas); let rgb = bucket[lumas.indexOf(luma)]; - console.log(rgb, luma); let from = rgb.luma(); if (from > 0) { rgb = rgb.multiply(luma / rgb.luma()); } - console.log(rgb, luma); - if (!rgb) { - throw new Error('xxx'); - } // Take the channel-brightest color in the bucket // bad - //rgb = bucket[bucket.length - 1]; + //let rgb = bucket[bucket.length - 1]; // Take the luma-brightest color in the bucket //let rgb = bucket.slice().sort((a, b) => b.luma() - a.luma())[bucket.length - 1];