tests/image: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:50:18 -05:00
1 parent e306d5c1d7
commit a80299dce0
27 files changed
+32 -199

No files matched your search

+1 -15
View File
@@ -1,8 +1,4 @@
-- image/webp tests: every still file of tools/fixtures/webp.py (cwebp lossless / lossy / alpha variants, libvpx key
-- frames with token partitions, metadata) against dwebp (-pam, -nofancy -pam, -yuv: bit-exact), animations (img2webp,
-- gif2webp, webpmux) against Pillow's WebPAnimDecoder frames (bit-exact), our encoder (round trips at every effort,
-- dwebp / Pillow decoding our files at fixture time, metadata, animations), error codes, and the fuzz no-throw pass.
-- Fixtures: tools/fixtures/webp.py.
-- image/webp tests: stills bit-exact with dwebp, animations with Pillow's WebPAnimDecoder (tools/fixtures/webp.py).
local T = require("@tests/T")
local Webp = require("@rosetta/image/webp")
local Bytes = require("@rosetta/core/Bytes")
@@ -21,13 +17,11 @@ local function decode(data: any, opts: any?): (any, any)
return Webp.decode(Bytes.reader(b), opts)
end
-- the contract
t:eq(Webp.name, "webp", "name")
t:eq(Webp.category, "image", "category")
t:check(table.find(Webp.extensions, "webp") ~= nil, "extensions")
t:check(Webp.caps.decode and Webp.caps.encode and Webp.caps.animation and Webp.caps.alpha, "caps")
-- still files, bit-exact with dwebp
do
local lossy, lossless, alpha = 0, 0, 0
for _, c in Cases do
@@ -60,7 +54,6 @@ do
t:check(img.meta.xmp and buffer.tostring(img.meta.xmp) == c.xmp, c.name .. ": XMP")
end
end
-- inside a bigger buffer (the Reader's range)
local c = Cases[3]
local big = buffer.create(#c.data + 11)
buffer.writestring(big, 5, c.data)
@@ -69,7 +62,6 @@ do
t:note("%d lossless and %d lossy files (%d with alpha) match dwebp", lossless, lossy, alpha)
end
-- animations, bit-exact with Pillow (libwebp WebPAnimDecoder)
local function opaque(px: buffer, n: number): buffer
local b = buffer.create(n * 4)
buffer.copy(b, 0, px, 0, n * 4)
@@ -113,7 +105,6 @@ for _, a in Anims do
end
t:note("%d animations match Pillow", #Anims)
-- the encoder: round trips, the fixture-time dwebp / Pillow checks of our files, metadata, animations
local function image(s: any): Types.Image
local img = Types.Image.new(s.width, s.height)
img.pixels = buffer.fromstring(s.rgba)
@@ -163,7 +154,6 @@ do
return f
end)(), loops = a.loops, rgba = true }, "our " .. a.name)
end
-- metadata chunks
local img = image(Src[1])
img.meta.icc = buffer.fromstring("icc profile bytes")
img.meta.exif = buffer.fromstring("Exif\0\0MM")
@@ -173,7 +163,6 @@ do
t:check(back.meta.exif and buffer.tostring(back.meta.exif) == "Exif\0\0MM", "EXIF round trip")
t:check(back.meta.xmp and buffer.tostring(back.meta.xmp) == "<x:xmpmeta/>", "XMP round trip")
t:check(back.meta.source.extended and buffer.tostring(back.pixels) == Src[1].rgba, "VP8X still round trip")
-- an animation round trip through our own decoder (frame fields kept)
local anim = Types.Image.new(8, 6)
local f1 = Types.Image.new(8, 6)
buffer.fill(f1.pixels, 0, 200)
@@ -189,7 +178,6 @@ do
t:check(ab.frames[2].x == 2 and ab.frames[2].y == 4 and ab.frames[2].dispose == "background" and ab.frames[2].blend == "over" and ab.frames[2].delay == 1.5, "animation round trip: frame fields")
t:check(buffer.tostring(ab.frames[2].image.pixels) == buffer.tostring(f2.pixels), "animation round trip: frame pixels")
t:check(ab.meta.background[1] == 10 and ab.meta.background[4] == 40, "animation round trip: background")
-- bad arguments
local _, e1 = Webp.encode({} :: any)
t:check(e1 and e1.code == Err.ARG, "encode a non-image: ARG")
local _, e2 = Webp.encode(img, { lossless = false })
@@ -201,7 +189,6 @@ do
t:check(e4 and e4.code == Err.ARG, "frame outside the canvas: ARG")
end
-- sniff, info, errors
do
local c = Cases[1]
t:eq(Webp.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff WebP")
@@ -222,7 +209,6 @@ do
t:check(e4 and e4.code == Err.CORRUPT, "junk: " .. tostring(e4))
end
-- fuzz: truncations, mutations and garbage never throw
do
local samples = {}
for i, c in Cases do