Skip to main content

SymbolEncoder

Struct SymbolEncoder 

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

Encoder for the AV1 symbol (range) coder.

Feed symbols with SymbolEncoder::encode_symbol (CDF-coded) and equiprobable bits with SymbolEncoder::encode_literal, then call SymbolEncoder::finish to flush and obtain the coded bytes. Those bytes are exactly what a decoder consumes via init_symbol(sz) (AV1 §8.2.2) where sz is the returned length.

Implementations§

Source§

impl SymbolEncoder

Source

pub fn new() -> Self

Creates an encoder with the initial range state of AV1’s symbol coder.

Source

pub fn encode_symbol(&mut self, symbol: usize, cdf: &[u16])

Encodes symbol against a static cumulative cdf (cdf.len() symbols, cdf[last] == 32768).

§Panics

Debug builds assert symbol < cdf.len() and the CDF normalisation invariants.

Source

pub fn encode_symbol_adapt( &mut self, symbol: usize, cdf: &mut [u16], count: &mut u16, )

Encodes symbol against an adapting cumulative cdf, then applies the §8.2.6 CDF adaptation in place (disable_cdf_update = 0). count is the spec’s trailing cdf[N] adaptation counter (start it at 0 for a freshly initialised context); it is bumped here, up to a maximum of 32. A decoder must apply the identical §8.2.6 update (decode the symbol, then the same adaptation) with the same count so its CDF tracks the encoder’s exactly.

§Panics

Debug builds assert symbol < cdf.len() and the CDF normalisation invariants.

Source

pub fn encode_literal(&mut self, value: u32, n: u32)

Encodes the low n bits of value as equiprobable bits, most-significant bit first.

This is the inverse of the decoder’s read_literal(n) (AV1 §8.2.5), which itself calls read_bool() (§8.2.3) with the fixed CDF {1 << 14, 1 << 15}.

Source

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

Flushes the coder and returns the coded bytes. Mirrors od_ec_enc_done: it emits the minimum number of bits that decode correctly regardless of trailing padding, then resolves the buffered carries into a big-endian byte stream.

Trait Implementations§

Source§

impl Clone for SymbolEncoder

Source§

fn clone(&self) -> SymbolEncoder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolEncoder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SymbolEncoder

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.