From 57999226fdf8e36021c37478730084424947f604 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 23 May 2020 13:44:33 +0100 Subject: [PATCH] draw565: rle2bit: Add support for palette overrides This allows some interesting manipulations of 2-bit images. --- wasp/draw565.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wasp/draw565.py b/wasp/draw565.py index 21b23ed..2e248b4 100644 --- a/wasp/draw565.py +++ b/wasp/draw565.py @@ -130,7 +130,7 @@ class Draw565(object): self._display.fill(bg, x, y, w, h) @micropython.native - def blit(self, image, x, y): + def blit(self, image, x, y, fg=0xffff, c1=0x4a69, c2=0x7bef): """Decode and draw an encoded image. :param image: Image data in either 1-bit RLE or 2-bit RLE formats. The @@ -140,10 +140,10 @@ class Draw565(object): """ if len(image) == 3: # Legacy 1-bit image - self.rleblit(image, (x, y)) + self.rleblit(image, (x, y), fg) else: #elif image[0] == 2: # 2-bit RLE image, (255x255, v1) - self._rle2bit(image, x, y) + self._rle2bit(image, x, y, fg, c1, c2) @micropython.native def rleblit(self, image, pos=(0, 0), fg=0xffff, bg=0): @@ -179,7 +179,7 @@ class Draw565(object): color = bg @micropython.native - def _rle2bit(self, image, x, y): + def _rle2bit(self, image, x, y, fg, c1, c2): """Decode and draw a 2-bit RLE image.""" display = self._display quick_write = display.quick_write @@ -193,7 +193,7 @@ class Draw565(object): sx *= 2 sy //= 2 - palette = array.array('H', (0, 0x4a69, 0x7bef, 0xffff)) + palette = array.array('H', (0, c1, c2, fg)) next_color = 1 rl = 0 buf = memoryview(display.linebuffer)[0:2*sx]