include/SDL_pixels.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
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@1662
    98
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
slouken@1662
    99
    ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
slouken@1662
   100
     ((bits) << 8) | ((bytes) << 0))
slouken@1662
   101
slouken@1662
   102
#define SDL_PIXELTYPE(X)	(((X) >> 24) & 0x0F)
slouken@1662
   103
#define SDL_PIXELORDER(X)	(((X) >> 20) & 0x0F)
slouken@1662
   104
#define SDL_PIXELLAYOUT(X)	(((X) >> 16) & 0x0F)
slouken@1662
   105
#define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
slouken@1662
   106
#define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
slouken@1662
   107
slouken@1662
   108
enum
slouken@1662
   109
{
slouken@1662
   110
    SDL_PixelFormat_Unknown,
slouken@1662
   111
    SDL_PixelFormat_Index1LSB =
slouken@1662
   112
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index1, SDL_BitmapOrder_1234, 0,
slouken@1662
   113
                                1, 0),
slouken@1662
   114
    SDL_PixelFormat_Index1MSB =
slouken@1662
   115
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index1, SDL_BitmapOrder_4321, 0,
slouken@1662
   116
                                1, 0),
slouken@1662
   117
    SDL_PixelFormat_Index4LSB =
slouken@1662
   118
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index4, SDL_BitmapOrder_1234, 0,
slouken@1662
   119
                                2, 0),
slouken@1662
   120
    SDL_PixelFormat_Index4MSB =
slouken@1662
   121
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index4, SDL_BitmapOrder_4321, 0,
slouken@1662
   122
                                2, 0),
slouken@1662
   123
    SDL_PixelFormat_Index8 =
slouken@1662
   124
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Index8, 0, 0, 8, 1),
slouken@1662
   125
    SDL_PixelFormat_RGB332 =
slouken@1662
   126
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed8, SDL_PackedOrder_XRGB,
slouken@1662
   127
                                SDL_PackedLayout_332, 8, 1),
slouken@1662
   128
    SDL_PixelFormat_RGB444 =
slouken@1662
   129
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1662
   130
                                SDL_PackedLayout_4444, 12, 2),
slouken@1662
   131
    SDL_PixelFormat_RGB555 =
slouken@1662
   132
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1662
   133
                                SDL_PackedLayout_1555, 15, 2),
slouken@1662
   134
    SDL_PixelFormat_ARGB4444 =
slouken@1662
   135
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
slouken@1662
   136
                                SDL_PackedLayout_4444, 16, 2),
slouken@1662
   137
    SDL_PixelFormat_ARGB1555 =
slouken@1662
   138
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_ARGB,
slouken@1662
   139
                                SDL_PackedLayout_1555, 16, 2),
slouken@1662
   140
    SDL_PixelFormat_RGB565 =
slouken@1662
   141
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed16, SDL_PackedOrder_XRGB,
slouken@1662
   142
                                SDL_PackedLayout_565, 16, 2),
slouken@1662
   143
    SDL_PixelFormat_RGB24 =
slouken@1662
   144
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_ArrayU8, SDL_ArrayOrder_RGB, 0,
slouken@1662
   145
                                24, 3),
slouken@1662
   146
    SDL_PixelFormat_BGR24 =
slouken@1662
   147
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_ArrayU8, SDL_ArrayOrder_BGR, 0,
slouken@1662
   148
                                24, 3),
slouken@1662
   149
    SDL_PixelFormat_RGB888 =
slouken@1662
   150
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_XRGB,
slouken@1662
   151
                                SDL_PackedLayout_8888, 24, 4),
slouken@1662
   152
    SDL_PixelFormat_BGR888 =
slouken@1662
   153
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_XBGR,
slouken@1662
   154
                                SDL_PackedLayout_8888, 24, 4),
slouken@1662
   155
    SDL_PixelFormat_ARGB8888 =
slouken@1662
   156
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
slouken@1662
   157
                                SDL_PackedLayout_8888, 32, 4),
slouken@1662
   158
    SDL_PixelFormat_RGBA8888 =
slouken@1662
   159
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_RGBA,
slouken@1662
   160
                                SDL_PackedLayout_8888, 32, 4),
slouken@1662
   161
    SDL_PixelFormat_ABGR8888 =
slouken@1662
   162
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ABGR,
slouken@1662
   163
                                SDL_PackedLayout_8888, 32, 4),
slouken@1662
   164
    SDL_PixelFormat_BGRA8888 =
slouken@1662
   165
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_BGRA,
slouken@1662
   166
                                SDL_PackedLayout_8888, 32, 4),
slouken@1662
   167
    SDL_PixelFormat_ARGB2101010 =
slouken@1662
   168
        SDL_DEFINE_PIXELFORMAT (SDL_PixelType_Packed32, SDL_PackedOrder_ARGB,
slouken@1662
   169
                                SDL_PackedLayout_2101010, 32, 4),
slouken@1662
   170
};
slouken@1662
   171
slouken@1662
   172
typedef struct SDL_Color
slouken@1662
   173
{
slouken@1662
   174
    Uint8 r;
slouken@1662
   175
    Uint8 g;
slouken@1662
   176
    Uint8 b;
slouken@1662
   177
    Uint8 unused;
slouken@1662
   178
} SDL_Color;
slouken@1662
   179
#define SDL_Colour SDL_Color
slouken@1662
   180
slouken@1662
   181
typedef struct SDL_Palette
slouken@1662
   182
{
slouken@1662
   183
    int ncolors;
slouken@1662
   184
    SDL_Color *colors;
slouken@1662
   185
} SDL_Palette;
slouken@1662
   186
slouken@1662
   187
/* Everything in the pixel format structure is read-only */
slouken@1662
   188
typedef struct SDL_PixelFormat
slouken@1662
   189
{
slouken@1662
   190
    SDL_Palette *palette;
slouken@1662
   191
    Uint8 BitsPerPixel;
slouken@1662
   192
    Uint8 BytesPerPixel;
slouken@1662
   193
    Uint8 Rloss;
slouken@1662
   194
    Uint8 Gloss;
slouken@1662
   195
    Uint8 Bloss;
slouken@1662
   196
    Uint8 Aloss;
slouken@1662
   197
    Uint8 Rshift;
slouken@1662
   198
    Uint8 Gshift;
slouken@1662
   199
    Uint8 Bshift;
slouken@1662
   200
    Uint8 Ashift;
slouken@1662
   201
    Uint32 Rmask;
slouken@1662
   202
    Uint32 Gmask;
slouken@1662
   203
    Uint32 Bmask;
slouken@1662
   204
    Uint32 Amask;
slouken@1662
   205
slouken@1662
   206
    /* RGB color key information */
slouken@1662
   207
    Uint32 colorkey;
slouken@1662
   208
    /* Alpha value information (per-surface alpha) */
slouken@1662
   209
    Uint8 alpha;
slouken@1662
   210
} SDL_PixelFormat;
slouken@1662
   211
slouken@1662
   212
/*
slouken@1662
   213
 * Convert one of the enumerated formats above to a bpp and RGBA masks.
slouken@1662
   214
 * Returns SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
slouken@1662
   215
 */
slouken@1662
   216
extern DECLSPEC SDL_bool SDL_PixelFormatEnumToMasks (Uint32 format, int *bpp,
slouken@1662
   217
                                                     Uint32 * Rmask,
slouken@1662
   218
                                                     Uint32 * Gmask,
slouken@1662
   219
                                                     Uint32 * Bmask,
slouken@1662
   220
                                                     Uint32 * Amask);
slouken@1662
   221
slouken@1662
   222
/*
slouken@1662
   223
 * Convert a bpp and RGBA masks to one of the enumerated formats above.
slouken@1662
   224
 * Returns SDL_PixelFormat_Unknown if the conversion wasn't possible.
slouken@1662
   225
 */
slouken@1662
   226
extern DECLSPEC Uint32 SDL_MasksToPixelFormatEnum (int bpp, Uint32 Rmask,
slouken@1662
   227
                                                   Uint32 Gmask, Uint32 Bmask,
slouken@1662
   228
                                                   Uint32 Amask);
slouken@1662
   229
slouken@1662
   230
/* Ends C function definitions when using C++ */
slouken@1662
   231
#ifdef __cplusplus
slouken@1662
   232
/* *INDENT-OFF* */
slouken@1662
   233
}
slouken@1662
   234
/* *INDENT-ON* */
slouken@1662
   235
#endif
slouken@1662
   236
#include "close_code.h"
slouken@1662
   237
slouken@1662
   238
#endif /* _SDL_pixels_h */
slouken@1662
   239
slouken@1662
   240
/* vi: set ts=4 sw=4 expandtab: */