This commit is contained in:
Brooke Vibber 2023-03-21 05:04:17 -07:00
parent 2c943419ce
commit 9df948721c

View file

@ -131,6 +131,10 @@ class RGB {
this.g * this.g + this.g * this.g +
this.b * this.b; this.b * this.b;
} }
luma() {
return this.r * 0.299 + this.g * 0.587 + this.b * 0.114;
}
} }
const maxDist = (new RGB(255, 255, 255)).magnitude(); const maxDist = (new RGB(255, 255, 255)).magnitude();
@ -576,12 +580,22 @@ function decimate(input, palette, n, inputError, y) {
// .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);
// Take the brightest color in the bucket // Take the channel-brightest color in the bucket
//let 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];
// Take the median color in the bucket // Take the median color in the bucket
let rgb = bucket[bucket.length >> 1]; let rgb = bucket[bucket.length >> 1];
// Take the luma-median color in the bucket
//let rgb = bucket.slice().sort((a, b) => b.luma() - a.luma())[bucket.length >> 1];
// Take the brightest-channel median
//let rgb = bucket.slice()
// .sort((a, b) => Math.max(b.r, b.g, b.b) - Math.max(a.r, b.g, b.b))[bucket.length >> 1];
// And map into the Atari palette // And map into the Atari palette
let dists = palette.map(( i) => rgb.difference(atariRGB[i]).magnitude()); let dists = palette.map(( i) => rgb.difference(atariRGB[i]).magnitude());
let closest = Math.min(...dists); let closest = Math.min(...dists);