annotate src/video/SDL_surface.c @ 2251:292bee385630

SSE and MMX intrinsics work with Visual Studio now...
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Aug 2007 06:37:22 +0000
parents 5a58b57b6724
children 6d99edd791bf
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1251
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 130
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #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
25 #include "SDL_compat.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include "SDL_RLEaccel_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include "SDL_pixels_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include "SDL_leaks.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31
1251
86d0d01290ea Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
32
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 /* Public routines */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 * Create an empty RGB surface of the appropriate depth
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 */
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
37 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
38 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
39 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
40 Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 {
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
42 SDL_Surface *surface;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
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
44 /* 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
45 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
46 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
47 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
48 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
49 }
940
bb1588ebe47b Date: Sat, 10 Jul 2004 21:02:33 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 915
diff changeset
50
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
51 surface->format = SDL_AllocFormat(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
52 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
53 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
54 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
55 }
c121d94672cb SDL 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 if (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
57 surface->flags |= SDL_SRCALPHA;
c121d94672cb SDL 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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
59 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
60 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
61 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
62 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
63
c121d94672cb SDL 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 if (surface->format->BitsPerPixel <= 8) {
c121d94672cb SDL 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 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
66 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
67 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
68 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
69 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
70 }
c121d94672cb SDL 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 if (Rmask || Bmask || Gmask) {
c121d94672cb SDL 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 const SDL_PixelFormat *format = 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
73
c121d94672cb SDL 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 /* create palette according to masks */
c121d94672cb SDL 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 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
76 int Rm = 0, Gm = 0, Bm = 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
77 int Rw = 0, Gw = 0, Bw = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78
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
79 if (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
80 Rw = 8 - format->Rloss;
c121d94672cb SDL 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 for (i = format->Rloss; i > 0; i -= Rw)
c121d94672cb SDL 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 Rm |= 1 << 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
83 }
c121d94672cb SDL 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 if (Gmask) {
c121d94672cb SDL 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 Gw = 8 - format->Gloss;
c121d94672cb SDL 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 for (i = format->Gloss; i > 0; i -= Gw)
c121d94672cb SDL 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 Gm |= 1 << 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
88 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
89 if (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
90 Bw = 8 - format->Bloss;
c121d94672cb SDL 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 for (i = format->Bloss; i > 0; i -= Bw)
c121d94672cb SDL 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 Bm |= 1 << 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
93 }
c121d94672cb SDL 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 for (i = 0; i < 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
95 int r, g, b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
96 r = (i & Rmask) >> format->Rshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
97 r = (r << format->Rloss) | ((r * Rm) >> Rw);
c121d94672cb SDL 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 palette->colors[i].r = r;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
99
c121d94672cb SDL 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 g = (i & Gmask) >> format->Gshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
101 g = (g << format->Gloss) | ((g * Gm) >> Gw);
c121d94672cb SDL 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 palette->colors[i].g = g;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103
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
104 b = (i & Bmask) >> format->Bshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
105 b = (b << format->Bloss) | ((b * Bm) >> Bw);
c121d94672cb SDL 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 palette->colors[i].b = b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 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 } else if (palette->ncolors == 2) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
109 /* 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
110 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
111 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
112 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
113 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
114 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
115 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
116 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
117 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
118 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
119 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120
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
121 /* 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
122 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
123 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
124 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
125 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
126 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
127 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
128 }
c121d94672cb SDL 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 /* 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
130 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
131 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132
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
133 /* 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
134 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
135 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
136 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
137 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
138 }
c121d94672cb SDL 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 SDL_FormatChanged(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
140
c121d94672cb SDL 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 /* 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
142 surface->refcount = 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 #ifdef CHECK_LEAKS
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
144 ++surfaces_allocated;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 #endif
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
146 return surface;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 }
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
148
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 * Create an RGB surface from an existing memory buffer
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 */
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
152 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
153 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
154 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
155 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
156 Uint32 Amask)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 {
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
158 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
159
c121d94672cb SDL 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 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
170 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
171 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
172
c121d94672cb SDL 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 static 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
174 SDL_SurfacePaletteChanged(void *userdata, 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
175 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
176 SDL_Surface *surface = (SDL_Surface *) userdata;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
177
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
178 SDL_FormatChanged(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
179
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
180 return 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
181 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
182
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
183 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
184 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
185 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
186 if (!surface || !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
187 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
188 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
189 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
190
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
191 if (palette && palette->ncolors != (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
192 SDL_SetError
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
193 ("SDL_SetSurfacePalette() passed a palette that doesn't match the 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
194 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
195 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
196
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
197 if (surface->format->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
198 return 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
199 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
200
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
201 if (surface->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
202 SDL_DelPaletteWatch(surface->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
203 SDL_SurfacePaletteChanged, 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
204 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
205
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
206 surface->format->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
207
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
208 if (surface->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
209 SDL_AddPaletteWatch(surface->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
210 SDL_SurfacePaletteChanged, 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
211 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
212 return 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
213 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
214
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 * Set the color key in a blittable surface
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 */
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
218 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
219 SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 {
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
221 /* Sanity check the flag as it gets passed in */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
222 if (flag & SDL_SRCCOLORKEY) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
223 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
224 flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
225 } 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
226 flag = SDL_SRCCOLORKEY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
227 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
228 } 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
229 flag = 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
230 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231
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
232 /* Optimize away operations that don't change anything */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
233 if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
234 (key == surface->format->colorkey)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
235 return (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
236 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237
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
238 /* UnRLE surfaces before we change the colorkey */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
239 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
240 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
241 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242
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
243 if (flag) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
244 surface->flags |= SDL_SRCCOLORKEY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
245 surface->format->colorkey = key;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
246 if (flag & SDL_RLEACCELOK) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
247 surface->flags |= SDL_RLEACCELOK;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
248 } 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
249 surface->flags &= ~SDL_RLEACCELOK;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
250 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
251 } 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
252 surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
253 surface->format->colorkey = 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
254 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
255 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
256 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
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
258
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
259 /* This function sets the alpha channel of a 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
260 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
261 SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 {
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
263 Uint32 oldflags = surface->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
264 Uint32 oldalpha = surface->format->alpha;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265
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
266 /* Sanity check the flag as it gets passed in */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
267 if (flag & SDL_SRCALPHA) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
268 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
269 flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
270 } 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
271 flag = SDL_SRCALPHA;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
272 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
273 } 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
274 flag = 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
275 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276
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
277 /* Optimize away operations that don't change anything */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
278 if ((flag == (surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK))) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
279 (!flag || value == oldalpha)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
280 return (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
281 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282
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
283 if (!(flag & SDL_RLEACCELOK) && (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
284 SDL_UnRLESurface(surface, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285
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
286 if (flag) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
287 surface->flags |= SDL_SRCALPHA;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
288 surface->format->alpha = value;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
289 if (flag & SDL_RLEACCELOK) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
290 surface->flags |= SDL_RLEACCELOK;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
291 } 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
292 surface->flags &= ~SDL_RLEACCELOK;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
293 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
294 } 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
295 surface->flags &= ~SDL_SRCALPHA;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
296 surface->format->alpha = SDL_ALPHA_OPAQUE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
297 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
298 /*
c121d94672cb SDL 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 * The representation for software surfaces is independent of
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
300 * per-surface alpha, so no need to invalidate the blit 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
301 * if just the alpha value was changed. (If either is 255, we still
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
302 * need to invalidate.)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
303 */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
304 if (oldflags != surface->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
305 || (((oldalpha + 1) ^ (value + 1)) & 0x100)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
306 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
307 }
c121d94672cb SDL 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 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 }
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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
311 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
312 SDL_SetAlphaChannel(SDL_Surface * surface, Uint8 value)
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
313 {
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
314 int row, col;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
315 int offset;
c121d94672cb SDL 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 Uint8 *buf;
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
317
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
318 if ((surface->format->Amask != 0xFF000000) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
319 (surface->format->Amask != 0x000000FF)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
320 SDL_SetError("Unsupported surface alpha mask 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
321 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
322 }
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
323 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
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
324 if (surface->format->Amask == 0xFF000000) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
325 offset = 3;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
326 } 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
327 offset = 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
328 }
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
329 #else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
330 if (surface->format->Amask == 0xFF000000) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
331 offset = 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
332 } 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
333 offset = 3;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
334 }
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
335 #endif /* Byte ordering */
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
336
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
337 /* Quickly set the alpha channel of an RGBA or ARGB 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
338 if (SDL_MUSTLOCK(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
339 if (SDL_LockSurface(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
340 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
341 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
342 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
343 row = 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
344 while (row--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
345 col = 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
346 buf = (Uint8 *) surface->pixels + row * surface->pitch + offset;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
347 while (col--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
348 *buf = value;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
349 buf += 4;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
350 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
351 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
352 if (SDL_MUSTLOCK(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
353 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
354 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
355 return 0;
431
41cadcba32e8 Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents: 422
diff changeset
356 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 * Set the clipping rectangle for a blittable surface
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 */
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
361 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
362 SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
364 SDL_Rect full_rect;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365
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
366 /* 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
367 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
368 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
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
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
371 /* 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
372 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
373 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
374 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
375 full_rect.h = surface->h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376
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
377 /* 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
378 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
379 surface->clip_rect = full_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
380 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
381 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
382 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
383 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384
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
385 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
386 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
387 {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
388 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
389 *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
390 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 }
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
392
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 * Set up a blit between two surfaces -- split into three parts:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 * The upper part, SDL_UpperBlit(), performs clipping and rectangle
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 * verification. The lower part is a pointer to a low level
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 * accelerated blitting function.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 * These parts are separated out and each used internally by this
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 * library in the optimimum places. They are exported so that if
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 * you know exactly what you are doing, you can optimize your code
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 * by calling the one(s) you need.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 */
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
404 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
405 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
406 SDL_Surface * dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 {
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
408 /* 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
409 if ((src->map->dst != 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
410 (src->map->dst->format_version != src->map->format_version)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
411 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
412 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
413 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
414 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
415 return (src->map->sw_blit(src, srcrect, dst, dstrect));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418
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
419 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
420 SDL_UpperBlit(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
421 SDL_Surface * dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 {
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
423 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
424 int srcx, srcy, w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425
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
426 /* 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
427 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
428 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
429 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
430 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
431 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
432 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
433 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
434 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
435
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
436 /* 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
437 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
438 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
439 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
440 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
441
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
442 /* 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
443 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
444 int maxw, maxh;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445
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
446 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
447 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
448 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
449 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
450 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
451 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
452 }
c121d94672cb SDL 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 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
454 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
455 w = maxw;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456
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
457 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
458 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
459 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
460 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
461 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
462 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
463 }
c121d94672cb SDL 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 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
465 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
466 h = maxh;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467
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
468 } 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
469 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
470 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
471 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
472 }
c121d94672cb SDL 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 /* 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
475 {
c121d94672cb SDL 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 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
477 int dx, dy;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478
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
479 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
480 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
481 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
482 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
483 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
484 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
485 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
486 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
487 w -= dx;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488
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
489 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
490 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
491 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
492 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
493 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
494 }
c121d94672cb SDL 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 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
496 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
497 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
498 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499
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
500 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
501 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
502 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
503 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
504 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
505 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
506 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
507 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
508 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
509 return 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
512 #ifdef __SSE__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
513 /* *INDENT-OFF* */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
514
2251
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
515 #ifdef _MSC_VER
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
516 #define SSE_BEGIN \
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
517 __m128 c128; \
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
518 c128.m128_u32[0] = color; \
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
519 c128.m128_u32[1] = color; \
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
520 c128.m128_u32[2] = color; \
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
521 c128.m128_u32[3] = color;
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
522 #else
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
523 #define SSE_BEGIN \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
524 DECLARE_ALIGNED(Uint32, cccc[4], 16); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
525 cccc[0] = color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
526 cccc[1] = color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
527 cccc[2] = color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
528 cccc[3] = color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
529 __m128 c128 = *(__m128 *)cccc;
2251
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
530 #endif
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
531
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
532 #define SSE_WORK \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
533 for (i = n / 64; i--;) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
534 _mm_stream_ps((float *)(p+0), c128); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
535 _mm_stream_ps((float *)(p+16), c128); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
536 _mm_stream_ps((float *)(p+32), c128); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
537 _mm_stream_ps((float *)(p+48), c128); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
538 p += 64; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
539 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
540
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
541 #define SSE_END
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
542
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
543 #define DEFINE_SSE_FILLRECT(bpp, type) \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
544 static void \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
545 SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
546 { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
547 SSE_BEGIN; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
548 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
549 while (h--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
550 int i, n = w * bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
551 Uint8 *p = pixels; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
552 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
553 if (n > 15) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
554 int adjust = 16 - ((uintptr_t)p & 15); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
555 if (adjust < 16) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
556 n -= adjust; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
557 adjust /= bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
558 while(adjust--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
559 *((type *)p) = (type)color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
560 p += bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
561 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
562 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
563 SSE_WORK; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
564 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
565 if (n & 63) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
566 int remainder = (n & 63); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
567 remainder /= bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
568 while(remainder--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
569 *((type *)p) = (type)color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
570 p += bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
571 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
572 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
573 pixels += pitch; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
574 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
575 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
576 SSE_END; \
532
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
577 }
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
578
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
579 DEFINE_SSE_FILLRECT(1, Uint8)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
580 DEFINE_SSE_FILLRECT(2, Uint16)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
581 DEFINE_SSE_FILLRECT(4, Uint32)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
582
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
583 /* *INDENT-ON* */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
584 #endif /* __SSE__ */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
585
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
586 #ifdef __MMX__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
587 /* *INDENT-OFF* */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
588
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
589 #define MMX_BEGIN \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
590 __m64 c64 = _mm_set_pi32(color, color)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
591
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
592 #define MMX_WORK \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
593 for (i = n / 64; i--;) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
594 _mm_stream_pi((__m64 *)(p+0), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
595 _mm_stream_pi((__m64 *)(p+8), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
596 _mm_stream_pi((__m64 *)(p+16), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
597 _mm_stream_pi((__m64 *)(p+24), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
598 _mm_stream_pi((__m64 *)(p+32), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
599 _mm_stream_pi((__m64 *)(p+40), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
600 _mm_stream_pi((__m64 *)(p+48), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
601 _mm_stream_pi((__m64 *)(p+56), c64); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
602 p += 64; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
603 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
604
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
605 #define MMX_END \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
606 _mm_empty()
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
607
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
608 #define DEFINE_MMX_FILLRECT(bpp, type) \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
609 static void \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
610 SDL_FillRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
611 { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
612 MMX_BEGIN; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
613 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
614 while (h--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
615 int i, n = w * bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
616 Uint8 *p = pixels; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
617 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
618 if (n > 7) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
619 int adjust = 8 - ((uintptr_t)p & 7); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
620 if (adjust < 8) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
621 n -= adjust; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
622 adjust /= bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
623 while(adjust--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
624 *((type *)p) = (type)color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
625 p += bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
626 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
627 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
628 MMX_WORK; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
629 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
630 if (n & 63) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
631 int remainder = (n & 63); \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
632 remainder /= bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
633 while(remainder--) { \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
634 *((type *)p) = (type)color; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
635 p += bpp; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
636 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
637 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
638 pixels += pitch; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
639 } \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
640 \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
641 MMX_END; \
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
642 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
643
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
644 DEFINE_MMX_FILLRECT(1, Uint8)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
645 DEFINE_MMX_FILLRECT(2, Uint16)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
646 DEFINE_MMX_FILLRECT(4, Uint32)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
647
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
648 /* *INDENT-ON* */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
649 #endif /* __MMX__ */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
650
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
651 static void
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
652 SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
532
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
653 {
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
654 while (h--) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
655 int n = w;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
656 Uint8 *p = pixels;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
657
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
658 if (n > 3) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
659 switch ((uintptr_t) p & 3) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
660 case 1:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
661 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
662 --n;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
663 case 2:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
664 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
665 --n;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
666 case 3:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
667 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
668 --n;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
669 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
670 SDL_memset4(p, color, (n >> 2));
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
671 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
672 if (n & 3) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
673 p += (n & ~3);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
674 switch (n & 3) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
675 case 3:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
676 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
677 case 2:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
678 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
679 case 1:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
680 *p++ = (Uint8) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
681 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
682 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
683 pixels += pitch;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
684 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
685 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
686
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
687 static void
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
688 SDL_FillRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
689 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
690 while (h--) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
691 int n = w;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
692 Uint16 *p = (Uint16 *) pixels;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
693
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
694 if (n > 1) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
695 if ((uintptr_t) p & 2) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
696 *p++ = (Uint16) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
697 --n;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
698 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
699 SDL_memset4(p, color, (n >> 1));
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
700 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
701 if (n & 1) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
702 p[n - 1] = (Uint16) color;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
703 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
704 pixels += pitch;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
705 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
706 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
707
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
708 static void
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
709 SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
710 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
711 Uint8 r = (Uint8) (color & 0xFF);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
712 Uint8 g = (Uint8) ((color >> 8) & 0xFF);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
713 Uint8 b = (Uint8) ((color >> 16) & 0xFF);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
714
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
715 while (h--) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
716 int n = w;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
717 Uint8 *p = pixels;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
718
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
719 while (n--) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
720 *p++ = r;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
721 *p++ = g;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
722 *p++ = b;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
723 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
724 pixels += pitch;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
725 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
726 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
727
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
728 static void
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
729 SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
730 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
731 while (h--) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
732 SDL_memset4(pixels, color, w);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
733 pixels += pitch;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
734 }
532
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
735 }
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
736
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
737 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
738 * This function performs a fast fill of the given rectangle with 'color'
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
739 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
740 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
741 SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
742 {
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
743 Uint8 *pixels;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
744
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
745 /* This function doesn't work on surfaces < 8 bpp */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
746 if (dst->format->BitsPerPixel < 8) {
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
747 SDL_SetError("Fill rect on unsupported surface format");
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
748 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
749 }
532
058d47b7a3b4 Return an error with color fills on less than 8 bpp surfaces.
Sam Lantinga <slouken@libsdl.org>
parents: 526
diff changeset
750
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
751 /* If 'dstrect' == NULL, then fill the whole 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
752 if (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
753 /* Perform clipping */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
754 if (!SDL_IntersectRect(dstrect, &dst->clip_rect, 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
755 return (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
756 }
c121d94672cb SDL 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 } 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
758 dstrect = &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
759 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
760
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
761 /* Perform software fill */
c121d94672cb SDL 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 if (SDL_LockSurface(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
763 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
764 }
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
765
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
766 pixels =
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
767 (Uint8 *) dst->pixels + dstrect->y * dst->pitch +
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
768 dstrect->x * dst->format->BytesPerPixel;
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
769
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
770 switch (dst->format->BytesPerPixel) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
771 case 1:
2234
cf8c3b0117b3 Gained 5 FPS in testsprite because Mac OS X memset is highly optimized
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
772 {
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
773 color |= (color << 8);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
774 color |= (color << 16);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
775 #ifdef __SSE__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
776 if (SDL_HasSSE()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
777 SDL_FillRect1SSE(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
778 dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
779 break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
780 }
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
781 #endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
782 #ifdef __MMX__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
783 if (SDL_HasMMX()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
784 SDL_FillRect1MMX(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
785 dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
786 break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
787 }
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
788 #endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
789 SDL_FillRect1(pixels, dst->pitch, color, dstrect->w, dstrect->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
790 break;
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
791 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
792
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
793 case 2:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
794 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
795 color |= (color << 16);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
796 #ifdef __SSE__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
797 if (SDL_HasSSE()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
798 SDL_FillRect2SSE(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
799 dstrect->h);
2239
31835fd24b2b Added SSE version of SDL_FillRect() for 32-bit ARGB surfaces
Sam Lantinga <slouken@libsdl.org>
parents: 2235
diff changeset
800 break;
31835fd24b2b Added SSE version of SDL_FillRect() for 32-bit ARGB surfaces
Sam Lantinga <slouken@libsdl.org>
parents: 2235
diff changeset
801 }
31835fd24b2b Added SSE version of SDL_FillRect() for 32-bit ARGB surfaces
Sam Lantinga <slouken@libsdl.org>
parents: 2235
diff changeset
802 #endif
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
803 #ifdef __MMX__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
804 if (SDL_HasMMX()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
805 SDL_FillRect2MMX(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
806 dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
807 break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
808 }
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
809 #endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
810 SDL_FillRect2(pixels, dst->pitch, color, dstrect->w, dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
811 break;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
812 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
813
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
814 case 3:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
815 /* 24-bit RGB is a slow path, at least for now. */
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
816 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
817 SDL_FillRect3(pixels, dst->pitch, color, dstrect->w, dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
818 break;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
819 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
820
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
821 case 4:
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
822 {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
823 #ifdef __SSE__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
824 if (SDL_HasSSE()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
825 SDL_FillRect4SSE(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
826 dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
827 break;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
828 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
829 #endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
830 #ifdef __MMX__
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
831 if (SDL_HasMMX()) {
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
832 SDL_FillRect4MMX(pixels, dst->pitch, color, dstrect->w,
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
833 dstrect->h);
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
834 break;
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
835 }
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
836 #endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
837 SDL_FillRect4(pixels, dst->pitch, color, dstrect->w, dstrect->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
838 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
839 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
840 }
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2239
diff changeset
841
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
842 SDL_UnlockSurface(dst);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
843
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
844 /* We're done! */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
845 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
846 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
847
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
848 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
849 * Lock a surface to directly access the pixels
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
850 */
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
851 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
852 SDL_LockSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
853 {
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 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
855 /* 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
856 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
857 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
858 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
859 }
c121d94672cb SDL 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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
861
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
862 /* 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
863 ++surface->locked;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
864
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
865 /* 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
866 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
867 }
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
868
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
869 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
870 * Unlock a previously locked surface
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
871 */
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
872 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
873 SDL_UnlockSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
874 {
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
875 /* 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
876 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
877 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
878 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
879
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
880 /* 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
881 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
882 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
883 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
884 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
885 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
886
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
887 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
888 * Convert a surface into the specified pixel format.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
889 */
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
890 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
891 SDL_ConvertSurface(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
892 SDL_PixelFormat * format, Uint32 flags)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
893 {
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
894 SDL_Surface *convert;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
895 Uint32 colorkey = 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
896 Uint8 alpha = 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
897 Uint32 surface_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
898 SDL_Rect bounds;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
899
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
900 /* 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
901 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
902 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
903 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
904 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
905 (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
906 (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
907 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
908 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
909 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
910 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
911 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
912 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
913 }
264
c9cd3b564e4b *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
914
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
915 /* Create a new surface with the desired 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
916 convert = SDL_CreateRGBSurface(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
917 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
918 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
919 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
920 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
921 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
922 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
923 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
924
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
925 /* 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
926 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
927 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
928 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
929 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
930 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
931 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
932
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
933 /* Save the original surface color key and alpha */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
934 surface_flags = surface->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
935 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
936 /* Convert colourkeyed surfaces to RGBA if requested */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
937 if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && 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
938 surface_flags &= ~SDL_SRCCOLORKEY;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
939 } 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
940 colorkey = surface->format->colorkey;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
941 SDL_SetColorKey(surface, 0, 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
942 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
943 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
944 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
945 /* Copy over the alpha channel to RGBA if requested */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
946 if (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
947 surface->flags &= ~SDL_SRCALPHA;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
948 } 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
949 alpha = surface->format->alpha;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
950 SDL_SetAlpha(surface, 0, 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
951 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
952 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
953
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
954 /* 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
955 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
956 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
957 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
958 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
959 SDL_LowerBlit(surface, &bounds, convert, &bounds);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
960
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
961 /* Clean up the original surface, and update converted 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
962 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
963 SDL_SetClipRect(convert, &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
964 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
965 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
966 Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
967 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
968 Uint8 keyR, keyG, keyB;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
969
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
970 SDL_GetRGB(colorkey, surface->format, &keyR, &keyG, &keyB);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
971 SDL_SetColorKey(convert, cflags | (flags & SDL_RLEACCELOK),
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
972 SDL_MapRGB(convert->format, keyR, keyG, keyB));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
973 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
974 SDL_SetColorKey(surface, cflags, colorkey);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
975 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
976 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
977 Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
978 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
979 SDL_SetAlpha(convert, aflags | (flags & SDL_RLEACCELOK), alpha);
c121d94672cb SDL 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 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
981 if (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
982 surface->flags |= SDL_SRCALPHA;
c121d94672cb SDL 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 } 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
984 SDL_SetAlpha(surface, aflags, alpha);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
985 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
986 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
987
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
988 /* 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
989 return (convert);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
990 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
991
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
992 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
993 * Free a surface created by the above function.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
994 */
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
995 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
996 SDL_FreeSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
997 {
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
998 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
999 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
1000 }
c121d94672cb SDL 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 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
1002 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
1003 }
c121d94672cb SDL 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 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
1005 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
1006 }
c121d94672cb SDL 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 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
1008 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
1009 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1010 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
1011 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
1012 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
1013 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
1014 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1015 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
1016 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
1017 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
1018 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1019 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
1020 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
1021 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1022 SDL_free(surface);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1023 #ifdef CHECK_LEAKS
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
1024 --surfaces_allocated;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1025 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1026 }
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
1027
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
1028 /* vi: set ts=4 sw=4 expandtab: */