diff --git a/tools/imageconvert.py b/tools/imageconvert.py deleted file mode 100755 index 72ea36139b31c3115307968c73ce5cccfa0fb483..0000000000000000000000000000000000000000 --- a/tools/imageconvert.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/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") diff --git a/tools/version-image.py b/tools/version-image.py new file mode 100755 index 0000000000000000000000000000000000000000..0a20327c25d5e669e05ed90b5255e888a0ac61e5 --- /dev/null +++ b/tools/version-image.py @@ -0,0 +1,58 @@ +#!/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()