tests/image: comments: specs only
This commit is contained in:
1 parent
e306d5c1d7
commit
a80299dce0
27 files changed
+32
-199
No files matched your search
@@ -1,5 +1,4 @@
|
||||
-- tests/image/_raster: the shared checks of the simple raster formats' tests (pcx, sgi, sunras, xbm, xpm, ilbm, icns,
|
||||
-- ani): decode every case against its reference rgba8 pixels, round-trip images through the encoder, fuzz samples.
|
||||
-- shared checks of the simple raster formats' tests: decode against reference rgba8, round trips, fuzz samples.
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Types = require("@rosetta/Types")
|
||||
|
||||
@@ -17,7 +16,6 @@ local function maxDiff(a: buffer, b: buffer, n: number): (number, number)
|
||||
end
|
||||
R.maxDiff = maxDiff
|
||||
|
||||
-- cases: { { name, data, w, h, rgba, tol? } } (rgba: the reference decode)
|
||||
function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number
|
||||
local n = 0
|
||||
for _, c in cases do
|
||||
@@ -31,7 +29,6 @@ function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number
|
||||
end
|
||||
n += 1
|
||||
end
|
||||
-- from inside a bigger buffer
|
||||
local big = buffer.create(#c.data + 9)
|
||||
buffer.writestring(big, 5, c.data)
|
||||
local img2 = Fmt.decode(Bytes.reader(big, 5, #c.data), opts)
|
||||
@@ -40,14 +37,12 @@ function R.decodes(t: any, Fmt: any, cases: { any }, opts: any?): number
|
||||
return n
|
||||
end
|
||||
|
||||
-- image(w, h, rgba string) -> Types.Image
|
||||
function R.image(w: number, h: number, rgba: string): Types.Image
|
||||
local img = Types.Image.new(w, h)
|
||||
img.pixels = buffer.fromstring(rgba)
|
||||
return img
|
||||
end
|
||||
|
||||
-- roundTrip(t, Fmt, img, encodeOpts?, label, tol?) -> the encoded buffer
|
||||
function R.roundTrip(t: any, Fmt: any, img: Types.Image, eopts: any?, label: string, tol: number?): buffer?
|
||||
local enc, err = Fmt.encode(img, eopts)
|
||||
t:check(enc, label .. ": encode " .. tostring(err))
|
||||
@@ -64,7 +59,6 @@ function R.roundTrip(t: any, Fmt: any, img: Types.Image, eopts: any?, label: str
|
||||
return enc
|
||||
end
|
||||
|
||||
-- samples(cases, every?) -> the fuzz samples (every n-th case's data)
|
||||
function R.samples(cases: { any }, every: number?): { string }
|
||||
local samples = {}
|
||||
for i, c in cases do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/ani tests: animated cursors around Pillow-written ICO / CUR frames (seq + rate, plain, cursor hotspots, INFO
|
||||
-- title) against Pillow's frame decodes and the written steps / delays; AF_ICON clear and a missing hook are
|
||||
-- UNSUPPORTED; the encoder through the ICO hook round-trips; the fuzz no-throw pass. Fixtures: tools/fixtures/ani.py.
|
||||
-- image/ani tests against Pillow (tools/fixtures/ani.py).
|
||||
local T = require("@tests/T")
|
||||
local Ani = require("@rosetta/image/ani")
|
||||
local Ico = require("@rosetta/image/ico")
|
||||
@@ -47,7 +45,6 @@ for _, c in Fx.cases do
|
||||
if c.hotspot then
|
||||
t:check(img.meta.hotspot and img.meta.hotspot.x == c.hotspot[1] and img.meta.hotspot.y == c.hotspot[2], c.name .. ": hotspot")
|
||||
end
|
||||
-- re-encode through the ICO hook
|
||||
local enc, eerr = Ani.encode(img, hooks)
|
||||
t:check(enc, c.name .. ": encode " .. tostring(eerr))
|
||||
local back = Ani.decode(Bytes.reader(enc :: buffer), hooks) :: any
|
||||
|
||||
+1
-10
@@ -1,7 +1,4 @@
|
||||
-- image/png APNG tests: animated PNGs from ffmpeg's encoder and hand-written ones (every dispose / blend op, sub-rects,
|
||||
-- palette + tRNS, grey, RGB, a hidden default image) decoded into frames and composited, compared with ffmpeg's
|
||||
-- composited canvases (CRC-32); the APNG encoder's round trips; bad sequence numbers / rectangles; the fuzz pass.
|
||||
-- Fixtures: tools/fixtures/apng.py.
|
||||
-- image/png APNG tests against ffmpeg's composited canvases (tools/fixtures/apng.py).
|
||||
local T = require("@tests/T")
|
||||
local Png = require("@rosetta/image/png")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -65,7 +62,6 @@ for _, c in Cases do
|
||||
for i, want in c.crcs do
|
||||
t:eq(canvasCrc(canv[i].pixels, c.opaque), want, c.name .. ": composited frame " .. i .. (if c.ffmpeg then " vs ffmpeg" else " vs reference"))
|
||||
end
|
||||
-- round trip through the encoder: the same frames, rectangles, ops, delays, loops and default image
|
||||
local enc, eerr = Png.encode(img)
|
||||
t:check(enc, c.name .. ": encode " .. tostring(eerr))
|
||||
local back, berr = Png.decode(Bytes.reader(enc :: buffer), { checkCrc = true })
|
||||
@@ -82,7 +78,6 @@ for _, c in Cases do
|
||||
end
|
||||
t:note("%d APNGs match the reference canvases and round-trip", #Cases)
|
||||
|
||||
-- encoder: frames built here (sub-rects, delays in seconds), opts.apng, validation
|
||||
do
|
||||
local function solid(w: number, h: number, r: number, g: number, b: number, a: number): Types.Image
|
||||
local im = Types.Image.new(w, h)
|
||||
@@ -112,13 +107,11 @@ do
|
||||
t:eq(buffer.readu8(canv[2].pixels, o + 3), 255, "over: alpha")
|
||||
t:eq(buffer.readu8(canv[2].pixels, o), (128 * 200 + 127 * 10 + 128) * 257 // 65536, "over: red")
|
||||
t:eq(buffer.readu32(canv[3].pixels, o), 0, "background dispose cleared frame 2's rect")
|
||||
-- one frame + opts.apng; a still image stays a PNG
|
||||
local still = solid(4, 4, 1, 2, 3, 255)
|
||||
local plain = decode(Png.encode(still) :: buffer)
|
||||
t:check(plain.frames == nil, "still image: no acTL")
|
||||
local one = decode(Png.encode(still, { apng = true }) :: buffer)
|
||||
t:check(one.frames and #one.frames == 1 and same(one.frames[1].image, still), "opts.apng: a one-frame APNG")
|
||||
-- bad frames
|
||||
local function bad(frames: any, label: string)
|
||||
local im = solid(4, 4, 0, 0, 0, 255)
|
||||
im.frames = frames
|
||||
@@ -132,7 +125,6 @@ do
|
||||
bad({ { image = still }, { image = still, delay = -1 } }, "negative delay")
|
||||
end
|
||||
|
||||
-- crafted bad input: a broken sequence number, a frame outside the canvas
|
||||
do
|
||||
local c = Cases[1]
|
||||
local s = c.data
|
||||
@@ -153,7 +145,6 @@ do
|
||||
t:check(Png.composite({} :: any) == nil, "composite of a non-image")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Cases do
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/blp tests: BLP1 / BLP2 palette files written by Pillow and DXT1 / DXT3 / DXT5 / palette-with-alpha files
|
||||
-- written by tools/fixtures/blp.py decode to Pillow's RGBA; BLP1 JPEG (3 components) to Pillow's, 4 components (BGRA)
|
||||
-- within a PSNR of the source; BLP2 BGRA and BLP1 palette + alpha against the writer; our BLP2 writer round-trips
|
||||
-- (with mips); errors; the fuzz pass. Fixtures: tools/fixtures/blp.py.
|
||||
-- image/blp tests against Pillow and the fixture writer (tools/fixtures/blp.py).
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Blp = require("@rosetta/image/blp")
|
||||
@@ -61,7 +58,6 @@ for _, c in Fx do
|
||||
else
|
||||
t:check(buffer.tostring(img.pixels) == c.rgba, c.name .. ": pixels against the writer")
|
||||
end
|
||||
-- our writer: BLP2 BGRA, lossless
|
||||
local enc = Blp.encode(img, { mips = true }) :: buffer
|
||||
local back = Blp.decode(Bytes.reader(enc)) :: any
|
||||
t:eq(Crc32.of(back.pixels), Crc32.of(img.pixels), c.name .. ": BLP2 BGRA round trip")
|
||||
|
||||
+1
-19
@@ -1,8 +1,4 @@
|
||||
-- image/bmp tests: synthesized BMPs (every header type, bit depth and compression, row order, palettes, masks and alpha
|
||||
-- rules, the RLE escapes, the lenient paths, errors), the BMP Suite against Pillow (g/ must match, q/ and b/ must not
|
||||
-- throw), the encoder byte-exact against Pillow (24 bpp, 8 bpp paletted, 32 bpp BI_RGB) plus the V4 alpha header and
|
||||
-- round trips (the V4 output was also checked by hand: Pillow and ImageMagick read the same RGBA), the api, and the
|
||||
-- fuzz passes. Ported from bmp-luau tests/core.luau + tests/files.luau.
|
||||
-- image/bmp tests: synthesized BMPs, the BMP Suite against Pillow (g/ must match, q/ and b/ must not throw).
|
||||
-- Fixtures: tools/fixtures/bmp.py.
|
||||
local T = require("@tests/T")
|
||||
local BmpF = require("@rosetta/image/bmp")
|
||||
@@ -19,8 +15,6 @@ local function check(cond: any, label: string)
|
||||
t:check(cond, label)
|
||||
end
|
||||
|
||||
-- the bmp-luau API on top of the contract (the ported tests below use it): decode(string | buffer) -> image with the
|
||||
-- old fields | nil, message
|
||||
local Bmp = {}
|
||||
function Bmp.decode(s: any, opts: any?): (any, any)
|
||||
local b = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
@@ -59,8 +53,6 @@ local function i32(v: number): string
|
||||
return le(if v < 0 then v + 4294967296 else v, 4)
|
||||
end
|
||||
|
||||
-- Builds a BMP. o: w, h (negative = top-down), bpp, comp, hs (12, 40, 52, 56, 108, 124), palette ({ {r,g,b} }),
|
||||
-- clrUsed, masks ({r,g,b[,a]}: in the header for hs >= 52, else after it), pixels (string), off / bfSize overrides.
|
||||
local function make(o): string
|
||||
local hs = o.hs or 40
|
||||
local hdr
|
||||
@@ -130,7 +122,6 @@ do
|
||||
check(td.topDown and td.height == 2, "top-down fields")
|
||||
is(td, 0, 0, 255, 0, 0, 255, "top-down first row on top")
|
||||
is(td, 0, 1, 255, 255, 255, 255, "top-down second row")
|
||||
-- string and buffer input are the same
|
||||
local b = Bmp.decode(buffer.fromstring(make({ w = 3, h = 2, bpp = 24, pixels = bottom .. top })))
|
||||
check(b and buffer.tostring(b.pixels) == buffer.tostring(img.pixels), "buffer input")
|
||||
end
|
||||
@@ -210,7 +201,6 @@ do
|
||||
is(img5, 0, 0, 255, 131, 8, 255, "v4 BI_RGB 16 -> 555")
|
||||
end
|
||||
|
||||
-- 32 bpp
|
||||
do
|
||||
-- BI_RGB, alpha bytes all zero -> opaque
|
||||
local img = decode(make({ w = 2, h = 1, bpp = 32, pixels = "\1\2\3\0\4\5\6\0" }), "rgb32 zero alpha")
|
||||
@@ -311,7 +301,6 @@ do
|
||||
is(t2, 3, 3, 0, 0, 0, 255, "no pixel data: index 0")
|
||||
end
|
||||
|
||||
-- info / isBmp
|
||||
do
|
||||
local s = make({ hs = 124, w = 7, h = -5, bpp = 32, comp = 3, masks = { 0xFF0000, 0xFF00, 0xFF, 0xFF000000 }, pixels = "" })
|
||||
local info = Bmp.info(s)
|
||||
@@ -347,7 +336,6 @@ do
|
||||
fails(make({ w = 100, h = 100, bpp = 24, pixels = "" }), "too large", "maxPixels option", { maxPixels = 9999 })
|
||||
end
|
||||
|
||||
-- fuzz: truncations and byte flips of every kind of file above must never throw
|
||||
do
|
||||
local seeds = {
|
||||
make({ w = 3, h = 2, bpp = 24, pixels = string.rep("\1\2\3", 8) }),
|
||||
@@ -387,8 +375,6 @@ do
|
||||
t:note("fuzz: %d decodes, no throw", runs)
|
||||
end
|
||||
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ the BMP Suite
|
||||
do
|
||||
local nMatch, nOther = 0, 0
|
||||
local samples = {}
|
||||
@@ -413,7 +399,6 @@ do
|
||||
end, samples, { mutations = 6 })
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encoder
|
||||
do
|
||||
for _, c in Enc do
|
||||
local img = Types.Image.new(c.w, c.h)
|
||||
@@ -438,7 +423,6 @@ do
|
||||
end
|
||||
end
|
||||
t:note("encoder: %d files identical to Pillow", #Enc)
|
||||
-- forced depths, dpi, errors
|
||||
local img = Types.Image.new(5, 4)
|
||||
for i = 0, 19 do
|
||||
buffer.writeu32(img.pixels, i * 4, 0xFF000000 + i * 0x010203)
|
||||
@@ -462,14 +446,12 @@ do
|
||||
t:check(e2 and e2.code == Err.ARG, "not an image")
|
||||
local _, e3 = BmpF.encode(img, { bitDepth = 16 } :: any)
|
||||
t:check(e3 and e3.code == Err.ARG, "bitDepth 16")
|
||||
-- the api
|
||||
local c = Enc[1]
|
||||
local loaded = F.image.load(c.bmp)
|
||||
t:check(loaded and loaded.width == c.w and buffer.tostring(loaded.pixels) == c.rgba, "F.image.load")
|
||||
t:eq(F.detect(c.bmp), "bmp", "F.detect")
|
||||
local saved = F.save(loaded, nil, { format = "bmp" })
|
||||
t:check(saved and buffer.tostring(saved) == c.bmp, "F.save bmp")
|
||||
-- a sub-range reader
|
||||
local big = buffer.create(#c.bmp + 5)
|
||||
buffer.writestring(big, 3, c.bmp)
|
||||
local sub = BmpF.decode(Bytes.reader(big, 3, #c.bmp)) :: any
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/dds tests: files from NVIDIA Texture Tools (BGRA, BC1..BC7 incl. BC6H, mips, DX10, cube / array / volume)
|
||||
-- and ImageMagick against every surface's reference decode (Pillow per surface, Godot floats for BC6H); hand-written
|
||||
-- uncompressed DXGI / legacy / FourCC formats against their values (rgba8 and native floats); our encoder's files read
|
||||
-- by Pillow and nvddsinfo, and round trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/dds.py.
|
||||
-- image/dds tests against NVIDIA Texture Tools, ImageMagick, Pillow and Godot (BC6H floats) (tools/fixtures/dds.py).
|
||||
local T = require("@tests/T")
|
||||
local Dds = require("@rosetta/image/dds")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -26,7 +23,6 @@ local function maxDiff(a: buffer, b: buffer, n: number): number
|
||||
return worst
|
||||
end
|
||||
|
||||
-- tool-written files
|
||||
local surfaces = 0
|
||||
for _, c in Fx.cases do
|
||||
local img, err = dec(c.data, { mips = true })
|
||||
@@ -70,7 +66,6 @@ for _, c in Fx.cases do
|
||||
end
|
||||
t:note("%d tool-written files, %d surfaces match the references", #Fx.cases, surfaces)
|
||||
|
||||
-- hand-written formats
|
||||
for _, c in Fx.hand do
|
||||
local img, err = dec(c.data)
|
||||
t:check(img, c.name .. ": " .. tostring(err))
|
||||
@@ -158,7 +153,6 @@ for _, o in Fx.ours do
|
||||
end
|
||||
t:note("%d of our files read by Pillow / nvddsinfo", #Fx.ours)
|
||||
|
||||
-- round trips
|
||||
do
|
||||
local img = Types.Image.new(37, 23)
|
||||
img.pixels = src
|
||||
@@ -178,7 +172,6 @@ do
|
||||
t:check(e2 and e2.code == Err.ARG, "no bc7 encoder")
|
||||
end
|
||||
|
||||
-- sniff and errors
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
t:eq(Dds.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff")
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
-- image/exr tests: files from the OpenEXR 3.5 bindings (NONE / RLE / ZIPS / ZIP / PIZ; HALF / FLOAT / UINT; offset
|
||||
-- data window; decreasing lines; Y-only; a layer), a hand-written subsampled file, exrmaketiled tiles (one level,
|
||||
-- mip-map, rip-map, round up) and exrmultipart parts against the bindings' reads; PXR24 / B44 / DWAA UNSUPPORTED; our
|
||||
-- files read back by the bindings and exrheader; round trips; errors; the fuzz no-throw pass. Fixtures:
|
||||
-- tools/fixtures/exr.py.
|
||||
-- image/exr tests against the OpenEXR 3.5 bindings, exrmaketiled, exrmultipart and exrheader (tools/fixtures/exr.py).
|
||||
local T = require("@tests/T")
|
||||
local Exr = require("@rosetta/image/exr")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -19,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any)
|
||||
return Exr.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts)
|
||||
end
|
||||
|
||||
-- the largest difference between two rgbaf32 buffers (exact for HALF / FLOAT, UINT as their values)
|
||||
local function worst(a: buffer, b: buffer, n: number): number
|
||||
local m = 0
|
||||
for i = 0, n * 4 - 1 do
|
||||
@@ -54,13 +49,11 @@ for _, c in Fx.cases do
|
||||
local up = string.find(c.name, "up") ~= nil
|
||||
t:eq(mm[1].width, if up then math.ceil(c.w / 2) else c.w // 2, c.name .. ": level 1 width")
|
||||
end
|
||||
-- the rgba8 display conversion
|
||||
local d8 = dec(c.data, { layer = c.layer, part = c.part })
|
||||
t:eq(d8.format, "rgba8", c.name .. ": rgba8 by default")
|
||||
end
|
||||
t:note("%d files match the OpenEXR bindings", #Fx.cases)
|
||||
|
||||
-- the window, the attributes
|
||||
do
|
||||
for _, c in Fx.cases do
|
||||
if c.name == "window_zip.exr" then
|
||||
@@ -109,7 +102,6 @@ do
|
||||
t:check(e and e.code == Err.ARG, "no PIZ encoder")
|
||||
end
|
||||
|
||||
-- sniff, info, errors
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
t:eq(Exr.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff")
|
||||
|
||||
+1
-13
@@ -1,8 +1,4 @@
|
||||
-- image/gif tests: GIFs from ImageMagick and Pillow (static, interlaced, 2..256 colours, grey, transparency,
|
||||
-- animations with every disposal, sub-rectangles, local colour tables, loop counts, comments) against ImageMagick's
|
||||
-- decode of every frame; the encoder (lossless round trips at <= 256 colours, quantized PSNR above, animations with
|
||||
-- frames / delays / disposal / transparency / loops, options); error codes; the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/gif.py.
|
||||
-- image/gif tests against ImageMagick's decodes (tools/fixtures/gif.py).
|
||||
local T = require("@tests/T")
|
||||
local Gif = require("@rosetta/image/gif")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -31,12 +27,10 @@ local function norm(px: buffer): buffer
|
||||
return c
|
||||
end
|
||||
|
||||
-- the contract
|
||||
t:eq(Gif.name, "gif", "name")
|
||||
t:eq(Gif.category, "image", "category")
|
||||
t:check(Gif.caps.decode and Gif.caps.encode and Gif.caps.animation, "caps")
|
||||
|
||||
-- every fixture against ImageMagick
|
||||
local nframes = 0
|
||||
for _, c in Fx do
|
||||
local img, err = decode(c.data)
|
||||
@@ -69,7 +63,6 @@ for _, c in Fx do
|
||||
end
|
||||
t:note("%d files, %d frames match ImageMagick", #Fx, nframes)
|
||||
|
||||
-- sniff, meta, limits, errors
|
||||
do
|
||||
local c = Fx[1]
|
||||
t:eq(Gif.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff a GIF")
|
||||
@@ -100,7 +93,6 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- the encoder
|
||||
local rand = T.rng(17)
|
||||
local function image(w: number, h: number, colors: number?, alpha: boolean?): Types.Image
|
||||
local img = Types.Image.new(w, h)
|
||||
@@ -161,7 +153,6 @@ do
|
||||
local small = Gif.encode(photo, { maxColors = 4 }) :: buffer
|
||||
local sb = decode(small)
|
||||
t:check(sb.meta.palette and #sb.meta.palette <= 4, "maxColors = 4")
|
||||
-- animation: frames, delays, disposal, transparency, loops, comment, local / global palettes
|
||||
local anim = image(40, 30, 50)
|
||||
anim.frames = {
|
||||
{ image = image(40, 30, 50), x = 0, y = 0, delay = 0.1, dispose = "none", blend = "source" },
|
||||
@@ -189,9 +180,7 @@ do
|
||||
t:check(psnr(back.frames[3].image.pixels, anim.frames[3].image.pixels) > 25, "frame 3 quantized")
|
||||
t:eq(back.meta.source.localPalettes, if global then 0 else 3, "palettes")
|
||||
end
|
||||
-- deterministic output
|
||||
t:eq(Crc32.of(Gif.encode(photo, { dither = true }) :: buffer), Crc32.of(Gif.encode(photo, { dither = true }) :: buffer), "deterministic")
|
||||
-- bad arguments
|
||||
local _, e = Gif.encode({} :: any)
|
||||
t:check(e and e.code == Err.ARG, "encode of a non-image")
|
||||
local _, e2 = Gif.encode(photo, { maxColors = 1 })
|
||||
@@ -202,7 +191,6 @@ do
|
||||
t:check(e4 and e4.code == Err.ARG, "too wide")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for _, c in Fx do
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/hdr tests: ImageMagick-written Radiance files (new-style RLE) against its float decodes, hand-written ones
|
||||
-- (flat and old-style RLE scanlines, "#?RGBE", EXPOSURE products, all orientations) against the rgbe.c rule; the
|
||||
-- display conversion to rgba8; our encoder round-trips (RLE and flat, rgbaf32 and rgba8) within RGBE precision;
|
||||
-- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/hdr.py.
|
||||
-- image/hdr tests against ImageMagick's float decodes and the rgbe.c rule (tools/fixtures/hdr.py).
|
||||
local T = require("@tests/T")
|
||||
local Hdr = require("@rosetta/image/hdr")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -18,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any)
|
||||
return Hdr.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts)
|
||||
end
|
||||
|
||||
-- worst relative error between two rgbaf32 buffers
|
||||
local function relErr(a: buffer, b: buffer, n: number): number
|
||||
local worst = 0
|
||||
for i = 0, n * 4 - 1 do
|
||||
@@ -40,7 +36,6 @@ for _, c in Fx do
|
||||
if c.exposure then
|
||||
t:check(math.abs(img.meta.exposure - c.exposure) < 1e-9, c.name .. ": exposure")
|
||||
end
|
||||
-- the default rgba8 display conversion
|
||||
local d8 = dec(c.data)
|
||||
t:eq(d8.format, "rgba8", c.name .. ": rgba8 by default")
|
||||
local v = buffer.readf32(img.pixels, 0)
|
||||
@@ -77,7 +72,6 @@ do
|
||||
end
|
||||
end
|
||||
t:check(worst < 1 / 128, "float precision " .. worst)
|
||||
-- rgba8 in, rgba8 out
|
||||
local i8 = Types.Image.new(9, 2)
|
||||
for i = 0, 17 do
|
||||
buffer.writeu32(i8.pixels, i * 4, 0xFF000000 + (i * 14) * 0x10101)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/icns tests: a libicns file (RLE entries + masks, JPEG 2000 entries skipped), a Pillow file (PNG entries through
|
||||
-- the decodeImage hook) and a hand-written one (ics#, raw is32, ic04 ARGB) against icns2png's / the written pixels;
|
||||
-- our RLE file read back by icns2png; PNG entries through encodeImage; errors; the fuzz no-throw pass. Fixtures:
|
||||
-- tools/fixtures/icns.py.
|
||||
-- image/icns tests against libicns' icns2png and Pillow (tools/fixtures/icns.py).
|
||||
local T = require("@tests/T")
|
||||
local Icns = require("@rosetta/image/icns")
|
||||
local Png = require("@rosetta/image/png")
|
||||
@@ -55,7 +52,6 @@ end
|
||||
t:note("%d files and our encoder's file match", #Fx.cases)
|
||||
|
||||
do
|
||||
-- PNG entries through the hooks, legacy entries without them
|
||||
local img = Types.Image.new(64, 64)
|
||||
for i = 0, 64 * 64 - 1 do
|
||||
buffer.writeu32(img.pixels, i * 4, i * 2654435761 % 4294967296)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/ico tests: ImageMagick- and Pillow-written icons (PNG and BMP entries, a 256 PNG entry) and hand-built ones
|
||||
-- (1 / 4 / 8 / 24 / 32-bit DIBs with AND masks, a cursor with hotspots) against Pillow's decode of every entry; PNG
|
||||
-- entries through opts.decodeImage (and UNSUPPORTED without it); the main image is the largest entry; our encoder
|
||||
-- (DIB, PNG through opts.encodeImage, cursors) round-trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/ico.py.
|
||||
-- image/ico tests against Pillow's decode of every entry (tools/fixtures/ico.py).
|
||||
local T = require("@tests/T")
|
||||
local Ico = require("@rosetta/image/ico")
|
||||
local Png = require("@rosetta/image/png")
|
||||
@@ -47,7 +44,6 @@ for _, c in Fx do
|
||||
entries += 1
|
||||
end
|
||||
t:eq(img.width * img.height, biggest, c.name .. ": the main image is the largest entry")
|
||||
-- round trip through our encoder (DIB entries, and PNG for 256 through the hook)
|
||||
local enc, eerr = Ico.encode(img, hooks)
|
||||
t:check(enc, c.name .. ": encode: " .. tostring(eerr))
|
||||
local back = dec(enc, hooks)
|
||||
@@ -90,7 +86,6 @@ do
|
||||
t:eq(buffer.readu16(cenc, 2), 2, "cursor written as CUR")
|
||||
local cb = dec(cenc)
|
||||
t:check(cb.meta.hotspot.x == 3 and cb.frames[2].image.meta.hotspot.y == 6, "hotspots round-trip")
|
||||
-- PNG entries on request
|
||||
local small = Types.Image.new(16, 16)
|
||||
buffer.fill(small.pixels, 0, 200, 16 * 16 * 4)
|
||||
local pe = Ico.encode(small, { png = true, encodeImage = hooks.encodeImage }) :: buffer
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/ilbm tests: files from netpbm's ppmtoilbm (palette, uncompressed, HAM6, HAM8, 24-bit) and hand-written ones
|
||||
-- (EHB, chunky PBM, a mask plane, a transparent colour) against ilbmtoppm (colours) and the written masks (alpha); our
|
||||
-- encoder's files read by ilbmtoppm; round trips (palette, 24 and 32 planes, uncompressed); errors; the fuzz no-throw
|
||||
-- pass. Fixtures: tools/fixtures/ilbm.py.
|
||||
-- image/ilbm tests against netpbm's ilbmtoppm (tools/fixtures/ilbm.py).
|
||||
local T = require("@tests/T")
|
||||
local Ilbm = require("@rosetta/image/ilbm")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
+2
-12
@@ -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
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
-- image/ktx tests: KTX2 files from KTX-Software (`ktx create` from PNGs and raw data in uncompressed / packed / float /
|
||||
-- BCn / ETC2 / EAC formats, mips, cube maps, arrays, 3D, Zstandard and ZLIB supercompression; Basis Universal is
|
||||
-- UNSUPPORTED) and KTX1 files from toktx / nvcompress / hand-written ones (big-endian, packed types, row padding,
|
||||
-- KTXorientation) against their sources or reference decodes; our KTX2 files through `ktx validate` / `ktx extract`;
|
||||
-- round trips; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/ktx.py.
|
||||
-- image/ktx tests against KTX-Software (ktx create / validate / extract), toktx and nvcompress (tools/fixtures/ktx.py).
|
||||
local T = require("@tests/T")
|
||||
local Ktx = require("@rosetta/image/ktx")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -119,7 +115,6 @@ for _, o in Fx.ours do
|
||||
end
|
||||
t:note("%d of our files pass ktx validate", #Fx.ours)
|
||||
|
||||
-- round trips
|
||||
do
|
||||
local img = Types.Image.new(37, 23)
|
||||
img.pixels = src
|
||||
@@ -139,7 +134,6 @@ do
|
||||
t:check(e2 and e2.code == Err.ARG, "zlib level")
|
||||
end
|
||||
|
||||
-- sniff, info, errors
|
||||
do
|
||||
local c = Fx.cases[1]
|
||||
t:eq(Ktx.sniff(Bytes.reader(buffer.fromstring(c.data))), 1, "sniff KTX2")
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/pcx tests: files from netpbm (24-bit, 8-bit, packed 2 / 4-bit, 3 / 4 planes, mono), ImageMagick and Pillow
|
||||
-- against pcxtoppm's decode; our files read by ImageMagick; round trips (palette, 24-bit, 32-bit alpha); errors; the
|
||||
-- fuzz no-throw pass. Fixtures: tools/fixtures/pcx.py.
|
||||
-- image/pcx tests against netpbm's pcxtoppm and ImageMagick (tools/fixtures/pcx.py).
|
||||
local T = require("@tests/T")
|
||||
local Pcx = require("@rosetta/image/pcx")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
+1
-11
@@ -1,7 +1,4 @@
|
||||
-- image/png tests: the whole PngSuite against reference decodes (pypng: tools/fixtures/_png_reference.py), the corrupt
|
||||
-- x* files rejected (with checkCrc), generated images of every colour type / depth / interlace / filter, the encoder
|
||||
-- (round trips for every colour type it picks, levels, text), the contract, and the fuzz no-throw pass.
|
||||
-- Ported from png-luau tests/png.luau. Fixtures: tools/fixtures/png.py.
|
||||
-- image/png tests: the PngSuite against pypng (tools/fixtures/_png_reference.py). Fixtures: tools/fixtures/png.py.
|
||||
local T = require("@tests/T")
|
||||
local Png = require("@rosetta/image/png")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -18,7 +15,6 @@ local function decode(data: any, opts: any?): (any, any)
|
||||
return Png.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
|
||||
-- the contract
|
||||
t:eq(Png.name, "png", "name")
|
||||
t:eq(Png.category, "image", "category")
|
||||
t:check(table.find(Png.extensions, "png") ~= nil, "extensions")
|
||||
@@ -32,7 +28,6 @@ local function verify(c: any, label: string)
|
||||
t:eq(buffer.len(img.pixels), c.width * c.height * 4, label .. ": pixel buffer size")
|
||||
local crc = Crc32.of(img.pixels)
|
||||
t:check(crc == c.crc, string.format("%s: pixels crc %08x, expected %08x", label, crc, c.crc))
|
||||
-- without the CRC check too, and at an offset inside a bigger buffer (the Reader's range)
|
||||
local img2 = decode(c.data)
|
||||
t:check(img2 and Crc32.of(img2.pixels) == c.crc, label .. ": no-CRC decode")
|
||||
local big = buffer.create(#c.data + 10)
|
||||
@@ -59,7 +54,6 @@ for _, c in Gen do
|
||||
end
|
||||
t:note("%d generated images match", #Gen)
|
||||
|
||||
-- sniff, info, palette, meta, limits
|
||||
do
|
||||
local c
|
||||
for _, s in Suite do
|
||||
@@ -83,7 +77,6 @@ do
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "junk: " .. tostring(e2))
|
||||
end
|
||||
|
||||
-- the encoder: round trips, colour type choice, levels, text
|
||||
do
|
||||
local rand = T.rng(99)
|
||||
local function image(w: number, h: number, kind: string): Types.Image
|
||||
@@ -120,20 +113,17 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
-- forced colour type, text chunks
|
||||
local img = image(16, 16, "rgba")
|
||||
img.meta.text = { Comment = "hello", Software = "rosetta" }
|
||||
local png = Png.encode(img, { colorType = "rgba" }) :: buffer
|
||||
local back = Png.decode(Bytes.reader(png))
|
||||
t:check(back.meta.text and back.meta.text.Comment == "hello" and back.meta.text.Software == "rosetta", "tEXt round trip")
|
||||
-- the photo bench image compresses
|
||||
local _, e = Png.encode({} :: any)
|
||||
t:check(e and e.code == Err.ARG, "encode of a non-image returns Err.ARG")
|
||||
local _, e2 = Png.encode(img, { colorType = "cmyk" } :: any)
|
||||
t:check(e2 and e2.code == Err.ARG, "unknown colorType returns Err.ARG")
|
||||
end
|
||||
|
||||
-- fuzz: truncations, mutations (also of the IHDR fields) and garbage never throw
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Suite do
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/pnm tests: ImageMagick-written P1-P7 / PFM files (ASCII and binary, 8 / 16-bit, PAM tuple types, both PFM
|
||||
-- byte orders) and hand-written edge cases (comments, packed P1 digits, odd maxvals) against ImageMagick's RGBA
|
||||
-- decodes (8-bit; 16-bit and float natively); round trips of every subtype through our encoder, binary and ASCII;
|
||||
-- errors; the fuzz no-throw pass. Fixtures: tools/fixtures/pnm.py.
|
||||
-- image/pnm tests against ImageMagick's decodes (tools/fixtures/pnm.py).
|
||||
local T = require("@tests/T")
|
||||
local Pnm = require("@rosetta/image/pnm")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -18,7 +15,6 @@ local function dec(data: any, opts: any?): (any, any)
|
||||
return Pnm.decode(Bytes.reader(if type(data) == "string" then buffer.fromstring(data) else data), opts)
|
||||
end
|
||||
|
||||
-- channel c (0..3) of pixel i of a native image, in 16-bit scale
|
||||
local function chan16(img: any, i: number, c: number): number
|
||||
local px, f = img.pixels, img.format
|
||||
if f == "gray16" then
|
||||
@@ -65,7 +61,6 @@ for _, c in Fx do
|
||||
end
|
||||
t:check(fw < 1e-6, c.name .. ": floats")
|
||||
end
|
||||
-- round trips through our encoder: the same subtype, binary and ASCII
|
||||
local ext = string.match(c.name, "%.(%a+)$")
|
||||
for _, ascii in { false, true } do
|
||||
local enc, eerr = Pnm.encode(nat, { format = ext, ascii = ascii })
|
||||
@@ -76,7 +71,6 @@ for _, c in Fx do
|
||||
end
|
||||
t:note("%d files match ImageMagick and round-trip", #Fx)
|
||||
|
||||
-- encoder choices, conversions, options
|
||||
do
|
||||
local img = Types.Image.new(3, 2)
|
||||
for i = 0, 23 do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/qoi tests: Pillow-written QOI files (RGB / RGBA, noise / gradients / runs / small deltas, 1x1 to 500x1)
|
||||
-- decode to Pillow's pixels; our encoder writes the same bytes as Pillow for the same pixels and round-trips exactly;
|
||||
-- native rgb8 output, the colour space tag, errors, and the fuzz no-throw pass. Fixtures: tools/fixtures/qoi.py.
|
||||
-- image/qoi tests: decodes and encoder bytes against Pillow (tools/fixtures/qoi.py).
|
||||
local T = require("@tests/T")
|
||||
local Qoi = require("@rosetta/image/qoi")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -20,7 +18,6 @@ for _, c in Fx do
|
||||
t:check(img, c.name .. ": " .. tostring(err))
|
||||
t:check(img.width == c.width and img.height == c.height and img.format == "rgba8", c.name .. ": size")
|
||||
t:eq(Crc32.of(img.pixels), c.crc, c.name .. ": pixels against Pillow")
|
||||
-- encode the source pixels: the same bytes as Pillow's writer
|
||||
local src = Types.Image.new(c.width, c.height, if c.channels == 4 then "rgba8" else "rgb8")
|
||||
src.pixels = buffer.fromstring(c.pixels)
|
||||
local enc = Qoi.encode(src, { channels = c.channels, linear = string.byte(c.data, 14) == 1 }) :: buffer -- Pillow tags its files linear
|
||||
@@ -29,7 +26,6 @@ for _, c in Fx do
|
||||
end
|
||||
local back = Qoi.decode(Bytes.reader(enc))
|
||||
t:eq(Crc32.of(back.pixels), c.crc, c.name .. ": our encoding round-trips")
|
||||
-- native rgb8
|
||||
if c.channels == 3 then
|
||||
local n = Qoi.decode(Bytes.reader(buffer.fromstring(c.data)), { native = true })
|
||||
t:check(n.format == "rgb8" and buffer.tostring(n.pixels) == c.pixels, c.name .. ": native rgb8")
|
||||
@@ -38,7 +34,6 @@ end
|
||||
t:eq(same, #Fx, "byte-identical to Pillow's encoder")
|
||||
t:note("%d Pillow files decode; %d of our encodings are byte-identical to Pillow's", #Fx, same)
|
||||
|
||||
-- round trips of random images, a sub-range reader, colour space, errors
|
||||
do
|
||||
local rand = T.rng(5)
|
||||
for _, s in { { 1, 1 }, { 70, 3 }, { 33, 33 } } do
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- image/sgi tests: files from netpbm / ImageMagick / Pillow against ImageMagick's decode, our encoder's files read
|
||||
-- by ImageMagick, round trips through every option, errors, the fuzz no-throw pass. Fixtures: tools/fixtures/sgi.py.
|
||||
-- image/sgi tests against ImageMagick (tools/fixtures/sgi.py).
|
||||
local T = require("@tests/T")
|
||||
local Sgi = require("@rosetta/image/sgi")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- image/sunras tests: files from netpbm / ImageMagick against ImageMagick's decode, our encoder's files read
|
||||
-- by rasttopnm, round trips through every option, errors, the fuzz no-throw pass. Fixtures: tools/fixtures/sunras.py.
|
||||
-- image/sunras tests against ImageMagick and rasttopnm (tools/fixtures/sunras.py).
|
||||
local T = require("@tests/T")
|
||||
local Sunras = require("@rosetta/image/sunras")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/tga tests: Pillow- and ImageMagick-written TGAs (RGB / RGBA / grey / grey + alpha / palette, raw and RLE, both
|
||||
-- origins) and hand-written ones (15 / 16-bit pixels and colour maps, first index, right-to-left, RLE across rows, an
|
||||
-- image ID) against the reference RGBA decodes; our encoder (raw / RLE, origins, 24 / 32-bit / grey) round-trips;
|
||||
-- sniffing stays low without a footer; errors; the fuzz no-throw pass. Fixtures: tools/fixtures/tga.py.
|
||||
-- image/tga tests against Pillow's and ImageMagick's decodes (tools/fixtures/tga.py).
|
||||
local T = require("@tests/T")
|
||||
local Tga = require("@rosetta/image/tga")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -31,7 +28,6 @@ for _, c in Fx do
|
||||
end
|
||||
t:check(worst == 0, string.format("%s: differs from the reference by %d at byte %d", c.name, worst, at))
|
||||
t:check(not img.meta.truncated, c.name .. ": not truncated")
|
||||
-- round trips through our encoder
|
||||
for _, rle in { false, true } do
|
||||
for _, origin in { "bottom-left", "top-left" } do
|
||||
local enc = Tga.encode(img, { rle = rle, origin = origin }) :: buffer
|
||||
@@ -61,7 +57,6 @@ do
|
||||
t:eq(Tga.sniff(Bytes.reader(Tga.encode(p) :: buffer)), 0.9, "sniff with the footer")
|
||||
t:eq(Tga.sniff(Bytes.reader(buffer.fromstring("\0\0\1\0\1\0\16\16\0\0\1\0\32\0\0\0\0\0\0\0\0\0"))), 0, "an ICO header is not a TGA")
|
||||
t:eq(Tga.sniff(Bytes.reader(buffer.fromstring("\137PNG\r\n\26\n\0\0\0\13IHDR\0\0\0\0\0\0"))), 0, "a PNG is not a TGA")
|
||||
-- encoder choices
|
||||
local img = Types.Image.new(3, 2)
|
||||
buffer.fill(img.pixels, 0, 255, 24)
|
||||
t:eq(buffer.readu8(Tga.encode(img) :: buffer, 16), 24, "opaque rgba8 -> 24-bit")
|
||||
|
||||
+1
-12
@@ -1,7 +1,4 @@
|
||||
-- image/tiff tests: files written by tifffile / imagecodecs and ImageMagick (every compression, predictors, strips and
|
||||
-- tiles, planar, both byte orders, BigTIFF, 1..32-bit integer and 16 / 32 / 64-bit float samples, palette, CMYK,
|
||||
-- alpha, multi-page) against tifffile's decode, in rgba8 and native layouts; the JPEG hook; encoder round trips for
|
||||
-- every layout and compression; errors; the fuzz pass. Fixtures: tools/fixtures/tiff.py.
|
||||
-- image/tiff tests against tifffile's decode (tools/fixtures/tiff.py).
|
||||
local T = require("@tests/T")
|
||||
local Tiff = require("@rosetta/image/tiff")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -17,14 +14,12 @@ local function decode(data: any, opts: any?): (any, any)
|
||||
return Tiff.decode(Bytes.reader(b), opts)
|
||||
end
|
||||
|
||||
-- contract
|
||||
t:eq(Tiff.name, "tiff", "name")
|
||||
t:check(Tiff.caps.decode and Tiff.caps.encode, "caps")
|
||||
t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("II*\0\8\0\0\0"))), 1, "sniff II")
|
||||
t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("MM\0*"))), 1, "sniff MM")
|
||||
t:eq(Tiff.sniff(Bytes.reader(buffer.fromstring("\137PNG"))), 0, "sniff png")
|
||||
|
||||
-- reference files
|
||||
local pagesChecked = 0
|
||||
for _, c in Fx.cases do
|
||||
local img, err = decode(c.data)
|
||||
@@ -43,7 +38,6 @@ for _, c in Fx.cases do
|
||||
t:check(ncrc == p.ncrc, string.format("%s page %d: native crc %08x, want %08x", c.name, i, ncrc, p.ncrc))
|
||||
pagesChecked += 1
|
||||
end
|
||||
-- inside a bigger buffer
|
||||
local big = buffer.create(#c.data + 9)
|
||||
buffer.writestring(big, 5, c.data)
|
||||
local img3 = Tiff.decode(Bytes.reader(big, 5, #c.data))
|
||||
@@ -51,7 +45,6 @@ for _, c in Fx.cases do
|
||||
end
|
||||
t:note("%d files, %d pages match tifffile", #Fx.cases, pagesChecked)
|
||||
|
||||
-- info, single page, meta
|
||||
do
|
||||
local multi
|
||||
for _, c in Fx.cases do
|
||||
@@ -104,7 +97,6 @@ do
|
||||
t:note("JPEG-in-TIFF through F.load: max error %d against tifffile / libjpeg-turbo", worst)
|
||||
end
|
||||
|
||||
-- encoder round trips
|
||||
do
|
||||
local rand = T.rng(11)
|
||||
local function image(fmt: string, w: number, h: number): Types.Image
|
||||
@@ -141,7 +133,6 @@ do
|
||||
end
|
||||
end
|
||||
t:note("%d encoder round trips", trips)
|
||||
-- multi-page
|
||||
local a, b = image("rgb8", 20, 10), image("gray16", 7, 9)
|
||||
local anim = image("rgb8", 20, 10)
|
||||
anim.frames = { { image = a, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" }, { image = b, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" } } :: any
|
||||
@@ -158,7 +149,6 @@ do
|
||||
t:check(e3 and e3.code == Err.ARG, "unsupported layout")
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e = decode("II*\0\255\255\0\0")
|
||||
t:check(e and (e.code == Err.TRUNCATED or e.code == Err.CORRUPT), "bad IFD offset")
|
||||
@@ -166,7 +156,6 @@ do
|
||||
t:check(e2 and e2.code == Err.TRUNCATED or e2.code == Err.CORRUPT, "junk")
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
do
|
||||
local samples = {}
|
||||
for i, c in Fx.cases do
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/tim tests: PlayStation TIM files written by tools/fixtures/tim.py (4 / 8-bit CLUT, 15-bit, 24-bit) decode to
|
||||
-- ImageMagick's RGB, colour 0x0000 is transparent, CLUT rows, the VRAM position; the encoder round-trips 16 / 24 /
|
||||
-- 8 / 4-bit; errors; the fuzz pass.
|
||||
-- image/tim tests against ImageMagick (tools/fixtures/tim.py).
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Tim = require("@rosetta/image/tim")
|
||||
@@ -42,8 +40,7 @@ for _, c in Fx do
|
||||
local other = Tim.decode(Bytes.reader(buffer.fromstring(c.data)), { clut = 1 }) :: any
|
||||
t:check(Crc32.of(other.pixels) ~= Crc32.of(img.pixels) and other.meta.source.clut.row == 1, c.name .. ": second CLUT row")
|
||||
end
|
||||
-- round trips: decoded 4 / 8 / 15-bit pixels are PSX colours, so every depth that fits is lossless (24-bit only
|
||||
-- round-trips as 24-bit)
|
||||
-- decoded 4 / 8 / 15-bit pixels are PSX colours, so every depth that fits is lossless (24-bit only as 24-bit)
|
||||
for _, bpp in (if c.bpp == 24 then { 24 } else { 16, 24, 8, 4 }) do
|
||||
local enc, eerr = Tim.encode(img, { bpp = bpp })
|
||||
if bpp == 24 then
|
||||
@@ -68,9 +65,9 @@ end
|
||||
|
||||
do
|
||||
local img = Types.Image.new(3, 1)
|
||||
buffer.writeu32(img.pixels, 0, 0xFF000000) -- opaque black
|
||||
buffer.writeu32(img.pixels, 4, 0x00FFFFFF) -- transparent
|
||||
buffer.writeu32(img.pixels, 8, 0xFF0000FF) -- red
|
||||
buffer.writeu32(img.pixels, 0, 0xFF000000)
|
||||
buffer.writeu32(img.pixels, 4, 0x00FFFFFF)
|
||||
buffer.writeu32(img.pixels, 8, 0xFF0000FF)
|
||||
local back = Tim.decode(Bytes.reader(Tim.encode(img) :: buffer)) :: any
|
||||
t:eq(buffer.readu32(back.pixels, 0), 0xFF000000, "opaque black stays opaque (STP)")
|
||||
t:eq(buffer.readu32(back.pixels, 4), 0, "transparent")
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
-- image/vtf tests: VTFs written by srctools (tools/fixtures/vtf.py: every texel format it writes, versions 7.2 / 7.4
|
||||
-- / 7.5, mips, two-frame animations) decode to srctools' own RGBA (DXT within its libsquish rounding), frames, the
|
||||
-- mip / thumbnail layout; the half / float / 16-bit formats srctools cannot write against the fixture writer; errors;
|
||||
-- the fuzz pass.
|
||||
-- image/vtf tests against srctools (DXT within its libsquish rounding) and the fixture writer (tools/fixtures/vtf.py).
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Vtf = require("@rosetta/image/vtf")
|
||||
|
||||
+1
-15
@@ -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
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/xbm tests: files from netpbm / ImageMagick / Pillow and hand-written ones against the reference decode
|
||||
-- (xbmtopbm), our encoder's files read back by it, round trips, errors, the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/xbm.py.
|
||||
-- image/xbm tests against xbmtopbm (tools/fixtures/xbm.py).
|
||||
local T = require("@tests/T")
|
||||
local Xbm = require("@rosetta/image/xbm")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
-- image/xpm tests: files from netpbm / ImageMagick and hand-written ones against the reference decode
|
||||
-- (ImageMagick), our encoder's files read back by it, round trips, errors, the fuzz no-throw pass.
|
||||
-- Fixtures: tools/fixtures/xpm.py.
|
||||
-- image/xpm tests against ImageMagick (tools/fixtures/xpm.py).
|
||||
local T = require("@tests/T")
|
||||
local Xpm = require("@rosetta/image/xpm")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
@@ -29,7 +27,6 @@ do
|
||||
t:eq(Xpm.sniff(Bytes.reader(buffer.fromstring("/* XPM */\n"))), 1, "sniff")
|
||||
local _, e = Xpm.decode(Bytes.reader(buffer.fromstring('/* XPM */ static char *x[] = {"2 1 5 1", "a c red"};')))
|
||||
t:check(e and e.code == Err.TRUNCATED, "short colour table")
|
||||
-- many colours: two chars per pixel
|
||||
local big = R.image(300, 1, "")
|
||||
big.pixels = buffer.create(1200)
|
||||
for i = 0, 299 do
|
||||
|
||||
Reference in new issue
Block a user