Skip to content

Commit

Permalink
make set_icc_profile function available (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
misl-smlz authored Oct 7, 2024
1 parent 8ecc99c commit a373218
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/codecs/webp/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl<W: Write> ImageEncoder for WebPEncoder<W> {
) -> ImageResult<()> {
self.encode(buf, width, height, color_type)
}

fn set_icc_profile(&mut self, icc_profile: Vec<u8>) -> Result<(), UnsupportedError> {
self.inner.set_icc_profile(icc_profile);
Ok(())
}
}

impl ImageError {
Expand Down
21 changes: 20 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -798,6 +798,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<u8>) -> 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
Expand Down

0 comments on commit a373218

Please sign in to comment.