diff options
| author | Peter Hinch <peter@hinch.me.uk> | 2021-08-18 20:05:25 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-08-25 15:31:23 +1000 |
| commit | 2296df0a327150f39ef5a915bf828daac3cd4658 (patch) | |
| tree | ea791c3b6308ca854e1ea62442abc6b3ea2c4b19 /tests/extmod/framebuf_palette.py | |
| parent | 996f703166d8c57122756f35f7f0185666237f2b (diff) | |
extmod/modframebuf: Enable blit between different formats via a palette.
This achieves a substantial performance improvement when rendering glyphs
to color displays, the benefit increasing proportional to the number of
pixels in the glyph.
Diffstat (limited to 'tests/extmod/framebuf_palette.py')
| -rw-r--r-- | tests/extmod/framebuf_palette.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/extmod/framebuf_palette.py b/tests/extmod/framebuf_palette.py new file mode 100644 index 000000000..84db834c1 --- /dev/null +++ b/tests/extmod/framebuf_palette.py @@ -0,0 +1,35 @@ +# Test blit between different color spaces +try: + import framebuf, usys +except ImportError: + print("SKIP") + raise SystemExit + +# Monochrome glyph/icon +w = 8 +h = 8 +cbuf = bytearray(w * h // 8) +fbc = framebuf.FrameBuffer(cbuf, w, h, framebuf.MONO_HLSB) +fbc.line(0, 0, 7, 7, 1) + +# RGB565 destination +wd = 16 +hd = 16 +dest = bytearray(wd * hd * 2) +fbd = framebuf.FrameBuffer(dest, wd, hd, framebuf.RGB565) + +wp = 2 +bg = 0x1234 +fg = 0xF800 +pal = bytearray(wp * 2) +palette = framebuf.FrameBuffer(pal, wp, 1, framebuf.RGB565) +palette.pixel(0, 0, bg) +palette.pixel(1, 0, fg) + +fbd.blit(fbc, 0, 0, -1, palette) + +print(fbd.pixel(0, 0) == fg) +print(fbd.pixel(7, 7) == fg) +print(fbd.pixel(8, 8) == 0) # Ouside blit +print(fbd.pixel(0, 1) == bg) +print(fbd.pixel(1, 0) == bg) |
