# QOI fixtures (tools/fixtures.py): Pillow's QOI writer and reader. # tests/gen/qoi.luau { { name, width, height, mode, pixels (source bytes, RGB or RGBA), data (Pillow's .qoi), crc # (CRC-32 of Pillow's RGBA decode) } } # tests/gen/qoi_bench.luau { width, height, pixels (RGBA), data } import struct CODE = r''' import io, random, struct, sys, zlib from PIL import Image rng = random.Random(11) def make(w, h, mode, kind): n = len(mode) px = bytearray() for y in range(h): for x in range(w): if kind == "noise": v = [rng.randrange(256) for _ in range(n)] elif kind == "grad": v = [(x * 3 + y) % 256, (y * 5) % 256, (x + y * 2) % 256, 255 - (x % 7) * 30][:n] elif kind == "flat": v = [10, 200, 30, 255][:n] if (x // 9 + y // 7) % 2 else [10, 200, 31, 128][:n] else: # small deltas around a walk, with an occasional jump base = (x * 2 + y) % 256 v = [(base + rng.randrange(-2, 2)) % 256, (base + rng.randrange(-30, 30)) % 256, (base + rng.randrange(-9, 9)) % 256, 255 if rng.random() < 0.9 else rng.randrange(256)][:n] px += bytes(v) return bytes(px) out = [] for (w, h, mode, kind) in ((1, 1, "RGB", "noise"), (1, 1, "RGBA", "noise"), (3, 2, "RGBA", "grad"), (64, 48, "RGB", "grad"), (64, 48, "RGBA", "grad"), (100, 37, "RGB", "noise"), (100, 37, "RGBA", "noise"), (200, 150, "RGBA", "flat"), (200, 150, "RGB", "flat"), (128, 99, "RGBA", "walk"), (128, 99, "RGB", "walk"), (500, 1, "RGBA", "flat"), (1, 300, "RGB", "walk")): px = make(w, h, mode, kind) im = Image.frombytes(mode, (w, h), px) b = io.BytesIO(); im.save(b, "QOI"); data = b.getvalue() back = Image.open(io.BytesIO(data)).convert("RGBA").tobytes() name = "%dx%d-%s-%s" % (w, h, mode, kind) sys.stdout.buffer.write(struct.pack("