inkplate-6-arduino-library/examples/3. Projects/1-Daily_weather_station_exa.../iconConvert.py

31 lines
918 B
Python
Raw Normal View History

2020-07-29 09:37:28 +02:00
# -----------
# Simple python script to
# create icon header files for Inkplate 6
# Arduino sketches
#
# Takes all files from /icons and saves them to /binary_icons
#
# -----------
2020-07-29 08:51:24 +02:00
from PIL import Image
import os, sys
if not os.path.isdir("./binary_icons"):
os.mkdir(os.path.abspath(os.getcwd()) + "/binary_icons")
for file in os.listdir("./icons"):
im = Image.open("./icons/" + file)
2020-08-11 09:26:59 +02:00
im = im.resize((48, 48))
2020-07-29 08:51:24 +02:00
alp = im.split()[-1]
2020-08-11 09:26:59 +02:00
s = [0 for x in range(48 * 48)]
for y in range(48):
for x in range(48):
2020-07-29 08:51:24 +02:00
# print(im.getpixel((x, y)))
if alp.getpixel((x, y)) > 128:
2020-08-11 09:26:59 +02:00
s[(x + 48 * y) // 8] |= 1 << (7 - (x + 48 * y) % 8)
2020-07-29 08:51:24 +02:00
2020-08-11 09:26:59 +02:00
with open("./binary_icons/icon_s_" + file[:-4] + ".h", "w") as f:
print("const uint8_t icon_s_" + file[:-4] + "[] PROGMEM = {", file=f)
2020-07-29 08:51:24 +02:00
print(",".join(list(map(hex, s))), file=f)
print("};", file=f)