SDL_BITSPERPIXEL(3)

πŸ’– SDL_BITSPERPIXEL(3) πŸ’–

ok so bestie, welcome to the SDL3 FUNCTIONS corner of the group chat, where today's main character is SDL_BITSPERPIXEL πŸŽ€


✨ NAME ✨

SDL_BITSPERPIXEL β€” a macro that figures out an SDL_PixelFormat's bits per pixel. that's it, that's the whole job, and it does it flawlessly, no notes πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_pixels.h>

#define SDL_BITSPERPIXEL(format) \
    (SDL_ISPIXELFORMAT_FOURCC(format) ? 0 : (((format) >> 8) & 0xFF))

✨ DESCRIPTION ✨

ok so real talk 🫢 β€” this macro double-evaluates its parameter. like, it looks at format more than once. so pls pls pls do not hand it expressions with side-effects, because they will run twice and that is giving chaos, not giving slay 😭

and FourCC formats? they report zero here. because honestly, measuring a FourCC per-pixel rarely makes sense β€” it's just not that kind of format, and we respect that πŸ™ˆ


✨ MACRO PARAMETERS ✨

  • format β€” an SDL_PixelFormat to check. that's the one, the only, the icon πŸ‘‘

✨ RETURN VALUE ✨

returns the bits-per-pixel of format. periodt ✨


✨ THREAD SAFETY ✨

it is safe to call this macro from any thread. yes, literally any of them. go wild, bestie 🌈


✨ AVAILABILITY ✨

this macro has been available since SDL 3.2.0 πŸ¦‹


✨ SEE ALSO ✨


ngl if you're passing something with side-effects in here, pls stop, i'm begging πŸ’€ the double-evaluation is not a vibe.

and that's the whole page, bestie!! 🌸 this lil gem comes to you from the Simple Directmedia Layer girlies, SDL 3.4.18 edition, dated the day of this very manual page. mwah πŸ’‹ go check your bits per pixel, you absolute legend πŸ‘‘βœ¨

πŸ“¦ where this page comes from