# Radiance HDR fixtures (tools/fixtures.py): files ImageMagick writes (new-style RLE, from float PFM sources) and # hand-written ones (flat and old-style RLE scanlines, narrow images, the "#?RGBE" header, EXPOSURE lines, every # orientation); references = ImageMagick's float decodes for its files, and for the hand-written ones the RGBE values # decoded by the rgbe.c rule (m * 2^(e - 136)) here. # tests/gen/hdr.luau { { name, data, width, height, floats (rgbaf32 little-endian bytes), exposure? } } import math, os, random, shutil, struct, subprocess, tempfile def rgbe(r, g, b): v = max(r, g, b) if v < 1e-32: return (0, 0, 0, 0) m, e = math.frexp(v) s = m * 256 / v return (min(255, int(r * s)), min(255, int(g * s)), min(255, int(b * s)), e + 128) def flt(p): if p[3] == 0: return (0.0, 0.0, 0.0) f = math.ldexp(1.0, p[3] - 136) return (p[0] * f, p[1] * f, p[2] * f) def generate(ctx): magick = ctx.nix("imagemagick", ["sh", "-c", "command -v magick"]).decode().strip() work = tempfile.mkdtemp(prefix="formats-hdr-") try: _generate(ctx, magick, work) finally: shutil.rmtree(work, ignore_errors=True) def _generate(ctx, magick, work): rng = random.Random(4) cases = [] def im_case(name, w, h, fn): pfm = os.path.join(work, name + ".pfm") with open(pfm, "wb") as f: f.write(b"PF\n%d %d\n-1.0\n" % (w, h)) for y in range(h - 1, -1, -1): for x in range(w): f.write(struct.pack(" (x, y) of scanline i pixel j; pix: (i, j) -> RGBE""" data = header + b"\n\n" + res + b"\n" + b"".join(r for r, _ in rows) fl = [(0.0, 0.0, 0.0)] * (w * h) for i, (_, pixels) in enumerate(rows): for j, p in enumerate(pixels): x, y = mapping(i, j) fl[y * w + x] = flt(p) c = {"name": name, "data": data, "width": w, "height": h, "floats": b"".join(struct.pack("