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]>