include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 12 Jun 2006 09:10:06 +0000
branchSDL-1.3
changeset 1676 e136f3ffdc1b
parent 1675 d33dcfc3fde7
child 1681 80a5e6a4e1e2
permissions -rw-r--r--
Adding software renderer implementation
     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_FOURCC(format)    (((format) & 0x8000000) != 0)
   112 
   113 enum
   114 {
   115     SDL_PixelFormat_Unknown,
   116     SDL_PixelFormat_Index1LSB =
   117         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
   118                                1, 0),
   119     SDL_PixelFormat_Index1MSB =
   120         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
   121                                1, 0),
   122     SDL_PixelFormat_Index4LSB =
   123         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
   124                                2, 0),
   125     SDL_PixelFormat_Index4MSB =
   126         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
   127                                2, 0),
   128     SDL_PixelFormat_Index8 =
   129         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index8, 0, 0, 8, 1),
   130     SDL_PixelFormat_RGB332 =
   131         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
   132                                SDL_PackedLayout_332, 8, 1),
   133     SDL_PixelFormat_RGB444 =
   134         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   135                                SDL_PackedLayout_4444, 12, 2),
   136     SDL_PixelFormat_RGB555 =
   137         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   138                                SDL_PackedLayout_1555, 15, 2),
   139     SDL_PixelFormat_ARGB4444 =
   140         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
   141                                SDL_PackedLayout_4444, 16, 2),
   142     SDL_PixelFormat_ARGB1555 =
   143         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
   144                                SDL_PackedLayout_1555, 16, 2),
   145     SDL_PixelFormat_RGB565 =
   146         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
   147                                SDL_PackedLayout_565, 16, 2),
   148     SDL_PixelFormat_RGB24 =
   149         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
   150                                24, 3),
   151     SDL_PixelFormat_BGR24 =
   152         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
   153                                24, 3),
   154     SDL_PixelFormat_RGB888 =
   155         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
   156                                SDL_PackedLayout_8888, 24, 4),
   157     SDL_PixelFormat_BGR888 =
   158         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
   159                                SDL_PackedLayout_8888, 24, 4),
   160     SDL_PixelFormat_ARGB8888 =
   161         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
   162                                SDL_PackedLayout_8888, 32, 4),
   163     SDL_PixelFormat_RGBA8888 =
   164         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
   165                                SDL_PackedLayout_8888, 32, 4),
   166     SDL_PixelFormat_ABGR8888 =
   167         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
   168                                SDL_PackedLayout_8888, 32, 4),
   169     SDL_PixelFormat_BGRA8888 =
   170         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
   171                                SDL_PackedLayout_8888, 32, 4),
   172     SDL_PixelFormat_ARGB2101010 =
   173         SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
   174                                SDL_PackedLayout_2101010, 32, 4),
   175 
   176     SDL_PixelFormat_YV12 = SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
   177     SDL_PixelFormat_IYUV = SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
   178     SDL_PixelFormat_YUY2 = SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
   179     SDL_PixelFormat_UYVY = SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
   180     SDL_PixelFormat_YVYU = SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
   181 };
   182 
   183 typedef struct SDL_Color
   184 {
   185     Uint8 r;
   186     Uint8 g;
   187     Uint8 b;
   188     Uint8 unused;
   189 } SDL_Color;
   190 #define SDL_Colour SDL_Color
   191 
   192 typedef struct SDL_Palette
   193 {
   194     int ncolors;
   195     SDL_Color *colors;
   196 } SDL_Palette;
   197 
   198 /* Everything in the pixel format structure is read-only */
   199 typedef struct SDL_PixelFormat
   200 {
   201     SDL_Palette *palette;
   202     Uint8 BitsPerPixel;
   203     Uint8 BytesPerPixel;
   204     Uint8 Rloss;
   205     Uint8 Gloss;
   206     Uint8 Bloss;
   207     Uint8 Aloss;
   208     Uint8 Rshift;
   209     Uint8 Gshift;
   210     Uint8 Bshift;
   211     Uint8 Ashift;
   212     Uint32 Rmask;
   213     Uint32 Gmask;
   214     Uint32 Bmask;
   215     Uint32 Amask;
   216 
   217     /* RGB color key information */
   218     Uint32 colorkey;
   219     /* Alpha value information (per-surface alpha) */
   220     Uint8 alpha;
   221 } SDL_PixelFormat;
   222 
   223 /*
   224  * Convert one of the enumerated formats above to a bpp and RGBA masks.
   225  * Returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
   226  */
   227 extern DECLSPEC SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp,
   228                                                     Uint32 * Rmask,
   229                                                     Uint32 * Gmask,
   230                                                     Uint32 * Bmask,
   231                                                     Uint32 * Amask);
   232 
   233 /*
   234  * Convert a bpp and RGBA masks to one of the enumerated formats above.
   235  * Returns SDL_PixelFormat_Unknown if the conversion wasn't possible.
   236  */
   237 extern DECLSPEC Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask,
   238                                                   Uint32 Gmask, Uint32 Bmask,
   239                                                   Uint32 Amask);
   240 
   241 /* Ends C function definitions when using C++ */
   242 #ifdef __cplusplus
   243 /* *INDENT-OFF* */
   244 }
   245 /* *INDENT-ON* */
   246 #endif
   247 #include "close_code.h"
   248 
   249 #endif /* _SDL_pixels_h */
   250 
   251 /* vi: set ts=4 sw=4 expandtab: */