Skip to content
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
13 changes: 9 additions & 4 deletions adafruit_framebuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,18 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
def image(self, img):
"""Set buffer to value of Python Imaging Library image. The image should
be in 1 bit mode and a size equal to the display size."""
# determine our effective width/height, taking rotation into account
width = self.width
height = self.height
if self.rotation == 1 or self.rotation == 3:
width, height = height, width
if img.mode != "1":
raise ValueError("Image must be in mode 1.")
imwidth, imheight = img.size
if imwidth != self.width or imheight != self.height:
if imwidth != width or imheight != height:
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.width, self.height
width, height
)
)
# Grab all the pixels from the image, faster than getpixel.
Expand All @@ -387,8 +392,8 @@ def image(self, img):
for i in range(len(self.buf)):
self.buf[i] = 0
# Iterate through the pixels
for x in range(self.width): # yes this double loop is slow,
for y in range(self.height): # but these displays are small!
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)]:
self.pixel(x, y, 1) # only write if pixel is true

Expand Down