From 399b2234d2b851d8a4d61c32d266fd1a59572936 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Sun, 7 Jun 2020 14:46:35 +0100 Subject: [PATCH] Add palette generator script --- util/img2pal.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 util/img2pal.py diff --git a/util/img2pal.py b/util/img2pal.py new file mode 100644 index 0000000..64d7e84 --- /dev/null +++ b/util/img2pal.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +import sys +from PIL import Image + +''' +Converts a PNG into a palette compatible +with aptdec. Requires PIL: + + pip3 install Pillow + +''' + +if len(sys.argv) == 1: + print("Usage: python3 {} filename.png".format(sys.argv[0])) + exit() + +image = Image.open(sys.argv[1]) +pixels = image.load() + +sys.stdout.write("char palette[{}][3] = {{\n \"".format(image.size[1])) +for y in range(1, image.size[1]+1): + sys.stdout.write(''.join('\\x{:02x}'.format(a) for a in pixels[0, y-1])) + if(y % 7 == 0 and y != 0): + sys.stdout.write("\",\n \"") + +print("\"\n};") \ No newline at end of file