insert imgconvert.py

Signed-off-by: Peter Siegmund <peter@rdkr.com>
This commit is contained in:
Peter Siegmund
2024-05-29 12:55:44 +02:00
parent e8543c1710
commit 2a98cb9367
3 changed files with 52 additions and 1 deletions

2
ePaper/Makefile Normal file
View File

@@ -0,0 +1,2 @@
convert:
python imgconvert.py -i ./data/staticmap.png -o src/staticmap.h -n staticmap

49
ePaper/imgconvert.py Executable file
View File

@@ -0,0 +1,49 @@
#!python3
from PIL import Image, ImageOps
from argparse import ArgumentParser
import sys
import math
SCREEN_WIDTH = 1200
SCREEN_HEIGHT = 825
if SCREEN_WIDTH % 2:
print("image width must be even!", file=sys.stderr)
sys.exit(1)
parser = ArgumentParser()
parser.add_argument('-i', action="store", dest="inputfile")
parser.add_argument('-n', action="store", dest="name")
parser.add_argument('-o', action="store", dest="outputfile")
args = parser.parse_args()
im = Image.open(args.inputfile)
# convert to grayscale
im = im.convert(mode='L')
im.thumbnail((SCREEN_WIDTH, SCREEN_HEIGHT), Image.LANCZOS)
# Write out the output file.
with open(args.outputfile, 'w') as f:
f.write("const uint32_t {}_width = {};\n".format(args.name, im.size[0]))
f.write("const uint32_t {}_height = {};\n".format(args.name, im.size[1]))
f.write(
"const uint8_t {}_data[({}*{})/2] = {{\n".format(args.name, math.ceil(im.size[0] / 2) * 2, im.size[1])
)
for y in range(0, im.size[1]):
byte = 0
done = True
for x in range(0, im.size[0]):
l = im.getpixel((x, y))
if x % 2 == 0:
byte = l >> 4
done = False;
else:
byte |= l & 0xF0
f.write("0x{:02X}, ".format(byte))
done = True
if not done:
f.write("0x{:02X}, ".format(byte))
f.write("\n\t");
f.write("};\n")

View File

@@ -34,7 +34,7 @@ void setup()
memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
Rect_t area = {
.x = 0,
.x = EPD_WIDTH - staticmap_width,
.y = 0,
.width = staticmap_width,
.height = staticmap_height};