1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-30 20:02:34 +00:00
trezor-firmware/core/embed/unix/jpg_to_h.py
grdddj 6b5f578d02 feat(core): implement basic R emulator
Can be built by `TREZOR_MODEL=R make build_unix`, `make build_unix_frozen` does not work yet.

All the dialogs are not very pretty, they are just meant to work.
2022-05-06 11:44:52 +02:00

35 lines
907 B
Python

"""
Creates a header file containing image data.
"""
background_image = "background_R.jpg"
h_file_name = "background_R.h"
h_file_template = """\
// clang-format off
unsigned char background_R_jpg[] = {content};
unsigned int background_R_jpg_len = {length};
"""
with open(background_image, "rb") as f:
image_data = f.read()
column_count = 12
content = "{{\n{image_bytes}\n}}"
image_bytes = " " # begin with indent
for index, byte in enumerate(image_data, start=1):
image_bytes += f"0x{byte:02x},"
# If at the end of line, include a newline with indent, otherwise just space
if index % column_count == 0:
image_bytes += "\n "
else:
image_bytes += " "
# Get rid of trailing coma
image_bytes = image_bytes.rstrip(", \n")
with open(h_file_name, "w") as f:
f.write(h_file_template.format(content=content.format(image_bytes=image_bytes), length=len(image_data)))