mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-27 01:44:31 +02:00
Replace resource tools with python scripts
May fix pipeline failures on ghactions where makeico or toarray just exit with a non-zero status for no reason. Also makes it easier (possible, rather) to build TPT using a cross-compiling msvc toolchain on windows; you can't have two different msvc toolchains in PATH on windows because of course you can't. toarray had been python before, maybe I converted it to cpp to avoid pulling in python as a dependency, I'm not sure. With android vanilla development (hopefully) gaining traction soon, we'll be relying anyway on helper scripts I've written in python, so python will be a dependency sooner or later. Meson implicitly makes python a dependency, but there could be Meson implementations out there that don't rely on python, who knows.
This commit is contained in:
38
resources/make-ico.py
Normal file
38
resources/make-ico.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import struct
|
||||
import sys
|
||||
|
||||
(
|
||||
script,
|
||||
output_ico,
|
||||
*input_pngs,
|
||||
) = sys.argv
|
||||
|
||||
input_pngs_size = len(input_pngs)
|
||||
assert(input_pngs_size <= 255)
|
||||
|
||||
ico_header = b''
|
||||
ico_data = b''
|
||||
data_offset = 6 + 16 * input_pngs_size
|
||||
for input_png in input_pngs:
|
||||
with open(input_png, 'rb') as input_png_f:
|
||||
data = input_png_f.read()
|
||||
data_size = len(data)
|
||||
assert(data_size >= 0x21)
|
||||
magic, width, height, bit_depth, color_type = struct.unpack('>QxxxxxxxxLLBBxxxxxxx', data[0 : 0x21])
|
||||
assert(magic == 0x89504E470D0A1A0A)
|
||||
assert(width <= 256)
|
||||
assert(height <= 256)
|
||||
assert(bit_depth == 8)
|
||||
assert(color_type == 6)
|
||||
if width == 256:
|
||||
width = 0
|
||||
if height == 256:
|
||||
height = 0
|
||||
ico_header += struct.pack('<BBxxHHLL', width, height, 1, 32, data_size, data_offset)
|
||||
data_offset += data_size
|
||||
ico_data += data
|
||||
|
||||
with open(output_ico, 'wb') as output_ico_f:
|
||||
output_ico_f.write(struct.pack('<xxHH', 1, input_pngs_size))
|
||||
output_ico_f.write(ico_header)
|
||||
output_ico_f.write(ico_data)
|
Reference in New Issue
Block a user