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

+11 -11
View File
@@ -5,27 +5,27 @@
-- samples, block-padded) cropped into u8 yuv420p planes without colour conversion or upsampling, 4:2:2 / 4:4:4
-- chroma reduced to 4:2:0 by averaging, and the interleaving of two fields (AVI1 interlaced Motion-JPEG).
-- The callers (codecs/Jpeg/Decode, codecs/Jpeg) size every buffer; each loop reads and writes inside those sizes.
local readu16, writeu8, readu32 = buffer.readu16, buffer.writeu8, buffer.readu32
local readu16, writeu8, readu32, writeu32 = buffer.readu16, buffer.writeu8, buffer.readu32, buffer.writeu32
local Yuv = {}
-- crop(src, stride, w, h, dst, doff): the top-left w x h samples of a u16 plane (stride samples per row) into u8
-- samples at dst[doff], w per row
function Yuv.crop(src: buffer, stride: number, w: number, h: number, dst: buffer, doff: number)
local npairs = w // 2
local quads = w // 4
local rest = w - quads * 4
for y = 0, h - 1 do
local s = y * stride * 2
local d = doff + y * w
-- two samples per u32 read
for _ = 1, npairs do
local v = readu32(src, s)
writeu8(dst, d, v % 65536)
writeu8(dst, d + 1, v // 65536)
s += 4
d += 2
-- four samples (two u32 reads of two u16 samples, each 0..255) per u32 write
for _ = 1, quads do
local a, b = readu32(src, s), readu32(src, s + 4)
writeu32(dst, d, a % 65536 + (a // 65536) * 256 + (b % 65536) * 65536 + (b // 65536) * 16777216)
s += 8
d += 4
end
if w % 2 == 1 then
writeu8(dst, d, readu16(src, s))
for k = 0, rest - 1 do
writeu8(dst, d + k, readu16(src, s + k * 2))
end
end
end