ws-tex: image/ilbm (IFF ILBM / PBM read: planar, EHB, HAM6/8, deep 24/32, masks; write palette / 24 / 32 planes)
Chunks through containers/Chunks, ByteRun1 through codecs/compress/PackBits. Tested against ppmtoilbm files and hand-written EHB / PBM / mask / transparent-colour files decoded by ilbmtoppm; our files read by ilbmtoppm.
This commit is contained in:
1 parent
ef460955d4
commit
ce4845ae13
6 files changed
+532
No files matched your search
@@ -0,0 +1,72 @@
|
||||
-- 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.
|
||||
local T = require("@tests/T")
|
||||
local Ilbm = require("@formats/image/ilbm")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local R = require("@tests/image/_raster")
|
||||
local Fx = require("@tests/gen/ilbm")
|
||||
|
||||
local t = T.suite("ilbm")
|
||||
t:eq(Ilbm.name, "ilbm", "name")
|
||||
t:check(Ilbm.caps.decode and Ilbm.caps.encode, "caps")
|
||||
|
||||
local function check(c: any)
|
||||
local img, err = Ilbm.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(img, c.name .. ": " .. tostring(err))
|
||||
t:check(img.width == c.w and img.height == c.h, c.name .. ": size")
|
||||
local ref = buffer.fromstring(c.rgba)
|
||||
local bad, badA = 0, 0
|
||||
for i = 0, c.w * c.h - 1 do
|
||||
local transparent = c.transparent and c.transparent[i + 1]
|
||||
local v = buffer.readu32(img.pixels, i * 4)
|
||||
if transparent then
|
||||
badA += if v == 0 then 0 else 1
|
||||
else
|
||||
for k = 0, 3 do
|
||||
if math.abs(buffer.readu8(img.pixels, i * 4 + k) - buffer.readu8(ref, i * 4 + k)) > (c.tol or 0) then
|
||||
bad += 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(bad, 0, c.name .. ": colours against ilbmtoppm")
|
||||
t:eq(badA, 0, c.name .. ": transparent pixels")
|
||||
return img
|
||||
end
|
||||
for _, c in Fx.cases do
|
||||
check(c)
|
||||
if not c.transparent and not c.tol then
|
||||
R.roundTrip(t, Ilbm, R.image(c.w, c.h, c.rgba), nil, c.name .. " re-encoded")
|
||||
R.roundTrip(t, Ilbm, R.image(c.w, c.h, c.rgba), { compress = false }, c.name .. " re-encoded uncompressed")
|
||||
end
|
||||
end
|
||||
for _, o in Fx.ours do
|
||||
check(o)
|
||||
end
|
||||
t:note("%d files and %d of ours match ilbmtoppm", #Fx.cases, #Fx.ours)
|
||||
do
|
||||
local img = R.image(3, 2, string.rep("\1\2\3\128", 6))
|
||||
local enc = R.roundTrip(t, Ilbm, img, nil, "alpha: 32 planes") :: buffer
|
||||
t:eq(Ilbm.sniff(Bytes.reader(enc)), 1, "sniff")
|
||||
t:eq(Ilbm.sniff(Bytes.reader(buffer.fromstring("FORM\0\0\0\4AIFF"))), 0, "sniff AIFF")
|
||||
local back = Ilbm.decode(Bytes.reader(enc)) :: any
|
||||
t:eq(back.meta.source.planes, 32, "32 planes")
|
||||
local _, e = Ilbm.decode(Bytes.reader(buffer.fromstring("FORM\0\0\0\4ILBM")))
|
||||
t:check(e and e.code == Err.CORRUPT, "no BMHD")
|
||||
local _, e2 = Ilbm.decode(Bytes.reader(enc), { maxPixels = 2 })
|
||||
t:check(e2 and e2.code == Err.LIMIT, "limit")
|
||||
for _, c in Fx.cases do
|
||||
if c.name == "hand_transparent.iff" then
|
||||
local im = Ilbm.decode(Bytes.reader(buffer.fromstring(c.data))) :: any
|
||||
t:eq(im.meta.text and im.meta.text.name, "tiny", "NAME chunk")
|
||||
end
|
||||
end
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Ilbm.decode(Bytes.reader(b))
|
||||
end, R.samples(Fx.cases), { mutations = 6 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user