comparison include/SDL_pixels.h @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents
children a788656ca29a
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 /**
24 * \file SDL_pixels.h
25 *
26 * Header for the enumerated pixel format definitions
27 */
28
29 #ifndef _SDL_pixels_h
30 #define _SDL_pixels_h
31
32 #include "begin_code.h"
33 /* Set up for C function definitions, even when using C++ */
34 #ifdef __cplusplus
35 /* *INDENT-OFF* */
36 extern "C" {
37 /* *INDENT-ON* */
38 #endif
39
40 enum
41 { /* Pixel type */
42 SDL_PixelType_Unknown,
43 SDL_PixelType_Index1,
44 SDL_PixelType_Index4,
45 SDL_PixelType_Index8,
46 SDL_PixelType_Packed8,
47 SDL_PixelType_Packed16,
48 SDL_PixelType_Packed32,
49 SDL_PixelType_ArrayU8,
50 SDL_PixelType_ArrayU16,
51 SDL_PixelType_ArrayU32,
52 SDL_PixelType_ArrayF16,
53 SDL_PixelType_ArrayF32,
54 };
55
56 enum
57 { /* bitmap pixel order, high bit -> low bit */
58 SDL_BitmapOrder_None,
59 SDL_BitmapOrder_4321,
60 SDL_BitmapOrder_1234,
61 };
62 enum
63 { /* packed component order, high bit -> low bit */
64 SDL_PackedOrder_None,
65 SDL_PackedOrder_XRGB,
66 SDL_PackedOrder_RGBX,
67 SDL_PackedOrder_ARGB,
68 SDL_PackedOrder_RGBA,
69 SDL_PackedOrder_XBGR,
70 SDL_PackedOrder_BGRX,
71 SDL_PackedOrder_ABGR,
72 SDL_PackedOrder_BGRA,
73 };
74 enum
75 { /* array component order, low byte -> high byte */
76 SDL_ArrayOrder_None,
77 SDL_ArrayOrder_RGB,
78 SDL_ArrayOrder_RGBA,
79 SDL_ArrayOrder_ARGB,
80 SDL_ArrayOrder_BGR,
81 SDL_ArrayOrder_BGRA,
82 SDL_ArrayOrder_ABGR,
83 };
84
85 enum
86 { /* Packed component layout */
87 SDL_PackedLayout_None,
88 SDL_PackedLayout_332,
89 SDL_PackedLayout_4444,
90 SDL_PackedLayout_1555,
91 SDL_PackedLayout_5551,
92 SDL_PackedLayout_565,
93 SDL_PackedLayout_8888,
94 SDL_PackedLayout_2101010,
95 SDL_PackedLayout_1010102,
96 };
97
98 #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \
99 ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))
100
101 #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
102 ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
103 ((bits) << 8) | ((bytes) << 0))
104
105 #define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
106 #define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
107 #define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
108 #define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
109 #define SDL_BYTESPERPIXEL(X) (((X) >> 0) & 0xFF)
110
111 #define SDL_ISPIXELFORMAT_INDEXED(format) \
112 ((SDL_PIXELTYPE(format) == SDL_PixelType_Index1) || \
113 (SDL_PIXELTYPE(format) == SDL_PixelType_Index4) || \
114 (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
115
116 #define SDL_ISPIXELFORMAT_FOURCC(format) \
117 ((format) && !((format) & 0x80000000))
118
119 enum
120 {
121 SDL_PixelFormat_Unknown,
122 SDL_PixelFormat_Index1LSB =
123 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
124 1, 0),
125 SDL_PixelFormat_Index1MSB =
126 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
127 1, 0),
128 SDL_PixelFormat_Index4LSB =
129 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
130 2, 0),
131 SDL_PixelFormat_Index4MSB =
132 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
133 2, 0),
134 SDL_PixelFormat_Index8 =
135 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index8, 0, 0, 8, 1),
136 SDL_PixelFormat_RGB332 =
137 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
138 SDL_PackedLayout_332, 8, 1),
139 SDL_PixelFormat_RGB444 =
140 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
141 SDL_PackedLayout_4444, 12, 2),
142 SDL_PixelFormat_RGB555 =
143 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
144 SDL_PackedLayout_1555, 15, 2),
145 SDL_PixelFormat_ARGB4444 =
146 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
147 SDL_PackedLayout_4444, 16, 2),
148 SDL_PixelFormat_ARGB1555 =
149 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
150 SDL_PackedLayout_1555, 16, 2),
151 SDL_PixelFormat_RGB565 =
152 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
153 SDL_PackedLayout_565, 16, 2),
154 SDL_PixelFormat_RGB24 =
155 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
156 24, 3),
157 SDL_PixelFormat_BGR24 =
158 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
159 24, 3),
160 SDL_PixelFormat_RGB888 =
161 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
162 SDL_PackedLayout_8888, 24, 4),
163 SDL_PixelFormat_BGR888 =
164 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
165 SDL_PackedLayout_8888, 24, 4),
166 SDL_PixelFormat_ARGB8888 =
167 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
168 SDL_PackedLayout_8888, 32, 4),
169 SDL_PixelFormat_RGBA8888 =
170 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
171 SDL_PackedLayout_8888, 32, 4),
172 SDL_PixelFormat_ABGR8888 =
173 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
174 SDL_PackedLayout_8888, 32, 4),
175 SDL_PixelFormat_BGRA8888 =
176 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
177 SDL_PackedLayout_8888, 32, 4),
178 SDL_PixelFormat_ARGB2101010 =
179 SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
180 SDL_PackedLayout_2101010, 32, 4),
181
182 SDL_PixelFormat_YV12 = /* Planar mode: Y + V + U (3 planes) */
183 SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
184 SDL_PixelFormat_IYUV = /* Planar mode: Y + U + V (3 planes) */
185 SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
186 SDL_PixelFormat_YUY2 = /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
187 SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
188 SDL_PixelFormat_UYVY = /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
189 SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
190 SDL_PixelFormat_YVYU = /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
191 SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
192 };
193
194 typedef struct SDL_Color
195 {
196 Uint8 r;
197 Uint8 g;
198 Uint8 b;
199 Uint8 unused;
200 } SDL_Color;
201 #define SDL_Colour SDL_Color
202
203 typedef struct SDL_Palette SDL_Palette;
204 typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette);
205
206 typedef struct SDL_PaletteWatch
207 {
208 SDL_PaletteChangedFunc callback;
209 void *userdata;
210 struct SDL_PaletteWatch *next;
211 } SDL_PaletteWatch;
212
213 struct SDL_Palette
214 {
215 int ncolors;
216 SDL_Color *colors;
217
218 int refcount;
219 SDL_PaletteWatch *watch;
220 };
221
222 /* Everything in the pixel format structure is read-only */
223 typedef struct SDL_PixelFormat
224 {
225 SDL_Palette *palette;
226 Uint8 BitsPerPixel;
227 Uint8 BytesPerPixel;
228 Uint8 Rloss;
229 Uint8 Gloss;
230 Uint8 Bloss;
231 Uint8 Aloss;
232 Uint8 Rshift;
233 Uint8 Gshift;
234 Uint8 Bshift;
235 Uint8 Ashift;
236 Uint32 Rmask;
237 Uint32 Gmask;
238 Uint32 Bmask;
239 Uint32 Amask;
240
241 /* RGB color key information */
242 Uint32 colorkey;
243 /* Alpha value information (per-surface alpha) */
244 Uint8 alpha;
245 } SDL_PixelFormat;
246
247 /**
248 * \fn SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
249 *
250 * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
251 *
252 * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
253 *
254 * \sa SDL_MasksToPixelFormatEnum()
255 */
256 extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
257 int *bpp,
258 Uint32 * Rmask,
259 Uint32 * Gmask,
260 Uint32 * Bmask,
261 Uint32 * Amask);
262
263 /**
264 * \fn Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
265 *
266 * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
267 *
268 * \return The pixel format, or SDL_PixelFormat_Unknown if the conversion wasn't possible.
269 *
270 * \sa SDL_PixelFormatEnumToMasks()
271 */
272 extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
273 Uint32 Rmask,
274 Uint32 Gmask,
275 Uint32 Bmask,
276 Uint32 Amask);
277
278 /**
279 * \fn SDL_Palette *SDL_AllocPalette(int ncolors)
280 *
281 * \brief Create a palette structure with the specified number of color entries.
282 *
283 * \return A new palette, or NULL if there wasn't enough memory
284 *
285 * \note The palette entries are initialized to white.
286 *
287 * \sa SDL_FreePalette()
288 */
289 extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
290
291 /**
292 * \fn int SDL_AddPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
293 *
294 * \brief Add a callback function which is called when the palette changes.
295 *
296 * \sa SDL_DelPaletteWatch()
297 */
298 extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
299 SDL_PaletteChangedFunc
300 callback, void *userdata);
301
302 /**
303 * \fn void SDL_DelPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
304 *
305 * \brief Remove a callback function previously added with SDL_AddPaletteWatch()
306 *
307 * \sa SDL_AddPaletteWatch()
308 */
309 extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
310 SDL_PaletteChangedFunc
311 callback, void *userdata);
312
313 /**
314 * \fn int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Colors *colors, int firstcolor, int numcolors)
315 *
316 * \brief Set a range of colors in a palette.
317 *
318 * \param palette The palette to modify
319 * \param colors An array of colors to copy into the palette
320 * \param firstcolor The index of the first palette entry to modify
321 * \param ncolors The number of entries to modify
322 *
323 * \return 0 on success, or -1 if not all of the colors could be set
324 */
325 extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
326 const SDL_Color * colors,
327 int firstcolor, int ncolors);
328
329 /**
330 * \fn void SDL_FreePalette(SDL_Palette *palette)
331 *
332 * \brief Free a palette created with SDL_AllocPalette()
333 *
334 * \sa SDL_AllocPalette()
335 */
336 extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
337
338 /* Ends C function definitions when using C++ */
339 #ifdef __cplusplus
340 /* *INDENT-OFF* */
341 }
342 /* *INDENT-ON* */
343 #endif
344 #include "close_code.h"
345
346 #endif /* _SDL_pixels_h */
347
348 /* vi: set ts=4 sw=4 expandtab: */