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 to SDL_PixelFormatDetails describing the pixel format. it's the one who knows what we're working with πŸ‘‘
  • palette β€” an optional palette for indexed formats, and it may be NULL.
  • 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