Mercurial > sdl-ios-xcode
annotate src/video/SDL_surface.c @ 5123:87f452305db4
Added CPU cache line size to the test output.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Jan 2011 20:49:07 -0800 |
parents | a130bc2f0a18 |
children | da10636e5eca |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
0 | 4 |
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 | 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 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
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 | 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 | 18 |
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 | 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 | 23 |
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 | 26 #include "SDL_sysvideo.h" |
27 #include "SDL_blit.h" | |
28 #include "SDL_RLEaccel_c.h" | |
29 #include "SDL_pixels_c.h" | |
30 #include "SDL_leaks.h" | |
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 | 33 /* Public routines */ |
34 /* | |
35 * Create an empty RGB surface of the appropriate depth | |
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 | 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 | 43 |
2807
365fe1a2aad5
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents:
2787
diff
changeset
|
44 /* The flags are no longer used, make the compiler happy */ |
4461
39c22a953456
Make the compiler even happier
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
45 (void)flags; |
2807
365fe1a2aad5
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents:
2787
diff
changeset
|
46 |
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
|
47 /* 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 } |
940
bb1588ebe47b
Date: Sat, 10 Jul 2004 21:02:33 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
915
diff
changeset
|
53 |
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
|
54 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
|
55 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
|
56 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
|
57 return NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
58 } |
c121d94672cb
SDL 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 | 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 | 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 | 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 | 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 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
141 /* By default surface with an alpha mask are set up for blending */ |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
142 if (Amask) { |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
143 SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
144 } |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
145 |
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 /* 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
|
147 surface->refcount = 1; |
0 | 148 #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
|
149 ++surfaces_allocated; |
0 | 150 #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
|
151 return surface; |
0 | 152 } |
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
|
153 |
0 | 154 /* |
155 * Create an RGB surface from an existing memory buffer | |
156 */ | |
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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 Uint32 Amask) |
0 | 162 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
163 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
|
164 |
c121d94672cb
SDL 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 = |
c121d94672cb
SDL 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 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 } |
c121d94672cb
SDL 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 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
|
176 } |
c121d94672cb
SDL 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 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
|
179 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
|
180 { |
c121d94672cb
SDL 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 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
|
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 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
|
184 |
c121d94672cb
SDL 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 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
|
186 } |
c121d94672cb
SDL 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 |
c121d94672cb
SDL 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 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
|
189 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
|
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 (!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
|
192 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
|
193 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
|
194 } |
c121d94672cb
SDL 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 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
|
197 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
|
198 ("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
|
199 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
|
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 |
c121d94672cb
SDL 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 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
|
203 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
|
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 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
|
207 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
|
208 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
|
209 } |
c121d94672cb
SDL 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 |
c121d94672cb
SDL 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 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
|
212 |
c121d94672cb
SDL 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 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
|
214 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
|
215 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
|
216 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
217 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
|
218 } |
c121d94672cb
SDL 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 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
220 int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
221 SDL_SetSurfaceRLE(SDL_Surface * surface, int flag) |
0 | 222 { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
223 int flags; |
0 | 224 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
225 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
226 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
|
227 } |
0 | 228 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
229 flags = surface->map->info.flags; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
230 if (flag) { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
231 surface->map->info.flags |= SDL_COPY_RLE_DESIRED; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
232 } else { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
233 surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
234 } |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
235 if (surface->map->info.flags != flags) { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
236 SDL_InvalidateMap(surface->map); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
237 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
238 return 0; |
0 | 239 } |
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
|
240 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
241 int |
3560
5543db4239e6
The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents:
3436
diff
changeset
|
242 SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) |
0 | 243 { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
244 int flags; |
0 | 245 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
246 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
247 return -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
248 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
249 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
250 if (flag & SDL_RLEACCEL) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
251 SDL_SetSurfaceRLE(surface, 1); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
252 } |
0 | 253 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
254 flags = surface->map->info.flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
255 if (flag) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
256 surface->map->info.flags |= SDL_COPY_COLORKEY; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
257 surface->map->info.colorkey = key; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
258 } else { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
259 surface->map->info.flags &= ~SDL_COPY_COLORKEY; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
260 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
261 if (surface->map->info.flags != flags) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
262 SDL_InvalidateMap(surface->map); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
263 } |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
264 |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
265 /* Compatibility mode */ |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
266 if (surface->map->info.flags & SDL_COPY_COLORKEY) { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
267 surface->flags |= SDL_SRCCOLORKEY; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
268 } else { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
269 surface->flags &= ~SDL_SRCCOLORKEY; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
270 } |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
271 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
272 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
273 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
274 |
3103 | 275 int |
276 SDL_GetColorKey(SDL_Surface * surface, Uint32 * key) | |
277 { | |
278 if (!surface) { | |
279 return -1; | |
280 } | |
281 | |
282 if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) { | |
283 return -1; | |
284 } | |
285 | |
286 if (key) { | |
287 *key = surface->map->info.colorkey; | |
288 } | |
289 return 0; | |
290 } | |
291 | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
292 /* This is a fairly slow function to switch from colorkey to alpha */ |
2787
93764fe8601a
It turns out both the software and the OpenGL renderer had the same problem.
Sam Lantinga <slouken@libsdl.org>
parents:
2786
diff
changeset
|
293 static void |
2786 | 294 SDL_ConvertColorkeyToAlpha(SDL_Surface * surface) |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
295 { |
2786 | 296 int x, y; |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
297 |
2786 | 298 if (!surface) { |
299 return; | |
300 } | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
301 |
2786 | 302 if (!(surface->map->info.flags & SDL_COPY_COLORKEY) || |
303 !surface->format->Amask) { | |
304 return; | |
305 } | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
306 |
2786 | 307 SDL_LockSurface(surface); |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
308 |
2786 | 309 switch (surface->format->BytesPerPixel) { |
310 case 2: | |
311 { | |
312 Uint16 *row, *spot; | |
313 Uint16 ckey = (Uint16) surface->map->info.colorkey; | |
314 Uint16 mask = (Uint16) (~surface->format->Amask); | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
315 |
2786 | 316 row = (Uint16 *) surface->pixels; |
317 for (y = surface->h; y--;) { | |
318 spot = row; | |
319 for (x = surface->w; x--;) { | |
320 if (*spot == ckey) { | |
321 *spot &= mask; | |
322 } | |
323 ++spot; | |
324 } | |
325 row += surface->pitch / 2; | |
326 } | |
327 } | |
328 break; | |
329 case 3: | |
330 /* FIXME */ | |
331 break; | |
332 case 4: | |
333 { | |
334 Uint32 *row, *spot; | |
335 Uint32 ckey = surface->map->info.colorkey; | |
336 Uint32 mask = ~surface->format->Amask; | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
337 |
2786 | 338 row = (Uint32 *) surface->pixels; |
339 for (y = surface->h; y--;) { | |
340 spot = row; | |
341 for (x = surface->w; x--;) { | |
342 if (*spot == ckey) { | |
343 *spot &= mask; | |
344 } | |
345 ++spot; | |
346 } | |
347 row += surface->pitch / 4; | |
348 } | |
349 } | |
350 break; | |
351 } | |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
352 |
2786 | 353 SDL_UnlockSurface(surface); |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
354 |
2786 | 355 SDL_SetColorKey(surface, 0, 0); |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
356 SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
357 } |
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
358 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
359 int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
360 SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
361 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
362 int flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
363 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
364 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
365 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
|
366 } |
0 | 367 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
368 surface->map->info.r = r; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
369 surface->map->info.g = g; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
370 surface->map->info.b = b; |
0 | 371 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
372 flags = surface->map->info.flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
373 if (r != 0xFF || g != 0xFF || b != 0xFF) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
374 surface->map->info.flags |= SDL_COPY_MODULATE_COLOR; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
375 } else { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
376 surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
377 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
378 if (surface->map->info.flags != flags) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
379 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
|
380 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
381 return 0; |
0 | 382 } |
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
|
383 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
384 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
385 int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
386 SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b) |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
387 { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
388 if (!surface) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
389 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
|
390 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
391 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
392 if (r) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
393 *r = surface->map->info.r; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
394 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
395 if (g) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
396 *g = surface->map->info.g; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
397 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
398 if (b) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
399 *b = surface->map->info.b; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
400 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
401 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
402 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
403 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
404 int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
405 SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
406 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
407 int flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
408 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
409 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
410 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
|
411 } |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
412 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
413 surface->map->info.a = alpha; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
414 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
415 flags = surface->map->info.flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
416 if (alpha != 0xFF) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
417 surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
418 } else { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
419 surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
420 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
421 if (surface->map->info.flags != flags) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
422 SDL_InvalidateMap(surface->map); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
423 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
424 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
425 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
426 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
427 int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
428 SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
429 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
430 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
431 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
|
432 } |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
433 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
434 if (alpha) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
435 *alpha = surface->map->info.a; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
436 } |
c121d94672cb
SDL 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 return 0; |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
438 } |
0 | 439 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
440 int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
441 SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
442 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
443 int flags, status; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
444 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
445 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
446 return -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
447 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
448 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
449 status = 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
450 flags = surface->map->info.flags; |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
451 surface->map->info.flags &= |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
452 ~(SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD); |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
453 switch (blendMode) { |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
454 case SDL_BLENDMODE_NONE: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
455 break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
456 case SDL_BLENDMODE_MASK: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
457 surface->map->info.flags |= SDL_COPY_MASK; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
458 break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
459 case SDL_BLENDMODE_BLEND: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
460 surface->map->info.flags |= SDL_COPY_BLEND; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
461 break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
462 case SDL_BLENDMODE_ADD: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
463 surface->map->info.flags |= SDL_COPY_ADD; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
464 break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
465 case SDL_BLENDMODE_MOD: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
466 surface->map->info.flags |= SDL_COPY_MOD; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
467 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
468 default: |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
469 SDL_Unsupported(); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
470 status = -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
471 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
472 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
473 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
474 if (surface->map->info.flags != flags) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
475 SDL_InvalidateMap(surface->map); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
476 } |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
477 |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
478 /* Compatibility mode */ |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
479 if (surface->map->info.flags & SDL_COPY_BLEND) { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
480 surface->flags |= SDL_SRCALPHA; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
481 } else { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
482 surface->flags &= ~SDL_SRCALPHA; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
483 } |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
484 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
485 return status; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
486 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
487 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
488 int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
489 SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
490 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
491 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
492 return -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
493 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
494 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
495 if (!blendMode) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
496 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
497 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
498 |
3013
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
499 switch (surface->map-> |
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
500 info.flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | |
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
501 SDL_COPY_MOD)) { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
502 case SDL_COPY_MASK: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
503 *blendMode = SDL_BLENDMODE_MASK; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
504 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
505 case SDL_COPY_BLEND: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
506 *blendMode = SDL_BLENDMODE_BLEND; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
507 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
508 case SDL_COPY_ADD: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
509 *blendMode = SDL_BLENDMODE_ADD; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
510 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
511 case SDL_COPY_MOD: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
512 *blendMode = SDL_BLENDMODE_MOD; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
513 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
514 default: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
515 *blendMode = SDL_BLENDMODE_NONE; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
516 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
517 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
518 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
519 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
520 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
521 int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
522 SDL_SetSurfaceScaleMode(SDL_Surface * surface, SDL_ScaleMode scaleMode) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
523 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
524 int flags, status; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
525 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
526 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
527 return -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
528 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
529 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
530 status = 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
531 flags = surface->map->info.flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
532 surface->map->info.flags &= ~(SDL_COPY_NEAREST); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
533 switch (scaleMode) { |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
534 case SDL_SCALEMODE_NONE: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
535 break; |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
536 case SDL_SCALEMODE_FAST: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
537 surface->map->info.flags |= SDL_COPY_NEAREST; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
538 break; |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
539 case SDL_SCALEMODE_SLOW: |
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
540 case SDL_SCALEMODE_BEST: |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
541 SDL_Unsupported(); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
542 surface->map->info.flags |= SDL_COPY_NEAREST; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
543 status = -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
544 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
545 default: |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
546 SDL_Unsupported(); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
547 status = -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
548 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
549 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
550 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
551 if (surface->map->info.flags != flags) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
552 SDL_InvalidateMap(surface->map); |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
553 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
554 return status; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
555 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
556 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
557 int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
558 SDL_GetSurfaceScaleMode(SDL_Surface * surface, SDL_ScaleMode *scaleMode) |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
559 { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
560 if (!surface) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
561 return -1; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
562 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
563 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
564 if (!scaleMode) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
565 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
566 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
567 |
2853
6258fa7cd300
Fixed picking blit function when RLE fails
Sam Lantinga <slouken@libsdl.org>
parents:
2824
diff
changeset
|
568 switch (surface->map->info.flags & SDL_COPY_NEAREST) { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
569 case SDL_COPY_NEAREST: |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
570 *scaleMode = SDL_SCALEMODE_FAST; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
571 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
572 default: |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
573 *scaleMode = SDL_SCALEMODE_NONE; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
574 break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
575 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
576 return 0; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
577 } |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
578 |
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
|
579 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
|
580 SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect) |
0 | 581 { |
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
|
582 SDL_Rect full_rect; |
0 | 583 |
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
|
584 /* 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
|
585 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
|
586 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
|
587 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
588 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
589 /* 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
|
590 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
|
591 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
|
592 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
|
593 full_rect.h = surface->h; |
0 | 594 |
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
|
595 /* 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
|
596 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
|
597 surface->clip_rect = full_rect; |
4966 | 598 return SDL_TRUE; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
599 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
600 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
|
601 } |
0 | 602 |
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
|
603 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
|
604 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
|
605 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
606 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
|
607 *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
|
608 } |
0 | 609 } |
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
|
610 |
0 | 611 /* |
612 * Set up a blit between two surfaces -- split into three parts: | |
613 * The upper part, SDL_UpperBlit(), performs clipping and rectangle | |
614 * verification. The lower part is a pointer to a low level | |
615 * accelerated blitting function. | |
616 * | |
617 * These parts are separated out and each used internally by this | |
618 * library in the optimimum places. They are exported so that if | |
619 * you know exactly what you are doing, you can optimize your code | |
620 * by calling the one(s) you need. | |
621 */ | |
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
|
622 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
|
623 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
|
624 SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 625 { |
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
|
626 /* 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
|
627 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
|
628 (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
|
629 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
|
630 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
|
631 } |
2328
91e601d9df8b
re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents:
2267
diff
changeset
|
632 /* just here for debugging */ |
2329 | 633 /* printf */ |
634 /* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */ | |
635 /* src, dst->flags, src->map->info.flags, dst, dst->flags, */ | |
636 /* dst->map->info.flags, src->map->blit); */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
637 } |
2257
340942cfda48
Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents:
2253
diff
changeset
|
638 return (src->map->blit(src, srcrect, dst, dstrect)); |
0 | 639 } |
640 | |
641 | |
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
|
642 int |
4949
68da5a234bba
The source rectangle isn't modified in SDL_UpperBlit
Sam Lantinga <slouken@libsdl.org>
parents:
4929
diff
changeset
|
643 SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
644 SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 645 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
646 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
|
647 int srcx, srcy, w, h; |
0 | 648 |
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
|
649 /* 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
|
650 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
|
651 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
|
652 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
|
653 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 } |
0 | 658 |
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
|
659 /* 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
|
660 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
|
661 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
|
662 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
|
663 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
664 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
665 /* 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
|
666 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
|
667 int maxw, maxh; |
0 | 668 |
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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
676 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
|
677 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
|
678 w = maxw; |
0 | 679 |
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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
687 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
|
688 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
|
689 h = maxh; |
0 | 690 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
691 } 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
|
692 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
|
693 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
|
694 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
|
695 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
696 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
697 /* 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
|
698 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
699 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
|
700 int dx, dy; |
0 | 701 |
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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
708 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
|
709 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
|
710 w -= dx; |
0 | 711 |
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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
718 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
|
719 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
|
720 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
|
721 } |
0 | 722 |
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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
731 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
|
732 return 0; |
0 | 733 } |
734 | |
735 /* | |
736 * Lock a surface to directly access the pixels | |
737 */ | |
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
|
738 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
|
739 SDL_LockSurface(SDL_Surface * surface) |
0 | 740 { |
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
|
741 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
|
742 /* 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
|
743 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
|
744 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
|
745 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
|
746 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
747 } |
0 | 748 |
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 /* 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
|
750 ++surface->locked; |
0 | 751 |
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
|
752 /* 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
|
753 return (0); |
0 | 754 } |
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
|
755 |
0 | 756 /* |
757 * Unlock a previously locked surface | |
758 */ | |
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
|
759 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
|
760 SDL_UnlockSurface(SDL_Surface * surface) |
0 | 761 { |
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
|
762 /* 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
|
763 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
|
764 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
|
765 } |
0 | 766 |
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
|
767 /* 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
|
768 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
|
769 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
|
770 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
|
771 } |
0 | 772 } |
773 | |
774 /* | |
775 * Convert a surface into the specified pixel format. | |
776 */ | |
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
|
777 SDL_Surface * |
2807
365fe1a2aad5
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents:
2787
diff
changeset
|
778 SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format, |
365fe1a2aad5
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents:
2787
diff
changeset
|
779 Uint32 flags) |
0 | 780 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
781 SDL_Surface *convert; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
782 Uint32 copy_flags; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
783 SDL_Rect bounds; |
0 | 784 |
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
|
785 /* 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
|
786 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
|
787 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
|
788 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
|
789 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
|
790 (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
|
791 (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
|
792 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
|
793 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
794 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
|
795 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
|
796 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
|
797 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
798 } |
264
c9cd3b564e4b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
799 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
800 /* Create a new surface with the desired format */ |
2807
365fe1a2aad5
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
Sam Lantinga <slouken@libsdl.org>
parents:
2787
diff
changeset
|
801 convert = SDL_CreateRGBSurface(flags, surface->w, surface->h, |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 } |
0 | 808 |
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
|
809 /* 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 } |
0 | 816 |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
817 /* Save the original copy flags */ |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
818 copy_flags = surface->map->info.flags; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
819 surface->map->info.flags = 0; |
0 | 820 |
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
|
821 /* 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 SDL_LowerBlit(surface, &bounds, convert, &bounds); |
0 | 827 |
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
|
828 /* Clean up the original surface, and update converted surface */ |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
829 convert->map->info.r = surface->map->info.r; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
830 convert->map->info.g = surface->map->info.g; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
831 convert->map->info.b = surface->map->info.b; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
832 convert->map->info.a = surface->map->info.a; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
833 convert->map->info.flags = |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
834 (copy_flags & |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
835 ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
836 | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY | |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
837 SDL_COPY_RLE_ALPHAKEY)); |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
838 surface->map->info.flags = copy_flags; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
839 if (copy_flags & SDL_COPY_COLORKEY) { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
840 Uint8 keyR, keyG, keyB, keyA; |
0 | 841 |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
842 SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
843 &keyG, &keyB, &keyA); |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
844 SDL_SetColorKey(convert, 1, |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
845 SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
846 /* This is needed when converting for 3D texture upload */ |
2787
93764fe8601a
It turns out both the software and the OpenGL renderer had the same problem.
Sam Lantinga <slouken@libsdl.org>
parents:
2786
diff
changeset
|
847 SDL_ConvertColorkeyToAlpha(convert); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
848 } |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
849 SDL_SetClipRect(convert, &surface->clip_rect); |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
850 |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
851 /* Enable alpha blending by default if the new surface has an |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
852 * alpha channel or alpha modulation */ |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
853 if ((surface->format->Amask && format->Amask) || |
4491
2cd7bb613a83
Turn on blending if we're converting from a surface with colorkey enabled
Sam Lantinga <slouken@libsdl.org>
parents:
4461
diff
changeset
|
854 (copy_flags & (SDL_COPY_COLORKEY|SDL_COPY_MODULATE_ALPHA))) { |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
855 SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
856 } |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
857 if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) { |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
858 SDL_SetSurfaceRLE(convert, SDL_RLEACCEL); |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
859 } |
0 | 860 |
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
|
861 /* 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
|
862 return (convert); |
0 | 863 } |
864 | |
865 /* | |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
866 * Create a surface on the stack for quick blit operations |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
867 */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
868 static __inline__ SDL_bool |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
869 SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
870 void * pixels, int pitch, SDL_Surface * surface, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
871 SDL_PixelFormat * format, SDL_BlitMap * blitmap) |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
872 { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
873 int bpp; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
874 Uint32 Rmask, Gmask, Bmask, Amask; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
875 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
876 if (!SDL_PixelFormatEnumToMasks(pixel_format, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
877 &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
878 return SDL_FALSE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
879 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
880 if (bpp <= 8) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
881 SDL_SetError("Indexed pixel formats not supported"); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
882 return SDL_FALSE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
883 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
884 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
885 SDL_zerop(surface); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
886 surface->flags = SDL_PREALLOC; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
887 surface->format = SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
888 surface->pixels = pixels; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
889 surface->w = width; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
890 surface->h = height; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
891 surface->pitch = pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
892 /* We don't actually need to set up the clip rect for our purposes */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
893 /*SDL_SetClipRect(surface, NULL);*/ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
894 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
895 /* Allocate an empty mapping */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
896 SDL_zerop(blitmap); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
897 blitmap->info.r = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
898 blitmap->info.g = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
899 blitmap->info.b = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
900 blitmap->info.a = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
901 surface->map = blitmap; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
902 SDL_FormatChanged(surface); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
903 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
904 /* The surface is ready to go */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
905 surface->refcount = 1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
906 return SDL_TRUE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
907 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
908 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
909 /* |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
910 * Copy a block of pixels of one format to another format |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
911 */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
912 int SDL_ConvertPixels(int width, int height, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
913 Uint32 src_format, const void * src, int src_pitch, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
914 Uint32 dst_format, void * dst, int dst_pitch) |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
915 { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
916 SDL_Surface src_surface, dst_surface; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
917 SDL_PixelFormat src_fmt, dst_fmt; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
918 SDL_BlitMap src_blitmap, dst_blitmap; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
919 SDL_Rect rect; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
920 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
921 /* Fast path for same format copy */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
922 if (src_format == dst_format) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
923 int bpp; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
924 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
925 if (SDL_ISPIXELFORMAT_FOURCC(src_format)) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
926 switch (src_format) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
927 case SDL_PIXELFORMAT_YV12: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
928 case SDL_PIXELFORMAT_IYUV: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
929 case SDL_PIXELFORMAT_YUY2: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
930 case SDL_PIXELFORMAT_UYVY: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
931 case SDL_PIXELFORMAT_YVYU: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
932 bpp = 2; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
933 default: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
934 SDL_SetError("Unknown FOURCC pixel format"); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
935 return -1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
936 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
937 } else { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
938 bpp = SDL_BYTESPERPIXEL(src_format); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
939 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
940 width *= bpp; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
941 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
942 while (height-- > 0) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
943 SDL_memcpy(dst, src, width); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
944 src = (Uint8*)src + src_pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
945 dst = (Uint8*)dst + dst_pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
946 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
947 return SDL_TRUE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
948 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
949 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
950 if (!SDL_CreateSurfaceOnStack(width, height, src_format, (void*)src, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
951 src_pitch, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
952 &src_surface, &src_fmt, &src_blitmap)) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
953 return -1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
954 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
955 if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
956 &dst_surface, &dst_fmt, &dst_blitmap)) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
957 return -1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
958 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
959 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
960 /* Set up the rect and go! */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
961 rect.x = 0; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
962 rect.y = 0; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
963 rect.w = width; |
3436
0538362b98d3
Fixed memory corruption in SW_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3434
diff
changeset
|
964 rect.h = height; |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
965 return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
966 } |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
967 |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
968 /* |
0 | 969 * Free a surface created by the above function. |
970 */ | |
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
|
971 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
|
972 SDL_FreeSurface(SDL_Surface * surface) |
0 | 973 { |
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
|
974 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
|
975 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
|
976 } |
c121d94672cb
SDL 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 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
|
978 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
|
979 } |
c121d94672cb
SDL 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 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
|
981 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
|
982 } |
c121d94672cb
SDL 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 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
|
984 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
|
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 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
|
987 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
|
988 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
|
989 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
|
990 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
991 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
|
992 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
|
993 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
|
994 } |
c121d94672cb
SDL 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 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
|
996 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
|
997 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
998 SDL_free(surface); |
0 | 999 #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
|
1000 --surfaces_allocated; |
0 | 1001 #endif |
1002 } | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
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 /* vi: set ts=4 sw=4 expandtab: */ |