wai-rs: jpegai_bitstream — full picture-header parser #17

Merged
dcharlot merged 1 commit from feat/jpegai-pih into main 2026-07-16 07:22:51 -04:00
Owner

Decodes the complete PIH substream → PictureHeader: fixed prefix (profile, synthesis transforms, level, dims, subsampling, colour_transform_idx, model_id), CCS_SGMM header (multi_threading_z, quantizer beta F/O headers + independent_beta_uv, region_partitioning), per-component tool groups (multi_threading_r, num_chs, then use_cube_flags → lsbs → rvs → grfs + channel flags), gain_3D, synthesis_tile_enable.

Field order + conditionals ported from the reference decode_header sources — notably use_cube precedes lsbs, and synthesis_tile_enable trails the groups (both differ from header_spec.json order; they follow the recursive tool-walk).

Validated on real test256.bin: 256x256 4:4:4, colour_idx=1, num_chs 160/96, per-component flags, and end_bit=437 — every field consumed exactly up to the 3-bit pad of the 49-byte PIH. The grfs channel-flag counts (4/9) independently match the sigma-additions gain fixture. Un-exercised branches (region splits, independent beta, signalled colour matrix) follow the reference syntax, untested.

Decodes the complete PIH substream → `PictureHeader`: fixed prefix (profile, synthesis transforms, level, dims, subsampling, colour_transform_idx, model_id), CCS_SGMM header (multi_threading_z, quantizer beta F/O headers + independent_beta_uv, region_partitioning), per-component tool groups (multi_threading_r, num_chs, then use_cube_flags → lsbs → rvs → grfs + channel flags), gain_3D, synthesis_tile_enable. Field order + conditionals ported from the reference `decode_header` sources — notably **use_cube precedes lsbs**, and **synthesis_tile_enable trails the groups** (both differ from header_spec.json order; they follow the recursive tool-walk). **Validated on real test256.bin:** 256x256 4:4:4, colour_idx=1, num_chs 160/96, per-component flags, and `end_bit=437` — **every field consumed exactly** up to the 3-bit pad of the 49-byte PIH. The grfs channel-flag counts (4/9) independently match the sigma-additions gain fixture. Un-exercised branches (region splits, independent beta, signalled colour matrix) follow the reference syntax, untested.
Decodes the complete PIH substream into a PictureHeader struct: the fixed prefix
(profile, synthesis transforms, level, dimensions, sub-sampling, colour_transform_idx,
model_id), then CCS_SGMM::decode_header (multi_threading_z, the quantizer beta F/O
headers with independent_beta_uv, region_partitioning), then the per-component tool
groups (multi_threading_r, num_chs, and the tools in sub-tool order: use_cube_flags,
lsbs_enable, rvs_enable, grfs_enable + per-channel flags), gain_3D_enable, and
synthesis_tile_enable per component.

Field order and conditionals ported from the reference decode_header sources
(ccs_sgmm_tool, quantization, sep_chan_tool, res_var_scale, skip_mode); notably
use_cube_flags precedes lsbs_enable, and synthesis_tile_enable trails the component
groups (both differ from the header_spec.json listing order).

Validated on real test256.bin: 256x256 4:4:4, colour_transform_idx=1, num_chs 160/96,
per-component tool flags, and end_bit=437 — i.e. EVERY field consumed exactly, up to
the 3-bit pad closing the 49-byte PIH. The grfs channel-flag counts (4 luma, 9 chroma)
independently match the sigma-additions gain fixture. Branches not exercised by this
4:4:4 single-tile stream (region sub-splits, independent beta, signalled colour matrix,
multi-threading) follow the reference syntax but are untested.

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