From 3d0a7dca9fd36cf828128412e4e2b669c760298d Mon Sep 17 00:00:00 2001 From: Ace Date: Mon, 4 Mar 2019 21:46:44 +0100 Subject: [PATCH] Added colour-improvement for bw display The function display_corrected_image also improves the image for the 2-colour E-Paper Display. --- Calendar/E-Paper.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index 37f7e7e..fd7647c 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -306,18 +306,29 @@ def main(): # image.save(path+'before.bmp') width, height = image.size pixels = image.load() - # To-Do: Use lambda instead of double-loop - for x in range(width): - for y in range(height): - pixel = image.getpixel((x, y)) - red = pixel[0] - green = pixel[1] - if red > 240 and green > 240: #white - pixels[x, y] = (255, 255, 255) - elif red > 250 and green < 180: #red - pixels[x, y] = (255, 0, 0) - else: - pixels[x, y] = (0, 0, 0) + if display_colours == "bwr": + for x in range(width): + for y in range(height): + pixel = image.getpixel((x, y)) + red = pixel[0] + green = pixel[1] + if red > 240 and green > 240: #white + pixels[x, y] = (255, 255, 255) + elif red > 250 and green < 180: #red + pixels[x, y] = (255, 0, 0) + else: + pixels[x, y] = (0, 0, 0) + + if display_colours == "bw": + for x in range(width): + for y in range(height): + pixel = image.getpixel((x, y)) + red = pixel[0] + green = pixel[1] + if red > 240 and green > 240: #white + pixels[x, y] = (255, 255, 255) + else: + pixels[x, y] = (0, 0, 0) print('Conversion finished. Enjoy a crisp image on the E-Paper') # Uncomment following line to save the processed image