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