Expand description
Shared digital signal processing routines for the gamut codecs.
Provides the AV1 1-D transform kernels:
- the lossless 4×4 Walsh–Hadamard pair (
fwht4x4/iwht4x4, AV1 §7.13.2.10), - the discrete cosine transform pair (
forward_dct/inverse_dct, AV1 §7.13.2.2–.3), - the asymmetric discrete sine pair (
forward_adst/inverse_adst, AV1 §7.13.2.4–.9 — DST-VII at size 4, DST-IV at 8/16), with the FLIPADST flip (flip_in_place), and - the identity transforms (
forward_identity/inverse_identity, AV1 §7.13.2.11–.15).
The 2-D assembly that selects per PlaneTxType and applies the per-pass normalization shifts
(AV1 §7.13.3) is tracked in gamut-avif/STATUS.md.
Alongside the transforms, [mod@math] exposes the small AV1 §4.7 integer arithmetic
primitives (round2, round2_signed, clip3) and the shared forward-quantize
rounding (round_div_nearest) that the codec crates build on, and [mod@mulaw] adds
µ-law companding/quantization (mu_compress / mu_expand / mu_quantize /
mu_dequantize).
Functions§
- clip3
Clip3(low, high, x)(AV1 §4.7): clampxto the inclusive range[low, high].- flip_
in_ place - Reverse the first
lenelements oftin place — the FLIPADST sample-order flip (AV1 §7.13.3 applies this around the shared inverse ADST for the FLIPADST transform variants). - forward_
adst - In-place 1-D forward ADST of the length-
2^narrayt(n ∈ {2, 3, 4}) — the transpose of the inverse ADST matrix, built from the inverse’s impulse responses (see module docs). - forward_
dct - In-place 1-D forward DCT-II of the length-
2^narrayt(2 ≤ n ≤ 6). - forward_
identity - In-place 1-D forward identity transform of the length-
2^narrayt(2 ≤ n ≤ 5): the reciprocal per-element scaling that pairs withinverse_identity. - fwht4x4
- Forward 4×4 Walsh–Hadamard transform: maps a row-major residual block to the lossless AV1 coefficients to be entropy-coded.
- inverse_
adst - In-place 1-D inverse ADST of the length-
2^narrayt(n ∈ {2, 3, 4}), per AV1 §7.13.2.9. - inverse_
dct - In-place 1-D inverse DCT of the length-
2^narrayt(2 ≤ n ≤ 6), per AV1 §7.13.2.3. - inverse_
identity - In-place 1-D inverse identity transform of the length-
2^narrayt(2 ≤ n ≤ 5), per AV1 §7.13.2.15. - iwht4x4
- Lossless 4×4 reconstruct: dequantizes (
* 4), applies the AV1 row (shift 2) and column (shift 0) inverse WHT, and returns the residual. Bit-exact with the AV1 decoder for an 8-bitbase_q_idx == 0block (AV1 §7.12.3, §7.13.3, §7.13.2.10). - mu_
compress - µ-law compress a
valuein[-1, 1]to a companded value in[-1, 1].valueis clamped to[-1, 1]. Precondition:mu > 0. - mu_
dequantize - Dequantize an integer
indexback to a value in[-1, 1]through µ-law — the inverse ofmu_quantize. The never-written top code clamps down to2^bits−2for robustness. - mu_
expand - µ-law expand a companded value in
[-1, 1]back to[-1, 1]— the inverse ofmu_compress. Precondition:mu > 0. - mu_
quantize - Quantize a
valuein[-1, 1]through µ-law to an integer index in0..=2^bits−2(odd level count; the center index is exactly0.0). - round2
Round2(x, n)(AV1 §4.7): rounding right shift,xforn == 0(arithmetic>>, ties up).- round2_
signed Round2Signed(x, n)(AV1 §4.7): symmetric rounding right shift — rounds the magnitude and keeps the sign (ties away from zero), unlikeround2which ties toward+∞.- round_
div_ nearest - Rounds
num / dento the nearest integer, ties away from zero — the encoder forward-quantize step shared by AV1 and VP8 (level ≈ coeff / q). Requiresden > 0.