Merge pull request #41 from makermelissa/master
Added grayscale image mode support because why not
This commit is contained in:
commit
3ca62375a9
1 changed files with 18 additions and 11 deletions
|
|
@ -352,8 +352,6 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu
|
|||
"""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,6 +366,7 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu
|
|||
# clear out any display buffers
|
||||
self.fill(Adafruit_EPD.WHITE)
|
||||
|
||||
if image.mode == "RGB": # RGB Mode
|
||||
for y in range(image.size[1]):
|
||||
for x in range(image.size[0]):
|
||||
pixel = pix[x, y]
|
||||
|
|
@ -377,3 +376,11 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu
|
|||
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.")
|
||||
|
|
|
|||
Loading…
Reference in a new issue