Skip to content

Add alpha conversion helpers#326

Draft
madsmtm wants to merge 2 commits intomadsmtm/alpha-modefrom
madsmtm/alpha-convert
Draft

Add alpha conversion helpers#326
madsmtm wants to merge 2 commits intomadsmtm/alpha-modefrom
madsmtm/alpha-convert

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Jan 27, 2026

Provide a few helper functions for handling the alpha channel when the pixel format of the buffer is PixelFormat::Bgra8 or PixelFormat::Rgba8.

I'm a bit unsure whether it makes sense to provide these? Their current implementations are quite simple, and if we can provide AlphaMode::Premultiplied everywhere, the [un-]premultiplication functions probably aren't really necessary. And perhaps the use-case of actually needing AlphaMode::Ignored is kinda niche, which makes make_pixels_opaque unnecessary too?


I think the biggest problem with providing these is that it kinda signals that they're fast implementations, which... They aren't really, they could be made much more performant using SIMD and/or rayon.

I know that I don't want Softbuffer to be in the business of providing drawing primitives like tiny-skia or vello_cpu does, and I guess you could argue that this is kinda in that category, at least in the sense that it's a very different set of things you need to worry about (CPU speed vs. abstracting platform details and managing buffers).

@madsmtm madsmtm added enhancement New feature or request question Further information is requested labels Jan 27, 2026
@madsmtm madsmtm force-pushed the madsmtm/alpha-mode branch from 304f431 to dc30b3c Compare January 28, 2026 23:44
@madsmtm madsmtm force-pushed the madsmtm/alpha-convert branch from 4e611ed to 4a776fe Compare January 28, 2026 23:47
@madsmtm madsmtm force-pushed the madsmtm/alpha-mode branch 2 times, most recently from fe20944 to 693551c Compare January 31, 2026 03:33
@ids1024
Copy link
Member

ids1024 commented Feb 5, 2026

I know that I don't want Softbuffer to be in the business of providing drawing primitives like tiny-skia or vello_cpu does, and I guess you could argue that this is kinda in that category, at least in the sense that it's a very different set of things you need to worry about (CPU speed vs. abstracting platform details and managing buffers).

On one hand, if some platforms only support premultiplied alpha and some only support postmultiplied, it would be nice for a user of softbuffer to not need to depend on tiny-skia or vello_cpu just to support both.

But yeah, if we're only going to provide fairly trivial unoptimized helpers, maybe the user of the library can do that themself. And I'm not familiar with the tricks for optimizing this sort of thing, but I don't know if we want to add fancy SIMD code to softbuffer at least until std::simd is available to make that easy without extra dependencies...

@madsmtm
Copy link
Member Author

madsmtm commented Feb 5, 2026

And I'm not familiar with the tricks for optimizing this sort of thing, but I don't know if we want to add fancy SIMD code to softbuffer at least until std::simd is available to make that easy without extra dependencies...

I'm kinda in the same boat.

I think we can support AlphaMode::Premultiplied everywhere, that seems to be the desired format on all backends, so let's wait and see until we figure that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request question Further information is requested

Development

Successfully merging this pull request may close these issues.

2 participants