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

Latest commit

 

History

History
342 lines (308 loc) · 9.3 KB

SDL_blendfillrect.c

File metadata and controls

342 lines (308 loc) · 9.3 KB
 
Apr 8, 2011
Apr 8, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
20
21
22
*/
#include "SDL_config.h"
Feb 8, 2011
Feb 8, 2011
23
24
#if !SDL_RENDER_DISABLED
Dec 21, 2008
Dec 21, 2008
25
#include "SDL_draw.h"
Feb 3, 2011
Feb 3, 2011
26
27
#include "SDL_blendfillrect.h"
Dec 21, 2008
Dec 21, 2008
29
static int
Dec 18, 2009
Dec 18, 2009
30
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
31
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
33
34
35
36
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
37
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
Dec 21, 2008
Dec 21, 2008
38
39
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
40
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
Dec 21, 2008
Dec 21, 2008
41
break;
Feb 5, 2011
Feb 5, 2011
42
43
44
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555);
break;
Dec 21, 2008
Dec 21, 2008
45
default:
Dec 21, 2008
Dec 21, 2008
46
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
Dec 21, 2008
Dec 21, 2008
47
break;
Dec 21, 2008
Dec 21, 2008
49
50
return 0;
}
Dec 21, 2008
Dec 21, 2008
52
static int
Dec 18, 2009
Dec 18, 2009
53
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
54
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
55
56
57
58
59
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
60
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
Dec 21, 2008
Dec 21, 2008
61
62
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
63
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
Dec 21, 2008
Dec 21, 2008
64
break;
Feb 5, 2011
Feb 5, 2011
65
66
67
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565);
break;
Dec 21, 2008
Dec 21, 2008
68
default:
Dec 21, 2008
Dec 21, 2008
69
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
Dec 21, 2008
Dec 21, 2008
70
break;
Dec 21, 2008
Dec 21, 2008
72
73
return 0;
}
Dec 21, 2008
Dec 21, 2008
75
static int
Dec 18, 2009
Dec 18, 2009
76
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
77
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
78
79
80
81
82
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
83
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
Dec 21, 2008
Dec 21, 2008
84
85
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
86
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
Dec 21, 2008
Dec 21, 2008
87
break;
Feb 5, 2011
Feb 5, 2011
88
89
90
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888);
break;
Dec 21, 2008
Dec 21, 2008
91
default:
Dec 21, 2008
Dec 21, 2008
92
FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
Dec 21, 2008
Dec 21, 2008
93
break;
Dec 20, 2008
Dec 20, 2008
94
}
Dec 21, 2008
Dec 21, 2008
95
96
97
return 0;
}
Dec 21, 2008
Dec 21, 2008
98
static int
Dec 18, 2009
Dec 18, 2009
99
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
100
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
101
102
103
104
105
{
unsigned inva = 0xff - a;
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
106
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
Dec 21, 2008
Dec 21, 2008
107
108
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
109
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
Dec 21, 2008
Dec 21, 2008
110
break;
Feb 5, 2011
Feb 5, 2011
111
112
113
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888);
break;
Dec 21, 2008
Dec 21, 2008
114
default:
Dec 21, 2008
Dec 21, 2008
115
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
Dec 21, 2008
Dec 21, 2008
116
117
118
119
120
break;
}
return 0;
}
Dec 21, 2008
Dec 21, 2008
121
static int
Dec 18, 2009
Dec 18, 2009
122
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
123
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
124
125
126
127
128
129
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 2:
Dec 20, 2008
Dec 20, 2008
130
131
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
132
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
133
134
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
135
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
136
break;
Feb 5, 2011
Feb 5, 2011
137
138
139
case SDL_BLENDMODE_MOD:
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB);
break;
Dec 21, 2008
Dec 21, 2008
140
default:
Dec 21, 2008
Dec 21, 2008
141
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
142
143
break;
}
Dec 21, 2008
Dec 21, 2008
144
145
return 0;
case 4:
Dec 20, 2008
Dec 20, 2008
146
147
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
148
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
Dec 20, 2008
Dec 20, 2008
149
150
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
151
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
Dec 20, 2008
Dec 20, 2008
152
break;
Feb 5, 2011
Feb 5, 2011
153
154
155
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB);
break;
Dec 21, 2008
Dec 21, 2008
156
default:
Dec 21, 2008
Dec 21, 2008
157
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
Dec 20, 2008
Dec 20, 2008
158
159
break;
}
Dec 21, 2008
Dec 21, 2008
160
161
162
163
164
165
166
167
return 0;
default:
SDL_Unsupported();
return -1;
}
}
static int
Dec 18, 2009
Dec 18, 2009
168
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
169
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
170
171
172
173
174
175
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;
switch (fmt->BytesPerPixel) {
case 4:
Dec 20, 2008
Dec 20, 2008
176
177
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 21, 2008
Dec 21, 2008
178
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
Dec 20, 2008
Dec 20, 2008
179
180
break;
case SDL_BLENDMODE_ADD:
Dec 21, 2008
Dec 21, 2008
181
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
Dec 20, 2008
Dec 20, 2008
182
break;
Feb 5, 2011
Feb 5, 2011
183
184
185
case SDL_BLENDMODE_MOD:
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA);
break;
Dec 21, 2008
Dec 21, 2008
186
default:
Dec 21, 2008
Dec 21, 2008
187
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
Dec 20, 2008
Dec 20, 2008
188
189
break;
}
Dec 21, 2008
Dec 21, 2008
190
return 0;
Dec 20, 2008
Dec 20, 2008
191
192
193
194
default:
SDL_Unsupported();
return -1;
}
Dec 21, 2008
Dec 21, 2008
195
196
197
}
int
Dec 18, 2009
Dec 18, 2009
198
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
199
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 21, 2008
Dec 21, 2008
200
{
Dec 9, 2009
Dec 9, 2009
201
202
203
204
205
206
SDL_Rect clipped;
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
Dec 21, 2008
Dec 21, 2008
207
208
/* This function doesn't work on surfaces < 8 bpp */
Dec 9, 2009
Dec 9, 2009
209
if (dst->format->BitsPerPixel < 8) {
Dec 18, 2009
Dec 18, 2009
210
SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
211
return -1;
Dec 21, 2008
Dec 21, 2008
212
213
}
Dec 9, 2009
Dec 9, 2009
214
215
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
Dec 21, 2008
Dec 21, 2008
216
/* Perform clipping */
Dec 9, 2009
Dec 9, 2009
217
218
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
return 0;
Dec 21, 2008
Dec 21, 2008
219
}
Dec 9, 2009
Dec 9, 2009
220
rect = &clipped;
Dec 21, 2008
Dec 21, 2008
221
} else {
Dec 9, 2009
Dec 9, 2009
222
rect = &dst->clip_rect;
Dec 21, 2008
Dec 21, 2008
223
224
}
Dec 9, 2009
Dec 9, 2009
225
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
Dec 21, 2008
Dec 21, 2008
226
227
228
229
230
r = DRAW_MUL(r, a);
g = DRAW_MUL(g, a);
b = DRAW_MUL(b, a);
}
Dec 9, 2009
Dec 9, 2009
231
switch (dst->format->BitsPerPixel) {
Dec 21, 2008
Dec 21, 2008
232
case 15:
Dec 9, 2009
Dec 9, 2009
233
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
234
case 0x7C00:
Dec 18, 2009
Dec 18, 2009
235
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
236
237
238
}
break;
case 16:
Dec 9, 2009
Dec 9, 2009
239
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
240
case 0xF800:
Dec 18, 2009
Dec 18, 2009
241
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
242
243
244
}
break;
case 32:
Dec 9, 2009
Dec 9, 2009
245
switch (dst->format->Rmask) {
Dec 21, 2008
Dec 21, 2008
246
case 0x00FF0000:
Dec 9, 2009
Dec 9, 2009
247
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
248
return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
249
} else {
Dec 18, 2009
Dec 18, 2009
250
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
251
252
253
}
break;
}
Dec 9, 2009
Dec 9, 2009
254
break;
Dec 21, 2008
Dec 21, 2008
255
256
257
258
default:
break;
}
Dec 9, 2009
Dec 9, 2009
259
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
260
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
261
} else {
Dec 18, 2009
Dec 18, 2009
262
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
Dec 9, 2009
Dec 9, 2009
263
264
265
266
}
}
int
Feb 15, 2011
Feb 15, 2011
267
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
Dec 12, 2010
Dec 12, 2010
268
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 9, 2009
Dec 9, 2009
269
{
Feb 15, 2011
Feb 15, 2011
270
SDL_Rect rect;
Dec 9, 2009
Dec 9, 2009
271
272
int i;
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
Dec 12, 2010
Dec 12, 2010
273
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
Dec 9, 2009
Dec 9, 2009
274
275
276
277
278
279
280
281
282
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
283
SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
284
285
286
287
288
289
290
291
292
293
294
295
296
297
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
298
func = SDL_BlendFillRect_RGB555;
Dec 9, 2009
Dec 9, 2009
299
300
301
302
303
}
break;
case 16:
switch (dst->format->Rmask) {
case 0xF800:
Dec 18, 2009
Dec 18, 2009
304
func = SDL_BlendFillRect_RGB565;
Dec 9, 2009
Dec 9, 2009
305
306
307
308
309
310
}
break;
case 32:
switch (dst->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
311
func = SDL_BlendFillRect_RGB888;
Dec 9, 2009
Dec 9, 2009
312
} else {
Dec 18, 2009
Dec 18, 2009
313
func = SDL_BlendFillRect_ARGB8888;
Dec 9, 2009
Dec 9, 2009
314
315
316
317
318
319
320
321
322
323
}
break;
}
break;
default:
break;
}
if (!func) {
if (!dst->format->Amask) {
Dec 18, 2009
Dec 18, 2009
324
func = SDL_BlendFillRect_RGB;
Dec 9, 2009
Dec 9, 2009
325
} else {
Dec 18, 2009
Dec 18, 2009
326
func = SDL_BlendFillRect_RGBA;
Dec 9, 2009
Dec 9, 2009
327
328
329
330
}
}
for (i = 0; i < count; ++i) {
Feb 15, 2011
Feb 15, 2011
331
332
333
/* Perform clipping */
if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) {
continue;
Dec 9, 2009
Dec 9, 2009
334
}
Feb 15, 2011
Feb 15, 2011
335
status = func(dst, &rect, blendMode, r, g, b, a);
Dec 21, 2008
Dec 21, 2008
336
}
Dec 9, 2009
Dec 9, 2009
337
return status;
Feb 8, 2011
Feb 8, 2011
340
341
#endif /* !SDL_RENDER_DISABLED */
342
/* vi: set ts=4 sw=4 expandtab: */