Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make set_icc_profile function available #2322

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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<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
Loading