merge ws/downscale
This commit is contained in:
commit
f1d98ec904
24 files changed
+3432
-1340
No files matched your search
@@ -4,6 +4,8 @@
|
||||
# tests/gen/png_gen.luau images written by a small PNG writer here: every colour type and bit depth, plain and
|
||||
# Adam7, odd sizes, every filter, split IDATs, tRNS keys; with the CRC-32 of the RGBA8 pixels
|
||||
# tests/gen/png_bench.luau 1024 x 768 RGBA / RGB / Adam7 / palette images for tools/bench.luau
|
||||
# tests/gen/png_big16.luau a 2048 x 2048 16-bit RGB image in 8 KB IDATs (rows alternate between two patterns, every
|
||||
# 97th row is noise under a random filter), with the CRC-32 of its RGBA8 pixels
|
||||
import os, random, struct, zlib
|
||||
|
||||
INPUTS = ["tests/fixtures/pngsuite", "tests/fixtures/pngsuite_ref.txt"]
|
||||
@@ -163,3 +165,31 @@ def generate(ctx):
|
||||
bench.append((label, data, zlib.crc32(exp)))
|
||||
|
||||
ctx.emit("png_bench", [{"name": l, "width": 1024, "height": 768, "crc": c, "data": d} for l, d, c in bench])
|
||||
|
||||
# --- a large 16-bit image that stays small compressed (rows repeat at a distance of two rows: 24578 bytes)
|
||||
w = h = 2048
|
||||
pat = []
|
||||
for k in range(2):
|
||||
pat.append([((x * 97 + k * 4000) & 0xFFFF, (x * x * 13 + k * 777) & 0xFFFF, (x * 7919 + k * 31337) & 0xFFFF) for x in range(w)])
|
||||
def row16(px):
|
||||
return b"".join(struct.pack(">HHH", *p) for p in px)
|
||||
def row8(px):
|
||||
return b"".join(bytes((p[0] >> 8, p[1] >> 8, p[2] >> 8, 255)) for p in px)
|
||||
raws = [row16(p) for p in pat]
|
||||
rgba = [row8(p) for p in pat]
|
||||
out, exp, prev = bytearray(), [], None
|
||||
for y in range(h):
|
||||
if y % 97 == 50:
|
||||
px = [(rng.randrange(65536), rng.randrange(65536), rng.randrange(65536)) for _ in range(w)]
|
||||
raw, r8, ft = row16(px), row8(px), rng.randrange(1, 5)
|
||||
else:
|
||||
raw, r8, ft = raws[y % 2], rgba[y % 2], 0
|
||||
out += filt(raw, prev, 6, ft) if ft else b"\0" + raw
|
||||
exp.append(r8)
|
||||
prev = raw
|
||||
z = zlib.compress(bytes(out), 9)
|
||||
data = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 16, 2, 0, 0, 0))
|
||||
for i in range(0, len(z), 8192):
|
||||
data += chunk(b"IDAT", z[i:i + 8192])
|
||||
data += chunk(b"IEND", b"")
|
||||
ctx.emit("png_big16", {"width": w, "height": h, "crc": zlib.crc32(b"".join(exp)), "data": data})
|
||||
Reference in new issue
Block a user