From cbeff523d3c01471fcddfbf713b5d8d9e36dc1a9 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 30 May 2023 23:32:52 +0100 Subject: pngpal tool and first stab at embedding data on the EXE WIP; the embedded data has an "environ" symbol that will cause issues when we embed more than one piece of data. --- tools/pngpal.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 tools/pngpal.py (limited to 'tools') diff --git a/tools/pngpal.py b/tools/pngpal.py new file mode 100755 index 0000000..7db451d --- /dev/null +++ b/tools/pngpal.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +import subprocess +import os +from PIL import Image + +__version__ = "1.0" + +ld = os.environ.get("LD", "i586-pc-msdosdjgpp-ld") + + +def main(): + parser = ArgumentParser( + description="PNG to palette .o", + epilog="Copyright (C) 2023 Juan J Martinez ", + ) + + parser.add_argument( + "--version", action="version", version="%(prog)s " + __version__ + ) + parser.add_argument("image", help="image to convert") + parser.add_argument("output", help="objtect name for the palette") + + args = parser.parse_args() + + try: + image = Image.open(args.image) + except IOError: + parser.error("failed to open the image") + + if image.mode != "P": + parser.error("not an indexed image (no palette)") + + palette = image.getpalette() + if not palette: + parser.error("failed to extract the palette") + + tmp = args.output.rstrip(".o") + with open(tmp, "wb") as fd: + fd.write(bytearray(palette)) + fd.flush() + rc = subprocess.call( + [ + ld, + "-r", + "-b", + "binary", + "-o", + args.output, + tmp, + ] + ) + os.unlink(tmp) + if rc != 0: + parser.error("Failed to run %s" % ld) + + +if __name__ == "__main__": + main() -- cgit v1.2.3