Expand description
Color Management System (CMS) traits.
Defines the interface for ICC profile-based color transforms. When a CMS
feature is enabled (e.g., cms-moxcms, cms-lcms2), the implementation
provides ICC-to-ICC transforms. Named profile conversions (sRGB, P3,
BT.2020) use hardcoded matrices and don’t require a CMS.
§When codecs need a CMS
Most codecs don’t need to interact with the CMS directly.
finalize_for_output handles CMS transforms
internally when the OutputProfile requires one.
A codec needs CMS awareness only when:
-
Decoding an image with an embedded ICC profile that doesn’t match any known CICP combination. The decoder extracts the ICC bytes and stores them on
ColorContext. The CMS is used later (at encode or processing time), not during decode. -
Encoding with
OutputProfile::Icc(custom_profile). The CMS builds a source→destination transform, whichfinalize_for_outputapplies row-by-row viaRowTransform.
§Implementing a CMS backend
To add a new CMS backend (e.g., wrapping Little CMS 2):
- Implement
ColorManagementon your backend struct. build_transformshould parse both ICC profiles, create an internal transform object, and return it asBox<dyn RowTransform>.identify_profileshould check if an ICC profile matches a known standard (sRGB, Display P3, etc.) and return the correspondingCicp. This enables the fast path: if both source and destination are known profiles, hardcoded matrices are used instead of the CMS.- Feature-gate your implementation behind a cargo feature
(e.g.,
cms-lcms2).
struct MyLcms2;
impl ColorManagement for MyLcms2 {
type Error = lcms2::Error;
fn build_transform(
&self,
src_icc: &[u8],
dst_icc: &[u8],
) -> Result<Box<dyn RowTransform>, Self::Error> {
let src = lcms2::Profile::new_icc(src_icc)?;
let dst = lcms2::Profile::new_icc(dst_icc)?;
let xform = lcms2::Transform::new(&src, &dst, ...)?;
Ok(Box::new(Lcms2RowTransform(xform)))
}
fn identify_profile(&self, icc: &[u8]) -> Option<Cicp> {
// Fast: check MD5 hash against known profiles
// Slow: parse TRC+matrix, compare within tolerance
None
}
}§No-op CMS
Codecs that don’t need ICC support can provide a no-op CMS whose
build_transform always returns an error. This satisfies the type
system while making it clear that ICC transforms are unsupported.
Structs§
- CmsPlugin
Error - Error produced by a
PluggableCmswhen a plugin recognized a conversion pair but failed to build a transform.
Enums§
- Color
Priority - Controls which transfer function metadata the CMS trusts when building a transform.
- Rendering
Intent - ICC rendering intent — controls how colors outside the destination gamut are handled during a profile-to-profile transform.
Traits§
- Color
Management Deprecated - Color management system interface.
- Pluggable
Cms - Dyn-compatible CMS plugin interface for overriding gamut/profile
conversions inside a
ConvertPlan. - RowTransform
- Shareable, stateless row-level color transform.
- RowTransform
Mut - Owned, stateful row-level color transform.