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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
federicomenaquintero opened this issue Dec 22, 2023 · 3 comments
Open

Comments

@federicomenaquintero
Copy link

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

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

@fintelia
Copy link
Contributor

fintelia commented Dec 22, 2023

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
Copy link
Contributor

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

@fintelia
Copy link
Contributor

fintelia commented Dec 22, 2023

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:

  • Many formats (including PNG*) don't have a field to indicate whether they're premultipled or not, so the decoder has no idea what it is outputting.
  • Applying pre-multiplication is an irreversible operation: RGB colors in fully transparent areas are lost, and precision is reduced in partially transparent areas

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

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

No branches or pull requests

3 participants