aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPedro de Medeiros <pedro.medeiros@gmail.com>2023-05-10 06:16:01 +0000
committerJuan J. Martínez <jjm@usebox.net>2023-05-10 06:16:01 +0000
commitb602944f9a9057933abb1ff1c12b4deabc4883fb (patch)
tree8dd526b2ddd5d19082458029753cdb7c63b51181 /tools
parentc9f28c1ce3ffda9c407003a26adf903d810b681b (diff)
downloadubox-msx-lib-b602944f9a9057933abb1ff1c12b4deabc4883fb.tar.gz
ubox-msx-lib-b602944f9a9057933abb1ff1c12b4deabc4883fb.zip
png2sprites: allow user to change transparent colour
Diffstat (limited to 'tools')
-rwxr-xr-xtools/png2sprites.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/png2sprites.py b/tools/png2sprites.py
index 95e6492..d51251f 100755
--- a/tools/png2sprites.py
+++ b/tools/png2sprites.py
@@ -21,6 +21,7 @@
# THE SOFTWARE.
#
+import re
from argparse import ArgumentParser
from PIL import Image
@@ -29,9 +30,18 @@ __version__ = "1.0"
DEF_W = 16
DEF_H = 16
+RE_COL = re.compile("^#?([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$")
TRANS = (28, 28, 28)
+def to_color_tuple(src):
+ g = RE_COL.search(src)
+ if g:
+ return int(g.group(1), 16), int(g.group(2), 16), int(g.group(3), 16)
+ else:
+ raise Exception("hexadecimal RRGGBB color expected")
+
+
def to_hex_list_str(src):
out = ""
for i in range(0, len(src), 8):
@@ -79,6 +89,14 @@ def main():
action="store_true",
help="include frame color as a comment",
)
+ parser.add_argument(
+ "-t",
+ "--transparent",
+ dest="trans_color",
+ type=to_color_tuple,
+ default="1c1c1c",
+ help="redefine transparent color in 6-digit hexadecimal notation (default: 1c1c1c)",
+ )
parser.add_argument("image", help="image to convert")
@@ -109,7 +127,7 @@ def main():
tile = [
data[x + i + ((y + j) * w)] for j in range(DEF_H) for i in range(DEF_W)
]
- cols = sorted(set([c for c in tile if c != TRANS]))
+ cols = sorted(set([c for c in tile if c != args.trans_color]))
if not cols:
continue