hmm
This commit is contained in:
parent
365d968448
commit
b74036ef8d
1 changed files with 15 additions and 17 deletions
|
@ -508,9 +508,10 @@ function decimate(input, palette, n, inputError) {
|
||||||
|
|
||||||
// not happy with this alt yet
|
// not happy with this alt yet
|
||||||
|
|
||||||
let colorCount = new Int32Array(256);
|
let colorCount = [];
|
||||||
let hues = new Int32Array(16);
|
for (let i = 0; i < 256; i++) {
|
||||||
let lumaByHue = new Int32Array(16);
|
colorCount[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
const bestColor = (rgb) => {
|
const bestColor = (rgb) => {
|
||||||
let best = -1;
|
let best = -1;
|
||||||
|
@ -528,26 +529,23 @@ function decimate(input, palette, n, inputError) {
|
||||||
let rgb = inputPixel(x);
|
let rgb = inputPixel(x);
|
||||||
let i = bestColor(rgb);
|
let i = bestColor(rgb);
|
||||||
colorCount[i]++;
|
colorCount[i]++;
|
||||||
let hue = i >> 4;
|
|
||||||
hues[hue]++;
|
|
||||||
let luma = i & 0xf;
|
|
||||||
lumaByHue[hue] = Math.max(luma, lumaByHue[hue]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let xhues = [];
|
for (let keep of reserved) {
|
||||||
xhues.push.apply(xhues, hues);
|
colorCount[keep] = Infinity;
|
||||||
|
|
||||||
let popularHues = xhues.map((count, hue) => {return {count, hue}}).sort((a, b) => b.count - a.count);
|
|
||||||
decimated = [0];
|
|
||||||
for (let {count, hue} of popularHues) {
|
|
||||||
let luma = lumaByHue[hue];
|
|
||||||
if (luma > 0 && count > 0) {
|
|
||||||
decimated.push((hue << 4) | luma);
|
|
||||||
}
|
}
|
||||||
|
let popular = colorCount
|
||||||
|
.map((count, color) => {return {count, color}})
|
||||||
|
.filter(({count}) => count > 0)
|
||||||
|
.sort((a, b) => b.count - a.count)
|
||||||
|
decimated = [];
|
||||||
|
for (let {color} of popular) {
|
||||||
|
decimated.push(color);
|
||||||
if (decimated.length == n) {
|
if (decimated.length == n) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
decimated.sort((a, b) => a - b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue