Files
rosetta/tools/fixtures/_simple.py
T
4DBug 403a4d6f31 ws-tex: image/sgi + image/sunras (read + write)
SGI: verbatim / RLE, 1-2 bytes per channel, 1-4 channels (rgba16 native); write RGB(A) RLE / verbatim.
Sun Raster: 1 / 8 / 24 / 32-bit, standard / byte-encoded / RGB types, colour maps; write 24 / 32-bit.
References: ImageMagick, netpbm (sgitopnm-era writers, rasttopnm), Pillow.
2026-10-31 14:52:47 -05:00

23 lines
1016 B
Python

# Shared by the simple raster fixture generators: run our encoder (tools/fixtures/_tex_encode.luau -a <fmt>) and
# decode files with ImageMagick into rgba8 (through PAM).
import os, shutil, subprocess
def ours(ctx, which):
exe = shutil.which("luau")
cmd = [exe] if exe else ["nix", "shell", "nixpkgs#luau", "-c", "luau"]
res = subprocess.run(cmd + ["tools/fixtures/_tex_encode.luau", "-a", which], cwd=ctx.root, capture_output=True, check=True)
files = {}
for line in res.stdout.decode().split("\n"):
if line.startswith("ours_") and "\t" in line:
n, hx = line.split("\t", 1)
files[n] = bytes.fromhex(hx.strip())
return files
def magick_cases(R, w, names, fmt=None):
"""ImageMagick decodes of the named files in the work dir -> { name: (w, h, rgba) }"""
pre = (fmt + ":") if fmt else ""
w.sh("imagemagick", ["magick %s%s -depth 8 -alpha on pam:%s.pam" % (pre, n, n) for n in names])
return {n: R.pnm_rgba(w.read(n + ".pam")) for n in names}