pub struct BitReader<'a> { /* private fields */ }Expand description
Bit-level reader for JPEG entropy-coded data.
Handles JPEG byte-stuffing (0xFF00 → 0xFF) and marker detection. Bits are read MSB-first from a 32-bit internal buffer.
Implementations§
Source§impl<'a> BitReader<'a>
impl<'a> BitReader<'a>
Sourcepub fn new(data: &'a [u8], pos: usize) -> Self
pub fn new(data: &'a [u8], pos: usize) -> Self
Create a new BitReader over the given byte slice.
pos should point to the first byte of entropy-coded data (after SOS header).
Sourcepub fn read_bits(&mut self, count: u8) -> Result<u16>
pub fn read_bits(&mut self, count: u8) -> Result<u16>
Read count bits (1–16) and return them right-aligned.
Sourcepub fn peek_bits(&mut self, count: u8) -> Result<u16>
pub fn peek_bits(&mut self, count: u8) -> Result<u16>
Peek at the top count bits without consuming them.
Sourcepub fn byte_align(&mut self)
pub fn byte_align(&mut self)
Align to the next byte boundary by discarding remaining bits in the current byte.
Sourcepub fn marker_found(&self) -> Option<u8>
pub fn marker_found(&self) -> Option<u8>
Returns the marker byte if a marker was encountered during reading.
Sourcepub fn check_restart_marker(&mut self) -> Result<Option<u8>>
pub fn check_restart_marker(&mut self) -> Result<Option<u8>>
Check if a restart marker (0xFFD0–0xFFD7) is present.
Checks both the marker_found flag (set if fill_byte already consumed
a RST marker during Huffman decoding) and the next bytes in the stream.
If found, consume the marker and return the marker’s low nibble (0–7).