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

Latest commit

 

History

History
782 lines (740 loc) · 23.9 KB

SDL_blendline.c

File metadata and controls

782 lines (740 loc) · 23.9 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
#include "SDL_blendline.h"
Feb 3, 2011
Feb 3, 2011
26
#include "SDL_blendpoint.h"
Dec 20, 2008
Dec 20, 2008
27
Dec 23, 2009
Dec 23, 2009
28
29
30
static void
SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
31
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 23, 2009
Dec 23, 2009
32
SDL_bool draw_end)
Dec 21, 2008
Dec 21, 2008
33
{
Dec 23, 2009
Dec 23, 2009
34
35
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 23, 2009
Dec 23, 2009
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
58
59
60
case SDL_BLENDMODE_MOD:
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
61
62
63
64
65
66
67
68
69
70
71
72
default:
HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
73
74
75
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
76
77
78
79
80
81
82
83
84
85
86
87
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
88
89
90
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
107
108
109
110
111
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
112
113
114
115
116
117
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
draw_end);
break;
}
Dec 21, 2008
Dec 21, 2008
118
119
120
}
}
Dec 23, 2009
Dec 23, 2009
121
122
static void
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
123
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 18, 2009
Dec 18, 2009
124
SDL_bool draw_end)
Dec 23, 2009
Dec 23, 2009
126
127
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 21, 2008
Dec 21, 2008
128
Dec 23, 2009
Dec 23, 2009
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break;
case SDL_BLENDMODE_ADD:
HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
150
151
152
case SDL_BLENDMODE_MOD:
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
153
154
155
156
157
158
159
160
161
162
163
164
default:
HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break;
}
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
165
166
167
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
168
169
170
171
172
173
174
175
176
177
178
179
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
180
181
182
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
199
200
201
202
203
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
204
205
206
207
208
209
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
draw_end);
break;
}
Dec 21, 2008
Dec 21, 2008
211
}
Dec 23, 2009
Dec 23, 2009
213
214
static void
SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
215
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 18, 2009
Dec 18, 2009
216
SDL_bool draw_end)
Dec 21, 2008
Dec 21, 2008
217
{
Dec 23, 2009
Dec 23, 2009
218
219
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 23, 2009
Dec 23, 2009
221
222
223
224
225
226
227
228
229
230
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
Dec 20, 2008
Dec 20, 2008
231
}
Dec 23, 2009
Dec 23, 2009
232
inva = (a ^ 0xff);
Dec 21, 2008
Dec 21, 2008
233
Dec 23, 2009
Dec 23, 2009
234
235
236
237
238
239
240
241
if (y1 == y2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break;
case SDL_BLENDMODE_ADD:
HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
242
243
244
case SDL_BLENDMODE_MOD:
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
245
246
247
248
249
250
251
252
253
254
255
256
default:
HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break;
}
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
257
258
259
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
260
261
262
263
264
265
266
267
268
269
270
271
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
272
273
274
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
291
292
293
294
295
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
296
297
298
299
300
301
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
draw_end);
break;
}
Dec 21, 2008
Dec 21, 2008
302
303
304
}
}
Dec 23, 2009
Dec 23, 2009
305
306
static void
SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
307
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 23, 2009
Dec 23, 2009
308
SDL_bool draw_end)
Dec 21, 2008
Dec 21, 2008
309
{
Dec 23, 2009
Dec 23, 2009
310
311
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 21, 2008
Dec 21, 2008
312
Dec 23, 2009
Dec 23, 2009
313
314
315
316
317
318
319
320
321
322
323
324
325
326
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
Dec 20, 2008
Dec 20, 2008
327
328
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 23, 2009
Dec 23, 2009
329
HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
Dec 20, 2008
Dec 20, 2008
330
331
break;
case SDL_BLENDMODE_ADD:
Dec 23, 2009
Dec 23, 2009
332
HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
Dec 20, 2008
Dec 20, 2008
333
break;
Feb 5, 2011
Feb 5, 2011
334
335
336
case SDL_BLENDMODE_MOD:
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 21, 2008
Dec 21, 2008
337
default:
Dec 23, 2009
Dec 23, 2009
338
HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
Dec 20, 2008
Dec 20, 2008
339
340
break;
}
Dec 23, 2009
Dec 23, 2009
341
} else if (x1 == x2) {
Dec 20, 2008
Dec 20, 2008
342
343
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 23, 2009
Dec 23, 2009
344
VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
Dec 20, 2008
Dec 20, 2008
345
346
break;
case SDL_BLENDMODE_ADD:
Dec 23, 2009
Dec 23, 2009
347
VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
Dec 20, 2008
Dec 20, 2008
348
break;
Feb 5, 2011
Feb 5, 2011
349
350
351
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 21, 2008
Dec 21, 2008
352
default:
Dec 23, 2009
Dec 23, 2009
353
354
355
356
357
358
359
360
361
362
363
VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
364
365
366
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
default:
DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
383
384
385
386
387
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
388
389
390
391
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
draw_end);
Dec 20, 2008
Dec 20, 2008
392
393
break;
}
Dec 21, 2008
Dec 21, 2008
394
395
396
}
}
Dec 23, 2009
Dec 23, 2009
397
398
static void
SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
399
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 23, 2009
Dec 23, 2009
400
SDL_bool draw_end)
Dec 21, 2008
Dec 21, 2008
401
{
Dec 23, 2009
Dec 23, 2009
402
403
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 21, 2008
Dec 21, 2008
404
Dec 23, 2009
Dec 23, 2009
405
406
407
408
409
410
411
412
413
414
415
416
417
418
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
Dec 20, 2008
Dec 20, 2008
419
420
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
Dec 23, 2009
Dec 23, 2009
421
HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
Dec 20, 2008
Dec 20, 2008
422
423
break;
case SDL_BLENDMODE_ADD:
Dec 23, 2009
Dec 23, 2009
424
HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
Dec 20, 2008
Dec 20, 2008
425
break;
Feb 5, 2011
Feb 5, 2011
426
427
428
case SDL_BLENDMODE_MOD:
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break;
Dec 21, 2008
Dec 21, 2008
429
default:
Dec 23, 2009
Dec 23, 2009
430
431
432
433
434
435
436
437
438
439
440
HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
break;
}
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
441
442
443
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
444
445
446
447
448
449
450
451
452
453
454
455
default:
VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
456
457
458
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
default:
DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
475
476
477
478
479
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
480
481
482
483
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
draw_end);
Dec 20, 2008
Dec 20, 2008
484
485
486
break;
}
}
Dec 21, 2008
Dec 21, 2008
487
488
}
Dec 23, 2009
Dec 23, 2009
489
490
static void
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
491
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 23, 2009
Dec 23, 2009
492
SDL_bool draw_end)
Dec 21, 2008
Dec 21, 2008
493
{
Dec 23, 2009
Dec 23, 2009
494
495
496
497
498
499
500
501
502
503
504
505
506
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
Dec 21, 2008
Dec 21, 2008
507
}
Dec 23, 2009
Dec 23, 2009
508
inva = (a ^ 0xff);
Dec 21, 2008
Dec 21, 2008
509
Dec 23, 2009
Dec 23, 2009
510
511
512
513
514
515
516
517
if (y1 == y2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
break;
case SDL_BLENDMODE_ADD:
HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
518
519
520
case SDL_BLENDMODE_MOD:
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
521
522
523
524
525
526
527
528
529
530
531
532
default:
HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
break;
}
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
533
534
535
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
536
537
538
539
540
541
542
543
544
545
546
547
default:
VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
548
549
550
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
default:
DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
567
568
569
570
571
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
572
573
574
575
576
577
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
draw_end);
break;
}
Dec 23, 2008
Dec 23, 2008
578
}
Dec 23, 2009
Dec 23, 2009
579
}
Dec 23, 2008
Dec 23, 2008
580
Dec 23, 2009
Dec 23, 2009
581
582
static void
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
583
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
Dec 23, 2009
Dec 23, 2009
584
585
586
587
SDL_bool draw_end)
{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
Dec 21, 2008
Dec 21, 2008
588
Dec 9, 2009
Dec 9, 2009
589
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
Dec 23, 2009
Dec 23, 2009
590
591
592
593
594
595
596
597
598
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
Dec 21, 2008
Dec 21, 2008
599
}
Dec 23, 2009
Dec 23, 2009
600
inva = (a ^ 0xff);
Dec 21, 2008
Dec 21, 2008
601
Dec 23, 2009
Dec 23, 2009
602
603
604
605
606
607
608
609
if (y1 == y2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_ADD:
HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
610
611
612
case SDL_BLENDMODE_MOD:
HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
613
614
615
default:
HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break;
Dec 21, 2008
Dec 21, 2008
616
}
Dec 23, 2009
Dec 23, 2009
617
618
619
620
621
622
623
624
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
625
626
627
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
628
629
630
631
632
633
634
635
636
637
638
639
default:
VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
Feb 5, 2011
Feb 5, 2011
640
641
642
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
Dec 23, 2009
Dec 23, 2009
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
default:
DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
draw_end);
break;
Feb 5, 2011
Feb 5, 2011
659
660
661
662
663
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
draw_end);
break;
Dec 23, 2009
Dec 23, 2009
664
665
666
667
668
669
670
671
672
673
674
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
draw_end);
break;
}
}
}
typedef void (*BlendLineFunc) (SDL_Surface * dst,
int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
675
SDL_BlendMode blendMode,
Dec 23, 2009
Dec 23, 2009
676
677
678
679
680
681
682
683
684
685
686
687
688
689
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end);
static BlendLineFunc
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
{
switch (fmt->BytesPerPixel) {
case 2:
if (fmt->Rmask == 0x7C00) {
return SDL_BlendLine_RGB555;
} else if (fmt->Rmask == 0xF800) {
return SDL_BlendLine_RGB565;
} else {
return SDL_BlendLine_RGB2;
Dec 21, 2008
Dec 21, 2008
690
691
}
break;
Dec 23, 2009
Dec 23, 2009
692
693
694
695
case 4:
if (fmt->Rmask == 0x00FF0000) {
if (fmt->Amask) {
return SDL_BlendLine_ARGB8888;
Dec 21, 2008
Dec 21, 2008
696
} else {
Dec 23, 2009
Dec 23, 2009
697
698
699
700
701
702
703
return SDL_BlendLine_RGB888;
}
} else {
if (fmt->Amask) {
return SDL_BlendLine_RGBA4;
} else {
return SDL_BlendLine_RGB4;
Dec 21, 2008
Dec 21, 2008
704
705
706
}
}
}
Dec 23, 2009
Dec 23, 2009
707
708
return NULL;
}
Dec 21, 2008
Dec 21, 2008
709
Dec 23, 2009
Dec 23, 2009
710
711
int
SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
Dec 12, 2010
Dec 12, 2010
712
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 23, 2009
Dec 23, 2009
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
{
BlendLineFunc func;
if (!dst) {
SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
return -1;
}
func = SDL_CalculateBlendLineFunc(dst->format);
if (!func) {
SDL_SetError("SDL_BlendLine(): Unsupported surface format");
return -1;
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
Dec 21, 2008
Dec 21, 2008
731
}
Dec 23, 2009
Dec 23, 2009
732
733
734
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
return 0;
Dec 9, 2009
Dec 9, 2009
737
738
int
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
Dec 12, 2010
Dec 12, 2010
739
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Dec 9, 2009
Dec 9, 2009
740
741
742
743
{
int i;
int x1, y1;
int x2, y2;
Dec 23, 2009
Dec 23, 2009
744
745
SDL_bool draw_end;
BlendLineFunc func;
Dec 9, 2009
Dec 9, 2009
746
747
if (!dst) {
Dec 23, 2009
Dec 23, 2009
748
SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
Dec 9, 2009
Dec 9, 2009
749
750
751
return -1;
}
Dec 23, 2009
Dec 23, 2009
752
753
func = SDL_CalculateBlendLineFunc(dst->format);
if (!func) {
Dec 9, 2009
Dec 9, 2009
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
SDL_SetError("SDL_BlendLines(): Unsupported surface format");
return -1;
}
for (i = 1; i < count; ++i) {
x1 = points[i-1].x;
y1 = points[i-1].y;
x2 = points[i].x;
y2 = points[i].y;
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
Dec 23, 2009
Dec 23, 2009
770
771
772
773
/* Draw the end if it was clipped */
draw_end = (x2 != points[i].x || y2 != points[i].y);
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
Dec 18, 2009
Dec 18, 2009
774
775
}
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
Dec 23, 2009
Dec 23, 2009
776
777
SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
blendMode, r, g, b, a);
Dec 9, 2009
Dec 9, 2009
778
}
Dec 23, 2009
Dec 23, 2009
779
return 0;
Dec 9, 2009
Dec 9, 2009
780
781
}
782
/* vi: set ts=4 sw=4 expandtab: */