summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2017-07-15 15:53:47 +0200
committerDamien George <damien.p.george@gmail.com>2017-12-14 17:13:02 +1100
commit34247465c34113bb26f6c9582ea31f31b0ea0d1b (patch)
tree5f041a343b1513be8ed0170d100eadce141691a3 /tests
parent36f79523abe8d79fec1cc7af41e8e96e8ceb2cc4 (diff)
extmod/modframebuf: Add 2-bit color format (GS2_HMSB).
This format is used in 2-color LED matrices and in e-ink displays like SSD1606.
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/framebuf2.py62
-rw-r--r--tests/extmod/framebuf2.py.exp57
2 files changed, 119 insertions, 0 deletions
diff --git a/tests/extmod/framebuf2.py b/tests/extmod/framebuf2.py
new file mode 100644
index 000000000..a313170eb
--- /dev/null
+++ b/tests/extmod/framebuf2.py
@@ -0,0 +1,62 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+def printbuf():
+ print("--8<--")
+ for y in range(h):
+ for x in range(w):
+ print('%u' % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end='')
+ print()
+ print("-->8--")
+
+w = 8
+h = 5
+buf = bytearray(w * h // 4)
+fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS2_HMSB)
+
+# fill
+fbuf.fill(3)
+printbuf()
+fbuf.fill(0)
+printbuf()
+
+# put pixel
+fbuf.pixel(0, 0, 1)
+fbuf.pixel(3, 0, 2)
+fbuf.pixel(0, 4, 3)
+fbuf.pixel(3, 4, 2)
+printbuf()
+
+# get pixel
+print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
+
+# scroll
+fbuf.fill(0)
+fbuf.pixel(2, 2, 3)
+printbuf()
+fbuf.scroll(0, 1)
+printbuf()
+fbuf.scroll(1, 0)
+printbuf()
+fbuf.scroll(-1, -2)
+printbuf()
+
+w2 = 2
+h2 = 3
+buf2 = bytearray(w2 * h2 // 4)
+fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.GS2_HMSB)
+
+# blit
+fbuf2.fill(0)
+fbuf2.pixel(0, 0, 1)
+fbuf2.pixel(0, 2, 2)
+fbuf2.pixel(1, 0, 1)
+fbuf2.pixel(1, 2, 2)
+fbuf.fill(3)
+fbuf.blit(fbuf2, 3, 3, 0)
+fbuf.blit(fbuf2, -1, -1, 0)
+fbuf.blit(fbuf2, 16, 16, 0)
+printbuf()
diff --git a/tests/extmod/framebuf2.py.exp b/tests/extmod/framebuf2.py.exp
new file mode 100644
index 000000000..c53e518a6
--- /dev/null
+++ b/tests/extmod/framebuf2.py.exp
@@ -0,0 +1,57 @@
+--8<--
+33333333
+33333333
+33333333
+33333333
+33333333
+-->8--
+--8<--
+00000000
+00000000
+00000000
+00000000
+00000000
+-->8--
+--8<--
+10020000
+00000000
+00000000
+00000000
+30020000
+-->8--
+3 0
+--8<--
+00000000
+00000000
+00300000
+00000000
+00000000
+-->8--
+--8<--
+00000000
+00000000
+00000000
+00300000
+00000000
+-->8--
+--8<--
+00000000
+00000000
+00000000
+00030000
+00000000
+-->8--
+--8<--
+00000000
+00300000
+00000000
+00030000
+00000000
+-->8--
+--8<--
+33333333
+23333333
+33333333
+33311333
+33333333
+-->8--