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

Latest commit

 

History

History
785 lines (742 loc) · 24.1 KB

SDL_blendline.c

File metadata and controls

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