Skip to content

Commit

Permalink
Merge pull request #63 from FoamyGuy/png_typing_and_example
Browse files Browse the repository at this point in the history
adding type annotations and png example script
  • Loading branch information
FoamyGuy authored Jan 9, 2023
2 parents 9b00824 + 5931103 commit b3953c8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
10 changes: 8 additions & 2 deletions adafruit_imageload/png.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
43 changes: 43 additions & 0 deletions examples/imageload_png_simpletest.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added examples/images/test_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/images/test_image.png.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-FileCopyrightText: 2022 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

0 comments on commit b3953c8

Please sign in to comment.