summaryrefslogtreecommitdiffstatshomepage
path: root/tests/extmod/framebuf1.py
diff options
context:
space:
mode:
authorPeter Hinch <peter@hinch.me.uk>2017-02-06 10:59:44 +0000
committerDamien George <damien.p.george@gmail.com>2017-03-20 16:21:47 +1100
commit231cfc84a7cae31f93208c334fc33b08278040eb (patch)
tree332db20d9198432732631e91fa8e330ee32feee0 /tests/extmod/framebuf1.py
parentfb981107eb6eef3af2b7a6b1c8da53e95c316e86 (diff)
downloadmicropython-231cfc84a7cae31f93208c334fc33b08278040eb.tar.gz
micropython-231cfc84a7cae31f93208c334fc33b08278040eb.zip
extmod/modframebuf: Add support for monochrome horizontal format.
MHLSB and MHMSB formats are added to the framebuf module, which have 8 adjacent horizontal pixels represented in a single byte.
Diffstat (limited to 'tests/extmod/framebuf1.py')
-rw-r--r--tests/extmod/framebuf1.py171
1 files changed, 90 insertions, 81 deletions
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
index c204e63aa3..0a8e1ae550 100644
--- a/tests/extmod/framebuf1.py
+++ b/tests/extmod/framebuf1.py
@@ -7,87 +7,96 @@ except ImportError:
w = 5
h = 16
-buf = bytearray(w * h // 8)
-fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.MVLSB)
-
-# access as buffer
-print(memoryview(fbuf)[0])
-
-# fill
-fbuf.fill(1)
-print(buf)
-fbuf.fill(0)
-print(buf)
-
-# put pixel
-fbuf.pixel(0, 0, 1)
-fbuf.pixel(4, 0, 1)
-fbuf.pixel(0, 15, 1)
-fbuf.pixel(4, 15, 1)
-print(buf)
-
-# clear pixel
-fbuf.pixel(4, 15, 0)
-print(buf)
-
-# get pixel
-print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
-
-# hline
-fbuf.fill(0)
-fbuf.hline(0, 1, w, 1)
-print('hline', buf)
-
-# vline
-fbuf.fill(0)
-fbuf.vline(1, 0, h, 1)
-print('vline', buf)
-
-# rect
-fbuf.fill(0)
-fbuf.rect(1, 1, 3, 3, 1)
-print('rect', buf)
-
-#fill rect
-fbuf.fill(0)
-fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
-fbuf.fill_rect(1, 1, 3, 3, 1)
-print('fill_rect', buf)
-
-# line
-fbuf.fill(0)
-fbuf.line(1, 1, 3, 3, 1)
-print('line', buf)
-
-# line steep negative gradient
-fbuf.fill(0)
-fbuf.line(3, 3, 2, 1, 1)
-print('line', buf)
-
-# scroll
-fbuf.fill(0)
-fbuf.pixel(2, 7, 1)
-fbuf.scroll(0, 1)
-print(buf)
-fbuf.scroll(0, -2)
-print(buf)
-fbuf.scroll(1, 0)
-print(buf)
-fbuf.scroll(-1, 0)
-print(buf)
-fbuf.scroll(2, 2)
-print(buf)
-
-# print text
-fbuf.fill(0)
-fbuf.text("hello", 0, 0, 1)
-print(buf)
-fbuf.text("hello", 0, 0, 0) # clear
-print(buf)
-
-# char out of font range set to chr(127)
-fbuf.text(str(chr(31)), 0, 0)
-print(buf)
+size = w * h // 8
+buf = bytearray(size)
+maps = {framebuf.MVLSB : 'MVLSB',
+ framebuf.MHLSB : 'MHLSB',
+ framebuf.MHMSB : 'MHMSB'}
+
+for mapping in maps.keys():
+ for x in range(size):
+ buf[x] = 0
+ fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
+ print(maps[mapping])
+ # access as buffer
+ print(memoryview(fbuf)[0])
+
+ # fill
+ fbuf.fill(1)
+ print(buf)
+ fbuf.fill(0)
+ print(buf)
+
+ # put pixel
+ fbuf.pixel(0, 0, 1)
+ fbuf.pixel(4, 0, 1)
+ fbuf.pixel(0, 15, 1)
+ fbuf.pixel(4, 15, 1)
+ print(buf)
+
+ # clear pixel
+ fbuf.pixel(4, 15, 0)
+ print(buf)
+
+ # get pixel
+ print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
+
+ # hline
+ fbuf.fill(0)
+ fbuf.hline(0, 1, w, 1)
+ print('hline', buf)
+
+ # vline
+ fbuf.fill(0)
+ fbuf.vline(1, 0, h, 1)
+ print('vline', buf)
+
+ # rect
+ fbuf.fill(0)
+ fbuf.rect(1, 1, 3, 3, 1)
+ print('rect', buf)
+
+ #fill rect
+ fbuf.fill(0)
+ fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
+ fbuf.fill_rect(1, 1, 3, 3, 1)
+ print('fill_rect', buf)
+
+ # line
+ fbuf.fill(0)
+ fbuf.line(1, 1, 3, 3, 1)
+ print('line', buf)
+
+ # line steep negative gradient
+ fbuf.fill(0)
+ fbuf.line(3, 3, 2, 1, 1)
+ print('line', buf)
+
+ # scroll
+ fbuf.fill(0)
+ fbuf.pixel(2, 7, 1)
+ fbuf.scroll(0, 1)
+ print(buf)
+ fbuf.scroll(0, -2)
+ print(buf)
+ fbuf.scroll(1, 0)
+ print(buf)
+ fbuf.scroll(-1, 0)
+ print(buf)
+ fbuf.scroll(2, 2)
+ print(buf)
+
+ # print text
+ fbuf.fill(0)
+ fbuf.text("hello", 0, 0, 1)
+ print(buf)
+ fbuf.text("hello", 0, 0, 0) # clear
+ print(buf)
+
+ # char out of font range set to chr(127)
+ fbuf.text(str(chr(31)), 0, 0)
+ print(buf)
+ print()
# test invalid constructor, and stride argument
try: