#!/usr/bin/env python3 import argparse import io import logging import os import struct from PIL import Image, ImageOps # XBM flipper sprite (.fxbm) is 1-bit depth, width-padded to 8 bits # file format: # uint32 size of the rest of the file in bytes # uint32 width in px # uint32 height in px # uint8[] pixel data, every row is padded to 8 bits (like XBM) def image2xbm(input_file_path): with Image.open(input_file_path) as im: with io.BytesIO() as output: bw = im.convert("1") bw = ImageOps.invert(bw) bw.save(output, format="XBM") return output.getvalue() def xbm2fxbm(data): # hell as it is, but it works f = io.StringIO(data.decode().strip()) width = int(f.readline().strip().split(" ")[2]) height = int(f.readline().strip().split(" ")[2]) data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1] data_str = data[1:-1].replace(",", " ").replace("0x", "") image_bin = bytearray.fromhex(data_str) output = struct.pack("