diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-02-10 22:11:25 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-02-10 22:11:25 +0100 |
commit | 467b1b587811a2091d04a5faab20d6430313cd51 (patch) | |
tree | 496f43b1b3ca16a1e0995267623914db4136e70c /src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc | |
parent | b5b506c97469f1917de4e7b7bd291f68b6d8d897 (diff) |
rename ssd1306-bad-apple to bad-apple-msp430fr-ssd1306-128x64
Diffstat (limited to 'src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc')
-rwxr-xr-x | src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc b/src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc new file mode 100755 index 0000000..bcbabf7 --- /dev/null +++ b/src/app/bad-apple-msp430fr-ssd1306-128x64/frames-to-cc @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +from PIL import Image +import os +import sys +import zlib + +buf_w, buf_h = map(int, os.getenv("size", "128x64").split("x")) + +def load_image(filename): + im = Image.open(filename) + w, h = im.size + buf = [0 for i in range(buf_w * buf_h // 8)] + for y in range(min(h, buf_h)): + for x in range(min(w, buf_w)): + if im.getpixel((x, y)): + buf[(y // 8) * buf_w + x] |= 1 << (y % 8) + return buf + + +for i in range(1, len(sys.argv) - 2, 3): + buf = ( + load_image(sys.argv[i]) + + load_image(sys.argv[i + 1]) + + load_image(sys.argv[i + 2]) + ) + c_buf = ",".join(map(str, buf)) + z_buf = zlib.compress(bytes(buf), 9) + z_buf = z_buf[2:-4] + out_buf = ",".join(map(str, z_buf)) + print( + f'__attribute__((section(".text"))) unsigned char const frame{i:04d}[] = {{ {out_buf} }};' + ) + +frames = list() +for i in range(1, len(sys.argv) - 2, 3): + frames.append(f"(unsigned char*)frame{i:04d}") + +prefix = "unsigned char* const frames[] = {" +postfix = "};" + +print(prefix + ", ".join(frames) + postfix) |