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! // Median cut!
// https://en.wikipedia.org/wiki/Median_cut // https://en.wikipedia.org/wiki/Median_cut
let buckets = [input.slice()]; //let buckets = [input.slice()];
//let initial = dither(palette); let initial = dither(palette);
//let buckets = [initial.output.map((i) => atariRGB[palette[i]])]; let buckets = [initial.output.map((i) => atariRGB[palette[i]])];
let medianCut = (bucket, range) => { let medianCut = (bucket, range) => {
if (bucket.length < 2) { if (bucket.length < 2) {
console.log(bucket); console.log(bucket);
@ -587,23 +587,18 @@ function decimate(input, palette, n, inputError, y) {
// .divide(bucket.length); // .divide(bucket.length);
// scale to the max luma // scale to the max luma
// kinda nice but really aggressive with the colors
let lumas = bucket.map((rgb) => rgb.luma()); let lumas = bucket.map((rgb) => rgb.luma());
console.log(lumas);
let luma = Math.max(...lumas); let luma = Math.max(...lumas);
let rgb = bucket[lumas.indexOf(luma)]; let rgb = bucket[lumas.indexOf(luma)];
console.log(rgb, luma);
let from = rgb.luma(); let from = rgb.luma();
if (from > 0) { if (from > 0) {
rgb = rgb.multiply(luma / rgb.luma()); rgb = rgb.multiply(luma / rgb.luma());
} }
console.log(rgb, luma);
if (!rgb) {
throw new Error('xxx');
}
// Take the channel-brightest color in the bucket // Take the channel-brightest color in the bucket
// bad // bad
//rgb = bucket[bucket.length - 1]; //let rgb = bucket[bucket.length - 1];
// Take the luma-brightest color in the bucket // Take the luma-brightest color in the bucket
//let rgb = bucket.slice().sort((a, b) => b.luma() - a.luma())[bucket.length - 1]; //let rgb = bucket.slice().sort((a, b) => b.luma() - a.luma())[bucket.length - 1];