use crate::adaptive_quant::AqMapScratch;
use crate::enc_group::AcGroupScratch;
use crate::enc_lossless::{GradientScratch, LzToken, PickThresholdScratch};
use crate::entropy::{
CLUSTERS_LIMIT, FixedClusterScratch, Histogram, HuffmanNode, HybridUintConfig, PrefixCode,
};
const LZ77_CANDIDATE_CAPACITY: usize = 1 << 19;
pub(crate) const LZ77_MAX_CONTEXTS: usize = 221;
pub(crate) struct LzEntropyScratch {
pub(crate) histograms: [Histogram; LZ77_MAX_CONTEXTS],
pub(crate) prefix_codes: [PrefixCode; LZ77_MAX_CONTEXTS],
pub(crate) context_map: [u8; LZ77_MAX_CONTEXTS],
pub(crate) configs: [HybridUintConfig; CLUSTERS_LIMIT],
pub(crate) clustering: FixedClusterScratch<LZ77_MAX_CONTEXTS>,
}
impl Default for LzEntropyScratch {
fn default() -> Self {
Self {
histograms: std::array::from_fn(|_| Histogram::new()),
prefix_codes: [PrefixCode::zero(); LZ77_MAX_CONTEXTS],
context_map: [0; LZ77_MAX_CONTEXTS],
configs: [HybridUintConfig::DEFAULT; CLUSTERS_LIMIT],
clustering: FixedClusterScratch::default(),
}
}
}
pub(crate) struct CoderScratch {
pub(crate) aq_map: AqMapScratch,
pub(crate) structure_corrections: Vec<f32>,
pub(crate) lz_repetitions: Vec<u32>,
pub(crate) lz_depth: Vec<u32>,
pub(crate) lz_candidate: Vec<LzToken>,
pub(crate) lz_entropy: LzEntropyScratch,
pub(crate) recon: [[f32; 1024]; 8],
pub(crate) dark_octile: Vec<f32>,
pub(crate) huffman_pool: Vec<HuffmanNode>,
pub(crate) ac_group: AcGroupScratch,
pub(crate) transform_gather: [f32; 1024],
pub(crate) strategy_coeffs: [[f32; 1024]; 3],
pub(crate) gradient: GradientScratch,
pub(crate) order0_entropy: Vec<u64>,
pub(crate) threshold: PickThresholdScratch,
}
impl Default for CoderScratch {
fn default() -> Self {
Self {
aq_map: AqMapScratch {
aq_map: vec![0.0; 256 * 256],
secondary: vec![0.0; 2048 + 512 * 512],
},
structure_corrections: vec![0.0; 256 * 256],
lz_repetitions: vec![0; 1 << 14],
lz_depth: vec![u32::MAX; 1 << 20],
lz_candidate: Vec::with_capacity(LZ77_CANDIDATE_CAPACITY),
lz_entropy: LzEntropyScratch::default(),
recon: [[0.0; 1024]; 8],
dark_octile: vec![0.0; 32 * 32],
huffman_pool: Vec::with_capacity(1024),
ac_group: AcGroupScratch::default(),
transform_gather: [0.0; 1024],
strategy_coeffs: [[0.0; 1024]; 3],
gradient: GradientScratch {
cur: vec![0; 256],
prev: vec![0; 256],
buf: vec![0; 256],
},
order0_entropy: vec![0; 1024],
threshold: PickThresholdScratch {
hist_scratch: vec![0; 3 * 1025],
},
}
}
}