# SGI fixtures (tools/fixtures.py): files from netpbm (pnmtosgi: RLE and verbatim, RGB and grey), ImageMagick (RGB, # RGBA, 16-bit) and Pillow (L, RGB, RGBA), plus our encoder's files (tools/fixtures/_tex_encode.luau -a sgi); the # reference is ImageMagick's decode of each file (16-bit within 1: it rounds where we keep the high byte). # tests/gen/sgi.luau { cases = { { name, data, w, h, rgba, tol } }, ours = { ... } } import importlib.util, os def _load(n): spec = importlib.util.spec_from_file_location(n, os.path.join(os.path.dirname(os.path.abspath(__file__)), n + ".py")) m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) return m R, S = _load("_raster_ref"), _load("_simple") INPUTS = ["tools/fixtures/_tex_encode.luau", "src/Rosetta/image/sgi"] def generate(ctx): w = R.Work(ctx) try: w.png("photo.png", 37, 23, R.photo(37, 23)) w.png("alpha.png", 30, 17, R.photo(30, 17, 3, True)) w.sh("netpbm", ["pngtopam photo.png | pamtopnm > photo.ppm", "pnmtosgi -rle photo.ppm > nb_rle.sgi", "pnmtosgi -verbatim photo.ppm > nb_verbatim.sgi", "ppmtopgm photo.ppm | pnmtosgi -rle > nb_grey.sgi"]) w.sh("imagemagick", ["magick photo.png -alpha off im_rgb.sgi", "magick alpha.png im_rgba.sgi", "magick photo.png -alpha off -depth 16 im_rgb16.sgi", "magick alpha.png -compress none im_rgba_verbatim.sgi"]) ctx.python(["pillow"], ("from PIL import Image\nimport os\nos.chdir(%r)\nim=Image.open('alpha.png')\nim.save('pil_rgba.sgi')\n" "im.convert('RGB').save('pil_rgb.sgi')\nim.convert('L').save('pil_l.sgi')\n") % w.dir) names = sorted(f for f in os.listdir(w.dir) if f.endswith(".sgi")) mine = S.ours(ctx, "sgi") for n, d in mine.items(): w.write(n, d) ref = S.magick_cases(R, w, names + sorted(mine)) out = {"cases": [], "ours": []} for n in names + sorted(mine): ww, hh, rgba = ref[n] out["ours" if n.startswith("ours_") else "cases"].append({"name": n, "data": w.read(n), "w": ww, "h": hh, "rgba": rgba, "tol": 1 if "16" in n else 0}) ctx.emit("sgi", out) finally: w.close()