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 toSDL_PixelFormatDetailsdescribing the pixel format. this is how she knows what she's looking at πpaletteβ an optional palette for indexed formats, may beNULL. optional bestie, she can be null πrβ a pointer filled in with the red component, may beNULL.gβ a pointer filled in with the green component, may beNULL.bβ a pointer filled in with the blue component, may beNULL.aβ a pointer filled in with the alpha component, may beNULL.
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
- 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