Skip to main content

ColorManagement

Trait ColorManagement 

Source
pub trait ColorManagement {
    type Error: Debug;

    // Required methods
    fn build_transform(
        &self,
        src_icc: &[u8],
        dst_icc: &[u8],
    ) -> Result<Box<dyn RowTransform>, Self::Error>;
    fn identify_profile(&self, icc: &[u8]) -> Option<Cicp>;

    // Provided method
    fn build_transform_for_format(
        &self,
        src_icc: &[u8],
        dst_icc: &[u8],
        src_format: PixelFormat,
        dst_format: PixelFormat,
    ) -> Result<Box<dyn RowTransform>, Self::Error> { ... }
}
Expand description

Color management system interface.

Abstracts over CMS backends (moxcms, lcms2, etc.) to provide ICC profile transforms and profile identification.

§Feature-gated

The trait is always available for trait bounds and generic code. Concrete implementations are provided by feature-gated modules (e.g., cms-moxcms).

Required Associated Types§

Source

type Error: Debug

Error type for CMS operations.

Required Methods§

Source

fn build_transform( &self, src_icc: &[u8], dst_icc: &[u8], ) -> Result<Box<dyn RowTransform>, Self::Error>

Build a row-level transform between two ICC profiles.

Returns a RowTransform that converts pixel rows from the source profile’s color space to the destination profile’s.

This method assumes u8 RGB pixel data. For format-aware transforms that match the actual source/destination bit depth and layout, use build_transform_for_format.

Source

fn identify_profile(&self, icc: &[u8]) -> Option<Cicp>

Identify whether an ICC profile matches a known CICP combination.

Two-tier matching:

  1. Hash table of known ICC byte sequences for instant lookup.
  2. Semantic comparison: parse matrix + TRC, compare against known values within tolerance.

Returns Some(cicp) if the profile matches a standard combination, None if the profile is custom.

Provided Methods§

Source

fn build_transform_for_format( &self, src_icc: &[u8], dst_icc: &[u8], src_format: PixelFormat, dst_format: PixelFormat, ) -> Result<Box<dyn RowTransform>, Self::Error>

Build a format-aware row-level transform between two ICC profiles.

Like build_transform, but the CMS backend can use the pixel format information to create a transform at the native bit depth (u8, u16, or f32) and layout (RGB, RGBA, Gray, etc.), avoiding unnecessary depth conversions.

The default implementation ignores the format parameters and delegates to build_transform.

Implementors§