summaryrefslogtreecommitdiffstatshomepage
path: root/tests/extmod/framebuf16.py
blob: 3aa1d34def297670fa8a0e1b3e0cc4a9edfb3804 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)
fbuf.blit(fbuf2, 16, 16, 0x0000)
printbuf()