-
Notifications
You must be signed in to change notification settings - Fork 31
/
convert.py
46 lines (34 loc) · 818 Bytes
/
convert.py
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
38
39
40
41
42
43
44
45
#!/bin/env python3
import sys, os
from PIL import Image
if len(sys.argv) != 2:
print("Usage: ",sys.argv[0],"dir")
exit()
def image_to_bytes(i):
im = Image.open(i)
w,h = im.size
pixels = [1 if p[0]>2 else 0 for p in list(im.getdata())]
print(" {",end="")
for x in range(w):
word = 0x0401FF00 | (1<<x)
for y in range(h):
p = (pixels[y*8+x])
if p:
if y == 8:
word &= ~(1<<16)
elif y == 9:
word &= ~(1<<26)
else:
word &= ~(1<<(y+8))
print(f"0x{word:08X}",end = ", " if x<w-1 else "")
print(" },")
files = [os.path.join( sys.argv[1], f) for f in os.listdir( sys.argv[1] )]
files.sort()
n=0
print(f"const uint32_t framedata[{len(files)//24}][24][8]=","{")
for f in files:
if (n%24) == 0:
print(" },{" if n>0 else " {")
n+=1
image_to_bytes(f)
print(" }\n};")