Skip to content

Commit 732e1a0

Browse files
committed
Added grayscale image support just because
1 parent be557c4 commit 732e1a0

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

adafruit_epd/epd.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ def image(self, image):
352352
"""Set buffer to value of Python Imaging Library image. The image should
353353
be in RGB mode and a size equal to the display size.
354354
"""
355-
if image.mode != "RGB":
356-
raise ValueError("Image must be in mode RGB.")
357355
imwidth, imheight = image.size
358356
if imwidth != self.width or imheight != self.height:
359357
raise ValueError(
@@ -368,12 +366,21 @@ def image(self, image):
368366
# clear out any display buffers
369367
self.fill(Adafruit_EPD.WHITE)
370368

371-
for y in range(image.size[1]):
372-
for x in range(image.size[0]):
373-
pixel = pix[x, y]
374-
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
375-
# reddish
376-
self.pixel(x, y, Adafruit_EPD.RED)
377-
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
378-
# dark
379-
self.pixel(x, y, Adafruit_EPD.BLACK)
369+
if image.mode == "RGB": # RGB Mode
370+
for y in range(image.size[1]):
371+
for x in range(image.size[0]):
372+
pixel = pix[x, y]
373+
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
374+
# reddish
375+
self.pixel(x, y, Adafruit_EPD.RED)
376+
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
377+
# dark
378+
self.pixel(x, y, Adafruit_EPD.BLACK)
379+
elif image.mode == "L": # Grayscale
380+
for y in range(image.size[1]):
381+
for x in range(image.size[0]):
382+
pixel = pix[x, y]
383+
if pixel < 0x80:
384+
self.pixel(x, y, Adafruit_EPD.BLACK)
385+
else:
386+
raise ValueError("Image must be in mode RGB or mode L.")

0 commit comments

Comments
 (0)