Skip to content

Set bitmap and palette to have default values #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions adafruit_imageload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def load(filename, *, bitmap=None, palette=None):
palette is the desired pallete type. The constructor should take the number of colors and
support assignment to indices via [].
"""
if not bitmap or not palette:
try:
# use displayio if available
import displayio

if not bitmap:
bitmap = displayio.Bitmap
if not palette:
palette = displayio.Palette
except ModuleNotFoundError:
# meh, we tried
pass

with open(filename, "rb") as file:
header = file.read(3)
file.seek(0)
Expand Down
5 changes: 2 additions & 3 deletions examples/imageload_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import displayio
import adafruit_imageload

image, palette = adafruit_imageload.load(
"images/4bit.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
)
image, palette = adafruit_imageload.load("images/4bit.bmp")

tile_grid = displayio.TileGrid(image, pixel_shader=palette)

group = displayio.Group()
Expand Down