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

Latest commit

 

History

History
348 lines (313 loc) · 9.4 KB

SDL_blendfillrect.c

File metadata and controls

348 lines (313 loc) · 9.4 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
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"
Dec 21, 2008
Dec 21, 2008
24
#include "SDL_draw.h"
Feb 3, 2011
Feb 3, 2011
25
26
#include "SDL_blendfillrect.h"
Dec 21, 2008
Dec 21, 2008
28
static int
Dec 18, 2009
Dec 18, 2009
29
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
30
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
32
33
34
35
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
36
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
Dec 21, 2008
Dec 21, 2008
37
38
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
39
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
Dec 21, 2008
Dec 21, 2008
40
break;
Feb 5, 2011
Feb 5, 2011
41
42
43
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555);
break;
Dec 21, 2008
Dec 21, 2008
44
default:
Dec 21, 2008
Dec 21, 2008
45
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
Dec 21, 2008
Dec 21, 2008
46
break;
Dec 21, 2008
Dec 21, 2008
48
49
return 0;
}
Dec 21, 2008
Dec 21, 2008
51
static int
Dec 18, 2009
Dec 18, 2009
52
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
53
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
54
55
56
57
58
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
59
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
Dec 21, 2008
Dec 21, 2008
60
61
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
62
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
Dec 21, 2008
Dec 21, 2008
63
break;
Feb 5, 2011
Feb 5, 2011
64
65
66
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565);
break;
Dec 21, 2008
Dec 21, 2008
67
default:
Dec 21, 2008
Dec 21, 2008
68
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
Dec 21, 2008
Dec 21, 2008
69
break;
Dec 21, 2008
Dec 21, 2008
71
72
return 0;
}
Dec 21, 2008
Dec 21, 2008
74
static int
Dec 18, 2009
Dec 18, 2009
75
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
76
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
77
78
79
80
81
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
82
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
Dec 21, 2008
Dec 21, 2008
83
84
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
85
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
Dec 21, 2008
Dec 21, 2008
86
break;
Feb 5, 2011
Feb 5, 2011
87
88
89
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888);
break;
Dec 21, 2008
Dec 21, 2008
90
default:
Dec 21, 2008
Dec 21, 2008
91
FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
Dec 21, 2008
Dec 21, 2008
92
break;
Dec 20, 2008
Dec 20, 2008
93
}
Dec 21, 2008
Dec 21, 2008
94
95
96
return 0;
}
Dec 21, 2008
Dec 21, 2008
97
static int
Dec 18, 2009
Dec 18, 2009
98
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
99
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
100
101
102
103
104
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
105
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
Dec 21, 2008
Dec 21, 2008
106
107
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
108
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
Dec 21, 2008
Dec 21, 2008
109
break;
Feb 5, 2011
Feb 5, 2011
110
111
112
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888);
break;
Dec 21, 2008
Dec 21, 2008
113
default:
Dec 21, 2008
Dec 21, 2008
114
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
Dec 21, 2008
Dec 21, 2008
115
116
117
118
119
break;
}
return 0;
}
Dec 21, 2008
Dec 21, 2008
120
static int
Dec 18, 2009
Dec 18, 2009
121
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
122
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
123
124
125
126
127
128
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 2:
Dec 20, 2008
Dec 20, 2008
129
130
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
131
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
132
133
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
134
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
135
break;
Feb 5, 2011
Feb 5, 2011
136
137
138
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB);
break;
Dec 21, 2008
Dec 21, 2008
139
default:
Dec 21, 2008
Dec 21, 2008
140
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
141
142
break;
}
Dec 21, 2008
Dec 21, 2008
143
144
return 0;
case 4:
Dec 20, 2008
Dec 20, 2008
145
146
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
147
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
148
149
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
150
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
151
break;
Feb 5, 2011
Feb 5, 2011
152
153
154
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB);
break;
Dec 21, 2008
Dec 21, 2008
155
default:
Dec 21, 2008
Dec 21, 2008
156
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
157
158
break;
}
Dec 21, 2008
Dec 21, 2008
159
160
161
162
163
164
165
166
return 0;
default:
SDL_Unsupported();
return -1;
}
}
static int
Dec 18, 2009
Dec 18, 2009
167
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
168
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
169
170
171
172
173
174
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 4:
Dec 20, 2008
Dec 20, 2008
175
176
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
177
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
Dec 20, 2008
Dec 20, 2008
178
179
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
180
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
Dec 20, 2008
Dec 20, 2008
181
break;
Feb 5, 2011
Feb 5, 2011
182
183
184
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA);
break;
Dec 21, 2008
Dec 21, 2008
185
default:
Dec 21, 2008
Dec 21, 2008
186
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
Dec 20, 2008
Dec 20, 2008
187
188
break;
}
Dec 21, 2008
Dec 21, 2008
189
return 0;
Dec 20, 2008
Dec 20, 2008
190
191
192
193
default:
SDL_Unsupported();
return -1;
}
Dec 21, 2008
Dec 21, 2008
194
195
196
}
int
Dec 18, 2009
Dec 18, 2009
197
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
198
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
199
{
Dec 9, 2009
Dec 9, 2009
200
201
202
203
204
205
SDL_Rect clipped;
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
Dec 21, 2008
Dec 21, 2008
206
207
/* This function doesn't work on surfaces < 8 bpp */
Dec 9, 2009
Dec 9, 2009
208
if (dst->format->BitsPerPixel < 8) {
Dec 18, 2009
Dec 18, 2009
209
SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
210
return -1;
Dec 21, 2008
Dec 21, 2008
211
212
}
Dec 9, 2009
Dec 9, 2009
213
214
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
Dec 21, 2008
Dec 21, 2008
215
/* Perform clipping */
Dec 9, 2009
Dec 9, 2009
216
217
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
return 0;
Dec 21, 2008
Dec 21, 2008
218
}
Dec 9, 2009
Dec 9, 2009
219
rect = &clipped;
Dec 21, 2008
Dec 21, 2008
220
} else {
Dec 9, 2009
Dec 9, 2009
221
rect = &dst->clip_rect;
Dec 21, 2008
Dec 21, 2008
222
223
}
Dec 9, 2009
Dec 9, 2009
224
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
Dec 21, 2008
Dec 21, 2008
225
226
227
228
229
r = DRAW_MUL(r, a);
g = DRAW_MUL(g, a);
b = DRAW_MUL(b, a);
}
Dec 9, 2009
Dec 9, 2009
230
switch (dst->format->BitsPerPixel) {
Dec 21, 2008
Dec 21, 2008
231
case 15:
Dec 9, 2009
Dec 9, 2009
232
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
233
case 0x7C00:
Dec 18, 2009
Dec 18, 2009
234
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
235
236
237
}
break;
case 16:
Dec 9, 2009
Dec 9, 2009
238
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
239
case 0xF800:
Dec 18, 2009
Dec 18, 2009
240
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
241
242
243
}
break;
case 32:
Dec 9, 2009
Dec 9, 2009
244
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
245
case 0x00FF0000:
Dec 9, 2009
Dec 9, 2009
246
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
247
return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
248
} else {
Dec 18, 2009
Dec 18, 2009
249
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
250
251
252
}
break;
}
Dec 9, 2009
Dec 9, 2009
253
break;
Dec 21, 2008
Dec 21, 2008
254
255
256
257
default:
break;
}
Dec 9, 2009
Dec 9, 2009
258
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
259
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
260
} else {
Dec 18, 2009
Dec 18, 2009
261
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
Dec 9, 2009
Dec 9, 2009
262
263
264
265
}
}
int
Dec 18, 2009
Dec 18, 2009
266
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
Dec 12, 2010
Dec 12, 2010
267
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 9, 2009
Dec 9, 2009
268
269
270
271
{
SDL_Rect clipped;
int i;
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
272
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
Dec 9, 2009
Dec 9, 2009
273
274
275
276
277
278
279
280
281
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
282
SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
283
284
285
286
287
288
289
290
291
292
293
294
295
296
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
297
func = SDL_BlendFillRect_RGB555;
Dec 9, 2009
Dec 9, 2009
298
299
300
301
302
}
break;
case 16:
switch (dst->format->Rmask) {
case 0xF800:
Dec 18, 2009
Dec 18, 2009
303
func = SDL_BlendFillRect_RGB565;
Dec 9, 2009
Dec 9, 2009
304
305
306
307
308
309
}
break;
case 32:
switch (dst->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
310
func = SDL_BlendFillRect_RGB888;
Dec 9, 2009
Dec 9, 2009
311
} else {
Dec 18, 2009
Dec 18, 2009
312
func = SDL_BlendFillRect_ARGB8888;
Dec 9, 2009
Dec 9, 2009
313
314
315
316
317
318
319
320
321
322
}
break;
}
break;
default:
break;
}
if (!func) {
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
323
func = SDL_BlendFillRect_RGB;
Dec 9, 2009
Dec 9, 2009
324
} else {
Dec 18, 2009
Dec 18, 2009
325
func = SDL_BlendFillRect_RGBA;
Dec 9, 2009
Dec 9, 2009
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
}
}
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
344
}
Dec 9, 2009
Dec 9, 2009
345
return status;
346
347
348
}
/* vi: set ts=4 sw=4 expandtab: */