adafruit_imageload
Load pixel values (indices or colors) into a bitmap and colors into a palette.
Author(s): Scott Shawcroft, Matt Land
- adafruit_imageload.load(file_or_filename: str | BufferedReader, *, bitmap: Callable[[int, int, int], displayio.Bitmap] | None = None, palette: Callable[[int], displayio.Palette] | None = None) Tuple[displayio.Bitmap, displayio.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 palette 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, Matt Land
- adafruit_imageload.bmp.load(file: BufferedReader, *, bitmap: Callable[[int, int, int], displayio.Bitmap] | None = None, palette: Callable[[int], displayio.Palette] | None = None) Tuple[displayio.Bitmap | None, displayio.Palette | None]
Loads a bmp image from the open
file
.Returns tuple of bitmap object and palette object.
- Parameters:
file (io.BufferedReader) – Open file handle or compatible (like
io.BytesIO
) with the data of a BMP file.bitmap (object) – Type to store bitmap data. Must have API similar to
displayio.Bitmap
. Will be skipped if Nonepalette (object) – Type to store the palette. Must have API similar to
displayio.Palette
. Will be skipped if None
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, Matt Land
- adafruit_imageload.bmp.indexed.decode_rle(bitmap: displayio.Bitmap, file: BufferedReader, compression: int, y_range: Tuple[int, int, int], width: int) None
Helper to decode RLE images
- adafruit_imageload.bmp.indexed.load(file: BufferedReader, width: int, height: int, data_start: int, colors: int, color_depth: int, compression: int, *, bitmap: Callable[[int, int, int], displayio.Bitmap] | None = None, palette: Callable[[int], displayio.Palette] | None = None) Tuple[displayio.Bitmap | None, displayio.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
bitmap (BitmapConstructor) – a function that returns a displayio.Bitmap
palette (PaletteConstructor) – a function that returns a displayio.Palette
adafruit_imageload.gif
Load pixel values (indices or colors) into a bitmap and colors into a palette from a GIF file.
Author(s): Radomir Dopieralski, Matt Land
- exception adafruit_imageload.gif.EndOfData
Signified end of compressed data.
- adafruit_imageload.gif.load(file: BufferedReader, *, bitmap: Callable[[int, int, int], displayio.Bitmap], palette: Callable[[int], displayio.Palette] | None = None) Tuple[displayio.Bitmap, displayio.Palette | None]
Loads a GIF image from the open
file
.Returns tuple of bitmap object and palette object.
- Parameters:
file (io.BufferedReader) – Open file handle or compatible (like
io.BytesIO
) with the data of a GIF file.bitmap (object) – Type to store bitmap data. Must have API similar to
displayio.Bitmap
.palette (object) – Type to store the palette. Must have API similar to
displayio.Palette
. Will be skipped if None.
- adafruit_imageload.gif.lzw_decode(data: Iterator[int], code_size: int) Iterator[bytes]
Decode LZW-compressed data.
adafruit_imageload.png
Load pixel values (indices or colors) into a bitmap and colors into a palette from a PNG file.
Author(s): Radomir Dopieralski, Matt Land, Channing Ramos
- adafruit_imageload.png.load(file: BufferedReader, *, bitmap: Callable[[int, int, int], displayio.Bitmap], palette: Callable[[int], displayio.Palette] | None = None) Tuple[displayio.Bitmap, displayio.Palette | None]
Loads a PNG image from the open
file
. Only supports indexed color images.Returns tuple of bitmap object and palette object.
- Parameters:
file (io.BufferedReader) – Open file handle or compatible (like
io.BytesIO
) with the data of a PNG file.bitmap (object) – Type to store bitmap data. Must have API similar to
displayio.Bitmap
.palette (object) – Type to store the palette. Must have API similar to
displayio.Palette
. Will be skipped if None.
adafruit_imageload.tilegrid_inflator
Use a 3x3 spritesheet to inflate a larger grid of tiles, duplicating the center rows and columns as many times as needed to reach a target size.
Author(s): Tim Cocks, Matt Land
- adafruit_imageload.tilegrid_inflator.inflate_tilegrid(bmp_path: str | None = None, target_size: Tuple[int, int] = (3, 3), tile_size: List[int] | None = None, transparent_index: tuple | int | None = None, bmp_obj: displayio.OnDiskBitmap | None = None, bmp_palette: displayio.Palette | None = None) displayio.TileGrid
inflate a TileGrid of
target_size
in tiles from a 3x3 spritesheet by duplicating the center rows and columns.- Parameters:
bmp_path (Optional[str]) – filepath to the 3x3 spritesheet bitmap file
target_size (tuple[int, int]) – desired size in tiles (target_width, target_height)
tile_size (Optional[List[int]]) – size of the tiles in the 3x3 spritesheet. If None is used it will equally divide the width and height of the Bitmap by 3.
transparent_index (Optional[Union[tuple, int]]) – a single index within the palette to make transparent, or a tuple of multiple indexes to make transparent
bmp_obj (Optional[OnDiskBitmap]) – Already loaded 3x3 spritesheet in an OnDiskBitmap
bmp_palette (Optional[Palette]) – Already loaded spritesheet Palette