Skip to main content

ArithmeticEncoder

Struct ArithmeticEncoder 

Source
pub struct ArithmeticEncoder<W> { /* private fields */ }
Expand description

Range arithmetic encoder writing big-endian bits to a BitOutputStream.

Implementations§

Source§

impl<W: Write> ArithmeticEncoder<W>

Source

pub fn new( num_state_bits: u32, output: BitOutputStream<W>, ) -> Result<Self, ArithError>

Constructs an encoder using num_state_bits (typically DEFAULT_STATE_BITS).

§Errors

Returns ArithError::InvalidStateBits if num_state_bits is not in 1..=62.

Source

pub fn write(&mut self, freqs: &[u32], symbol: usize) -> Result<(), ArithError>

Encodes symbol using the cumulative frequency table freqs.

freqs[i] must hold the inclusive cumulative frequency of symbols 0..=i, with freqs.last() equal to the total frequency mass (<= minimum_range).

§Errors

Returns ArithError if freqs or symbol is invalid or writing fails.

Source

pub fn finish(&mut self) -> Result<(), ArithError>

Terminates the arithmetic stream by emitting the final disambiguating bit.

Call BitOutputStream::finish_padding on Self::bit_stream_mut afterwards to pad the final partial byte, or call Self::into_inner directly instead of calling finish.

§Errors

Returns ArithError::Io if writing to the underlying bit stream fails.

Source

pub fn state(&self) -> EncoderState

Captures the minimal exact encoder state for checkpointing.

Source

pub fn restore_state(&mut self, state: EncoderState) -> Result<(), ArithError>

Restores a previously captured EncoderState.

Note that the underlying BitOutputStream must also be restored separately.

§Errors

Returns ArithError::StateWidthMismatch if num_state_bits differs.

Source

pub fn bit_stream(&self) -> &BitOutputStream<W>

Returns a shared reference to the underlying BitOutputStream.

Source

pub fn bit_stream_mut(&mut self) -> &mut BitOutputStream<W>

Returns a mutable reference to the underlying BitOutputStream.

Source

pub fn into_inner(self) -> Result<W, ArithError>

Finishes arithmetic coding, pads the bit stream, and returns the underlying writer.

§Errors

Returns ArithError if finishing or flushing fails.

Trait Implementations§

Source§

impl<W: Debug> Debug for ArithmeticEncoder<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for ArithmeticEncoder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for ArithmeticEncoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for ArithmeticEncoder<W>
where W: Send,

§

impl<W> Sync for ArithmeticEncoder<W>
where W: Sync,

§

impl<W> Unpin for ArithmeticEncoder<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for ArithmeticEncoder<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for ArithmeticEncoder<W>
where W: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.