@@ -352,8 +352,6 @@ def image(self, image):
352
352
"""Set buffer to value of Python Imaging Library image. The image should
353
353
be in RGB mode and a size equal to the display size.
354
354
"""
355
- if image .mode != "RGB" :
356
- raise ValueError ("Image must be in mode RGB." )
357
355
imwidth , imheight = image .size
358
356
if imwidth != self .width or imheight != self .height :
359
357
raise ValueError (
@@ -368,12 +366,21 @@ def image(self, image):
368
366
# clear out any display buffers
369
367
self .fill (Adafruit_EPD .WHITE )
370
368
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