Skip to content
Permalink
Browse files

finish?

  • Loading branch information...
graphitemaster committed Jun 9, 2019
1 parent b66fdab commit 8174ed6a2b979d394f21b2bc05eccd8e1a1f6cbf
Showing with 86 additions and 1 deletion.
  1. +37 −1 README.md
  2. BIN done-scale.png
  3. BIN done.png
  4. +49 −0 index.js
@@ -381,4 +381,40 @@ The `decode` function here gives us our original `1x5` strip for the given glyph

* Writing this in assembler or C would allow you to actually see these savings

Now all that's left is a way to compose these vertical strips into an image for the purposes of drawing some text.
Now all that's left is a way to compose these vertical strips into an image for the purposes of drawing some text.

```js
print = (t) => {
const c = t.toUpperCase().replace(/[^\w\d ]/g, '');
const w = c.length * 2 - 1, h = 5, bpp = 3; // * 2 for whitespace
const b = new Uint8Array(w * h * bpp);
[...c].forEach((g, i) => {
if (g !== ' ') for (let y = 0; y < h; y++) {
// copy each 1x1 pixel row to the the bitmap
b.set(decode(g).slice(y * bpp, y * bpp + bpp), (y * w + i * 2) * bpp);
}
});
return {w: w, h: h, data: b};
};
```

With that we've broken the physical limits of fonts. Here

```js
const fs = require('fs');
const result = print("Breaking the physical limits of fonts");
fs.writeFileSync(`${result.w}x${result.h}.bin`, result.data);
```

Use some [imagemagick](https://imagemagick.org/index.php)
```
# convert -size 73x5 -depth 8 rgb:73x5.bin done.png
```

Here's the final result

![](done.png)

Here it is scaled up 12x

![](done-scale.png)
BIN +630 Bytes done-scale.png
Binary file not shown.
BIN +391 Bytes done.png
Binary file not shown.
@@ -0,0 +1,49 @@
const Alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const Atlas = Uint8Array.from(Buffer.from('MFAAAAwDKNbUsky0bVFtTdq2aZJqDdq2Udt2FQBgAJwCheagdS21kFRlW9e1adJqTdugU4kqADBgQA0jKFC0CmthrQA=', 'base64'));
const Palette = [
[0xff, 0xff, 0xff],
[0xff, 0x00, 0x00],
[0x00, 0xff, 0x00],
[0x00, 0x00, 0xff],
[0x00, 0xff, 0xff],
[0xff, 0x00, 0xff],
[0xff, 0xff, 0x00]
];

read = (offset) => {
let value = 0;
for (let i = 0; i < 3; ) {
const bit_offset = offset & 7;
const read = Math.min(3 - i, 8 - bit_offset);
const read_bits = (Atlas[offset >> 3] >> bit_offset) & (~(0xff << read));
value |= read_bits << i;
offset += read;
i += read;
}
return value;
};

unpack = (g) => {
return (new Uint8Array(5)).map((_, i) =>
read(Alphabet.length*3*i + Alphabet.indexOf(g)*3));
};

decode = (g) => {
const rgb = new Uint8Array(5*3);
unpack(g).forEach((value, index) =>
rgb.set(Palette[value], index*3));
return rgb;
}

print = (t) => {
const c = t.toUpperCase().replace(/[^\w\d ]/g, '');
const w = c.length * 2 - 1, h = 5, bpp = 3;
const b = new Uint8Array(w*h*bpp);
let x = 0;
[...c].forEach((g, i) => {
if (g !== ' ') for (let y = 0; y < 5; y++) {
b.set(decode(g).slice(y*3, y*3+3), (y * w + i*2) * bpp);
}
});
return {w: w, h: h, data: b};
};

0 comments on commit 8174ed6

Please sign in to comment.
You can’t perform that action at this time.