SDL_MapSurfaceRGBA(3)

πŸ’– SDL_MapSurfaceRGBA(3) πŸ’–

okay bestie, welcome to the SDL3 functions page for SDL_MapSurfaceRGBA ✨ this one is literally just "turn a colour into a pixel number" and it's so much less scary than it sounds, i promise 🫢


🌸 NAME 🌸

SDL_MapSurfaceRGBA β€” Map an RGBA quadruple to a pixel value for a surface. it's giving "translator for colours" πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_surface.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so what this does is: it takes your RGBA colour value, maps it to the pixel format you specified, and hands you back the pixel value that best approximates that colour for that format. it's the matchmaker of the pixel world fr fr πŸŽ€

if the surface's pixel format has no alpha component, the alpha value just gets ignored (and same energy for formats with a palette, bestie β€” the a is not invited to that party πŸ™ˆ).

if the surface does have a palette, you get the index of the closest matching colour in the palette. closest. not exact. it's doing its best πŸ’œ

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. so like, with a 16-bpp format you can assign the return value to a Uint16, and same deal with a Uint8 for an 8-bpp format. no cap, you can just toss those extra bits πŸ’€


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • surface β€” the surface you're using for the pixel format and palette. it's the main character here πŸ‘‘
  • r β€” the red component of the pixel, range 0-255. πŸ“
  • g β€” the green component of the pixel, range 0-255. 🌈
  • b β€” the blue component of the pixel, range 0-255. πŸ’™
  • a β€” the alpha component of the pixel, range 0-255. (may or may not be acknowledged, see above, it's complicated 😭)

🌟 RETURN VALUE 🌟

Returns a pixel value. that's it, that's the whole vibe ✨


🧚 THREAD SAFETY 🧚

this function can be called on different threads with different surfaces. go off, multithreaded queen πŸ’… (different surfaces though β€” read it again, i said what i said)


πŸ’« AVAILABILITY πŸ’«

this function is available since SDL 3.2.0 ⭐


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie!! mwah πŸ’–

this has been Simple Directmedia Layer, version SDL 3.4.18, dated SDL_MapSurfaceRGBA(3) β€” go forth and map those pixels, you absolute icon πŸŒΈβœ¨πŸŽ€

πŸ“¦ where this page comes from