# -*- coding: utf-8 -*- # Downscale an UNCOMPRESSED RGBA4444 Godot .stex by 2x in each dimension. # Works directly on the packed 16-bit data, averaging each 4-bit channel in # place -> packing-agnostic (no need to know the R/G/B/A nibble order). # python halve_stex.py import sys, struct, numpy as np def main(inp, outp): with open(inp, "rb") as f: blob = f.read() assert blob[0:4] == b"GDST", "not a .stex" w, h, flags, fmt = struct.unpack_from("> shift) & 0xF).astype(np.uint16) blk = ch.reshape(h2, 2, w2, 2) # 2x2 blocks avg = (blk.sum(axis=(1, 3)) + 2) // 4 # rounded mean out |= (avg.astype(np.uint32) & 0xF) << shift out = out.astype(" %dx%d (%d -> %d bytes)" % (w, h, w2, h2, len(blob), 20 + out.nbytes)) if __name__ == "__main__": main(sys.argv[1], sys.argv[2])