ws-cleanup-types: codecs: type table.create results, string-keyed tables and multi-assigned locals
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8e6894c6b5
commit
c436f4d265
22 files changed
+73
-73
No files matched your search
@@ -95,7 +95,7 @@ local function rawPlanar(data: buffer, pf: string, bits: number, w: number, h: n
|
||||
if pf == "gray" then
|
||||
u, v = 128, 128
|
||||
elseif pf == "yuv420p" then
|
||||
u, v = sample(uo + i * bps), sample(vo + i * bps)
|
||||
u, v = sample(uo + i * bps), sample(vo + i * bps) :: number
|
||||
elseif pf == "yuv422p" then
|
||||
local y0, y1 = cy * 2, math.min(cy * 2 + 1, h - 1)
|
||||
u = (sample(uo + (y0 * scw + cx) * bps) + sample(uo + (y1 * scw + cx) * bps) + 1) // 2
|
||||
@@ -166,7 +166,7 @@ local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDec
|
||||
return rawPlanar(data, pf, bits, w, h), nil
|
||||
end
|
||||
local bpp = if pf == "bgra" or pf == "rgba" then 4 else 3
|
||||
local stride = if track.stride then track.stride else w * bpp
|
||||
local stride: number = track.stride or w * bpp
|
||||
if n < stride * (h - 1) + w * bpp then
|
||||
return nil, Err.new(Err.TRUNCATED, "raw frame too short")
|
||||
end
|
||||
@@ -186,7 +186,7 @@ local function rawDecoder(track: Types.Track, _opts: any?): (Types.VideoCodecDec
|
||||
end
|
||||
end
|
||||
return img, nil
|
||||
end)
|
||||
end), nil
|
||||
end
|
||||
|
||||
local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
|
||||
@@ -210,21 +210,21 @@ local function vp8Decoder(_track: Types.Track, opts: any?): (Types.VideoCodecDec
|
||||
else
|
||||
dec = Vp8.newDecoder()
|
||||
end
|
||||
end)
|
||||
end), nil
|
||||
end
|
||||
|
||||
-- Motion JPEG: every packet one JPEG (or two fields), yuv420p straight from the planes (full range) when the layout
|
||||
-- allows, else rgba8
|
||||
local function mjpegDecoder(_track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
|
||||
local Jpeg = require("@formats/codecs/Jpeg")
|
||||
local o = { yuv = true, maxPixels = opts and opts.maxPixels }
|
||||
local o: Jpeg.DecodeOptions = { yuv = true, maxPixels = opts and opts.maxPixels }
|
||||
return Video.simpleDecoder(function(data: buffer): (Types.Image?, Err.Err?)
|
||||
local img, err = Jpeg.decode(data, 0, buffer.len(data), o)
|
||||
if img and img.format == "yuv420p" then
|
||||
img.meta.yuv = { range = "full", matrix = "bt601" }
|
||||
end
|
||||
return img, err
|
||||
end)
|
||||
end), nil
|
||||
end
|
||||
|
||||
-- the MJPEG encoder (writers): JPEG is full-range, so limited-range yuv420p frames are remapped first
|
||||
@@ -444,7 +444,7 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
|
||||
end
|
||||
local index, flushed, skipUntil = 0, false, -math.huge
|
||||
local tid = if track then track.id else -1
|
||||
local scale = if track and track.timescale and track.timescale > 0 then track.timescale else 1000
|
||||
local scale: number = if track and track.timescale and track.timescale > 0 then track.timescale else 1000
|
||||
local start = demuxer.startTime or 0
|
||||
v.startTime = start
|
||||
local defaultDur = if v.frameRate > 0 then 1 / v.frameRate else 0
|
||||
@@ -461,8 +461,8 @@ function Video.open(demuxer: Types.Demuxer, opts: OpenOptions?): (Types.VideoDec
|
||||
if t + 1e-9 >= skipUntil then
|
||||
index += 1
|
||||
local d = defaultDur
|
||||
if lastPts and t > lastPts and defaultDur == 0 then
|
||||
d = t - lastPts
|
||||
if lastPts and t > (lastPts :: number) and defaultDur == 0 then
|
||||
d = t - (lastPts :: number)
|
||||
end
|
||||
lastPts = t
|
||||
if o.rgba then
|
||||
|
||||
Reference in new issue
Block a user