author | Sam Lantinga <slouken@libsdl.org> |
Mon, 07 Mar 2011 00:30:05 -0800 | |
changeset 5438 | b705640cb34a |
parent 5375 | 16877f74123c |
child 5499 | 2b8e6d1e3817 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
SDL - Simple DirectMedia Layer |
|
5262 | 3 |
Copyright (C) 1997-2011 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 |
||
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1155
diff
changeset
|
31 |
|
0 | 32 |
/* Public routines */ |
33 |
/* |
|
34 |
* Create an empty RGB surface of the appropriate depth |
|
35 |
*/ |
|
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) |
0 | 40 |
{ |
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
|
41 |
SDL_Surface *surface; |
5288 | 42 |
Uint32 format; |
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 |
|
5288 | 47 |
/* Get the pixel format */ |
48 |
format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask); |
|
49 |
if (format == SDL_PIXELFORMAT_UNKNOWN) { |
|
50 |
SDL_SetError("Unknown pixel format"); |
|
51 |
return NULL; |
|
52 |
} |
|
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 |
/* 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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
} |
940
bb1588ebe47b
Date: Sat, 10 Jul 2004 21:02:33 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
915
diff
changeset
|
60 |
|
5288 | 61 |
surface->format = SDL_AllocFormat(format); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
66 |
surface->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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
|
5288 | 71 |
if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
} |
5438
b705640cb34a
Fixed bitmap order interpretation; SDL defaults to MSB ordering so a bitstream corresponds to a pixel stream.
Sam Lantinga <slouken@libsdl.org>
parents:
5375
diff
changeset
|
78 |
if (palette->ncolors == 2) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
79 |
/* 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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
87 |
SDL_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
|
88 |
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
|
89 |
} |
0 | 90 |
|
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
|
91 |
/* 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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
} |
c121d94672cb
SDL 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 |
/* 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
|
100 |
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
|
101 |
} |
0 | 102 |
|
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
|
103 |
/* 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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
} |
c121d94672cb
SDL 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 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
110 |
/* 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
|
111 |
if (Amask) { |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
112 |
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
|
113 |
} |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
114 |
|
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
|
115 |
/* 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
|
116 |
surface->refcount = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
117 |
return surface; |
0 | 118 |
} |
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
|
119 |
|
0 | 120 |
/* |
121 |
* Create an RGB surface from an existing memory buffer |
|
122 |
*/ |
|
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
Uint32 Amask) |
0 | 128 |
{ |
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
|
129 |
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
|
130 |
|
c121d94672cb
SDL 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 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
141 |
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
|
142 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
143 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
{ |
5288 | 147 |
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
|
148 |
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
|
149 |
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
|
150 |
} |
5288 | 151 |
return SDL_SetPixelFormatPalette(surface->format, palette); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
152 |
} |
c121d94672cb
SDL 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 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
154 |
int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
155 |
SDL_SetSurfaceRLE(SDL_Surface * surface, int flag) |
0 | 156 |
{ |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
157 |
int flags; |
0 | 158 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
} |
0 | 162 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
163 |
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
|
164 |
if (flag) { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
165 |
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
|
166 |
} else { |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
167 |
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
|
168 |
} |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
172 |
return 0; |
0 | 173 |
} |
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
|
174 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
175 |
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
|
176 |
SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key) |
0 | 177 |
{ |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
178 |
int flags; |
0 | 179 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
183 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
} |
0 | 187 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
} else { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
193 |
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
|
194 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
} |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
198 |
|
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
199 |
/* Compatibility mode */ |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
200 |
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
|
201 |
surface->flags |= SDL_SRCCOLORKEY; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
202 |
} else { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
203 |
surface->flags &= ~SDL_SRCCOLORKEY; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
204 |
} |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
205 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
206 |
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
|
207 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
208 |
|
3103 | 209 |
int |
210 |
SDL_GetColorKey(SDL_Surface * surface, Uint32 * key) |
|
211 |
{ |
|
212 |
if (!surface) { |
|
213 |
return -1; |
|
214 |
} |
|
215 |
||
216 |
if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) { |
|
217 |
return -1; |
|
218 |
} |
|
219 |
||
220 |
if (key) { |
|
221 |
*key = surface->map->info.colorkey; |
|
222 |
} |
|
223 |
return 0; |
|
224 |
} |
|
225 |
||
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
226 |
/* 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
|
227 |
static void |
2786 | 228 |
SDL_ConvertColorkeyToAlpha(SDL_Surface * surface) |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
229 |
{ |
2786 | 230 |
int x, y; |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
231 |
|
2786 | 232 |
if (!surface) { |
233 |
return; |
|
234 |
} |
|
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
235 |
|
2786 | 236 |
if (!(surface->map->info.flags & SDL_COPY_COLORKEY) || |
237 |
!surface->format->Amask) { |
|
238 |
return; |
|
239 |
} |
|
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
240 |
|
2786 | 241 |
SDL_LockSurface(surface); |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
242 |
|
2786 | 243 |
switch (surface->format->BytesPerPixel) { |
244 |
case 2: |
|
245 |
{ |
|
246 |
Uint16 *row, *spot; |
|
247 |
Uint16 ckey = (Uint16) surface->map->info.colorkey; |
|
248 |
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
|
249 |
|
2786 | 250 |
row = (Uint16 *) surface->pixels; |
251 |
for (y = surface->h; y--;) { |
|
252 |
spot = row; |
|
253 |
for (x = surface->w; x--;) { |
|
254 |
if (*spot == ckey) { |
|
255 |
*spot &= mask; |
|
256 |
} |
|
257 |
++spot; |
|
258 |
} |
|
259 |
row += surface->pitch / 2; |
|
260 |
} |
|
261 |
} |
|
262 |
break; |
|
263 |
case 3: |
|
264 |
/* FIXME */ |
|
265 |
break; |
|
266 |
case 4: |
|
267 |
{ |
|
268 |
Uint32 *row, *spot; |
|
269 |
Uint32 ckey = surface->map->info.colorkey; |
|
270 |
Uint32 mask = ~surface->format->Amask; |
|
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
271 |
|
2786 | 272 |
row = (Uint32 *) surface->pixels; |
273 |
for (y = surface->h; y--;) { |
|
274 |
spot = row; |
|
275 |
for (x = surface->w; x--;) { |
|
276 |
if (*spot == ckey) { |
|
277 |
*spot &= mask; |
|
278 |
} |
|
279 |
++spot; |
|
280 |
} |
|
281 |
row += surface->pitch / 4; |
|
282 |
} |
|
283 |
} |
|
284 |
break; |
|
285 |
} |
|
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
286 |
|
2786 | 287 |
SDL_UnlockSurface(surface); |
2785
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
288 |
|
2786 | 289 |
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
|
290 |
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
|
291 |
} |
fa1095d42a5b
Fixed bug with converting colorkey surface to texture
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
292 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
293 |
int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
294 |
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
|
295 |
{ |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
296 |
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
|
297 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
} |
0 | 301 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
302 |
surface->map->info.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
|
303 |
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
|
304 |
surface->map->info.b = b; |
0 | 305 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
} 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
|
310 |
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
|
311 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
315 |
return 0; |
0 | 316 |
} |
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
|
317 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
318 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
319 |
int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
320 |
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
|
321 |
{ |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
325 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
326 |
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
|
327 |
*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
|
328 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
329 |
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
|
330 |
*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
|
331 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
332 |
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
|
333 |
*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
|
334 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
335 |
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
|
336 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
337 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
338 |
int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
339 |
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
|
340 |
{ |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
341 |
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
|
342 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
} |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
346 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
347 |
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
|
348 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
349 |
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
|
350 |
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
|
351 |
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
|
352 |
} else { |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
353 |
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
|
354 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
358 |
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
|
359 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
360 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
361 |
int |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
362 |
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
|
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 |
} |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
367 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
368 |
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
|
369 |
*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
|
370 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
371 |
return 0; |
431
41cadcba32e8
Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
Sam Lantinga <slouken@libsdl.org>
parents:
422
diff
changeset
|
372 |
} |
0 | 373 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
374 |
int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
375 |
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
|
376 |
{ |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
377 |
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
|
378 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
379 |
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
|
380 |
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
|
381 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
382 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
383 |
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
|
384 |
flags = surface->map->info.flags; |
5184
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
385 |
surface->map->info.flags &= |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
386 |
~(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
|
387 |
switch (blendMode) { |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
388 |
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
|
389 |
break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
390 |
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
|
391 |
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
|
392 |
break; |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
393 |
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
|
394 |
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
|
395 |
break; |
5184
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
396 |
case SDL_BLENDMODE_MOD: |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
397 |
surface->map->info.flags |= SDL_COPY_MOD; |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
398 |
break; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
399 |
default: |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
400 |
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
|
401 |
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
|
402 |
break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
403 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
404 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
405 |
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
|
406 |
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
|
407 |
} |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
408 |
|
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
409 |
/* Compatibility mode */ |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
410 |
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
|
411 |
surface->flags |= SDL_SRCALPHA; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
412 |
} else { |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
413 |
surface->flags &= ~SDL_SRCALPHA; |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
414 |
} |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
415 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
416 |
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
|
417 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
418 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
419 |
int |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4491
diff
changeset
|
420 |
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
|
421 |
{ |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
422 |
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
|
423 |
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
|
424 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
425 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
426 |
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
|
427 |
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
|
428 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
429 |
|
5184
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
430 |
switch (surface->map-> |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
431 |
info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) { |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
432 |
case SDL_COPY_BLEND: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
433 |
*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
|
434 |
break; |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
435 |
case SDL_COPY_ADD: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
436 |
*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
|
437 |
break; |
5184
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
438 |
case SDL_COPY_MOD: |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
439 |
*blendMode = SDL_BLENDMODE_MOD; |
d976b67150c5
Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents:
5140
diff
changeset
|
440 |
break; |
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
441 |
default: |
2884
9dde605c7540
Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
442 |
*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
|
443 |
break; |
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 |
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
|
446 |
} |
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
447 |
|
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
|
448 |
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
|
449 |
SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect) |
0 | 450 |
{ |
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
|
451 |
SDL_Rect full_rect; |
0 | 452 |
|
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
|
453 |
/* 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
|
454 |
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
|
455 |
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
|
456 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
457 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
458 |
/* 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
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
full_rect.h = surface->h; |
0 | 463 |
|
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
|
464 |
/* 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
|
465 |
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
|
466 |
surface->clip_rect = full_rect; |
4966 | 467 |
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
|
468 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
469 |
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
|
470 |
} |
0 | 471 |
|
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
|
472 |
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
|
473 |
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
|
474 |
{ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
475 |
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
|
476 |
*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
|
477 |
} |
0 | 478 |
} |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
479 |
|
0 | 480 |
/* |
481 |
* Set up a blit between two surfaces -- split into three parts: |
|
482 |
* The upper part, SDL_UpperBlit(), performs clipping and rectangle |
|
483 |
* verification. The lower part is a pointer to a low level |
|
484 |
* accelerated blitting function. |
|
485 |
* |
|
486 |
* These parts are separated out and each used internally by this |
|
487 |
* library in the optimimum places. They are exported so that if |
|
488 |
* you know exactly what you are doing, you can optimize your code |
|
489 |
* by calling the one(s) you need. |
|
490 |
*/ |
|
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
|
491 |
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
|
492 |
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
|
493 |
SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 494 |
{ |
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
|
495 |
/* 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
|
496 |
if ((src->map->dst != dst) || |
5288 | 497 |
(dst->format->palette && |
498 |
src->map->palette_version != dst->format->palette->version)) { |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
499 |
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
|
500 |
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
|
501 |
} |
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
|
502 |
/* just here for debugging */ |
2329 | 503 |
/* printf */ |
504 |
/* ("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", */ |
|
505 |
/* src, dst->flags, src->map->info.flags, dst, dst->flags, */ |
|
506 |
/* 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
|
507 |
} |
2257
340942cfda48
Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents:
2253
diff
changeset
|
508 |
return (src->map->blit(src, srcrect, dst, dstrect)); |
0 | 509 |
} |
510 |
||
511 |
||
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
|
512 |
int |
4949
68da5a234bba
The source rectangle isn't modified in SDL_UpperBlit
Sam Lantinga <slouken@libsdl.org>
parents:
4929
diff
changeset
|
513 |
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
|
514 |
SDL_Surface * dst, SDL_Rect * dstrect) |
0 | 515 |
{ |
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
|
516 |
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
|
517 |
int srcx, srcy, w, h; |
0 | 518 |
|
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
|
519 |
/* 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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
} |
0 | 528 |
|
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
|
529 |
/* 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
|
530 |
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
|
531 |
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
|
532 |
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
|
533 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
534 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
535 |
/* 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
|
536 |
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
|
537 |
int maxw, maxh; |
0 | 538 |
|
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
|
539 |
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
|
540 |
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
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
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
|
545 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
546 |
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
|
547 |
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
|
548 |
w = maxw; |
0 | 549 |
|
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
|
550 |
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
|
551 |
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
|
552 |
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
|
553 |
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
|
554 |
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
|
555 |
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
|
556 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
557 |
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
|
558 |
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
|
559 |
h = maxh; |
0 | 560 |
|
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
|
561 |
} 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
|
562 |
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
|
563 |
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
|
564 |
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
|
565 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
566 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
567 |
/* 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
|
568 |
{ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
569 |
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
|
570 |
int dx, dy; |
0 | 571 |
|
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
|
572 |
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
|
573 |
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
|
574 |
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
|
575 |
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
|
576 |
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
|
577 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
578 |
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
|
579 |
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
|
580 |
w -= dx; |
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 |
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
|
583 |
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
|
584 |
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
|
585 |
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
|
586 |
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
|
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 |
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
|
589 |
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
|
590 |
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
|
591 |
} |
0 | 592 |
|
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
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
|
599 |
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
|
600 |
} |
c121d94672cb
SDL 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 |
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
|
602 |
return 0; |
0 | 603 |
} |
604 |
||
605 |
/* |
|
5296
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
606 |
* Scale and blit a surface |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
607 |
*/ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
608 |
int |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
609 |
SDL_BlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
610 |
SDL_Surface * dst, const SDL_Rect * dstrect) |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
611 |
{ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
612 |
/* Save off the original dst width, height */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
613 |
int dstW = dstrect->w; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
614 |
int dstH = dstrect->h; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
615 |
SDL_Rect final_dst = *dstrect; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
616 |
SDL_Rect final_src = *srcrect; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
617 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
618 |
/* Clip the dst surface to the dstrect */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
619 |
SDL_SetClipRect( dst, &final_dst ); |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
620 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
621 |
/* If the dest was clipped to a zero sized rect then exit */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
622 |
if ( dst->clip_rect.w <= 0 || dst->clip_rect.h <= 0 ) { |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
623 |
return -1; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
624 |
} |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
625 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
626 |
/* Did the dst width change? */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
627 |
if ( dstW != dst->clip_rect.w ) { |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
628 |
/* scale the src width appropriately */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
629 |
final_src.w = final_src.w * dst->clip_rect.w / dstW; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
630 |
} |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
631 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
632 |
/* Did the dst height change? */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
633 |
if ( dstH != dst->clip_rect.h ) { |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
634 |
/* scale the src width appropriately */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
635 |
final_src.h = final_src.h * dst->clip_rect.h / dstH; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
636 |
} |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
637 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
638 |
/* Clip the src surface to the srcrect */ |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
639 |
SDL_SetClipRect( src, &final_src ); |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
640 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
641 |
src->map->info.flags |= SDL_COPY_NEAREST; |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
642 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
643 |
if ( src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) { |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
644 |
return SDL_SoftStretch( src, &final_src, dst, &final_dst ); |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
645 |
} else { |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
646 |
return SDL_LowerBlit( src, &final_src, dst, &final_dst ); |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
647 |
} |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
648 |
} |
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
649 |
|
48067bfc300c
Software scaling support. Not very fast, but it seems to work.
Ken Rogoway <ken@rogoway.com>
parents:
5288
diff
changeset
|
650 |
/* |
0 | 651 |
* Lock a surface to directly access the pixels |
652 |
*/ |
|
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
|
653 |
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
|
654 |
SDL_LockSurface(SDL_Surface * surface) |
0 | 655 |
{ |
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
|
656 |
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
|
657 |
/* 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
|
658 |
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
|
659 |
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
|
660 |
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
|
661 |
} |
c121d94672cb
SDL 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 |
} |
0 | 663 |
|
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
|
664 |
/* 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
|
665 |
++surface->locked; |
0 | 666 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
667 |
/* 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
|
668 |
return (0); |
0 | 669 |
} |
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
|
670 |
|
0 | 671 |
/* |
672 |
* Unlock a previously locked surface |
|
673 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
674 |
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
|
675 |
SDL_UnlockSurface(SDL_Surface * surface) |
0 | 676 |
{ |
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
|
677 |
/* 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
|
678 |
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
|
679 |
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
|
680 |
} |
0 | 681 |
|
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
|
682 |
/* 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
|
683 |
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
|
684 |
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
|
685 |
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
|
686 |
} |
0 | 687 |
} |
688 |
||
689 |
/* |
|
690 |
* Convert a surface into the specified pixel format. |
|
691 |
*/ |
|
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
|
692 |
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
|
693 |
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
|
694 |
Uint32 flags) |
0 | 695 |
{ |
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
|
696 |
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
|
697 |
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
|
698 |
SDL_Rect bounds; |
0 | 699 |
|
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
|
700 |
/* 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
|
701 |
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
|
702 |
int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
703 |
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
|
704 |
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
|
705 |
(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
|
706 |
(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
|
707 |
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
|
708 |
} |
c121d94672cb
SDL 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 (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
|
710 |
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
|
711 |
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
|
712 |
} |
c121d94672cb
SDL 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 |
} |
264
c9cd3b564e4b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
714 |
|
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
|
715 |
/* 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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
} |
0 | 723 |
|
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
|
724 |
/* 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
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
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
|
729 |
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
|
730 |
} |
0 | 731 |
|
2266
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
732 |
/* 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
|
733 |
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
|
734 |
surface->map->info.flags = 0; |
0 | 735 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
736 |
/* 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
|
737 |
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
|
738 |
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
|
739 |
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
|
740 |
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
|
741 |
SDL_LowerBlit(surface, &bounds, convert, &bounds); |
0 | 742 |
|
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
|
743 |
/* 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
|
744 |
convert->map->info.r = surface->map->info.r; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
745 |
convert->map->info.g = surface->map->info.g; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
746 |
convert->map->info.b = surface->map->info.b; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
747 |
convert->map->info.a = surface->map->info.a; |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
748 |
convert->map->info.flags = |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
749 |
(copy_flags & |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
750 |
~(SDL_COPY_COLORKEY | SDL_COPY_BLEND |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
751 |
| SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY | |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
752 |
SDL_COPY_RLE_ALPHAKEY)); |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
753 |
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
|
754 |
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
|
755 |
Uint8 keyR, keyG, keyB, keyA; |
0 | 756 |
|
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
2266
diff
changeset
|
757 |
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
|
758 |
&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
|
759 |
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
|
760 |
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
|
761 |
/* 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
|
762 |
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
|
763 |
} |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
764 |
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
|
765 |
|
e61ad15a205f
More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents:
2260
diff
changeset
|
766 |
/* 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
|
767 |
* alpha channel or alpha modulation */ |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
768 |
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
|
769 |
(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
|
770 |
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
|
771 |
} |
2824
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
772 |
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
|
773 |
SDL_SetSurfaceRLE(convert, SDL_RLEACCEL); |
4dba7aa7ea77
Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents:
2807
diff
changeset
|
774 |
} |
0 | 775 |
|
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
|
776 |
/* 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
|
777 |
return (convert); |
0 | 778 |
} |
779 |
||
5375
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
780 |
SDL_Surface * |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
781 |
SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format, |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
782 |
Uint32 flags) |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
783 |
{ |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
784 |
SDL_PixelFormat *fmt; |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
785 |
SDL_Surface *convert; |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
786 |
|
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
787 |
fmt = SDL_AllocFormat(pixel_format); |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
788 |
if (fmt) { |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
789 |
convert = SDL_ConvertSurface(surface, fmt, flags); |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
790 |
SDL_FreeFormat(fmt); |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
791 |
} |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
792 |
return convert; |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
793 |
} |
16877f74123c
Implemented Cocoa_SetWindowIcon(), added SDL_ConvertSurfaceFormat()
Sam Lantinga <slouken@libsdl.org>
parents:
5296
diff
changeset
|
794 |
|
0 | 795 |
/* |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
796 |
* 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
|
797 |
*/ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
798 |
static __inline__ SDL_bool |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
799 |
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
|
800 |
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
|
801 |
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
|
802 |
{ |
5288 | 803 |
if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) { |
804 |
SDL_SetError("Indexed pixel formats not supported"); |
|
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
805 |
return SDL_FALSE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
806 |
} |
5288 | 807 |
if (SDL_InitFormat(format, pixel_format) < 0) { |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
808 |
return SDL_FALSE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
809 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
810 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
811 |
SDL_zerop(surface); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
812 |
surface->flags = SDL_PREALLOC; |
5288 | 813 |
surface->format = format; |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
814 |
surface->pixels = pixels; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
815 |
surface->w = width; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
816 |
surface->h = height; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
817 |
surface->pitch = pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
818 |
/* 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
|
819 |
/*SDL_SetClipRect(surface, NULL);*/ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
820 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
821 |
/* Allocate an empty mapping */ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
822 |
SDL_zerop(blitmap); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
823 |
blitmap->info.r = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
824 |
blitmap->info.g = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
825 |
blitmap->info.b = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
826 |
blitmap->info.a = 0xFF; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
827 |
surface->map = blitmap; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
828 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
829 |
/* 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
|
830 |
surface->refcount = 1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
831 |
return SDL_TRUE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
832 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
833 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
834 |
/* |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
835 |
* 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
|
836 |
*/ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
837 |
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
|
838 |
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
|
839 |
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
|
840 |
{ |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
841 |
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
|
842 |
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
|
843 |
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
|
844 |
SDL_Rect rect; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
845 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
846 |
/* 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
|
847 |
if (src_format == dst_format) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
848 |
int bpp; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
849 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
850 |
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
|
851 |
switch (src_format) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
852 |
case SDL_PIXELFORMAT_YV12: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
853 |
case SDL_PIXELFORMAT_IYUV: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
854 |
case SDL_PIXELFORMAT_YUY2: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
855 |
case SDL_PIXELFORMAT_UYVY: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
856 |
case SDL_PIXELFORMAT_YVYU: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
857 |
bpp = 2; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
858 |
default: |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
859 |
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
|
860 |
return -1; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
861 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
862 |
} else { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
863 |
bpp = SDL_BYTESPERPIXEL(src_format); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
864 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
865 |
width *= bpp; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
866 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
867 |
while (height-- > 0) { |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
868 |
SDL_memcpy(dst, src, width); |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
869 |
src = (Uint8*)src + src_pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
870 |
dst = (Uint8*)dst + dst_pitch; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
871 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
872 |
return SDL_TRUE; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
873 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
874 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
875 |
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
|
876 |
src_pitch, |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
877 |
&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
|
878 |
return -1; |
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 (!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
|
881 |
&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
|
882 |
return -1; |
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 |
/* 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
|
886 |
rect.x = 0; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
887 |
rect.y = 0; |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
888 |
rect.w = width; |
3436
0538362b98d3
Fixed memory corruption in SW_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents:
3434
diff
changeset
|
889 |
rect.h = height; |
3434
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
890 |
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
|
891 |
} |
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
892 |
|
147d6ef5be03
Added a utility function to convert blocks of pixels
Sam Lantinga <slouken@libsdl.org>
parents:
3103
diff
changeset
|
893 |
/* |
0 | 894 |
* Free a surface created by the above function. |
895 |
*/ |
|
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
|
896 |
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
|
897 |
SDL_FreeSurface(SDL_Surface * surface) |
0 | 898 |
{ |
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
|
899 |
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
|
900 |
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
|
901 |
} |
5288 | 902 |
if (surface->flags & SDL_DONTFREE) { |
903 |
return; |
|
904 |
} |
|
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
|
905 |
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
|
906 |
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
|
907 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
908 |
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
|
909 |
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
|
910 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
911 |
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
|
912 |
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
|
913 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
914 |
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
|
915 |
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
|
916 |
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
|
917 |
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
|
918 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
919 |
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
|
920 |
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
|
921 |
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
|
922 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
923 |
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
|
924 |
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
|
925 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
926 |
SDL_free(surface); |
0 | 927 |
} |
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
|
928 |
|
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1456
diff
changeset
|
929 |
/* vi: set ts=4 sw=4 expandtab: */ |