2019-03-09 17:24:49 +00:00
|
|
|
#!/usr/bin/env python3
|
2014-04-29 12:26:51 +00:00
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
class Img(object):
|
2014-04-29 12:26:51 +00:00
|
|
|
def __init__(self, fn):
|
|
|
|
im = Image.open(fn)
|
|
|
|
self.w, self.h = im.size
|
|
|
|
self.data = list(im.getdata())
|
|
|
|
|
|
|
|
def pixel(self, r, c):
|
2019-04-18 14:27:27 +00:00
|
|
|
p = self.data[r + c * self.w]
|
2014-04-29 12:26:51 +00:00
|
|
|
if p == (255, 255, 255):
|
2019-04-18 14:27:27 +00:00
|
|
|
return "0"
|
2014-04-29 12:26:51 +00:00
|
|
|
if p == (0, 0, 0):
|
2019-04-18 14:27:27 +00:00
|
|
|
return "1"
|
2014-04-29 12:26:51 +00:00
|
|
|
if p == (255, 0, 255):
|
|
|
|
return None
|
2019-04-18 14:27:27 +00:00
|
|
|
raise Exception("Unknown color", p)
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
|
2018-02-06 21:29:33 +00:00
|
|
|
def convert(imgfile, outfile):
|
|
|
|
img = Img(imgfile)
|
2019-04-18 14:27:27 +00:00
|
|
|
cur = ""
|
|
|
|
with open(outfile, "w") as f:
|
2018-02-06 21:29:33 +00:00
|
|
|
for i in range(128):
|
|
|
|
x = (i % 16) * 10
|
|
|
|
y = (i // 16) * 10
|
2019-04-18 14:27:27 +00:00
|
|
|
cur = ""
|
|
|
|
while img.pixel(x, y) is not None:
|
|
|
|
val = "".join(img.pixel(x, y + j) for j in range(8))
|
2018-02-06 21:29:33 +00:00
|
|
|
x += 1
|
2019-04-18 14:27:27 +00:00
|
|
|
cur += "\\x%02x" % int(val, 2)
|
|
|
|
cur = "\\x%02x" % (len(cur) // 4) + cur
|
|
|
|
ch = chr(i) if i >= 32 and i <= 126 else "_"
|
|
|
|
f.write('\t/* 0x%02x %c */ (uint8_t *)"%s",\n' % (i, ch, cur))
|
|
|
|
|
2018-02-06 21:29:33 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
convert("fonts/fontfixed.png", "fontfixed.inc")
|
|
|
|
convert("fonts/font.png", "font.inc")
|