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 displayio
import adafruit_imageload
image, palette = adafruit_imageload.load("images/4bit.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
Zip release files¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-imageload --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
Simple test¶
Ensure your image loads with this simple test.
1 2 3 4 5 6 | import displayio
import adafruit_imageload
image, palette = adafruit_imageload.load("images/4bit.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
|
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.
load
(file, width, height, data_start, colors, color_depth, *, bitmap=None, palette=None)¶ Loads indexed bitmap data into bitmap and palette objects.
Parameters:
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