video/fli: FLI / FLC / FLX animations (read)
Header (FLI 1/70 s, FLC ms, depths 8 / 15 / 16 / 24), frame chunks into containers/Demux, open() through the registry's flic decoder (codecs/video/Legacy/Flic); the ring frame is dropped unless opts.ringFrame. Fixtures encoded by tools/fixtures/fli.py (every chunk type) with ffmpeg's decode as the reference: bit-exact.
This commit is contained in:
1 parent
8e3873c9fb
commit
a1d2e7218c
5 files changed
+670
No files matched your search
@@ -0,0 +1,105 @@
|
||||
-- video/fli tests: FLI (COLOR_64, BRUN, LC, BLACK, COPY, PSTAMP, a ring frame), FLC (prefix chunk, COLOR_256, SS2 with
|
||||
-- line skips and the last-byte opcode, an empty frame), an odd-size FLC, and 15 / 16 / 24-bit FLCs (BRUN, DTA_BRUN,
|
||||
-- DELTA, DTA_LC, COPY, DTA_COPY, BLACK), all encoded by the fixture script: every frame equals ffmpeg's decode
|
||||
-- (CRC-32 of rgba), frame rates, the ring frame option, seeking, errors, the fuzz pass. Fixtures: tools/fixtures/fli.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Fli = require("@formats/video/fli")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Fx = require("@tests/gen/fli_cases")
|
||||
|
||||
local t = T.suite("fli")
|
||||
t:eq(Fli.name, "fli", "name")
|
||||
t:eq(Fli.category, "video", "category")
|
||||
|
||||
local function reader(s: string): Bytes.Reader
|
||||
return Bytes.reader(buffer.fromstring(s))
|
||||
end
|
||||
|
||||
for _, c in Fx do
|
||||
local label = c.name
|
||||
t:check(Fli.sniff(reader(c.data)) > 0, label .. ": sniff")
|
||||
t:eq(F.detect(buffer.fromstring(c.data)), "fli", label .. ": detect")
|
||||
local v, err = F.video.open(buffer.fromstring(c.data))
|
||||
t:check(v ~= nil, label .. ": open " .. tostring(err))
|
||||
if v then
|
||||
t:eq(v.codec, "flic", label .. ": codec")
|
||||
t:check(v.width == c.width and v.height == c.height, label .. ": size")
|
||||
t:check(math.abs(v.frameRate - c.rate) < 1e-9, label .. ": frame rate " .. v.frameRate)
|
||||
t:eq(v.track.bitsPerPixel, c.depth, label .. ": depth")
|
||||
local ring = v.demuxer.meta.ringFrame
|
||||
local want = if ring then #c.frames - 1 else #c.frames
|
||||
local n, bad = 0, 0
|
||||
while true do
|
||||
local f, ferr = v:nextFrame()
|
||||
if not f then
|
||||
t:check(ferr == nil, label .. ": " .. tostring(ferr))
|
||||
break
|
||||
end
|
||||
n += 1
|
||||
if f.image.format ~= "rgba8" or Crc32.of(f.image.pixels) ~= c.frames[n] then
|
||||
bad += 1
|
||||
end
|
||||
end
|
||||
t:check(n == want and bad == 0, string.format("%s: %d of %d frames equal ffmpeg's (%d differ)", label, n - bad, want, bad))
|
||||
v:seek(0.25)
|
||||
local f = v:nextFrame()
|
||||
local k = math.floor(0.25 * c.rate + 1 - 1e-9) + 1
|
||||
t:check(f ~= nil and Crc32.of(f.image.pixels) == c.frames[k], label .. ": seek to frame " .. k)
|
||||
if ring then
|
||||
local v2 = Fli.open(reader(c.data), { ringFrame = true })
|
||||
local m = 0
|
||||
while v2 and v2:nextFrame() do
|
||||
m += 1
|
||||
end
|
||||
t:eq(m, #c.frames, label .. ": with the ring frame")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
do
|
||||
local _, e = Fli.open(reader(string.sub(Fx[1].data, 1, 100)))
|
||||
t:check(e ~= nil and e.code == Err.TRUNCATED, "short header: TRUNCATED")
|
||||
local bad = Fx[1].data
|
||||
bad = string.sub(bad, 1, 4) .. "\0\0" .. string.sub(bad, 7)
|
||||
t:eq(Fli.sniff(reader(bad)), 0, "bad magic: no sniff")
|
||||
local _, e2 = Fli.open(reader(bad))
|
||||
t:check(e2 ~= nil and e2.code == Err.CORRUPT, "bad magic: CORRUPT")
|
||||
local big = string.sub(Fx[1].data, 1, 8) .. "\255\15\255\15" .. string.sub(Fx[1].data, 13)
|
||||
local _, e3 = Fli.open(reader(big), { maxPixels = 2 ^ 20 })
|
||||
t:check(e3 ~= nil and e3.code == Err.LIMIT, "maxPixels: LIMIT")
|
||||
end
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx do
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
t:fuzz("open", function(b: buffer)
|
||||
local v = Fli.open(Bytes.reader(b))
|
||||
if v then
|
||||
while v:nextFrame() do
|
||||
end
|
||||
end
|
||||
return v
|
||||
end, samples, { mutations = 12, garbage = 40, keepHeader = 16 })
|
||||
-- the frame decoder itself (codecs/video/Legacy/Flic, native: no pcall in between)
|
||||
local Flic = require("@formats/codecs/video/Legacy").Flic
|
||||
for _, c in { Fx[1], Fx[2], Fx[4], Fx[6] } do
|
||||
local d = Fli.demux(reader(c.data))
|
||||
local packets = {}
|
||||
for k = 1, math.min(4, d:count(1)) do
|
||||
table.insert(packets, d:get(1, k).data)
|
||||
end
|
||||
t:fuzz(c.name .. " frames", function(b: buffer)
|
||||
local st = Flic.state(c.width, c.height, c.depth)
|
||||
if st then
|
||||
Flic.decode(st, b)
|
||||
return Flic.image(st)
|
||||
end
|
||||
return nil
|
||||
end, packets, { mutations = 20, garbage = 30 })
|
||||
end
|
||||
t:done()
|
||||
Reference in new issue
Block a user