wip aslfkjlfjsdlkjd
This commit is contained in:
parent
89db2f3d1d
commit
fdb20b47ec
1 changed files with 34 additions and 20 deletions
|
@ -566,31 +566,45 @@ function decimate(input, palette, n, inputError, y) {
|
|||
console.log('end', decimated);
|
||||
*/
|
||||
|
||||
// fitness
|
||||
// popularity? not really working right
|
||||
// first, dither to the total atari palette
|
||||
while (decimated.length > n) {
|
||||
console.log(`y ${y}`);
|
||||
let worstFitness = Infinity;
|
||||
let nextPalette = null;
|
||||
for (let i = 0; i < decimated.length; i++) {
|
||||
if (keepers[i]) {
|
||||
continue;
|
||||
}
|
||||
let without = decimated.slice();
|
||||
without.splice(i, 1);
|
||||
let {popularity, fitness} = dither(decimated);
|
||||
//console.log(y);
|
||||
|
||||
let total = 0;
|
||||
for (let n of fitness) {
|
||||
total += n;
|
||||
}
|
||||
let avg = total / fitness.length;
|
||||
if (avg < worstFitness) {
|
||||
worstFitness = avg;
|
||||
nextPalette = without;
|
||||
let {popularity, fitness, output} = dither(decimated);
|
||||
let pops = [];
|
||||
let fits = [];
|
||||
pops.fill(0, 0, 256);
|
||||
fits.fill(0, 0, 256);
|
||||
for (let i = 0; i < decimated.length; i++) {
|
||||
let c = decimated[i];
|
||||
pops[c] = popularity[i];
|
||||
for (let x = 0; x < fitness.length; x++) {
|
||||
if (output[x] === i) {
|
||||
fits[c] += fitness[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
decimated = nextPalette;
|
||||
let metric = (c) => {
|
||||
let rgb = atariRGB[c];
|
||||
let max = Math.max(rgb.r, rgb.g, rgb.b);
|
||||
let fit = fits[c];
|
||||
let pop = pops[c];
|
||||
return pop;
|
||||
}
|
||||
|
||||
let a = decimated.slice();
|
||||
// temporarily strip the reserved items
|
||||
a = a.filter((color) => !keepers[color]);
|
||||
a = a.filter((color) => popularity[color]);
|
||||
a.sort((a, b) => {
|
||||
return metric(b) - metric(a);
|
||||
});
|
||||
console.log(a);
|
||||
a = reserved.concat(a);
|
||||
decimated = a.slice(0, n);
|
||||
//decimated = a.slice(0, decimated.length - 1);
|
||||
//console.log(decimated);
|
||||
}
|
||||
//console.log('end', decimated);
|
||||
|
||||
|
|
Loading…
Reference in a new issue