diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 0fdc056..db304b5 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -13,16 +13,22 @@ """ +try: + # pylint: disable=unused-import + import typing + from .displayio_types import PaletteConstructor, BitmapConstructor +except ImportError: + pass + import struct import zlib - __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git" def load( - file, *, bitmap, palette=None + file: str, *, bitmap: BitmapConstructor, palette: PaletteConstructor = None ): # pylint: disable=too-many-locals,too-many-branches """Loads a PNG image from the open ``file``. diff --git a/examples/imageload_png_simpletest.py b/examples/imageload_png_simpletest.py new file mode 100644 index 0000000..c1dc09f --- /dev/null +++ b/examples/imageload_png_simpletest.py @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks +# SPDX-License-Identifier: MIT + +import board +import displayio +from vectorio import Rectangle +import adafruit_imageload + +# built-in display +display = board.DISPLAY + +# load png image +image, palette = adafruit_imageload.load("images/test_image.png") + +# Set the transparency index color to be hidden +palette.make_transparent(0) + +# make tilegrid for the loaded image +tile_grid = displayio.TileGrid(image, pixel_shader=palette) +tile_grid.x = display.width // 2 - tile_grid.tile_width // 2 +tile_grid.y = display.height // 2 - tile_grid.tile_height // 2 + +# make a blank background +bg_palette = displayio.Palette(1) +bg_palette[0] = 0xFFFFFF +rect = Rectangle( + pixel_shader=bg_palette, width=display.width, height=display.height, x=0, y=0 +) + +# make a group to show on the display +group = displayio.Group() + +# add background +group.append(rect) +# add loaded image tilegrid +group.append(tile_grid) + +# show our group +board.DISPLAY.show(group) + +# loop forever so it stays on the display +while True: + pass diff --git a/examples/images/test_image.png b/examples/images/test_image.png new file mode 100644 index 0000000..9e196dc Binary files /dev/null and b/examples/images/test_image.png differ diff --git a/examples/images/test_image.png.license b/examples/images/test_image.png.license new file mode 100644 index 0000000..ad03cf2 --- /dev/null +++ b/examples/images/test_image.png.license @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2022 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT