pub struct ZpDecoder<'a> {
pub a: u32,
pub c: u32,
pub fence: u32,
pub bit_buf: u32,
pub bit_count: i32,
pub data: &'a [u8],
pub pos: usize,
}Expand description
ZP (Z-Prime) adaptive binary arithmetic decoder.
Implements the decoder described in the DjVu v3 specification. The decoder maintains a probability model for each context and adapts the model as bits are decoded.
Context bytes encode both the probability state index and the current MPS (most probable symbol) value. The low bit of the context byte indicates the current MPS; the remaining bits encode the probability state.
Fields§
§a: u32Current interval width register (16-bit value held in low 16 bits).
c: u32Current code (value within the interval) register (16-bit value held in low 16 bits).
fence: u32Cached upper bound for the fast decode path (= min(c, 0x7fff)).
bit_buf: u32Bit buffer for feeding bits into the code register.
bit_count: i32Number of valid bits remaining in bit_buf.
data: &'a [u8]Compressed input bytes.
pos: usizeCurrent read position within data.
Implementations§
Source§impl<'a> ZpDecoder<'a>
impl<'a> ZpDecoder<'a>
Sourcepub fn new(data: &'a [u8]) -> Result<Self, ZpError>
pub fn new(data: &'a [u8]) -> Result<Self, ZpError>
Construct a new ZP decoder from the given compressed byte slice.
Reads the initial code register from the first two bytes of data.
§Errors
Returns ZpError::TooShort if data has fewer than 2 bytes.
Sourcepub fn decode_bit(&mut self, ctx: &mut u8) -> bool
pub fn decode_bit(&mut self, ctx: &mut u8) -> bool
Decode one bit using an adaptive probability context.
ctx is a mutable context byte encoding the current probability state
and MPS value. It is updated in-place after each call.
Returns true if the decoded bit is 1.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Returns true once all real input bytes have been consumed.
After exhaustion the coder returns 0xFF bytes indefinitely, producing
deterministic but meaningless bits. Callers may use this to skip
remaining work that would otherwise loop on constant input.
Sourcepub fn decode_passthrough(&mut self) -> bool
pub fn decode_passthrough(&mut self) -> bool
Decode one bit in passthrough (context-free) mode.
Used by BZZ to decode raw integer values (block size, BWT index).
The threshold is z = 0x8000 + (a >> 1).
Returns true if the decoded bit is 1.
Sourcepub fn decode_passthrough_iw44(&mut self) -> bool
pub fn decode_passthrough_iw44(&mut self) -> bool
Decode one bit in IW44 passthrough mode.
The threshold is z = 0x8000 + (3 * a / 8).
Returns true if the decoded bit is 1.