Skip to content
Snippets Groups Projects
Verified Commit 9e005da2 authored by rahix's avatar rahix
Browse files

feat(tools): Rewrite imageconvert script


Rewrite image-convert script to more easily change the version splash
screen.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 6bf3fd5b
No related branches found
No related tags found
No related merge requests found
Pipeline #4221 passed
#!/usr/bin/env python3
from PIL import Image
import sys
if len(sys.argv) < 2:
print("Usage: %s <image file>" % sys.argv[0])
sys.exit(1)
im = Image.open(sys.argv[1])
out_name = '.'.join(sys.argv[1].split('.')[:-1])
print(out_name)
out = open(out_name + ".h", 'w')
out.write("const unsigned char %s[] = {\n" % out_name.split('/')[-1])
for x in range(im.size[1]):
for y in range(im.size[0]):
px = im.getpixel((y, x))
px16 = ((px[0] >> 3) << 11) | ((px[1] >> 2) << 5) | (px[2] >> 3)
px16h = (px16 & 0xFF00) >> 8
px16l = px16 & 0xFF
out.write("0x%02x, 0x%02x,\n" % (px16l, px16h))
out.write("};\n")
#!/usr/bin/env python3
import argparse
import os
from PIL import Image
def main() -> None:
parser = argparse.ArgumentParser(
description="""\
Update the epicardium version-splash. NOTE: You need to adjust
epicardium/main.c if you want to actually see your version splash!!
"""
)
parser.add_argument("image", help="Path to version image")
args = parser.parse_args()
im = Image.open(args.image)
assert im.size[0] == 160, "Image must be 160 pixels wide"
assert im.size[1] == 80, "Image must be 80 pixels high)"
# find version-splash.h
vsplash = os.path.join(os.path.dirname(__file__), "../epicardium/version-splash.h")
with open(vsplash, "w") as f:
tmp = """\
#pragma once
#include <stdint.h>
/* clang-format off */
const uint8_t version_splash[] = {
"""
f.write(tmp)
for x in range(im.size[1]):
for y in range(im.size[0]):
px = im.getpixel((y, x))
px565 = ((px[0] >> 3) << 11) | ((px[1] >> 2) << 5) | (px[2] >> 3)
byte_high = (px565 & 0xFF00) >> 8
byte_low = px565 & 0xFF
if y % 4 == 0:
f.write("\t")
f.write("0x{:02x}, 0x{:02x},".format(byte_low, byte_high))
if y % 4 == 3:
f.write("\n")
else:
f.write(" ")
f.write("};\n")
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment