This commit is contained in:
Brooke Vibber 2023-03-21 18:09:23 -07:00
parent 3216af39d6
commit 2cc9198e2c

View file

@ -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];