pub struct RangeDecoder<R: Read> { /* private fields */ }Expand description
Streaming range‐decoder for arithmetic coding.
The decoder maintains three internal registers:
low: the low end of the current coding intervalcode: the buffered input bits read from the streamrange: the size of the current coding interval
On each symbol decode, you first call [get_freq] to map the current code
to a frequency within the total frequency range, then call [decode]
to narrow the interval and consume bits as needed.
§Example
use std::fs::File;
use ppmd_core::{RangeDecoder, PpmModel, PpmResult};
fn decode_stream() -> PpmResult<()> {
let file = File::open("data.ppm")?;
let mut decoder = RangeDecoder::new(file)?;
let mut model = PpmModel::new(5)?;
let mut history = Vec::new();
let mut out_byte = [0u8; 1];
// Repeatedly call `decode_symbol` until end of stream
while model.decode_symbol(&mut decoder, &mut history, &mut out_byte).is_ok() {
print!("{}", out_byte[0] as char);
}
Ok(())
}Implementations§
Source§impl<R: Read> RangeDecoder<R>
impl<R: Read> RangeDecoder<R>
Sourcepub fn new(reader: R) -> PpmResult<Self>
pub fn new(reader: R) -> PpmResult<Self>
Initialize a new RangeDecoder by reading the first 4 bytes
from reader into the internal code register.
The range decoder uses these first 32 bits as its starting buffer.
Subsequent calls to [get_freq] and [decode] will consume more
bytes from reader as needed to renormalize the interval.
§Errors
Returns PpmError::IoError if reading the initial 4-byte code prefix fails.
Auto Trait Implementations§
impl<R> Freeze for RangeDecoder<R>where
R: Freeze,
impl<R> RefUnwindSafe for RangeDecoder<R>where
R: RefUnwindSafe,
impl<R> Send for RangeDecoder<R>where
R: Send,
impl<R> Sync for RangeDecoder<R>where
R: Sync,
impl<R> Unpin for RangeDecoder<R>where
R: Unpin,
impl<R> UnsafeUnpin for RangeDecoder<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for RangeDecoder<R>where
R: 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