SDL_MapRGB(3)
π SDL_MapRGB(3) π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, this one's called SDL_MapRGB and it's literally the glow-up station for your colors β¨
πΈ NAME πΈ
SDL_MapRGB β map an RGB triple to an opaque pixel value for a given pixel format. yes queen, three little numbers in, one pixel value out π
π SYNOPSIS π
#include <SDL3/SDL_pixels.h>
Uint32 SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b);
π¦ DESCRIPTION π¦
so what this function does is take your RGB color value, map it to the pixel format you specified, and hand you back the pixel value that best approximates the RGB color you asked for in that format. it's giving matchmaker energy fr fr π«Ά
if the format has a palette (8-bit), then what you get back is the index of the closest matching color in that palette. the palette is doing the vibes-matching for you π
if the specified pixel format has an alpha component, that alpha comes back as all 1 bits, aka fully opaque. no half-transparent nonsense here, we're committed β¨
and if the pixel format bpp (color depth) is less than 32-bpp, then the unused upper bits of the return value can safely be ignored. like, for example, with a 16-bpp format you can just assign the return value to a Uint16, and same deal with a Uint8 for an 8-bpp format. no cap, those extra bits are just hanging out, minding their business π
π FUNCTION PARAMETERS π
formatβ a pointer toSDL_PixelFormatDetailsdescribing the pixel format. it's the one who knows what we're working with πpaletteβ an optional palette for indexed formats, and it may beNULL.rβ the red component of the pixel, in the range 0-255.gβ the green component of the pixel, in the range 0-255.bβ the blue component of the pixel, in the range 0-255.
β RETURN VALUE β
Returns a pixel value. that's it, that's the whole thing, she's simple and she ate π₯
π§ THREAD SAFETY π§
It is safe to call this function from any thread, as long as the palette is not modified. so like, go off with your threads bestie, just don't be out here editing the palette mid-call, that's the one rule π
π« AVAILABILITY π«
This function is available since SDL 3.2.0. if you're on something older, sorry babe, no SDL_MapRGB for you π
π SEE ALSO π
and that's the whole page, bestie π this little gem comes to you straight from Simple Directmedia Layer, version SDL 3.4.18 β go map some colors, you've got this πβ¨π
π¦ 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