Skip to content

Commit

Permalink
Merge pull request #41 from makermelissa/master
Browse files Browse the repository at this point in the history
Added grayscale image mode support because why not
  • Loading branch information
makermelissa committed Aug 18, 2020
2 parents be557c4 + 732e1a0 commit 3ca6237
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions adafruit_epd/epd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.")

0 comments on commit 3ca6237

Please sign in to comment.