Skip to main content

Module bits

Module bits 

Source
Expand description

High-throughput bit readers (“bit pumps”).

RAW codecs consume bit streams in several orders:

PumpBit order inside a wordUsed by (examples)
BitPumpMsbMSB-first, bytes in orderNikon, Pentax, Canon CRW/CRX, packed BE
BitPumpJpegMSB-first with FF 00 unstuffinglossless JPEG (CR2, DNG, Sony, Kodak…)
BitPumpLsbLSB-first, bytes in orderPanasonic, Olympus? (no), packed LE
BitPumpMsb16MSB-first inside 16-bit LE wordsSony/Olympus packed variants, Fuji
BitPumpMsb32MSB-first inside 32-bit LE wordsSamsung, Phase One, Hasselblad packed

All pumps keep a 64-bit cache. The hot refill reads 8 bytes at once and tops the cache up to at least 56 valid bits without per-byte branches; the last few bytes of a stream go through a bounds-checked slow path that pads with zeros. Reading past the end never panics: it yields zero bits and increments an overrun counter that decoders check (see BitRead::overrun) to reject truncated/corrupt data instead of looping forever.

Structs§

BitPumpJpeg
MSB-first pump for JPEG entropy-coded segments: removes FF 00 byte stuffing and stops (feeding zeros) at a marker (FF xx, xx != 0).
BitPumpLsb
LSB-first bit pump (little-endian bit order).
BitPumpMsb
MSB-first bit pump (big-endian bit order).
BitPumpMsbWords
MSB-first bit order inside little-endian words of W bytes (2 or 4).

Traits§

BitRead
Common interface of all bit pumps.

Functions§

extend_diff
Sign-extend a JPEG-style difference value: len bits v → signed diff.

Type Aliases§

BitPumpMsb16
MSB-first inside 16-bit little-endian words.
BitPumpMsb32
MSB-first inside 32-bit little-endian words.