2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
25 * Header for the enumerated pixel format definitions.
31 #include "begin_code.h"
32 /* Set up for C function definitions, even when using C++ */
38 * \name Transparency definitions
40 * These define alpha as the opacity of a surface.
43 #define SDL_ALPHA_OPAQUE 255
44 #define SDL_ALPHA_TRANSPARENT 0
50 SDL_PIXELTYPE_UNKNOWN
,
54 SDL_PIXELTYPE_PACKED8
,
55 SDL_PIXELTYPE_PACKED16
,
56 SDL_PIXELTYPE_PACKED32
,
57 SDL_PIXELTYPE_ARRAYU8
,
58 SDL_PIXELTYPE_ARRAYU16
,
59 SDL_PIXELTYPE_ARRAYU32
,
60 SDL_PIXELTYPE_ARRAYF16
,
61 SDL_PIXELTYPE_ARRAYF32
64 /** Bitmap pixel order, high bit -> low bit. */
72 /** Packed component order, high bit -> low bit. */
86 /** Array component order, low byte -> high byte. */
98 /** Packed component layout. */
101 SDL_PACKEDLAYOUT_NONE
,
102 SDL_PACKEDLAYOUT_332
,
103 SDL_PACKEDLAYOUT_4444
,
104 SDL_PACKEDLAYOUT_1555
,
105 SDL_PACKEDLAYOUT_5551
,
106 SDL_PACKEDLAYOUT_565
,
107 SDL_PACKEDLAYOUT_8888
,
108 SDL_PACKEDLAYOUT_2101010
,
109 SDL_PACKEDLAYOUT_1010102
112 #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
114 #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
115 ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
116 ((bits) << 8) | ((bytes) << 0))
118 #define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
119 #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
120 #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
121 #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
122 #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
123 #define SDL_BYTESPERPIXEL(X) \
124 (SDL_ISPIXELFORMAT_FOURCC(X) ? \
125 ((((X) == SDL_PIXELFORMAT_YUY2) || \
126 ((X) == SDL_PIXELFORMAT_UYVY) || \
127 ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
129 #define SDL_ISPIXELFORMAT_INDEXED(format) \
130 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
131 ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
132 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
133 (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
135 #define SDL_ISPIXELFORMAT_ALPHA(format) \
136 (!SDL_ISPIXELFORMAT_FOURCC(format) && \
137 ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
138 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
139 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
140 (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))
142 /* The flag is set to 1 because 0x1? is not in the printable ASCII range */
143 #define SDL_ISPIXELFORMAT_FOURCC(format) \
144 ((format) && (SDL_PIXELFLAG(format) != 1))
146 /* Note: If you modify this list, update SDL_GetPixelFormatName() */
149 SDL_PIXELFORMAT_UNKNOWN
,
150 SDL_PIXELFORMAT_INDEX1LSB
=
151 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1
, SDL_BITMAPORDER_4321
, 0,
153 SDL_PIXELFORMAT_INDEX1MSB
=
154 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1
, SDL_BITMAPORDER_1234
, 0,
156 SDL_PIXELFORMAT_INDEX4LSB
=
157 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4
, SDL_BITMAPORDER_4321
, 0,
159 SDL_PIXELFORMAT_INDEX4MSB
=
160 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4
, SDL_BITMAPORDER_1234
, 0,
162 SDL_PIXELFORMAT_INDEX8
=
163 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8
, 0, 0, 8, 1),
164 SDL_PIXELFORMAT_RGB332
=
165 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8
, SDL_PACKEDORDER_XRGB
,
166 SDL_PACKEDLAYOUT_332
, 8, 1),
167 SDL_PIXELFORMAT_RGB444
=
168 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_XRGB
,
169 SDL_PACKEDLAYOUT_4444
, 12, 2),
170 SDL_PIXELFORMAT_RGB555
=
171 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_XRGB
,
172 SDL_PACKEDLAYOUT_1555
, 15, 2),
173 SDL_PIXELFORMAT_BGR555
=
174 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_XBGR
,
175 SDL_PACKEDLAYOUT_1555
, 15, 2),
176 SDL_PIXELFORMAT_ARGB4444
=
177 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_ARGB
,
178 SDL_PACKEDLAYOUT_4444
, 16, 2),
179 SDL_PIXELFORMAT_RGBA4444
=
180 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_RGBA
,
181 SDL_PACKEDLAYOUT_4444
, 16, 2),
182 SDL_PIXELFORMAT_ABGR4444
=
183 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_ABGR
,
184 SDL_PACKEDLAYOUT_4444
, 16, 2),
185 SDL_PIXELFORMAT_BGRA4444
=
186 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_BGRA
,
187 SDL_PACKEDLAYOUT_4444
, 16, 2),
188 SDL_PIXELFORMAT_ARGB1555
=
189 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_ARGB
,
190 SDL_PACKEDLAYOUT_1555
, 16, 2),
191 SDL_PIXELFORMAT_RGBA5551
=
192 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_RGBA
,
193 SDL_PACKEDLAYOUT_5551
, 16, 2),
194 SDL_PIXELFORMAT_ABGR1555
=
195 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_ABGR
,
196 SDL_PACKEDLAYOUT_1555
, 16, 2),
197 SDL_PIXELFORMAT_BGRA5551
=
198 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_BGRA
,
199 SDL_PACKEDLAYOUT_5551
, 16, 2),
200 SDL_PIXELFORMAT_RGB565
=
201 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_XRGB
,
202 SDL_PACKEDLAYOUT_565
, 16, 2),
203 SDL_PIXELFORMAT_BGR565
=
204 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16
, SDL_PACKEDORDER_XBGR
,
205 SDL_PACKEDLAYOUT_565
, 16, 2),
206 SDL_PIXELFORMAT_RGB24
=
207 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8
, SDL_ARRAYORDER_RGB
, 0,
209 SDL_PIXELFORMAT_BGR24
=
210 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8
, SDL_ARRAYORDER_BGR
, 0,
212 SDL_PIXELFORMAT_RGB888
=
213 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_XRGB
,
214 SDL_PACKEDLAYOUT_8888
, 24, 4),
215 SDL_PIXELFORMAT_RGBX8888
=
216 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_RGBX
,
217 SDL_PACKEDLAYOUT_8888
, 24, 4),
218 SDL_PIXELFORMAT_BGR888
=
219 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_XBGR
,
220 SDL_PACKEDLAYOUT_8888
, 24, 4),
221 SDL_PIXELFORMAT_BGRX8888
=
222 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_BGRX
,
223 SDL_PACKEDLAYOUT_8888
, 24, 4),
224 SDL_PIXELFORMAT_ARGB8888
=
225 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_ARGB
,
226 SDL_PACKEDLAYOUT_8888
, 32, 4),
227 SDL_PIXELFORMAT_RGBA8888
=
228 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_RGBA
,
229 SDL_PACKEDLAYOUT_8888
, 32, 4),
230 SDL_PIXELFORMAT_ABGR8888
=
231 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_ABGR
,
232 SDL_PACKEDLAYOUT_8888
, 32, 4),
233 SDL_PIXELFORMAT_BGRA8888
=
234 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_BGRA
,
235 SDL_PACKEDLAYOUT_8888
, 32, 4),
236 SDL_PIXELFORMAT_ARGB2101010
=
237 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32
, SDL_PACKEDORDER_ARGB
,
238 SDL_PACKEDLAYOUT_2101010
, 32, 4),
240 SDL_PIXELFORMAT_YV12
= /**< Planar mode: Y + V + U (3 planes) */
241 SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
242 SDL_PIXELFORMAT_IYUV
= /**< Planar mode: Y + U + V (3 planes) */
243 SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
244 SDL_PIXELFORMAT_YUY2
= /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
245 SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
246 SDL_PIXELFORMAT_UYVY
= /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
247 SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
248 SDL_PIXELFORMAT_YVYU
= /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
249 SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U')
252 typedef struct SDL_Color
259 #define SDL_Colour SDL_Color
261 typedef struct SDL_Palette
270 * \note Everything in the pixel format structure is read-only.
272 typedef struct SDL_PixelFormat
275 SDL_Palette
*palette
;
292 struct SDL_PixelFormat
*next
;
296 * \brief Get the human readable name of a pixel format
298 extern DECLSPEC
const char* SDLCALL
SDL_GetPixelFormatName(Uint32 format
);
301 * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
303 * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
305 * \sa SDL_MasksToPixelFormatEnum()
307 extern DECLSPEC SDL_bool SDLCALL
SDL_PixelFormatEnumToMasks(Uint32 format
,
315 * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
317 * \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion
320 * \sa SDL_PixelFormatEnumToMasks()
322 extern DECLSPEC Uint32 SDLCALL
SDL_MasksToPixelFormatEnum(int bpp
,
329 * \brief Create an SDL_PixelFormat structure from a pixel format enum.
331 extern DECLSPEC SDL_PixelFormat
* SDLCALL
SDL_AllocFormat(Uint32 pixel_format
);
334 * \brief Free an SDL_PixelFormat structure.
336 extern DECLSPEC
void SDLCALL
SDL_FreeFormat(SDL_PixelFormat
*format
);
339 * \brief Create a palette structure with the specified number of color
342 * \return A new palette, or NULL if there wasn't enough memory.
344 * \note The palette entries are initialized to white.
346 * \sa SDL_FreePalette()
348 extern DECLSPEC SDL_Palette
*SDLCALL
SDL_AllocPalette(int ncolors
);
351 * \brief Set the palette for a pixel format structure.
353 extern DECLSPEC
int SDLCALL
SDL_SetPixelFormatPalette(SDL_PixelFormat
* format
,
354 SDL_Palette
*palette
);
357 * \brief Set a range of colors in a palette.
359 * \param palette The palette to modify.
360 * \param colors An array of colors to copy into the palette.
361 * \param firstcolor The index of the first palette entry to modify.
362 * \param ncolors The number of entries to modify.
364 * \return 0 on success, or -1 if not all of the colors could be set.
366 extern DECLSPEC
int SDLCALL
SDL_SetPaletteColors(SDL_Palette
* palette
,
367 const SDL_Color
* colors
,
368 int firstcolor
, int ncolors
);
371 * \brief Free a palette created with SDL_AllocPalette().
373 * \sa SDL_AllocPalette()
375 extern DECLSPEC
void SDLCALL
SDL_FreePalette(SDL_Palette
* palette
);
378 * \brief Maps an RGB triple to an opaque pixel value for a given pixel format.
382 extern DECLSPEC Uint32 SDLCALL
SDL_MapRGB(const SDL_PixelFormat
* format
,
383 Uint8 r
, Uint8 g
, Uint8 b
);
386 * \brief Maps an RGBA quadruple to a pixel value for a given pixel format.
390 extern DECLSPEC Uint32 SDLCALL
SDL_MapRGBA(const SDL_PixelFormat
* format
,
391 Uint8 r
, Uint8 g
, Uint8 b
,
395 * \brief Get the RGB components from a pixel of the specified format.
399 extern DECLSPEC
void SDLCALL
SDL_GetRGB(Uint32 pixel
,
400 const SDL_PixelFormat
* format
,
401 Uint8
* r
, Uint8
* g
, Uint8
* b
);
404 * \brief Get the RGBA components from a pixel of the specified format.
408 extern DECLSPEC
void SDLCALL
SDL_GetRGBA(Uint32 pixel
,
409 const SDL_PixelFormat
* format
,
410 Uint8
* r
, Uint8
* g
, Uint8
* b
,
414 * \brief Calculate a 256 entry gamma ramp for a gamma value.
416 extern DECLSPEC
void SDLCALL
SDL_CalculateGammaRamp(float gamma
, Uint16
* ramp
);
419 /* Ends C function definitions when using C++ */
423 #include "close_code.h"
425 #endif /* _SDL_pixels_h */
427 /* vi: set ts=4 sw=4 expandtab: */