pub struct TokenEncoder { /* private fields */ }Expand description
Phase-2 token-block encoder handle.
A thin wrapper around the §13 encode_coeff_block free function
that owns its own BoolEncoder + resolved coeff_probs table
and exposes a stateful encode_block method. Useful for the
higher-level encoder rounds that will emit many blocks into the
same partition.
The encoder is stateless across blocks in the §13.3 sense —
the ctx3 rollover lives entirely inside encode_coeff_block and
the neighbour predictors are passed in per call. What the wrapper
owns is the underlying entropy-coder byte stream + the (large)
probability table.
Implementations§
Source§impl TokenEncoder
impl TokenEncoder
Sourcepub fn new(coeff_probs: CoeffProbs) -> Self
pub fn new(coeff_probs: CoeffProbs) -> Self
Build an encoder against the supplied resolved coefficient
probabilities. Pass crate::DEFAULT_COEFF_PROBS (or the
merge_default_token_probs(&updates) result) to match the
decode_block path callers go through on the other side.
Sourcepub fn encode_block(
&mut self,
block_type: BlockType,
above_has_nonzero: bool,
left_has_nonzero: bool,
coeffs: &[i16; 16],
) -> Result<usize, TokenEncodeError>
pub fn encode_block( &mut self, block_type: BlockType, above_has_nonzero: bool, left_has_nonzero: bool, coeffs: &[i16; 16], ) -> Result<usize, TokenEncodeError>
Encode one 16-coefficient sub-block. See
encode_coeff_block for the parameter semantics.
Sourcepub fn finish(self) -> Vec<u8> ⓘ
pub fn finish(self) -> Vec<u8> ⓘ
Finalise the underlying BoolEncoder and return the byte
stream the decoder should consume.
Sourcepub fn bytes_written(&self) -> usize
pub fn bytes_written(&self) -> usize
Number of bytes committed so far (excludes the §7.3 4-byte
flush trailer that finish will append).