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

Latest commit

 

History

History
682 lines (640 loc) · 20.3 KB

SDL_blendline.c

File metadata and controls

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