image-rs / image-png

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

Docs should say whether Rgba<T> is premultiplied or not #443

Open federicomenaquintero opened 6 months ago

federicomenaquintero commented 6 months ago

I couldn't find the string premul in the source code except for the algorithm in the blend filter :sweat_smile:

Are images decoded with alpha premultiplied or not? It doesn't matter for my application; it can handle either format.

fintelia commented 6 months ago

This library neither applies pre-multiplication nor removes it. We'll return the pixel values as they're stored in the file so it is up to you to know whether your image files come pre-multiplied or not.

The main image crate however does contain some amount of code for applying blending which I believe assumes that the image is stored non-premultiplied

sophie-h commented 6 months ago

But is there a convention for the DynamicImage's the decoders in image-rs give?

fintelia commented 6 months ago

In practice, DynamicImage's are usually not premultiplied because the majority of image files don't use premultiplied alpha.

However, there's some challenges to making that a convention everywhere:

*I think the PNG spec says images are always supposed to be non-premultiplied but people sometimes ignore that.