working just terrible :D:wq
This commit is contained in:
parent
ca7faf698f
commit
555a34b4db
1 changed files with 31 additions and 32 deletions
63
index.html
63
index.html
|
@ -78,6 +78,30 @@
|
|||
return block.map((n) => ~n & 0xf);
|
||||
}
|
||||
|
||||
function drawChar(bits, cx, cy, char, charset) {
|
||||
let invert = Boolean(char & 0x80);
|
||||
char &= 0x7f;
|
||||
if (char >= charset.length) {
|
||||
return;
|
||||
}
|
||||
let block = charset[char];
|
||||
for (let y = 0; y < blockHeight; y++) {
|
||||
for (let x = 0; x < blockWidth; x++) {
|
||||
let i = y * blockWidth + x;
|
||||
let ii = (y + cy * blockHeight) * bits.width + (x + cx * blockWidth);
|
||||
let gray16 = block[i];
|
||||
if (invert) {
|
||||
gray16 = ~gray16 & 0x0f;
|
||||
}
|
||||
let gray256 = Math.round(gray16 * 255 / 15);
|
||||
bits.data[ii * 4] = gray256;
|
||||
bits.data[ii * 4 + 1] = gray256;
|
||||
bits.data[ii * 4 + 2] = gray256;
|
||||
bits.data[ii * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
let ctx = work.getContext('2d');
|
||||
let pixels = new Uint8Array(width * height);
|
||||
|
@ -142,6 +166,7 @@
|
|||
chars[i] = char;
|
||||
}
|
||||
*/
|
||||
|
||||
for (let threshold = 0; threshold < 16; threshold++) {
|
||||
charIter:
|
||||
for (let i = 0; i < chars.length; i++) {
|
||||
|
@ -187,43 +212,17 @@
|
|||
for (let hi = 0; hi < 16; hi++) {
|
||||
for (let lo = 0; lo < 16; lo++) {
|
||||
let char = (hi << 4) | lo;
|
||||
let invert = Boolean(char & 0x80);
|
||||
char &= 0x7f;
|
||||
if (char >= uniques.length) {
|
||||
continue;
|
||||
}
|
||||
let block = uniques[char];
|
||||
for (let y = 0; y < blockHeight; y++) {
|
||||
for (let x = 0; x < blockWidth; x++) {
|
||||
let i = y * blockWidth + x;
|
||||
let ii = (y + hi * blockHeight) * 16 * blockWidth + (x + lo * blockWidth);
|
||||
if (block.length < i) {
|
||||
debugger;
|
||||
}
|
||||
let gray16 = block[i];
|
||||
if (invert) {
|
||||
gray16 = ~gray16 & 0x0f;
|
||||
}
|
||||
let gray256 = Math.round(gray16 * 255 / 15);
|
||||
font.data[ii * 4] = gray256;
|
||||
font.data[ii * 4 + 1] = gray256;
|
||||
font.data[ii * 4 + 2] = gray256;
|
||||
font.data[ii * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
drawChar(font, lo, hi, char, uniques);
|
||||
}
|
||||
}
|
||||
fontCtx.putImageData(font, 0, 0);
|
||||
|
||||
// Redraw the blocks
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
let i = y * width + x;
|
||||
let gray16 = pixels[i];
|
||||
let gray256 = Math.round(gray16 * 255 / 15);
|
||||
data[i * 4] = gray256;
|
||||
data[i * 4 + 1] = gray256;
|
||||
data[i * 4 + 2] = gray256;
|
||||
|
||||
for (let cy = 0; cy < heightBlocks; cy++) {
|
||||
for (let cx = 0; cx < widthBlocks; cx++) {
|
||||
let i = cy * widthBlocks + cx;
|
||||
drawChar(bits, cx, cy, chars[i], uniques);
|
||||
}
|
||||
}
|
||||
ctx.putImageData(bits, 0, 0);
|
||||
|
|
Loading…
Reference in a new issue