merge ws/video2-legacy (FLIC, Cinepak, MSV1, QT RLE / SMC, Smacker; video/fli, video/smk)
This commit is contained in:
commit
9694c652ec
32 files changed
+4786
-5
No files matched your search
@@ -0,0 +1,113 @@
|
||||
-- codecs/video/Legacy tests: Cinepak (24-bit, grey, 8-bit palettised, several strips, a 92x68 size), Microsoft Video 1
|
||||
-- (16-bit, 8-bit with an AVI palette), QuickTime RLE (depths 1 / 2 / 4 / 8 with colour tables, default Macintosh
|
||||
-- tables and grey ramps; 16 / 24 / 32-bit and grey from ffmpeg) and QuickTime SMC, in AVI, MOV and MKV: every frame
|
||||
-- equals ffmpeg's decode (CRC-32 of rgba); seeking; the registry entries; the fuzz pass on each codec's packet decoder.
|
||||
-- Fixtures: tools/fixtures/legacy.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Video = require("@formats/codecs/video/Video")
|
||||
local Legacy = require("@formats/codecs/video/Legacy")
|
||||
local Fx = require("@tests/gen/legacy_cases")
|
||||
|
||||
local t = T.suite("legacy")
|
||||
|
||||
-- the registry
|
||||
t:eq(Video.fromFourcc("cvid"), "cinepak", "cvid")
|
||||
t:eq(Video.fromFourcc("CRAM"), "msvideo1", "CRAM")
|
||||
t:eq(Video.fromFourcc("msvc"), "msvideo1", "msvc")
|
||||
t:eq(Video.fromFourcc("rle "), "qtrle", "rle ")
|
||||
t:eq(Video.fromFourcc("smc "), "smc", "smc ")
|
||||
for _, id in Legacy.CODECS do
|
||||
t:check(Video.canDecode(id), id .. ": decodable")
|
||||
end
|
||||
|
||||
local samples: { [string]: { any } } = {}
|
||||
|
||||
for _, c in Fx do
|
||||
local label = c.name
|
||||
local v, err = F.video.open(c.data)
|
||||
t:check(v ~= nil, label .. ": open: " .. tostring(err))
|
||||
if v then
|
||||
t:eq(v.codec, c.codec, label .. ": codec")
|
||||
t:eq(v.width, c.width, label .. ": width")
|
||||
local n, bad, first = 0, 0, nil
|
||||
while true do
|
||||
local f, ferr = v:nextFrame()
|
||||
if not f then
|
||||
t:check(ferr == nil, label .. ": decode error " .. tostring(ferr))
|
||||
break
|
||||
end
|
||||
n += 1
|
||||
local img = f.image
|
||||
if img.format ~= "rgba8" or img.width ~= c.width or Crc32.of(img.pixels) ~= c.frames[n] then
|
||||
bad += 1
|
||||
first = first or n
|
||||
end
|
||||
end
|
||||
t:check(n == #c.frames and bad == 0, string.format("%s: %d of %d frames equal ffmpeg's (%d differ, first %s)", label, n - bad, #c.frames, bad, tostring(first)))
|
||||
-- seeking: back to the start, the first frame again
|
||||
v:seek(0)
|
||||
local f = v:nextFrame()
|
||||
t:check(f ~= nil and Crc32.of(f.image.pixels) == c.frames[1], label .. ": seek(0)")
|
||||
-- packets for the fuzz pass
|
||||
local dmx = v.demuxer
|
||||
local tr = dmx:track("video")
|
||||
if not samples[c.codec] then
|
||||
local list = {}
|
||||
for k = 1, math.min(3, dmx:count(tr.id)) do
|
||||
table.insert(list, dmx:get(tr.id, k).data)
|
||||
end
|
||||
samples[c.codec] = { track = tr, packets = list }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- the fuzz pass on the native packet decoders (no pcall in between)
|
||||
local P = Legacy.Picture
|
||||
local raw: { [string]: (tr: any) -> (buffer) -> any } = {
|
||||
cinepak = function(tr)
|
||||
return function(b)
|
||||
local pic = P.new(tr.width, tr.height, tr.bitsPerPixel == 8, 4, 4, tr.palette)
|
||||
return Legacy.Cinepak.decode(pic, b, Legacy.Cinepak.state(), false)
|
||||
end
|
||||
end,
|
||||
msvideo1 = function(tr)
|
||||
return function(b)
|
||||
local bits = if tr.bitsPerPixel == 8 then 8 else 16
|
||||
return Legacy.Msvideo1.decode(P.new(tr.width, tr.height, bits == 8, 4, 4), b, bits)
|
||||
end
|
||||
end,
|
||||
qtrle = function(tr)
|
||||
return function(b)
|
||||
local d = tr.bitsPerPixel or 24
|
||||
for _, depth in { d, 1, 2, 4, 8, 16, 32 } do
|
||||
Legacy.QtRle.decode(P.new(tr.width, tr.height, Legacy.QtRle.palettised(depth), Legacy.QtRle.pad(depth), 1), b, depth)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end,
|
||||
smc = function(tr)
|
||||
return function(b)
|
||||
return Legacy.Smc.decode(P.new(tr.width, tr.height, true, 4, 4), b, Legacy.Smc.tables())
|
||||
end
|
||||
end,
|
||||
}
|
||||
for id, s in samples do
|
||||
local fn = raw[id]
|
||||
if fn then
|
||||
t:fuzz(id .. " packets", fn(s.track), s.packets, { mutations = 24, garbage = 60 })
|
||||
end
|
||||
end
|
||||
t:fuzz("open", function(b: buffer)
|
||||
local v = F.video.open(b)
|
||||
if v then
|
||||
for _ = 1, 3 do
|
||||
if not v:nextFrame() then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return v
|
||||
end, { Fx[1].data, Fx[#Fx].data }, { mutations = 8, garbage = 20 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user