include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 16 Jun 2006 06:00:31 +0000
branchSDL-1.3
changeset 1682 7ae8018b2e5d
parent 1681 80a5e6a4e1e2
child 1683 396a35389351
permissions -rw-r--r--
Default palette entries to white, instead of black.
More palettized video mode support...
     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 = SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
   183     SDL_PixelFormat_IYUV = SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
   184     SDL_PixelFormat_YUY2 = SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
   185     SDL_PixelFormat_UYVY = SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
   186     SDL_PixelFormat_YVYU = SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
   187 };
   188 
   189 typedef struct SDL_Color
   190 {
   191     Uint8 r;
   192     Uint8 g;
   193     Uint8 b;
   194     Uint8 unused;
   195 } SDL_Color;
   196 #define SDL_Colour SDL_Color
   197 
   198 typedef struct SDL_Palette
   199 {
   200     int ncolors;
   201     SDL_Color *colors;
   202 } SDL_Palette;
   203 
   204 /* Everything in the pixel format structure is read-only */
   205 typedef struct SDL_PixelFormat
   206 {
   207     SDL_Palette *palette;
   208     Uint8 BitsPerPixel;
   209     Uint8 BytesPerPixel;
   210     Uint8 Rloss;
   211     Uint8 Gloss;
   212     Uint8 Bloss;
   213     Uint8 Aloss;
   214     Uint8 Rshift;
   215     Uint8 Gshift;
   216     Uint8 Bshift;
   217     Uint8 Ashift;
   218     Uint32 Rmask;
   219     Uint32 Gmask;
   220     Uint32 Bmask;
   221     Uint32 Amask;
   222 
   223     /* RGB color key information */
   224     Uint32 colorkey;
   225     /* Alpha value information (per-surface alpha) */
   226     Uint8 alpha;
   227 } SDL_PixelFormat;
   228 
   229 /*
   230  * Convert one of the enumerated formats above to a bpp and RGBA masks.
   231  * Returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
   232  */
   233 extern DECLSPEC SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp,
   234                                                     Uint32 * Rmask,
   235                                                     Uint32 * Gmask,
   236                                                     Uint32 * Bmask,
   237                                                     Uint32 * Amask);
   238 
   239 /*
   240  * Convert a bpp and RGBA masks to one of the enumerated formats above.
   241  * Returns SDL_PixelFormat_Unknown if the conversion wasn't possible.
   242  */
   243 extern DECLSPEC Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask,
   244                                                   Uint32 Gmask, Uint32 Bmask,
   245                                                   Uint32 Amask);
   246 
   247 /* Ends C function definitions when using C++ */
   248 #ifdef __cplusplus
   249 /* *INDENT-OFF* */
   250 }
   251 /* *INDENT-ON* */
   252 #endif
   253 #include "close_code.h"
   254 
   255 #endif /* _SDL_pixels_h */
   256 
   257 /* vi: set ts=4 sw=4 expandtab: */