Skip to content

Commit 21fddc1

Browse files
committed
πŸ§‘β€πŸ’» Update image2bin with "transparency" color
1 parent 528a1ad commit 21fddc1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

β€Žbuildroot/share/scripts/gen-tft-image.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,31 @@
2626
from PIL import Image
2727

2828
def image2bin(image, output_file):
29+
print(f"Converting image with dimensions {image.size[0]}x{image.size[1]}...")
2930
if output_file.endswith(('.c', '.cpp')):
30-
f = open(output_file, 'wt')
3131
is_cpp = True
32+
f = open(output_file, 'wt')
3233
f.write("const uint16_t image[%d] = {\n" % (image.size[1] * image.size[0]))
3334
else:
34-
f = open(output_file, 'wb')
3535
is_cpp = False
36+
f = open(output_file, 'wb')
3637
pixs = image.load()
3738
for y in range(image.size[1]):
39+
f.write(" ")
3840
for x in range(image.size[0]):
3941
R = pixs[x, y][0] >> 3
4042
G = pixs[x, y][1] >> 2
4143
B = pixs[x, y][2] >> 3
4244
rgb = (R << 11) | (G << 5) | B
45+
if rgb == 0: rgb = 1
4346
if is_cpp:
44-
strHex = '0x{0:04X}, '.format(rgb)
47+
strHex = " 0x{0:04X},".format(rgb)
4548
f.write(strHex)
4649
else:
4750
f.write(struct.pack("B", (rgb & 0xFF)))
4851
f.write(struct.pack("B", (rgb >> 8) & 0xFF))
49-
if is_cpp:
50-
f.write("\n")
51-
if is_cpp:
52-
f.write("};\n")
52+
if is_cpp: f.write("\n")
53+
if is_cpp: f.write("};\n")
5354
f.close()
5455

5556
if len(sys.argv) <= 2:

0 commit comments

Comments
Β (0)