ws-video2: MPEG-2 field-picture / concealment-vector fixtures (a syntax-level writer in tools/fixtures/mpeg2.py), bit-exact; LuaJIT-friendlier hot paths; mpeg2 bench line

This commit is contained in:
4DBug committed 2026-10-31 14:50:27 -05:00
1 parent 5585ce53ce
commit d22c72c1bc
4 files changed
+322 -18

No files matched your search

+53 -14
View File
@@ -31,6 +31,7 @@ local readi32 = buffer.readi32
local writei32 = buffer.writei32
local band = bit32.band
local bor = bit32.bor
local bxor = bit32.bxor
local lshift = bit32.lshift
local rshift = bit32.rshift
local bswap = bit32.byteswap
@@ -549,12 +550,18 @@ function D.new(maxPixels: number?): Core
mc(rY, stride, sb + sy * stride + sx, curY, stride, dOff, 16, h, hx, hy, avg)
end
-- chroma: horizontal vector / 2 truncated toward zero; vertical too in 4:2:0
local mx = if mvx < 0 then -((-mvx) // 2) else mvx // 2
local mx = mvx // 2
if mvx < 0 then
mx = -((-mvx) // 2)
end
local cx, cy, chh, cph, chx, chy
chx = band(mx, 1)
cx = mbCol * 8 + (mx - chx) // 2
if chroma == 1 then
local my = if mvy < 0 then -((-mvy) // 2) else mvy // 2
local my = mvy // 2
if mvy < 0 then
my = -((-mvy) // 2)
end
chy = band(my, 1)
cy = rowY // 2 + (my - chy) // 2
chh, cph = h // 2, ph // 2
@@ -563,7 +570,11 @@ function D.new(maxPixels: number?): Core
cy = rowY + (mvy - chy) // 2
chh, cph = h, ph
end
local cdOff = cdb + (if chroma == 1 then rowY // 2 else rowY) * cs + mbCol * 8
local crow = rowY
if chroma == 1 then
crow = rowY // 2
end
local cdOff = cdb + crow * cs + mbCol * 8
if cx < 0 or cy < 0 or cx + 8 + chx > chw or cy + chh + chy > cph then
Dsp.edge(rCb, cs, csb, cx, cy, 8, chh, chw, cph, EDGE)
mc(EDGE, 32, 0, curCb, cs, cdOff, 8, chh, chx, chy, avg)
@@ -592,8 +603,15 @@ function D.new(maxPixels: number?): Core
local function predictDir(d: number, avg: boolean)
local o = d * 8
if not fieldPic then
local r = (if d == 0 then fwS else bwS) or cur :: Store
local ry, rcb, rcr = r.y, r.cb, r.cr
local r = bwS
if d == 0 then
r = fwS
end
if r == nil then
r = cur
end
local ref = r :: Store
local ry, rcb, rcr = ref.y, ref.cb, ref.cr
if motionType == 1 then
mcPart(ry, rcb, rcr, -1, -1, mbRow * 16, 16, MV[o + 1], MV[o + 2], avg)
elseif motionType == 2 then
@@ -736,7 +754,10 @@ function D.new(maxPixels: number?): Core
dc = dcY
else
size = vlc(DC_CHROMA, DC_CHROMA_BITS)
dc = if b % 2 == 0 then dcCb else dcCr
dc = dcCr
if b % 2 == 0 then
dc = dcCb
end
end
if size > 0 then
local diff = read(size)
@@ -761,14 +782,24 @@ function D.new(maxPixels: number?): Core
end
local v = lshift(dc, 3 - dcPrec)
writei32(blk, 0, v)
parityOdd = bit32.bxor(1, band(v, 1))
q = if luma then intraQ else chromaIntraQ
parityOdd = bxor(1, band(v, 1))
q = chromaIntraQ
if luma then
q = intraQ
end
n = 1
else
q = if luma then nonIntraQ else chromaNonIntraQ
q = chromaNonIntraQ
if luma then
q = nonIntraQ
end
end
local lut, nextLut = DCT_NEXT, DCT_NEXT
if mbIntra and intraVlc then
lut, nextLut = DCT_B15, DCT_B15
elseif n == 0 then
lut = DCT_FIRST
end
local lut = if mbIntra and intraVlc then DCT_B15 elseif n == 0 then DCT_FIRST else DCT_NEXT
local nextLut = if mbIntra and intraVlc then DCT_B15 else DCT_NEXT
local intra = mbIntra
local qs = qscale
local m2 = mpeg2
@@ -853,7 +884,9 @@ function D.new(maxPixels: number?): Core
if neg then
m = -m
end
parityOdd = bit32.bxor(parityOdd, band(m, 1))
if m2 then
parityOdd = bxor(parityOdd, band(m, 1))
end
-- saturate
if m > 2047 then
m = 2047
@@ -887,7 +920,10 @@ function D.new(maxPixels: number?): Core
off = (mbRow * 16 + (if b >= 2 then 8 else 0)) * cw + mbCol * 16 + (if b % 2 == 1 then 8 else 0)
end
else
dst = if b % 2 == 0 then curCb else curCr
dst = curCr
if b % 2 == 0 then
dst = curCb
end
local k = (b - 4) // 2 -- the vertical chroma block of a 4:2:2 macroblock
if chroma == 1 then
stride = cstride
@@ -923,7 +959,10 @@ function D.new(maxPixels: number?): Core
-- motion vectors of direction d (13818-2 7.6.3; MPEG-1: frame vectors, full_pel doubled)
local function motionVectors(d: number)
local fh, fv = if d == 0 then fc00 else fc10, if d == 0 then fc01 else fc11
local fh, fv = fc10, fc11
if d == 0 then
fh, fv = fc00, fc01
end
local o, p, f = d * 8, d * 4, d * 2
if motionType == 1 and not fieldPic then
local x = decodeMotion(fh, PMV[p + 1])