SDL_MapSurfaceRGB(3)

πŸ’– SDL_MapSurfaceRGB πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_MapSurfaceRGB β€” she maps an RGB triple to an opaque pixel value for a surface. that's it, that's the gig, and she does it flawlessly. periodt. ✨


🌈 SYNOPSIS 🌈

#include <SDL3/SDL_surface.h>

Uint32 SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);

like, look at her. clean signature. no notes. 🫢


✨ DESCRIPTION ✨

so what does she actually do? this function maps the RGB color value to the specified pixel format and hands you back the pixel value that best approximates the RGB color value you gave her, for that pixel format. it's giving translator, but for colors. πŸ’…

if the surface has a palette, then the index of the closest matching color in the palette will be returned. she's out here doing her best matchmaking, fr fr. πŸŽ€

if the surface pixel format has an alpha component, that alpha will be returned as all 1 bits β€” which is fully opaque. no half-transparent nonsense, she said opaque and she meant it. πŸ‘‘

and here's the cute lil detail you need to remember: 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, with a 16-bpp format the return value can be assigned to a Uint16, and similarly a Uint8 for an 8-bpp format. so don't panic about the extra bits bestie, they're just vibes. πŸ’€


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • surface β€” the surface to use for the pixel format and palette. your source of truth, your blueprint, your girl. 🌸
  • 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 the whole thing. iconic, honestly. πŸ’–


🧚 THREAD SAFETY 🧚

good news bestie: this function can be called on different threads with different surfaces. so go forth and parallelize, just keep your surfaces separate, okay? no sharing drama. πŸ™ˆ


πŸ‘‘ AVAILABILITY πŸ‘‘

This function is available since SDL 3.2.0. so if you're on anything older... not me finding out the hard way. 😭


🌟 SEE ALSO 🌟


and that's the whole page, bestie!! this lil slice of documentation came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18 β€” tysm for reading, mwah, slay, drink water, and go map some pixels. πŸŽ€πŸ’…βœ¨πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from