Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
347 lines (313 loc) · 9.3 KB

SDL_blendfillrect.c

File metadata and controls

347 lines (313 loc) · 9.3 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_video.h"
Dec 21, 2008
Dec 21, 2008
25
#include "SDL_draw.h"
Dec 21, 2008
Dec 21, 2008
27
static int
Dec 18, 2009
Dec 18, 2009
28
29
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
31
32
33
34
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
35
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
Dec 21, 2008
Dec 21, 2008
36
37
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
38
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
Dec 21, 2008
Dec 21, 2008
39
40
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
41
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555);
Dec 21, 2008
Dec 21, 2008
42
43
break;
default:
Dec 21, 2008
Dec 21, 2008
44
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
Dec 21, 2008
Dec 21, 2008
45
break;
Dec 21, 2008
Dec 21, 2008
47
48
return 0;
}
Dec 21, 2008
Dec 21, 2008
50
static int
Dec 18, 2009
Dec 18, 2009
51
52
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
53
54
55
56
57
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
58
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
Dec 21, 2008
Dec 21, 2008
59
60
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
61
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
Dec 21, 2008
Dec 21, 2008
62
63
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
64
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565);
Dec 21, 2008
Dec 21, 2008
65
66
break;
default:
Dec 21, 2008
Dec 21, 2008
67
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
Dec 21, 2008
Dec 21, 2008
68
break;
Dec 21, 2008
Dec 21, 2008
70
71
return 0;
}
Dec 21, 2008
Dec 21, 2008
73
static int
Dec 18, 2009
Dec 18, 2009
74
75
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
76
77
78
79
80
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
81
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
Dec 21, 2008
Dec 21, 2008
82
83
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
84
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
Dec 21, 2008
Dec 21, 2008
85
86
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
87
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888);
Dec 21, 2008
Dec 21, 2008
88
89
break;
default:
Dec 21, 2008
Dec 21, 2008
90
FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
Dec 21, 2008
Dec 21, 2008
91
break;
Dec 20, 2008
Dec 20, 2008
92
}
Dec 21, 2008
Dec 21, 2008
93
94
95
return 0;
}
Dec 21, 2008
Dec 21, 2008
96
static int
Dec 18, 2009
Dec 18, 2009
97
98
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
99
100
101
102
103
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
104
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
Dec 21, 2008
Dec 21, 2008
105
106
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
107
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
Dec 21, 2008
Dec 21, 2008
108
109
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
110
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888);
Dec 21, 2008
Dec 21, 2008
111
112
break;
default:
Dec 21, 2008
Dec 21, 2008
113
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
Dec 21, 2008
Dec 21, 2008
114
115
116
117
118
break;
}
return 0;
}
Dec 21, 2008
Dec 21, 2008
119
static int
Dec 18, 2009
Dec 18, 2009
120
121
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
122
123
124
125
126
127
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 2:
Dec 20, 2008
Dec 20, 2008
128
129
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
130
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
131
132
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
133
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
134
135
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
136
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB);
Dec 21, 2008
Dec 21, 2008
137
138
break;
default:
Dec 21, 2008
Dec 21, 2008
139
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
140
141
break;
}
Dec 21, 2008
Dec 21, 2008
142
143
return 0;
case 4:
Dec 20, 2008
Dec 20, 2008
144
145
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
146
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
147
148
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
149
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
150
151
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
152
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB);
Dec 21, 2008
Dec 21, 2008
153
154
break;
default:
Dec 21, 2008
Dec 21, 2008
155
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
156
157
break;
}
Dec 21, 2008
Dec 21, 2008
158
159
160
161
162
163
164
165
return 0;
default:
SDL_Unsupported();
return -1;
}
}
static int
Dec 18, 2009
Dec 18, 2009
166
167
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
168
169
170
171
172
173
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 4:
Dec 20, 2008
Dec 20, 2008
174
175
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
176
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
Dec 20, 2008
Dec 20, 2008
177
178
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
179
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
Dec 20, 2008
Dec 20, 2008
180
181
break;
case SDL_BLENDMODE_MOD:
Dec 21, 2008
Dec 21, 2008
182
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA);
Dec 21, 2008
Dec 21, 2008
183
184
break;
default:
Dec 21, 2008
Dec 21, 2008
185
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
Dec 20, 2008
Dec 20, 2008
186
187
break;
}
Dec 21, 2008
Dec 21, 2008
188
return 0;
Dec 20, 2008
Dec 20, 2008
189
190
191
192
default:
SDL_Unsupported();
return -1;
}
Dec 21, 2008
Dec 21, 2008
193
194
195
}
int
Dec 18, 2009
Dec 18, 2009
196
197
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
198
{
Dec 9, 2009
Dec 9, 2009
199
200
201
202
203
204
SDL_Rect clipped;
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
Dec 21, 2008
Dec 21, 2008
205
206
/* This function doesn't work on surfaces < 8 bpp */
Dec 9, 2009
Dec 9, 2009
207
if (dst->format->BitsPerPixel < 8) {
Dec 18, 2009
Dec 18, 2009
208
SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
209
return -1;
Dec 21, 2008
Dec 21, 2008
210
211
}
Dec 9, 2009
Dec 9, 2009
212
213
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
Dec 21, 2008
Dec 21, 2008
214
/* Perform clipping */
Dec 9, 2009
Dec 9, 2009
215
216
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
return 0;
Dec 21, 2008
Dec 21, 2008
217
}
Dec 9, 2009
Dec 9, 2009
218
rect = &clipped;
Dec 21, 2008
Dec 21, 2008
219
} else {
Dec 9, 2009
Dec 9, 2009
220
rect = &dst->clip_rect;
Dec 21, 2008
Dec 21, 2008
221
222
}
Dec 9, 2009
Dec 9, 2009
223
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
Dec 21, 2008
Dec 21, 2008
224
225
226
227
228
r = DRAW_MUL(r, a);
g = DRAW_MUL(g, a);
b = DRAW_MUL(b, a);
}
Dec 9, 2009
Dec 9, 2009
229
switch (dst->format->BitsPerPixel) {
Dec 21, 2008
Dec 21, 2008
230
case 15:
Dec 9, 2009
Dec 9, 2009
231
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
232
case 0x7C00:
Dec 18, 2009
Dec 18, 2009
233
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
234
235
236
}
break;
case 16:
Dec 9, 2009
Dec 9, 2009
237
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
238
case 0xF800:
Dec 18, 2009
Dec 18, 2009
239
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
240
241
242
}
break;
case 32:
Dec 9, 2009
Dec 9, 2009
243
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
244
case 0x00FF0000:
Dec 9, 2009
Dec 9, 2009
245
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
246
return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
247
} else {
Dec 18, 2009
Dec 18, 2009
248
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
249
250
251
}
break;
}
Dec 9, 2009
Dec 9, 2009
252
break;
Dec 21, 2008
Dec 21, 2008
253
254
255
256
default:
break;
}
Dec 9, 2009
Dec 9, 2009
257
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
258
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
259
} else {
Dec 18, 2009
Dec 18, 2009
260
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
Dec 9, 2009
Dec 9, 2009
261
262
263
264
}
}
int
Dec 18, 2009
Dec 18, 2009
265
266
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 9, 2009
Dec 9, 2009
267
268
269
270
271
272
273
274
275
276
277
278
279
280
{
SDL_Rect clipped;
int i;
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
Dec 18, 2009
Dec 18, 2009
281
SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
282
283
284
285
286
287
288
289
290
291
292
293
294
295
return -1;
}
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(r, a);
g = DRAW_MUL(g, a);
b = DRAW_MUL(b, a);
}
/* FIXME: Does this function pointer slow things down significantly? */
switch (dst->format->BitsPerPixel) {
case 15:
switch (dst->format->Rmask) {
case 0x7C00:
Dec 18, 2009
Dec 18, 2009
296
func = SDL_BlendFillRect_RGB555;
Dec 9, 2009
Dec 9, 2009
297
298
299
300
301
}
break;
case 16:
switch (dst->format->Rmask) {
case 0xF800:
Dec 18, 2009
Dec 18, 2009
302
func = SDL_BlendFillRect_RGB565;
Dec 9, 2009
Dec 9, 2009
303
304
305
306
307
308
}
break;
case 32:
switch (dst->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
309
func = SDL_BlendFillRect_RGB888;
Dec 9, 2009
Dec 9, 2009
310
} else {
Dec 18, 2009
Dec 18, 2009
311
func = SDL_BlendFillRect_ARGB8888;
Dec 9, 2009
Dec 9, 2009
312
313
314
315
316
317
318
319
320
321
}
break;
}
break;
default:
break;
}
if (!func) {
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
322
func = SDL_BlendFillRect_RGB;
Dec 9, 2009
Dec 9, 2009
323
} else {
Dec 18, 2009
Dec 18, 2009
324
func = SDL_BlendFillRect_RGBA;
Dec 9, 2009
Dec 9, 2009
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
}
}
for (i = 0; i < count; ++i) {
const SDL_Rect * rect = rects[i];
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
/* Perform clipping */
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
continue;
}
rect = &clipped;
} else {
rect = &dst->clip_rect;
}
status = func(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
343
}
Dec 9, 2009
Dec 9, 2009
344
return status;
345
346
347
}
/* vi: set ts=4 sw=4 expandtab: */