include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 17 Aug 2007 00:54:53 +0000
changeset 2257 340942cfda48
parent 2208 b03710fb0333
child 2275 12ea0fdc0df2
permissions -rw-r--r--
Moved the colorkey and per-surface alpha into the blit info,
in preparation for support for general color channel modulation.

Removed and consolidated some data in the blit info.
     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 } SDL_PixelFormat;
   241 
   242 /**
   243  * \fn SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
   244  *
   245  * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
   246  *
   247  * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
   248  *
   249  * \sa SDL_MasksToPixelFormatEnum()
   250  */
   251 extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
   252                                                             int *bpp,
   253                                                             Uint32 * Rmask,
   254                                                             Uint32 * Gmask,
   255                                                             Uint32 * Bmask,
   256                                                             Uint32 * Amask);
   257 
   258 /**
   259  * \fn Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
   260  *
   261  * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
   262  *
   263  * \return The pixel format, or SDL_PixelFormat_Unknown if the conversion wasn't possible.
   264  *
   265  * \sa SDL_PixelFormatEnumToMasks()
   266  */
   267 extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
   268                                                           Uint32 Rmask,
   269                                                           Uint32 Gmask,
   270                                                           Uint32 Bmask,
   271                                                           Uint32 Amask);
   272 
   273 /**
   274  * \fn SDL_Palette *SDL_AllocPalette(int ncolors)
   275  *
   276  * \brief Create a palette structure with the specified number of color entries.
   277  *
   278  * \return A new palette, or NULL if there wasn't enough memory
   279  *
   280  * \note The palette entries are initialized to white.
   281  *
   282  * \sa SDL_FreePalette()
   283  */
   284 extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
   285 
   286 /**
   287  * \fn int SDL_AddPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
   288  *
   289  * \brief Add a callback function which is called when the palette changes.
   290  *
   291  * \sa SDL_DelPaletteWatch()
   292  */
   293 extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
   294                                                 SDL_PaletteChangedFunc
   295                                                 callback, void *userdata);
   296 
   297 /**
   298  * \fn void SDL_DelPaletteWatch(SDL_Palette *palette, SDL_PaletteChangedFunc callback, void *userdata)
   299  *
   300  * \brief Remove a callback function previously added with SDL_AddPaletteWatch()
   301  *
   302  * \sa SDL_AddPaletteWatch()
   303  */
   304 extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette,
   305                                                  SDL_PaletteChangedFunc
   306                                                  callback, void *userdata);
   307 
   308 /**
   309  * \fn int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Colors *colors, int firstcolor, int numcolors)
   310  *
   311  * \brief Set a range of colors in a palette.
   312  *
   313  * \param palette The palette to modify
   314  * \param colors An array of colors to copy into the palette
   315  * \param firstcolor The index of the first palette entry to modify
   316  * \param ncolors The number of entries to modify
   317  *
   318  * \return 0 on success, or -1 if not all of the colors could be set
   319  */
   320 extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
   321                                                  const SDL_Color * colors,
   322                                                  int firstcolor, int ncolors);
   323 
   324 /**
   325  * \fn void SDL_FreePalette(SDL_Palette *palette)
   326  *
   327  * \brief Free a palette created with SDL_AllocPalette()
   328  *
   329  * \sa SDL_AllocPalette()
   330  */
   331 extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
   332 
   333 /* Ends C function definitions when using C++ */
   334 #ifdef __cplusplus
   335 /* *INDENT-OFF* */
   336 }
   337 /* *INDENT-ON* */
   338 #endif
   339 #include "close_code.h"
   340 
   341 #endif /* _SDL_pixels_h */
   342 
   343 /* vi: set ts=4 sw=4 expandtab: */