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 β€” an SDL_PixelFormat value 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 β€” an SDL_PixelFormat value 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 β€” true to convert from sRGB to linear space for the alpha multiplication, false to 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