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 * \file SDL_pixels.h
24 *
25 * Header for the enumerated pixel format definitions.
26 *
27 * SDL's pixel formats have the following naming convention:
28 *
29 * * Names with a list of components and a single bit count, such as
30 * RGB24 and ABGR32, define a platform-independent encoding into
31 * bytes in the order specified. For example, in RGB24 data, each
32 * pixel is encoded in 3 bytes (red, green, blue) in that order,
33 * and in ABGR32 data, each pixel is encoded in 4 bytes
34 * (alpha, blue, green, red) in that order. Use these names if the
35 * property of a format that is important to you is the order of
36 * the bytes in memory or on disk.
37 *
38 * * Names with a bit count per component, such as ARGB8888 and
39 * XRGB1555, are "packed" into an appropriately-sized integer in
40 * the platform's native endianness. For example, ARGB8888 is
41 * a sequence of 32-bit integers; in each integer, the most
42 * significant bits are alpha, and the least significant bits are
43 * blue. On a little-endian CPU such as x86, the least significant
44 * bits of each integer are arranged first in memory, but on a
45 * big-endian CPU such as s390x, the most significant bits are
46 * arranged first. Use these names if the property of a format that
47 * is important to you is the meaning of each bit position within a
48 * native-endianness integer.
49 *
50 * * In indexed formats such as INDEX4LSB, each pixel is represented
51 * by encoding an index into the palette into the indicated number
52 * of bits, with multiple pixels packed into each byte if appropriate.
53 * In LSB formats, the first (leftmost) pixel is stored in the
54 * least-significant bits of the byte; in MSB formats, it's stored
55 * in the most-significant bits. INDEX8 does not need LSB/MSB
56 * variants, because each pixel exactly fills one byte.
57 *
58 * The 32-bit byte-array encodings such as RGBA32 are aliases for the
59 * appropriate 8888 encoding for the current platform. For example,
60 * RGBA32 is an alias for ABGR8888 on little-endian CPUs like x86,
61 * or an alias for RGBA8888 on big-endian CPUs.
62 */
63
64#ifndef SDL_pixels_h_
65#define SDL_pixels_h_
66
67#include <SDL3/SDL_stdinc.h>
68#include <SDL3/SDL_endian.h>
69
70#include <SDL3/SDL_begin_code.h>
71/* Set up for C function definitions, even when using C++ */
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76/**
77 * \name Transparency definitions
78 *
79 * These define alpha as the opacity of a surface.
80 */
81/* @{ */
82#define SDL_ALPHA_OPAQUE 255
83#define SDL_ALPHA_TRANSPARENT 0
84/* @} */
85
86/** Pixel type. */
104
105/** Bitmap pixel order, high bit -> low bit. */
112
113/** Packed component order, high bit -> low bit. */
126
127/** Array component order, low byte -> high byte. */
138
139/** Packed component layout. */
152
153#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
154
155#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
156 ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
157 ((bits) << 8) | ((bytes) << 0))
158
159#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
160#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
161#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
162#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
163#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
164#define SDL_BYTESPERPIXEL(X) \
165 (SDL_ISPIXELFORMAT_FOURCC(X) ? \
166 ((((X) == SDL_PIXELFORMAT_YUY2) || \
167 ((X) == SDL_PIXELFORMAT_UYVY) || \
168 ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
169
170#define SDL_ISPIXELFORMAT_INDEXED(format) \
171 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
172 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
173 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX2) || \
174 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
175 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
176
177#define SDL_ISPIXELFORMAT_PACKED(format) \
178 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
179 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
180 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
181 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
182
183#define SDL_ISPIXELFORMAT_ARRAY(format) \
184 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
185 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
186 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
187 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
188 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
189 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
190
191#define SDL_ISPIXELFORMAT_ALPHA(format) \
192 ((SDL_ISPIXELFORMAT_PACKED(format) && \
193 ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
194 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
195 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
196 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))))
197
198#define SDL_ISPIXELFORMAT_10BIT(format) \
199 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32) && \
200 (SDL_PIXELLAYOUT(format) == SDL_PACKEDLAYOUT_2101010))
201
202/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
203#define SDL_ISPIXELFORMAT_FOURCC(format) \
204 ((format) && (SDL_PIXELFLAG(format) != 1))
205
206/* Note: If you modify this list, update SDL_GetPixelFormatName() */
207typedef enum
208{
212 1, 0),
215 1, 0),
218 2, 0),
221 2, 0),
224 4, 0),
227 4, 0),
281 24, 3),
284 24, 3),
323 48, 3),
326 48, 3),
329 64, 4),
332 64, 4),
335 64, 4),
338 64, 4),
341 48, 3),
344 48, 3),
347 64, 4),
350 64, 4),
353 64, 4),
356 64, 4),
357
358 /* Aliases for RGBA byte arrays of color data, for the current platform */
359#if SDL_BYTEORDER == SDL_BIG_ENDIAN
368#else
377#endif
378
379 SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
380 SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
381 SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
382 SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
383 SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
384 SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
385 SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
386 SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
387 SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
388 SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
389 SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
390 SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
391 SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
392 SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
393 SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
394 SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
396
397/**
398 * Pixels are a representation of a color in a particular color space.
399 *
400 * 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.
401 *
402 * RGB colors consist of red, green, and blue channels of color that are added together to represent the colors we see on the screen.
403 * https://en.wikipedia.org/wiki/RGB_color_model
404 *
405 * 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.
406 * https://en.wikipedia.org/wiki/YCbCr
407 *
408 * 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.
409 *
410 * 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.
411 *
412 * The color primaries and white point are a definition of the colors in the color space relative to the standard XYZ color space.
413 * https://en.wikipedia.org/wiki/CIE_1931_color_space
414 *
415 * 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.
416 * https://en.wikipedia.org/wiki/Rec._709#Transfer_characteristics
417 *
418 * The matrix coefficients are used to convert between YCbCr and RGB colors.
419 */
420
421/**
422 * The color type
423 */
430
431/**
432 * The color range, as described by https://www.itu.int/rec/R-REC-BT.2100-2-201807-I/en
433 */
434typedef enum
435{
437 SDL_COLOR_RANGE_LIMITED = 1, /**< Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma */
438 SDL_COLOR_RANGE_FULL = 2 /**< Full range, e.g. 0-255 for 8-bit RGB and luma, and 1-255 for 8-bit chroma */
440
441/**
442 * The color primaries, as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
443 */
461
462/**
463 * The transfer characteristics, as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
464 */
465typedef enum
466{
468 SDL_TRANSFER_CHARACTERISTICS_BT709 = 1, /**< ITU-R BT1361 */
470 SDL_TRANSFER_CHARACTERISTICS_GAMMA22 = 4, /**< ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM */
471 SDL_TRANSFER_CHARACTERISTICS_GAMMA28 = 5, /**< ITU-R BT470BG */
472 SDL_TRANSFER_CHARACTERISTICS_BT601 = 6, /**< SMPTE ST 170M */
473 SDL_TRANSFER_CHARACTERISTICS_SMPTE240 = 7, /**< SMPTE ST 240M */
477 SDL_TRANSFER_CHARACTERISTICS_IEC61966 = 11, /**< IEC 61966-2-4 */
478 SDL_TRANSFER_CHARACTERISTICS_BT1361 = 12, /**< ITU-R BT1361 Extended Colour Gamut */
479 SDL_TRANSFER_CHARACTERISTICS_SRGB = 13, /**< IEC 61966-2-1 (sRGB or sYCC) */
480 SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT = 14, /**< ITU-R BT2020 for 10-bit system */
481 SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT = 15, /**< ITU-R BT2020 for 12-bit system */
482 SDL_TRANSFER_CHARACTERISTICS_PQ = 16, /**< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems */
483 SDL_TRANSFER_CHARACTERISTICS_SMPTE428 = 17, /**< SMPTE ST 428-1 */
484 SDL_TRANSFER_CHARACTERISTICS_HLG = 18, /**< ARIB STD-B67, known as "Hybrid log-gamma" */
487
488/**
489 * The matrix coefficients, as described by https://www.itu.int/rec/T-REC-H.273-201612-S/en
490 */
509
510/**
511 * The chroma sample location
512 */
513typedef enum
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 2×2 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 2×2 the 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
534typedef enum
535{
537 SDL_COLORSPACE_SRGB = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 */
544 SDL_COLORSPACE_SCRGB = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 */
551 SDL_COLORSPACE_HDR10 = /**< Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 */
558 SDL_COLORSPACE_BT601_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
565 SDL_COLORSPACE_BT601_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 */
572 SDL_COLORSPACE_BT709_LIMITED = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
579 SDL_COLORSPACE_BT709_FULL = /**< Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 */
586
587 /* The default colorspace for RGB surfaces if no colorspace is specified */
590
591/**
592 * The bits of this structure can be directly reinterpreted as an integer-packed
593 * color which uses the SDL_PIXELFORMAT_RGBA32 format (SDL_PIXELFORMAT_ABGR8888
594 * on little-endian systems and SDL_PIXELFORMAT_RGBA8888 on big-endian systems).
595 */
603#define SDL_Colour SDL_Color
604
612
613/**
614 * \note Everything in the pixel format structure is read-only.
615 */
638
639/**
640 * Get the human readable name of a pixel format.
641 *
642 * \param format the pixel format to query
643 * \returns the human readable name of the specified pixel format or
644 * `SDL_PIXELFORMAT_UNKNOWN` if the format isn't recognized.
645 *
646 * \since This function is available since SDL 3.0.0.
647 */
648extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
649
650/**
651 * Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
652 *
653 * \param format one of the SDL_PixelFormatEnum values
654 * \param bpp a bits per pixel value; usually 15, 16, or 32
655 * \param Rmask a pointer filled in with the red mask for the format
656 * \param Gmask a pointer filled in with the green mask for the format
657 * \param Bmask a pointer filled in with the blue mask for the format
658 * \param Amask a pointer filled in with the alpha mask for the format
659 * \returns SDL_TRUE on success or SDL_FALSE if the conversion wasn't
660 * possible; call SDL_GetError() for more information.
661 *
662 * \since This function is available since SDL 3.0.0.
663 *
664 * \sa SDL_GetPixelFormatEnumForMasks
665 */
667 int *bpp,
668 Uint32 * Rmask,
669 Uint32 * Gmask,
670 Uint32 * Bmask,
671 Uint32 * Amask);
672
673/**
674 * Convert a bpp value and RGBA masks to an enumerated pixel format.
675 *
676 * This will return `SDL_PIXELFORMAT_UNKNOWN` if the conversion wasn't
677 * possible.
678 *
679 * \param bpp a bits per pixel value; usually 15, 16, or 32
680 * \param Rmask the red mask for the format
681 * \param Gmask the green mask for the format
682 * \param Bmask the blue mask for the format
683 * \param Amask the alpha mask for the format
684 * \returns one of the SDL_PixelFormatEnum values
685 *
686 * \since This function is available since SDL 3.0.0.
687 *
688 * \sa SDL_GetMasksForPixelFormatEnum
689 */
690extern DECLSPEC Uint32 SDLCALL SDL_GetPixelFormatEnumForMasks(int bpp,
694 Uint32 Amask);
695
696/**
697 * Create an SDL_PixelFormat structure corresponding to a pixel format.
698 *
699 * Returned structure may come from a shared global cache (i.e. not newly
700 * allocated), and hence should not be modified, especially the palette. Weird
701 * errors such as `Blit combination not supported` may occur.
702 *
703 * \param pixel_format one of the SDL_PixelFormatEnum values
704 * \returns the new SDL_PixelFormat structure or NULL on failure; call
705 * SDL_GetError() for more information.
706 *
707 * \since This function is available since SDL 3.0.0.
708 *
709 * \sa SDL_DestroyPixelFormat
710 */
711extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_CreatePixelFormat(Uint32 pixel_format);
712
713/**
714 * Free an SDL_PixelFormat structure allocated by SDL_CreatePixelFormat().
715 *
716 * \param format the SDL_PixelFormat structure to free
717 *
718 * \since This function is available since SDL 3.0.0.
719 *
720 * \sa SDL_CreatePixelFormat
721 */
722extern DECLSPEC void SDLCALL SDL_DestroyPixelFormat(SDL_PixelFormat *format);
723
724/**
725 * Create a palette structure with the specified number of color entries.
726 *
727 * The palette entries are initialized to white.
728 *
729 * \param ncolors represents the number of color entries in the color palette
730 * \returns a new SDL_Palette structure on success or NULL on failure (e.g. if
731 * there wasn't enough memory); call SDL_GetError() for more
732 * information.
733 *
734 * \since This function is available since SDL 3.0.0.
735 *
736 * \sa SDL_DestroyPalette
737 */
738extern DECLSPEC SDL_Palette *SDLCALL SDL_CreatePalette(int ncolors);
739
740/**
741 * Set the palette for a pixel format structure.
742 *
743 * \param format the SDL_PixelFormat structure that will use the palette
744 * \param palette the SDL_Palette structure that will be used
745 * \returns 0 on success or a negative error code on failure; call
746 * SDL_GetError() for more information.
747 *
748 * \since This function is available since SDL 3.0.0.
749 *
750 * \sa SDL_CreatePalette
751 * \sa SDL_DestroyPalette
752 */
755
756/**
757 * Set a range of colors in a palette.
758 *
759 * \param palette the SDL_Palette structure to modify
760 * \param colors an array of SDL_Color structures to copy into the palette
761 * \param firstcolor the index of the first palette entry to modify
762 * \param ncolors the number of entries to modify
763 * \returns 0 on success or a negative error code on failure; call
764 * SDL_GetError() for more information.
765 *
766 * \since This function is available since SDL 3.0.0.
767 *
768 * \sa SDL_CreatePalette
769 * \sa SDL_CreateSurface
770 */
771extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
772 const SDL_Color * colors,
773 int firstcolor, int ncolors);
774
775/**
776 * Free a palette created with SDL_CreatePalette().
777 *
778 * \param palette the SDL_Palette structure to be freed
779 *
780 * \since This function is available since SDL 3.0.0.
781 *
782 * \sa SDL_CreatePalette
783 */
784extern DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
785
786/**
787 * Map an RGB triple to an opaque pixel value for a given pixel format.
788 *
789 * This function maps the RGB color value to the specified pixel format and
790 * returns the pixel value best approximating the given RGB color value for
791 * the given pixel format.
792 *
793 * If the format has a palette (8-bit) the index of the closest matching color
794 * in the palette will be returned.
795 *
796 * If the specified pixel format has an alpha component it will be returned as
797 * all 1 bits (fully opaque).
798 *
799 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
800 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
801 * format the return value can be assigned to a Uint16, and similarly a Uint8
802 * for an 8-bpp format).
803 *
804 * \param format an SDL_PixelFormat structure describing the pixel format
805 * \param r the red component of the pixel in the range 0-255
806 * \param g the green component of the pixel in the range 0-255
807 * \param b the blue component of the pixel in the range 0-255
808 * \returns a pixel value
809 *
810 * \since This function is available since SDL 3.0.0.
811 *
812 * \sa SDL_GetRGB
813 * \sa SDL_GetRGBA
814 * \sa SDL_MapRGBA
815 */
816extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
817 Uint8 r, Uint8 g, Uint8 b);
818
819/**
820 * Map an RGBA quadruple to a pixel value for a given pixel format.
821 *
822 * This function maps the RGBA color value to the specified pixel format and
823 * returns the pixel value best approximating the given RGBA color value for
824 * the given pixel format.
825 *
826 * If the specified pixel format has no alpha component the alpha value will
827 * be ignored (as it will be in formats with a palette).
828 *
829 * If the format has a palette (8-bit) the index of the closest matching color
830 * in the palette will be returned.
831 *
832 * If the pixel format bpp (color depth) is less than 32-bpp then the unused
833 * upper bits of the return value can safely be ignored (e.g., with a 16-bpp
834 * format the return value can be assigned to a Uint16, and similarly a Uint8
835 * for an 8-bpp format).
836 *
837 * \param format an SDL_PixelFormat structure describing the format of the
838 * pixel
839 * \param r the red component of the pixel in the range 0-255
840 * \param g the green component of the pixel in the range 0-255
841 * \param b the blue component of the pixel in the range 0-255
842 * \param a the alpha component of the pixel in the range 0-255
843 * \returns a pixel value
844 *
845 * \since This function is available since SDL 3.0.0.
846 *
847 * \sa SDL_GetRGB
848 * \sa SDL_GetRGBA
849 * \sa SDL_MapRGB
850 */
851extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
852 Uint8 r, Uint8 g, Uint8 b,
853 Uint8 a);
854
855/**
856 * Get RGB values from a pixel in the specified format.
857 *
858 * This function uses the entire 8-bit [0..255] range when converting color
859 * components from pixel formats with less than 8-bits per RGB component
860 * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
861 * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
862 *
863 * \param pixel a pixel value
864 * \param format an SDL_PixelFormat structure describing the format of the
865 * pixel
866 * \param r a pointer filled in with the red component
867 * \param g a pointer filled in with the green component
868 * \param b a pointer filled in with the blue component
869 *
870 * \since This function is available since SDL 3.0.0.
871 *
872 * \sa SDL_GetRGBA
873 * \sa SDL_MapRGB
874 * \sa SDL_MapRGBA
875 */
876extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
877 const SDL_PixelFormat * format,
878 Uint8 * r, Uint8 * g, Uint8 * b);
879
880/**
881 * Get RGBA values from a pixel in the specified format.
882 *
883 * This function uses the entire 8-bit [0..255] range when converting color
884 * components from pixel formats with less than 8-bits per RGB component
885 * (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
886 * 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
887 *
888 * If the surface has no alpha component, the alpha will be returned as 0xff
889 * (100% opaque).
890 *
891 * \param pixel a pixel value
892 * \param format an SDL_PixelFormat structure describing the format of the
893 * pixel
894 * \param r a pointer filled in with the red component
895 * \param g a pointer filled in with the green component
896 * \param b a pointer filled in with the blue component
897 * \param a a pointer filled in with the alpha component
898 *
899 * \since This function is available since SDL 3.0.0.
900 *
901 * \sa SDL_GetRGB
902 * \sa SDL_MapRGB
903 * \sa SDL_MapRGBA
904 */
905extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
906 const SDL_PixelFormat * format,
907 Uint8 * r, Uint8 * g, Uint8 * b,
908 Uint8 * a);
909
910
911/* Ends C function definitions when using C++ */
912#ifdef __cplusplus
913}
914#endif
915#include <SDL3/SDL_close_code.h>
916
917#endif /* SDL_pixels_h_ */
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
SDL_bool SDL_GetMasksForPixelFormatEnum(Uint32 format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
SDL_MatrixCoefficients
Definition SDL_pixels.h:492
@ SDL_MATRIX_COEFFICIENTS_BT709
Definition SDL_pixels.h:494
@ SDL_MATRIX_COEFFICIENTS_BT2020_CL
Definition SDL_pixels.h:502
@ SDL_MATRIX_COEFFICIENTS_BT601
Definition SDL_pixels.h:498
@ SDL_MATRIX_COEFFICIENTS_BT2020_NCL
Definition SDL_pixels.h:501
@ SDL_MATRIX_COEFFICIENTS_SMPTE240
Definition SDL_pixels.h:499
@ SDL_MATRIX_COEFFICIENTS_YCGCO
Definition SDL_pixels.h:500
@ SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL
Definition SDL_pixels.h:504
@ SDL_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL
Definition SDL_pixels.h:505
@ SDL_MATRIX_COEFFICIENTS_UNSPECIFIED
Definition SDL_pixels.h:495
@ SDL_MATRIX_COEFFICIENTS_CUSTOM
Definition SDL_pixels.h:507
@ SDL_MATRIX_COEFFICIENTS_ICTCP
Definition SDL_pixels.h:506
@ SDL_MATRIX_COEFFICIENTS_IDENTITY
Definition SDL_pixels.h:493
@ SDL_MATRIX_COEFFICIENTS_FCC
Definition SDL_pixels.h:496
@ SDL_MATRIX_COEFFICIENTS_BT470BG
Definition SDL_pixels.h:497
@ SDL_MATRIX_COEFFICIENTS_SMPTE2085
Definition SDL_pixels.h:503
SDL_PixelType
Definition SDL_pixels.h:88
@ SDL_PIXELTYPE_UNKNOWN
Definition SDL_pixels.h:89
@ SDL_PIXELTYPE_ARRAYU16
Definition SDL_pixels.h:97
@ SDL_PIXELTYPE_PACKED32
Definition SDL_pixels.h:95
@ SDL_PIXELTYPE_INDEX2
Definition SDL_pixels.h:102
@ SDL_PIXELTYPE_ARRAYU8
Definition SDL_pixels.h:96
@ SDL_PIXELTYPE_INDEX4
Definition SDL_pixels.h:91
@ SDL_PIXELTYPE_PACKED8
Definition SDL_pixels.h:93
@ SDL_PIXELTYPE_ARRAYF16
Definition SDL_pixels.h:99
@ SDL_PIXELTYPE_ARRAYU32
Definition SDL_pixels.h:98
@ SDL_PIXELTYPE_INDEX1
Definition SDL_pixels.h:90
@ SDL_PIXELTYPE_ARRAYF32
Definition SDL_pixels.h:100
@ SDL_PIXELTYPE_INDEX8
Definition SDL_pixels.h:92
@ SDL_PIXELTYPE_PACKED16
Definition SDL_pixels.h:94
const char * SDL_GetPixelFormatName(Uint32 format)
SDL_ColorRange
Definition SDL_pixels.h:435
@ SDL_COLOR_RANGE_LIMITED
Definition SDL_pixels.h:437
@ SDL_COLOR_RANGE_FULL
Definition SDL_pixels.h:438
@ SDL_COLOR_RANGE_UNKNOWN
Definition SDL_pixels.h:436
void SDL_DestroyPixelFormat(SDL_PixelFormat *format)
Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
SDL_ColorPrimaries
Definition SDL_pixels.h:445
@ SDL_COLOR_PRIMARIES_SMPTE431
Definition SDL_pixels.h:456
@ SDL_COLOR_PRIMARIES_CUSTOM
Definition SDL_pixels.h:459
@ SDL_COLOR_PRIMARIES_EBU3213
Definition SDL_pixels.h:458
@ SDL_COLOR_PRIMARIES_GENERIC_FILM
Definition SDL_pixels.h:453
@ SDL_COLOR_PRIMARIES_BT601
Definition SDL_pixels.h:451
@ SDL_COLOR_PRIMARIES_UNSPECIFIED
Definition SDL_pixels.h:448
@ SDL_COLOR_PRIMARIES_SMPTE240
Definition SDL_pixels.h:452
@ SDL_COLOR_PRIMARIES_XYZ
Definition SDL_pixels.h:455
@ SDL_COLOR_PRIMARIES_UNKNOWN
Definition SDL_pixels.h:446
@ SDL_COLOR_PRIMARIES_SMPTE432
Definition SDL_pixels.h:457
@ SDL_COLOR_PRIMARIES_BT2020
Definition SDL_pixels.h:454
@ SDL_COLOR_PRIMARIES_BT470BG
Definition SDL_pixels.h:450
@ SDL_COLOR_PRIMARIES_BT709
Definition SDL_pixels.h:447
@ SDL_COLOR_PRIMARIES_BT470M
Definition SDL_pixels.h:449
SDL_PackedLayout
Definition SDL_pixels.h:141
@ SDL_PACKEDLAYOUT_NONE
Definition SDL_pixels.h:142
@ SDL_PACKEDLAYOUT_8888
Definition SDL_pixels.h:148
@ SDL_PACKEDLAYOUT_1010102
Definition SDL_pixels.h:150
@ SDL_PACKEDLAYOUT_565
Definition SDL_pixels.h:147
@ SDL_PACKEDLAYOUT_332
Definition SDL_pixels.h:143
@ SDL_PACKEDLAYOUT_5551
Definition SDL_pixels.h:146
@ SDL_PACKEDLAYOUT_1555
Definition SDL_pixels.h:145
@ SDL_PACKEDLAYOUT_4444
Definition SDL_pixels.h:144
@ SDL_PACKEDLAYOUT_2101010
Definition SDL_pixels.h:149
SDL_Palette * SDL_CreatePalette(int ncolors)
SDL_BitmapOrder
Definition SDL_pixels.h:107
@ SDL_BITMAPORDER_1234
Definition SDL_pixels.h:110
@ SDL_BITMAPORDER_NONE
Definition SDL_pixels.h:108
@ SDL_BITMAPORDER_4321
Definition SDL_pixels.h:109
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_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
#define SDL_DEFINE_COLORSPACE(type, range, primaries, transfer, matrix, chroma)
Definition SDL_pixels.h:523
void SDL_DestroyPalette(SDL_Palette *palette)
SDL_ColorType
Definition SDL_pixels.h:425
@ SDL_COLOR_TYPE_RGB
Definition SDL_pixels.h:427
@ SDL_COLOR_TYPE_YCBCR
Definition SDL_pixels.h:428
@ SDL_COLOR_TYPE_UNKNOWN
Definition SDL_pixels.h:426
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D)
Definition SDL_pixels.h:153
SDL_TransferCharacteristics
Definition SDL_pixels.h:466
@ SDL_TRANSFER_CHARACTERISTICS_BT709
Definition SDL_pixels.h:468
@ SDL_TRANSFER_CHARACTERISTICS_BT1361
Definition SDL_pixels.h:478
@ SDL_TRANSFER_CHARACTERISTICS_HLG
Definition SDL_pixels.h:484
@ SDL_TRANSFER_CHARACTERISTICS_LOG100_SQRT10
Definition SDL_pixels.h:476
@ SDL_TRANSFER_CHARACTERISTICS_UNKNOWN
Definition SDL_pixels.h:467
@ SDL_TRANSFER_CHARACTERISTICS_BT601
Definition SDL_pixels.h:472
@ SDL_TRANSFER_CHARACTERISTICS_IEC61966
Definition SDL_pixels.h:477
@ SDL_TRANSFER_CHARACTERISTICS_UNSPECIFIED
Definition SDL_pixels.h:469
@ SDL_TRANSFER_CHARACTERISTICS_SMPTE428
Definition SDL_pixels.h:483
@ SDL_TRANSFER_CHARACTERISTICS_LOG100
Definition SDL_pixels.h:475
@ SDL_TRANSFER_CHARACTERISTICS_GAMMA28
Definition SDL_pixels.h:471
@ SDL_TRANSFER_COEFFICIENTS_CUSTOM
Definition SDL_pixels.h:485
@ SDL_TRANSFER_CHARACTERISTICS_SMPTE240
Definition SDL_pixels.h:473
@ SDL_TRANSFER_CHARACTERISTICS_BT2020_10BIT
Definition SDL_pixels.h:480
@ SDL_TRANSFER_CHARACTERISTICS_SRGB
Definition SDL_pixels.h:479
@ SDL_TRANSFER_CHARACTERISTICS_PQ
Definition SDL_pixels.h:482
@ SDL_TRANSFER_CHARACTERISTICS_LINEAR
Definition SDL_pixels.h:474
@ SDL_TRANSFER_CHARACTERISTICS_BT2020_12BIT
Definition SDL_pixels.h:481
@ SDL_TRANSFER_CHARACTERISTICS_GAMMA22
Definition SDL_pixels.h:470
SDL_ArrayOrder
Definition SDL_pixels.h:129
@ SDL_ARRAYORDER_RGB
Definition SDL_pixels.h:131
@ SDL_ARRAYORDER_NONE
Definition SDL_pixels.h:130
@ SDL_ARRAYORDER_ARGB
Definition SDL_pixels.h:133
@ SDL_ARRAYORDER_BGRA
Definition SDL_pixels.h:135
@ SDL_ARRAYORDER_ABGR
Definition SDL_pixels.h:136
@ SDL_ARRAYORDER_RGBA
Definition SDL_pixels.h:132
@ SDL_ARRAYORDER_BGR
Definition SDL_pixels.h:134
SDL_PixelFormat * SDL_CreatePixelFormat(Uint32 pixel_format)
SDL_PixelFormatEnum
Definition SDL_pixels.h:208
@ SDL_PIXELFORMAT_BGR48_FLOAT
Definition SDL_pixels.h:342
@ SDL_PIXELFORMAT_BGR565
Definition SDL_pixels.h:276
@ SDL_PIXELFORMAT_EXTERNAL_OES
Definition SDL_pixels.h:393
@ SDL_PIXELFORMAT_ARGB64
Definition SDL_pixels.h:330
@ SDL_PIXELFORMAT_YVYU
Definition SDL_pixels.h:387
@ SDL_PIXELFORMAT_RGB332
Definition SDL_pixels.h:230
@ SDL_PIXELFORMAT_INDEX2LSB
Definition SDL_pixels.h:216
@ SDL_PIXELFORMAT_INDEX1LSB
Definition SDL_pixels.h:210
@ SDL_PIXELFORMAT_BGR444
Definition SDL_pixels.h:240
@ SDL_PIXELFORMAT_RGBX32
Definition SDL_pixels.h:364
@ SDL_PIXELFORMAT_ABGR4444
Definition SDL_pixels.h:255
@ SDL_PIXELFORMAT_BGRA4444
Definition SDL_pixels.h:258
@ SDL_PIXELFORMAT_BGR24
Definition SDL_pixels.h:282
@ SDL_PIXELFORMAT_INDEX4MSB
Definition SDL_pixels.h:225
@ SDL_PIXELFORMAT_ABGR2101010
Definition SDL_pixels.h:318
@ SDL_PIXELFORMAT_BGRA32
Definition SDL_pixels.h:362
@ SDL_PIXELFORMAT_RGB555
Definition SDL_pixels.h:244
@ SDL_PIXELFORMAT_RGB444
Definition SDL_pixels.h:236
@ SDL_PIXELFORMAT_XBGR2101010
Definition SDL_pixels.h:312
@ SDL_PIXELFORMAT_RGBA64_FLOAT
Definition SDL_pixels.h:345
@ SDL_PIXELFORMAT_INDEX2MSB
Definition SDL_pixels.h:219
@ SDL_PIXELFORMAT_BGRA64_FLOAT
Definition SDL_pixels.h:351
@ SDL_PIXELFORMAT_RGBA8888
Definition SDL_pixels.h:300
@ SDL_PIXELFORMAT_RGBA5551
Definition SDL_pixels.h:264
@ SDL_PIXELFORMAT_ARGB1555
Definition SDL_pixels.h:261
@ SDL_PIXELFORMAT_XBGR4444
Definition SDL_pixels.h:237
@ SDL_PIXELFORMAT_RGBA64
Definition SDL_pixels.h:327
@ SDL_PIXELFORMAT_INDEX8
Definition SDL_pixels.h:228
@ SDL_PIXELFORMAT_XRGB2101010
Definition SDL_pixels.h:309
@ SDL_PIXELFORMAT_XRGB8888
Definition SDL_pixels.h:285
@ SDL_PIXELFORMAT_UYVY
Definition SDL_pixels.h:385
@ SDL_PIXELFORMAT_BGRX32
Definition SDL_pixels.h:366
@ SDL_PIXELFORMAT_YV12
Definition SDL_pixels.h:379
@ SDL_PIXELFORMAT_ABGR32
Definition SDL_pixels.h:363
@ SDL_PIXELFORMAT_BGRX8888
Definition SDL_pixels.h:294
@ SDL_PIXELFORMAT_RGB24
Definition SDL_pixels.h:279
@ SDL_PIXELFORMAT_BGRA64
Definition SDL_pixels.h:333
@ SDL_PIXELFORMAT_ABGR8888
Definition SDL_pixels.h:303
@ SDL_PIXELFORMAT_YUY2
Definition SDL_pixels.h:383
@ SDL_PIXELFORMAT_XBGR32
Definition SDL_pixels.h:367
@ SDL_PIXELFORMAT_NV12
Definition SDL_pixels.h:389
@ SDL_PIXELFORMAT_BGRA8888
Definition SDL_pixels.h:306
@ SDL_PIXELFORMAT_ARGB32
Definition SDL_pixels.h:361
@ SDL_PIXELFORMAT_ABGR1555
Definition SDL_pixels.h:267
@ SDL_PIXELFORMAT_NV21
Definition SDL_pixels.h:391
@ SDL_PIXELFORMAT_IYUV
Definition SDL_pixels.h:381
@ SDL_PIXELFORMAT_ARGB8888
Definition SDL_pixels.h:297
@ SDL_PIXELFORMAT_ABGR64_FLOAT
Definition SDL_pixels.h:354
@ SDL_PIXELFORMAT_ABGR64
Definition SDL_pixels.h:336
@ SDL_PIXELFORMAT_XRGB32
Definition SDL_pixels.h:365
@ SDL_PIXELFORMAT_XBGR1555
Definition SDL_pixels.h:245
@ SDL_PIXELFORMAT_RGB48
Definition SDL_pixels.h:321
@ SDL_PIXELFORMAT_XRGB4444
Definition SDL_pixels.h:233
@ SDL_PIXELFORMAT_ARGB4444
Definition SDL_pixels.h:249
@ SDL_PIXELFORMAT_RGB48_FLOAT
Definition SDL_pixels.h:339
@ SDL_PIXELFORMAT_BGR48
Definition SDL_pixels.h:324
@ SDL_PIXELFORMAT_RGBA32
Definition SDL_pixels.h:360
@ SDL_PIXELFORMAT_ARGB64_FLOAT
Definition SDL_pixels.h:348
@ SDL_PIXELFORMAT_INDEX1MSB
Definition SDL_pixels.h:213
@ SDL_PIXELFORMAT_INDEX4LSB
Definition SDL_pixels.h:222
@ SDL_PIXELFORMAT_RGBX8888
Definition SDL_pixels.h:288
@ SDL_PIXELFORMAT_BGRA5551
Definition SDL_pixels.h:270
@ SDL_PIXELFORMAT_XRGB1555
Definition SDL_pixels.h:241
@ SDL_PIXELFORMAT_RGB565
Definition SDL_pixels.h:273
@ SDL_PIXELFORMAT_XBGR8888
Definition SDL_pixels.h:291
@ SDL_PIXELFORMAT_ARGB2101010
Definition SDL_pixels.h:315
@ SDL_PIXELFORMAT_BGR555
Definition SDL_pixels.h:248
@ SDL_PIXELFORMAT_UNKNOWN
Definition SDL_pixels.h:209
@ SDL_PIXELFORMAT_RGBA4444
Definition SDL_pixels.h:252
SDL_Colorspace
Definition SDL_pixels.h:535
@ SDL_COLORSPACE_SCRGB
Definition SDL_pixels.h:544
@ SDL_COLORSPACE_BT601_LIMITED
Definition SDL_pixels.h:558
@ SDL_COLORSPACE_BT709_FULL
Definition SDL_pixels.h:579
@ SDL_COLORSPACE_HDR10
Definition SDL_pixels.h:551
@ SDL_COLORSPACE_BT601_FULL
Definition SDL_pixels.h:565
@ SDL_COLORSPACE_UNKNOWN
Definition SDL_pixels.h:536
@ SDL_COLORSPACE_BT709_LIMITED
Definition SDL_pixels.h:572
@ SDL_COLORSPACE_SRGB
Definition SDL_pixels.h:537
@ SDL_COLORSPACE_RGB_DEFAULT
Definition SDL_pixels.h:588
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes)
Definition SDL_pixels.h:155
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
SDL_PackedOrder
Definition SDL_pixels.h:115
@ SDL_PACKEDORDER_NONE
Definition SDL_pixels.h:116
@ SDL_PACKEDORDER_RGBX
Definition SDL_pixels.h:118
@ SDL_PACKEDORDER_BGRX
Definition SDL_pixels.h:122
@ SDL_PACKEDORDER_XBGR
Definition SDL_pixels.h:121
@ SDL_PACKEDORDER_RGBA
Definition SDL_pixels.h:120
@ SDL_PACKEDORDER_ABGR
Definition SDL_pixels.h:123
@ SDL_PACKEDORDER_BGRA
Definition SDL_pixels.h:124
@ SDL_PACKEDORDER_XRGB
Definition SDL_pixels.h:117
@ SDL_PACKEDORDER_ARGB
Definition SDL_pixels.h:119
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b)
Uint32 SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
uint8_t Uint8
Definition SDL_stdinc.h:150
int SDL_bool
Definition SDL_stdinc.h:137
uint32_t Uint32
Definition SDL_stdinc.h:174
Uint32 version
Definition SDL_pixels.h:609
SDL_Color * colors
Definition SDL_pixels.h:608
struct SDL_PixelFormat * next
Definition SDL_pixels.h:636
Uint8 padding[2]
Definition SDL_pixels.h:622
SDL_Palette * palette
Definition SDL_pixels.h:619