SDL_GetRGB(3)
π SDL_GetRGB β get RGB values from a pixel in the specified format π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, page SDL_GetRGB(3). this one is short, sweet, and honestly so useful. let's get into it β¨
β¨ NAME β¨
SDL_GetRGB β pull the red, green and blue values out of a pixel, in whatever format that pixel happens to be in. yes, even the weird ones. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_pixels.h>
void SDL_GetRGB(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
that's the whole vibe. five params plus a return of absolutely nothing, because she fills in your pointers instead. π
π¦ DESCRIPTION π¦
okay so here's the thing that makes this function lowkey iconic: when it converts color components out of pixel formats that have less than 8 bits per RGB component, it uses the entire 8-bit [0..255] range. she's not being stingy, she's stretching that range all the way out.
the example the docs give is so good: a completely white pixel in 16-bit RGB565 format would return [0xff, 0xff, 0xff] β not [0xf8, 0xfc, 0xf8].
so like, you get the full 255 treatment even though the source format couldn't technically represent it. that's the main character energy we're talking about. π
π FUNCTION PARAMETERS π
pixelvalueβ a pixel value. yeah that's it, that's the description. a pixel. the value. give her the pixel. πformatβ a pointer toSDL_PixelFormatDetailsdescribing the pixel format. she needs to know what she's working with, bestie.paletteβ an optional palette for indexed formats. may beNULL. optional!! she doesn't need it unless you're doing indexed formats. π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.
the way thatr,gandbare all allowed to beNULLis so generous. don't care about blue? don't pass it. just want the green? iconic. just pass the pointers you actually want filled in. π«Ά
π THREAD SAFETY π
it is safe to call this function from any thread, as long as the palette is not modified. so go off, thread away, just don't be out here editing the palette while somebody's reading from it. that's the one rule. π§
β AVAILABILITY β
this function is available since SDL 3.2.0. so if you're on anything older, no she's not there yet, sorry bestie π
π SEE ALSO π
okay that's the page!! go convert some pixels, you got this fr fr π
this has been Simple Directmedia Layer, SDL 3.4.18, signing off on SDL_GetRGB(3). slay, bye bestie!! β¨ππ¦π
π¦ 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