codecs/image: comments to specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
95a6b03f70
30 files changed
+224
-770
No files matched your search
@@ -2,16 +2,8 @@
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- codecs/image/Dct: the 8x8 DCTs JPEG, Motion-JPEG and MPEG-1 share (native; never throws).
|
||||
-- Inverse: libjpeg's islow (jidctint.c: the Loeffler-Ligtenberg-Moschytz algorithm, 13-bit constants, two passes with
|
||||
-- PASS1_BITS of scaling between them), plus the reduced 4x4 / 2x2 / 1x1 IDCTs for scaled decodes (jidctred.c); the
|
||||
-- results match libjpeg-turbo's djpeg bit for bit. Absorbed from jpeg-luau 1.0 src/Jpeg/Idct.luau (same author).
|
||||
-- Forward: libjpeg's islow (jfdctint.c) with jcdctmgr.c's rounding quantiser, so an encoder built on it produces
|
||||
-- the same coefficients as cjpeg. Both are Luau translations of IJG code (licenses/libjpeg-turbo-LICENSE.md).
|
||||
-- Values are exact integers in doubles: no overflow even on corrupt coefficients; outputs are clamped to 0..maxv.
|
||||
--
|
||||
-- Dct.idctComponent(coef, q, bpl, bpc, size, plane, p1, center, maxv) -- every block of a component
|
||||
-- Dct.idctBlock(coef, off, q, plane, out, stride, p1, center, maxv) -- one 8x8 block (u16 samples)
|
||||
-- Dct.fdctQuantize(src, stride, x, y, w, h, div, coef, off) -- one block from u8 samples
|
||||
-- libjpeg's islow (jidctint.c / jfdctint.c), the reduced IDCTs (jidctred.c) and jcdctmgr.c's rounding quantiser, bit-exact
|
||||
-- with libjpeg-turbo. From jpeg-luau 1.0 (same author); IJG code: licenses/libjpeg-turbo-LICENSE.md.
|
||||
local readi16, readu16, writeu16, readu8, writei16 = buffer.readi16, buffer.readu16, buffer.writeu16, buffer.readu8, buffer.writei16
|
||||
local clamp = math.clamp
|
||||
|
||||
@@ -243,10 +235,7 @@ local function idct2(coef: buffer, off: number, q: buffer, plane: buffer, out: n
|
||||
end
|
||||
end
|
||||
|
||||
-- Inverse-transforms every block of a component: coef (i16, 64 per block, natural order) on a bpl x bpc block
|
||||
-- grid, quantisation table q (64 u16, natural order), into plane (u16 samples, (bpl * size) per row) at size x
|
||||
-- size samples per block. p1 is PASS1_BITS (2 for 8-bit, 1 for 12-bit), center the level shift, maxv the top.
|
||||
-- hook (optional): a cooperative yield point after every block row (pcall'ed: it can't throw through here).
|
||||
-- p1 = PASS1_BITS (2 for 8-bit, 1 for 12-bit)
|
||||
function Dct.idctComponent(coef: buffer, q: buffer, bpl: number, bpc: number, size: number, plane: buffer, p1: number, center: number, maxv: number, hook: (() -> ())?)
|
||||
local stride = bpl * size
|
||||
for by = 0, bpc - 1 do
|
||||
@@ -270,13 +259,10 @@ function Dct.idctComponent(coef: buffer, q: buffer, bpl: number, bpc: number, si
|
||||
end
|
||||
end
|
||||
|
||||
-- idctBlock(coef, off, q, plane, out, stride, p1, center, maxv): one 8x8 block, coef (i16, natural order) at byte
|
||||
-- offset off, dequantised by q (64 u16), into the u16 plane at sample index out with stride samples per row
|
||||
function Dct.idctBlock(coef: buffer, off: number, q: buffer, plane: buffer, out: number, stride: number, p1: number, center: number, maxv: number)
|
||||
idct8(coef, off, q, plane, out, stride, p1, center, maxv)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ forward
|
||||
local fw = table.create(64, 0)
|
||||
|
||||
local function quant(coef: buffer, off: number, div: buffer, v: number, i: number)
|
||||
@@ -289,10 +275,7 @@ local function quant(coef: buffer, off: number, div: buffer, v: number, i: numbe
|
||||
end
|
||||
end
|
||||
|
||||
-- fdctQuantize(src, stride, x, y, w, h, div, coef, off): the 8x8 block of u8 samples at (x, y) in src (stride bytes
|
||||
-- per row; samples past w - 1 / h - 1 repeat the edge), level-shifted by 128, forward DCT (jfdctint.c islow), then
|
||||
-- quantised as jcdctmgr.c: (|v| + q * 4) // (q * 8) with the sign restored, q = div (64 u16, natural order). Writes
|
||||
-- 64 i16 at coef[off] (natural order). The caller keeps x < w, y < h and the src range valid.
|
||||
-- quantised as jcdctmgr.c: (|v| + q * 4) // (q * 8) with the sign restored
|
||||
function Dct.fdctQuantize(src: buffer, stride: number, x: number, y: number, w: number, h: number, div: buffer, coef: buffer, off: number)
|
||||
local lastX, lastY = w - 1, h - 1
|
||||
for r = 0, 7 do
|
||||
|
||||
Reference in new issue
Block a user