Skip to content

Add alpha premultiplication to tiff based on ExtraSamples tag#2889

Closed
mpospelova wants to merge 2 commits intoimage-rs:mainfrom
mpospelova:alpha-premultiplication
Closed

Add alpha premultiplication to tiff based on ExtraSamples tag#2889
mpospelova wants to merge 2 commits intoimage-rs:mainfrom
mpospelova:alpha-premultiplication

Conversation

@mpospelova
Copy link
Copy Markdown
Contributor

libtiff premultiplies the alpha channel based on the ExtraSamples tag (Tag 338). This pull request mimics the behavior of libtiff.

For value 0 (unspecified), libtiff does not perform any premultiplication and this PR sets the premultiplication flag to false

For value 1 (associated alpha), the rgb channels are already premultiplied and libtiff doesn't do anything. This PR sets the premultiplication flag to false in this case

For value 2 (unassociated alpha), libtiff multiplies the color channels by the alpha value. This PR mimics this by performing premultiplication with the pic-scale-safe library

@197g
Copy link
Copy Markdown
Member

197g commented Mar 26, 2026

Our ImageBuffer does not have premultiplied samples so the output should undo that on associated samples (semantics we already use for color conversion and for rescaling where we premultiply in an extra step). From the description I had expected the change to be on the encoder. We should only emulate libtiff insofar as our own types align with it.

@mpospelova mpospelova closed this Mar 27, 2026
@197g
Copy link
Copy Markdown
Member

197g commented Mar 27, 2026

@mpospelova Of course it means our decoder is wrong in all the other cases right now. If you want to contribute a PR, I'd gladly see one fixing color fidelity in that direction by checking the tag.

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

Successfully merging this pull request may close these issues.

2 participants