Last active
July 30, 2024 19:04
-
-
Save 0xD34D/99c5e5e471f140ea5f838049fd303e8e to your computer and use it in GitHub Desktop.
drawing a PNG on an E3V3SE display using lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Image.open(filename).convert('RGB') as image: | |
width, height = image.size | |
img_x = int((240 - width) / 2) | |
img_y = int((320 - height) / 2) | |
start_color = 0 | |
start_x = 0 | |
for y in range(0, height): | |
start_color = 0 | |
start_x = 0 | |
for x in range(0, width): | |
pixel = image.getpixel((x, y)) | |
color_rgb565 = rgb_to_rgb565(pixel[0], pixel[1], pixel[2]) | |
if x == 0: | |
# starting a new line so set start_color to this color value | |
start_color = color_rgb565 | |
elif x == width - 1: | |
# process the end of the line | |
if color_rgb565 != start_color: | |
disp.draw_line(start_x + img_x, y + img_y, img_x + x-1, y + img_y, start_color) | |
start_x = x | |
start_color = color_rgb565 | |
disp.draw_line(start_x + img_x, y + img_y, img_x + x, y + img_y, start_color) | |
elif color_rgb565 != start_color: | |
# current color does not match start color so draw line up to | |
# x-1 using start_color | |
disp.draw_line(start_x + img_x, y + img_y, img_x + x-1, y + img_y, start_color) | |
start_x = x | |
start_color = color_rgb565 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment