From 732e1a0d7e6679424822773937b96d1c8b2dafa7 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 18 Aug 2020 13:51:29 -0700 Subject: [PATCH] Added grayscale image support just because --- adafruit_epd/epd.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/adafruit_epd/epd.py b/adafruit_epd/epd.py index 46de793..f2abc04 100644 --- a/adafruit_epd/epd.py +++ b/adafruit_epd/epd.py @@ -352,8 +352,6 @@ def image(self, image): """Set buffer to value of Python Imaging Library image. The image should be in RGB mode and a size equal to the display size. """ - if image.mode != "RGB": - raise ValueError("Image must be in mode RGB.") imwidth, imheight = image.size if imwidth != self.width or imheight != self.height: raise ValueError( @@ -368,12 +366,21 @@ def image(self, image): # clear out any display buffers self.fill(Adafruit_EPD.WHITE) - for y in range(image.size[1]): - for x in range(image.size[0]): - pixel = pix[x, y] - if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80): - # reddish - self.pixel(x, y, Adafruit_EPD.RED) - elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80): - # dark - self.pixel(x, y, Adafruit_EPD.BLACK) + if image.mode == "RGB": # RGB Mode + for y in range(image.size[1]): + for x in range(image.size[0]): + pixel = pix[x, y] + if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80): + # reddish + self.pixel(x, y, Adafruit_EPD.RED) + elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80): + # dark + self.pixel(x, y, Adafruit_EPD.BLACK) + elif image.mode == "L": # Grayscale + for y in range(image.size[1]): + for x in range(image.size[0]): + pixel = pix[x, y] + if pixel < 0x80: + self.pixel(x, y, Adafruit_EPD.BLACK) + else: + raise ValueError("Image must be in mode RGB or mode L.")