SDL_PremultiplyAlpha(3)
π SDL_PremultiplyAlpha(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_PremultiplyAlpha. she premultiplies. she's iconic. let's get into it π«Ά
β¨ NAME β¨
SDL_PremultiplyAlpha β Premultiply the alpha on a block of pixels. that's it, that's the whole job, and she does it flawlessly π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
bool SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, bool linear);
like, look at that signature. it's giving eight arguments and a dream β¨
π¦ DESCRIPTION π¦
so here's the tea: this is safe to use with src == dst, but not for other overlapping areas. that's the whole description, no notes π
β οΈ bestie please read that again. same pointer? fine. other overlapping areas? NOT fine. do not do it. i'm serious. π
π FUNCTION PARAMETERS π
widthβ the width of the block to convert, in pixels. how wide is the vibe? this wide πheightβ the height of the block to convert, in pixels. and how tall? this tall πsrc_formatβ anSDL_PixelFormatvalue of the src pixels format. tell her what the source pixels are serving πsrcβ a pointer to the source pixels. the original, the blueprint, the blueprint that ate π₯src_pitchβ the pitch of the source pixels, in bytes. yes, bytes. not pixels. bytes. iykyk βdst_formatβ anSDL_PixelFormatvalue of the dst pixels format. and what's the destination serving? πdstβ a pointer to be filled in with premultiplied pixel data. she gets filled in, periodt πdst_pitchβ the pitch of the destination pixels, in bytes. again, bytes bestie, don't come at me with pixels πlinearβtrueto convert from sRGB to linear space for the alpha multiplication,falseto do multiplication in sRGB space. pick your lane, both are valid π§
π RETURN VALUE π
Returns true on success or false on failure; call SDL_GetError() for more information. so if she says false? don't spiral. just call SDL_GetError() and she'll tell you exactly what went wrong π
π THREAD SAFETY π
okay listen up, this one matters:
- The same destination pixels should not be used from two threads at once. sharing is caring but not here π
- It is safe to use the same source pixels from multiple threads. read-only girlies stay winning π
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something older, it's not her fault, she literally wasn't born yet π
and that's the whole page bestie, you ate it, no crumbs π«Άβ¨
Simple Directmedia Layer made this, we're all living in SDL 3.4.18 era, and this page is SDL_PremultiplyAlpha(3) β go premultiply something responsibly, ily, bye ππ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms