diff options
author | Radomir Dopieralski <openstack@sheep.art.pl> | 2016-08-28 17:44:36 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-12-01 16:43:25 +1100 |
commit | 225e22b2877c7731b7428db0e28d3ad7e6751e35 (patch) | |
tree | 5305546fe5c8b4849ab79439517d0114201e131a /tests/extmod/framebuf16.py | |
parent | 8b8242954e3cd81fa82c24401f1eee0e516c8251 (diff) | |
download | micropython-225e22b2877c7731b7428db0e28d3ad7e6751e35.tar.gz micropython-225e22b2877c7731b7428db0e28d3ad7e6751e35.zip |
extmod/modframebuf: Make FrameBuffer handle 16bit depth.
Rename FrameBuffer1 into FrameBuffer and make it handle different bit
depths via a method table that has getpixel and setpixel. Currently
supported formats are MVLSB (monochrome, vertical, LSB) and RGB565.
Also add blit() and fill_rect() methods.
Diffstat (limited to 'tests/extmod/framebuf16.py')
-rw-r--r-- | tests/extmod/framebuf16.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py new file mode 100644 index 0000000000..754b28fdf1 --- /dev/null +++ b/tests/extmod/framebuf16.py @@ -0,0 +1,59 @@ +try: + import framebuf +except ImportError: + print("SKIP") + import sys + sys.exit() + +def printbuf(): + print("--8<--") + for y in range(h): + print(buf[y * w * 2:(y + 1) * w * 2]) + print("-->8--") + +w = 4 +h = 5 +buf = bytearray(w * h * 2) +fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565) + +# fill +fbuf.fill(0xffff) +printbuf() +fbuf.fill(0x0000) +printbuf() + +# put pixel +fbuf.pixel(0, 0, 0xeeee) +fbuf.pixel(3, 0, 0xee00) +fbuf.pixel(0, 4, 0x00ee) +fbuf.pixel(3, 4, 0x0ee0) +printbuf() + +# get pixel +print(fbuf.pixel(0, 4), fbuf.pixel(1, 1)) + +# scroll +fbuf.fill(0x0000) +fbuf.pixel(2, 2, 0xffff) +printbuf() +fbuf.scroll(0, 1) +printbuf() +fbuf.scroll(1, 0) +printbuf() +fbuf.scroll(-1, -2) +printbuf() + +w2 = 2 +h2 = 3 +buf2 = bytearray(w2 * h2 * 2) +fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565) + +fbuf2.fill(0x0000) +fbuf2.pixel(0, 0, 0x0ee0) +fbuf2.pixel(0, 2, 0xee00) +fbuf2.pixel(1, 0, 0x00ee) +fbuf2.pixel(1, 2, 0xe00e) +fbuf.fill(0xffff) +fbuf.blit(fbuf2, 3, 3, 0x0000) +fbuf.blit(fbuf2, -1, -1, 0x0000) +printbuf() |