image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.86k stars 597 forks source link

Opening and saving an sRGB image yields different colors #2247

Open rrohrer opened 3 months ago

rrohrer commented 3 months ago

This happens in image 0.25.1

Expected

Colors should be preserved when an image is opened and saved.

Actual behaviour

Two different images with different colors (after image opened and saved, it’s much more yellow)

Reproduction steps

Take an sRGB IEC61966-2.1 encoded jpeg, open it with Reader, call the save method on the result, and compare the before and after images. Looking at meta data, it preserves the sRGB color profile, but the result is different colors.

Provide source code, a repository link, or steps:


use image::{io::Reader as ImageReader, ImageError};

fn main() -> Result<(), ImageError> {
    let image = ImageReader::open("input.jpg")?.decode()?;
    image.save("output.jpg")?;

    Ok(())
}
fintelia commented 3 months ago

Could you share a failing image? Is it possible there's an embedded ICC profile and we have a longstanding issue to handle those better

rrohrer commented 3 months ago

I was using the full resolution download of this flickr image: https://flickr.com/photos/alexislours/53637525879/

I believe it does have an embedded ICC profile

rrohrer commented 3 months ago

Reading through the linked issue, and the other issues around it… is there currently a work around or are embedded ICC profiles a no-go for now with image-rs?

fintelia commented 3 months ago

We have the low level capability to read ICC profiles, but aren't yet able to write them when encoding images

rrohrer commented 3 months ago

Ah, so the correct thing would be to read the profile, apply it, then save in a format image-rs supports. Thanks!