ws-video-codecs: codecs/Jpeg: yuv output crops four samples per write and reuses one frame-sized IDCT plane between calls

This commit is contained in:
4DBug committed 2026-10-31 09:37:01 -05:00
1 parent c0e8a89050
commit ed76378cd0
2 files changed
+27 -12

No files matched your search

+16 -1
View File
@@ -679,6 +679,21 @@ end
-- horizontally ("422", 2x1 / 1x1 or ffmpeg's 2x2 / 1x2: each pair of chroma rows averaged, rounding up); at the luma
-- rate ("444", 1x1 or ffmpeg's 1x2 everywhere: each 2 x 2 chroma block averaged, rounding to nearest); grey ("gray":
-- chroma 128). Full scale only (opts.scale = 1).
-- one IDCT plane at a time is live (each is cropped into the output before the next component): frame-sized planes
-- (up to 4 MB) are kept between calls, so a stream of video frames does not allocate them per frame
local scratch: buffer? = nil
local function scratchPlane(n: number): buffer
local sc = scratch
if sc and buffer.len(sc) >= n then
return sc
end
local b = buffer.create(n)
if n <= 4 * 1024 * 1024 then
scratch = b
end
return b
end
function Decode.outputYuv(st: State): (number?, number?, buffer?, string?)
local f: Frame = st.frame
if st.scale ~= 1 or f.precision ~= 8 then
@@ -719,7 +734,7 @@ function Decode.outputYuv(st: State): (number?, number?, buffer?, string?)
local zeroQ: buffer? = nil
for i, c in comps do
local stride, rows = c.bpl * 8, c.bpc * 8
local plane = buffer.create(stride * rows * 2)
local plane = scratchPlane(stride * rows * 2)
local coef = c.coef or buffer.create(c.bpl * c.bpc * 128)
local q = c.quant
if not q then