Skip to main content

ArithmeticDecoder

Struct ArithmeticDecoder 

Source
pub struct ArithmeticDecoder<R: Read> { /* private fields */ }
Expand description

Arithmetic decoder using 16-bit precision with E3 underflow prevention.

The decoder maintains an interval [low, high] and a code value read from the bitstream. As symbols are decoded, the interval narrows and bits are shifted out when the MSBs converge.

Implementations§

Source§

impl<R: Read> ArithmeticDecoder<R>

Source

pub fn new(reader: R) -> Result<Self>

Initialize decoder by reading the first 16 bits of encoded data.

Source

pub fn threshold_val(&self, total: u16) -> u16

Compute threshold for symbol lookup given total frequency.

Returns a value in [0, total-1] indicating where the current code falls within the frequency distribution.

Source

pub fn decode_update( &mut self, cum_low: u16, cum_high: u16, total: u16, ) -> Result<()>

Narrow interval after decoding a symbol and renormalize.

  • cum_low: cumulative frequency of all symbols before this one
  • cum_high: cumulative frequency up to and including this symbol
  • total: sum of all symbol frequencies

Auto Trait Implementations§

§

impl<R> Freeze for ArithmeticDecoder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for ArithmeticDecoder<R>
where R: RefUnwindSafe,

§

impl<R> Send for ArithmeticDecoder<R>
where R: Send,

§

impl<R> Sync for ArithmeticDecoder<R>
where R: Sync,

§

impl<R> Unpin for ArithmeticDecoder<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for ArithmeticDecoder<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for ArithmeticDecoder<R>
where R: 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> Same for T

Source§

type Output = T

Should always be Self
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.