diff --git a/src/codecs/webp/encoder.rs b/src/codecs/webp/encoder.rs index dfdfbead01..422a36b795 100644 --- a/src/codecs/webp/encoder.rs +++ b/src/codecs/webp/encoder.rs @@ -92,6 +92,11 @@ impl ImageEncoder for WebPEncoder { ) -> ImageResult<()> { self.encode(buf, width, height, color_type) } + + fn set_icc_profile(&mut self, icc_profile: Vec) -> Result<(), UnsupportedError> { + self.inner.set_icc_profile(icc_profile); + Ok(()) + } } impl ImageError { diff --git a/src/image.rs b/src/image.rs index 06a5953e41..0e6ead8708 100644 --- a/src/image.rs +++ b/src/image.rs @@ -8,7 +8,7 @@ use std::path::Path; use crate::color::{ColorType, ExtendedColorType}; use crate::error::{ ImageError, ImageFormatHint, ImageResult, LimitError, LimitErrorKind, ParameterError, - ParameterErrorKind, + ParameterErrorKind, UnsupportedError, UnsupportedErrorKind, }; use crate::math::Rect; use crate::traits::Pixel; @@ -787,6 +787,25 @@ pub trait ImageEncoder { height: u32, color_type: ExtendedColorType, ) -> ImageResult<()>; + + /// Set the ICC profile to use for the image. + /// + /// This function is a no-op for formats that don't support ICC profiles. + /// For formats that do support ICC profiles, the profile will be embedded + /// in the image when it is saved. + /// + /// # Errors + /// + /// This function returns an error if the format does not support ICC profiles. + fn set_icc_profile(&mut self, icc_profile: Vec) -> Result<(), UnsupportedError> { + let _ = icc_profile; + Err(UnsupportedError::from_format_and_kind( + ImageFormatHint::Unknown, + UnsupportedErrorKind::GenericFeature( + "ICC profiles are not supported for this format".into(), + ), + )) + } } /// Immutable pixel iterator