SDL_MapRGBA(3)
π SDL_MapRGBA β the glow-up your colors deserve π
okay bestie, so this is a page from the SDL3 FUNCTIONS collection, and it's literally about turning a whole RGBA quadruple into a single pixel value for whatever pixel format you're working with. no cap. β¨
πΈ NAME πΈ
SDL_MapRGBA β Map an RGBA quadruple to a pixel value for a given pixel format.
like... you give it a color, it gives you back the pixel. it's giving translator. it's giving matchmaker. π«Ά
β¨ SYNOPSIS β¨
#include <SDL3/SDL_pixels.h>
Uint32 SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
π¦ DESCRIPTION π¦
okay so here's the tea, this function maps the RGBA color value to the specified pixel format and returns the pixel value that best approximates the given RGBA color value for the given pixel format. it's literally out here doing its best, and honestly? its best is great. π₯
if the pixel format you picked has no alpha component, then the alpha value gets straight-up ignored (same energy in formats with a palette, so don't come for it).
if the format has a palette (8-bit), you get back the index of the closest matching color in that palette. it's shopping the palette for you. icon behavior. π
and if the pixel format's 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 the return value can be assigned to a Uint16, and same vibe with a Uint8 for an 8-bpp format. the extra bits are just hanging out, they're not doing anything, ignore them. π
π FUNCTION PARAMETERS π
formatβ a pointer toSDL_PixelFormatDetailsdescribing the pixel format. this is the blueprint, the vibe check, the whole moment.paletteβ an optional palette for indexed formats, may beNULL. optional!! she can be absent and that's fine.rβ the red component of the pixel in the range0-255.gβ the green component of the pixel in the range0-255.bβ the blue component of the pixel in the range0-255.aβ the alpha component of the pixel in the range0-255.
β RETURN VALUE β
Returns a pixel value. that's it, that's the whole thing. short queen. π
π§ THREAD SAFETY π§
It is safe to call this function from any thread, as long as the palette is not modified. so like β multitask all you want, but do NOT go changing the palette out from under everyone. that's the one rule fr fr. π
π AVAILABILITY π
This function is available since SDL 3.2.0. she's been around. she's established. periodt.
π SEE ALSO π
go read those too, iykyk π
ngl bestie, if your format has no alpha, your alpha is getting ignored and that's not a bug, that's the design. don't @ me. π
and that's the whole page, mwah π this one came from the lovely people at Simple Directmedia Layer, living in SDL 3.4.18 β so go map some RGBA and slay, okay? bye babe πβ¨π
π¦ 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