更改 sant 任意尺寸图像显示由C完成,加快处理速度

This commit is contained in:
dahanzimin
2025-10-29 21:17:06 +08:00
parent 619281e107
commit b240e1ed1a

View File

@@ -37,35 +37,12 @@ class ST7789(uframebuf.FrameBuffer_Uincode):
def display(self, data=None, x=None, y=None, rotation=0, sync=True):
if type(data) is str:
data = Image.open(data, rotation)
self._blit(data, x, y)
self.blit_rgb565(data.image, data.width, data.height, 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]))