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

Conversation

misl-smlz
Copy link
Contributor

We need to set the icc profile for webp. This PR makes the set_icc_profile function available from the outside.

@fintelia
Copy link
Contributor

I think this should probably be added as a method on ImageEncoder, with a default implementation that returns an unsupported error

@misl-smlz
Copy link
Contributor Author

@fintelia I've changed it the way you suggested

src/image.rs Outdated
Comment on lines 785 to 808
fn set_icc_profile(&mut self, icc_profile: Vec<u8>) {
let _ = icc_profile;
panic!("ICC profiles are not supported for this format");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @fintelia meant an error, not a panic. We're already seeing bug reports for returning honest and correct error returns when calling functions on formats that do not support them (e.g. encoding floats into a png). I can't imagine error handling by panic to fare any better, it's probably significantly worse.

Copy link
Contributor

@kornelski kornelski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return Result<(), …>.

I'm not sure if a generic error or a dedicated UnsupportedError.

it would be good to also document that it doesn't check ICC for validity at this point, so doesn't guarantee to fail if the profile is invalid.

@misl-smlz
Copy link
Contributor Author

@kornelski Now it returns an Result

@fintelia
Copy link
Contributor

fintelia commented Oct 5, 2024

Looks like there's a few compile errors:

error[E0433]: failed to resolve: use of undeclared type `UnsupportedError`
   --> src/image.rs:798:13
    |
798 |         Err(UnsupportedError::from_format_and_kind(
    |             ^^^^^^^^^^^^^^^^ use of undeclared type `UnsupportedError`
    |
help: consider importing this struct
    |
2   + use crate::error::UnsupportedError;
    |

src/image.rs Outdated
Comment on lines 793 to 795
/// # Panics
///
/// Panics if the ICC profile is not implemented for the format.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update

@fintelia fintelia merged commit a373218 into image-rs:main Oct 7, 2024
32 checks passed
@fintelia
Copy link
Contributor

fintelia commented Oct 7, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants