Skip to main content

ZpEncoder

Struct ZpEncoder 

Source
pub struct ZpEncoder { /* private fields */ }
Expand description

ZP adaptive binary arithmetic encoder.

All internal registers (a, subend) are u32 to match DjVuLibre’s unsigned int types. They hold u16-range values but intermediate arithmetic can exceed 0xFFFF, which is critical for correct carry propagation in zemit.

Implementations§

Source§

impl ZpEncoder

Source

pub fn new() -> Self

Source

pub fn encode_bit(&mut self, ctx: &mut u8, bit: bool)

Encode one bit using an adaptive probability context.

Matches DjVuLibre’s inline encoder(int bit, BitContext &ctx):

  • LPS always calls encode_lps
  • MPS with z >= 0x8000 calls encode_mps
  • MPS with z < 0x8000 takes fast path (a = z, no shift)
Source

pub fn encode_passthrough_iw44(&mut self, bit: bool)

Encode one bit in IW44 passthrough mode (threshold z = 0x8000 + 3a/8).

Counterpart to [ZpDecoder::decode_passthrough_iw44]; must produce a stream that it correctly decodes.

Source

pub fn encode_passthrough(&mut self, bit: bool)

Source

pub fn finish(self) -> Vec<u8>

Flush the encoder and return the compressed byte stream.

Trait Implementations§

Source§

impl Default for ZpEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.