Skip to content

Allow image drawing in subscreen areas #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
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
25 changes: 13 additions & 12 deletions adafruit_rgb_display/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ def pixel(self, x, y, color=None):
self._block(x, y, x, y, self._encode_pixel(color))
return None

def image(self, img, rotation=None):
"""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."""
def image(self, img, rotation=None, x=0, y=0):
"""Set buffer to value of Python Imaging Library image. The image should
be in 1 bit mode and a size not exceeding the display size when drawn at
the supplied origin."""
if rotation is None:
rotation = self.rotation
if not img.mode in ('RGB', 'RGBA'):
Expand All @@ -187,20 +188,20 @@ def image(self, img, rotation=None):
if rotation != 0:
img = img.rotate(rotation, expand=True)
imwidth, imheight = img.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
if x + imwidth > self.width or y + imheight > self.height:
raise ValueError('Image must not exceed dimensions of display ({0}x{1}).' \
.format(self.width, self.height))
if numpy:
pixels = list(image_to_data(img))
else:
# Slower but doesn't require numpy
pixels = bytearray(self.width * self.height * 2)
for x in range(self.width):
for y in range(self.height):
pix = color565(img.getpixel((x, y)))
pixels[2*(y * self.width + x)] = pix >> 8
pixels[2*(y * self.width + x) + 1] = pix & 0xFF
self._block(0, 0, self.width - 1, self.height - 1, pixels)
pixels = bytearray(imwidth * imheight * 2)
for i in range(imwidth):
for j in range(imheight):
pix = color565(img.getpixel((i, j)))
pixels[2*(j * imwidth + i)] = pix >> 8
pixels[2*(j * imwidth + i) + 1] = pix & 0xFF
self._block(x, y, x + imwidth - 1, y + imheight - 1, pixels)

#pylint: disable-msg=too-many-arguments
def fill_rectangle(self, x, y, width, height, color):
Expand Down