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

+2 -12
View File
@@ -1,8 +1,5 @@
-- image/jpeg tests: every cjpeg / jpegtran fixture (baseline, progressive, arithmetic, every sampling, restarts, grey,
-- RGB, 12-bit, odd sizes, stripped DHT) against djpeg's decodes at scales 1, 1/2, 1/4, 1/8 (bit-exact, CRC-32);
-- CMYK / YCCK against Pillow; refused files; info / meta (EXIF orientation applied, ICC, comment, density); the
-- encoder byte-identical to cjpeg for the same settings, its PSNR, round trips through our decoder; truncated files;
-- the fuzz no-throw pass. Ported from jpeg-luau tests/jpeg.luau. Fixtures: tools/fixtures/jpeg.py.
-- image/jpeg tests: decodes bit-exact with djpeg (CMYK / YCCK against Pillow), encoder byte-identical to cjpeg.
-- Fixtures: tools/fixtures/jpeg.py.
local T = require("@tests/T")
local Jpeg = require("@rosetta/image/jpeg")
local Bytes = require("@rosetta/core/Bytes")
@@ -19,12 +16,10 @@ local function decode(data: any, opts: any?): (any, any)
return Jpeg.decode(Bytes.reader(b), opts)
end
-- the contract
t:eq(Jpeg.name, "jpeg", "name")
t:eq(Jpeg.category, "image", "category")
t:check(Jpeg.caps.decode and Jpeg.caps.encode, "caps")
-- decodes against djpeg / Pillow
local files: { [string]: string } = {}
do
local refs, arith = 0, 0
@@ -69,7 +64,6 @@ local function file(name: string): buffer
return buffer.fromstring(files[name])
end
-- sniff, info, meta, options
do
t:eq(Jpeg.sniff(Bytes.reader(file("photo_q90_420"))), 1, "sniff a JPEG")
t:eq(Jpeg.sniff(Bytes.reader(buffer.fromstring("GIF89a"))), 0, "sniff a GIF")
@@ -102,7 +96,6 @@ do
t:check(e2 and e2.code == Err.ARG, "bad scale")
local _, e3 = decode("nope")
t:check(e3 and e3.code == Err.CORRUPT, "junk: " .. tostring(e3))
-- a range inside a bigger buffer
local data = files["photo_q90_420"]
local big = buffer.create(#data + 20)
buffer.writestring(big, 11, data)
@@ -171,7 +164,6 @@ do
t:check(img.meta.dpi == nil, "no density in cjpeg's JFIF (aspect only)")
end
-- the encoder: byte-identical to cjpeg
local function source(c: any): any
local img = Types.Image.new(c.width, c.height, c.format)
if c.format == "rgb8" then
@@ -227,7 +219,6 @@ do
t:note("%d encodes byte-identical to cjpeg", exact)
end
-- encoder: meta segments round trip, rgba8 input, options, errors
do
local c = Enc[1]
local rgb = source(c)
@@ -281,7 +272,6 @@ do
t:note("%d truncated files, %d decoded partially", count, partial)
end
-- fuzz
do
local samples = {}
for i, c in Dec do