src/video/SDL_surface.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 31 Oct 2011 02:44:21 -0400
changeset 6041 69d7539ff51f
parent 5535 96594ac5fd1a
child 6138 4c64952a58fb
permissions -rw-r--r--
SDL_ConvertPixels() returns 0 on success
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     2
  Simple DirectMedia Layer
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5515
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    21
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
#include "SDL_video.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    24
#include "SDL_compat.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_RLEaccel_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include "SDL_pixels_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
1251
86d0d01290ea Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
    30
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
/* Public routines */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
 * Create an empty RGB surface of the appropriate depth
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    35
SDL_Surface *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    36
SDL_CreateRGBSurface(Uint32 flags,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    37
                     int width, int height, int depth,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    38
                     Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    40
    SDL_Surface *surface;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    41
    Uint32 format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
2807
365fe1a2aad5 The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents: 2787
diff changeset
    43
    /* The flags are no longer used, make the compiler happy */
4461
39c22a953456 Make the compiler even happier
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    44
    (void)flags;
2807
365fe1a2aad5 The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents: 2787
diff changeset
    45
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    46
    /* Get the pixel format */
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    47
    format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    48
    if (format == SDL_PIXELFORMAT_UNKNOWN) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    49
        SDL_SetError("Unknown pixel format");
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    50
        return NULL;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    51
    }
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    52
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    53
    /* Allocate the surface */
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
    54
    surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    55
    if (surface == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    56
        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: 1456
diff changeset
    57
        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: 1456
diff changeset
    58
    }
940
bb1588ebe47b Date: Sat, 10 Jul 2004 21:02:33 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 915
diff changeset
    59
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    60
    surface->format = SDL_AllocFormat(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: 1456
diff changeset
    61
    if (!surface->format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    62
        SDL_FreeSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    63
        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: 1456
diff changeset
    64
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    65
    surface->w = width;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    66
    surface->h = height;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    67
    surface->pitch = SDL_CalculatePitch(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    68
    SDL_SetClipRect(surface, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    69
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    70
    if (SDL_ISPIXELFORMAT_INDEXED(surface->format->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: 1456
diff changeset
    71
        SDL_Palette *palette =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    72
            SDL_AllocPalette((1 << 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: 1456
diff changeset
    73
        if (!palette) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    74
            SDL_FreeSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    75
            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: 1456
diff changeset
    76
        }
5438
b705640cb34a Fixed bitmap order interpretation; SDL defaults to MSB ordering so a bitstream corresponds to a pixel stream.
Sam Lantinga <slouken@libsdl.org>
parents: 5375
diff changeset
    77
        if (palette->ncolors == 2) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    78
            /* Create a black and white bitmap palette */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    79
            palette->colors[0].r = 0xFF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    80
            palette->colors[0].g = 0xFF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    81
            palette->colors[0].b = 0xFF;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    82
            palette->colors[1].r = 0x00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    83
            palette->colors[1].g = 0x00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    84
            palette->colors[1].b = 0x00;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    85
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    86
        SDL_SetSurfacePalette(surface, palette);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    87
        SDL_FreePalette(palette);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    88
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    90
    /* Get the pixels */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    91
    if (surface->w && surface->h) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    92
        surface->pixels = SDL_malloc(surface->h * surface->pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    93
        if (!surface->pixels) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    94
            SDL_FreeSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    95
            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: 1456
diff changeset
    96
            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: 1456
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: 1456
diff changeset
    98
        /* This is important for bitmaps */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
    99
        SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   100
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   102
    /* Allocate an empty mapping */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   103
    surface->map = SDL_AllocBlitMap();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   104
    if (!surface->map) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   105
        SDL_FreeSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   106
        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: 1456
diff changeset
   107
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   108
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   109
    /* By default surface with an alpha mask are set up for blending */
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   110
    if (Amask) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   111
        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   112
    }
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   113
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   114
    /* The surface is 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: 1456
diff changeset
   115
    surface->refcount = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   116
    return surface;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   118
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
 * Create an RGB surface from an existing memory buffer
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   122
SDL_Surface *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   123
SDL_CreateRGBSurfaceFrom(void *pixels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   124
                         int width, int height, int depth, int pitch,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   125
                         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: 1456
diff changeset
   126
                         Uint32 Amask)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   127
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   128
    SDL_Surface *surface;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   129
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   130
    surface =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   131
        SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   132
    if (surface != NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   133
        surface->flags |= SDL_PREALLOC;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   134
        surface->pixels = pixels;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   135
        surface->w = width;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   136
        surface->h = height;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   137
        surface->pitch = pitch;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   138
        SDL_SetClipRect(surface, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   139
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   140
    return surface;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   141
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   142
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   143
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   144
SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   145
{
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   146
    if (!surface) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   147
        SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   148
        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: 1456
diff changeset
   149
    }
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   150
    return SDL_SetPixelFormatPalette(surface->format, 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: 1456
diff changeset
   151
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   152
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   153
int
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   154
SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
{
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   156
    int flags;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   158
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   159
        return -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: 1456
diff changeset
   160
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   162
    flags = surface->map->info.flags;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   163
    if (flag) {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   164
        surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   165
    } else {
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   166
        surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   167
    }
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   168
    if (surface->map->info.flags != flags) {
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   169
        SDL_InvalidateMap(surface->map);
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   170
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   171
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   173
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   174
int
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3436
diff changeset
   175
SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
{
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   177
    int flags;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   179
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   180
        return -1;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   181
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   182
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   183
    if (flag & SDL_RLEACCEL) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   184
        SDL_SetSurfaceRLE(surface, 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: 1456
diff changeset
   185
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   187
    flags = surface->map->info.flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   188
    if (flag) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   189
        surface->map->info.flags |= SDL_COPY_COLORKEY;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   190
        surface->map->info.colorkey = key;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   191
    } else {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   192
        surface->map->info.flags &= ~SDL_COPY_COLORKEY;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   193
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   194
    if (surface->map->info.flags != flags) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   195
        SDL_InvalidateMap(surface->map);
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   196
    }
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   197
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   198
    /* Compatibility mode */
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   199
    if (surface->map->info.flags & SDL_COPY_COLORKEY) {
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   200
        surface->flags |= SDL_SRCCOLORKEY;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   201
    } else {
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   202
        surface->flags &= ~SDL_SRCCOLORKEY;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   203
    }
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   204
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   205
    return 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   206
}
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   207
3103
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   208
int
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   209
SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   210
{
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   211
    if (!surface) {
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   212
        return -1;
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   213
    }
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   214
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   215
    if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   216
        return -1;
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   217
    }
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   218
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   219
    if (key) {
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   220
        *key = surface->map->info.colorkey;
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   221
    }
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   222
    return 0;
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   223
}
7be21a78777e Added SDL_GetColorKey()
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   224
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   225
/* This is a fairly slow function to switch from colorkey to alpha */
2787
93764fe8601a It turns out both the software and the OpenGL renderer had the same problem.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
   226
static void
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   227
SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   228
{
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   229
    int x, y;
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   230
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   231
    if (!surface) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   232
        return;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   233
    }
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   234
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   235
    if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   236
        !surface->format->Amask) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   237
        return;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   238
    }
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   239
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   240
    SDL_LockSurface(surface);
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   241
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   242
    switch (surface->format->BytesPerPixel) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   243
    case 2:
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   244
        {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   245
            Uint16 *row, *spot;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   246
            Uint16 ckey = (Uint16) surface->map->info.colorkey;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   247
            Uint16 mask = (Uint16) (~surface->format->Amask);
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   248
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   249
            row = (Uint16 *) surface->pixels;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   250
            for (y = surface->h; y--;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   251
                spot = row;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   252
                for (x = surface->w; x--;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   253
                    if (*spot == ckey) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   254
                        *spot &= mask;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   255
                    }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   256
                    ++spot;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   257
                }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   258
                row += surface->pitch / 2;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   259
            }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   260
        }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   261
        break;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   262
    case 3:
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   263
        /* FIXME */
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   264
        break;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   265
    case 4:
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   266
        {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   267
            Uint32 *row, *spot;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   268
            Uint32 ckey = surface->map->info.colorkey;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   269
            Uint32 mask = ~surface->format->Amask;
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   270
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   271
            row = (Uint32 *) surface->pixels;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   272
            for (y = surface->h; y--;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   273
                spot = row;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   274
                for (x = surface->w; x--;) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   275
                    if (*spot == ckey) {
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   276
                        *spot &= mask;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   277
                    }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   278
                    ++spot;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   279
                }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   280
                row += surface->pitch / 4;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   281
            }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   282
        }
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   283
        break;
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   284
    }
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   285
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   286
    SDL_UnlockSurface(surface);
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   287
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2785
diff changeset
   288
    SDL_SetColorKey(surface, 0, 0);
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   289
    SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
2785
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   290
}
fa1095d42a5b Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
   291
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   292
int
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   293
SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   294
{
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   295
    int flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   296
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   297
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   298
        return -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: 1456
diff changeset
   299
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   300
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   301
    surface->map->info.r = r;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   302
    surface->map->info.g = g;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   303
    surface->map->info.b = b;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   304
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   305
    flags = surface->map->info.flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   306
    if (r != 0xFF || g != 0xFF || b != 0xFF) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   307
        surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   308
    } else {
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   309
        surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   310
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   311
    if (surface->map->info.flags != flags) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   312
        SDL_InvalidateMap(surface->map);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   313
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   314
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   315
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   316
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   317
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   318
int
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   319
SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
   320
{
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   321
    if (!surface) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   322
        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: 1456
diff changeset
   323
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   324
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   325
    if (r) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   326
        *r = surface->map->info.r;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   327
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   328
    if (g) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   329
        *g = surface->map->info.g;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   330
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   331
    if (b) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   332
        *b = surface->map->info.b;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   333
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   334
    return 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   335
}
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   336
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   337
int
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   338
SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   339
{
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   340
    int flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   341
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   342
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   343
        return -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: 1456
diff changeset
   344
    }
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
   345
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   346
    surface->map->info.a = alpha;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   347
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   348
    flags = surface->map->info.flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   349
    if (alpha != 0xFF) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   350
        surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   351
    } else {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   352
        surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   353
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   354
    if (surface->map->info.flags != flags) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   355
        SDL_InvalidateMap(surface->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: 1456
diff changeset
   356
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   357
    return 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   358
}
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   359
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   360
int
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   361
SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   362
{
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   363
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   364
        return -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: 1456
diff changeset
   365
    }
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   366
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   367
    if (alpha) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   368
        *alpha = surface->map->info.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: 1456
diff changeset
   369
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   370
    return 0;
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
   371
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   372
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   373
int
4929
aa8888658021 Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents: 4491
diff changeset
   374
SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode)
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   375
{
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   376
    int flags, status;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   377
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   378
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   379
        return -1;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   380
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   381
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   382
    status = 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   383
    flags = surface->map->info.flags;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   384
    surface->map->info.flags &=
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   385
        ~(SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   386
    switch (blendMode) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   387
    case SDL_BLENDMODE_NONE:
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   388
        break;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   389
    case SDL_BLENDMODE_BLEND:
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   390
        surface->map->info.flags |= SDL_COPY_BLEND;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   391
        break;
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   392
    case SDL_BLENDMODE_ADD:
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   393
        surface->map->info.flags |= SDL_COPY_ADD;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   394
        break;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   395
    case SDL_BLENDMODE_MOD:
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   396
        surface->map->info.flags |= SDL_COPY_MOD;
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   397
        break;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   398
    default:
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   399
        SDL_Unsupported();
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   400
        status = -1;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   401
        break;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   402
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   403
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   404
    if (surface->map->info.flags != flags) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   405
        SDL_InvalidateMap(surface->map);
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   406
    }
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   407
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   408
    /* Compatibility mode */
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   409
    if (surface->map->info.flags & SDL_COPY_BLEND) {
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   410
        surface->flags |= SDL_SRCALPHA;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   411
    } else {
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   412
        surface->flags &= ~SDL_SRCALPHA;
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   413
    }
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   414
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   415
    return status;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   416
}
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   417
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   418
int
4929
aa8888658021 Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents: 4491
diff changeset
   419
SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode)
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   420
{
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   421
    if (!surface) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   422
        return -1;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   423
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   424
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   425
    if (!blendMode) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   426
        return 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   427
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   428
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   429
    switch (surface->map->
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   430
            info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   431
    case SDL_COPY_BLEND:
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   432
        *blendMode = SDL_BLENDMODE_BLEND;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   433
        break;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   434
    case SDL_COPY_ADD:
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   435
        *blendMode = SDL_BLENDMODE_ADD;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   436
        break;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   437
    case SDL_COPY_MOD:
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   438
        *blendMode = SDL_BLENDMODE_MOD;
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   439
        break;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   440
    default:
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   441
        *blendMode = SDL_BLENDMODE_NONE;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   442
        break;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   443
    }
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   444
    return 0;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   445
}
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   446
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   447
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: 1456
diff changeset
   448
SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   449
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   450
    SDL_Rect full_rect;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   451
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   452
    /* Don't do anything if there's no surface to act on */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   453
    if (!surface) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   454
        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: 1456
diff changeset
   455
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   456
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   457
    /* Set up the full surface rectangle */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   458
    full_rect.x = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   459
    full_rect.y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   460
    full_rect.w = surface->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   461
    full_rect.h = surface->h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   462
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   463
    /* Set the clipping rectangle */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   464
    if (!rect) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   465
        surface->clip_rect = full_rect;
4966
a130bc2f0a18 Fixed return value
Sam Lantinga <slouken@libsdl.org>
parents: 4949
diff changeset
   466
        return SDL_TRUE;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   467
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   468
    return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   469
}
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   470
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   471
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   472
SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   473
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   474
    if (surface && rect) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   475
        *rect = surface->clip_rect;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   476
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   477
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   478
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   479
/* 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   480
 * Set up a blit between two surfaces -- split into three parts:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   481
 * The upper part, SDL_UpperBlit(), performs clipping and rectangle 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   482
 * verification.  The lower part is a pointer to a low level
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   483
 * accelerated blitting function.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   484
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   485
 * These parts are separated out and each used internally by this 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   486
 * library in the optimimum places.  They are exported so that if
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   487
 * you know exactly what you are doing, you can optimize your code
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   488
 * by calling the one(s) you need.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   489
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   490
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   491
SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   492
              SDL_Surface * dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   493
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   494
    /* Check to make sure the blit mapping is valid */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   495
    if ((src->map->dst != dst) ||
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   496
        (dst->format->palette &&
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   497
         src->map->palette_version != dst->format->palette->version)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   498
        if (SDL_MapSurface(src, dst) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   499
            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: 1456
diff changeset
   500
        }
2328
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2267
diff changeset
   501
        /* just here for debugging */
2329
c1a390f6a819 ran make indent
Bob Pendleton <bob@pendleton.com>
parents: 2328
diff changeset
   502
/*         printf */
c1a390f6a819 ran make indent
Bob Pendleton <bob@pendleton.com>
parents: 2328
diff changeset
   503
/*             ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
c1a390f6a819 ran make indent
Bob Pendleton <bob@pendleton.com>
parents: 2328
diff changeset
   504
/*              src, dst->flags, src->map->info.flags, dst, dst->flags, */
c1a390f6a819 ran make indent
Bob Pendleton <bob@pendleton.com>
parents: 2328
diff changeset
   505
/*              dst->map->info.flags, src->map->blit); */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   506
    }
2257
340942cfda48 Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents: 2253
diff changeset
   507
    return (src->map->blit(src, srcrect, dst, dstrect));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   508
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   510
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   511
int
4949
68da5a234bba The source rectangle isn't modified in SDL_UpperBlit
Sam Lantinga <slouken@libsdl.org>
parents: 4929
diff changeset
   512
SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   513
              SDL_Surface * dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   514
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   515
    SDL_Rect fulldst;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   516
    int srcx, srcy, w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   517
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   518
    /* Make sure the surfaces aren't locked */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   519
    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: 1456
diff changeset
   520
        SDL_SetError("SDL_UpperBlit: passed a NULL surface");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   521
        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: 1456
diff changeset
   522
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   523
    if (src->locked || dst->locked) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   524
        SDL_SetError("Surfaces must not be locked during blit");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   525
        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: 1456
diff changeset
   526
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   527
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   528
    /* If the destination rectangle is NULL, use the entire dest surface */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   529
    if (dstrect == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   530
        fulldst.x = fulldst.y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   531
        dstrect = &fulldst;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   532
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   533
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   534
    /* clip the source rectangle to the source surface */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   535
    if (srcrect) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   536
        int maxw, maxh;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   537
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   538
        srcx = srcrect->x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   539
        w = srcrect->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   540
        if (srcx < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   541
            w += srcx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   542
            dstrect->x -= srcx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   543
            srcx = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   544
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   545
        maxw = src->w - srcx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   546
        if (maxw < w)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   547
            w = maxw;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   548
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   549
        srcy = srcrect->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   550
        h = srcrect->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   551
        if (srcy < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   552
            h += srcy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   553
            dstrect->y -= srcy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   554
            srcy = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   555
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   556
        maxh = src->h - srcy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   557
        if (maxh < h)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   558
            h = maxh;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   559
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   560
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   561
        srcx = srcy = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   562
        w = src->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   563
        h = src->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   564
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   565
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   566
    /* clip the destination rectangle against the clip rectangle */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   567
    {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   568
        SDL_Rect *clip = &dst->clip_rect;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   569
        int dx, dy;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   570
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   571
        dx = clip->x - dstrect->x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   572
        if (dx > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   573
            w -= dx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   574
            dstrect->x += dx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   575
            srcx += dx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   576
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   577
        dx = dstrect->x + w - clip->x - clip->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   578
        if (dx > 0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   579
            w -= dx;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   580
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   581
        dy = clip->y - dstrect->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   582
        if (dy > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   583
            h -= dy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   584
            dstrect->y += dy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   585
            srcy += dy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   586
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   587
        dy = dstrect->y + h - clip->y - clip->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   588
        if (dy > 0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   589
            h -= dy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   590
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   591
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   592
    if (w > 0 && h > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   593
        SDL_Rect sr;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   594
        sr.x = srcx;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   595
        sr.y = srcy;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   596
        sr.w = dstrect->w = w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   597
        sr.h = dstrect->h = h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   598
        return SDL_LowerBlit(src, &sr, dst, dstrect);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   599
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   600
    dstrect->w = dstrect->h = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   601
    return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   602
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   603
5296
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   604
int
5499
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   605
SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   606
              SDL_Surface * dst, SDL_Rect * dstrect)
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   607
{
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   608
    SDL_Rect final_src, final_dst, fulldst;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   609
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   610
    /* Make sure the surfaces aren't locked */
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   611
    if (!src || !dst) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   612
        SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   613
        return (-1);
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   614
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   615
    if (src->locked || dst->locked) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   616
        SDL_SetError("Surfaces must not be locked during blit");
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   617
        return (-1);
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   618
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   619
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   620
    /* If the destination rectangle is NULL, use the entire dest surface */
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   621
    if (dstrect == NULL) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   622
        fulldst.x = fulldst.y = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   623
        dstrect = &fulldst;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   624
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   625
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   626
    /* clip the source rectangle to the source surface */
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   627
    if (srcrect) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   628
        int maxw, maxh;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   629
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   630
        final_src.x = srcrect->x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   631
        final_src.w = srcrect->w;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   632
        if (final_src.x < 0) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   633
            final_src.w += final_src.x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   634
            final_src.x = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   635
        }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   636
        maxw = src->w - final_src.x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   637
        if (maxw < final_src.w)
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   638
            final_src.w = maxw;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   639
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   640
        final_src.y = srcrect->y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   641
        final_src.h = srcrect->h;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   642
        if (final_src.y < 0) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   643
            final_src.h += final_src.y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   644
            final_src.y = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   645
        }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   646
        maxh = src->h - final_src.y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   647
        if (maxh < final_src.h)
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   648
            final_src.h = maxh;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   649
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   650
    } else {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   651
        final_src.x = final_src.y = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   652
        final_src.w = src->w;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   653
        final_src.h = src->h;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   654
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   655
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   656
    /* clip the destination rectangle against the clip rectangle */
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   657
    if (dstrect) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   658
        int maxw, maxh;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   659
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   660
        final_dst.x = dstrect->x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   661
        final_dst.w = dstrect->w;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   662
        if (final_dst.x < 0) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   663
            final_dst.w += final_dst.x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   664
            final_dst.x = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   665
        }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   666
        maxw = dst->w - final_dst.x;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   667
        if (maxw < final_dst.w)
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   668
            final_dst.w = maxw;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   669
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   670
        final_dst.y = dstrect->y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   671
        final_dst.h = dstrect->h;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   672
        if (final_dst.y < 0) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   673
            final_dst.h += final_dst.y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   674
            final_dst.y = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   675
        }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   676
        maxh = dst->h - final_dst.y;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   677
        if (maxh < final_dst.h)
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   678
            final_dst.h = maxh;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   679
    } else {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   680
        final_dst.x = final_dst.y = 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   681
        final_dst.w = dst->w;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   682
        final_dst.h = dst->h;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   683
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   684
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   685
    if (final_dst.w > 0 && final_dst.h > 0) {
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   686
        return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   687
    }
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   688
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   689
    return 0;
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   690
}
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   691
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   692
/**
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   693
 *  This is a semi-private blit function and it performs low-level surface
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   694
 *  scaled blitting only.
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   695
 */
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   696
int
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   697
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
2b8e6d1e3817 Split SDL_BlitScaled into SDL_UpperBlitScaled and SDL_LowerBlitScaled.
Ken Rogoway <ken@rogoway.com>
parents: 5438
diff changeset
   698
                SDL_Surface * dst, SDL_Rect * dstrect)
5296
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   699
{
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   700
    /* Save off the original dst width, height */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   701
    int dstW = dstrect->w;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   702
    int dstH = dstrect->h;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   703
    SDL_Rect final_dst = *dstrect;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   704
    SDL_Rect final_src = *srcrect;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   705
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   706
    /* Clip the dst surface to the dstrect */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   707
    SDL_SetClipRect( dst, &final_dst );
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   708
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   709
    /* Did the dst width change? */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   710
    if ( dstW != dst->clip_rect.w ) {
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   711
        /* scale the src width appropriately */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   712
        final_src.w = final_src.w * dst->clip_rect.w / dstW;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   713
    }
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   714
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   715
    /* Did the dst height change? */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   716
    if ( dstH != dst->clip_rect.h ) {
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   717
        /* scale the src width appropriately */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   718
        final_src.h = final_src.h * dst->clip_rect.h / dstH;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   719
    }
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   720
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   721
    /* Clip the src surface to the srcrect */
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   722
    SDL_SetClipRect( src, &final_src );
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   723
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   724
    src->map->info.flags |= SDL_COPY_NEAREST;
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   725
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   726
    if ( src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   727
        return SDL_SoftStretch( src, &final_src, dst, &final_dst );
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   728
    } else {
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   729
        return SDL_LowerBlit( src, &final_src, dst, &final_dst );
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   730
    }
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   731
}
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   732
48067bfc300c Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents: 5288
diff changeset
   733
/*
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   734
 * Lock a surface to directly access the pixels
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   736
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   737
SDL_LockSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   738
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   739
    if (!surface->locked) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   740
        /* Perform the lock */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   741
        if (surface->flags & 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: 1456
diff changeset
   742
            SDL_UnRLESurface(surface, 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   743
            surface->flags |= SDL_RLEACCEL;     /* save accel'd state */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   744
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   745
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   746
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   747
    /* Increment the surface lock count, for recursive locks */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   748
    ++surface->locked;
0
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: 1456
diff changeset
   750
    /* 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: 1456
diff changeset
   751
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   752
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   753
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   754
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   755
 * Unlock a previously locked surface
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   756
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   757
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   758
SDL_UnlockSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   759
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   760
    /* Only perform an unlock if we are locked */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   761
    if (!surface->locked || (--surface->locked > 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   762
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   763
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   764
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   765
    /* Update RLE encoded surface with new data */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   766
    if ((surface->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: 1456
diff changeset
   767
        surface->flags &= ~SDL_RLEACCEL;        /* stop lying */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   768
        SDL_RLESurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   769
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   770
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   772
/* 
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   773
 * Convert a surface into the specified pixel format.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   774
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   775
SDL_Surface *
2807
365fe1a2aad5 The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents: 2787
diff changeset
   776
SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
365fe1a2aad5 The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents: 2787
diff changeset
   777
                   Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   778
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   779
    SDL_Surface *convert;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   780
    Uint32 copy_flags;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   781
    SDL_Rect bounds;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   782
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   783
    /* Check for empty destination palette! (results in empty image) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   784
    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: 1456
diff changeset
   785
        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: 1456
diff changeset
   786
        for (i = 0; i < format->palette->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: 1456
diff changeset
   787
            if ((format->palette->colors[i].r != 0xFF) ||
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   788
                (format->palette->colors[i].g != 0xFF) ||
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   789
                (format->palette->colors[i].b != 0xFF))
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   790
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   791
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   792
        if (i == format->palette->ncolors) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   793
            SDL_SetError("Empty destination palette");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   794
            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: 1456
diff changeset
   795
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   796
    }
264
c9cd3b564e4b *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
   797
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   798
    /* Create a new surface with the desired format */
2807
365fe1a2aad5 The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents: 2787
diff changeset
   799
    convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   800
                                   format->BitsPerPixel, format->Rmask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   801
                                   format->Gmask, format->Bmask,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   802
                                   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: 1456
diff changeset
   803
    if (convert == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   804
        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: 1456
diff changeset
   805
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   806
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   807
    /* Copy the palette if any */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   808
    if (format->palette && convert->format->palette) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   809
        SDL_memcpy(convert->format->palette->colors,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   810
                   format->palette->colors,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   811
                   format->palette->ncolors * sizeof(SDL_Color));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   812
        convert->format->palette->ncolors = format->palette->ncolors;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   813
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   814
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   815
    /* Save the original copy flags */
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   816
    copy_flags = surface->map->info.flags;
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   817
    surface->map->info.flags = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   818
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   819
    /* Copy over the image data */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   820
    bounds.x = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   821
    bounds.y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   822
    bounds.w = surface->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   823
    bounds.h = surface->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   824
    SDL_LowerBlit(surface, &bounds, convert, &bounds);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   825
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   826
    /* Clean up the original surface, and update converted surface */
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   827
    convert->map->info.r = surface->map->info.r;
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   828
    convert->map->info.g = surface->map->info.g;
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   829
    convert->map->info.b = surface->map->info.b;
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   830
    convert->map->info.a = surface->map->info.a;
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   831
    convert->map->info.flags =
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   832
        (copy_flags &
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   833
         ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   834
           | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   835
           SDL_COPY_RLE_ALPHAKEY));
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   836
    surface->map->info.flags = copy_flags;
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   837
    if (copy_flags & SDL_COPY_COLORKEY) {
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   838
        Uint8 keyR, keyG, keyB, keyA;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   839
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   840
        SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   841
                    &keyG, &keyB, &keyA);
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   842
        SDL_SetColorKey(convert, 1,
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   843
                        SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   844
        /* This is needed when converting for 3D texture upload */
2787
93764fe8601a It turns out both the software and the OpenGL renderer had the same problem.
Sam Lantinga <slouken@libsdl.org>
parents: 2786
diff changeset
   845
        SDL_ConvertColorkeyToAlpha(convert);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   846
    }
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   847
    SDL_SetClipRect(convert, &surface->clip_rect);
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   848
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   849
    /* Enable alpha blending by default if the new surface has an
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2260
diff changeset
   850
     * alpha channel or alpha modulation */
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   851
    if ((surface->format->Amask && format->Amask) ||
4491
2cd7bb613a83 Turn on blending if we're converting from a surface with colorkey enabled
Sam Lantinga <slouken@libsdl.org>
parents: 4461
diff changeset
   852
        (copy_flags & (SDL_COPY_COLORKEY|SDL_COPY_MODULATE_ALPHA))) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   853
        SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   854
    }
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   855
    if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   856
        SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2807
diff changeset
   857
    }
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: 1456
diff changeset
   859
    /* We're 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: 1456
diff changeset
   860
    return (convert);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   861
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   862
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   863
SDL_Surface *
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   864
SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   865
                         Uint32 flags)
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   866
{
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   867
    SDL_PixelFormat *fmt;
5515
0fcf231a6e74 NDS update
Sam Lantinga <slouken@libsdl.org>
parents: 5499
diff changeset
   868
    SDL_Surface *convert = NULL;
5375
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   869
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   870
    fmt = SDL_AllocFormat(pixel_format);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   871
    if (fmt) {
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   872
        convert = SDL_ConvertSurface(surface, fmt, flags);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   873
        SDL_FreeFormat(fmt);
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   874
    }
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   875
    return convert;
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   876
}
16877f74123c Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents: 5296
diff changeset
   877
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   878
/*
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   879
 * Create a surface on the stack for quick blit operations
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   880
 */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   881
static __inline__ SDL_bool
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   882
SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   883
                         void * pixels, int pitch, SDL_Surface * surface, 
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   884
                         SDL_PixelFormat * format, SDL_BlitMap * blitmap)
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   885
{
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   886
    if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   887
        SDL_SetError("Indexed pixel formats not supported");
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   888
        return SDL_FALSE;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   889
    }
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   890
    if (SDL_InitFormat(format, pixel_format) < 0) {
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   891
        return SDL_FALSE;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   892
    }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   893
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   894
    SDL_zerop(surface);
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   895
    surface->flags = SDL_PREALLOC;
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   896
    surface->format = format;
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   897
    surface->pixels = pixels;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   898
    surface->w = width;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   899
    surface->h = height;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   900
    surface->pitch = pitch;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   901
    /* We don't actually need to set up the clip rect for our purposes */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   902
    /*SDL_SetClipRect(surface, NULL);*/
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   903
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   904
    /* Allocate an empty mapping */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   905
    SDL_zerop(blitmap);
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   906
    blitmap->info.r = 0xFF;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   907
    blitmap->info.g = 0xFF;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   908
    blitmap->info.b = 0xFF;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   909
    blitmap->info.a = 0xFF;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   910
    surface->map = blitmap;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   911
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   912
    /* The surface is ready to go */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   913
    surface->refcount = 1;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   914
    return SDL_TRUE;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   915
}
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   916
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   917
/*
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   918
 * Copy a block of pixels of one format to another format
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   919
 */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   920
int SDL_ConvertPixels(int width, int height,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   921
                      Uint32 src_format, const void * src, int src_pitch,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   922
                      Uint32 dst_format, void * dst, int dst_pitch)
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   923
{
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   924
    SDL_Surface src_surface, dst_surface;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   925
    SDL_PixelFormat src_fmt, dst_fmt;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   926
    SDL_BlitMap src_blitmap, dst_blitmap;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   927
    SDL_Rect rect;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   928
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   929
    /* Fast path for same format copy */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   930
    if (src_format == dst_format) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   931
        int bpp;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   932
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   933
        if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   934
            switch (src_format) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   935
            case SDL_PIXELFORMAT_YV12:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   936
            case SDL_PIXELFORMAT_IYUV:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   937
            case SDL_PIXELFORMAT_YUY2:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   938
            case SDL_PIXELFORMAT_UYVY:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   939
            case SDL_PIXELFORMAT_YVYU:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   940
                bpp = 2;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   941
            default:
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   942
                SDL_SetError("Unknown FOURCC pixel format");
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   943
                return -1;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   944
            }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   945
        } else {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   946
            bpp = SDL_BYTESPERPIXEL(src_format);
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   947
        }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   948
        width *= bpp;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   949
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   950
        while (height-- > 0) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   951
            SDL_memcpy(dst, src, width);
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   952
            src = (Uint8*)src + src_pitch;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   953
            dst = (Uint8*)dst + dst_pitch;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   954
        }
6041
69d7539ff51f SDL_ConvertPixels() returns 0 on success
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   955
        return 0;
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   956
    }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   957
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   958
    if (!SDL_CreateSurfaceOnStack(width, height, src_format, (void*)src,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   959
                                  src_pitch,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   960
                                  &src_surface, &src_fmt, &src_blitmap)) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   961
        return -1;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   962
    }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   963
    if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   964
                                  &dst_surface, &dst_fmt, &dst_blitmap)) {
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   965
        return -1;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   966
    }
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   967
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   968
    /* Set up the rect and go! */
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   969
    rect.x = 0;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   970
    rect.y = 0;
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   971
    rect.w = width;
3436
0538362b98d3 Fixed memory corruption in SW_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3434
diff changeset
   972
    rect.h = height;
3434
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   973
    return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   974
}
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   975
147d6ef5be03 Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents: 3103
diff changeset
   976
/*
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   977
 * Free a surface created by the above function.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   978
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   979
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   980
SDL_FreeSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   981
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   982
    if (surface == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   983
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   984
    }
5288
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   985
    if (surface->flags & SDL_DONTFREE) {
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   986
        return;
d4381f3b0d1e A few fixes:
Sam Lantinga <slouken@libsdl.org>
parents: 5262
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: 1456
diff changeset
   988
    if (--surface->refcount > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   989
        return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   990
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   991
    while (surface->locked > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   992
        SDL_UnlockSurface(surface);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   993
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   994
    if (surface->flags & 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: 1456
diff changeset
   995
        SDL_UnRLESurface(surface, 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   996
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   997
    if (surface->format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   998
        SDL_SetSurfacePalette(surface, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   999
        SDL_FreeFormat(surface->format);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1000
        surface->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: 1456
diff changeset
  1001
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1002
    if (surface->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: 1456
diff changeset
  1003
        SDL_FreeBlitMap(surface->map);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1004
        surface->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: 1456
diff changeset
  1005
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1006
    if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1007
        SDL_free(surface->pixels);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
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: 1456
diff changeset
  1009
    SDL_free(surface);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1010
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1011
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1012
/* vi: set ts=4 sw=4 expandtab: */