SDL_BYTESPERPIXEL(3)
π SDL_BYTESPERPIXEL(3) β bestie edition
okay so we're in the SDL3 FUNCTIONS part of the manual, and today's main character is SDL_BYTESPERPIXEL π
β¨ NAME β¨
SDL_BYTESPERPIXEL β it's a macro that tells you how many bytes per pixel an SDL_PixelFormat has. that's it, that's the whole job, and it ate π«Ά
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_pixels.h>
#define SDL_BYTESPERPIXEL(format) \
(SDL_ISPIXELFORMAT_FOURCC(format) ? \
((((format) == SDL_PIXELFORMAT_YUY2) || \
((format) == SDL_PIXELFORMAT_UYVY) || \
((format) == SDL_PIXELFORMAT_YVYU) || \
((format) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((format) >> 0) & 0xFF))
like. look at her. she's doing bit math AND a ternary chain AND she's a macro. multitasking queen π
π¦ DESCRIPTION π¦
okay important thing first, and I need you to actually listen bestie:
this macro double-evaluates its parameter π so do NOT pass it expressions with side-effects. that means no i++, no function calls that do stuff, nothing spicy. it'll run your thing twice and you'll be sitting there like "why is my counter wrong" π
and second thing, about FourCC formats: they do their best here, fr fr, but ngl a lot of them just don't have a meaningful measurement of bytes per pixel. so the number you get back for those is... vibes-adjacent. it's giving "we tried our best" π
π MACRO PARAMETERS π
formatβ anSDL_PixelFormatto check. just hand her the format, she'll handle the rest π
β RETURN VALUE β
returns the bytes-per-pixel of format. literally that. no surprises, no plot twists β¨
π THREAD SAFETY π
it is safe to call this macro from any thread. every thread. all at once. she doesn't care, she's unbothered, she's thriving π§
π AVAILABILITY π
this macro has been available since SDL 3.2.0. so if you're on something older... bestie. upgrade. π
π SEE ALSO π
SDL_BITSPERPIXEL(3)β her sister, she counts bits instead of bytes, iconic behavior honestly π
Simple Directmedia Layer β SDL 3.4.18 β that's the source and version, and the date's riding along with it in the footer, so consider this your cute lil sign-off π
stay hydrated, read your manpages, and never double-evaluate something with side effects. mwah πβ¨
π¦ 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