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>
impl<W: Write> ArithmeticEncoder<W>
Sourcepub fn new(
num_state_bits: u32,
output: BitOutputStream<W>,
) -> Result<Self, ArithError>
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.
Sourcepub fn write(&mut self, freqs: &[u32], symbol: usize) -> Result<(), ArithError>
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.
Sourcepub fn finish(&mut self) -> Result<(), ArithError>
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.
Sourcepub fn state(&self) -> EncoderState
pub fn state(&self) -> EncoderState
Captures the minimal exact encoder state for checkpointing.
Sourcepub fn restore_state(&mut self, state: EncoderState) -> Result<(), ArithError>
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.
Sourcepub fn bit_stream(&self) -> &BitOutputStream<W>
pub fn bit_stream(&self) -> &BitOutputStream<W>
Returns a shared reference to the underlying BitOutputStream.
Sourcepub fn bit_stream_mut(&mut self) -> &mut BitOutputStream<W>
pub fn bit_stream_mut(&mut self) -> &mut BitOutputStream<W>
Returns a mutable reference to the underlying BitOutputStream.
Sourcepub fn into_inner(self) -> Result<W, ArithError>
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.