Add Pixmap::take_demultiplied
to get raw, demultiplied pixel data
#152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new consuming method,
Pixmap::take_demultiplied
, which returns aVec<u8>
containing straight alpha RGBA data.The new method simply extracts the existing demultiplication loop from
PixmapRef::encode_png
and makes it public.Motivation
Currently, the logic to convert from the library's internal premultiplied alpha format to straight alpha is hidden inside the
encode_png
function. To obtain raw, demultiplied pixel data for other purposes (e.g., interfacing with custom image processing code), users would have to re-implement this logic usingPremultipliedColorU8::from_rgba
, which is inefficient sincePremultipliedColorU8::from_rgba_unchecked
is private, or resort to manipulating the underlying slice directly with something likecontainer.chunks_exact_mut(4)
.