This commit is contained in:
Brooke Vibber 2023-03-21 18:37:22 -07:00
parent b4e3394809
commit 23e60ae668

View file

@ -537,8 +537,6 @@ function decimate(input, palette, n) {
// 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 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);
@ -582,6 +580,7 @@ function decimate(input, palette, n) {
.reduce((acc, rgb) => acc.inc(rgb), new RGB(0, 0, 0)) .reduce((acc, rgb) => acc.inc(rgb), new RGB(0, 0, 0))
.divide(bucket.length); .divide(bucket.length);
// Scale the average to the brightest
let avg_luma = rgb.luma(); let avg_luma = rgb.luma();
let lumas = bucket.map((rgb) => rgb.luma()); let lumas = bucket.map((rgb) => rgb.luma());
let brightest = Math.max(...lumas); let brightest = Math.max(...lumas);