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
Owner

Ports the last two inputs the mANS sgm decoder needed but that were still 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
rvs_additive  likely = clamp((Σ_8x8|i_s| + 32) >> 6, 0, 4351)
              band   = #{ e ∈ [1003,1352,1937] : likely >= e }
              rvs    = A[grfs_flag ? 0 : 1][band]

The skip decision uses the scale without the RVS additive while sigma_index uses it with — they differ by exactly the rvs values and are easy to conflate.

Band edges are precomputed as idx2log(thr·2^4) against the reference Log2Lin table, so the 4352-entry table isn not needed at decode time. Band membership is inclusive at the lower edge — only luma exercises this (one block lands exactly on 1352), which is why both planes are tested.

Validated against the reference on real test256.bin, both planes, including the composition (derived rvs → sigma_index must reproduce the indices the reference entropy coder consumed):

plane rvs mask sigma
luma 40960/40960 40960/40960 (703 coded) 40960/40960
chroma 24576/24576 24576/24576 (537 coded) 24576/24576
Ports the last two inputs the mANS `sgm` decoder needed but that were still 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 rvs_additive likely = clamp((Σ_8x8|i_s| + 32) >> 6, 0, 4351) band = #{ e ∈ [1003,1352,1937] : likely >= e } rvs = A[grfs_flag ? 0 : 1][band] ``` The skip decision uses the scale **without** the RVS additive while `sigma_index` uses it **with** — they differ by exactly the rvs values and are easy to conflate. Band edges are precomputed as `idx2log(thr·2^4)` against the reference Log2Lin table, so the 4352-entry table isn not needed at decode time. Band membership is **inclusive** at the lower edge — only luma exercises this (one block lands exactly on 1352), which is why both planes are tested. **Validated against the reference on real test256.bin, both planes**, including the composition (derived rvs → `sigma_index` must reproduce the indices the reference entropy coder consumed): | plane | rvs | mask | sigma | |---|---|---|---| | luma | 40960/40960 | 40960/40960 (703 coded) | 40960/40960 | | chroma | 24576/24576 | 24576/24576 (537 coded) | 24576/24576 |
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]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!28
No description provided.