wai-rs: derive the entropy-decode inputs — skip_mask + rvs_additive (fixture-free) #28

Merged
dcharlot merged 1 commit from feat/jpegai-derive-inputs into main 2026-07-18 23:33:26 -04:00

2026-07-18

Transaction Science
wai-rs: derive the entropy-decode inputs — skip_mask + rvs_additive (fixture-free)
Ports the last two inputs the mANS sgm decoder needed but that were still being read
from an e2e fixture. With these, every input of the decode path is computable from the
codestream plus normative assets.

  skip_mask     scale_hat = i_s + gain_per_ch ; mask = scale_hat > 382
                NOTE the skip decision uses the scale WITHOUT the RVS additive, while
                sigma_index uses it WITH — the two differ by exactly the rvs values and
                are easy to conflate.

  rvs_additive  likely = clamp((sum_8x8 |i_s| + 32) >> 6, 0, 4351)
                band   = #{ e in [1003,1352,1937] : likely >= e }
                rvs    = A[grfs_flag ? 0 : 1][band]

Band edges are precomputed as idx2log(thr * 2^4) against the reference
Log2LinConvertion table, so the 4352-entry table is not needed at decode time; the
per-band additives come from the normative scale list scaled by the GRFS branch factor.
Band membership is INCLUSIVE at the lower edge — only the luma plane exercises this
(one block lands exactly on 1352 and the reference places it in the band above), which
is why both planes are tested.

Validated against the ISO reference on real test256.bin, both planes, including the
composition (derived rvs fed through sigma_index must reproduce the indices the
reference entropy coder consumed):
  luma   rvs 40960/40960, mask 40960/40960 (703 coded), sigma 40960/40960
  chroma rvs 24576/24576, mask 24576/24576 (537 coded), sigma 24576/24576

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-18 23:30:54 -04:00