pub struct TableArithmeticCoder { /* private fields */ }Expand description
High-throughput table-based arithmetic coder.
Uses pre-computed probability tables for O(1) symbol lookup, avoiding floating-point division in the inner loop. This matches the approach used in many modern video entropy engines.
§Design
The coding interval is maintained as (low, range) in a 32-bit window.
After each symbol, the interval is renormalised to keep range in the
half-open interval [LOW_RANGE_MIN, LOW_RANGE_MAX) by emitting bytes.
§Example
use oximedia_codec::entropy_coding::{TableArithmeticCoder, build_prob_table};
let freqs = [10u32, 30, 20, 5];
let table = build_prob_table(&freqs);
let mut enc = TableArithmeticCoder::new();
enc.encode_symbol(1, &table[1]);
enc.encode_symbol(0, &table[0]);
let bitstream = enc.flush();
assert!(!bitstream.is_empty() || true); // output depends on stateImplementations§
Source§impl TableArithmeticCoder
impl TableArithmeticCoder
Sourcepub fn encode_symbol(&mut self, sym_is_high: bool, entry: &ProbTableEntry)
pub fn encode_symbol(&mut self, sym_is_high: bool, entry: &ProbTableEntry)
Encode one symbol using its pre-computed ProbTableEntry.
sym_is_high selects the high partition when true.
Sourcepub fn bytes_emitted(&self) -> usize
pub fn bytes_emitted(&self) -> usize
Returns the number of bytes emitted so far (before flush).
Trait Implementations§
Source§impl Clone for TableArithmeticCoder
impl Clone for TableArithmeticCoder
Source§fn clone(&self) -> TableArithmeticCoder
fn clone(&self) -> TableArithmeticCoder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TableArithmeticCoder
impl RefUnwindSafe for TableArithmeticCoder
impl Send for TableArithmeticCoder
impl Sync for TableArithmeticCoder
impl Unpin for TableArithmeticCoder
impl UnsafeUnpin for TableArithmeticCoder
impl UnwindSafe for TableArithmeticCoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more