Making the API simpler, moved the surface drawing functions to the software renderer.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
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.
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.
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
22 #include "SDL_config.h"
25 #include "SDL_blendline.h"
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,
33 const SDL_PixelFormat *fmt = dst->format;
34 unsigned r, g, b, a, inva;
36 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
51 case SDL_BLENDMODE_BLEND:
52 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
54 case SDL_BLENDMODE_ADD:
55 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
58 HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
61 } else if (x1 == x2) {
63 case SDL_BLENDMODE_BLEND:
64 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
66 case SDL_BLENDMODE_ADD:
67 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
70 VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
73 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
75 case SDL_BLENDMODE_BLEND:
76 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
78 case SDL_BLENDMODE_ADD:
79 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
82 DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
87 case SDL_BLENDMODE_BLEND:
88 AALINE(x1, y1, x2, y2,
89 DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
92 case SDL_BLENDMODE_ADD:
93 AALINE(x1, y1, x2, y2,
94 DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
98 AALINE(x1, y1, x2, y2,
99 DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
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,
111 const SDL_PixelFormat *fmt = dst->format;
112 unsigned r, g, b, a, inva;
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);
129 case SDL_BLENDMODE_BLEND:
130 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
132 case SDL_BLENDMODE_ADD:
133 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
136 HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
139 } else if (x1 == x2) {
141 case SDL_BLENDMODE_BLEND:
142 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
144 case SDL_BLENDMODE_ADD:
145 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
148 VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
151 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
153 case SDL_BLENDMODE_BLEND:
154 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
156 case SDL_BLENDMODE_ADD:
157 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
160 DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
165 case SDL_BLENDMODE_BLEND:
166 AALINE(x1, y1, x2, y2,
167 DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
170 case SDL_BLENDMODE_ADD:
171 AALINE(x1, y1, x2, y2,
172 DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
176 AALINE(x1, y1, x2, y2,
177 DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
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,
189 const SDL_PixelFormat *fmt = dst->format;
190 unsigned r, g, b, a, inva;
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);
207 case SDL_BLENDMODE_BLEND:
208 HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
210 case SDL_BLENDMODE_ADD:
211 HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
214 HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
217 } else if (x1 == x2) {
219 case SDL_BLENDMODE_BLEND:
220 VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
222 case SDL_BLENDMODE_ADD:
223 VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
226 VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
229 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
231 case SDL_BLENDMODE_BLEND:
232 DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
234 case SDL_BLENDMODE_ADD:
235 DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
238 DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
243 case SDL_BLENDMODE_BLEND:
244 AALINE(x1, y1, x2, y2,
245 DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
248 case SDL_BLENDMODE_ADD:
249 AALINE(x1, y1, x2, y2,
250 DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
254 AALINE(x1, y1, x2, y2,
255 DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
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,
267 const SDL_PixelFormat *fmt = dst->format;
268 unsigned r, g, b, a, inva;
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);
285 case SDL_BLENDMODE_BLEND:
286 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
288 case SDL_BLENDMODE_ADD:
289 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
292 HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
295 } else if (x1 == x2) {
297 case SDL_BLENDMODE_BLEND:
298 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
300 case SDL_BLENDMODE_ADD:
301 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
304 VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
307 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
309 case SDL_BLENDMODE_BLEND:
310 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
312 case SDL_BLENDMODE_ADD:
313 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
316 DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
321 case SDL_BLENDMODE_BLEND:
322 AALINE(x1, y1, x2, y2,
323 DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
326 case SDL_BLENDMODE_ADD:
327 AALINE(x1, y1, x2, y2,
328 DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
332 AALINE(x1, y1, x2, y2,
333 DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
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,
345 const SDL_PixelFormat *fmt = dst->format;
346 unsigned r, g, b, a, inva;
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);
363 case SDL_BLENDMODE_BLEND:
364 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
366 case SDL_BLENDMODE_ADD:
367 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
370 HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
373 } else if (x1 == x2) {
375 case SDL_BLENDMODE_BLEND:
376 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
378 case SDL_BLENDMODE_ADD:
379 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
382 VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
385 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
387 case SDL_BLENDMODE_BLEND:
388 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
390 case SDL_BLENDMODE_ADD:
391 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
394 DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
399 case SDL_BLENDMODE_BLEND:
400 AALINE(x1, y1, x2, y2,
401 DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
404 case SDL_BLENDMODE_ADD:
405 AALINE(x1, y1, x2, y2,
406 DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
410 AALINE(x1, y1, x2, y2,
411 DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
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,
423 const SDL_PixelFormat *fmt = dst->format;
424 unsigned r, g, b, a, inva;
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);
441 case SDL_BLENDMODE_BLEND:
442 HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
444 case SDL_BLENDMODE_ADD:
445 HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
448 HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
451 } else if (x1 == x2) {
453 case SDL_BLENDMODE_BLEND:
454 VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
456 case SDL_BLENDMODE_ADD:
457 VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
460 VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
463 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
465 case SDL_BLENDMODE_BLEND:
466 DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
468 case SDL_BLENDMODE_ADD:
469 DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
472 DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
477 case SDL_BLENDMODE_BLEND:
478 AALINE(x1, y1, x2, y2,
479 DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
482 case SDL_BLENDMODE_ADD:
483 AALINE(x1, y1, x2, y2,
484 DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
488 AALINE(x1, y1, x2, y2,
489 DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
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,
501 const SDL_PixelFormat *fmt = dst->format;
502 unsigned r, g, b, a, inva;
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);
519 case SDL_BLENDMODE_BLEND:
520 HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
522 case SDL_BLENDMODE_ADD:
523 HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
526 HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
529 } else if (x1 == x2) {
531 case SDL_BLENDMODE_BLEND:
532 VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
534 case SDL_BLENDMODE_ADD:
535 VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
538 VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
541 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
543 case SDL_BLENDMODE_BLEND:
544 DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
546 case SDL_BLENDMODE_ADD:
547 DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
550 DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
555 case SDL_BLENDMODE_BLEND:
556 AALINE(x1, y1, x2, y2,
557 DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
560 case SDL_BLENDMODE_ADD:
561 AALINE(x1, y1, x2, y2,
562 DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
566 AALINE(x1, y1, x2, y2,
567 DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
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,
581 SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
583 switch (fmt->BytesPerPixel) {
585 if (fmt->Rmask == 0x7C00) {
586 return SDL_BlendLine_RGB555;
587 } else if (fmt->Rmask == 0xF800) {
588 return SDL_BlendLine_RGB565;
590 return SDL_BlendLine_RGB2;
594 if (fmt->Rmask == 0x00FF0000) {
596 return SDL_BlendLine_ARGB8888;
598 return SDL_BlendLine_RGB888;
602 return SDL_BlendLine_RGBA4;
604 return SDL_BlendLine_RGB4;
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)
618 SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
622 func = SDL_CalculateBlendLineFunc(dst->format);
624 SDL_SetError("SDL_BlendLine(): Unsupported surface format");
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)) {
634 func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
639 SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
640 SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
649 SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
653 func = SDL_CalculateBlendLineFunc(dst->format);
655 SDL_SetError("SDL_BlendLines(): Unsupported surface format");
659 for (i = 1; i < count; ++i) {
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)) {
671 /* Draw the end if it was clipped */
672 draw_end = (x2 != points[i].x || y2 != points[i].y);
674 func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
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);
683 /* vi: set ts=4 sw=4 expandtab: */