add logos
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/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 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("<BH", raw, 4)
|
||||
off, logos = 7, {}
|
||||
step = 4 + size * size * 3
|
||||
for _ in range(count):
|
||||
code = raw[off:off + 4].rstrip(b"\0").decode()
|
||||
logos[code] = Image.frombytes("RGB", (size, size), raw[off + 4:off + step])
|
||||
off += step
|
||||
return logos
|
||||
|
||||
|
||||
LOGOS = load_atlas()
|
||||
FALLBACK = Image.open("fallback.png").convert("RGB") # your unidentified/GA icon
|
||||
|
||||
|
||||
def logo_for(callsign: str) -> Image.Image:
|
||||
# Airline callsigns are a 3-letter ICAO prefix + digits (DAL1234). N-numbers (N123AB) -> fallback.
|
||||
prefix = callsign[:3].upper()
|
||||
if len(callsign) > 3 and callsign[3].isdigit() and prefix.isalpha():
|
||||
return LOGOS.get(prefix, FALLBACK)
|
||||
return FALLBACK
|
||||
|
||||
|
||||
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")
|
||||
Reference in New Issue
Block a user