Skip to main content

ZpDecoder

Struct ZpDecoder 

Source
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: u32

Current interval width register (16-bit value held in low 16 bits).

§c: u32

Current code (value within the interval) register (16-bit value held in low 16 bits).

§fence: u32

Cached upper bound for the fast decode path (= min(c, 0x7fff)).

§bit_buf: u32

Bit buffer for feeding bits into the code register.

§bit_count: i32

Number of valid bits remaining in bit_buf.

§data: &'a [u8]

Compressed input bytes.

§pos: usize

Current read position within data.

Implementations§

Source§

impl<'a> ZpDecoder<'a>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> Freeze for ZpDecoder<'a>

§

impl<'a> RefUnwindSafe for ZpDecoder<'a>

§

impl<'a> Send for ZpDecoder<'a>

§

impl<'a> Sync for ZpDecoder<'a>

§

impl<'a> Unpin for ZpDecoder<'a>

§

impl<'a> UnsafeUnpin for ZpDecoder<'a>

§

impl<'a> UnwindSafe for ZpDecoder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.