SDL_DEFINE_COLORSPACE(3)

โœจ SDL_DEFINE_COLORSPACE โœจ

okay bestie, welcome to the SDL_DEFINE_COLORSPACE(3) page โ€” it's part of the SDL3 FUNCTIONS lineup and it's literally the macro that lets you build your own custom SDL_Colorspace formats from scratch. no cap. ๐ŸŽจ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

SDL_DEFINE_COLORSPACE โ€” a macro for defining custom SDL_Colorspace formats. it's giving "build-a-bear but for pixel color metadata" ๐Ÿงธโœจ


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

#include <SDL3/SDL_pixels.h>

#define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
    (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
    ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))

likeโ€ฆ look at that bit-shifting choreography. it's giving main character energy. ๐Ÿ”ฅ


๐Ÿ’– DESCRIPTION ๐Ÿ’–

so the whole vibe is: you hand it six little pieces of color info, and it smooshes them all into one Uint32 with some very intentional shifting. no judgment, it's just math. ๐Ÿงฎ

for example, defining SDL_COLORSPACE_SRGB looks like this:

SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
                      SDL_COLOR_RANGE_FULL,
                      SDL_COLOR_PRIMARIES_BT709,
                      SDL_TRANSFER_CHARACTERISTICS_SRGB,
                      SDL_MATRIX_COEFFICIENTS_IDENTITY,
                      SDL_CHROMA_LOCATION_NONE)

see how it justโ€ฆ slots everything in? obsessed. ๐Ÿ˜Œ


๐Ÿฆ‹ MACRO PARAMETERS ๐Ÿฆ‹

six besties walk into a macro:

  • type โ€” the type of the new format, probably an SDL_ColorType value. ๐ŸŒˆ
  • range โ€” the range of the new format, probably a SDL_ColorRange value. ๐Ÿ“
  • primaries โ€” the primaries of the new format, probably an SDL_ColorPrimaries value. ๐ŸŽจ
  • transfer โ€” the transfer characteristics of the new format, probably an SDL_TransferCharacteristics value. ๐Ÿ”„
  • matrix โ€” the matrix coefficients of the new format, probably an SDL_MatrixCoefficients value. ๐ŸงŠ
  • chroma โ€” the chroma sample location of the new format, probably an SDL_ChromaLocation value. ๐Ÿ“

๐Ÿ’œ RETURN VALUE ๐Ÿ’œ

returns a format value in the style of SDL_Colorspace. so like, you give it crumbs and it gives you a whole snack. ๐Ÿ“


๐Ÿงš THREAD SAFETY ๐Ÿงš

it is safe to call this macro from any thread. yes bestie, any thread. go wild. ๐Ÿซถ๐Ÿ”ฅ


โญ AVAILABILITY โญ

this macro is available since SDL 3.2.0. so if you're on something olderโ€ฆ girl. upgrade. ๐Ÿ˜ญ๐Ÿ’€


๐Ÿ’€ lowkey important: all those shifts โ€” 28, 24, 20, 10, 5, and 0 โ€” are doing the heavy lifting. copy the macro exactly, don't get creative with the numbers. iykyk.

and that's the whole page, bestie!! this was Simple Directmedia Layer, SDL 3.4.18, dated SDL_DEFINE_COLORSPACE(3) โ€” thanks for reading, mwah ๐Ÿ’‹โœจ

๐Ÿ“ฆ where this page comes from