Skip to content

Instantly share code, notes, and snippets.

@jedgarpark
Created March 14, 2024 02:03
Show Gist options
  • Save jedgarpark/2ee8dfaa71553891477f555660299227 to your computer and use it in GitHub Desktop.
Save jedgarpark/2ee8dfaa71553891477f555660299227 to your computer and use it in GitHub Desktop.
# jpeg loader slideshow
# based on color summarizer by @todbot / Tod Kurt
#https://gist.github.com/todbot/0bf32a6bf8dd21983a32bafc173b3223#file-code_color_palette_finder-py
import time
import board
import displayio
import jpegio
from adafruit_hx8357 import HX8357
import gc
displayio.release_displays()
jpeg_fnames = (
"/imgs/radroom2.jpg",
"/imgs/queen.jpg",
"/imgs/bike.jpg",
"/imgs/Jules_and_Vincent.jpg"
)
spi = board.SPI()
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = HX8357(display_bus, width=320, height=480, rotation=270)
main_group = displayio.Group()
display.root_group = main_group
# start out with a blank screen, we'll replace later
bitmap = displayio.Bitmap(480, 320, 65535)
pixel_shader = displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565_SWAPPED)
tile_grid = displayio.TileGrid(bitmap, pixel_shader=pixel_shader)
main_group.append(tile_grid)
def load_jpeg_to_bitmap(jpeg_fname):
"""Load a JPEG into a displayio.Bitmap"""
decoder = jpegio.JpegDecoder()
width, height = decoder.open(jpeg_fname)
bitmap = displayio.Bitmap(width, height, 65535) # RGB565_SWAPPED is 16-bit
decoder.decode(bitmap)
return bitmap
def slide_show(time_delay=1):
for jpeg_fname in jpeg_fnames:
print("----\njpeg file:", jpeg_fname)
bitmap = load_jpeg_to_bitmap(jpeg_fname)
tile_grid = displayio.TileGrid(bitmap, pixel_shader=pixel_shader)
main_group[0] = tile_grid
gc.collect()
time.sleep(time_delay)
while True:
slide_show(time_delay=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment