1try:
2    import framebuf
3except ImportError:
4    print("SKIP")
5    raise SystemExit
6
7w = 5
8h = 16
9size = w * h // 8
10buf = bytearray(size)
11maps = {
12    framebuf.MONO_VLSB: "MONO_VLSB",
13    framebuf.MONO_HLSB: "MONO_HLSB",
14    framebuf.MONO_HMSB: "MONO_HMSB",
15}
16
17for mapping in maps.keys():
18    for x in range(size):
19        buf[x] = 0
20    fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
21    print(maps[mapping])
22    # access as buffer
23    print(memoryview(fbuf)[0])
24
25    # fill
26    fbuf.fill(1)
27    print(buf)
28    fbuf.fill(0)
29    print(buf)
30
31    # put pixel
32    fbuf.pixel(0, 0, 1)
33    fbuf.pixel(4, 0, 1)
34    fbuf.pixel(0, 15, 1)
35    fbuf.pixel(4, 15, 1)
36    print(buf)
37
38    # clear pixel
39    fbuf.pixel(4, 15, 0)
40    print(buf)
41
42    # get pixel
43    print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
44
45    # hline
46    fbuf.fill(0)
47    fbuf.hline(0, 1, w, 1)
48    print("hline", buf)
49
50    # vline
51    fbuf.fill(0)
52    fbuf.vline(1, 0, h, 1)
53    print("vline", buf)
54
55    # rect
56    fbuf.fill(0)
57    fbuf.rect(1, 1, 3, 3, 1)
58    print("rect", buf)
59
60    # fill rect
61    fbuf.fill(0)
62    fbuf.fill_rect(0, 0, 0, 3, 1)  # zero width, no-operation
63    fbuf.fill_rect(1, 1, 3, 3, 1)
64    print("fill_rect", buf)
65
66    # line
67    fbuf.fill(0)
68    fbuf.line(1, 1, 3, 3, 1)
69    print("line", buf)
70
71    # line steep negative gradient
72    fbuf.fill(0)
73    fbuf.line(3, 3, 2, 1, 1)
74    print("line", buf)
75
76    # scroll
77    fbuf.fill(0)
78    fbuf.pixel(2, 7, 1)
79    fbuf.scroll(0, 1)
80    print(buf)
81    fbuf.scroll(0, -2)
82    print(buf)
83    fbuf.scroll(1, 0)
84    print(buf)
85    fbuf.scroll(-1, 0)
86    print(buf)
87    fbuf.scroll(2, 2)
88    print(buf)
89
90    # print text
91    fbuf.fill(0)
92    fbuf.text("hello", 0, 0, 1)
93    print(buf)
94    fbuf.text("hello", 0, 0, 0)  # clear
95    print(buf)
96
97    # char out of font range set to chr(127)
98    fbuf.text(str(chr(31)), 0, 0)
99    print(buf)
100    print()
101
102# test invalid constructor, and stride argument
103try:
104    fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
105except ValueError:
106    print("ValueError")
107
108# test legacy constructor
109fbuf = framebuf.FrameBuffer1(buf, w, h)
110fbuf = framebuf.FrameBuffer1(buf, w, h, w)
111print(framebuf.MVLSB == framebuf.MONO_VLSB)
112