include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 19 Oct 2009 13:31:58 +0000
changeset 3407 d3baf5ac4e37
parent 3177 efe3b3971e4f
child 3483 a54df8e52333
permissions -rw-r--r--
Partial fix for bug #859

Header file update from Ken for improved doxygen output
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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 /**
    41  *  \name Transparency definitions
    42  *  
    43  *  These define alpha as the opacity of a surface.
    44  */
    45 /*@{*/
    46 #define SDL_ALPHA_OPAQUE 255
    47 #define SDL_ALPHA_TRANSPARENT 0
    48 /*@}*/
    49 
    50 /** Pixel type. */
    51 enum
    52 {
    53     SDL_PIXELTYPE_UNKNOWN,
    54     SDL_PIXELTYPE_INDEX1,
    55     SDL_PIXELTYPE_INDEX4,
    56     SDL_PIXELTYPE_INDEX8,
    57     SDL_PIXELTYPE_PACKED8,
    58     SDL_PIXELTYPE_PACKED16,
    59     SDL_PIXELTYPE_PACKED32,
    60     SDL_PIXELTYPE_ARRAYU8,
    61     SDL_PIXELTYPE_ARRAYU16,
    62     SDL_PIXELTYPE_ARRAYU32,
    63     SDL_PIXELTYPE_ARRAYF16,
    64     SDL_PIXELTYPE_ARRAYF32
    65 };
    66 
    67 /** Bitmap pixel order, high bit -> low bit. */
    68 enum
    69 {
    70     SDL_BITMAPORDER_NONE,
    71     SDL_BITMAPORDER_4321,
    72     SDL_BITMAPORDER_1234
    73 };
    74 
    75 /** Packed component order, high bit -> low bit. */
    76 enum
    77 {
    78     SDL_PACKEDORDER_NONE,
    79     SDL_PACKEDORDER_XRGB,
    80     SDL_PACKEDORDER_RGBX,
    81     SDL_PACKEDORDER_ARGB,
    82     SDL_PACKEDORDER_RGBA,
    83     SDL_PACKEDORDER_XBGR,
    84     SDL_PACKEDORDER_BGRX,
    85     SDL_PACKEDORDER_ABGR,
    86     SDL_PACKEDORDER_BGRA
    87 };
    88 
    89 /** Array component order, low byte -> high byte. */
    90 enum
    91 {
    92     SDL_ARRAYORDER_NONE,
    93     SDL_ARRAYORDER_RGB,
    94     SDL_ARRAYORDER_RGBA,
    95     SDL_ARRAYORDER_ARGB,
    96     SDL_ARRAYORDER_BGR,
    97     SDL_ARRAYORDER_BGRA,
    98     SDL_ARRAYORDER_ABGR
    99 };
   100 
   101 /** Packed component layout. */
   102 enum
   103 {
   104     SDL_PACKEDLAYOUT_NONE,
   105     SDL_PACKEDLAYOUT_332,
   106     SDL_PACKEDLAYOUT_4444,
   107     SDL_PACKEDLAYOUT_1555,
   108     SDL_PACKEDLAYOUT_5551,
   109     SDL_PACKEDLAYOUT_565,
   110     SDL_PACKEDLAYOUT_8888,
   111     SDL_PACKEDLAYOUT_2101010,
   112     SDL_PACKEDLAYOUT_1010102
   113 };
   114 
   115 #define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \
   116     ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))
   117 
   118 #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
   119     ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
   120      ((bits) << 8) | ((bytes) << 0))
   121 
   122 #define SDL_PIXELTYPE(X)	(((X) >> 24) & 0x0F)
   123 #define SDL_PIXELORDER(X)	(((X) >> 20) & 0x0F)
   124 #define SDL_PIXELLAYOUT(X)	(((X) >> 16) & 0x0F)
   125 #define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
   126 #define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
   127 
   128 #define SDL_ISPIXELFORMAT_INDEXED(format)   \
   129     ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
   130      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
   131      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8))
   132 
   133 #define SDL_ISPIXELFORMAT_ALPHA(format)   \
   134     ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
   135      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
   136      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
   137      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))
   138 
   139 #define SDL_ISPIXELFORMAT_FOURCC(format)    \
   140     ((format) && !((format) & 0x80000000))
   141 
   142 enum
   143 {
   144     SDL_PIXELFORMAT_UNKNOWN,
   145     SDL_PIXELFORMAT_INDEX1LSB =
   146         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
   147                                1, 0),
   148     SDL_PIXELFORMAT_INDEX1MSB =
   149         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
   150                                1, 0),
   151     SDL_PIXELFORMAT_INDEX4LSB =
   152         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
   153                                4, 0),
   154     SDL_PIXELFORMAT_INDEX4MSB =
   155         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
   156                                4, 0),
   157     SDL_PIXELFORMAT_INDEX8 =
   158         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
   159     SDL_PIXELFORMAT_RGB332 =
   160         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
   161                                SDL_PACKEDLAYOUT_332, 8, 1),
   162     SDL_PIXELFORMAT_RGB444 =
   163         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
   164                                SDL_PACKEDLAYOUT_4444, 12, 2),
   165     SDL_PIXELFORMAT_RGB555 =
   166         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
   167                                SDL_PACKEDLAYOUT_1555, 15, 2),
   168     SDL_PIXELFORMAT_BGR555 =
   169         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
   170                                SDL_PACKEDLAYOUT_1555, 15, 2),
   171     SDL_PIXELFORMAT_ARGB4444 =
   172         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
   173                                SDL_PACKEDLAYOUT_4444, 16, 2),
   174     SDL_PIXELFORMAT_ABGR4444 =
   175         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
   176                                SDL_PACKEDLAYOUT_4444, 16, 2),
   177     SDL_PIXELFORMAT_ARGB1555 =
   178         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
   179                                SDL_PACKEDLAYOUT_1555, 16, 2),
   180     SDL_PIXELFORMAT_ABGR1555 =
   181         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
   182                                SDL_PACKEDLAYOUT_1555, 16, 2),
   183     SDL_PIXELFORMAT_RGB565 =
   184         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
   185                                SDL_PACKEDLAYOUT_565, 16, 2),
   186     SDL_PIXELFORMAT_BGR565 =
   187         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
   188                                SDL_PACKEDLAYOUT_565, 16, 2),
   189     SDL_PIXELFORMAT_RGB24 =
   190         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
   191                                24, 3),
   192     SDL_PIXELFORMAT_BGR24 =
   193         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
   194                                24, 3),
   195     SDL_PIXELFORMAT_RGB888 =
   196         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
   197                                SDL_PACKEDLAYOUT_8888, 24, 4),
   198     SDL_PIXELFORMAT_BGR888 =
   199         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
   200                                SDL_PACKEDLAYOUT_8888, 24, 4),
   201     SDL_PIXELFORMAT_ARGB8888 =
   202         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
   203                                SDL_PACKEDLAYOUT_8888, 32, 4),
   204     SDL_PIXELFORMAT_RGBA8888 =
   205         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
   206                                SDL_PACKEDLAYOUT_8888, 32, 4),
   207     SDL_PIXELFORMAT_ABGR8888 =
   208         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
   209                                SDL_PACKEDLAYOUT_8888, 32, 4),
   210     SDL_PIXELFORMAT_BGRA8888 =
   211         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
   212                                SDL_PACKEDLAYOUT_8888, 32, 4),
   213     SDL_PIXELFORMAT_ARGB2101010 =
   214         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
   215                                SDL_PACKEDLAYOUT_2101010, 32, 4),
   216 
   217     SDL_PIXELFORMAT_YV12 =      /**< Planar mode: Y + V + U  (3 planes) */
   218         SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
   219     SDL_PIXELFORMAT_IYUV =      /**< Planar mode: Y + U + V  (3 planes) */
   220         SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
   221     SDL_PIXELFORMAT_YUY2 =      /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
   222         SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
   223     SDL_PIXELFORMAT_UYVY =      /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
   224         SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
   225     SDL_PIXELFORMAT_YVYU =      /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
   226         SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U')
   227 };
   228 
   229 typedef struct SDL_Color
   230 {
   231     Uint8 r;
   232     Uint8 g;
   233     Uint8 b;
   234     Uint8 unused;
   235 } SDL_Color;
   236 #define SDL_Colour SDL_Color
   237 
   238 typedef struct SDL_Palette SDL_Palette;
   239 typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette);
   240 
   241 typedef struct SDL_PaletteWatch
   242 {
   243     SDL_PaletteChangedFunc callback;
   244     void *userdata;
   245     struct SDL_PaletteWatch *next;
   246 } SDL_PaletteWatch;
   247 
   248 struct SDL_Palette
   249 {
   250     int ncolors;
   251     SDL_Color *colors;
   252 
   253     int refcount;
   254     SDL_PaletteWatch *watch;
   255 };
   256 
   257 /**
   258  *  \note Everything in the pixel format structure is read-only.
   259  */
   260 typedef struct SDL_PixelFormat
   261 {
   262     SDL_Palette *palette;
   263     Uint8 BitsPerPixel;
   264     Uint8 BytesPerPixel;
   265     Uint8 Rloss;
   266     Uint8 Gloss;
   267     Uint8 Bloss;
   268     Uint8 Aloss;
   269     Uint8 Rshift;
   270     Uint8 Gshift;
   271     Uint8 Bshift;
   272     Uint8 Ashift;
   273     Uint32 Rmask;
   274     Uint32 Gmask;
   275     Uint32 Bmask;
   276     Uint32 Amask;
   277 } SDL_PixelFormat;
   278 
   279 /**
   280  *  \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
   281  *  
   282  *  \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
   283  *  
   284  *  \sa SDL_MasksToPixelFormatEnum()
   285  */
   286 extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
   287                                                             int *bpp,
   288                                                             Uint32 * Rmask,
   289                                                             Uint32 * Gmask,
   290                                                             Uint32 * Bmask,
   291                                                             Uint32 * Amask);
   292 
   293 /**
   294  *  \brief Convert a bpp and RGBA masks to an enumerated pixel format.
   295  *  
   296  *  \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion 
   297  *          wasn't possible.
   298  *  
   299  *  \sa SDL_PixelFormatEnumToMasks()
   300  */
   301 extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
   302                                                           Uint32 Rmask,
   303                                                           Uint32 Gmask,
   304                                                           Uint32 Bmask,
   305                                                           Uint32 Amask);
   306 
   307 /**
   308  *  \brief Create a palette structure with the specified number of color 
   309  *         entries.
   310  *  
   311  *  \return A new palette, or NULL if there wasn't enough memory.
   312  *  
   313  *  \note The palette entries are initialized to white.
   314  *  
   315  *  \sa SDL_FreePalette()
   316  */
   317 extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
   318 
   319 /**
   320  *  \brief Add a callback function which is called when the palette changes.
   321  *  
   322  *  \sa SDL_DelPaletteWatch()
   323  */
   324 extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
   325                                                 SDL_PaletteChangedFunc
   326                                                 callback, void *userdata);
   327 
   328 /**
   329  *  \brief Remove a callback function previously added with 
   330  *         SDL_AddPaletteWatch().
   331  *  
   332  *  \sa SDL_AddPaletteWatch()
   333  */
   334 extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
   335                                                  SDL_PaletteChangedFunc
   336                                                  callback, void *userdata);
   337 
   338 /**
   339  *  \brief Set a range of colors in a palette.
   340  *  
   341  *  \param palette    The palette to modify.
   342  *  \param colors     An array of colors to copy into the palette.
   343  *  \param firstcolor The index of the first palette entry to modify.
   344  *  \param ncolors    The number of entries to modify.
   345  *  
   346  *  \return 0 on success, or -1 if not all of the colors could be set.
   347  */
   348 extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
   349                                                  const SDL_Color * colors,
   350                                                  int firstcolor, int ncolors);
   351 
   352 /**
   353  *  \brief Free a palette created with SDL_AllocPalette().
   354  *  
   355  *  \sa SDL_AllocPalette()
   356  */
   357 extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
   358 
   359 /**
   360  *  \brief Maps an RGB triple to an opaque pixel value for a given pixel format.
   361  *  
   362  *  \sa SDL_MapRGBA
   363  */
   364 extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
   365                                           Uint8 r, Uint8 g, Uint8 b);
   366 
   367 /**
   368  *  \brief Maps an RGBA quadruple to a pixel value for a given pixel format.
   369  *  
   370  *  \sa SDL_MapRGB
   371  */
   372 extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
   373                                            Uint8 r, Uint8 g, Uint8 b,
   374                                            Uint8 a);
   375 
   376 /**
   377  *  \brief Maps a pixel value into the RGB components for a given pixel format.
   378  *  
   379  *  \sa SDL_GetRGBA
   380  */
   381 extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
   382                                         const SDL_PixelFormat * format,
   383                                         Uint8 * r, Uint8 * g, Uint8 * b);
   384 
   385 /**
   386  *  \brief Maps a pixel value into the RGBA components for a given pixel format.
   387  *  
   388  *  \sa SDL_GetRGB
   389  */
   390 extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
   391                                          const SDL_PixelFormat * format,
   392                                          Uint8 * r, Uint8 * g, Uint8 * b,
   393                                          Uint8 * a);
   394 
   395 /* Ends C function definitions when using C++ */
   396 #ifdef __cplusplus
   397 /* *INDENT-OFF* */
   398 }
   399 /* *INDENT-ON* */
   400 #endif
   401 #include "close_code.h"
   402 
   403 #endif /* _SDL_pixels_h */
   404 
   405 /* vi: set ts=4 sw=4 expandtab: */