decimation to <128 chars
This commit is contained in:
parent
7fe0c34790
commit
260f9c53ed
1 changed files with 38 additions and 0 deletions
38
index.html
38
index.html
|
@ -123,6 +123,7 @@
|
||||||
// Convert the 4bpp pixel indices into hex strings
|
// Convert the 4bpp pixel indices into hex strings
|
||||||
let blockMap = {};
|
let blockMap = {};
|
||||||
let uniques = [];
|
let uniques = [];
|
||||||
|
/*
|
||||||
for (let i = 0; i < chars.length; i++) {
|
for (let i = 0; i < chars.length; i++) {
|
||||||
let char = chars[i];
|
let char = chars[i];
|
||||||
let block = blocks[char];
|
let block = blocks[char];
|
||||||
|
@ -139,6 +140,43 @@
|
||||||
}
|
}
|
||||||
chars[i] = char;
|
chars[i] = char;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
for (let threshold = 0; threshold < 16; threshold++) {
|
||||||
|
charIter:
|
||||||
|
for (let i = 0; i < chars.length; i++) {
|
||||||
|
let char = chars[i];
|
||||||
|
let block = blocks[char];
|
||||||
|
if (!block) {
|
||||||
|
debugger
|
||||||
|
throw new Error('missing block');
|
||||||
|
}
|
||||||
|
|
||||||
|
fontMatch:
|
||||||
|
for (let j = 0; j < uniques.length; j++) {
|
||||||
|
let other = uniques[j];
|
||||||
|
if (!block) {
|
||||||
|
debugger
|
||||||
|
throw new Error('missing other');
|
||||||
|
}
|
||||||
|
for (let k = 0; k < blockWidth * blockHeight; k++) {
|
||||||
|
if (Math.abs(block[k] - other[k]) > threshold) {
|
||||||
|
continue fontMatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// we're close enough to reuse a character
|
||||||
|
chars[i] = j;
|
||||||
|
continue charIter;
|
||||||
|
}
|
||||||
|
// add a new char
|
||||||
|
chars[i] = uniques.push(block) - 1;
|
||||||
|
}
|
||||||
|
if (uniques.length < 128) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// We need to decimate further
|
||||||
|
blocks = uniques;
|
||||||
|
uniques = [];
|
||||||
|
}
|
||||||
let span = document.querySelector('#block-count');
|
let span = document.querySelector('#block-count');
|
||||||
span.textContent = `${uniques.length}`;
|
span.textContent = `${uniques.length}`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue