From 21fddc1cc8efec2f74984097fc0e541b4b65b553 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 29 Aug 2024 15:36:55 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Update=20im?= =?UTF-8?q?age2bin=20with=20"transparency"=20color?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildroot/share/scripts/gen-tft-image.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/buildroot/share/scripts/gen-tft-image.py b/buildroot/share/scripts/gen-tft-image.py index d00f980fb016..95471a991286 100644 --- a/buildroot/share/scripts/gen-tft-image.py +++ b/buildroot/share/scripts/gen-tft-image.py @@ -26,30 +26,31 @@ from PIL import Image def image2bin(image, output_file): + print(f"Converting image with dimensions {image.size[0]}x{image.size[1]}...") if output_file.endswith(('.c', '.cpp')): - f = open(output_file, 'wt') is_cpp = True + f = open(output_file, 'wt') f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0])) else: - f = open(output_file, 'wb') is_cpp = False + f = open(output_file, 'wb') pixs = image.load() for y in range(image.size[1]): + f.write(" ") for x in range(image.size[0]): R = pixs[x, y][0] >> 3 G = pixs[x, y][1] >> 2 B = pixs[x, y][2] >> 3 rgb = (R << 11) | (G << 5) | B + if rgb == 0: rgb = 1 if is_cpp: - strHex = '0x{0:04X}, '.format(rgb) + strHex = " 0x{0:04X},".format(rgb) f.write(strHex) else: f.write(struct.pack("B", (rgb & 0xFF))) f.write(struct.pack("B", (rgb >> 8) & 0xFF)) - if is_cpp: - f.write("\n") - if is_cpp: - f.write("};\n") + if is_cpp: f.write("\n") + if is_cpp: f.write("};\n") f.close() if len(sys.argv) <= 2: