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
|
"""Set buffer to value of Python Imaging Library image. The image should
|
||||||
be in RGB mode and a size equal to the display size.
|
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
|
imwidth, imheight = image.size
|
||||||
if imwidth != self.width or imheight != self.height:
|
if imwidth != self.width or imheight != self.height:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
@ -368,12 +366,21 @@ class Adafruit_EPD: # pylint: disable=too-many-instance-attributes, too-many-pu
|
||||||
# clear out any display buffers
|
# clear out any display buffers
|
||||||
self.fill(Adafruit_EPD.WHITE)
|
self.fill(Adafruit_EPD.WHITE)
|
||||||
|
|
||||||
for y in range(image.size[1]):
|
if image.mode == "RGB": # RGB Mode
|
||||||
for x in range(image.size[0]):
|
for y in range(image.size[1]):
|
||||||
pixel = pix[x, y]
|
for x in range(image.size[0]):
|
||||||
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
|
pixel = pix[x, y]
|
||||||
# reddish
|
if (pixel[1] < 0x80 <= pixel[0]) and (pixel[2] < 0x80):
|
||||||
self.pixel(x, y, Adafruit_EPD.RED)
|
# reddish
|
||||||
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
|
self.pixel(x, y, Adafruit_EPD.RED)
|
||||||
# dark
|
elif (pixel[0] < 0x80) and (pixel[1] < 0x80) and (pixel[2] < 0x80):
|
||||||
self.pixel(x, y, Adafruit_EPD.BLACK)
|
# 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