from PIL import Image import warnings import numpy as np import struct import io def load(data): def consume(n): nonlocal data out, data = data[:n], data[n:] if len(out) < n: raise ValueError(f'File is truncated, tried to read {n} bytes, but only {len(out)} bytes remain.') return out header = consume(128) for model, match in { 'c201': bytes([0xca, 0xac]), 'other': bytes([0xba, 0xab]), 'p200': bytes([0x04, 0xa0]), }.items(): if (header[:2] + header[-2:]).startswith(match): break else: raise ValueError(f'Header magic not found. Got header: {header[0]:02x} {header[1]:02x}') _unk0, coarse_section_length, y_res, x_res,\ _zero0, _unk1, _zero1, fine_offset, _unk2, jpeg_length,\ y_res_2, x_res_2, _unk3, = struct.unpack('