@@ -175,9 +175,10 @@ def pixel(self, x, y, color=None):
175
175
self ._block (x , y , x , y , self ._encode_pixel (color ))
176
176
return None
177
177
178
- def image (self , img , rotation = None ):
179
- """Set buffer to value of Python Imaging Library image. The image should
180
- be in 1 bit mode and a size equal to the display size."""
178
+ def image (self , img , rotation = None , x = 0 , y = 0 ):
179
+ """Set buffer to value of Python Imaging Library image. The image should
180
+ be in 1 bit mode and a size not exceeding the display size when drawn at
181
+ the supplied origin."""
181
182
if rotation is None :
182
183
rotation = self .rotation
183
184
if not img .mode in ('RGB' , 'RGBA' ):
@@ -187,20 +188,20 @@ def image(self, img, rotation=None):
187
188
if rotation != 0 :
188
189
img = img .rotate (rotation , expand = True )
189
190
imwidth , imheight = img .size
190
- if imwidth != self .width or imheight != self .height :
191
- raise ValueError ('Image must be same dimensions as display ({0}x{1}).' \
191
+ if x + imwidth > self .width or y + imheight > self .height :
192
+ raise ValueError ('Image must not exceed dimensions of display ({0}x{1}).' \
192
193
.format (self .width , self .height ))
193
194
if numpy :
194
195
pixels = list (image_to_data (img ))
195
196
else :
196
197
# Slower but doesn't require numpy
197
- pixels = bytearray (self . width * self . height * 2 )
198
- for x in range (self . width ):
199
- for y in range (self . height ):
200
- pix = color565 (img .getpixel ((x , y )))
201
- pixels [2 * (y * self . width + x )] = pix >> 8
202
- pixels [2 * (y * self . width + x ) + 1 ] = pix & 0xFF
203
- self ._block (0 , 0 , self . width - 1 , self . height - 1 , pixels )
198
+ pixels = bytearray (imwidth * imheight * 2 )
199
+ for i in range (imwidth ):
200
+ for j in range (imheight ):
201
+ pix = color565 (img .getpixel ((i , j )))
202
+ pixels [2 * (j * imwidth + i )] = pix >> 8
203
+ pixels [2 * (j * imwidth + i ) + 1 ] = pix & 0xFF
204
+ self ._block (x , y , x + imwidth - 1 , y + imheight - 1 , pixels )
204
205
205
206
#pylint: disable-msg=too-many-arguments
206
207
def fill_rectangle (self , x , y , width , height , color ):
0 commit comments