aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-30 23:32:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-30 23:32:52 +0100
commitcbeff523d3c01471fcddfbf713b5d8d9e36dc1a9 (patch)
treeea96fc1371df2abae24b09954997277f762cad57 /tools
parentd6cce83a4c5a6540f0b32e3bca9fb56c1f8855d1 (diff)
downloadgold-mine-run-cbeff523d3c01471fcddfbf713b5d8d9e36dc1a9.tar.gz
gold-mine-run-cbeff523d3c01471fcddfbf713b5d8d9e36dc1a9.zip
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.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/pngpal.py60
1 files changed, 60 insertions, 0 deletions
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 <jjm@usebox.net>",
+ )
+
+ 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()