wai-rs: jpegai_bitstream — codestream container + MSB-first header bit reader #16
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/jpegai-bitstream"
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?
The decoder entry point. A codestream is a sequence of marker segments:
marker(2B BE) + expgolomb_k0(size) + byte-align + payload. Header substreams (PIH/TON) are plain bit-packed, read MSB-first — headers are NOT arithmetic-coded (only latent substreams are, → jpegai_mans).BitReader— faithful port of the referenceEcLibDirect::read_bits(MSB-first, bit-granular cursor)read_expgolomb_k0— segment payload lengthsparse_container— marker walk →[Segment]Validated on the real test256.bin codestream: full layout SOC/PIH(49)/TON(63)/RDI(1)/SORP(97)/SORS(47)/SOZ(83)/EOC, picture-header prefix → 256x256, 4:4:4, colour_transform_idx=1. Cross-check: SORP/SORS/SOZ sizes (97/47/83) equal the mANS
memlengths — container parse and byte-exact entropy decode agree on the same bytes.The decoder's entry point. A codestream is a sequence of marker segments; each (except the marker-only SOC/EOC) is `marker(2B big-endian) + expgolomb_k0(size) + byte-align + payload`. The header substreams (PIH/TON) are plain bit-packed and read MSB-first — the headers are NOT arithmetic-coded (only the latent substreams are, and those go to jpegai_mans). BitReader faithful port of the reference EcLibDirect::read_bits — MSB-first within each byte, accumulated MSB-first, bit-granular cursor, reads past end return the available bits (matching the bounds check) read_expgolomb_k0 unsigned exp-Golomb k=0, for the segment payload lengths parse_container walk the markers -> [Segment{marker, start, len}] Validated against the real test256.bin codestream: full segment layout SOC/PIH(49)/TON(63)/RDI(1)/SORP(97)/SORS(47)/SOZ(83)/EOC, and the picture-header prefix decodes to 256x256, 4:4:4, colour_transform_idx=1, level 52. Cross-check: the SORP/SORS/SOZ payload sizes (97/47/83) equal the `mem` lengths the byte-exact mANS decoder consumes — the container parse and the entropy decode agree on the same bytes. Co-Authored-By: Claude Opus 4.8 <[email protected]>dcharlot referenced this pull request2026-11-06 13:54:17 -05:00