From dbf44e3f605968ff08851e1779d53a66a5ed747e Mon Sep 17 00:00:00 2001 From: dahanzimin <353767514@qq.com> Date: Mon, 27 Oct 2025 19:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20sant=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=A7=E4=BA=8E=E5=92=8C=E5=B0=8F=E4=BA=8E=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA=EF=BC=8C?= =?UTF-8?q?=E5=8F=8A=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../origin/build/lib/st7789_cf.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py index 8da8b900..c67b1464 100644 --- a/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py +++ b/boards/default_src/micropython_esp32s3/origin/build/lib/st7789_cf.py @@ -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]))