Skip to content

Conversation

@JustForFun88
Copy link
Contributor

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.

@LaurenzV LaurenzV force-pushed the take_demultiplied_data branch from cc06d05 to f8895d8 Compare August 15, 2025 14:00
@LaurenzV LaurenzV merged commit 04a911f into linebender:main Aug 15, 2025
4 checks passed
@LaurenzV
Copy link
Contributor

Thanks!

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