src/video/SDL_pixels.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 23:56:23 -0800
changeset 5436 29977c050731
parent 5433 1b6eee840e26
child 5437 ce10653e370c
permissions -rw-r--r--
Fixed memory corruption with invalid pixel values.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
5262
b530ef003506 Happy 2011! :)
Sam Lantinga <slouken@libsdl.org>
parents: 5243
diff changeset
     3
    Copyright (C) 1997-2011 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
    13
    Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1057
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    19
    Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 50
diff changeset
    20
    slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    22
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
/* General (mostly internal) pixel/color manipulation routines for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#include "SDL_endian.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
#include "SDL_pixels_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
#include "SDL_RLEaccel_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
3555
7549b986ccb1 The SDL_PaletteWatch structure is really internal-only.
Sam Lantinga <slouken@libsdl.org>
parents: 3484
diff changeset
    33
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
/* Helper functions */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    35
4982
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    36
const char*
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    37
SDL_GetPixelFormatName(Uint32 format)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    38
{
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    39
    switch (format) {
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    40
#define CASE(X) case X: return #X;
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    41
    CASE(SDL_PIXELFORMAT_INDEX1LSB)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    42
    CASE(SDL_PIXELFORMAT_INDEX1MSB)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    43
    CASE(SDL_PIXELFORMAT_INDEX4LSB)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    44
    CASE(SDL_PIXELFORMAT_INDEX4MSB)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    45
    CASE(SDL_PIXELFORMAT_INDEX8)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    46
    CASE(SDL_PIXELFORMAT_RGB332)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    47
    CASE(SDL_PIXELFORMAT_RGB444)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    48
    CASE(SDL_PIXELFORMAT_RGB555)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    49
    CASE(SDL_PIXELFORMAT_BGR555)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    50
    CASE(SDL_PIXELFORMAT_ARGB4444)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    51
    CASE(SDL_PIXELFORMAT_RGBA4444)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    52
    CASE(SDL_PIXELFORMAT_ABGR4444)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    53
    CASE(SDL_PIXELFORMAT_BGRA4444)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    54
    CASE(SDL_PIXELFORMAT_ARGB1555)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    55
    CASE(SDL_PIXELFORMAT_RGBA5551)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    56
    CASE(SDL_PIXELFORMAT_ABGR1555)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    57
    CASE(SDL_PIXELFORMAT_BGRA5551)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    58
    CASE(SDL_PIXELFORMAT_RGB565)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    59
    CASE(SDL_PIXELFORMAT_BGR565)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    60
    CASE(SDL_PIXELFORMAT_RGB24)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    61
    CASE(SDL_PIXELFORMAT_BGR24)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    62
    CASE(SDL_PIXELFORMAT_RGB888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    63
    CASE(SDL_PIXELFORMAT_BGR888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    64
    CASE(SDL_PIXELFORMAT_ARGB8888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    65
    CASE(SDL_PIXELFORMAT_RGBA8888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    66
    CASE(SDL_PIXELFORMAT_ABGR8888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    67
    CASE(SDL_PIXELFORMAT_BGRA8888)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    68
    CASE(SDL_PIXELFORMAT_ARGB2101010)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    69
    CASE(SDL_PIXELFORMAT_YV12)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    70
    CASE(SDL_PIXELFORMAT_IYUV)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    71
    CASE(SDL_PIXELFORMAT_YUY2)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    72
    CASE(SDL_PIXELFORMAT_UYVY)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    73
    CASE(SDL_PIXELFORMAT_YVYU)
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    74
#undef CASE
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    75
    default:
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    76
        return "SDL_PIXELFORMAT_UNKNOWN";
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    77
    }
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    78
}
660d3a432102 Added some missing pixel formats and SDL_GetPixelFormatName()
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    79
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    80
SDL_bool
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    81
SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    82
                           Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    83
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    84
    Uint32 masks[4];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    85
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
    86
    /* This function doesn't work with FourCC pixel formats */
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
    87
    if (SDL_ISPIXELFORMAT_FOURCC(format)) {
5433
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
    88
        SDL_SetError("FOURCC pixel formats are not supported");
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
    89
        return SDL_FALSE;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
    90
    }
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
    91
 
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    92
    /* Initialize the values here */
3284
2b95b2c0b6d4 Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents: 3182
diff changeset
    93
    if (SDL_BYTESPERPIXEL(format) <= 2) {
2b95b2c0b6d4 Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents: 3182
diff changeset
    94
        *bpp = SDL_BITSPERPIXEL(format);
2b95b2c0b6d4 Fixed compatibility with SDL 1.2 pixel format (24 bits per pixel of color data with 4 bytes per pixel == 32 bpp)
Sam Lantinga <slouken@libsdl.org>
parents: 3182
diff changeset
    95
    } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    96
        *bpp = SDL_BYTESPERPIXEL(format) * 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    97
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    98
    *Rmask = *Gmask = *Bmask = *Amask = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
    99
3557
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   100
    if (format == SDL_PIXELFORMAT_RGB24) {
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   101
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   102
        *Rmask = 0x00FF0000;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   103
        *Gmask = 0x0000FF00;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   104
        *Bmask = 0x000000FF;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   105
#else
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   106
        *Rmask = 0x000000FF;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   107
        *Gmask = 0x0000FF00;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   108
        *Bmask = 0x00FF0000;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   109
#endif
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   110
        return SDL_TRUE;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   111
    }
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   112
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   113
    if (format == SDL_PIXELFORMAT_BGR24) {
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   114
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   115
        *Rmask = 0x000000FF;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   116
        *Gmask = 0x0000FF00;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   117
        *Bmask = 0x00FF0000;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   118
#else
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   119
        *Rmask = 0x00FF0000;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   120
        *Gmask = 0x0000FF00;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   121
        *Bmask = 0x000000FF;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   122
#endif
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   123
        return SDL_TRUE;
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   124
    }
7184580ab756 Added support for SDL_PIXELFORMAT_RGB24 and SDL_PIXELFORMAT_BGR24 to SDL_PixelFormatEnumToMasks()
Sam Lantinga <slouken@libsdl.org>
parents: 3555
diff changeset
   125
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   126
    if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   127
        SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   128
        SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   129
        /* Not a format that uses masks */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   130
        return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   131
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   132
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   133
    switch (SDL_PIXELLAYOUT(format)) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   134
    case SDL_PACKEDLAYOUT_332:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   135
        masks[0] = 0x00000000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   136
        masks[1] = 0x000000E0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   137
        masks[2] = 0x0000001C;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   138
        masks[3] = 0x00000003;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   139
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   140
    case SDL_PACKEDLAYOUT_4444:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   141
        masks[0] = 0x0000F000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   142
        masks[1] = 0x00000F00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   143
        masks[2] = 0x000000F0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   144
        masks[3] = 0x0000000F;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   145
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   146
    case SDL_PACKEDLAYOUT_1555:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   147
        masks[0] = 0x00008000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   148
        masks[1] = 0x00007C00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   149
        masks[2] = 0x000003E0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   150
        masks[3] = 0x0000001F;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   151
        break;
3163
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   152
    case SDL_PACKEDLAYOUT_5551:
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   153
        masks[0] = 0x0000F800;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   154
        masks[1] = 0x000007C0;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   155
        masks[2] = 0x0000003E;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   156
        masks[3] = 0x00000001;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   157
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   158
    case SDL_PACKEDLAYOUT_565:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   159
        masks[0] = 0x00000000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   160
        masks[1] = 0x0000F800;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   161
        masks[2] = 0x000007E0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   162
        masks[3] = 0x0000001F;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   163
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   164
    case SDL_PACKEDLAYOUT_8888:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   165
        masks[0] = 0xFF000000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   166
        masks[1] = 0x00FF0000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   167
        masks[2] = 0x0000FF00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   168
        masks[3] = 0x000000FF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   169
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   170
    case SDL_PACKEDLAYOUT_2101010:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   171
        masks[0] = 0xC0000000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   172
        masks[1] = 0x3FF00000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   173
        masks[2] = 0x000FFC00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   174
        masks[3] = 0x000003FF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   175
        break;
3163
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   176
    case SDL_PACKEDLAYOUT_1010102:
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   177
        masks[0] = 0xFFC00000;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   178
        masks[1] = 0x003FF000;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   179
        masks[2] = 0x00000FFC;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   180
        masks[3] = 0x00000003;
a252014ce27d Support for BGR565 pixel format has been added, mainly for OpenGL ES renderer. OpenGL ES renderer now have new texture formats.
Mike Gorchak <lestat@i.com.ua>
parents: 2990
diff changeset
   181
        break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   182
    default:
3484
fed6d4c6c693 Set the error so someone can get more information
Sam Lantinga <slouken@libsdl.org>
parents: 3284
diff changeset
   183
        SDL_SetError("Unknown pixel format");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   184
        return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   185
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   186
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   187
    switch (SDL_PIXELORDER(format)) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   188
    case SDL_PACKEDORDER_XRGB:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   189
        *Rmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   190
        *Gmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   191
        *Bmask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   192
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   193
    case SDL_PACKEDORDER_RGBX:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   194
        *Rmask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   195
        *Gmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   196
        *Bmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   197
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   198
    case SDL_PACKEDORDER_ARGB:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   199
        *Amask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   200
        *Rmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   201
        *Gmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   202
        *Bmask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   203
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   204
    case SDL_PACKEDORDER_RGBA:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   205
        *Rmask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   206
        *Gmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   207
        *Bmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   208
        *Amask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   209
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   210
    case SDL_PACKEDORDER_XBGR:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   211
        *Bmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   212
        *Gmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   213
        *Rmask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   214
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   215
    case SDL_PACKEDORDER_BGRX:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   216
        *Bmask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   217
        *Gmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   218
        *Rmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   219
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   220
    case SDL_PACKEDORDER_BGRA:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   221
        *Bmask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   222
        *Gmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   223
        *Rmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   224
        *Amask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   225
        break;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   226
    case SDL_PACKEDORDER_ABGR:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   227
        *Amask = masks[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   228
        *Bmask = masks[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   229
        *Gmask = masks[2];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   230
        *Rmask = masks[3];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   231
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   232
    default:
3484
fed6d4c6c693 Set the error so someone can get more information
Sam Lantinga <slouken@libsdl.org>
parents: 3284
diff changeset
   233
        SDL_SetError("Unknown pixel format");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   234
        return SDL_FALSE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   235
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   236
    return SDL_TRUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   237
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   238
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   239
Uint32
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   240
SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   241
                           Uint32 Amask)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   242
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   243
    switch (bpp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   244
    case 8:
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   245
        if (Rmask == 0) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   246
            return SDL_PIXELFORMAT_INDEX8;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   247
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   248
        if (Rmask == 0xE0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   249
            Gmask == 0x1C &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   250
            Bmask == 0x03 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   251
            Amask == 0x00) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   252
            return SDL_PIXELFORMAT_RGB332;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   253
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   254
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   255
    case 12:
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   256
        if (Rmask == 0) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   257
            return SDL_PIXELFORMAT_RGB444;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   258
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   259
        if (Rmask == 0x0F00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   260
            Gmask == 0x00F0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   261
            Bmask == 0x000F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   262
            Amask == 0x0000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   263
            return SDL_PIXELFORMAT_RGB444;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   264
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   265
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   266
    case 15:
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   267
        if (Rmask == 0) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   268
            return SDL_PIXELFORMAT_RGB555;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   269
        }
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   270
        /* Fall through to 16-bit checks */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   271
    case 16:
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   272
        if (Rmask == 0) {
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   273
            return SDL_PIXELFORMAT_RGB565;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   274
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   275
        if (Rmask == 0x7C00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   276
            Gmask == 0x03E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   277
            Bmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   278
            Amask == 0x0000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   279
            return SDL_PIXELFORMAT_RGB555;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   280
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   281
        if (Rmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   282
            Gmask == 0x03E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   283
            Bmask == 0x7C00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   284
            Amask == 0x0000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   285
            return SDL_PIXELFORMAT_BGR555;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   286
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   287
        if (Rmask == 0x0F00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   288
            Gmask == 0x00F0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   289
            Bmask == 0x000F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   290
            Amask == 0xF000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   291
            return SDL_PIXELFORMAT_ARGB4444;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   292
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   293
        if (Rmask == 0xF000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   294
            Gmask == 0x0F00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   295
            Bmask == 0x00F0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   296
            Amask == 0x000F) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   297
            return SDL_PIXELFORMAT_RGBA4444;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   298
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   299
        if (Rmask == 0x000F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   300
            Gmask == 0x00F0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   301
            Bmask == 0x0F00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   302
            Amask == 0xF000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   303
            return SDL_PIXELFORMAT_ABGR4444;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   304
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   305
        if (Rmask == 0x00F0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   306
            Gmask == 0x0F00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   307
            Bmask == 0xF000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   308
            Amask == 0x000F) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   309
            return SDL_PIXELFORMAT_BGRA4444;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   310
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   311
        if (Rmask == 0x7C00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   312
            Gmask == 0x03E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   313
            Bmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   314
            Amask == 0x8000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   315
            return SDL_PIXELFORMAT_ARGB1555;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   316
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   317
        if (Rmask == 0xF800 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   318
            Gmask == 0x07C0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   319
            Bmask == 0x003E &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   320
            Amask == 0x0001) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   321
            return SDL_PIXELFORMAT_RGBA5551;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   322
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   323
        if (Rmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   324
            Gmask == 0x03E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   325
            Bmask == 0x7C00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   326
            Amask == 0x8000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   327
            return SDL_PIXELFORMAT_ABGR1555;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   328
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   329
        if (Rmask == 0x003E &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   330
            Gmask == 0x07C0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   331
            Bmask == 0xF800 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   332
            Amask == 0x0001) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   333
            return SDL_PIXELFORMAT_BGRA5551;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   334
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   335
        if (Rmask == 0xF800 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   336
            Gmask == 0x07E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   337
            Bmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   338
            Amask == 0x0000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   339
            return SDL_PIXELFORMAT_RGB565;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   340
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   341
        if (Rmask == 0x001F &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   342
            Gmask == 0x07E0 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   343
            Bmask == 0xF800 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   344
            Amask == 0x0000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   345
            return SDL_PIXELFORMAT_BGR565;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   346
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   347
        break;
3182
9f82979eaaf0 Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
   348
    case 24:
9f82979eaaf0 Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
   349
        switch (Rmask) {
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   350
        case 0:
3182
9f82979eaaf0 Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
   351
        case 0x00FF0000:
3597
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   352
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   353
            return SDL_PIXELFORMAT_RGB24;
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   354
#else
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   355
            return SDL_PIXELFORMAT_BGR24;
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   356
#endif
3182
9f82979eaaf0 Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
   357
        case 0x000000FF:
3597
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   358
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   359
            return SDL_PIXELFORMAT_BGR24;
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   360
#else
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   361
            return SDL_PIXELFORMAT_RGB24;
7dec3fe9b580 Fixed bug #912
Sam Lantinga <slouken@libsdl.org>
parents: 3557
diff changeset
   362
#endif
3182
9f82979eaaf0 Support for 24 bpp pixel formats has been added.
Mike Gorchak <lestat@i.com.ua>
parents: 3163
diff changeset
   363
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   364
    case 32:
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   365
        if (Rmask == 0) {
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   366
            return SDL_PIXELFORMAT_RGB888;
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   367
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   368
        if (Rmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   369
            Gmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   370
            Bmask == 0x000000FF &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   371
            Amask == 0x00000000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   372
            return SDL_PIXELFORMAT_RGB888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   373
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   374
        if (Rmask == 0x000000FF &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   375
            Gmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   376
            Bmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   377
            Amask == 0x00000000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   378
            return SDL_PIXELFORMAT_BGR888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   379
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   380
        if (Rmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   381
            Gmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   382
            Bmask == 0x000000FF &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   383
            Amask == 0xFF000000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   384
            return SDL_PIXELFORMAT_ARGB8888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   385
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   386
        if (Rmask == 0xFF000000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   387
            Gmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   388
            Bmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   389
            Amask == 0x000000FF) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   390
            return SDL_PIXELFORMAT_RGBA8888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   391
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   392
        if (Rmask == 0x000000FF &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   393
            Gmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   394
            Bmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   395
            Amask == 0xFF000000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   396
            return SDL_PIXELFORMAT_ABGR8888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   397
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   398
        if (Rmask == 0x0000FF00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   399
            Gmask == 0x00FF0000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   400
            Bmask == 0xFF000000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   401
            Amask == 0x000000FF) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   402
            return SDL_PIXELFORMAT_BGRA8888;
5350
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   403
        }
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   404
        if (Rmask == 0x3FF00000 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   405
            Gmask == 0x000FFC00 &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   406
            Bmask == 0x000003FF &&
95712d32f0ed Autogenerated full mask checks for pixel format match
Sam Lantinga <slouken@libsdl.org>
parents: 5295
diff changeset
   407
            Amask == 0xC0000000) {
5352
e0da15452037 Yes, it compiles now.
Sam Lantinga <slouken@libsdl.org>
parents: 5350
diff changeset
   408
            return SDL_PIXELFORMAT_ARGB2101010;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   409
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   410
    }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1920
diff changeset
   411
    return SDL_PIXELFORMAT_UNKNOWN;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   412
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   413
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   414
static SDL_PixelFormat *formats;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   415
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   416
SDL_PixelFormat *
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   417
SDL_AllocFormat(Uint32 pixel_format)
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   418
{
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   419
    SDL_PixelFormat *format;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   420
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   421
    /* Look it up in our list of previously allocated formats */
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   422
    for (format = formats; format; format = format->next) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   423
        if (pixel_format == format->format) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   424
            ++format->refcount;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   425
            return format;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   426
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   427
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   428
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   429
    /* Allocate an empty pixel format structure, and initialize it */
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   430
    format = SDL_malloc(sizeof(*format));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   431
    if (format == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   432
        SDL_OutOfMemory();
5433
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
   433
        return NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   434
    }
5433
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
   435
    if (SDL_InitFormat(format, pixel_format) < 0) {
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
   436
        SDL_free(format);
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
   437
        return NULL;
1b6eee840e26 Better error reporting in allocating a pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5432
diff changeset
   438
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   439
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   440
    if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   441
        /* Cache the RGB formats */
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   442
        format->next = formats;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   443
        formats = format;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   444
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   445
    return format;
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   446
}
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   447
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   448
int
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   449
SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format)
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   450
{
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   451
    int bpp;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   452
    Uint32 Rmask, Gmask, Bmask, Amask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   453
    Uint32 mask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   454
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   455
    if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   456
                                    &Rmask, &Gmask, &Bmask, &Amask)) {
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   457
        return -1;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   458
    }
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   459
2967
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   460
    /* Set up the format */
e4a469d6ddab Implemented SDL_SetWindowIcon(), with translucent icon support under X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   461
    SDL_zerop(format);
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   462
    format->format = pixel_format;
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   463
    format->BitsPerPixel = bpp;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   464
    format->BytesPerPixel = (bpp + 7) / 8;
5431
5369d8f32f08 Fixed initializing pixel format for indexed formats
Sam Lantinga <slouken@libsdl.org>
parents: 5352
diff changeset
   465
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   466
    format->Rmask = Rmask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   467
    format->Rshift = 0;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   468
    format->Rloss = 8;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   469
    if (Rmask) {
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   470
        for (mask = Rmask; !(mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   471
            ++format->Rshift;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   472
        for (; (mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   473
            --format->Rloss;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   474
    }
5431
5369d8f32f08 Fixed initializing pixel format for indexed formats
Sam Lantinga <slouken@libsdl.org>
parents: 5352
diff changeset
   475
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   476
    format->Gmask = Gmask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   477
    format->Gshift = 0;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   478
    format->Gloss = 8;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   479
    if (Gmask) {
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   480
        for (mask = Gmask; !(mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   481
            ++format->Gshift;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   482
        for (; (mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   483
            --format->Gloss;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   484
    }
5432
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   485
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   486
    format->Bmask = Bmask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   487
    format->Bshift = 0;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   488
    format->Bloss = 8;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   489
    if (Bmask) {
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   490
        for (mask = Bmask; !(mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   491
            ++format->Bshift;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   492
        for (; (mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   493
            --format->Bloss;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   494
    }
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   495
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   496
    format->Amask = Amask;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   497
    format->Ashift = 0;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   498
    format->Aloss = 8;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   499
    if (Amask) {
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   500
        for (mask = Amask; !(mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   501
            ++format->Ashift;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   502
        for (; (mask & 0x01); mask >>= 1)
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   503
            --format->Aloss;
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   504
    }
b3913347f1d7 Fixed garbage trying to create a FourCC pixel format.
Sam Lantinga <slouken@libsdl.org>
parents: 5431
diff changeset
   505
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   506
    format->palette = NULL;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   507
    format->refcount = 1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   508
    format->next = NULL;
1057
e9d23bb80140 Date: Mon, 02 May 2005 04:23:16 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 1027
diff changeset
   509
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   510
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   511
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   512
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   513
void
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   514
SDL_FreeFormat(SDL_PixelFormat *format)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   515
{
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   516
    SDL_PixelFormat *prev;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   517
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   518
    if (!format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   519
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   520
    }
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   521
    if (--format->refcount > 0) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   522
        return;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   523
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   524
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   525
    /* Remove this format from our list */
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   526
    if (format == formats) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   527
        formats = format->next;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   528
    } else if (formats) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   529
        for (prev = formats; prev->next; prev = prev->next) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   530
            if (prev->next == format) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   531
                prev->next = format->next;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   532
                break;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   533
            }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   534
        }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   535
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   536
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   537
    if (format->palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   538
        SDL_FreePalette(format->palette);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   539
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   540
    SDL_free(format);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   541
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   542
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
SDL_Palette *
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   544
SDL_AllocPalette(int ncolors)
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   545
{
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   546
    SDL_Palette *palette;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   547
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   548
    palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   549
    if (!palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   550
        SDL_OutOfMemory();
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   551
        return NULL;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   552
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   553
    palette->colors =
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   554
        (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   555
    if (!palette->colors) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   556
        SDL_free(palette);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   557
        return NULL;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   558
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   559
    palette->ncolors = ncolors;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   560
    palette->version = 1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   561
    palette->refcount = 1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   562
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   563
    SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors));
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   564
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   565
    return palette;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   566
}
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   567
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   568
int
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   569
SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette)
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   570
{
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   571
    if (!format) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   572
        SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format");
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   573
        return -1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   574
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   575
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   576
    if (palette && palette->ncolors != (1 << format->BitsPerPixel)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   577
        SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   578
        return -1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   579
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   580
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   581
    if (format->palette == palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   582
        return 0;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   583
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   584
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   585
    if (format->palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   586
        SDL_FreePalette(format->palette);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   587
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   588
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   589
    format->palette = palette;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   590
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   591
    if (format->palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   592
        ++format->palette->refcount;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   593
    }
5295
b88d05603e4b Patch from Ken Rogoway:
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   594
b88d05603e4b Patch from Ken Rogoway:
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
   595
    return 0;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   596
}
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   597
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   598
int
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   599
SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors,
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   600
                     int firstcolor, int ncolors)
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   601
{
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   602
    int status = 0;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   603
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   604
    /* Verify the parameters */
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   605
    if (!palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   606
        return -1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   607
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   608
    if (ncolors > (palette->ncolors - firstcolor)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   609
        ncolors = (palette->ncolors - firstcolor);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   610
        status = -1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   611
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   612
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   613
    if (colors != (palette->colors + firstcolor)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   614
        SDL_memcpy(palette->colors + firstcolor, colors,
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   615
                   ncolors * sizeof(*colors));
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   616
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   617
    ++palette->version;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   618
    if (!palette->version) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   619
        palette->version = 1;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   620
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   621
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   622
    return status;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   623
}
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   624
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   625
void
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   626
SDL_FreePalette(SDL_Palette * palette)
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   627
{
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   628
    if (!palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   629
        return;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   630
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   631
    if (--palette->refcount > 0) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   632
        return;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   633
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   634
    if (palette->colors) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   635
        SDL_free(palette->colors);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   636
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   637
    SDL_free(palette);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   638
}
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   639
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   640
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   641
 * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   642
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   643
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   644
SDL_DitherColors(SDL_Color * colors, int bpp)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   645
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   646
    int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   647
    if (bpp != 8)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   648
        return;                 /* only 8bpp supported right now */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   649
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   650
    for (i = 0; i < 256; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   651
        int r, g, b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   652
        /* map each bit field to the full [0, 255] interval,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   653
           so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   654
        r = i & 0xe0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   655
        r |= r >> 3 | r >> 6;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   656
        colors[i].r = r;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   657
        g = (i << 3) & 0xe0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   658
        g |= g >> 3 | g >> 6;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   659
        colors[i].g = g;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   660
        b = i & 0x3;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   661
        b |= b << 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   662
        b |= b << 4;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   663
        colors[i].b = b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   664
        colors[i].unused = SDL_ALPHA_OPAQUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   665
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   666
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   667
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   668
/* 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   669
 * Calculate the pad-aligned scanline width of a surface
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   670
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   671
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   672
SDL_CalculatePitch(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   673
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   674
    int pitch;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   675
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   676
    /* Surface should be 4-byte aligned for speed */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   677
    pitch = surface->w * surface->format->BytesPerPixel;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   678
    switch (surface->format->BitsPerPixel) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   679
    case 1:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   680
        pitch = (pitch + 7) / 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   681
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   682
    case 4:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   683
        pitch = (pitch + 1) / 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   684
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   685
    default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   686
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   687
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   688
    pitch = (pitch + 3) & ~3;   /* 4-byte aligning */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   689
    return (pitch);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   690
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   691
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   692
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   693
 * Match an RGB value to a particular palette index
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   694
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   695
Uint8
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   696
SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   697
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   698
    /* Do colorspace distance matching */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   699
    unsigned int smallest;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   700
    unsigned int distance;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   701
    int rd, gd, bd;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   702
    int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   703
    Uint8 pixel = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   704
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   705
    smallest = ~0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   706
    for (i = 0; i < pal->ncolors; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   707
        rd = pal->colors[i].r - r;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   708
        gd = pal->colors[i].g - g;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   709
        bd = pal->colors[i].b - b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   710
        distance = (rd * rd) + (gd * gd) + (bd * bd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   711
        if (distance < smallest) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   712
            pixel = i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   713
            if (distance == 0) {        /* Perfect match! */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   714
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   715
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   716
            smallest = distance;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   717
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   718
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   719
    return (pixel);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   720
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
/* Find the opaque pixel value corresponding to an RGB triple */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   723
Uint32
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   724
SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   725
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   726
    if (format->palette == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   727
        return (r >> format->Rloss) << format->Rshift
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   728
            | (g >> format->Gloss) << format->Gshift
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   729
            | (b >> format->Bloss) << format->Bshift | format->Amask;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   730
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   731
        return SDL_FindColor(format->palette, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   732
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   733
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   734
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
/* Find the pixel value corresponding to an RGBA quadruple */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   736
Uint32
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   737
SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b,
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   738
            Uint8 a)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   739
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   740
    if (format->palette == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   741
        return (r >> format->Rloss) << format->Rshift
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   742
            | (g >> format->Gloss) << format->Gshift
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   743
            | (b >> format->Bloss) << format->Bshift
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   744
            | ((a >> format->Aloss) << format->Ashift & format->Amask);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   745
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   746
        return SDL_FindColor(format->palette, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   747
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   748
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   749
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   750
void
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   751
SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   752
           Uint8 * b)
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   753
{
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   754
    if (format->palette == NULL) {
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   755
        /*
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   756
         * This makes sure that the result is mapped to the
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   757
         * interval [0..255], and the maximum value for each
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   758
         * component is 255. This is important to make sure
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   759
         * that white is indeed reported as (255, 255, 255).
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   760
         * This only works for RGB bit fields at least 4 bit
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   761
         * wide, which is almost always the case.
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   762
         */
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   763
        unsigned v;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   764
        v = (pixel & format->Rmask) >> format->Rshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   765
        *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   766
        v = (pixel & format->Gmask) >> format->Gshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   767
        *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   768
        v = (pixel & format->Bmask) >> format->Bshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   769
        *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   770
    } else {
5436
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   771
        if (pixel < format->palette->ncolors) {
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   772
            *r = format->palette->colors[pixel].r;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   773
            *g = format->palette->colors[pixel].g;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   774
            *b = format->palette->colors[pixel].b;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   775
        } else {
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   776
            *r = *g = *b = 0;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   777
        }
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   778
    }
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   779
}
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   780
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   781
void
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   782
SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   783
            Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   784
{
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   785
    if (format->palette == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   786
        /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   787
         * This makes sure that the result is mapped to the
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   788
         * interval [0..255], and the maximum value for each
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   789
         * component is 255. This is important to make sure
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   790
         * that white is indeed reported as (255, 255, 255),
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   791
         * and that opaque alpha is 255.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   792
         * This only works for RGB bit fields at least 4 bit
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   793
         * wide, which is almost always the case.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   794
         */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   795
        unsigned v;
2275
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   796
        v = (pixel & format->Rmask) >> format->Rshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   797
        *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   798
        v = (pixel & format->Gmask) >> format->Gshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   799
        *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   800
        v = (pixel & format->Bmask) >> format->Bshift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   801
        *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   802
        if (format->Amask) {
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   803
            v = (pixel & format->Amask) >> format->Ashift;
12ea0fdc0df2 Split out the SDL_rect and SDL_surface functions into their own headers.
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   804
            *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1)));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   805
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   806
            *a = SDL_ALPHA_OPAQUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   807
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   808
    } else {
5436
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   809
        if (pixel < format->palette->ncolors) {
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   810
            *r = format->palette->colors[pixel].r;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   811
            *g = format->palette->colors[pixel].g;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   812
            *b = format->palette->colors[pixel].b;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   813
            *a = SDL_ALPHA_OPAQUE;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   814
        } else {
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   815
            *r = *g = *b = *a = 0;
29977c050731 Fixed memory corruption with invalid pixel values.
Sam Lantinga <slouken@libsdl.org>
parents: 5433
diff changeset
   816
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   817
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   818
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   819
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   820
/* Map from Palette to Palette */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   821
static Uint8 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   822
Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   823
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   824
    Uint8 *map;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   825
    int i;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   826
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   827
    if (identical) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   828
        if (src->ncolors <= dst->ncolors) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   829
            /* If an identical palette, no need to map */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   830
            if (src == dst
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   831
                ||
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   832
                (SDL_memcmp
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   833
                 (src->colors, dst->colors,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   834
                  src->ncolors * sizeof(SDL_Color)) == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   835
                *identical = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   836
                return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   837
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   838
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   839
        *identical = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   840
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   841
    map = (Uint8 *) SDL_malloc(src->ncolors);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   842
    if (map == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   843
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   844
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   845
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   846
    for (i = 0; i < src->ncolors; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   847
        map[i] = SDL_FindColor(dst,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   848
                               src->colors[i].r, src->colors[i].g,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   849
                               src->colors[i].b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   850
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   851
    return (map);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   852
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   853
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   854
/* Map from Palette to BitField */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   855
static Uint8 *
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   856
Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   857
        SDL_PixelFormat * dst)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   858
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   859
    Uint8 *map;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   860
    int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   861
    int bpp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   862
    SDL_Palette *pal = src->palette;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   863
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   864
    bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   865
    map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   866
    if (map == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   867
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   868
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   869
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   870
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   871
    /* We memory copy to the pixel map so the endianness is preserved */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   872
    for (i = 0; i < pal->ncolors; ++i) {
2257
340942cfda48 Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   873
        Uint8 A = Amod;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   874
        Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   875
        Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   876
        Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
2257
340942cfda48 Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents: 2120
diff changeset
   877
        ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   878
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   879
    return (map);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   881
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   882
/* Map from BitField to Dithered-Palette to Palette */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   883
static Uint8 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   884
MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   885
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   886
    /* Generate a 256 color dither palette */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   887
    SDL_Palette dithered;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   888
    SDL_Color colors[256];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   889
    SDL_Palette *pal = dst->palette;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   891
    dithered.ncolors = 256;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   892
    SDL_DitherColors(colors, 8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   893
    dithered.colors = colors;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   894
    return (Map1to1(&dithered, pal, identical));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   895
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   896
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   897
SDL_BlitMap *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   898
SDL_AllocBlitMap(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   900
    SDL_BlitMap *map;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   901
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   902
    /* Allocate the empty map */
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   903
    map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   904
    if (map == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   905
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   906
        return (NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   907
    }
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   908
    map->info.r = 0xFF;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   909
    map->info.g = 0xFF;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   910
    map->info.b = 0xFF;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   911
    map->info.a = 0xFF;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   912
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   913
    /* It's ready to go */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   914
    return (map);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   916
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   917
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   918
SDL_InvalidateMap(SDL_BlitMap * map)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   919
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   920
    if (!map) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   921
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   922
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   923
    map->dst = NULL;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   924
    map->palette_version = 0;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   925
    if (map->info.table) {
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   926
        SDL_free(map->info.table);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   927
        map->info.table = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   928
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   929
}
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2275
diff changeset
   930
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   931
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   932
SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   934
    SDL_PixelFormat *srcfmt;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   935
    SDL_PixelFormat *dstfmt;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   936
    SDL_BlitMap *map;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   937
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   938
    /* Clear out any previous mapping */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   939
    map = src->map;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   940
    if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   941
        SDL_UnRLESurface(src, 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   942
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   943
    SDL_InvalidateMap(map);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   944
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   945
    /* Figure out what kind of mapping we're doing */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   946
    map->identity = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   947
    srcfmt = src->format;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   948
    dstfmt = dst->format;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   949
    if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   950
        if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   951
            /* Palette --> Palette */
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   952
            map->info.table =
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   953
                Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   954
            if (!map->identity) {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   955
                if (map->info.table == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   956
                    return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   957
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   958
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   959
            if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   960
                map->identity = 0;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   961
        } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   962
            /* Palette --> BitField */
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   963
            map->info.table =
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   964
                Map1toN(srcfmt, src->map->info.r, src->map->info.g,
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   965
                        src->map->info.b, src->map->info.a, dstfmt);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   966
            if (map->info.table == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   967
                return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   968
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   969
        }
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   970
    } else {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   971
        if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   972
            /* BitField --> Palette */
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   973
            map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   974
            if (!map->identity) {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   975
                if (map->info.table == NULL) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   976
                    return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   977
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   978
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   979
            map->identity = 0;  /* Don't optimize to copy */
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   980
        } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   981
            /* BitField --> BitField */
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   982
            if (srcfmt == dstfmt) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   983
                map->identity = 1;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   984
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   985
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   986
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   987
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   988
    map->dst = dst;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   989
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   990
    if (dstfmt->palette) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   991
        map->palette_version = dstfmt->palette->version;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   992
    } else {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   993
        map->palette_version = 0;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   994
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   995
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   996
    /* Choose your blitters wisely */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   997
    return (SDL_CalculateBlit(src));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   998
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
   999
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1000
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1001
SDL_FreeBlitMap(SDL_BlitMap * map)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1003
    if (map) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1004
        SDL_InvalidateMap(map);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1005
        SDL_free(map);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1006
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1007
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1008
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1557
diff changeset
  1009
/* vi: set ts=4 sw=4 expandtab: */