tests/ops: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:09 -05:00
1 parent 9d80ee11b9
commit 75ddfb4068
5 files changed
+7 -58

No files matched your search

+1 -15
View File
@@ -1,8 +1,4 @@
-- ops/ImageOps tests: against Pillow (tools/fixtures/imageops.py): grey conversion (exact), resize nearest / bilinear /
-- Lanczos up and down (max error), rotate with bilinear + expand (PSNR), alpha_composite (exact); property tests for
-- every pixel format (conversion round trips, flips, quarter turns, crop, premultiply, pixel access, fill), blit
-- clipping and blend modes, animation helpers (coalesce with each disposal, fromFrames, durations), and a pass of bad
-- arguments that must return nil, Err without throwing.
-- ops/ImageOps tests against Pillow (tools/fixtures/imageops.py) and property tests.
local T = require("@tests/T")
local Ops = require("@rosetta/ops/ImageOps")
local Types = require("@rosetta/Types")
@@ -17,7 +13,6 @@ local function image(w: number, h: number, fmt: string, px: string): any
return img
end
-- max abs difference and PSNR of two byte strings / buffers
local function diff(a: buffer, b: string): (number, number)
local n = #b
local mx, se = 0, 0
@@ -36,7 +31,6 @@ local rgb = image(Fx.rgb.w, Fx.rgb.h, "rgb8", Fx.rgb.px)
local rgba = image(Fx.rgba.w, Fx.rgba.h, "rgba8", Fx.rgba.px)
local rgba2 = image(Fx.rgba2.w, Fx.rgba2.h, "rgba8", Fx.rgba2.px)
-- Pillow references
do
local g = Ops.convert(rgb, "gray8") :: any
t:check(buffer.tostring(g.pixels) == Fx.gray, "rgb8 -> gray8 matches Pillow convert('L')")
@@ -67,7 +61,6 @@ do
t:check(mx == 0, "alpha_composite matches Pillow exactly (max error " .. mx .. ")")
end
-- conversions between every format
local FORMATS = { "rgba8", "rgba16", "rgbaf32", "rgb8", "gray8", "gray16", "graya8", "alpha8", "yuv420p" }
do
for _, f in FORMATS do
@@ -104,7 +97,6 @@ do
t:check(buffer.readu8(b.pixels, 0) == 255 and buffer.readu8(b.pixels, 1) == 0 and buffer.readu8(b.pixels, 2) == 128, "float -> 8 bit clamps and rounds")
end
-- geometry properties on every format
do
for _, f in FORMATS do
local img = Ops.convert(rgba, f) :: any
@@ -131,7 +123,6 @@ do
local rr = Ops.rotate(img, 33) :: any
t:check(rr and rr.format == f, f .. ": rotate 33")
end
-- crop content, nearest identity, ccw convention
local c = Ops.crop(rgba, 3, 4, 5, 6) :: any
t:check(buffer.readu32(c.pixels, 0) == buffer.readu32(rgba.pixels, (4 * rgba.width + 3) * 4), "crop origin")
t:check(buffer.tostring((Ops.resize(rgba, rgba.width, rgba.height, "lanczos") :: any).pixels) == buffer.tostring(rgba.pixels), "same-size resize is a copy")
@@ -139,7 +130,6 @@ do
t:eq(buffer.readu32(q.pixels, 0), buffer.readu32(rgba.pixels, (rgba.width - 1) * 4), "rotate90 is counter-clockwise")
end
-- pixels, fill, premultiply
do
for _, f in FORMATS do
local img = Ops.new(3, 2, f) :: any
@@ -173,7 +163,6 @@ do
t:note("premultiply round trip: max error %d for alpha >= 32", worst)
end
-- blit
do
local dst = Ops.new(10, 10, "rgba8") :: any
Ops.fill(dst, 10, 20, 30, 255)
@@ -191,7 +180,6 @@ do
Ops.blit(dst, src, 5, 5, { opacity = 0.5 })
local r = Ops.getPixel(dst, 5, 5)
t:check(math.abs(r - 133) <= 1, "opacity 0.5 over (10 -> " .. r .. ")")
-- rgb8 destination, gray source, float destination
local d3 = Ops.convert(dst, "rgb8") :: any
t:check(Ops.blit(d3, Ops.convert(src, "graya8") :: any, 1, 1) == d3, "blit onto rgb8")
local df = Ops.convert(dst, "rgbaf32") :: any
@@ -200,7 +188,6 @@ do
t:check(Ops.blit(dy, src, 3, 3) == dy, "blit onto yuv420p")
end
-- animation helpers
do
local W, H = 6, 4
local function solid(w: number, h: number, r: number, a: number): any
@@ -241,7 +228,6 @@ do
t:check(Ops.fromFrames({ fr[1], rgba }) == nil, "fromFrames refuses mixed sizes")
end
-- bad arguments: nil, Err, never a throw
do
local rand = T.rng(5)
local junk: { any } = { nil, 0, -1, 1.5, 2 ^ 40, "x", {}, true, 0 / 0, math.huge, -7 }