Introduction¶
This library decodes an image file into new bitmap and palette objects of the provided type. It’s designed to load code needed during decoding as needed. This is meant to minimize the memory overhead of the decoding code.
Usage Example¶
import board
import displayio
import adafruit_imageload
image, palette = adafruit_imageload.load(
"images/4bit.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)
tile_grid = displayio.TileGrid(image, pixel_shader=palette)
group = displayio.Group()
group.append(tile_grid)
board.DISPLAY.show(group)
while True:
pass
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Documentation¶
For information on building library documentation, please check out this guide.
Table of Contents¶
Simple test¶
Ensure your image loads with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import board
import displayio
import adafruit_imageload
image, palette = adafruit_imageload.load(
"images/4bit.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)
tile_grid = displayio.TileGrid(image, pixel_shader=palette)
group = displayio.Group()
group.append(tile_grid)
board.DISPLAY.show(group)
while True:
pass
|
adafruit_imageload
¶
Load pixel values (indices or colors) into a bitmap and colors into a palette.
- Author(s): Scott Shawcroft
-
adafruit_imageload.
load
(filename, *, bitmap=None, palette=None)¶ Load pixel values (indices or colors) into a bitmap and colors into a palette.
bitmap is the desired type. It must take width, height and color_depth in the constructor. It must also have a _load_row method to load a row’s worth of pixel data.
palette is the desired pallete type. The constructor should take the number of colors and support assignment to indices via [].
adafruit_imageload.bmp
¶
Load pixel values (indices or colors) into a bitmap and colors into a palette from a BMP file.
- Author(s): Scott Shawcroft
-
adafruit_imageload.bmp.
load
(file, *, bitmap=None, palette=None)¶ Loads a bmp image from the open
file
.Returns tuple of bitmap object and palette object.
Parameters: - bitmap (object) – Type to store bitmap data. Must have API similar to
displayio.Bitmap
. Will be skipped if None - palette (object) – Type to store the palette. Must have API similar to
displayio.Palette
. Will be skipped if None
- bitmap (object) – Type to store bitmap data. Must have API similar to
adafruit_imageload.bmp.indexed
¶
Load pixel values (indices or colors) into a bitmap and colors into a palette from an indexed BMP.
- Author(s): Scott Shawcroft
-
adafruit_imageload.bmp.indexed.
decode_rle
(bitmap, file, compression, y_range, width)¶ Helper to decode RLE images
-
adafruit_imageload.bmp.indexed.
load
(file, width, height, data_start, colors, color_depth, compression, *, bitmap=None, palette=None)¶ Loads indexed bitmap data into bitmap and palette objects.
Parameters: - file (file) – The open bmp file
- width (int) – Image width in pixels
- height (int) – Image height in pixels
- data_start (int) – Byte location where the data starts (after headers)
- colors (int) – Number of distinct colors in the image
- color_depth (int) – Number of bits used to store a value
- compression (int) – 0 - none, 1 - 8bit RLE, 2 - 4bit RLE
Developing¶
Strategy: * read headers to determine file type * keep a pointer to the start of data * read data into the Palette for all colors present * rewind the file pointer back to start of data * read data into the Bitmap * return a bitmap and palette instance