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.
slouken@1662
     1
/*
slouken@1662
     2
    SDL - Simple DirectMedia Layer
slouken@1662
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1662
     4
slouken@1662
     5
    This library is free software; you can redistribute it and/or
slouken@1662
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1662
     7
    License as published by the Free Software Foundation; either
slouken@1662
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1662
     9
slouken@1662
    10
    This library is distributed in the hope that it will be useful,
slouken@1662
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1662
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1662
    13
    Lesser General Public License for more details.
slouken@1662
    14
slouken@1662
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1662
    16
    License along with this library; if not, write to the Free Software
slouken@1662
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1662
    18
slouken@1662
    19
    Sam Lantinga
slouken@1662
    20
    slouken@libsdl.org
slouken@1662
    21
*/
slouken@1662
    22
slouken@1662
    23
/**
slouken@1662
    24
 * \file SDL_pixels.h
slouken@1662
    25
 *
slouken@1662
    26
 * Header for the enumerated pixel format definitions
slouken@1662
    27
 */
slouken@1662
    28
slouken@1662
    29
#ifndef _SDL_pixels_h
slouken@1662
    30
#define _SDL_pixels_h
slouken@1662
    31
slouken@1662
    32
#include "begin_code.h"
slouken@1662
    33
/* Set up for C function definitions, even when using C++ */
slouken@1662
    34
#ifdef __cplusplus
slouken@1662
    35
/* *INDENT-OFF* */
slouken@1662
    36
extern "C" {
slouken@1662
    37
/* *INDENT-ON* */
slouken@1662
    38
#endif
slouken@1662
    39
slouken@1662
    40
enum
slouken@1662
    41
{                               /* Pixel type */
slouken@1662
    42
    SDL_PixelType_Unknown,
slouken@1662
    43
    SDL_PixelType_Index1,
slouken@1662
    44
    SDL_PixelType_Index4,
slouken@1662
    45
    SDL_PixelType_Index8,
slouken@1662
    46
    SDL_PixelType_Packed8,
slouken@1662
    47
    SDL_PixelType_Packed16,
slouken@1662
    48
    SDL_PixelType_Packed32,
slouken@1662
    49
    SDL_PixelType_ArrayU8,
slouken@1662
    50
    SDL_PixelType_ArrayU16,
slouken@1662
    51
    SDL_PixelType_ArrayU32,
slouken@1662
    52
    SDL_PixelType_ArrayF16,
slouken@1662
    53
    SDL_PixelType_ArrayF32,
slouken@1662
    54
};
slouken@1662
    55
slouken@1662
    56
enum
slouken@1662
    57
{                               /* bitmap pixel order, high bit -> low bit */
slouken@1662
    58
    SDL_BitmapOrder_None,
slouken@1662
    59
    SDL_BitmapOrder_4321,
slouken@1662
    60
    SDL_BitmapOrder_1234,
slouken@1662
    61
};
slouken@1662
    62
enum
slouken@1662
    63
{                               /* packed component order, high bit -> low bit */
slouken@1662
    64
    SDL_PackedOrder_None,
slouken@1662
    65
    SDL_PackedOrder_XRGB,
slouken@1662
    66
    SDL_PackedOrder_RGBX,
slouken@1662
    67
    SDL_PackedOrder_ARGB,
slouken@1662
    68
    SDL_PackedOrder_RGBA,
slouken@1662
    69
    SDL_PackedOrder_XBGR,
slouken@1662
    70
    SDL_PackedOrder_BGRX,
slouken@1662
    71
    SDL_PackedOrder_ABGR,
slouken@1662
    72
    SDL_PackedOrder_BGRA,
slouken@1662
    73
};
slouken@1662
    74
enum
slouken@1662
    75
{                               /* array component order, low byte -> high byte */
slouken@1662
    76
    SDL_ArrayOrder_None,
slouken@1662
    77
    SDL_ArrayOrder_RGB,
slouken@1662
    78
    SDL_ArrayOrder_RGBA,
slouken@1662
    79
    SDL_ArrayOrder_ARGB,
slouken@1662
    80
    SDL_ArrayOrder_BGR,
slouken@1662
    81
    SDL_ArrayOrder_BGRA,
slouken@1662
    82
    SDL_ArrayOrder_ABGR,
slouken@1662
    83
};
slouken@1662
    84
slouken@1662
    85
enum
slouken@1662
    86
{                               /* Packed component layout */
slouken@1662
    87
    SDL_PackedLayout_None,
slouken@1662
    88
    SDL_PackedLayout_332,
slouken@1662
    89
    SDL_PackedLayout_4444,
slouken@1662
    90
    SDL_PackedLayout_1555,
slouken@1662
    91
    SDL_PackedLayout_5551,
slouken@1662
    92
    SDL_PackedLayout_565,
slouken@1662
    93
    SDL_PackedLayout_8888,
slouken@1662
    94
    SDL_PackedLayout_2101010,
slouken@1662
    95
    SDL_PackedLayout_1010102,
slouken@1662
    96
};
slouken@1662
    97
slouken@1675
    98
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \
slouken@1675
    99
    ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24))
slouken@1675
   100
slouken@1662
   101
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
slouken@1662
   102
    ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
slouken@1662
   103
     ((bits) << 8) | ((bytes) << 0))
slouken@1662
   104
slouken@1662
   105
#define SDL_PIXELTYPE(X)	(((X) >> 24) & 0x0F)
slouken@1662
   106
#define SDL_PIXELORDER(X)	(((X) >> 20) & 0x0F)
slouken@1662
   107
#define SDL_PIXELLAYOUT(X)	(((X) >> 16) & 0x0F)
slouken@1662
   108
#define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
slouken@1662
   109
#define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
slouken@1662
   110
slouken@1662
   111
enum
slouken@1662
   112
{
slouken@1662
   113
    SDL_PixelFormat_Unknown,
slouken@1662
   114
    SDL_PixelFormat_Index1LSB =
slouken@1668
   115
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
slouken@1668
   116
                               1, 0),
slouken@1662
   117
    SDL_PixelFormat_Index1MSB =
slouken@1668
   118
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
slouken@1668
   119
                               1, 0),
slouken@1662
   120
    SDL_PixelFormat_Index4LSB =
slouken@1668
   121
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
slouken@1668
   122
                               2, 0),
slouken@1662
   123
    SDL_PixelFormat_Index4MSB =
slouken@1668
   124
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
slouken@1668
   125
                               2, 0),
slouken@1662
   126
    SDL_PixelFormat_Index8 =
slouken@1668
   127
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Index8, 0, 0, 8, 1),
slouken@1662
   128
    SDL_PixelFormat_RGB332 =
slouken@1668
   129
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
slouken@1668
   130
                               SDL_PackedLayout_332, 8, 1),
slouken@1662
   131
    SDL_PixelFormat_RGB444 =
slouken@1668
   132
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1668
   133
                               SDL_PackedLayout_4444, 12, 2),
slouken@1662
   134
    SDL_PixelFormat_RGB555 =
slouken@1668
   135
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1668
   136
                               SDL_PackedLayout_1555, 15, 2),
slouken@1662
   137
    SDL_PixelFormat_ARGB4444 =
slouken@1668
   138
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
slouken@1668
   139
                               SDL_PackedLayout_4444, 16, 2),
slouken@1662
   140
    SDL_PixelFormat_ARGB1555 =
slouken@1668
   141
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
slouken@1668
   142
                               SDL_PackedLayout_1555, 16, 2),
slouken@1662
   143
    SDL_PixelFormat_RGB565 =
slouken@1668
   144
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1668
   145
                               SDL_PackedLayout_565, 16, 2),
slouken@1662
   146
    SDL_PixelFormat_RGB24 =
slouken@1668
   147
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
slouken@1668
   148
                               24, 3),
slouken@1662
   149
    SDL_PixelFormat_BGR24 =
slouken@1668
   150
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
slouken@1668
   151
                               24, 3),
slouken@1662
   152
    SDL_PixelFormat_RGB888 =
slouken@1668
   153
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
slouken@1668
   154
                               SDL_PackedLayout_8888, 24, 4),
slouken@1662
   155
    SDL_PixelFormat_BGR888 =
slouken@1668
   156
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
slouken@1668
   157
                               SDL_PackedLayout_8888, 24, 4),
slouken@1662
   158
    SDL_PixelFormat_ARGB8888 =
slouken@1668
   159
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
slouken@1668
   160
                               SDL_PackedLayout_8888, 32, 4),
slouken@1662
   161
    SDL_PixelFormat_RGBA8888 =
slouken@1668
   162
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
slouken@1668
   163
                               SDL_PackedLayout_8888, 32, 4),
slouken@1662
   164
    SDL_PixelFormat_ABGR8888 =
slouken@1668
   165
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
slouken@1668
   166
                               SDL_PackedLayout_8888, 32, 4),
slouken@1662
   167
    SDL_PixelFormat_BGRA8888 =
slouken@1668
   168
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
slouken@1668
   169
                               SDL_PackedLayout_8888, 32, 4),
slouken@1662
   170
    SDL_PixelFormat_ARGB2101010 =
slouken@1668
   171
        SDL_DEFINE_PIXELFORMAT(SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
slouken@1668
   172
                               SDL_PackedLayout_2101010, 32, 4),
slouken@1675
   173
slouken@1675
   174
    SDL_PixelFormat_YV12 = SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
slouken@1675
   175
    SDL_PixelFormat_IYUV = SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
slouken@1675
   176
    SDL_PixelFormat_YUY2 = SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
slouken@1675
   177
    SDL_PixelFormat_UYVY = SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
slouken@1675
   178
    SDL_PixelFormat_YVYU = SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
slouken@1662
   179
};
slouken@1662
   180
slouken@1662
   181
typedef struct SDL_Color
slouken@1662
   182
{
slouken@1662
   183
    Uint8 r;
slouken@1662
   184
    Uint8 g;
slouken@1662
   185
    Uint8 b;
slouken@1662
   186
    Uint8 unused;
slouken@1662
   187
} SDL_Color;
slouken@1662
   188
#define SDL_Colour SDL_Color
slouken@1662
   189
slouken@1662
   190
typedef struct SDL_Palette
slouken@1662
   191
{
slouken@1662
   192
    int ncolors;
slouken@1662
   193
    SDL_Color *colors;
slouken@1662
   194
} SDL_Palette;
slouken@1662
   195
slouken@1662
   196
/* Everything in the pixel format structure is read-only */
slouken@1662
   197
typedef struct SDL_PixelFormat
slouken@1662
   198
{
slouken@1662
   199
    SDL_Palette *palette;
slouken@1662
   200
    Uint8 BitsPerPixel;
slouken@1662
   201
    Uint8 BytesPerPixel;
slouken@1662
   202
    Uint8 Rloss;
slouken@1662
   203
    Uint8 Gloss;
slouken@1662
   204
    Uint8 Bloss;
slouken@1662
   205
    Uint8 Aloss;
slouken@1662
   206
    Uint8 Rshift;
slouken@1662
   207
    Uint8 Gshift;
slouken@1662
   208
    Uint8 Bshift;
slouken@1662
   209
    Uint8 Ashift;
slouken@1662
   210
    Uint32 Rmask;
slouken@1662
   211
    Uint32 Gmask;
slouken@1662
   212
    Uint32 Bmask;
slouken@1662
   213
    Uint32 Amask;
slouken@1662
   214
slouken@1662
   215
    /* RGB color key information */
slouken@1662
   216
    Uint32 colorkey;
slouken@1662
   217
    /* Alpha value information (per-surface alpha) */
slouken@1662
   218
    Uint8 alpha;
slouken@1662
   219
} SDL_PixelFormat;
slouken@1662
   220
slouken@1662
   221
/*
slouken@1662
   222
 * Convert one of the enumerated formats above to a bpp and RGBA masks.
slouken@1662
   223
 * Returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
slouken@1662
   224
 */
slouken@1668
   225
extern DECLSPEC SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp,
slouken@1668
   226
                                                    Uint32 * Rmask,
slouken@1668
   227
                                                    Uint32 * Gmask,
slouken@1668
   228
                                                    Uint32 * Bmask,
slouken@1668
   229
                                                    Uint32 * Amask);
slouken@1662
   230
slouken@1662
   231
/*
slouken@1662
   232
 * Convert a bpp and RGBA masks to one of the enumerated formats above.
slouken@1662
   233
 * Returns SDL_PixelFormat_Unknown if the conversion wasn't possible.
slouken@1662
   234
 */
slouken@1668
   235
extern DECLSPEC Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask,
slouken@1668
   236
                                                  Uint32 Gmask, Uint32 Bmask,
slouken@1668
   237
                                                  Uint32 Amask);
slouken@1662
   238
slouken@1662
   239
/* Ends C function definitions when using C++ */
slouken@1662
   240
#ifdef __cplusplus
slouken@1662
   241
/* *INDENT-OFF* */
slouken@1662
   242
}
slouken@1662
   243
/* *INDENT-ON* */
slouken@1662
   244
#endif
slouken@1662
   245
#include "close_code.h"
slouken@1662
   246
slouken@1662
   247
#endif /* _SDL_pixels_h */
slouken@1662
   248
slouken@1662
   249
/* vi: set ts=4 sw=4 expandtab: */