diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-02-11 10:54:47 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-02-11 10:54:47 +0100 |
commit | b6206e83d10eb7e350b6ea17ab9f649a09332f52 (patch) | |
tree | 3599c4345fa56a4a0129fc1dcb7a0369a086492c /src/app/bad-apple-atmega2560-ssd1306/frames-to-cc | |
parent | 0d6dfd6e47cbeff1e10f0c536824e5f7259b21e8 (diff) |
Add Bad Apple on ATMega2560 (not working very well)
Looks like these devices can only use the lower 64 kB as PROGMEM, so the
whole exercise is kinda pointless. Also inflate() is slow af.
Diffstat (limited to 'src/app/bad-apple-atmega2560-ssd1306/frames-to-cc')
-rwxr-xr-x | src/app/bad-apple-atmega2560-ssd1306/frames-to-cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/app/bad-apple-atmega2560-ssd1306/frames-to-cc b/src/app/bad-apple-atmega2560-ssd1306/frames-to-cc new file mode 100755 index 0000000..07b55be --- /dev/null +++ b/src/app/bad-apple-atmega2560-ssd1306/frames-to-cc @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from PIL import Image +import os +import sys +import zlib + +buf_w, buf_h = map(int, os.getenv("size", "128x32").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): + buf = load_image(sys.argv[i]) + 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"unsigned char const PROGMEM frame{i:04d}[] = {{ {len(z_buf)}, {out_buf} }};") + +frames = list() +for i in range(1, len(sys.argv) - 2): + frames.append(f"frame{i:04d}") + +prefix = "const unsigned char* const frames[] PROGMEM = {" +postfix = "};" + +print(prefix + ", ".join(frames) + postfix) |