SDL_GetRGBA(3)

✨ SDL_GetRGBA(3) ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, we're literally about to pull color values out of a single pixel and it's giving main character energy πŸ’…


πŸŽ€ NAME πŸŽ€

SDL_GetRGBA β€” get RGBA values from a pixel in the specified format. no cap, that's the whole gig 🫢


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_pixels.h>

void SDL_GetRGBA(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);

πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜• β€” this function uses the entire 8-bit [0..255] range when it converts color components from pixel formats that have less than 8 bits per RGB component. like, a completely white pixel in 16-bit RGB565 format would come back as [0xff, 0xff, 0xff], not [0xf8, 0xfc, 0xf8]. she scales it up fully, she's generous like that ✨

and if the surface has no alpha component, the alpha comes back as 0xff (100% opaque). fully solid, fully booked, no transparency drama πŸ™ˆ


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • pixelvalue β€” a pixel value. the lil guy we're dissecting πŸ”
  • format β€” a pointer to SDL_PixelFormatDetails describing the pixel format. this is how she knows what she's looking at πŸ‘‘
  • palette β€” an optional palette for indexed formats, may be NULL. optional bestie, she can be null πŸ’œ
  • r β€” a pointer filled in with the red component, may be NULL.
  • g β€” a pointer filled in with the green component, may be NULL.
  • b β€” a pointer filled in with the blue component, may be NULL.
  • a β€” a pointer filled in with the alpha component, may be NULL.
note the vibe: every single one of those output pointers can be NULL and that's fine, she just won't fill that one in. you only take what you need, periodt πŸ’…

🌈 THREAD SAFETY 🌈

it is safe to call this function from any thread, as long as the palette is not modified. don't be out here editing the palette mid-call and then acting surprised, that's the one rule bestie 😭


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on something older, sorry babe, she doesn't exist yet 🫢


πŸ”₯ SEE ALSO πŸ”₯

go read those too, they're all in the same friend group fr fr 🧚


and that's the whole page!! brought to you by the fine folks at Simple Directmedia Layer, running SDL 3.4.18 πŸ’– stay slaying, keep your pixels converted, and remember: 0xff alpha means fully opaque and fully iconic βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from