use compression_core::Level;
use zrip::{MAX_LEVEL, MIN_LEVEL};
const DEFAULT_LEVEL: i32 = 3;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CParameter(CParameterInner);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum CParameterInner {
WindowLog(u32),
EnableLongDistanceMatching(bool),
}
impl CParameter {
pub fn quality(level: Level) -> i32 {
match level {
Level::Fastest => 1,
Level::Best => MAX_LEVEL,
Level::Precise(0) => DEFAULT_LEVEL,
Level::Precise(quality) => quality.clamp(MIN_LEVEL, MAX_LEVEL),
_ => DEFAULT_LEVEL,
}
}
pub fn window_log(value: u32) -> Self {
Self(CParameterInner::WindowLog(value))
}
pub fn enable_long_distance_matching(value: bool) -> Self {
Self(CParameterInner::EnableLongDistanceMatching(value))
}
}
pub(crate) fn options(params: &[CParameter]) -> zrip::Options {
params
.iter()
.fold(zrip::Options::default(), |opts, param| match param.0 {
CParameterInner::WindowLog(value) => opts.window_log(value),
CParameterInner::EnableLongDistanceMatching(value) => opts.ldm(value),
})
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct DParameter(DParameterInner);
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum DParameterInner {
WindowLogMax(u32),
}
impl DParameter {
pub fn window_log_max(value: u32) -> Self {
Self(DParameterInner::WindowLogMax(value))
}
}
pub(crate) fn max_window(params: &[DParameter]) -> Option<u64> {
params.iter().fold(None, |_, param| match param.0 {
DParameterInner::WindowLogMax(0) => None,
DParameterInner::WindowLogMax(value) => Some(1u64 << value.min(63)),
})
}