1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00
trezor-firmware/core/tools/codegen/gen_loader.py

38 lines
1.4 KiB
Python
Raw Normal View History

2018-09-30 13:42:58 +00:00
#!/usr/bin/env python3
# script used to generate /embed/extmod/modtrezorui/loader.h
2016-05-12 12:07:15 +00:00
import math
outer = 60
2016-10-04 14:33:57 +00:00
inner = 42
2016-05-12 12:07:15 +00:00
2018-07-31 09:35:09 +00:00
with open("loader.h", "wt") as f:
f.write("static const int img_loader_size = %d;\n" % outer)
f.write("static const uint16_t img_loader[%d][%d] = {\n" % (outer, outer))
2016-05-12 12:07:15 +00:00
for y in range(outer):
2018-07-31 09:35:09 +00:00
f.write(" {")
2016-05-12 12:07:15 +00:00
for x in range(outer):
d = math.sqrt((outer - 1 - x) ** 2 + (outer - 1 - y) ** 2)
c = {}
for i in [5, 15]:
if (inner - 0.5 <= d) and (d <= inner + 0.5):
c[i] = 15 * (d - inner + 0.5)
2016-05-12 12:07:15 +00:00
elif (inner + 0.5 <= d) and (d <= inner + 1.5):
c[i] = 15
elif (inner + 1.5 <= d) and (d <= inner + 2.5):
c[i] = 15 if i == 15 else 15 - (15 - i) * (d - inner - 1.5)
elif (outer - 1.5 <= d) and (d <= outer - 0.5):
c[i] = i - i * (d - outer + 1.5)
elif (inner + 2.5 < d) and (d < outer - 1.5):
c[i] = i
else:
c[i] = 0
# clamp (should not be needed)
c[i] = max(0, min(int(c[i]), 15))
a = int(math.atan2((outer - 1 - x), (outer - 1 - y)) * 2 * 249 / math.pi)
v = (a << 8) | (c[15] << 4) | c[5]
2018-07-31 09:35:09 +00:00
f.write("%d," % v)
f.write("},\n")
f.write("};\n")