use super::coeff::{CoeffBlock, CoeffCdfs, TxTypeCtx, decode_coeffs};
use super::symbol::SymbolDecoder;
use super::tile::TileState;
use super::transform::TxSize;
use otf_pixels_core::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Site {
Partition { r: usize, c: usize, bsize4: usize },
SplitOr { r: usize, c: usize, bsize4: usize },
Skip,
CdefIdx,
YMode,
AngleDeltaY,
UvMode,
AngleDeltaUv,
CflSign,
CflAlpha,
TxDepth,
Other,
}
pub(crate) struct CoeffJob<'a> {
pub plane: usize,
pub x: usize,
pub y: usize,
pub prediction: &'a [u16],
pub dc_q: i64,
pub ac_q: i64,
}
pub(crate) trait TileCoder {
fn symbol(&mut self, cdf: &mut [u16], site: Site) -> Result<usize>;
fn literal(&mut self, n: u32, site: Site) -> Result<u32>;
fn ns(&mut self, n: u32) -> Result<u32>;
fn plan_block(&mut self, _state: &TileState, _r: usize, _c: usize, _bw4: usize, _bh4: usize) {}
#[allow(clippy::too_many_arguments, reason = "the coefficient syntax's inputs")]
fn coeffs(
&mut self,
cdfs: &mut CoeffCdfs,
tx_size: TxSize,
tx: TxTypeCtx<'_>,
ptype: usize,
all_zero_ctx: usize,
dc_sign_ctx: usize,
job: &CoeffJob<'_>,
) -> Result<CoeffBlock>;
}
impl TileCoder for SymbolDecoder<'_> {
fn symbol(&mut self, cdf: &mut [u16], _site: Site) -> Result<usize> {
self.read_symbol(cdf)
}
fn literal(&mut self, n: u32, _site: Site) -> Result<u32> {
self.read_literal(n)
}
fn ns(&mut self, n: u32) -> Result<u32> {
self.read_ns(n)
}
fn coeffs(
&mut self,
cdfs: &mut CoeffCdfs,
tx_size: TxSize,
tx: TxTypeCtx<'_>,
ptype: usize,
all_zero_ctx: usize,
dc_sign_ctx: usize,
_job: &CoeffJob<'_>,
) -> Result<CoeffBlock> {
decode_coeffs(self, cdfs, tx_size, tx, ptype, all_zero_ctx, dc_sign_ctx)
}
}