Skip to main content

Module wavcodec

Module wavcodec 

Source
Expand description

The wavelet codec: CDF 9/7 pyramid → deadzone quantizer → context model → adaptive binary range coding, with a SPERR-style outlier stream for pointwise bounds and an integer 5/3 lossless mode.

§Lossy path

  1. Forward multi-level CDF 9/7 (crate::wavelet); every coefficient is multiplied by its band’s synthesis-basis norm, so one uniform step Δ is equal-slope (MSE-matched) across bands.
  2. Deadzone uniform quantizer q = sgn(c)·⌊|c|/Δ + ρ⌋ (ρ < ½ widens the zero bin); reconstruction at the per-(class, |q|∈{1,2,≥3}) centroid |ĉ| = (|q| − δ)Δ, the 30 δs transmitted in 1/512 units.
  3. Coefficients coded by crate::coefcode (hand contexts) or a learned model (crate::learned).
  4. Rate control: for a PSNR/RMSE target Δ is bisected on the measured error of the actual decoder output.

§Max-abs mode

For a bound b the wavelet layer is coded at Δ = f·b for several f; the encoder decodes its own output and every cell with |x − x̂| > b gets a correction k = round((x − x̂)/2b) (then |x − (x̂ + 2bk)| ≤ b), coded as a context-modelled significance map plus |k|; cells a float cast still pushes over b are stored raw. The f with the smallest total wins and the bound is re-verified on the exact decoder output before returning.

Structs§

Coeffs
Forward-transformed, band-weighted coefficients.
WavConfig
Wavelet-codec options.
WavStats
What the encoder did.

Enums§

ModelChoice
Which coefficient model codes the stream.

Constants§

FAST_K_MAXABS
See FAST_K_RMSE.
FAST_K_RMSE
Fast-mode step ratios Δ / target: RMSE targets (Δ = k·rmse) and max-abs bounds (Δ = k·b). Calibrated on the 19 seen fields.
MAGIC
Stream magic of the wavelet codec.

Functions§

decode
Decode a lossy wavelet stream.
decode_i32_lossless
Decode a lossless stream from encode_i32_lossless.
encode_f32
Encode f32 samples (row-major, dims 1D–3D).
encode_f64
Encode f64 samples.
encode_i32_lossless
Lossless coding of integer samples via the reversible 5/3 transform.
fast_step
Step for an RMSE target: start from the formula Δ = k·t, then take log–log secant steps on the measured error (rmse ∝ Δ^γ), aiming 1% under the target, for at most checks trials. Returns the largest tried step that met the target (or the last one, halved, when none did) and the number of trials.
quantize
Deadzone quantization with centroid offsets.
reconstruct
Dequantize + inverse transform → reconstruction (f64, row-major).