Skip to content

Commit de455b5

Browse files
committed
Add bitmap loading test
1 parent ee5e716 commit de455b5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/circuitpython/_loadbmp16.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import displayio
2+
import bitmaptools
3+
4+
5+
def loadbmp16(filename, width=320, height=240):
6+
"""This specialized routine loads 16bpp uncompressed bmp files with a
7+
70-byte header. It is not appropriate for generic bmp files."""
8+
9+
bitmap = displayio.Bitmap(width, height, 65536)
10+
with open(filename, "rb") as f:
11+
f.seek(70)
12+
bitmaptools.readinto(
13+
bitmap,
14+
f,
15+
bits_per_pixel=16,
16+
element_size=2,
17+
swap_bytes_in_element=True,
18+
reverse_rows=True,
19+
)
20+
21+
return bitmap
22+
23+
24+
if __name__ == "__main__":
25+
if "/" in __file__:
26+
here = __file__.rsplit("/", 1)[0]
27+
else:
28+
here = "."
29+
b = loadbmp16(here + "/minerva16.bmp")
30+
print(b[0, 0])
31+
print(b[160, 160])

0 commit comments

Comments
 (0)