Initial commit

This commit is contained in:
Alec Murphy
2022-03-23 16:47:42 -04:00
parent 0c6c7f8728
commit 92bc4ee529
3 changed files with 71 additions and 1 deletions
BIN
View File
Binary file not shown.
+16 -1
View File
@@ -1,3 +1,18 @@
# svg2GR
Converts .svg files generated by Aseprite to TempleOS GR format, preserving palette and transparency
Converts .svg files generated by Aseprite to TempleOS GR format, preserving palette and transparency
# Notes
Tested w/ Aseprite v1.2.33-x64
# Usage
- Create new indexed-color, transparent background image in Aseprite; use provided `GR.ase` palette file.
- Draw something
- Save file as .svg
- `svg2GR filename.svg` will generate `filename.GR`
Executable
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/python3
import os
import struct
import sys
color_lookup = { "#000000": 0, "#0000AA": 1, "#00AA00": 2, "#00AAAA": 3, "#AA0000": 4, "#AA00AA": 5, "#AA5500": 6, "#AAAAAA": 7, "#555555": 8, "#5555FF": 9, "#55FF55": 10, "#55FFFF": 11, "#FF5555": 12, "#FF55FF": 13, "#FFFF55": 14, "#FFFFFF": 15 }
def get_attr(src, substr):
return src[src.find(substr) + len(substr) + 2:src.find('"', src.find(substr) + len(substr) + 2)]
def main():
if len(sys.argv) < 2:
print("svg2GR - Converts .svg files generated by Aseprite to TempleOS GR format,")
print(" preserving palette and transparency.")
print("Usage: svg2GR [svg file]")
return 1
svg_file = sys.argv[1]
if not os.path.exists(svg_file):
print("Error: file not found - " + svg_file)
return 1
svg_rows = open(svg_file, "r").readlines()
width = int(get_attr(svg_rows[1], "width"))
height = int(get_attr(svg_rows[1], "height"))
width_internal = (width + 7) & (-8);
x = 0
y = 0
color = 0
buffer = bytearray([255]) * (height * width_internal)
i = 2
while i < len(svg_rows) - 1:
x = int(get_attr(svg_rows[i], "x"))
y = int(get_attr(svg_rows[i], "y"))
if "opacity" in svg_rows[i]:
color = 255
else:
color = color_lookup[get_attr(svg_rows[i], "fill")]
buffer[(y * width_internal) + x] = color
i += 1
f = open(svg_file.replace(".svg",".GR"), "wb")
f.write(struct.pack('Qiiiiii', 0, 0, 0, width, width_internal, height, 0))
f.write(buffer)
f.close()
return 0
main()