ws-video-codecs: codecs/Jpeg: 4:2:2 / 4:4:4 as ffmpeg writes them (2x2/1x2, 1x2) for yuv output; tests/codecs/jpeg.luau + tools/fixtures/mjpeg.py (ffmpeg mjpeg frames bit-exact vs TurboJPEG planes / djpeg, PSNR vs ffmpeg, stripped DHT, AVI1, fields, yuv420p encode byte-identical with tj3CompressFromYUV8)

This commit is contained in:
4DBug committed 2026-10-31 09:35:34 -05:00
1 parent 2ca0d1f10a
commit c0e8a89050
3 files changed
+575 -11

No files matched your search

+18 -11
View File
@@ -675,9 +675,10 @@ end
-- outputYuv(st) -> width, height, yuv420p pixels, sampling | nil when the frame has no direct yuv420p form (the
-- caller falls back to output). The IDCT output planes as they are, cropped to the image, without colour conversion
-- or upsampling: 8-bit YCbCr with 2x2 luma and 1x1 chroma sampling ("420"); 2x1 luma ("422": each pair of chroma
-- rows averaged, rounding up); 1x1 everywhere ("444": each 2 x 2 chroma block averaged, rounding to nearest); grey
-- ("gray": chroma 128). Full scale only (opts.scale = 1).
-- or upsampling: 8-bit YCbCr whose chroma is sampled at half the luma rate both ways ("420", 2x2 / 1x1); half
-- 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).
function Decode.outputYuv(st: State): (number?, number?, buffer?, string?)
local f: Frame = st.frame
if st.scale ~= 1 or f.precision ~= 8 then
@@ -688,14 +689,20 @@ function Decode.outputYuv(st: State): (number?, number?, buffer?, string?)
local mode = nil
if space == "gray" then
mode = "gray"
elseif space == "ycbcr" and comps[2].h == 1 and comps[2].v == 1 and comps[3].h == 1 and comps[3].v == 1 then
local l = comps[1]
if l.h == 2 and l.v == 2 then
mode = "420"
elseif l.h == 2 and l.v == 1 then
mode = "422"
elseif l.h == 1 and l.v == 1 then
mode = "444"
elseif space == "ycbcr" then
-- the ratios of luma to chroma sampling (ffmpeg writes 4:2:2 as 2x2 / 1x2 and 4:4:4 as 1x2 everywhere)
local l, cb, cr = comps[1], comps[2], comps[3]
if l.h == f.hmax and l.v == f.vmax and cb.h == cr.h and cb.v == cr.v then
local rh, rv = f.hmax // cb.h, f.vmax // cb.v
if rh * cb.h ~= f.hmax or rv * cb.v ~= f.vmax then
mode = nil
elseif rh == 2 and rv == 2 then
mode = "420"
elseif rh == 2 and rv == 1 then
mode = "422"
elseif rh == 1 and rv == 1 then
mode = "444"
end
end
end
if not mode then