Skip to content

Add Pixmap::take_demultiplied to get raw, demultiplied pixel data #152

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JustForFun88
Copy link

This PR introduces a new consuming method, Pixmap::take_demultiplied, which returns a Vec<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 using PremultipliedColorU8::from_rgba, which is inefficient since PremultipliedColorU8::from_rgba_unchecked is private, or resort to manipulating the underlying slice directly with something like container.chunks_exact_mut(4).

@RazrFalcon
Copy link
Collaborator

Looks good to me.

@LaurenzV
Copy link
Contributor

Will be merged after we've fixed the CI issue.

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.

3 participants