SDL 3.0
SDL_pixels.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryPixels
24 *
25 * Pixel management.
26 */
27
28#ifndef SDL_pixels_h_
29#define SDL_pixels_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_error.h>
33#include <SDL3/SDL_endian.h>
34
35#include <SDL3/SDL_begin_code.h>
36/* Set up for C function definitions, even when using C++ */
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * A fully opaque 8-bit alpha value.
43 *
44 * \since This macro is available since SDL 3.1.3.
45 *
46 * \sa SDL_ALPHA_TRANSPARENT
47 */
48#define SDL_ALPHA_OPAQUE 255
49
50/**
51 * A fully opaque floating point alpha value.
52 *
53 * \since This macro is available since SDL 3.1.3.
54 *
55 * \sa SDL_ALPHA_TRANSPARENT_FLOAT
56 */
57#define SDL_ALPHA_OPAQUE_FLOAT 1.0f
58
59/**
60 * A fully transparent 8-bit alpha value.
61 *
62 * \since This macro is available since SDL 3.1.3.
63 *
64 * \sa SDL_ALPHA_OPAQUE
65 */
66#define SDL_ALPHA_TRANSPARENT 0
67
68/**
69 * A fully transparent floating point alpha value.
70 *
71 * \since This macro is available since SDL 3.1.3.
72 *
73 * \sa SDL_ALPHA_OPAQUE_FLOAT
74 */
75#define SDL_ALPHA_TRANSPARENT_FLOAT 0.0f
76
77/**
78 * Pixel type.
79 *
80 * \since This enum is available since SDL 3.1.3.
81 */
99
100/**
101 * Bitmap pixel order, high bit -> low bit.
102 *
103 * \since This enum is available since SDL 3.1.3.
104 */
111
112/**
113 * Packed component order, high bit -> low bit.
114 *
115 * \since This enum is available since SDL 3.1.3.
116 */
129
130/**
131 * Array component order, low byte -> high byte.
132 *
133 * \since This enum is available since SDL 3.1.3.
134 */
145
146/**
147 * Packed component layout.
148 *
149 * \since This enum is available since SDL 3.1.3.
150 */
163
164#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
165
166#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
167 ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
168 ((bits) << 8) | ((bytes) << 0))
169
170#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
171#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
172#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
173#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
174#define SDL_BITSPERPIXEL(X) \
175 (SDL_ISPIXELFORMAT_FOURCC(X) ? 0 : (((X) >> 8) & 0xFF))
176#define SDL_BYTESPERPIXEL(X) \
177 (SDL_ISPIXELFORMAT_FOURCC(X) ? \
178 ((((X) == SDL_PIXELFORMAT_YUY2) || \
179 ((X) == SDL_PIXELFORMAT_UYVY) || \
180 ((X) == SDL_PIXELFORMAT_YVYU) || \
181 ((X) == SDL_PIXELFORMAT_P010)) ? 2 : 1) : (((X) >> 0) & 0xFF))
182
183#define SDL_ISPIXELFORMAT_INDEXED(format) \
184 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
185 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
186 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
187 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
188 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
189
190#define SDL_ISPIXELFORMAT_PACKED(format) \
191 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
192 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
193 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
194 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
195
196#define SDL_ISPIXELFORMAT_ARRAY(format) \
197 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
198 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
199 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
200 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
201 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
202 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
203
204#define SDL_ISPIXELFORMAT_10BIT(format) \
205 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
206 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
207 (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010)))
208
209#define SDL_ISPIXELFORMAT_FLOAT(format) \
210 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
211 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
212 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
213
214#define SDL_ISPIXELFORMAT_ALPHA(format) \
215 ((SDL_ISPIXELFORMAT_PACKED(format) && \
216 ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
217 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
218 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
219 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
220 (SDL_ISPIXELFORMAT_ARRAY(format) && \
221 ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
222 (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
223 (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
224 (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
225
226/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
227#define SDL_ISPIXELFORMAT_FOURCC(format) \
228 ((format) && (SDL_PIXELFLAG(format) != 1))
229
230/* Note: If you modify this enum, update SDL_GetPixelFormatName() */
231
232/**
233 * Pixel format.
234 *
235 * SDL's pixel formats have the following naming convention:
236 *
237 * - Names with a list of components and a single bit count, such as RGB24 and
238 * ABGR32, define a platform-independent encoding into bytes in the order
239 * specified. For example, in RGB24 data, each pixel is encoded in 3 bytes
240 * (red, green, blue) in that order, and in ABGR32 data, each pixel is
241 * encoded in 4 bytes alpha, blue, green, red) in that order. Use these
242 * names if the property of a format that is important to you is the order
243 * of the bytes in memory or on disk.
244 * - Names with a bit count per component, such as ARGB8888 and XRGB1555, are
245 * "packed" into an appropriately-sized integer in the platform's native
246 * endianness. For example, ARGB8888 is a sequence of 32-bit integers; in
247 * each integer, the most significant bits are alpha, and the least
248 * significant bits are blue. On a little-endian CPU such as x86, the least
249 * significant bits of each integer are arranged first in memory, but on a
250 * big-endian CPU such as s390x, the most significant bits are arranged
251 * first. Use these names if the property of a format that is important to
252 * you is the meaning of each bit position within a native-endianness
253 * integer.
254 * - In indexed formats such as INDEX4LSB, each pixel is represented by
255 * encoding an index into the palette into the indicated number of bits,
256 * with multiple pixels packed into each byte if appropriate. In LSB
257 * formats, the first (leftmost) pixel is stored in the least-significant
258 * bits of the byte; in MSB formats, it's stored in the most-significant
259 * bits. INDEX8 does not need LSB/MSB variants, because each pixel exactly
260 * fills one byte.
261 *
262 * The 32-bit byte-array encodings such as RGBA32 are aliases for the
263 * appropriate 8888 encoding for the current platform. For example, RGBA32 is
264 * an alias for ABGR8888 on little-endian CPUs like x86, or an alias for
265 * RGBA8888 on big-endian CPUs.
266 *
267 * \since This enum is available since SDL 3.1.3.
268 */
269typedef enum SDL_PixelFormat
270{
273 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0, 1, 0), */
275 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0, 1, 0), */
277 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_4321, 0, 2, 0), */
279 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX2, SDL_BITMAPORDER_1234, 0, 2, 0), */
281 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0, 4, 0), */
283 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0, 4, 0), */
285 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1), */
287 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_332, 8, 1), */
289 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_4444, 12, 2), */
291 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_4444, 12, 2), */
293 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_1555, 15, 2), */
295 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_1555, 15, 2), */
297 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_4444, 16, 2), */
299 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_4444, 16, 2), */
301 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_4444, 16, 2), */
303 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_4444, 16, 2), */
305 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_1555, 16, 2), */
307 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_5551, 16, 2), */
309 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_1555, 16, 2), */
311 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_5551, 16, 2), */
313 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_565, 16, 2), */
315 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_565, 16, 2), */
317 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0, 24, 3), */
319 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0, 24, 3), */
321 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_8888, 24, 4), */
323 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX, SDL_PACKEDLAYOUT_8888, 24, 4), */
325 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_8888, 24, 4), */
327 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX, SDL_PACKEDLAYOUT_8888, 24, 4), */
329 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_8888, 32, 4), */
331 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4), */
333 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_8888, 32, 4), */
335 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA, SDL_PACKEDLAYOUT_8888, 32, 4), */
337 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB, SDL_PACKEDLAYOUT_2101010, 32, 4), */
339 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR, SDL_PACKEDLAYOUT_2101010, 32, 4), */
341 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_2101010, 32, 4), */
343 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, SDL_PACKEDLAYOUT_2101010, 32, 4), */
345 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGB, 0, 48, 6), */
347 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGR, 0, 48, 6), */
349 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_RGBA, 0, 64, 8), */
351 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ARGB, 0, 64, 8), */
353 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_BGRA, 0, 64, 8), */
355 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU16, SDL_ARRAYORDER_ABGR, 0, 64, 8), */
357 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGB, 0, 48, 6), */
359 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGR, 0, 48, 6), */
361 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_RGBA, 0, 64, 8), */
363 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ARGB, 0, 64, 8), */
365 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_BGRA, 0, 64, 8), */
367 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF16, SDL_ARRAYORDER_ABGR, 0, 64, 8), */
369 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGB, 0, 96, 12), */
371 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGR, 0, 96, 12), */
373 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_RGBA, 0, 128, 16), */
375 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ARGB, 0, 128, 16), */
377 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_BGRA, 0, 128, 16), */
379 /* SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYF32, SDL_ARRAYORDER_ABGR, 0, 128, 16), */
380
381 SDL_PIXELFORMAT_YV12 = 0x32315659u, /**< Planar mode: Y + V + U (3 planes) */
382 /* SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'), */
383 SDL_PIXELFORMAT_IYUV = 0x56555949u, /**< Planar mode: Y + U + V (3 planes) */
384 /* SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'), */
385 SDL_PIXELFORMAT_YUY2 = 0x32595559u, /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
386 /* SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'), */
387 SDL_PIXELFORMAT_UYVY = 0x59565955u, /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
388 /* SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'), */
389 SDL_PIXELFORMAT_YVYU = 0x55595659u, /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
390 /* SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'), */
391 SDL_PIXELFORMAT_NV12 = 0x3231564eu, /**< Planar mode: Y + U/V interleaved (2 planes) */
392 /* SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'), */
393 SDL_PIXELFORMAT_NV21 = 0x3132564eu, /**< Planar mode: Y + V/U interleaved (2 planes) */
394 /* SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'), */
395 SDL_PIXELFORMAT_P010 = 0x30313050u, /**< Planar mode: Y + U/V interleaved (2 planes) */
396 /* SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'), */
397 SDL_PIXELFORMAT_EXTERNAL_OES = 0x2053454fu, /**< Android video texture format */
398 /* SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ') */
399
400 /* Aliases for RGBA byte arrays of color data, for the current platform */
401 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
410 #else
419 #endif
421
422/**
423 * Pixels are a representation of a color in a particular color space.
424 *
425 * The first characteristic of a color space is the color type. SDL understands two different color types, RGB and YCbCr, or in SDL also referred to as YUV.
426 *
427 * RGB colors consist of red, green, and blue channels of color that are added together to represent the colors we see on the screen.
428 * https://en.wikipedia.org/wiki/RGB_color_model
429 *
430 * YCbCr colors represent colors as a Y luma brightness component and red and blue chroma color offsets. This color representation takes advantage of the fact that the human eye is more sensitive to brightness than the color in an image. The Cb and Cr components are often compressed and have lower resolution than the luma component.
431 * https://en.wikipedia.org/wiki/YCbCr
432 *
433 * When the color information in YCbCr is compressed, the Y pixels are left at full resolution and each Cr and Cb pixel represents an average of the color information in a block of Y pixels. The chroma location determines where in that block of pixels the color information is coming from.
434 *
435 * The color range defines how much of the pixel to use when converting a pixel into a color on the display. When the full color range is used, the entire numeric range of the pixel bits is significant. When narrow color range is used, for historical reasons, the pixel uses only a portion of the numeric range to represent colors.
436 *
437 * The color primaries and white point are a definition of the colors in the color space relative to the standard XYZ color space.
438 * https://en.wikipedia.org/wiki/CIE_1931_color_space
439 *
440 * The transfer characteristic, or opto-electrical transfer function (OETF), is the way a color is converted from mathematically linear space into a non-linear output signals.
441 * https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
442 *
443 * The matrix coefficients are used to convert between YCbCr and RGB colors.
444 */
445
446/**
447 * Colorspace color type.
448 *
449 * \since This enum is available since SDL 3.1.3.
450 */
457
458/**
459 * Colorspace color range, as described by
460 * https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
461 *
462 * \since This enum is available since SDL 3.1.3.
463 */
464typedef enum SDL_ColorRange
465{
467 SDL_COLOR_RANGE_LIMITED = 1, /**< Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma */
468 SDL_COLOR_RANGE_FULL = 2 /**< Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma */
470
471/**
472 * Colorspace color primaries, as described by
473 * https://www.itu.int/rec/T-REC-H.273-201612-S/en
474 *
475 * \since This enum is available since SDL 3.1.3.
476 */
478{
480 SDL_COLOR_PRIMARIES_BT709 = 1, /**< ITU-R BT.709-6 */
482 SDL_COLOR_PRIMARIES_BT470M = 4, /**< ITU-R BT.470-6 System M */
483 SDL_COLOR_PRIMARIES_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 */
484 SDL_COLOR_PRIMARIES_BT601 = 6, /**< ITU-R BT.601-7 525, SMPTE 170M */
485 SDL_COLOR_PRIMARIES_SMPTE240 = 7, /**< SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 */
486 SDL_COLOR_PRIMARIES_GENERIC_FILM = 8, /**< Generic film (color filters using Illuminant C) */
487 SDL_COLOR_PRIMARIES_BT2020 = 9, /**< ITU-R BT.2020-2 / ITU-R BT.2100-0 */
488 SDL_COLOR_PRIMARIES_XYZ = 10, /**< SMPTE ST 428-1 */
489 SDL_COLOR_PRIMARIES_SMPTE431 = 11, /**< SMPTE RP 431-2 */
490 SDL_COLOR_PRIMARIES_SMPTE432 = 12, /**< SMPTE EG 432-1 / DCI P3 */
491 SDL_COLOR_PRIMARIES_EBU3213 = 22, /**< EBU Tech. 3213-E */
494
495/**
496 * Colorspace transfer characteristics.
497 *
498 * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
499 *
500 * \since This enum is available since SDL 3.1.3.
501 */
503{
505 SDL_TRANSFER_CHARACTERISTICS_BT709 = 1, /**< Rec. ITU-R BT.709-6 / ITU-R BT1361 */
507 SDL_TRANSFER_CHARACTERISTICS_GAMMA22 = 4, /**< ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM */
508 SDL_TRANSFER_CHARACTERISTICS_GAMMA28 = 5, /**< ITU-R BT.470-6 System B, G */
509 SDL_TRANSFER_CHARACTERISTICS_BT601 = 6, /**< SMPTE ST 170M / ITU-R BT.601-7 525 or 625 */
510 SDL_TRANSFER_CHARACTERISTICS_SMPTE240 = 7, /**< SMPTE ST 240M */
514 SDL_TRANSFER_CHARACTERISTICS_IEC61966 = 11, /**< IEC 61966-2-4 */
515 SDL_TRANSFER_CHARACTERISTICS_BT1361 = 12, /**< ITU-R BT1361 Extended Colour Gamut */
516 SDL_TRANSFER_CHARACTERISTICS_SRGB = 13, /**< IEC 61966-2-1 (sRGB or sYCC) */
517 SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14, /**< ITU-R BT2020 for 10-bit system */
518 SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15, /**< ITU-R BT2020 for 12-bit system */
519 SDL_TRANSFER_CHARACTERISTICS_PQ = 16, /**< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems */
520 SDL_TRANSFER_CHARACTERISTICS_SMPTE428 = 17, /**< SMPTE ST 428-1 */
521 SDL_TRANSFER_CHARACTERISTICS_HLG = 18, /**< ARIB STD-B67, known as "hybrid log-gamma" (HLG) */
524
525/**
526 * Colorspace matrix coefficients.
527 *
528 * These are as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
529 *
530 * \since This enum is available since SDL 3.1.3.
531 */
533{
535 SDL_MATRIX_COEFFICIENTS_BT709 = 1, /**< ITU-R BT.709-6 */
537 SDL_MATRIX_COEFFICIENTS_FCC = 4, /**< US FCC Title 47 */
538 SDL_MATRIX_COEFFICIENTS_BT470BG = 5, /**< ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625, functionally the same as SDL_MATRIX_COEFFICIENTS_BT601 */
539 SDL_MATRIX_COEFFICIENTS_BT601 = 6, /**< ITU-R BT.601-7 525 */
540 SDL_MATRIX_COEFFICIENTS_SMPTE240 = 7, /**< SMPTE 240M */
542 SDL_MATRIX_COEFFICIENTS_BT2020_NCL = 9, /**< ITU-R BT.2020-2 non-constant luminance */
543 SDL_MATRIX_COEFFICIENTS_BT2020_CL = 10, /**< ITU-R BT.2020-2 constant luminance */
544 SDL_MATRIX_COEFFICIENTS_SMPTE2085 = 11, /**< SMPTE ST 2085 */
547 SDL_MATRIX_COEFFICIENTS_ICTCP = 14, /**< ITU-R BT.2100-0 ICTCP */
550
551/**
552 * Colorspace chroma sample location.
553 *
554 * \since This enum is available since SDL 3.1.3.
555 */
557{
558 SDL_CHROMA_LOCATION_NONE = 0, /**< RGB, no chroma sampling */
559 SDL_CHROMA_LOCATION_LEFT = 1, /**< In MPEG-2, MPEG-4, and AVC, Cb and Cr are taken on midpoint of the left-edge of the 2x2 square. In other words, they have the same horizontal location as the top-left pixel, but is shifted one-half pixel down vertically. */
560 SDL_CHROMA_LOCATION_CENTER = 2, /**< In JPEG/JFIF, H.261, and MPEG-1, Cb and Cr are taken at the center of the 2x2 square. In other words, they are offset one-half pixel to the right and one-half pixel down compared to the top-left pixel. */
561 SDL_CHROMA_LOCATION_TOPLEFT = 3 /**< In HEVC for BT.2020 and BT.2100 content (in particular on Blu-rays), Cb and Cr are sampled at the same location as the group's top-left Y pixel ("co-sited", "co-located"). */
563
564
565/* Colorspace definition */
566#define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma) \
567 (((Uint32)(type) << 28) | ((Uint32)(range) << 24) | ((Uint32)(chroma) << 20) | \
568 ((Uint32)(primaries) << 10) | ((Uint32)(transfer) << 5) | ((Uint32)(matrix) << 0))
569
570#define SDL_COLORSPACETYPE(X) (SDL_ColorType)(((X) >> 28) & 0x0F)
571#define SDL_COLORSPACERANGE(X) (SDL_ColorRange)(((X) >> 24) & 0x0F)
572#define SDL_COLORSPACECHROMA(X) (SDL_ChromaLocation)(((X) >> 20) & 0x0F)
573#define SDL_COLORSPACEPRIMARIES(X) (SDL_ColorPrimaries)(((X) >> 10) & 0x1F)
574#define SDL_COLORSPACETRANSFER(X) (SDL_TransferCharacteristics)(((X) >> 5) & 0x1F)
575#define SDL_COLORSPACEMATRIX(X) (SDL_MatrixCoefficients)((X) & 0x1F)
576
577#define SDL_ISCOLORSPACE_MATRIX_BT601(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT601 || SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT470BG)
578#define SDL_ISCOLORSPACE_MATRIX_BT709(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT709)
579#define SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(X) (SDL_COLORSPACEMATRIX(X) == SDL_MATRIX_COEFFICIENTS_BT2020_NCL)
580#define SDL_ISCOLORSPACE_LIMITED_RANGE(X) (SDL_COLORSPACERANGE(X) != SDL_COLOR_RANGE_FULL)
581#define SDL_ISCOLORSPACE_FULL_RANGE(X) (SDL_COLORSPACERANGE(X) == SDL_COLOR_RANGE_FULL)
582
583/**
584 * Colorspace definitions.
585 *
586 * Since similar colorspaces may vary in their details (matrix, transfer
587 * function, etc.), this is not an exhaustive list, but rather a
588 * representative sample of the kinds of colorspaces supported in SDL.
589 *
590 * \since This enum is available since SDL 3.1.3.
591 *
592 * \sa SDL_ColorPrimaries
593 * \sa SDL_ColorRange
594 * \sa SDL_ColorType
595 * \sa SDL_MatrixCoefficients
596 * \sa SDL_TransferCharacteristics
597 */
598typedef enum SDL_Colorspace
599{
601
602 /* sRGB is a gamma corrected colorspace, and the default colorspace for SDL rendering and 8-bit RGB surfaces */
603 SDL_COLORSPACE_SRGB = 0x120005a0u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 */
604 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
605 SDL_COLOR_RANGE_FULL,
606 SDL_COLOR_PRIMARIES_BT709,
607 SDL_TRANSFER_CHARACTERISTICS_SRGB,
608 SDL_MATRIX_COEFFICIENTS_IDENTITY,
609 SDL_CHROMA_LOCATION_NONE), */
610
611 /* This is a linear colorspace and the default colorspace for floating point surfaces. On Windows this is the scRGB colorspace, and on Apple platforms this is kCGColorSpaceExtendedLinearSRGB for EDR content */
612 SDL_COLORSPACE_SRGB_LINEAR = 0x12000500u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 */
613 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
614 SDL_COLOR_RANGE_FULL,
615 SDL_COLOR_PRIMARIES_BT709,
616 SDL_TRANSFER_CHARACTERISTICS_LINEAR,
617 SDL_MATRIX_COEFFICIENTS_IDENTITY,
618 SDL_CHROMA_LOCATION_NONE), */
619
620 /* HDR10 is a non-linear HDR colorspace and the default colorspace for 10-bit surfaces */
621 SDL_COLORSPACE_HDR10 = 0x12002600u, /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 */
622 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_RGB,
623 SDL_COLOR_RANGE_FULL,
624 SDL_COLOR_PRIMARIES_BT2020,
625 SDL_TRANSFER_CHARACTERISTICS_PQ,
626 SDL_MATRIX_COEFFICIENTS_IDENTITY,
627 SDL_CHROMA_LOCATION_NONE), */
628
629 SDL_COLORSPACE_JPEG = 0x220004c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 */
630 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
631 SDL_COLOR_RANGE_FULL,
632 SDL_COLOR_PRIMARIES_BT709,
633 SDL_TRANSFER_CHARACTERISTICS_BT601,
634 SDL_MATRIX_COEFFICIENTS_BT601,
635 SDL_CHROMA_LOCATION_NONE), */
636
637 SDL_COLORSPACE_BT601_LIMITED = 0x211018c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
638 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
639 SDL_COLOR_RANGE_LIMITED,
640 SDL_COLOR_PRIMARIES_BT601,
641 SDL_TRANSFER_CHARACTERISTICS_BT601,
642 SDL_MATRIX_COEFFICIENTS_BT601,
643 SDL_CHROMA_LOCATION_LEFT), */
644
645 SDL_COLORSPACE_BT601_FULL = 0x221018c6u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
646 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
647 SDL_COLOR_RANGE_FULL,
648 SDL_COLOR_PRIMARIES_BT601,
649 SDL_TRANSFER_CHARACTERISTICS_BT601,
650 SDL_MATRIX_COEFFICIENTS_BT601,
651 SDL_CHROMA_LOCATION_LEFT), */
652
653 SDL_COLORSPACE_BT709_LIMITED = 0x21100421u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
654 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
655 SDL_COLOR_RANGE_LIMITED,
656 SDL_COLOR_PRIMARIES_BT709,
657 SDL_TRANSFER_CHARACTERISTICS_BT709,
658 SDL_MATRIX_COEFFICIENTS_BT709,
659 SDL_CHROMA_LOCATION_LEFT), */
660
661 SDL_COLORSPACE_BT709_FULL = 0x22100421u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
662 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
663 SDL_COLOR_RANGE_FULL,
664 SDL_COLOR_PRIMARIES_BT709,
665 SDL_TRANSFER_CHARACTERISTICS_BT709,
666 SDL_MATRIX_COEFFICIENTS_BT709,
667 SDL_CHROMA_LOCATION_LEFT), */
668
669 SDL_COLORSPACE_BT2020_LIMITED = 0x21102609u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 */
670 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
671 SDL_COLOR_RANGE_LIMITED,
672 SDL_COLOR_PRIMARIES_BT2020,
673 SDL_TRANSFER_CHARACTERISTICS_PQ,
674 SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
675 SDL_CHROMA_LOCATION_LEFT), */
676
677 SDL_COLORSPACE_BT2020_FULL = 0x22102609u, /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 */
678 /* SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
679 SDL_COLOR_RANGE_FULL,
680 SDL_COLOR_PRIMARIES_BT2020,
681 SDL_TRANSFER_CHARACTERISTICS_PQ,
682 SDL_MATRIX_COEFFICIENTS_BT2020_NCL,
683 SDL_CHROMA_LOCATION_LEFT), */
684
685 SDL_COLORSPACE_RGB_DEFAULT = SDL_COLORSPACE_SRGB, /**< The default colorspace for RGB surfaces if no colorspace is specified */
686 SDL_COLORSPACE_YUV_DEFAULT = SDL_COLORSPACE_JPEG /**< The default colorspace for YUV surfaces if no colorspace is specified */
688
689/**
690 * A structure that represents a color as RGBA components.
691 *
692 * The bits of this structure can be directly reinterpreted as an
693 * integer-packed color which uses the SDL_PIXELFORMAT_RGBA32 format
694 * (SDL_PIXELFORMAT_ABGR8888 on little-endian systems and
695 * SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
696 *
697 * \since This struct is available since SDL 3.1.3.
698 */
706
707/**
708 * The bits of this structure can be directly reinterpreted as a float-packed
709 * color which uses the SDL_PIXELFORMAT_RGBA128_FLOAT format
710 *
711 * \since This struct is available since SDL 3.1.3.
712 */
713typedef struct SDL_FColor
714{
715 float r;
716 float g;
717 float b;
718 float a;
719} SDL_FColor;
720
721/**
722 * A set of indexed colors representing a palette.
723 *
724 * \since This struct is available since SDL 3.1.3.
725 *
726 * \sa SDL_SetPaletteColors
727 */
728typedef struct SDL_Palette
729{
730 int ncolors; /**< number of elements in `colors`. */
731 SDL_Color *colors; /**< an array of colors, `ncolors` long. */
732 Uint32 version; /**< internal use only, do not touch. */
733 int refcount; /**< internal use only, do not touch. */
735
736/**
737 * Details about the format of a pixel.
738 *
739 * \since This struct is available since SDL 3.1.3.
740 */
760
761/**
762 * Get the human readable name of a pixel format.
763 *
764 * \param format the pixel format to query.
765 * \returns the human readable name of the specified pixel format or
766 * "SDL_PIXELFORMAT_UNKNOWN" if the format isn't recognized.
767 *
768 * \threadsafety It is safe to call this function from any thread.
769 *
770 * \since This function is available since SDL 3.1.3.
771 */
772extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat format);
773
774/**
775 * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
776 *
777 * \param format one of the SDL_PixelFormat values.
778 * \param bpp a bits per pixel value; usually 15, 16, or 32.
779 * \param Rmask a pointer filled in with the red mask for the format.
780 * \param Gmask a pointer filled in with the green mask for the format.
781 * \param Bmask a pointer filled in with the blue mask for the format.
782 * \param Amask a pointer filled in with the alpha mask for the format.
783 * \returns true on success or false on failure; call SDL_GetError() for more
784 * information.
785 *
786 * \threadsafety It is safe to call this function from any thread.
787 *
788 * \since This function is available since SDL 3.1.3.
789 *
790 * \sa SDL_GetPixelFormatForMasks
791 */
792extern SDL_DECLSPEC bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
793
794/**
795 * Convert a bpp value and RGBA masks to an enumerated pixel format.
796 *
797 * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
798 * possible.
799 *
800 * \param bpp a bits per pixel value; usually 15, 16, or 32.
801 * \param Rmask the red mask for the format.
802 * \param Gmask the green mask for the format.
803 * \param Bmask the blue mask for the format.
804 * \param Amask the alpha mask for the format.
805 * \returns the SDL_PixelFormat value corresponding to the format masks, or
806 * SDL_PIXELFORMAT_UNKNOWN if there isn't a match.
807 *
808 * \threadsafety It is safe to call this function from any thread.
809 *
810 * \since This function is available since SDL 3.1.3.
811 *
812 * \sa SDL_GetMasksForPixelFormat
813 */
814extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
815
816/**
817 * Create an SDL_PixelFormatDetails structure corresponding to a pixel format.
818 *
819 * Returned structure may come from a shared global cache (i.e. not newly
820 * allocated), and hence should not be modified, especially the palette. Weird
821 * errors such as `Blit combination not supported` may occur.
822 *
823 * \param format one of the SDL_PixelFormat values.
824 * \returns a pointer to a SDL_PixelFormatDetails structure or NULL on
825 * failure; call SDL_GetError() for more information.
826 *
827 * \threadsafety It is safe to call this function from any thread.
828 *
829 * \since This function is available since SDL 3.1.3.
830 */
831extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDetails(SDL_PixelFormat format);
832
833/**
834 * Create a palette structure with the specified number of color entries.
835 *
836 * The palette entries are initialized to white.
837 *
838 * \param ncolors represents the number of color entries in the color palette.
839 * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
840 * there wasn't enough memory); call SDL_GetError() for more
841 * information.
842 *
843 * \threadsafety It is safe to call this function from any thread.
844 *
845 * \since This function is available since SDL 3.1.3.
846 *
847 * \sa SDL_DestroyPalette
848 * \sa SDL_SetPaletteColors
849 * \sa SDL_SetSurfacePalette
850 */
851extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreatePalette(int ncolors);
852
853/**
854 * Set a range of colors in a palette.
855 *
856 * \param palette the SDL_Palette structure to modify.
857 * \param colors an array of SDL_Color structures to copy into the palette.
858 * \param firstcolor the index of the first palette entry to modify.
859 * \param ncolors the number of entries to modify.
860 * \returns true on success or false on failure; call SDL_GetError() for more
861 * information.
862 *
863 * \threadsafety It is safe to call this function from any thread, as long as
864 * the palette is not modified or destroyed in another thread.
865 *
866 * \since This function is available since SDL 3.1.3.
867 */
868extern SDL_DECLSPEC bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
869
870/**
871 * Free a palette created with SDL_CreatePalette().
872 *
873 * \param palette the SDL_Palette structure to be freed.
874 *
875 * \threadsafety It is safe to call this function from any thread, as long as
876 * the palette is not modified or destroyed in another thread.
877 *
878 * \since This function is available since SDL 3.1.3.
879 *
880 * \sa SDL_CreatePalette
881 */
882extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette *palette);
883
884/**
885 * Map an RGB triple to an opaque pixel value for a given pixel format.
886 *
887 * This function maps the RGB color value to the specified pixel format and
888 * returns the pixel value best approximating the given RGB color value for
889 * the given pixel format.
890 *
891 * If the format has a palette (8-bit) the index of the closest matching color
892 * in the palette will be returned.
893 *
894 * If the specified pixel format has an alpha component it will be returned as
895 * all 1 bits (fully opaque).
896 *
897 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
898 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
899 * format the return value can be assigned to a Uint16, and similarly a Uint8
900 * for an 8-bpp format).
901 *
902 * \param format a pointer to SDL_PixelFormatDetails describing the pixel
903 * format.
904 * \param palette an optional palette for indexed formats, may be NULL.
905 * \param r the red component of the pixel in the range 0-255.
906 * \param g the green component of the pixel in the range 0-255.
907 * \param b the blue component of the pixel in the range 0-255.
908 * \returns a pixel value.
909 *
910 * \threadsafety It is safe to call this function from any thread, as long as
911 * the palette is not modified.
912 *
913 * \since This function is available since SDL 3.1.3.
914 *
915 * \sa SDL_GetPixelFormatDetails
916 * \sa SDL_GetRGB
917 * \sa SDL_MapRGBA
918 * \sa SDL_MapSurfaceRGB
919 */
920extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b);
921
922/**
923 * Map an RGBA quadruple to a pixel value for a given pixel format.
924 *
925 * This function maps the RGBA color value to the specified pixel format and
926 * returns the pixel value best approximating the given RGBA color value for
927 * the given pixel format.
928 *
929 * If the specified pixel format has no alpha component the alpha value will
930 * be ignored (as it will be in formats with a palette).
931 *
932 * If the format has a palette (8-bit) the index of the closest matching color
933 * in the palette will be returned.
934 *
935 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
936 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
937 * format the return value can be assigned to a Uint16, and similarly a Uint8
938 * for an 8-bpp format).
939 *
940 * \param format a pointer to SDL_PixelFormatDetails describing the pixel
941 * format.
942 * \param palette an optional palette for indexed formats, may be NULL.
943 * \param r the red component of the pixel in the range 0-255.
944 * \param g the green component of the pixel in the range 0-255.
945 * \param b the blue component of the pixel in the range 0-255.
946 * \param a the alpha component of the pixel in the range 0-255.
947 * \returns a pixel value.
948 *
949 * \threadsafety It is safe to call this function from any thread, as long as
950 * the palette is not modified.
951 *
952 * \since This function is available since SDL 3.1.3.
953 *
954 * \sa SDL_GetPixelFormatDetails
955 * \sa SDL_GetRGBA
956 * \sa SDL_MapRGB
957 * \sa SDL_MapSurfaceRGBA
958 */
959extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
960
961/**
962 * Get RGB values from a pixel in the specified format.
963 *
964 * This function uses the entire 8-bit [0..255] range when converting color
965 * components from pixel formats with less than 8-bits per RGB component
966 * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
967 * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
968 *
969 * \param pixel a pixel value.
970 * \param format a pointer to SDL_PixelFormatDetails describing the pixel
971 * format.
972 * \param palette an optional palette for indexed formats, may be NULL.
973 * \param r a pointer filled in with the red component, may be NULL.
974 * \param g a pointer filled in with the green component, may be NULL.
975 * \param b a pointer filled in with the blue component, may be NULL.
976 *
977 * \threadsafety It is safe to call this function from any thread, as long as
978 * the palette is not modified.
979 *
980 * \since This function is available since SDL 3.1.3.
981 *
982 * \sa SDL_GetPixelFormatDetails
983 * \sa SDL_GetRGBA
984 * \sa SDL_MapRGB
985 * \sa SDL_MapRGBA
986 */
987extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
988
989/**
990 * Get RGBA values from a pixel in the specified format.
991 *
992 * This function uses the entire 8-bit [0..255] range when converting color
993 * components from pixel formats with less than 8-bits per RGB component
994 * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
995 * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
996 *
997 * If the surface has no alpha component, the alpha will be returned as 0xff
998 * (100% opaque).
999 *
1000 * \param pixel a pixel value.
1001 * \param format a pointer to SDL_PixelFormatDetails describing the pixel
1002 * format.
1003 * \param palette an optional palette for indexed formats, may be NULL.
1004 * \param r a pointer filled in with the red component, may be NULL.
1005 * \param g a pointer filled in with the green component, may be NULL.
1006 * \param b a pointer filled in with the blue component, may be NULL.
1007 * \param a a pointer filled in with the alpha component, may be NULL.
1008 *
1009 * \threadsafety It is safe to call this function from any thread, as long as
1010 * the palette is not modified.
1011 *
1012 * \since This function is available since SDL 3.1.3.
1013 *
1014 * \sa SDL_GetPixelFormatDetails
1015 * \sa SDL_GetRGB
1016 * \sa SDL_MapRGB
1017 * \sa SDL_MapRGBA
1018 */
1019extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
1020
1021
1022/* Ends C function definitions when using C++ */
1023#ifdef __cplusplus
1024}
1025#endif
1026#include <SDL3/SDL_close_code.h>
1027
1028#endif /* SDL_pixels_h_ */
SDL_MatrixCoefficients
Definition SDL_pixels.h:533
@ SDL_MATRIX_COEFFICIENTS_BT709
Definition SDL_pixels.h:535
@ SDL_MATRIX_COEFFICIENTS_BT2020_CL
Definition SDL_pixels.h:543
@ SDL_MATRIX_COEFFICIENTS_BT601
Definition SDL_pixels.h:539
@ SDL_MATRIX_COEFFICIENTS_BT2020_NCL
Definition SDL_pixels.h:542
@ SDL_MATRIX_COEFFICIENTS_SMPTE240
Definition SDL_pixels.h:540
@ SDL_MATRIX_COEFFICIENTS_YCGCO
Definition SDL_pixels.h:541
@ SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL
Definition SDL_pixels.h:545
@ SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL
Definition SDL_pixels.h:546
@ SDL_MATRIX_COEFFICIENTS_UNSPECIFIED
Definition SDL_pixels.h:536
@ SDL_MATRIX_COEFFICIENTS_CUSTOM
Definition SDL_pixels.h:548
@ SDL_MATRIX_COEFFICIENTS_ICTCP
Definition SDL_pixels.h:547
@ SDL_MATRIX_COEFFICIENTS_IDENTITY
Definition SDL_pixels.h:534
@ SDL_MATRIX_COEFFICIENTS_FCC
Definition SDL_pixels.h:537
@ SDL_MATRIX_COEFFICIENTS_BT470BG
Definition SDL_pixels.h:538
@ SDL_MATRIX_COEFFICIENTS_SMPTE2085
Definition SDL_pixels.h:544
SDL_PixelType
Definition SDL_pixels.h:83
@ SDL_PIXELTYPE_UNKNOWN
Definition SDL_pixels.h:84
@ SDL_PIXELTYPE_ARRAYU16
Definition SDL_pixels.h:92
@ SDL_PIXELTYPE_PACKED32
Definition SDL_pixels.h:90
@ SDL_PIXELTYPE_INDEX2
Definition SDL_pixels.h:97
@ SDL_PIXELTYPE_ARRAYU8
Definition SDL_pixels.h:91
@ SDL_PIXELTYPE_INDEX4
Definition SDL_pixels.h:86
@ SDL_PIXELTYPE_PACKED8
Definition SDL_pixels.h:88
@ SDL_PIXELTYPE_ARRAYF16
Definition SDL_pixels.h:94
@ SDL_PIXELTYPE_ARRAYU32
Definition SDL_pixels.h:93
@ SDL_PIXELTYPE_INDEX1
Definition SDL_pixels.h:85
@ SDL_PIXELTYPE_ARRAYF32
Definition SDL_pixels.h:95
@ SDL_PIXELTYPE_INDEX8
Definition SDL_pixels.h:87
@ SDL_PIXELTYPE_PACKED16
Definition SDL_pixels.h:89
SDL_ColorRange
Definition SDL_pixels.h:465
@ SDL_COLOR_RANGE_LIMITED
Definition SDL_pixels.h:467
@ SDL_COLOR_RANGE_FULL
Definition SDL_pixels.h:468
@ SDL_COLOR_RANGE_UNKNOWN
Definition SDL_pixels.h:466
SDL_ColorPrimaries
Definition SDL_pixels.h:478
@ SDL_COLOR_PRIMARIES_SMPTE431
Definition SDL_pixels.h:489
@ SDL_COLOR_PRIMARIES_CUSTOM
Definition SDL_pixels.h:492
@ SDL_COLOR_PRIMARIES_EBU3213
Definition SDL_pixels.h:491
@ SDL_COLOR_PRIMARIES_GENERIC_FILM
Definition SDL_pixels.h:486
@ SDL_COLOR_PRIMARIES_BT601
Definition SDL_pixels.h:484
@ SDL_COLOR_PRIMARIES_UNSPECIFIED
Definition SDL_pixels.h:481
@ SDL_COLOR_PRIMARIES_SMPTE240
Definition SDL_pixels.h:485
@ SDL_COLOR_PRIMARIES_XYZ
Definition SDL_pixels.h:488
@ SDL_COLOR_PRIMARIES_UNKNOWN
Definition SDL_pixels.h:479
@ SDL_COLOR_PRIMARIES_SMPTE432
Definition SDL_pixels.h:490
@ SDL_COLOR_PRIMARIES_BT2020
Definition SDL_pixels.h:487
@ SDL_COLOR_PRIMARIES_BT470BG
Definition SDL_pixels.h:483
@ SDL_COLOR_PRIMARIES_BT709
Definition SDL_pixels.h:480
@ SDL_COLOR_PRIMARIES_BT470M
Definition SDL_pixels.h:482
Uint32 SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b)
SDL_PackedLayout
Definition SDL_pixels.h:152
@ SDL_PACKEDLAYOUT_NONE
Definition SDL_pixels.h:153
@ SDL_PACKEDLAYOUT_8888
Definition SDL_pixels.h:159
@ SDL_PACKEDLAYOUT_1010102
Definition SDL_pixels.h:161
@ SDL_PACKEDLAYOUT_565
Definition SDL_pixels.h:158
@ SDL_PACKEDLAYOUT_332
Definition SDL_pixels.h:154
@ SDL_PACKEDLAYOUT_5551
Definition SDL_pixels.h:157
@ SDL_PACKEDLAYOUT_1555
Definition SDL_pixels.h:156
@ SDL_PACKEDLAYOUT_4444
Definition SDL_pixels.h:155
@ SDL_PACKEDLAYOUT_2101010
Definition SDL_pixels.h:160
SDL_Palette * SDL_CreatePalette(int ncolors)
SDL_BitmapOrder
Definition SDL_pixels.h:106
@ SDL_BITMAPORDER_1234
Definition SDL_pixels.h:109
@ SDL_BITMAPORDER_NONE
Definition SDL_pixels.h:107
@ SDL_BITMAPORDER_4321
Definition SDL_pixels.h:108
SDL_ChromaLocation
Definition SDL_pixels.h:557
@ SDL_CHROMA_LOCATION_NONE
Definition SDL_pixels.h:558
@ SDL_CHROMA_LOCATION_TOPLEFT
Definition SDL_pixels.h:561
@ SDL_CHROMA_LOCATION_CENTER
Definition SDL_pixels.h:560
@ SDL_CHROMA_LOCATION_LEFT
Definition SDL_pixels.h:559
Uint32 SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
void SDL_DestroyPalette(SDL_Palette *palette)
SDL_ColorType
Definition SDL_pixels.h:452
@ SDL_COLOR_TYPE_RGB
Definition SDL_pixels.h:454
@ SDL_COLOR_TYPE_YCBCR
Definition SDL_pixels.h:455
@ SDL_COLOR_TYPE_UNKNOWN
Definition SDL_pixels.h:453
SDL_TransferCharacteristics
Definition SDL_pixels.h:503
@ SDL_TRANSFER_CHARACTERISTICS_BT709
Definition SDL_pixels.h:505
@ SDL_TRANSFER_CHARACTERISTICS_BT1361
Definition SDL_pixels.h:515
@ SDL_TRANSFER_CHARACTERISTICS_CUSTOM
Definition SDL_pixels.h:522
@ SDL_TRANSFER_CHARACTERISTICS_HLG
Definition SDL_pixels.h:521
@ SDL_TRANSFER_CHARACTERISTICS_LOG100_SQRT10
Definition SDL_pixels.h:513
@ SDL_TRANSFER_CHARACTERISTICS_UNKNOWN
Definition SDL_pixels.h:504
@ SDL_TRANSFER_CHARACTERISTICS_BT601
Definition SDL_pixels.h:509
@ SDL_TRANSFER_CHARACTERISTICS_IEC61966
Definition SDL_pixels.h:514
@ SDL_TRANSFER_CHARACTERISTICS_UNSPECIFIED
Definition SDL_pixels.h:506
@ SDL_TRANSFER_CHARACTERISTICS_SMPTE428
Definition SDL_pixels.h:520
@ SDL_TRANSFER_CHARACTERISTICS_LOG100
Definition SDL_pixels.h:512
@ SDL_TRANSFER_CHARACTERISTICS_GAMMA28
Definition SDL_pixels.h:508
@ SDL_TRANSFER_CHARACTERISTICS_SMPTE240
Definition SDL_pixels.h:510
@ SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT
Definition SDL_pixels.h:517
@ SDL_TRANSFER_CHARACTERISTICS_SRGB
Definition SDL_pixels.h:516
@ SDL_TRANSFER_CHARACTERISTICS_PQ
Definition SDL_pixels.h:519
@ SDL_TRANSFER_CHARACTERISTICS_LINEAR
Definition SDL_pixels.h:511
@ SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT
Definition SDL_pixels.h:518
@ SDL_TRANSFER_CHARACTERISTICS_GAMMA22
Definition SDL_pixels.h:507
SDL_ArrayOrder
Definition SDL_pixels.h:136
@ SDL_ARRAYORDER_RGB
Definition SDL_pixels.h:138
@ SDL_ARRAYORDER_NONE
Definition SDL_pixels.h:137
@ SDL_ARRAYORDER_ARGB
Definition SDL_pixels.h:140
@ SDL_ARRAYORDER_BGRA
Definition SDL_pixels.h:142
@ SDL_ARRAYORDER_ABGR
Definition SDL_pixels.h:143
@ SDL_ARRAYORDER_RGBA
Definition SDL_pixels.h:139
@ SDL_ARRAYORDER_BGR
Definition SDL_pixels.h:141
bool SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
const char * SDL_GetPixelFormatName(SDL_PixelFormat format)
SDL_Colorspace
Definition SDL_pixels.h:599
@ SDL_COLORSPACE_BT2020_LIMITED
Definition SDL_pixels.h:669
@ SDL_COLORSPACE_BT601_LIMITED
Definition SDL_pixels.h:637
@ SDL_COLORSPACE_BT709_FULL
Definition SDL_pixels.h:661
@ SDL_COLORSPACE_HDR10
Definition SDL_pixels.h:621
@ SDL_COLORSPACE_BT601_FULL
Definition SDL_pixels.h:645
@ SDL_COLORSPACE_UNKNOWN
Definition SDL_pixels.h:600
@ SDL_COLORSPACE_BT2020_FULL
Definition SDL_pixels.h:677
@ SDL_COLORSPACE_JPEG
Definition SDL_pixels.h:629
@ SDL_COLORSPACE_BT709_LIMITED
Definition SDL_pixels.h:653
@ SDL_COLORSPACE_SRGB_LINEAR
Definition SDL_pixels.h:612
@ SDL_COLORSPACE_SRGB
Definition SDL_pixels.h:603
@ SDL_COLORSPACE_RGB_DEFAULT
Definition SDL_pixels.h:685
@ SDL_COLORSPACE_YUV_DEFAULT
Definition SDL_pixels.h:686
SDL_PixelFormat
Definition SDL_pixels.h:270
@ SDL_PIXELFORMAT_BGR48_FLOAT
Definition SDL_pixels.h:358
@ SDL_PIXELFORMAT_RGBA128_FLOAT
Definition SDL_pixels.h:372
@ SDL_PIXELFORMAT_BGR565
Definition SDL_pixels.h:314
@ SDL_PIXELFORMAT_P010
Definition SDL_pixels.h:395
@ SDL_PIXELFORMAT_EXTERNAL_OES
Definition SDL_pixels.h:397
@ SDL_PIXELFORMAT_ARGB64
Definition SDL_pixels.h:350
@ SDL_PIXELFORMAT_YVYU
Definition SDL_pixels.h:389
@ SDL_PIXELFORMAT_RGB332
Definition SDL_pixels.h:286
@ SDL_PIXELFORMAT_INDEX2LSB
Definition SDL_pixels.h:276
@ SDL_PIXELFORMAT_INDEX1LSB
Definition SDL_pixels.h:272
@ SDL_PIXELFORMAT_RGB96_FLOAT
Definition SDL_pixels.h:368
@ SDL_PIXELFORMAT_RGBX32
Definition SDL_pixels.h:406
@ SDL_PIXELFORMAT_ABGR4444
Definition SDL_pixels.h:300
@ SDL_PIXELFORMAT_BGRA4444
Definition SDL_pixels.h:302
@ SDL_PIXELFORMAT_BGR24
Definition SDL_pixels.h:318
@ SDL_PIXELFORMAT_INDEX4MSB
Definition SDL_pixels.h:282
@ SDL_PIXELFORMAT_ABGR2101010
Definition SDL_pixels.h:342
@ SDL_PIXELFORMAT_BGRA32
Definition SDL_pixels.h:404
@ SDL_PIXELFORMAT_XBGR2101010
Definition SDL_pixels.h:338
@ SDL_PIXELFORMAT_RGBA64_FLOAT
Definition SDL_pixels.h:360
@ SDL_PIXELFORMAT_INDEX2MSB
Definition SDL_pixels.h:278
@ SDL_PIXELFORMAT_BGRA64_FLOAT
Definition SDL_pixels.h:364
@ SDL_PIXELFORMAT_RGBA8888
Definition SDL_pixels.h:330
@ SDL_PIXELFORMAT_RGBA5551
Definition SDL_pixels.h:306
@ SDL_PIXELFORMAT_ARGB1555
Definition SDL_pixels.h:304
@ SDL_PIXELFORMAT_XBGR4444
Definition SDL_pixels.h:290
@ SDL_PIXELFORMAT_RGBA64
Definition SDL_pixels.h:348
@ SDL_PIXELFORMAT_INDEX8
Definition SDL_pixels.h:284
@ SDL_PIXELFORMAT_XRGB2101010
Definition SDL_pixels.h:336
@ SDL_PIXELFORMAT_XRGB8888
Definition SDL_pixels.h:320
@ SDL_PIXELFORMAT_UYVY
Definition SDL_pixels.h:387
@ SDL_PIXELFORMAT_BGRX32
Definition SDL_pixels.h:408
@ SDL_PIXELFORMAT_YV12
Definition SDL_pixels.h:381
@ SDL_PIXELFORMAT_ABGR32
Definition SDL_pixels.h:405
@ SDL_PIXELFORMAT_BGRX8888
Definition SDL_pixels.h:326
@ SDL_PIXELFORMAT_RGB24
Definition SDL_pixels.h:316
@ SDL_PIXELFORMAT_BGRA64
Definition SDL_pixels.h:352
@ SDL_PIXELFORMAT_ABGR8888
Definition SDL_pixels.h:332
@ SDL_PIXELFORMAT_YUY2
Definition SDL_pixels.h:385
@ SDL_PIXELFORMAT_XBGR32
Definition SDL_pixels.h:409
@ SDL_PIXELFORMAT_NV12
Definition SDL_pixels.h:391
@ SDL_PIXELFORMAT_BGRA8888
Definition SDL_pixels.h:334
@ SDL_PIXELFORMAT_ABGR128_FLOAT
Definition SDL_pixels.h:378
@ SDL_PIXELFORMAT_ARGB32
Definition SDL_pixels.h:403
@ SDL_PIXELFORMAT_ABGR1555
Definition SDL_pixels.h:308
@ SDL_PIXELFORMAT_NV21
Definition SDL_pixels.h:393
@ SDL_PIXELFORMAT_IYUV
Definition SDL_pixels.h:383
@ SDL_PIXELFORMAT_ARGB8888
Definition SDL_pixels.h:328
@ SDL_PIXELFORMAT_ABGR64_FLOAT
Definition SDL_pixels.h:366
@ SDL_PIXELFORMAT_ABGR64
Definition SDL_pixels.h:354
@ SDL_PIXELFORMAT_XRGB32
Definition SDL_pixels.h:407
@ SDL_PIXELFORMAT_XBGR1555
Definition SDL_pixels.h:294
@ SDL_PIXELFORMAT_RGB48
Definition SDL_pixels.h:344
@ SDL_PIXELFORMAT_XRGB4444
Definition SDL_pixels.h:288
@ SDL_PIXELFORMAT_BGR96_FLOAT
Definition SDL_pixels.h:370
@ SDL_PIXELFORMAT_ARGB4444
Definition SDL_pixels.h:296
@ SDL_PIXELFORMAT_RGB48_FLOAT
Definition SDL_pixels.h:356
@ SDL_PIXELFORMAT_BGR48
Definition SDL_pixels.h:346
@ SDL_PIXELFORMAT_RGBA32
Definition SDL_pixels.h:402
@ SDL_PIXELFORMAT_BGRA128_FLOAT
Definition SDL_pixels.h:376
@ SDL_PIXELFORMAT_ARGB64_FLOAT
Definition SDL_pixels.h:362
@ SDL_PIXELFORMAT_INDEX1MSB
Definition SDL_pixels.h:274
@ SDL_PIXELFORMAT_INDEX4LSB
Definition SDL_pixels.h:280
@ SDL_PIXELFORMAT_RGBX8888
Definition SDL_pixels.h:322
@ SDL_PIXELFORMAT_BGRA5551
Definition SDL_pixels.h:310
@ SDL_PIXELFORMAT_ARGB128_FLOAT
Definition SDL_pixels.h:374
@ SDL_PIXELFORMAT_XRGB1555
Definition SDL_pixels.h:292
@ SDL_PIXELFORMAT_RGB565
Definition SDL_pixels.h:312
@ SDL_PIXELFORMAT_XBGR8888
Definition SDL_pixels.h:324
@ SDL_PIXELFORMAT_ARGB2101010
Definition SDL_pixels.h:340
@ SDL_PIXELFORMAT_UNKNOWN
Definition SDL_pixels.h:271
@ SDL_PIXELFORMAT_RGBA4444
Definition SDL_pixels.h:298
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b)
const SDL_PixelFormatDetails * SDL_GetPixelFormatDetails(SDL_PixelFormat format)
SDL_PackedOrder
Definition SDL_pixels.h:118
@ SDL_PACKEDORDER_NONE
Definition SDL_pixels.h:119
@ SDL_PACKEDORDER_RGBX
Definition SDL_pixels.h:121
@ SDL_PACKEDORDER_BGRX
Definition SDL_pixels.h:125
@ SDL_PACKEDORDER_XBGR
Definition SDL_pixels.h:124
@ SDL_PACKEDORDER_RGBA
Definition SDL_pixels.h:123
@ SDL_PACKEDORDER_ABGR
Definition SDL_pixels.h:126
@ SDL_PACKEDORDER_BGRA
Definition SDL_pixels.h:127
@ SDL_PACKEDORDER_XRGB
Definition SDL_pixels.h:120
@ SDL_PACKEDORDER_ARGB
Definition SDL_pixels.h:122
bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
uint8_t Uint8
Definition SDL_stdinc.h:337
uint32_t Uint32
Definition SDL_stdinc.h:373
Uint32 version
Definition SDL_pixels.h:732
SDL_Color * colors
Definition SDL_pixels.h:731
SDL_PixelFormat format
Definition SDL_pixels.h:743