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

Latest commit

 

History

History
786 lines (742 loc) · 24 KB

SDL_blendline.c

File metadata and controls

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