#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DecodeSettings {
strict: bool,
}
impl DecodeSettings {
#[must_use]
pub const fn lenient() -> Self {
Self { strict: false }
}
#[must_use]
pub const fn strict() -> Self {
Self { strict: true }
}
#[must_use]
pub const fn is_strict(self) -> bool {
self.strict
}
#[must_use]
pub const fn lenient_tolerance_enabled(self) -> bool {
!self.strict
}
pub(crate) const fn to_native(
self,
target_resolution: Option<(u32, u32)>,
) -> j2k_native::DecodeSettings {
j2k_native::DecodeSettings {
resolve_palette_indices: true,
strict: self.strict,
target_resolution,
}
}
}
impl Default for DecodeSettings {
fn default() -> Self {
Self::strict()
}
}
#[cfg(test)]
mod tests {
use super::DecodeSettings;
#[test]
fn facade_policy_preserves_strictness_and_internal_geometry() {
assert!(DecodeSettings::default().is_strict());
assert!(!DecodeSettings::default().lenient_tolerance_enabled());
assert!(!DecodeSettings::lenient().is_strict());
assert!(DecodeSettings::strict().is_strict());
let native = DecodeSettings::strict().to_native(Some((17, 11)));
assert!(native.resolve_palette_indices);
assert!(native.strict);
assert_eq!(native.target_resolution, Some((17, 11)));
}
}