From 04a8daeff4bef4649d12ce78e6949c9d744a238b Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Mon, 22 Jun 2020 22:20:34 +0100 Subject: [PATCH] draw565: Optimize filled rectangle drawing The original approach is *really* bad at drawing vertical lines (it ends up working a pixel at a time and works the chip select for each one. Optimize both the pixel fill and the use of the line buffer. The result is 20% faster for quarter screen fills, 3x for horizontal lines and 6x for vertical lines. Signed-off-by: Daniel Thompson --- wasp/draw565.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/wasp/draw565.py b/wasp/draw565.py index 2e248b4..f0313dc 100644 --- a/wasp/draw565.py +++ b/wasp/draw565.py @@ -125,9 +125,32 @@ class Draw565(object): :param h: Height of the rectangle, defaults to None (which means select the bottom-most pixel of the display) """ + display = self._display + quick_write = display.quick_write + if bg is None: bg = self._bgfg >> 16 - self._display.fill(bg, x, y, w, h) + if w is None: + w = display.width - x + if h is None: + h = display.height - y + + display.set_window(x, y, w, h) + + remaining = w * h + + # Populate the line buffer + buf = display.linebuffer + sz = len(display.linebuffer) // 2 + _fill(buf, bg, min(sz, remaining), 0) + + display.quick_start() + while remaining >= sz: + quick_write(buf) + remaining -= sz + if remaining: + quick_write(memoryview(display.linebuffer)[0:2*remaining]) + display.quick_end() @micropython.native def blit(self, image, x, y, fg=0xffff, c1=0x4a69, c2=0x7bef):