annotate src/video/SDL_draw.h @ 2898:e40448bc7727

Share code between fill and line drawing Added general RGB surface format fallbacks to drawing code Fixed issues with destination surface alpha channel
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 Dec 2008 08:28:25 +0000
parents
children a0c837a16e4c
rev   line source
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_blit.h"
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* This code assumes that r, g, b, a are the source color,
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * and in the blend and add case, the RGB values are premultiplied by a.
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #define DRAW_SETPIXEL(setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 unsigned sr = r, sg = g, sb = b, sa = a; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 sr = DRAW_MUL(inva, sr) + r; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 sg = DRAW_MUL(inva, sg) + g; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 sb = DRAW_MUL(inva, sb) + b; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 sr += r; if (sr > 0xff) sr = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 sg += g; if (sg > 0xff) sg = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 sb += b; if (sb > 0xff) sb = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 #define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 sr = DRAW_MUL(sr, r); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 sg = DRAW_MUL(sg, g); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 sb = DRAW_MUL(sb, b); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #define DRAW_SETPIXELXY(x, y, type, bpp, op) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 type *pixel = (type *)(dst->pixels + y * dst->pitch + x * bpp); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 op; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 * Define draw operators for RGB555
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 #define DRAW_SETPIXEL_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 #define DRAW_SETPIXEL_BLEND_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 RGB555_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 #define DRAW_SETPIXEL_ADD_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 RGB555_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 #define DRAW_SETPIXEL_MOD_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 RGB555_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 #define DRAW_SETPIXELXY_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 * Define draw operators for RGB565
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 #define DRAW_SETPIXEL_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 #define DRAW_SETPIXEL_BLEND_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 RGB565_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 #define DRAW_SETPIXEL_ADD_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 RGB565_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 #define DRAW_SETPIXEL_MOD_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 RGB565_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 #define DRAW_SETPIXELXY_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 * Define draw operators for RGB888
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #define DRAW_SETPIXEL_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 #define DRAW_SETPIXEL_BLEND_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 RGB888_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 #define DRAW_SETPIXEL_ADD_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 RGB888_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 #define DRAW_SETPIXEL_MOD_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 RGB888_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 #define DRAW_SETPIXELXY_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 * Define draw operators for general RGB
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 #define DRAW_SETPIXEL_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 #define DRAW_SETPIXEL_BLEND_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 #define DRAW_SETPIXEL_ADD_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 #define DRAW_SETPIXEL_MOD_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 #define DRAW_SETPIXELXY2_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 #define DRAW_SETPIXELXY4_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 * Define draw operators for general RGBA
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 #define DRAW_SETPIXEL_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 #define DRAW_SETPIXEL_BLEND_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 #define DRAW_SETPIXEL_ADD_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 #define DRAW_SETPIXEL_MOD_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 #define DRAW_SETPIXELXY4_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 * Define line drawing macro
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 #define SWAP(_x, _y) do { int tmp; tmp = _x; _x = _y; _y = tmp; } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 #define BRESENHAM(x0, y0, x1, y1, op) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 int deltax, deltay, steep, error, xstep, ystep, x, y; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 deltax = ABS(x1 - x0); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 deltay = ABS(y1 - y0); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 steep = (deltay > deltax); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 if (steep) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 SWAP(x0, y0); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 SWAP(x1, y1); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 SWAP(deltax, deltay); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 error = (x1 - x0) / 2; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 y = y0; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 if (x0 > x1) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 xstep = -1; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 } else { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 xstep = 1; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 if (y0 < y1) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 ystep = 1; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 } else { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 ystep = -1; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 if (!steep) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 for (x = x0; x != x1; x += xstep) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 op(x, y); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 error -= deltay; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 if (error < 0) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 y += ystep; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 error += deltax; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 } else { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 for (x = x0; x != x1; x += xstep) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 op(y, x); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 error -= deltay; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 if (error < 0) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 y += ystep; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 error += deltax; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 * Define blend fill macro
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 #define BLENDRECT(type, op) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 int w; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 int width = dstrect->w; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 int height = dstrect->h; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 int skip = pitch - width; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 type *pixel = (type *)dst->pixels + dstrect->y * pitch + dstrect->x; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 while (height--) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 { int n = (width+3)/4; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 switch (width & 3) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 case 0: do { op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 case 3: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 case 2: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 case 1: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 } while ( --n > 0 ); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 pixel += skip; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 * Define blend line macro
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 /* vi: set ts=4 sw=4 expandtab: */