wai-rs: fix picture-header per-component flag order (grfs_channel_flags were corrupt) #22

Merged
dcharlot merged 1 commit from fix/jpegai-pih-flags into main 2026-07-18 02:05:00 -04:00
Owner

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.

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. 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]>
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!22
No description provided.