use crate::api::JxlCms;
use std::sync::Arc;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct JxlDecoderLimits {
pub max_pixels: Option<usize>,
pub max_extra_channels: Option<usize>,
pub max_icc_size: Option<usize>,
pub max_tree_size: Option<usize>,
pub max_patches: Option<usize>,
pub max_spline_points: Option<u32>,
pub max_reference_frames: Option<usize>,
pub max_memory_bytes: Option<u64>,
}
impl Default for JxlDecoderLimits {
fn default() -> Self {
let max_memory = if cfg!(target_pointer_width = "32") {
2u64 << 30 } else {
4u64 << 30 };
Self {
max_pixels: Some(1 << 28), max_extra_channels: Some(256), max_icc_size: Some(1 << 28), max_tree_size: Some(1 << 22), max_patches: None, max_spline_points: Some(1 << 20), max_reference_frames: Some(4), max_memory_bytes: Some(max_memory),
}
}
}
impl JxlDecoderLimits {
pub fn unlimited() -> Self {
Self {
max_pixels: None,
max_extra_channels: None,
max_icc_size: None,
max_tree_size: None,
max_patches: None,
max_spline_points: None,
max_reference_frames: None,
max_memory_bytes: None,
}
}
pub fn restrictive() -> Self {
Self {
max_pixels: Some(100_000_000), max_extra_channels: Some(16), max_icc_size: Some(1 << 20), max_tree_size: Some(1 << 20), max_patches: Some(1 << 16), max_spline_points: Some(1 << 16), max_reference_frames: Some(2), max_memory_bytes: Some(1 << 30), }
}
}
pub enum JxlProgressiveMode {
Eager,
Pass,
FullFrame,
}
#[non_exhaustive]
pub struct JxlDecoderOptions {
pub adjust_orientation: bool,
pub render_spot_colors: bool,
pub coalescing: bool,
pub desired_intensity_target: Option<f32>,
pub skip_preview: bool,
pub progressive_mode: JxlProgressiveMode,
pub cms: Option<Box<dyn JxlCms>>,
pub high_precision: bool,
pub premultiply_output: bool,
pub limits: JxlDecoderLimits,
pub stop: Arc<dyn enough::Stop>,
pub parallel: bool,
}
impl Default for JxlDecoderOptions {
fn default() -> Self {
Self {
adjust_orientation: true,
render_spot_colors: true,
coalescing: true,
skip_preview: true,
desired_intensity_target: None,
progressive_mode: JxlProgressiveMode::Pass,
cms: None,
high_precision: false,
premultiply_output: false,
limits: JxlDecoderLimits::default(),
stop: Arc::new(enough::Unstoppable),
parallel: cfg!(feature = "threads"),
}
}
}