更新 sant 支持大于和小于屏幕尺寸图片显示,及位置
This commit is contained in:
@@ -34,15 +34,38 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
|
||||
self._oneclight = True
|
||||
self._backlight = backlight
|
||||
|
||||
def display(self, data=None, rotation=0, sync=True):
|
||||
def display(self, data=None, x=None, y=None, rotation=0, sync=True):
|
||||
if type(data) is str:
|
||||
data = Image.open(data, rotation)
|
||||
self._buffer[:] = data.image # 后期做图像尺寸匹配处理
|
||||
self._blit(data, x, y)
|
||||
if sync: self.show()
|
||||
|
||||
def screenshot(self):
|
||||
return IMG(memoryview(self._buffer), self.width, self.height)
|
||||
|
||||
def _blit(self, img, x=None, y=None):
|
||||
'''考虑后期封装C模块,加快速度'''
|
||||
if img.width == self.width and img.height == self.height:
|
||||
self._buffer[:] = img.image
|
||||
#大于屏幕图像
|
||||
elif img.width > self.width and img.height > self.height:
|
||||
_x = ((img.width - self.width) // 2) if x is None else max(0, min(x, img.width - self.width))
|
||||
_y = ((img.height - self.height) // 2) if y is None else max(0, min(y, img.height - self.height))
|
||||
for line in range(self.height):
|
||||
src_pos = ((_y + line) * img.width + _x) * 2
|
||||
dst_pos = line * self.width * 2
|
||||
self._buffer[dst_pos:dst_pos + self.width * 2] = img.image[src_pos:src_pos + self.width * 2]
|
||||
#小于屏幕图像
|
||||
elif img.width < self.width and img.height < self.height:
|
||||
_x = ((self.width - img.width) // 2) if x is None else max(0, min(x, self.width - img.width))
|
||||
_y = ((self.height- img.height) // 2) if y is None else max(0, min(y, self.height - img.width))
|
||||
for line in range(img.height):
|
||||
src_pos = line * img.width * 2
|
||||
dst_pos = ((_y + line) * self.width + _x) * 2
|
||||
self._buffer[dst_pos:dst_pos + img.width * 2] = img.image[src_pos:src_pos + img.width * 2]
|
||||
else:
|
||||
raise ValueError("Unsupported image size for display")
|
||||
|
||||
def _write(self, cmd, dat=None):
|
||||
self.dc.off()
|
||||
self.spi.write(bytearray([cmd]))
|
||||
|
||||
Reference in New Issue
Block a user