#!/usr/bin/env python3 """Load the logo atlas once, then blit logos to an rpi-rgb-led-matrix panel. Speed notes (rpi-rgb-led-matrix): - Decode everything at startup (atlas.bin), never PNGs inside the render loop. - Keep logos as RGB-mode PIL images and only redraw when the aircraft changes. The Python binding's SetImage(img, x, y) defaults to unsafe=True, a fast raw-buffer path that requires RGB mode (which the atlas loader guarantees). Pass unsafe=False only if you feed it other image modes. - Draw into an offscreen canvas and SwapOnVSync() so you never show a half-drawn frame. - Don't pre-apply gamma: the library's luminance correction (on by default) handles it. """ import re import struct from pathlib import Path from PIL import Image from rgbmatrix import RGBMatrix, RGBMatrixOptions # type: ignore def load_atlas(path="out/atlas.bin"): raw = Path(path).read_bytes() assert raw[:4] == b"LG16" size, count = struct.unpack_from(" Image.Image: cs = (callsign or "").strip().upper() if not cs: return UFO if N_NUMBER.match(cs): return GA # Airline callsign = 3-letter ICAO prefix + flight number (DAL1234) if len(cs) > 3 and cs[:3].isalpha() and cs[3].isdigit(): return LOGOS.get(cs[:3], UFO) return UFO if __name__ == "__main__": o = RGBMatrixOptions() o.rows, o.cols = 32, 64 # adjust to your panel matrix = RGBMatrix(options=o) canvas = matrix.CreateFrameCanvas() canvas.Clear() canvas.SetImage(logo_for("DAL1234"), 0, 8) canvas = matrix.SwapOnVSync(canvas) input("enter to quit")