#!/usr/bin/env python3 # SPDX-License-Identifier: MPL-2.0 """Decode a private GIF test into bounded RGB565 frames for the cover panel.""" import argparse from array import array from pathlib import Path import struct import sys from PIL import Image, ImageOps def prepare(source, destination): if source.stat().st_size > 16 * 1024 * 1024: raise ValueError('GIF exceeds 16 MiB') with Image.open(source) as image: if image.format != 'GIF' or not 1 <= image.n_frames <= 240: raise ValueError('Expected a GIF with at most 240 frames') if image.width * image.height > 4_000_000: raise ValueError('GIF dimensions exceed limit') with destination.open('wb') as output: output.write(b'VULPANM1' + struct.pack('>3)<<11) | ((g>>2)<<5) | (b>>3) for r,g,b in zip(rgb[0::3],rgb[1::3],rgb[2::3]))) if sys.byteorder != 'little': pixels.byteswap() output.write(struct.pack('