diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-06-22 21:20:34 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-06-22 21:20:34 (GMT) |
| commit | 04a8daeff4bef4649d12ce78e6949c9d744a238b (patch) | |
| tree | a60ff492c90e56075d0dda906af24dd63b799661 /wasp/draw565.py | |
| parent | d81e8e75aca512e156e5af610db6026b9cb785dd (diff) | |
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 <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/draw565.py')
| -rw-r--r-- | wasp/draw565.py | 25 |
1 files changed, 24 insertions, 1 deletions
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): |
