Skip to content

Commit 3ca6237

Browse files
authored
Merge pull request #41 from makermelissa/master
Added grayscale image mode support because why not
2 parents be557c4 + 732e1a0 commit 3ca6237

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)