Skip to content

Commit

Permalink
Merge pull request #35 from makermelissa/master
Browse files Browse the repository at this point in the history
Added RGB888 support to image() function
  • Loading branch information
makermelissa authored Sep 11, 2020
2 parents 622eb96 + 58112d2 commit 036f48d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions adafruit_framebuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,12 @@ def image(self, img):
height = self.height
if self.rotation == 1 or self.rotation == 3:
width, height = height, width
if img.mode != "1":

if isinstance(self.format, RGB888Format) and img.mode != "RGB":
raise ValueError("Image must be in mode RGB.")
if isinstance(self.format, (MHMSBFormat, MVLSBFormat)) and img.mode != "1":
raise ValueError("Image must be in mode 1.")

imwidth, imheight = img.size
if imwidth != width or imheight != height:
raise ValueError(
Expand All @@ -444,7 +448,9 @@ def image(self, img):
# Iterate through the pixels
for x in range(width): # yes this double loop is slow,
for y in range(height): # but these displays are small!
if pixels[(x, y)]:
if img.mode == "RGB":
self.pixel(x, y, pixels[(x, y)])
elif pixels[(x, y)]:
self.pixel(x, y, 1) # only write if pixel is true


Expand Down

0 comments on commit 036f48d

Please sign in to comment.