Skip to content

Added grayscale image mode support because why not #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")