# -*- coding: utf-8 -*- # Fractional (num/den) downscale of an uncompressed RGBA4444 Godot .stex. # Packing-agnostic: works per 4-bit channel by repeating each axis `num` times # then box-averaging `den`x`den` blocks. Output dims must be integer. # Output is written with flags=0 (no mipmaps) to save CDRAM/VRAM. # python resize_stex.py import sys, struct, numpy as np def main(inp, outp, num, den): blob = open(inp, "rb").read() assert blob[0:4] == b"GDST" w, h, flags, fmt = struct.unpack_from("> shift) & 0xF).astype(np.float32) up = np.repeat(np.repeat(ch, num, axis=0), num, axis=1) # h*num x w*num blk = up.reshape(h2, den, w2, den) avg = np.rint(blk.mean(axis=(1, 3))).astype(np.uint32) out |= (avg & 0xF) << shift out = out.astype(" %dx%d (x%d/%d) %d -> %d bytes flags=0" % (w, h, w2, h2, num, den, len(blob), 20 + out.nbytes)) if __name__ == "__main__": main(sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]))