image-rs / image-png

PNG decoding and encoding library in pure Rust
https://docs.rs/png
Apache License 2.0
354 stars 140 forks source link

DuplicateChunk error for image with sRGB chunk preceding gAMA chunk #340

Closed DutChen18 closed 2 years ago

DutChen18 commented 2 years ago

This image with an sRGB chunk preceding a gAMA chunk fails to decode in 0.17.4 but it decodes fine in 0.17.3. https://user-images.githubusercontent.com/6209323/155889742-979e8698-2e87-4206-8930-a1a454c2dc10.png

$ pngcheck raw_strips/006e8720-00d7-425d-9382-7f1676970f5e.png 
ERROR: raw_strips/006e8720-00d7-425d-9382-7f1676970f5e.png
raw_strips/006e8720-00d7-425d-9382-7f1676970f5e.png: Chunk ChunkType { type: gAMA, critical: false, private: false, reserved: false, safecopy: false } must appear at most once.

I believe the breaking change to be from #334

The error originates from this check: https://github.com/image-rs/image-png/blob/bb55a6646b2493b1411dacb870faa5ef49003a3c/src/decoder/stream.rs#L959-L963 Because source_gamma is set in parse_srgb here: https://github.com/image-rs/image-png/blob/bb55a6646b2493b1411dacb870faa5ef49003a3c/src/decoder/stream.rs#L991-L995

ogoffart commented 2 years ago

I'm also seeing this regression with a bunch of other images.

(For example https://raw.githubusercontent.com/slint-ui/slint/v0.1.6/examples/imagefilter/cat_preview_round.png )

ScranchNew commented 8 months ago

I still encountered this error with version 0.24.8 with this image:

Endless banner

The Error shown was: Decoding(DecodingError { format: Exact(Png), underlying: Some(Format(FormatError { inner: DuplicateChunk { kind: ChunkType { type: iCCP, critical: false, private: false, reserved: false, safecopy: false } } })) }).

Running with version 0.23.14 currently solves the issue.

fintelia commented 7 months ago

@ScranchNew Make sure you run cargo update. If you're still seeing this failure, please open a new issue with both the code you're using and the exact png crate version (0.23.14 and 0.24.8 are versions of the image crate which are compatible multiple png crate versions).

ogoffart commented 7 months ago

If one can still reproduce this issue with the last png version, the best would be to open the issue directly on the png crate repository and attach the exact image. https://github.com/image-rs/image-png