Mercurial > sdl-ios-xcode
comparison src/render/software/SDL_blendline.c @ 5166:d72793305335
Making the API simpler, moved the surface drawing functions to the software renderer.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Feb 2011 02:45:29 -0800 |
parents | src/video/SDL_blendline.c@e743b9c3f6d6 |
children | 4d39eeaad00b |
comparison
equal
deleted
inserted
replaced
5165:e2b3f003e085 | 5166:d72793305335 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2010 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 #include "SDL_config.h" | |
23 | |
24 #include "SDL_draw.h" | |
25 #include "SDL_blendline.h" | |
26 | |
27 | |
28 static void | |
29 SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
30 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
31 SDL_bool draw_end) | |
32 { | |
33 const SDL_PixelFormat *fmt = dst->format; | |
34 unsigned r, g, b, a, inva; | |
35 | |
36 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
37 r = DRAW_MUL(_r, _a); | |
38 g = DRAW_MUL(_g, _a); | |
39 b = DRAW_MUL(_b, _a); | |
40 a = _a; | |
41 } else { | |
42 r = _r; | |
43 g = _g; | |
44 b = _b; | |
45 a = _a; | |
46 } | |
47 inva = (a ^ 0xff); | |
48 | |
49 if (y1 == y2) { | |
50 switch (blendMode) { | |
51 case SDL_BLENDMODE_BLEND: | |
52 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
53 break; | |
54 case SDL_BLENDMODE_ADD: | |
55 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
56 break; | |
57 default: | |
58 HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); | |
59 break; | |
60 } | |
61 } else if (x1 == x2) { | |
62 switch (blendMode) { | |
63 case SDL_BLENDMODE_BLEND: | |
64 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
65 break; | |
66 case SDL_BLENDMODE_ADD: | |
67 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
68 break; | |
69 default: | |
70 VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); | |
71 break; | |
72 } | |
73 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
74 switch (blendMode) { | |
75 case SDL_BLENDMODE_BLEND: | |
76 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
77 break; | |
78 case SDL_BLENDMODE_ADD: | |
79 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
80 break; | |
81 default: | |
82 DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end); | |
83 break; | |
84 } | |
85 } else { | |
86 switch (blendMode) { | |
87 case SDL_BLENDMODE_BLEND: | |
88 AALINE(x1, y1, x2, y2, | |
89 DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB, | |
90 draw_end); | |
91 break; | |
92 case SDL_BLENDMODE_ADD: | |
93 AALINE(x1, y1, x2, y2, | |
94 DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB, | |
95 draw_end); | |
96 break; | |
97 default: | |
98 AALINE(x1, y1, x2, y2, | |
99 DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB, | |
100 draw_end); | |
101 break; | |
102 } | |
103 } | |
104 } | |
105 | |
106 static void | |
107 SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
108 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
109 SDL_bool draw_end) | |
110 { | |
111 const SDL_PixelFormat *fmt = dst->format; | |
112 unsigned r, g, b, a, inva; | |
113 | |
114 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
115 r = DRAW_MUL(_r, _a); | |
116 g = DRAW_MUL(_g, _a); | |
117 b = DRAW_MUL(_b, _a); | |
118 a = _a; | |
119 } else { | |
120 r = _r; | |
121 g = _g; | |
122 b = _b; | |
123 a = _a; | |
124 } | |
125 inva = (a ^ 0xff); | |
126 | |
127 if (y1 == y2) { | |
128 switch (blendMode) { | |
129 case SDL_BLENDMODE_BLEND: | |
130 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); | |
131 break; | |
132 case SDL_BLENDMODE_ADD: | |
133 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); | |
134 break; | |
135 default: | |
136 HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); | |
137 break; | |
138 } | |
139 } else if (x1 == x2) { | |
140 switch (blendMode) { | |
141 case SDL_BLENDMODE_BLEND: | |
142 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); | |
143 break; | |
144 case SDL_BLENDMODE_ADD: | |
145 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); | |
146 break; | |
147 default: | |
148 VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); | |
149 break; | |
150 } | |
151 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
152 switch (blendMode) { | |
153 case SDL_BLENDMODE_BLEND: | |
154 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end); | |
155 break; | |
156 case SDL_BLENDMODE_ADD: | |
157 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end); | |
158 break; | |
159 default: | |
160 DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end); | |
161 break; | |
162 } | |
163 } else { | |
164 switch (blendMode) { | |
165 case SDL_BLENDMODE_BLEND: | |
166 AALINE(x1, y1, x2, y2, | |
167 DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, | |
168 draw_end); | |
169 break; | |
170 case SDL_BLENDMODE_ADD: | |
171 AALINE(x1, y1, x2, y2, | |
172 DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555, | |
173 draw_end); | |
174 break; | |
175 default: | |
176 AALINE(x1, y1, x2, y2, | |
177 DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555, | |
178 draw_end); | |
179 break; | |
180 } | |
181 } | |
182 } | |
183 | |
184 static void | |
185 SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
186 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
187 SDL_bool draw_end) | |
188 { | |
189 const SDL_PixelFormat *fmt = dst->format; | |
190 unsigned r, g, b, a, inva; | |
191 | |
192 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
193 r = DRAW_MUL(_r, _a); | |
194 g = DRAW_MUL(_g, _a); | |
195 b = DRAW_MUL(_b, _a); | |
196 a = _a; | |
197 } else { | |
198 r = _r; | |
199 g = _g; | |
200 b = _b; | |
201 a = _a; | |
202 } | |
203 inva = (a ^ 0xff); | |
204 | |
205 if (y1 == y2) { | |
206 switch (blendMode) { | |
207 case SDL_BLENDMODE_BLEND: | |
208 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); | |
209 break; | |
210 case SDL_BLENDMODE_ADD: | |
211 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); | |
212 break; | |
213 default: | |
214 HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); | |
215 break; | |
216 } | |
217 } else if (x1 == x2) { | |
218 switch (blendMode) { | |
219 case SDL_BLENDMODE_BLEND: | |
220 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); | |
221 break; | |
222 case SDL_BLENDMODE_ADD: | |
223 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); | |
224 break; | |
225 default: | |
226 VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); | |
227 break; | |
228 } | |
229 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
230 switch (blendMode) { | |
231 case SDL_BLENDMODE_BLEND: | |
232 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end); | |
233 break; | |
234 case SDL_BLENDMODE_ADD: | |
235 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end); | |
236 break; | |
237 default: | |
238 DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end); | |
239 break; | |
240 } | |
241 } else { | |
242 switch (blendMode) { | |
243 case SDL_BLENDMODE_BLEND: | |
244 AALINE(x1, y1, x2, y2, | |
245 DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, | |
246 draw_end); | |
247 break; | |
248 case SDL_BLENDMODE_ADD: | |
249 AALINE(x1, y1, x2, y2, | |
250 DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565, | |
251 draw_end); | |
252 break; | |
253 default: | |
254 AALINE(x1, y1, x2, y2, | |
255 DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565, | |
256 draw_end); | |
257 break; | |
258 } | |
259 } | |
260 } | |
261 | |
262 static void | |
263 SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
264 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
265 SDL_bool draw_end) | |
266 { | |
267 const SDL_PixelFormat *fmt = dst->format; | |
268 unsigned r, g, b, a, inva; | |
269 | |
270 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
271 r = DRAW_MUL(_r, _a); | |
272 g = DRAW_MUL(_g, _a); | |
273 b = DRAW_MUL(_b, _a); | |
274 a = _a; | |
275 } else { | |
276 r = _r; | |
277 g = _g; | |
278 b = _b; | |
279 a = _a; | |
280 } | |
281 inva = (a ^ 0xff); | |
282 | |
283 if (y1 == y2) { | |
284 switch (blendMode) { | |
285 case SDL_BLENDMODE_BLEND: | |
286 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
287 break; | |
288 case SDL_BLENDMODE_ADD: | |
289 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
290 break; | |
291 default: | |
292 HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); | |
293 break; | |
294 } | |
295 } else if (x1 == x2) { | |
296 switch (blendMode) { | |
297 case SDL_BLENDMODE_BLEND: | |
298 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
299 break; | |
300 case SDL_BLENDMODE_ADD: | |
301 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
302 break; | |
303 default: | |
304 VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); | |
305 break; | |
306 } | |
307 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
308 switch (blendMode) { | |
309 case SDL_BLENDMODE_BLEND: | |
310 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end); | |
311 break; | |
312 case SDL_BLENDMODE_ADD: | |
313 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end); | |
314 break; | |
315 default: | |
316 DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end); | |
317 break; | |
318 } | |
319 } else { | |
320 switch (blendMode) { | |
321 case SDL_BLENDMODE_BLEND: | |
322 AALINE(x1, y1, x2, y2, | |
323 DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB, | |
324 draw_end); | |
325 break; | |
326 case SDL_BLENDMODE_ADD: | |
327 AALINE(x1, y1, x2, y2, | |
328 DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB, | |
329 draw_end); | |
330 break; | |
331 default: | |
332 AALINE(x1, y1, x2, y2, | |
333 DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB, | |
334 draw_end); | |
335 break; | |
336 } | |
337 } | |
338 } | |
339 | |
340 static void | |
341 SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
342 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
343 SDL_bool draw_end) | |
344 { | |
345 const SDL_PixelFormat *fmt = dst->format; | |
346 unsigned r, g, b, a, inva; | |
347 | |
348 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
349 r = DRAW_MUL(_r, _a); | |
350 g = DRAW_MUL(_g, _a); | |
351 b = DRAW_MUL(_b, _a); | |
352 a = _a; | |
353 } else { | |
354 r = _r; | |
355 g = _g; | |
356 b = _b; | |
357 a = _a; | |
358 } | |
359 inva = (a ^ 0xff); | |
360 | |
361 if (y1 == y2) { | |
362 switch (blendMode) { | |
363 case SDL_BLENDMODE_BLEND: | |
364 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); | |
365 break; | |
366 case SDL_BLENDMODE_ADD: | |
367 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); | |
368 break; | |
369 default: | |
370 HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); | |
371 break; | |
372 } | |
373 } else if (x1 == x2) { | |
374 switch (blendMode) { | |
375 case SDL_BLENDMODE_BLEND: | |
376 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); | |
377 break; | |
378 case SDL_BLENDMODE_ADD: | |
379 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); | |
380 break; | |
381 default: | |
382 VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); | |
383 break; | |
384 } | |
385 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
386 switch (blendMode) { | |
387 case SDL_BLENDMODE_BLEND: | |
388 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end); | |
389 break; | |
390 case SDL_BLENDMODE_ADD: | |
391 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end); | |
392 break; | |
393 default: | |
394 DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end); | |
395 break; | |
396 } | |
397 } else { | |
398 switch (blendMode) { | |
399 case SDL_BLENDMODE_BLEND: | |
400 AALINE(x1, y1, x2, y2, | |
401 DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, | |
402 draw_end); | |
403 break; | |
404 case SDL_BLENDMODE_ADD: | |
405 AALINE(x1, y1, x2, y2, | |
406 DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA, | |
407 draw_end); | |
408 break; | |
409 default: | |
410 AALINE(x1, y1, x2, y2, | |
411 DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA, | |
412 draw_end); | |
413 break; | |
414 } | |
415 } | |
416 } | |
417 | |
418 static void | |
419 SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
420 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
421 SDL_bool draw_end) | |
422 { | |
423 const SDL_PixelFormat *fmt = dst->format; | |
424 unsigned r, g, b, a, inva; | |
425 | |
426 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
427 r = DRAW_MUL(_r, _a); | |
428 g = DRAW_MUL(_g, _a); | |
429 b = DRAW_MUL(_b, _a); | |
430 a = _a; | |
431 } else { | |
432 r = _r; | |
433 g = _g; | |
434 b = _b; | |
435 a = _a; | |
436 } | |
437 inva = (a ^ 0xff); | |
438 | |
439 if (y1 == y2) { | |
440 switch (blendMode) { | |
441 case SDL_BLENDMODE_BLEND: | |
442 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); | |
443 break; | |
444 case SDL_BLENDMODE_ADD: | |
445 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); | |
446 break; | |
447 default: | |
448 HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); | |
449 break; | |
450 } | |
451 } else if (x1 == x2) { | |
452 switch (blendMode) { | |
453 case SDL_BLENDMODE_BLEND: | |
454 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); | |
455 break; | |
456 case SDL_BLENDMODE_ADD: | |
457 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); | |
458 break; | |
459 default: | |
460 VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); | |
461 break; | |
462 } | |
463 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
464 switch (blendMode) { | |
465 case SDL_BLENDMODE_BLEND: | |
466 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end); | |
467 break; | |
468 case SDL_BLENDMODE_ADD: | |
469 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end); | |
470 break; | |
471 default: | |
472 DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end); | |
473 break; | |
474 } | |
475 } else { | |
476 switch (blendMode) { | |
477 case SDL_BLENDMODE_BLEND: | |
478 AALINE(x1, y1, x2, y2, | |
479 DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, | |
480 draw_end); | |
481 break; | |
482 case SDL_BLENDMODE_ADD: | |
483 AALINE(x1, y1, x2, y2, | |
484 DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888, | |
485 draw_end); | |
486 break; | |
487 default: | |
488 AALINE(x1, y1, x2, y2, | |
489 DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888, | |
490 draw_end); | |
491 break; | |
492 } | |
493 } | |
494 } | |
495 | |
496 static void | |
497 SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
498 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a, | |
499 SDL_bool draw_end) | |
500 { | |
501 const SDL_PixelFormat *fmt = dst->format; | |
502 unsigned r, g, b, a, inva; | |
503 | |
504 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { | |
505 r = DRAW_MUL(_r, _a); | |
506 g = DRAW_MUL(_g, _a); | |
507 b = DRAW_MUL(_b, _a); | |
508 a = _a; | |
509 } else { | |
510 r = _r; | |
511 g = _g; | |
512 b = _b; | |
513 a = _a; | |
514 } | |
515 inva = (a ^ 0xff); | |
516 | |
517 if (y1 == y2) { | |
518 switch (blendMode) { | |
519 case SDL_BLENDMODE_BLEND: | |
520 HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); | |
521 break; | |
522 case SDL_BLENDMODE_ADD: | |
523 HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); | |
524 break; | |
525 default: | |
526 HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); | |
527 break; | |
528 } | |
529 } else if (x1 == x2) { | |
530 switch (blendMode) { | |
531 case SDL_BLENDMODE_BLEND: | |
532 VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); | |
533 break; | |
534 case SDL_BLENDMODE_ADD: | |
535 VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); | |
536 break; | |
537 default: | |
538 VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); | |
539 break; | |
540 } | |
541 } else if (ABS(x1 - x2) == ABS(y1 - y2)) { | |
542 switch (blendMode) { | |
543 case SDL_BLENDMODE_BLEND: | |
544 DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end); | |
545 break; | |
546 case SDL_BLENDMODE_ADD: | |
547 DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end); | |
548 break; | |
549 default: | |
550 DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end); | |
551 break; | |
552 } | |
553 } else { | |
554 switch (blendMode) { | |
555 case SDL_BLENDMODE_BLEND: | |
556 AALINE(x1, y1, x2, y2, | |
557 DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, | |
558 draw_end); | |
559 break; | |
560 case SDL_BLENDMODE_ADD: | |
561 AALINE(x1, y1, x2, y2, | |
562 DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888, | |
563 draw_end); | |
564 break; | |
565 default: | |
566 AALINE(x1, y1, x2, y2, | |
567 DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888, | |
568 draw_end); | |
569 break; | |
570 } | |
571 } | |
572 } | |
573 | |
574 typedef void (*BlendLineFunc) (SDL_Surface * dst, | |
575 int x1, int y1, int x2, int y2, | |
576 SDL_BlendMode blendMode, | |
577 Uint8 r, Uint8 g, Uint8 b, Uint8 a, | |
578 SDL_bool draw_end); | |
579 | |
580 static BlendLineFunc | |
581 SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt) | |
582 { | |
583 switch (fmt->BytesPerPixel) { | |
584 case 2: | |
585 if (fmt->Rmask == 0x7C00) { | |
586 return SDL_BlendLine_RGB555; | |
587 } else if (fmt->Rmask == 0xF800) { | |
588 return SDL_BlendLine_RGB565; | |
589 } else { | |
590 return SDL_BlendLine_RGB2; | |
591 } | |
592 break; | |
593 case 4: | |
594 if (fmt->Rmask == 0x00FF0000) { | |
595 if (fmt->Amask) { | |
596 return SDL_BlendLine_ARGB8888; | |
597 } else { | |
598 return SDL_BlendLine_RGB888; | |
599 } | |
600 } else { | |
601 if (fmt->Amask) { | |
602 return SDL_BlendLine_RGBA4; | |
603 } else { | |
604 return SDL_BlendLine_RGB4; | |
605 } | |
606 } | |
607 } | |
608 return NULL; | |
609 } | |
610 | |
611 int | |
612 SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, | |
613 SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | |
614 { | |
615 BlendLineFunc func; | |
616 | |
617 if (!dst) { | |
618 SDL_SetError("SDL_BlendLine(): Passed NULL destination surface"); | |
619 return -1; | |
620 } | |
621 | |
622 func = SDL_CalculateBlendLineFunc(dst->format); | |
623 if (!func) { | |
624 SDL_SetError("SDL_BlendLine(): Unsupported surface format"); | |
625 return -1; | |
626 } | |
627 | |
628 /* Perform clipping */ | |
629 /* FIXME: We don't actually want to clip, as it may change line slope */ | |
630 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | |
631 return 0; | |
632 } | |
633 | |
634 func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE); | |
635 return 0; | |
636 } | |
637 | |
638 int | |
639 SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, | |
640 SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | |
641 { | |
642 int i; | |
643 int x1, y1; | |
644 int x2, y2; | |
645 SDL_bool draw_end; | |
646 BlendLineFunc func; | |
647 | |
648 if (!dst) { | |
649 SDL_SetError("SDL_BlendLines(): Passed NULL destination surface"); | |
650 return -1; | |
651 } | |
652 | |
653 func = SDL_CalculateBlendLineFunc(dst->format); | |
654 if (!func) { | |
655 SDL_SetError("SDL_BlendLines(): Unsupported surface format"); | |
656 return -1; | |
657 } | |
658 | |
659 for (i = 1; i < count; ++i) { | |
660 x1 = points[i-1].x; | |
661 y1 = points[i-1].y; | |
662 x2 = points[i].x; | |
663 y2 = points[i].y; | |
664 | |
665 /* Perform clipping */ | |
666 /* FIXME: We don't actually want to clip, as it may change line slope */ | |
667 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | |
668 continue; | |
669 } | |
670 | |
671 /* Draw the end if it was clipped */ | |
672 draw_end = (x2 != points[i].x || y2 != points[i].y); | |
673 | |
674 func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end); | |
675 } | |
676 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { | |
677 SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, | |
678 blendMode, r, g, b, a); | |
679 } | |
680 return 0; | |
681 } | |
682 | |
683 /* vi: set ts=4 sw=4 expandtab: */ |