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);
|
let popular = colorCount
|
||||||
decimated = [0];
|
.map((count, color) => {return {count, color}})
|
||||||
for (let {count, hue} of popularHues) {
|
.filter(({count}) => count > 0)
|
||||||
let luma = lumaByHue[hue];
|
.sort((a, b) => b.count - a.count)
|
||||||
if (luma > 0 && count > 0) {
|
decimated = [];
|
||||||
decimated.push((hue << 4) | luma);
|
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