include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 11 Jun 2006 07:30:16 +0000
branchSDL-1.3
changeset 1675 d33dcfc3fde7
parent 1668 4da1ee79c9af
child 1676 e136f3ffdc1b
permissions -rw-r--r--
Overlay functions are being replaced by YUV textures.
If the driver doesn't support YUV textures, they can be emulated by backing
the texture with an RGB texture and using the software conversion routines.

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