image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.98k stars 618 forks source link

Access ICC profile data #1832

Closed sophie-h closed 1 year ago

sophie-h commented 1 year ago

I would like to be able to convert images to sRGB (or other profiles in the future.) The specific png and jpeg-decoder crates support accessing icc_profile() that I can use with the lcms2 crate but, they do not support DynamicImage. The image crate does not support accessing the color profile information but supports DynamicImage.

My specific use case for this functionality is writing a new image viewer for GNOME.

This might be more generally applicable to other features like EXIF block data or background colors (bKGD).

Draft

  1. Add those features to ImageDecoder returning None if not applicable.
  2. Add DynamicImage support to the specific crates. Webp already has that.
  3. Add those features to the format-specific decoders like image::codecs::png::PngDecoder. However, not sure if that's possible for EXIF where the end of the file is relevant?
fintelia commented 1 year ago

The individual format crates cannot support DynamicImage because of a circular dependency issue: image dependends on the format specific crates to provide its various decoders, but those crates would need to depend on image if they wanted to access DynamicImage.

I think a good first step would be to add a ImageDecoder::icc_profile(&mut self) -> Option<Vec<u8>> method that defaults to returning None. After calling it, you can then use DynamicImage::from_decoder to get the rest of the image.