pub struct RangeEncoder<W: Write> { /* private fields */ }Expand description
Streaming range‐encoder for arithmetic coding.
The encoder maintains three key internal values:
low: the low end of the current coding intervalrange: the size of the current coding intervalbuffer: a byte buffer (flushed in 4 KB chunks) holding the high‐order output bytes
For each symbol you wish to encode, call encode with:
cum_freq: cumulative frequency of all symbols less than the one you’re encodingfreq: the frequency of the symbol itselftot_freq: the total of all symbol frequencies in the current context
After encoding every symbol, call finish to flush any remaining bytes
and retrieve the underlying writer.
§Example
use std::fs::File;
use ppmd_core::{RangeEncoder, PpmResult};
fn encode_stream() -> PpmResult<()> {
let file = File::create("out.ppm")?;
let mut encoder = RangeEncoder::new(file);
// Suppose `model` yields (cum, freq, tot) triples for each byte:
for (cum, freq, tot) in model.symbols() {
encoder.encode(cum, freq, tot)?;
}
// Finalize and get back the file writer
let _file = encoder.finish()?;
Ok(())
}Implementations§
Source§impl<W: Write> RangeEncoder<W>
impl<W: Write> RangeEncoder<W>
Auto Trait Implementations§
impl<W> Freeze for RangeEncoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for RangeEncoder<W>where
W: RefUnwindSafe,
impl<W> Send for RangeEncoder<W>where
W: Send,
impl<W> Sync for RangeEncoder<W>where
W: Sync,
impl<W> Unpin for RangeEncoder<W>where
W: Unpin,
impl<W> UnsafeUnpin for RangeEncoder<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for RangeEncoder<W>where
W: UnwindSafe,
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