wai-rs: fix picture-header per-component flag order (grfs_channel_flags were corrupt) #22
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/jpegai-pih-flags"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
parse_picture_headerread four flags before the GRFS channel flags; only three precede them and the fourth trails the group:Reading four up-front shifted
grfs_channel_flagsone bit late, so every channel flag was wrong — while still landing on the correctend_bit(437), because the extra leading bit was cancelled by consuming one fewer channel flag. A cursor-position assertion catches net drift, not compensating errors.Found by deriving the RVS additive independently: the chroma plane separates cleanly by cwg branch, so its true per-channel assignment is directly derivable and pinned the channel flags to bit 337 (chroma) / 164 (luma). With the corrected offsets, RVS reproduction is byte-exact on both planes (luma 40960/40960, chroma 24576/24576) — independently confirming the counts are 5 and 10, not 4 and 9.
parse_picture_header read four flags before the GRFS channel flags; only three precede them and the fourth trails the group: { multi_threading_r, num_chs, use_cube, rvs_enable, grfs_enable, grfs_channel_flags[num_chs], lsbs_enable } Reading four up-front shifted grfs_channel_flags one bit late, so every channel flag was wrong — while still landing on the correct end_bit (437), because the extra leading bit was cancelled by consuming one fewer channel flag. A cursor-position assertion catches net drift, not compensating errors; the values it produced were silently wrong. Found by deriving the residual-variance-scale (RVS) additive independently: the chroma plane separates cleanly by cwg branch, so its true per-channel assignment is directly derivable and pinned the channel flags to bit 337 (chroma) / 164 (luma) — one earlier than assumed. With the corrected offsets the RVS reproduction is byte-exact on BOTH planes (luma 40960/40960, chroma 24576/24576), which independently confirms the flag counts are 5 (luma) and 10 (chroma), not 4 and 9. Tests updated accordingly and re-validated: end_bit still 437, and the channel-flag counts now match the independently-derived RVS assignment. Co-Authored-By: Claude Opus 4.8 <[email protected]>dcharlot referenced this pull request2026-11-06 13:54:17 -05:00