ws-tex: image/pcx (read 1/2/4/8-bit, planes, palettes; write 8-bit palette / 24 / 32-bit RLE)
Tested against netpbm ppmtopcx / ImageMagick / Pillow files decoded by pcxtoppm; our files read by ImageMagick. Shared test helper tests/image/_raster.luau and fixture helper tools/fixtures/_raster_ref.py.
This commit is contained in:
1 parent
abd01270f0
commit
d294c211f9
8 files changed
+614
No files matched your search
@@ -0,0 +1,39 @@
|
||||
-- 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.
|
||||
local T = require("@tests/T")
|
||||
local Pcx = require("@formats/image/pcx")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local R = require("@tests/image/_raster")
|
||||
local Fx = require("@tests/gen/pcx")
|
||||
|
||||
local t = T.suite("pcx")
|
||||
t:eq(Pcx.name, "pcx", "name")
|
||||
t:check(Pcx.caps.decode and Pcx.caps.encode, "caps")
|
||||
|
||||
t:note("%d files match pcxtoppm", R.decodes(t, Pcx, Fx.cases))
|
||||
-- our files: ImageMagick reads what we decode
|
||||
for _, o in Fx.ours do
|
||||
local img = Pcx.decode(Bytes.reader(buffer.fromstring(o.data))) :: any
|
||||
t:eq(R.maxDiff(img.pixels, buffer.fromstring(o.rgba), o.w * o.h), 0, o.name .. ": ImageMagick reads our file")
|
||||
end
|
||||
for _, c in Fx.cases do
|
||||
R.roundTrip(t, Pcx, R.image(c.w, c.h, c.rgba), nil, c.name .. " re-encoded")
|
||||
R.roundTrip(t, Pcx, R.image(c.w, c.h, c.rgba), { palette = false }, c.name .. " re-encoded 24-bit")
|
||||
end
|
||||
do
|
||||
local img = R.image(3, 2, string.rep("\1\2\3\128", 6))
|
||||
local enc = R.roundTrip(t, Pcx, img, nil, "alpha: 4 planes") :: buffer
|
||||
t:eq(buffer.readu8(enc, 65), 4, "alpha -> 4 planes")
|
||||
t:eq(Pcx.sniff(Bytes.reader(enc)), 0.8, "sniff")
|
||||
t:eq(Pcx.sniff(Bytes.reader(buffer.fromstring("GIF89a"))), 0, "sniff other")
|
||||
local _, e = Pcx.decode(Bytes.reader(buffer.fromstring(string.sub(buffer.tostring(enc), 1, 60))))
|
||||
t:check(e and e.code == Err.TRUNCATED, "short header")
|
||||
local _, e2 = Pcx.decode(Bytes.reader(enc), { maxPixels = 2 })
|
||||
t:check(e2 and e2.code == Err.LIMIT, "limit")
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Pcx.decode(Bytes.reader(b))
|
||||
end, R.samples(Fx.cases), { mutations = 6 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user