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, range0-255. πgβ the green component of the pixel, range0-255. πbβ the blue component of the pixel, range0-255. πaβ the alpha component of the pixel, range0-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 π
SDL_MapSurfaceRGB(3)β the no-alpha sibling, if that's your thing π«Ά
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
- 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