1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
|