png: tests for maxSide / reduce (every PngSuite and generated image, APNG frames, a 2048x2048 16-bit fixture), yield; paeth for 16-bit RGB rows; jpeg: opts.maxSide (scale 1..8) and opts.yield reach the codec; Deflate.zlibStream tests

This commit is contained in:
4DBug committed 2026-11-02 23:01:59 -06:00
1 parent e3e6273799
commit 64a2553c0c
8 files changed
+321 -9

No files matched your search

+32
View File
@@ -69,4 +69,36 @@ function R.samples(cases: { any }, every: number?): { string }
return samples
end
-- the reference k x k box reduction of an rgba8 Image (the PNG decoder's maxSide / reduce): the alpha-weighted mean,
-- halves up, a fully transparent block is 0, 0, 0, 0
function R.box(img: Types.Image, k: number): Types.Image
local w, h, px = img.width, img.height, img.pixels
local ow, oh = (w + k - 1) // k, (h + k - 1) // k
local out = Types.Image.new(ow, oh)
for oy = 0, oh - 1 do
for ox = 0, ow - 1 do
local r, g, b, a, n = 0, 0, 0, 0, 0
for y = oy * k, math.min(oy * k + k, h) - 1 do
for x = ox * k, math.min(ox * k + k, w) - 1 do
local o = (y * w + x) * 4
local al = buffer.readu8(px, o + 3)
r += buffer.readu8(px, o) * al
g += buffer.readu8(px, o + 1) * al
b += buffer.readu8(px, o + 2) * al
a += al
n += 1
end
end
local o = (oy * ow + ox) * 4
if a > 0 then
buffer.writeu8(out.pixels, o, (r + a // 2) // a)
buffer.writeu8(out.pixels, o + 1, (g + a // 2) // a)
buffer.writeu8(out.pixels, o + 2, (b + a // 2) // a)
buffer.writeu8(out.pixels, o + 3, (a + n // 2) // n)
end
end
end
return out
end
return R