35 lines
1.6 KiB
Luau
35 lines
1.6 KiB
Luau
-- 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.
|
|
local T = require("@tests/T")
|
|
local Sgi = require("@rosetta/image/sgi")
|
|
local Bytes = require("@rosetta/core/Bytes")
|
|
local Err = require("@rosetta/core/Err")
|
|
local R = require("@tests/image/_raster")
|
|
local Fx = require("@tests/gen/sgi")
|
|
|
|
local t = T.suite("sgi")
|
|
t:eq(Sgi.name, "sgi", "name")
|
|
t:check(Sgi.caps.decode and Sgi.caps.encode, "caps")
|
|
|
|
t:note("%d files match ImageMagick", R.decodes(t, Sgi, Fx.cases))
|
|
t:note("%d of our files read by ImageMagick", R.decodes(t, Sgi, Fx.ours))
|
|
for _, c in Fx.cases do
|
|
R.roundTrip(t, Sgi, R.image(c.w, c.h, c.rgba), nil, c.name .. " re-encoded")
|
|
R.roundTrip(t, Sgi, R.image(c.w, c.h, c.rgba), { rle = false }, c.name .. " re-encoded without RLE")
|
|
end
|
|
do
|
|
local enc = Sgi.encode(R.image(2, 2, string.rep("\1\2\3\4", 4))) :: buffer
|
|
t:eq(Sgi.sniff(Bytes.reader(enc)), 1, "sniff")
|
|
t:eq(Sgi.sniff(Bytes.reader(buffer.fromstring("GIF89a"))), 0, "sniff other")
|
|
local _, e = Sgi.decode(Bytes.reader(buffer.fromstring(string.sub(buffer.tostring(enc), 1, 20))))
|
|
t:check(e and e.code == Err.TRUNCATED, "short header")
|
|
local _, e2 = Sgi.decode(Bytes.reader(enc), { maxPixels = 2 })
|
|
t:check(e2 and e2.code == Err.LIMIT, "limit")
|
|
local _, e3 = Sgi.encode({} :: any)
|
|
t:check(e3 and e3.code == Err.ARG, "bad image")
|
|
end
|
|
t:fuzz("decode", function(b: buffer)
|
|
return Sgi.decode(Bytes.reader(b))
|
|
end, R.samples(Fx.cases), { mutations = 6 })
|
|
t:done()
|