jxl_color/cms.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use crate::RenderingIntent;
/// Color management system that handles ICCv4 profiles.
///
/// Implementors can implement `transform_impl` to integrate into external color management system.
pub trait ColorManagementSystem {
fn transform_impl(
&self,
from: &[u8],
to: &[u8],
intent: RenderingIntent,
channels: &mut [&mut [f32]],
) -> Result<usize, Box<dyn std::error::Error + Send + Sync + 'static>>;
/// Performs color transformation between two ICC profiles.
///
/// # Errors
/// This function will return an error if the internal CMS implementation returned an error.
fn transform(
&self,
from: &[u8],
to: &[u8],
intent: RenderingIntent,
channels: &mut [&mut [f32]],
) -> Result<usize, crate::Error> {
self.transform_impl(from, to, intent, channels)
.map_err(crate::Error::CmsFailure)
}
/// Returns whether the CMS supports linear transfer function.
///
/// This method will return `false` if it doesn't support (or it lacks precision to handle)
/// linear transfer function.
fn supports_linear_tf(&self) -> bool {
true
}
}
/// "Null" color management system that fails on every operation.
#[derive(Debug, Copy, Clone)]
pub struct NullCms;
impl ColorManagementSystem for NullCms {
fn transform_impl(
&self,
_: &[u8],
_: &[u8],
_: RenderingIntent,
_: &mut [&mut [f32]],
) -> Result<usize, Box<dyn std::error::Error + Send + Sync + 'static>> {
Err(Box::new(crate::Error::CmsNotAvailable))
}
fn transform(
&self,
_: &[u8],
_: &[u8],
_: RenderingIntent,
_: &mut [&mut [f32]],
) -> Result<usize, crate::Error> {
Err(crate::Error::CmsNotAvailable)
}
}