codecs/image: comments to specs only

This commit is contained in:
4DBug committed 2026-11-01 01:22:45 -06:00
1 parent 0bd7b87d2b
commit 95a6b03f70
30 files changed
+224 -770

No files matched your search

+9 -26
View File
@@ -1,13 +1,9 @@
--!strict
--!native
--!optimize 2
-- codecs/image/Vp8/Predict: VP8 inter prediction (RFC 6386 section 18): the six-tap sub-pixel filters (version 0), the
-- bilinear ones (versions 1-3; version 3 also rounds chroma vectors to full pixels), chroma vectors derived from the
-- luma ones, split macroblocks, and the reference frame borders. After libvpx 1.17 vp8/common/reconinter.c and
-- filter.c (BSD-3-Clause, licenses/libvpx-LICENSE.txt). Out-of-frame motion reads the reference as if its edge pixels
-- extended forever, which is exactly what libvpx computes with its 32 pixel border plus its motion vector clamping (the
-- clamps only kick in once every tap is in the border). The planes keep a BORDER pixel border filled by extend(); a
-- block whose taps leave it is first copied with clamped coordinates. Never throws.
-- codecs/image/Vp8/Predict: VP8 inter prediction (RFC 6386 section 18), after libvpx 1.17 vp8/common/reconinter.c and
-- filter.c (BSD-3-Clause, licenses/libvpx-LICENSE.txt). Out-of-frame motion reads the edge pixels extended forever,
-- which equals libvpx's 32 pixel border plus its motion vector clamping.
local Tables = require("@rosetta/codecs/image/Vp8/Tables")
local readu8, writeu8, bcopy, bcreate, bfill = buffer.readu8, buffer.writeu8, buffer.copy, buffer.create, buffer.fill
@@ -20,14 +16,12 @@ local Predict = {}
local BORDER = 32
Predict.BORDER = BORDER
-- the work buffer stride (codecs/image/Vp8/Decode: BPS)
local BPS = 32
local emu = bcreate(32 * 32) -- a block with its taps, edges replicated
local tmp = bcreate(32 * 32) -- the first (horizontal) pass of a two-dimensional filter
local emu = bcreate(32 * 32)
local tmp = bcreate(32 * 32)
-- the six-tap filter along rows: dst[i] = clamp((sum of src[i - 2 .. i + 3] * taps + 64) >> 7). Each output reads
-- its six pixels (a sliding window of locals is no faster in Luau and stops LuaJIT's register allocator).
-- six-tap along rows: dst[i] = clamp((sum of src[i - 2 .. i + 3] * taps + 64) >> 7)
local function sixH(src: buffer, so: number, ss: number, dst: buffer, d: number, ds: number, w: number, h: number, f: number)
local k = f * 6
local t0, t1, t2, t3, t4, t5 = SIX[k + 1], SIX[k + 2], SIX[k + 3], SIX[k + 4], SIX[k + 5], SIX[k + 6]
@@ -42,7 +36,6 @@ local function sixH(src: buffer, so: number, ss: number, dst: buffer, d: number,
end
end
-- the six-tap filter along columns
local function sixV(src: buffer, so: number, ss: number, dst: buffer, d: number, ds: number, w: number, h: number, f: number)
local k = f * 6
local t0, t1, t2, t3, t4, t5 = SIX[k + 1], SIX[k + 2], SIX[k + 3], SIX[k + 4], SIX[k + 5], SIX[k + 6]
@@ -83,9 +76,6 @@ local function bilV(src: buffer, so: number, ss: number, dst: buffer, d: number,
end
end
-- block(src, stride, base, wmax, hmax, x, y, mvx, mvy, w, h, dst, d, bil): predicts the w x h block at plane pixel
-- (x, y) moved by (mvx, mvy) eighth pixels into dst at d (stride BPS). base: the offset of plane pixel (0, 0); wmax,
-- hmax: the last pixel column / row of the (macroblock aligned) plane.
local function block(src: buffer, stride: number, base: number, wmax: number, hmax: number, x: number, y: number, mvx: number, mvy: number, w: number, h: number, dst: buffer, d: number, bil: boolean)
local fx, fy = band(mvx, 7), band(mvy, 7)
local px, py = x + (mvx - fx) // 8, y + (mvy - fy) // 8
@@ -163,17 +153,14 @@ export type Planes = {
Y: buffer,
U: buffer,
V: buffer,
ys: number, -- luma stride
uvs: number, -- chroma stride
yb: number, -- offset of luma pixel (0, 0)
ys: number,
uvs: number,
yb: number,
uvb: number,
mbw: number,
mbh: number,
}
-- mb(ref, mbx, mby, mvr, mvc, split, subR, subC, sb, dst, yo, uo, vo, bil, full): the prediction of one inter
-- macroblock into the work buffer (luma at yo, chroma at uo / vo). Not split: one vector (mvr, mvc) in eighth pixels;
-- split: the 16 block vectors subR / subC[sb + 1 .. sb + 16] (part < 3: the four 8x8 quarters share them).
function Predict.mb(ref: Planes, mbx: number, mby: number, mvr: number, mvc: number, part: number, subR: { number }, subC: { number }, sb: number, dst: buffer, yo: number, uo: number, vo: number, bil: boolean, full: boolean)
local Y, U, V, ys, uvs, yb, uvb = ref.Y, ref.U, ref.V, ref.ys, ref.uvs, ref.yb, ref.uvb
local wl, hl = ref.mbw * 16 - 1, ref.mbh * 16 - 1
@@ -236,9 +223,6 @@ function Predict.mb(ref: Planes, mbx: number, mby: number, mvr: number, mvc: num
end
end
-- row(refs, mby, mbw, ref, part, miMvR, miMvC, miSubR, miSubC, mi0, pred, chunk, yo, uo, vo, bil, full): predicts the
-- inter macroblocks of a row (ref[mbx + 1] > 0: refs[ref]) into pred, macroblock mbx at mbx * chunk + yo / uo / vo;
-- mi0 + mbx + 1: the mode info index of macroblock mbx. A loop of its own (LuaJIT traces it apart from the decoder).
function Predict.row(refs: { Planes }, mby: number, mbw: number, ref: { number }, part: { number }, miMvR: { number }, miMvC: { number }, miSubR: { number }, miSubC: { number }, mi0: number, pred: buffer, chunk: number, yo: number, uo: number, vo: number, bil: boolean, full: boolean)
for mbx = 0, mbw - 1 do
local rf = ref[mbx + 1]
@@ -250,7 +234,6 @@ function Predict.row(refs: { Planes }, mby: number, mbw: number, ref: { number }
end
end
-- extend(P, stride, base, w, h): fills the BORDER pixels around a w x h plane with its edge pixels
local function extend(P: buffer, stride: number, base: number, w: number, h: number)
for r = 0, h - 1 do
local o = base + r * stride