Add bitmap loading test

This commit is contained in:
Jeff Epler 2021-11-20 08:52:18 -05:00
parent ee5e7161af
commit de455b5c4e
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -0,0 +1,31 @@
import displayio
import bitmaptools
def loadbmp16(filename, width=320, height=240):
"""This specialized routine loads 16bpp uncompressed bmp files with a
70-byte header. It is not appropriate for generic bmp files."""
bitmap = displayio.Bitmap(width, height, 65536)
with open(filename, "rb") as f:
f.seek(70)
bitmaptools.readinto(
bitmap,
f,
bits_per_pixel=16,
element_size=2,
swap_bytes_in_element=True,
reverse_rows=True,
)
return bitmap
if __name__ == "__main__":
if "/" in __file__:
here = __file__.rsplit("/", 1)[0]
else:
here = "."
b = loadbmp16(here + "/minerva16.bmp")
print(b[0, 0])
print(b[160, 160])