include/SDL_pixels.h
changeset 1895 c121d94672cb
child 1965 a788656ca29a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_pixels.h	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -0,0 +1,348 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +/**
    1.27 + * \file SDL_pixels.h
    1.28 + *
    1.29 + * Header for the enumerated pixel format definitions
    1.30 + */
    1.31 +
    1.32 +#ifndef _SDL_pixels_h
    1.33 +#define _SDL_pixels_h
    1.34 +
    1.35 +#include "begin_code.h"
    1.36 +/* Set up for C function definitions, even when using C++ */
    1.37 +#ifdef __cplusplus
    1.38 +/* *INDENT-OFF* */
    1.39 +extern "C" {
    1.40 +/* *INDENT-ON* */
    1.41 +#endif
    1.42 +
    1.43 +enum
    1.44 +{                               /* Pixel type */
    1.45 +    SDL_PixelType_Unknown,
    1.46 +    SDL_PixelType_Index1,
    1.47 +    SDL_PixelType_Index4,
    1.48 +    SDL_PixelType_Index8,
    1.49 +    SDL_PixelType_Packed8,
    1.50 +    SDL_PixelType_Packed16,
    1.51 +    SDL_PixelType_Packed32,
    1.52 +    SDL_PixelType_ArrayU8,
    1.53 +    SDL_PixelType_ArrayU16,
    1.54 +    SDL_PixelType_ArrayU32,
    1.55 +    SDL_PixelType_ArrayF16,
    1.56 +    SDL_PixelType_ArrayF32,
    1.57 +};
    1.58 +
    1.59 +enum
    1.60 +{                               /* bitmap pixel order, high bit -> low bit */
    1.61 +    SDL_BitmapOrder_None,
    1.62 +    SDL_BitmapOrder_4321,
    1.63 +    SDL_BitmapOrder_1234,
    1.64 +};
    1.65 +enum
    1.66 +{                               /* packed component order, high bit -> low bit */
    1.67 +    SDL_PackedOrder_None,
    1.68 +    SDL_PackedOrder_XRGB,
    1.69 +    SDL_PackedOrder_RGBX,
    1.70 +    SDL_PackedOrder_ARGB,
    1.71 +    SDL_PackedOrder_RGBA,
    1.72 +    SDL_PackedOrder_XBGR,
    1.73 +    SDL_PackedOrder_BGRX,
    1.74 +    SDL_PackedOrder_ABGR,
    1.75 +    SDL_PackedOrder_BGRA,
    1.76 +};
    1.77 +enum
    1.78 +{                               /* array component order, low byte -> high byte */
    1.79 +    SDL_ArrayOrder_None,
    1.80 +    SDL_ArrayOrder_RGB,
    1.81 +    SDL_ArrayOrder_RGBA,
    1.82 +    SDL_ArrayOrder_ARGB,
    1.83 +    SDL_ArrayOrder_BGR,
    1.84 +    SDL_ArrayOrder_BGRA,
    1.85 +    SDL_ArrayOrder_ABGR,
    1.86 +};
    1.87 +
    1.88 +enum
    1.89 +{                               /* Packed component layout */
    1.90 +    SDL_PackedLayout_None,
    1.91 +    SDL_PackedLayout_332,
    1.92 +    SDL_PackedLayout_4444,
    1.93 +    SDL_PackedLayout_1555,
    1.94 +    SDL_PackedLayout_5551,
    1.95 +    SDL_PackedLayout_565,
    1.96 +    SDL_PackedLayout_8888,
    1.97 +    SDL_PackedLayout_2101010,
    1.98 +    SDL_PackedLayout_1010102,
    1.99 +};
   1.100 +
   1.101 +#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \
   1.102 +    ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))
   1.103 +
   1.104 +#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
   1.105 +    ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
   1.106 +     ((bits) << 8) | ((bytes) << 0))
   1.107 +
   1.108 +#define SDL_PIXELTYPE(X)	(((X) >> 24) & 0x0F)
   1.109 +#define SDL_PIXELORDER(X)	(((X) >> 20) & 0x0F)
   1.110 +#define SDL_PIXELLAYOUT(X)	(((X) >> 16) & 0x0F)
   1.111 +#define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
   1.112 +#define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
   1.113 +
   1.114 +#define SDL_ISPIXELFORMAT_INDEXED(format)   \
   1.115 +    ((SDL_PIXELTYPE(format) == SDL_PixelType_Index1) || \
   1.116 +     (SDL_PIXELTYPE(format) == SDL_PixelType_Index4) || \
   1.117 +     (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
   1.118 +
   1.119 +#define SDL_ISPIXELFORMAT_FOURCC(format)    \
   1.120 +    ((format) && !((format) & 0x80000000))
   1.121 +
   1.122 +enum
   1.123 +{
   1.124 +    SDL_PixelFormat_Unknown,
   1.125 +    SDL_PixelFormat_Index1LSB =
   1.126 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
   1.127 +                               1, 0),
   1.128 +    SDL_PixelFormat_Index1MSB =
   1.129 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
   1.130 +                               1, 0),
   1.131 +    SDL_PixelFormat_Index4LSB =
   1.132 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
   1.133 +                               2, 0),
   1.134 +    SDL_PixelFormat_Index4MSB =
   1.135 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
   1.136 +                               2, 0),
   1.137 +    SDL_PixelFormat_Index8 =
   1.138 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index8, 0, 0, 8, 1),
   1.139 +    SDL_PixelFormat_RGB332 =
   1.140 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
   1.141 +                               SDL_PackedLayout_332, 8, 1),
   1.142 +    SDL_PixelFormat_RGB444 =
   1.143 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   1.144 +                               SDL_PackedLayout_4444, 12, 2),
   1.145 +    SDL_PixelFormat_RGB555 =
   1.146 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   1.147 +                               SDL_PackedLayout_1555, 15, 2),
   1.148 +    SDL_PixelFormat_ARGB4444 =
   1.149 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
   1.150 +                               SDL_PackedLayout_4444, 16, 2),
   1.151 +    SDL_PixelFormat_ARGB1555 =
   1.152 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
   1.153 +                               SDL_PackedLayout_1555, 16, 2),
   1.154 +    SDL_PixelFormat_RGB565 =
   1.155 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   1.156 +                               SDL_PackedLayout_565, 16, 2),
   1.157 +    SDL_PixelFormat_RGB24 =
   1.158 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
   1.159 +                               24, 3),
   1.160 +    SDL_PixelFormat_BGR24 =
   1.161 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
   1.162 +                               24, 3),
   1.163 +    SDL_PixelFormat_RGB888 =
   1.164 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
   1.165 +                               SDL_PackedLayout_8888, 24, 4),
   1.166 +    SDL_PixelFormat_BGR888 =
   1.167 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
   1.168 +                               SDL_PackedLayout_8888, 24, 4),
   1.169 +    SDL_PixelFormat_ARGB8888 =
   1.170 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
   1.171 +                               SDL_PackedLayout_8888, 32, 4),
   1.172 +    SDL_PixelFormat_RGBA8888 =
   1.173 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
   1.174 +                               SDL_PackedLayout_8888, 32, 4),
   1.175 +    SDL_PixelFormat_ABGR8888 =
   1.176 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
   1.177 +                               SDL_PackedLayout_8888, 32, 4),
   1.178 +    SDL_PixelFormat_BGRA8888 =
   1.179 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
   1.180 +                               SDL_PackedLayout_8888, 32, 4),
   1.181 +    SDL_PixelFormat_ARGB2101010 =
   1.182 +        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
   1.183 +                               SDL_PackedLayout_2101010, 32, 4),
   1.184 +
   1.185 +    SDL_PixelFormat_YV12 =      /* Planar mode: Y + V + U  (3 planes) */
   1.186 +        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
   1.187 +    SDL_PixelFormat_IYUV =      /* Planar mode: Y + U + V  (3 planes) */
   1.188 +        SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
   1.189 +    SDL_PixelFormat_YUY2 =      /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   1.190 +        SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
   1.191 +    SDL_PixelFormat_UYVY =      /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   1.192 +        SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
   1.193 +    SDL_PixelFormat_YVYU =      /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   1.194 +        SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
   1.195 +};
   1.196 +
   1.197 +typedef struct SDL_Color
   1.198 +{
   1.199 +    Uint8 r;
   1.200 +    Uint8 g;
   1.201 +    Uint8 b;
   1.202 +    Uint8 unused;
   1.203 +} SDL_Color;
   1.204 +#define SDL_Colour SDL_Color
   1.205 +
   1.206 +typedef struct SDL_Palette SDL_Palette;
   1.207 +typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette);
   1.208 +
   1.209 +typedef struct SDL_PaletteWatch
   1.210 +{
   1.211 +    SDL_PaletteChangedFunc callback;
   1.212 +    void *userdata;
   1.213 +    struct SDL_PaletteWatch *next;
   1.214 +} SDL_PaletteWatch;
   1.215 +
   1.216 +struct SDL_Palette
   1.217 +{
   1.218 +    int ncolors;
   1.219 +    SDL_Color *colors;
   1.220 +
   1.221 +    int refcount;
   1.222 +    SDL_PaletteWatch *watch;
   1.223 +};
   1.224 +
   1.225 +/* Everything in the pixel format structure is read-only */
   1.226 +typedef struct SDL_PixelFormat
   1.227 +{
   1.228 +    SDL_Palette *palette;
   1.229 +    Uint8 BitsPerPixel;
   1.230 +    Uint8 BytesPerPixel;
   1.231 +    Uint8 Rloss;
   1.232 +    Uint8 Gloss;
   1.233 +    Uint8 Bloss;
   1.234 +    Uint8 Aloss;
   1.235 +    Uint8 Rshift;
   1.236 +    Uint8 Gshift;
   1.237 +    Uint8 Bshift;
   1.238 +    Uint8 Ashift;
   1.239 +    Uint32 Rmask;
   1.240 +    Uint32 Gmask;
   1.241 +    Uint32 Bmask;
   1.242 +    Uint32 Amask;
   1.243 +
   1.244 +    /* RGB color key information */
   1.245 +    Uint32 colorkey;
   1.246 +    /* Alpha value information (per-surface alpha) */
   1.247 +    Uint8 alpha;
   1.248 +} SDL_PixelFormat;
   1.249 +
   1.250 +/**
   1.251 + * \fn SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
   1.252 + *
   1.253 + * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
   1.254 + *
   1.255 + * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
   1.256 + *
   1.257 + * \sa SDL_MasksToPixelFormatEnum()
   1.258 + */
   1.259 +extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
   1.260 +                                                            int *bpp,
   1.261 +                                                            Uint32 * Rmask,
   1.262 +                                                            Uint32 * Gmask,
   1.263 +                                                            Uint32 * Bmask,
   1.264 +                                                            Uint32 * Amask);
   1.265 +
   1.266 +/**
   1.267 + * \fn Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
   1.268 + *
   1.269 + * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
   1.270 + *
   1.271 + * \return The pixel format, or SDL_PixelFormat_Unknown if the conversion wasn't possible.
   1.272 + *
   1.273 + * \sa SDL_PixelFormatEnumToMasks()
   1.274 + */
   1.275 +extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
   1.276 +                                                          Uint32 Rmask,
   1.277 +                                                          Uint32 Gmask,
   1.278 +                                                          Uint32 Bmask,
   1.279 +                                                          Uint32 Amask);
   1.280 +
   1.281 +/**
   1.282 + * \fn SDL_Palette *SDL_AllocPalette(int ncolors)
   1.283 + *
   1.284 + * \brief Create a palette structure with the specified number of color entries.
   1.285 + *
   1.286 + * \return A new palette, or NULL if there wasn't enough memory
   1.287 + *
   1.288 + * \note The palette entries are initialized to white.
   1.289 + *
   1.290 + * \sa SDL_FreePalette()
   1.291 + */
   1.292 +extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
   1.293 +
   1.294 +/**
   1.295 + * \fn int SDL_AddPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
   1.296 + *
   1.297 + * \brief Add a callback function which is called when the palette changes.
   1.298 + *
   1.299 + * \sa SDL_DelPaletteWatch()
   1.300 + */
   1.301 +extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
   1.302 +                                                SDL_PaletteChangedFunc
   1.303 +                                                callback, void *userdata);
   1.304 +
   1.305 +/**
   1.306 + * \fn void SDL_DelPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
   1.307 + *
   1.308 + * \brief Remove a callback function previously added with SDL_AddPaletteWatch()
   1.309 + *
   1.310 + * \sa SDL_AddPaletteWatch()
   1.311 + */
   1.312 +extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
   1.313 +                                                 SDL_PaletteChangedFunc
   1.314 +                                                 callback, void *userdata);
   1.315 +
   1.316 +/**
   1.317 + * \fn int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Colors *colors, int firstcolor, int numcolors)
   1.318 + *
   1.319 + * \brief Set a range of colors in a palette.
   1.320 + *
   1.321 + * \param palette The palette to modify
   1.322 + * \param colors An array of colors to copy into the palette
   1.323 + * \param firstcolor The index of the first palette entry to modify
   1.324 + * \param ncolors The number of entries to modify
   1.325 + *
   1.326 + * \return 0 on success, or -1 if not all of the colors could be set
   1.327 + */
   1.328 +extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
   1.329 +                                                 const SDL_Color * colors,
   1.330 +                                                 int firstcolor, int ncolors);
   1.331 +
   1.332 +/**
   1.333 + * \fn void SDL_FreePalette(SDL_Palette *palette)
   1.334 + *
   1.335 + * \brief Free a palette created with SDL_AllocPalette()
   1.336 + *
   1.337 + * \sa SDL_AllocPalette()
   1.338 + */
   1.339 +extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
   1.340 +
   1.341 +/* Ends C function definitions when using C++ */
   1.342 +#ifdef __cplusplus
   1.343 +/* *INDENT-OFF* */
   1.344 +}
   1.345 +/* *INDENT-ON* */
   1.346 +#endif
   1.347 +#include "close_code.h"
   1.348 +
   1.349 +#endif /* _SDL_pixels_h */
   1.350 +
   1.351 +/* vi: set ts=4 sw=4 expandtab: */