archive/wad2, image/lmp, image/spr, data/q3shader, data/q3skin
WAD2 / WAD3 with miptex / qpic / conchars / font / palette images and addImage; Quake .lmp pictures, palette and colormap (palette never embedded); Quake / Half-Life / SPR32 sprites with frame groups; Quake III shader scripts and .skin files. Miptex gains qpic decode / encode and palette mapping; Pixels.keyed keeps the key colour (alpha 0).
This commit is contained in:
1 parent
67e116a6c6
commit
175ca9e823
23 files changed
+5380
-1143
No files matched your search
@@ -0,0 +1,48 @@
|
||||
-- image/lmp tests: qpic pictures, palette.lmp and colormap.lmp against Pillow (tools/fixtures/lmp.py), the palette
|
||||
-- through files, the grey fallback, the qpic writer round trip, errors, the fuzz pass.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Lmp = require("@rosetta/image/lmp")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Fx = require("@tests/gen/lmp")
|
||||
|
||||
local t = T.suite("lmp")
|
||||
t:eq(Lmp.name, "lmp", "name")
|
||||
|
||||
local samples = {}
|
||||
for _, p in Fx.pics do
|
||||
local img, err = Lmp.decode(Bytes.reader(buffer.fromstring(p.data)), { palette = Fx.palette })
|
||||
t:check(img, p.name .. ": " .. tostring(err))
|
||||
t:eq(img.width .. "x" .. img.height, p.w .. "x" .. p.h, p.name .. ": size")
|
||||
t:eq(Crc32.of(img.pixels), p.crc, p.name .. ": pixels = Pillow (index 255 transparent)")
|
||||
local opaque = assert(Lmp.decode(Bytes.reader(buffer.fromstring(p.data)), { files = { ["gfx/palette.lmp"] = Fx.palette }, keyed = false }))
|
||||
t:eq(Crc32.of(opaque.pixels), p.crcOpaque, p.name .. ": opaque, palette through files")
|
||||
t:eq(opaque.meta.source.palette, true, p.name .. ": palette found")
|
||||
-- write back: the palette colours map to the same indices
|
||||
local out = assert(Lmp.encode(img, { palette = Fx.palette }))
|
||||
t:check(buffer.tostring(out) == p.data, p.name .. ": writer gives the same bytes")
|
||||
table.insert(samples, p.data)
|
||||
end
|
||||
do
|
||||
local p = Fx.pics[2]
|
||||
t:eq(F.detect(p.data, { name = "conback.lmp" }), "lmp", "F.detect by size + extension")
|
||||
local grey = assert(Lmp.decode(Bytes.reader(buffer.fromstring(p.data))))
|
||||
t:eq(grey.meta.source.palette, false, "no palette: grey")
|
||||
local cm = assert(Lmp.decode(Bytes.reader(buffer.fromstring(Fx.colormap.data)), { palette = Fx.palette }))
|
||||
t:eq(cm.width .. "x" .. cm.height, "256x64", "colormap size")
|
||||
t:eq(Crc32.of(cm.pixels), Fx.colormap.crc, "colormap = Pillow")
|
||||
local pal = assert(Lmp.decode(Bytes.reader(buffer.fromstring(Fx.palette))))
|
||||
t:eq(Crc32.of(pal.pixels), Fx.palcrc, "palette.lmp swatch = Pillow")
|
||||
t:eq(#pal.meta.palette, 256, "palette entries")
|
||||
t:check(buffer.tostring(assert(Lmp.encode(pal, { kind = "palette" }))) == Fx.palette, "palette round trip")
|
||||
local _, e1 = Lmp.encode(grey)
|
||||
t:check(e1 and e1.code == Err.ARG, "qpic writer needs the palette")
|
||||
local _, e2 = Lmp.decode(Bytes.reader(buffer.fromstring(string.sub(p.data, 1, 30))), { kind = "qpic" })
|
||||
t:check(e2 and e2.code == Err.CORRUPT or e2 and e2.code == Err.TRUNCATED, "truncated qpic: " .. tostring(e2))
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Lmp.decode(Bytes.reader(b), { palette = Fx.palette, kind = "qpic" })
|
||||
end, samples)
|
||||
t:done()
|
||||
@@ -0,0 +1,67 @@
|
||||
-- image/spr tests: Quake / Half-Life (alpha test, index alpha, normal) / SPR32 sprites against the frames written by
|
||||
-- tools/fixtures/spr.py (pixels, canvas positions from the origins, group delays), the writer round trips (versions 1,
|
||||
-- 2 and 32), errors, the fuzz pass.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Spr = require("@rosetta/image/spr")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Fx = require("@tests/gen/spr")
|
||||
|
||||
local t = T.suite("spr")
|
||||
t:eq(Spr.name, "spr", "name")
|
||||
|
||||
local samples = {}
|
||||
for _, s in Fx.sprites do
|
||||
t:eq(F.detect(s.data), "spr", s.name .. ": F.detect")
|
||||
local img, err = Spr.decode(Bytes.reader(buffer.fromstring(s.data)), { palette = Fx.palette })
|
||||
t:check(img, s.name .. ": " .. tostring(err))
|
||||
t:eq(img.width .. "x" .. img.height, s.w .. "x" .. s.h, s.name .. ": canvas")
|
||||
t:eq(img.meta.origin[1] .. " " .. img.meta.origin[2], s.origin[1] .. " " .. s.origin[2], s.name .. ": origin")
|
||||
local frames = img.frames or { { image = img, x = 0, y = 0, delay = 0.1 } }
|
||||
t:eq(#frames, #s.frames, s.name .. ": frames")
|
||||
for i, want in s.frames do
|
||||
local f = frames[i]
|
||||
t:eq(f.x .. "," .. f.y .. " " .. f.image.width .. "x" .. f.image.height, want.x .. "," .. want.y .. " " .. want.w .. "x" .. want.h, s.name .. ": frame " .. i .. " placement")
|
||||
t:eq(Crc32.of(f.image.pixels), want.crc, s.name .. ": frame " .. i .. " pixels")
|
||||
t:check(math.abs(f.delay - want.delay) < 1e-6, s.name .. ": frame " .. i .. " delay")
|
||||
end
|
||||
t:eq(img.meta.source.version, s.version, s.name .. ": version")
|
||||
-- write in the same version and read back the same frames
|
||||
local out, eerr = Spr.encode(img, { version = s.version, palette = if s.version == 2 then Fx.hlpalette else Fx.palette, texFormat = s.tex })
|
||||
t:check(out, s.name .. ": encode " .. tostring(eerr))
|
||||
local back = assert(Spr.decode(Bytes.reader(out :: buffer), { palette = Fx.palette }))
|
||||
local bf = back.frames or { { image = back, x = 0, y = 0 } }
|
||||
local same = #bf == #frames
|
||||
for i, f in frames do
|
||||
local g = bf[i]
|
||||
same = same and g and g.x == f.x and g.y == f.y
|
||||
if s.version == 32 or s.version == 1 or s.tex == 0 or s.tex == 3 then
|
||||
same = same and Crc32.of(g.image.pixels) == Crc32.of(f.image.pixels)
|
||||
end
|
||||
end
|
||||
t:check(same, s.name .. ": round trip keeps frames, placement and pixels")
|
||||
table.insert(samples, s.data)
|
||||
end
|
||||
do
|
||||
local q = Fx.sprites[1]
|
||||
local img = assert(Spr.decode(Bytes.reader(buffer.fromstring(q.data)), { palette = Fx.palette }))
|
||||
-- Half-Life from a Quake sprite: a made palette
|
||||
local hl = assert(Spr.encode(img))
|
||||
local back = assert(Spr.decode(Bytes.reader(hl)))
|
||||
t:eq(back.meta.source.version, 2, "default version 2")
|
||||
t:eq(back.meta.source.texFormat, "alphatest", "transparent pixels: alpha test")
|
||||
local grey = assert(Spr.decode(Bytes.reader(buffer.fromstring(q.data))))
|
||||
t:eq(grey.meta.source.palette, false, "Quake sprite without a palette: grey")
|
||||
local _, e1 = Spr.encode(img, { version = 1 })
|
||||
t:check(e1 and e1.code == Err.ARG, "version 1 needs a palette")
|
||||
local _, e2 = Spr.decode(Bytes.reader(buffer.fromstring("IDS2" .. string.rep("\0", 40))))
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "Quake II sprite: not IDSP")
|
||||
local _, e3 = Spr.decode(Bytes.reader(buffer.fromstring(string.sub(q.data, 1, 60))), { palette = Fx.palette })
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated: " .. tostring(e3))
|
||||
end
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Spr.decode(Bytes.reader(b), { palette = Fx.palette })
|
||||
end, samples)
|
||||
t:done()
|
||||
Reference in new issue
Block a user