from PIL import Image INPUT = "/home/gabriel/Downloads/Logo.png" OUTPUT = "/home/gabriel/Downloads/logo_splash.h" DISPLAY_W, DISPLAY_H = 240, 320 BG_COLOR = (30, 30, 30) # dark background, change to (0,0,0) for pure black img = Image.open(INPUT).convert("RGB") # Scale logo to fit within display, preserving aspect ratio img.thumbnail((DISPLAY_W, DISPLAY_H), Image.LANCZOS) # Center on display canvas canvas = Image.new("RGB", (DISPLAY_W, DISPLAY_H), BG_COLOR) x = (DISPLAY_W - img.width) // 2 y = (DISPLAY_H - img.height) // 2 canvas.paste(img, (x, y)) # Convert to RGB565 pixels = [] for r, g, b in canvas.getdata(): rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3) # Swap bytes for ILI9341 (big-endian over SPI) pixels.append(((rgb565 & 0xFF) << 8) | (rgb565 >> 8)) # Write header file with open(OUTPUT, "w") as f: f.write("#pragma once\n") f.write("#include \n\n") f.write(f"// {DISPLAY_W}x{DISPLAY_H} RGB565, big-endian\n") f.write(f"const uint16_t SPLASH_WIDTH = {DISPLAY_W};\n") f.write(f"const uint16_t SPLASH_HEIGHT = {DISPLAY_H};\n\n") f.write("const uint16_t splash_logo[] PROGMEM = {\n") for i, p in enumerate(pixels): if i % 12 == 0: f.write(" ") f.write(f"0x{p:04X},") if i % 12 == 11: f.write("\n") f.write("\n};\n") print(f"Done — {len(pixels)} pixels, {len(pixels)*2/1024:.1f} KB") print(f"Output: {OUTPUT}")