arsa  2.7
SDL_pixels.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2019 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 
28 #ifndef SDL_pixels_h_
29 #define SDL_pixels_h_
30 
31 #include "SDL_stdinc.h"
32 #include "SDL_endian.h"
33 
34 #include "begin_code.h"
35 /* Set up for C function definitions, even when using C++ */
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
45 /* @{ */
46 #define SDL_ALPHA_OPAQUE 255
47 #define SDL_ALPHA_TRANSPARENT 0
48 /* @} */
49 
51 typedef enum
52 {
66 
68 typedef enum
69 {
74 
76 typedef enum
77 {
88 
90 /* !!! FIXME: in 2.1, make these not overlap differently with
91  !!! FIXME: SDL_PACKEDORDER_*, so we can simplify SDL_ISPIXELFORMAT_ALPHA */
92 typedef enum
93 {
102 
104 typedef enum
105 {
116 
117 #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
118 
119 #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
120  ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
121  ((bits) << 8) | ((bytes) << 0))
122 
123 #define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
124 #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
125 #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
126 #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
127 #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
128 #define SDL_BYTESPERPIXEL(X) \
129  (SDL_ISPIXELFORMAT_FOURCC(X) ? \
130  ((((X) == SDL_PIXELFORMAT_YUY2) || \
131  ((X) == SDL_PIXELFORMAT_UYVY) || \
132  ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
133 
134 #define SDL_ISPIXELFORMAT_INDEXED(format) \
135  (!SDL_ISPIXELFORMAT_FOURCC(format) && \
136  ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
137  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
138  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
139 
140 #define SDL_ISPIXELFORMAT_PACKED(format) \
141  (!SDL_ISPIXELFORMAT_FOURCC(format) && \
142  ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
143  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
144  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
145 
146 #define SDL_ISPIXELFORMAT_ARRAY(format) \
147  (!SDL_ISPIXELFORMAT_FOURCC(format) && \
148  ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
149  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
150  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
151  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
152  (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
153 
154 #define SDL_ISPIXELFORMAT_ALPHA(format) \
155  ((SDL_ISPIXELFORMAT_PACKED(format) && \
156  ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
157  (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
158  (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
159  (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
160  (SDL_ISPIXELFORMAT_ARRAY(format) && \
161  ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
162  (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
163  (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
164  (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
165 
166 /* The flag is set to 1 because 0x1? is not in the printable ASCII range */
167 #define SDL_ISPIXELFORMAT_FOURCC(format) \
168  ((format) && (SDL_PIXELFLAG(format) != 1))
169 
170 /* Note: If you modify this list, update SDL_GetPixelFormatName() */
171 typedef enum
172 {
176  1, 0),
179  1, 0),
182  4, 0),
185  4, 0),
190  SDL_PACKEDLAYOUT_332, 8, 1),
193  SDL_PACKEDLAYOUT_4444, 12, 2),
196  SDL_PACKEDLAYOUT_1555, 15, 2),
199  SDL_PACKEDLAYOUT_1555, 15, 2),
202  SDL_PACKEDLAYOUT_4444, 16, 2),
205  SDL_PACKEDLAYOUT_4444, 16, 2),
208  SDL_PACKEDLAYOUT_4444, 16, 2),
211  SDL_PACKEDLAYOUT_4444, 16, 2),
214  SDL_PACKEDLAYOUT_1555, 16, 2),
217  SDL_PACKEDLAYOUT_5551, 16, 2),
220  SDL_PACKEDLAYOUT_1555, 16, 2),
223  SDL_PACKEDLAYOUT_5551, 16, 2),
226  SDL_PACKEDLAYOUT_565, 16, 2),
229  SDL_PACKEDLAYOUT_565, 16, 2),
232  24, 3),
235  24, 3),
238  SDL_PACKEDLAYOUT_8888, 24, 4),
241  SDL_PACKEDLAYOUT_8888, 24, 4),
244  SDL_PACKEDLAYOUT_8888, 24, 4),
247  SDL_PACKEDLAYOUT_8888, 24, 4),
250  SDL_PACKEDLAYOUT_8888, 32, 4),
253  SDL_PACKEDLAYOUT_8888, 32, 4),
256  SDL_PACKEDLAYOUT_8888, 32, 4),
259  SDL_PACKEDLAYOUT_8888, 32, 4),
262  SDL_PACKEDLAYOUT_2101010, 32, 4),
263 
264  /* Aliases for RGBA byte arrays of color data, for the current platform */
265 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
270 #else
275 #endif
276 
278  SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
280  SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
282  SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
284  SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
286  SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
288  SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
290  SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
292  SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
294 
295 typedef struct SDL_Color
296 {
301 } SDL_Color;
302 #define SDL_Colour SDL_Color
303 
304 typedef struct SDL_Palette
305 {
306  int ncolors;
309  int refcount;
310 } SDL_Palette;
311 
315 typedef struct SDL_PixelFormat
316 {
334  int refcount;
337 
342 
351  int *bpp,
352  Uint32 * Rmask,
353  Uint32 * Gmask,
354  Uint32 * Bmask,
355  Uint32 * Amask);
356 
366  Uint32 Rmask,
367  Uint32 Gmask,
368  Uint32 Bmask,
369  Uint32 Amask);
370 
374 extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
375 
380 
391 extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
392 
398 
410  const SDL_Color * colors,
411  int firstcolor, int ncolors);
412 
419 
426  Uint8 r, Uint8 g, Uint8 b);
427 
434  Uint8 r, Uint8 g, Uint8 b,
435  Uint8 a);
436 
442 extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
443  const SDL_PixelFormat * format,
444  Uint8 * r, Uint8 * g, Uint8 * b);
445 
451 extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
452  const SDL_PixelFormat * format,
453  Uint8 * r, Uint8 * g, Uint8 * b,
454  Uint8 * a);
455 
459 extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
460 
461 
462 /* Ends C function definitions when using C++ */
463 #ifdef __cplusplus
464 }
465 #endif
466 #include "close_code.h"
467 
468 #endif /* SDL_pixels_h_ */
469 
470 /* vi: set ts=4 sw=4 expandtab: */
Uint32 version
Definition: SDL_pixels.h:308
DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format)
Free an SDL_PixelFormat structure.
SDL_PixelFormatEnum
Definition: SDL_pixels.h:171
Uint8 g
Definition: SDL_pixels.h:298
DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
Set the palette for a pixel format structure.
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_bool
Definition: SDL_stdinc.h:161
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
Uint8 padding[2]
Definition: SDL_pixels.h:321
DECLSPEC const char *SDLCALL SDL_GetPixelFormatName(Uint32 format)
Get the human readable name of a pixel format.
SDL_PixelType
Definition: SDL_pixels.h:51
DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette *palette)
Free a palette created with SDL_AllocPalette().
SDL_PackedLayout
Definition: SDL_pixels.h:104
DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Convert a bpp and RGBA masks to an enumerated pixel format.
#define DECLSPEC
Definition: begin_code.h:74
Uint8 b
Definition: SDL_pixels.h:299
uint32_t Uint32
Definition: SDL_stdinc.h:203
struct SDL_Palette SDL_Palette
#define SDLCALL
Definition: begin_code.h:89
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D)
Definition: SDL_pixels.h:117
DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Maps an RGBA quadruple to a pixel value for a given pixel format.
struct SDL_Color SDL_Color
SDL_AudioFormat format
Definition: SDL_audio.h:194
uint16_t Uint16
Definition: SDL_stdinc.h:191
DECLSPEC SDL_PixelFormat *SDLCALL SDL_AllocFormat(Uint32 pixel_format)
Create an SDL_PixelFormat structure from a pixel format enum.
Uint8 r
Definition: SDL_pixels.h:297
SDL_ArrayOrder
Definition: SDL_pixels.h:92
Uint8 a
Definition: SDL_pixels.h:300
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
SDL_Color * colors
Definition: SDL_pixels.h:307
DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 *ramp)
Calculate a 256 entry gamma ramp for a gamma value.
DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
Get the RGBA components from a pixel of the specified format.
GLboolean GLboolean GLboolean b
SDL_BitmapOrder
Definition: SDL_pixels.h:68
DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors)
Create a palette structure with the specified number of color entries.
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes)
Definition: SDL_pixels.h:119
DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
Convert one of the enumerated pixel formats to a bpp and RGBA masks.
DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
Maps an RGB triple to an opaque pixel value for a given pixel format.
DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b)
Get the RGB components from a pixel of the specified format.
SDL_PackedOrder
Definition: SDL_pixels.h:76
GLboolean GLboolean GLboolean GLboolean a
SDL_Palette * palette
Definition: SDL_pixels.h:318
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLboolean GLboolean g
struct SDL_PixelFormat * next
Definition: SDL_pixels.h:335
struct SDL_PixelFormat SDL_PixelFormat
DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
Set a range of colors in a palette.