1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 21:38:26 +00:00
trezor-firmware/gen/fonts/generate.py

36 lines
923 B
Python
Raw Normal View History

2017-02-01 17:07:47 +00:00
#!/usr/bin/env python
from __future__ import print_function
2014-04-29 12:26:51 +00:00
from PIL import Image
class Img(object):
def __init__(self, fn):
im = Image.open(fn)
self.w, self.h = im.size
self.data = list(im.getdata())
def pixel(self, r, c):
p = self.data[ r + c * self.w ]
if p == (255, 255, 255):
return '0'
if p == (0, 0, 0):
return '1'
if p == (255, 0, 255):
return None
raise Exception('Unknown color', p)
img = Img('font.png')
cur = ''
2015-02-13 16:42:23 +00:00
for i in range(256):
x = (i % 16) * 10
2017-02-01 17:07:47 +00:00
y = (i // 16) * 10
2015-02-13 16:42:23 +00:00
cur = ''
while img.pixel(x, y) != None:
val = ''.join(img.pixel(x, y + j) for j in range(8))
x += 1
cur += '\\x%02x' % int(val, 2)
2017-02-01 17:07:47 +00:00
cur = '\\x%02x' % (len(cur) // 4) + cur
2015-02-13 16:42:23 +00:00
ch = chr(i) if i >= 32 and i <= 126 else '_'
2017-02-01 17:07:47 +00:00
print('\t/* 0x%02x %c */ (uint8_t *)"%s",' % (i, ch , cur))