annotate src/video/SDL_draw.h @ 3603:847549156244

Removed in the interest of actually finishing 1.3. :) They can be done later, either by me or by someone else.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 30 Dec 2009 19:10:41 +0000
parents f638ded38b8a
children f7b03b6838cb
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
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
32 #define DRAW_FASTSETPIXEL(type) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
33 *pixel = (type) color
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
34
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
35 #define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
36 #define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
37 #define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2900
diff changeset
38
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
39 #define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
40 *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
41 + (x) * bpp) = (type) color
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
42
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
43 #define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
44 #define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
45 #define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
2901
133601e3b255 Added RenderPiont() API
Sam Lantinga <slouken@libsdl.org>
parents: 2900
diff changeset
46
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #define DRAW_SETPIXEL(setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 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
50 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 #define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 sr = DRAW_MUL(inva, sr) + r; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 sg = DRAW_MUL(inva, sg) + g; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 sb = DRAW_MUL(inva, sb) + b; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 sr += r; if (sr > 0xff) sr = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 sg += g; if (sg > 0xff) sg = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 sb += b; if (sb > 0xff) sb = 0xff; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 #define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 do { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 unsigned sr, sg, sb, sa; sa; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 getpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 sr = DRAW_MUL(sr, r); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 sg = DRAW_MUL(sg, g); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 sb = DRAW_MUL(sb, b); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 setpixel; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #define DRAW_SETPIXELXY(x, y, type, bpp, op) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 do { \
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
85 type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
86 + (x) * bpp); \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 op; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 * Define draw operators for RGB555
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
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 #define DRAW_SETPIXEL_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 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
96
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 #define DRAW_SETPIXEL_BLEND_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 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
99 RGB555_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 #define DRAW_SETPIXEL_ADD_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 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
103 RGB555_FROM_RGB(*pixel, sr, sg, sb))
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 #define DRAW_SETPIXEL_MOD_RGB555 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 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
107 RGB555_FROM_RGB(*pixel, sr, sg, sb))
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_SETPIXELXY_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 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
111
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 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
114
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 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
117
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 #define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 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
120
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 * Define draw operators for RGB565
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
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 #define DRAW_SETPIXEL_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 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
127
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 #define DRAW_SETPIXEL_BLEND_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 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
130 RGB565_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 #define DRAW_SETPIXEL_ADD_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 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
134 RGB565_FROM_RGB(*pixel, sr, sg, sb))
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 #define DRAW_SETPIXEL_MOD_RGB565 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 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
138 RGB565_FROM_RGB(*pixel, sr, sg, sb))
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_SETPIXELXY_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 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
142
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 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
145
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 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
148
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 #define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 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
151
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 * Define draw operators for RGB888
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
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 #define DRAW_SETPIXEL_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 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
158
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 #define DRAW_SETPIXEL_BLEND_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 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
161 RGB888_FROM_RGB(*pixel, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 #define DRAW_SETPIXEL_ADD_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 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
165 RGB888_FROM_RGB(*pixel, sr, sg, sb))
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 #define DRAW_SETPIXEL_MOD_RGB888 \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 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
169 RGB888_FROM_RGB(*pixel, sr, sg, sb))
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_SETPIXELXY_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 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
173
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 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
176
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 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
179
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 #define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 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
182
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 /*
2899
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
184 * Define draw operators for ARGB8888
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
185 */
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
186
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
187 #define DRAW_SETPIXEL_ARGB8888 \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
188 DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
189
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
190 #define DRAW_SETPIXEL_BLEND_ARGB8888 \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
191 DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
192 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
193
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
194 #define DRAW_SETPIXEL_ADD_ARGB8888 \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
195 DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
196 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
197
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
198 #define DRAW_SETPIXEL_MOD_ARGB8888 \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
199 DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
200 ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
201
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
202 #define DRAW_SETPIXELXY_ARGB8888(x, y) \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
203 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
204
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
205 #define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
206 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
207
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
208 #define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
209 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
210
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
211 #define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
212 DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888)
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
213
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
214 /*
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 * Define draw operators for general RGB
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 */
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_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 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
220
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 #define DRAW_SETPIXEL_BLEND_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 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
223 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 #define DRAW_SETPIXEL_ADD_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 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
227 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 #define DRAW_SETPIXEL_MOD_RGB \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 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
231 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
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_SETPIXELXY2_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 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
235
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 #define DRAW_SETPIXELXY4_RGB(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_RGB)
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_SETPIXELXY2_BLEND_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 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
241
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 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
244
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 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
247
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 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
250
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 #define DRAW_SETPIXELXY2_MOD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 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
253
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 #define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 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
256
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 * Define draw operators for general RGBA
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 */
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 #define DRAW_SETPIXEL_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 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
264
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 #define DRAW_SETPIXEL_BLEND_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 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
267 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
268
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 #define DRAW_SETPIXEL_ADD_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 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
271 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
272
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 #define DRAW_SETPIXEL_MOD_RGBA \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 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
275 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
276
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 #define DRAW_SETPIXELXY4_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 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
279
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 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
282
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 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
285
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 #define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 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
288
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 /*
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 * Define line drawing macro
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 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
295 /* Horizontal line */
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
296 #define HLINE(type, op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
297 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
298 int length; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
299 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
300 type *pixel; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
301 if (x1 <= x2) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
302 pixel = (type *)dst->pixels + y1 * pitch + x1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
303 length = draw_end ? (x2-x1+1) : (x2-x1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
304 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
305 pixel = (type *)dst->pixels + y1 * pitch + x2; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
306 if (!draw_end) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
307 ++pixel; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
308 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
309 length = draw_end ? (x1-x2+1) : (x1-x2); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
310 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
311 while (length--) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
312 op; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
313 ++pixel; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
314 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
315 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
316
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
317 /* Vertical line */
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
318 #define VLINE(type, op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
319 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
320 int length; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
321 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
322 type *pixel; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
323 if (y1 <= y2) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
324 pixel = (type *)dst->pixels + y1 * pitch + x1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
325 length = draw_end ? (y2-y1+1) : (y2-y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
326 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
327 pixel = (type *)dst->pixels + y2 * pitch + x1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
328 if (!draw_end) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
329 pixel += pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
330 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
331 length = draw_end ? (y1-y2+1) : (y1-y2); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
332 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
333 while (length--) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
334 op; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
335 pixel += pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
336 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
337 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
338
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
339 /* Diagonal line */
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
340 #define DLINE(type, op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
341 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
342 int length; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
343 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
344 type *pixel; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
345 if (y1 <= y2) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
346 pixel = (type *)dst->pixels + y1 * pitch + x1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
347 if (x1 <= x2) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
348 ++pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
349 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
350 --pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
351 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
352 length = (y2-y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
353 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
354 pixel = (type *)dst->pixels + y2 * pitch + x2; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
355 if (x2 <= x1) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
356 ++pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
357 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
358 --pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
359 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
360 if (!draw_end) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
361 pixel += pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
362 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
363 length = (y1-y2); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
364 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
365 if (draw_end) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
366 ++length; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
367 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
368 while (length--) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
369 op; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
370 pixel += pitch; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
371 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
372 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
373
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
374 /* Bresenham's line algorithm */
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
375 #define BLINE(x1, y1, x2, y2, op, draw_end) \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 { \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
377 int i, deltax, deltay, numpixels; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
378 int d, dinc1, dinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
379 int x, xinc1, xinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
380 int y, yinc1, yinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
381 \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
382 deltax = ABS(x2 - x1); \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
383 deltay = ABS(y2 - y1); \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
385 if (deltax >= deltay) { \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
386 numpixels = deltax + 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
387 d = (2 * deltay) - deltax; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
388 dinc1 = deltay * 2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
389 dinc2 = (deltay - deltax) * 2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
390 xinc1 = 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
391 xinc2 = 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
392 yinc1 = 0; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
393 yinc2 = 1; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 } else { \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
395 numpixels = deltay + 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
396 d = (2 * deltax) - deltay; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
397 dinc1 = deltax * 2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
398 dinc2 = (deltax - deltay) * 2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
399 xinc1 = 0; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
400 xinc2 = 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
401 yinc1 = 1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
402 yinc2 = 1; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 } \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
404 \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
405 if (x1 > x2) { \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
406 xinc1 = -xinc1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
407 xinc2 = -xinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
408 } \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
409 if (y1 > y2) { \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
410 yinc1 = -yinc1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
411 yinc2 = -yinc2; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 } \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
413 \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
414 x = x1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
415 y = y1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
416 \
3594
c8bed77b0386 Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents: 3593
diff changeset
417 if (!draw_end) { \
c8bed77b0386 Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents: 3593
diff changeset
418 --numpixels; \
c8bed77b0386 Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents: 3593
diff changeset
419 } \
3063
9f2482d6662c Fixed off by one error in line drawing code
Sam Lantinga <slouken@libsdl.org>
parents: 2918
diff changeset
420 for (i = 0; i < numpixels; ++i) { \
2903
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
421 op(x, y); \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
422 if (d < 0) { \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
423 d += dinc1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
424 x += xinc1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
425 y += yinc1; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
426 } else { \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
427 d += dinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
428 x += xinc2; \
e426c4fc9cf7 Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents: 2901
diff changeset
429 y += yinc2; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 }
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
434 /* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
435 #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
436 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
437 Uint16 ErrorAdj, ErrorAcc; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
438 Uint16 ErrorAccTemp, Weighting; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
439 int DeltaX, DeltaY, Temp, XDir; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
440 unsigned r, g, b, a, inva; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
441 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
442 /* Draw the initial pixel, which is always exactly intersected by \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
443 the line and so needs no weighting */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
444 opaque_op(x1, y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
445 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
446 /* Draw the final pixel, which is always exactly intersected by the line \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
447 and so needs no weighting */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
448 if (draw_end) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
449 opaque_op(x2, y2); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
450 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
451 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
452 /* Make sure the line runs top to bottom */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
453 if (y1 > y2) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
454 Temp = y1; y1 = y2; y2 = Temp; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
455 Temp = x1; x1 = x2; x2 = Temp; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
456 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
457 DeltaY = y2 - y1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
458 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
459 if ((DeltaX = x2 - x1) >= 0) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
460 XDir = 1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
461 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
462 XDir = -1; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
463 DeltaX = -DeltaX; /* make DeltaX positive */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
464 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
465 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
466 /* line is not horizontal, diagonal, or vertical */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
467 ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
468 \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
469 /* Is this an X-major or Y-major line? */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
470 if (DeltaY > DeltaX) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
471 /* Y-major line; calculate 16-bit fixed-point fractional part of a \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
472 pixel that X advances each time Y advances 1 pixel, truncating the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
473 result so that we won't overrun the endpoint along the X axis */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
474 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
475 /* Draw all pixels other than the first and last */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
476 while (--DeltaY) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
477 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
478 ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
479 if (ErrorAcc <= ErrorAccTemp) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
480 /* The error accumulator turned over, so advance the X coord */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
481 x1 += XDir; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
482 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
483 y1++; /* Y-major, so always advance Y */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
484 /* The IntensityBits most significant bits of ErrorAcc give us the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
485 intensity weighting for this pixel, and the complement of the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
486 weighting for the paired pixel */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
487 Weighting = ErrorAcc >> 8; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
488 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
489 a = DRAW_MUL(_a, (Weighting ^ 255)); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
490 r = DRAW_MUL(_r, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
491 g = DRAW_MUL(_g, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
492 b = DRAW_MUL(_b, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
493 inva = (a ^ 0xFF); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
494 blend_op(x1, y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
495 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
496 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
497 a = DRAW_MUL(_a, Weighting); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
498 r = DRAW_MUL(_r, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
499 g = DRAW_MUL(_g, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
500 b = DRAW_MUL(_b, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
501 inva = (a ^ 0xFF); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
502 blend_op(x1 + XDir, y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
503 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
504 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
505 } else { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
506 /* X-major line; calculate 16-bit fixed-point fractional part of a \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
507 pixel that Y advances each time X advances 1 pixel, truncating the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
508 result to avoid overrunning the endpoint along the X axis */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
509 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
510 /* Draw all pixels other than the first and last */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
511 while (--DeltaX) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
512 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
513 ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
514 if (ErrorAcc <= ErrorAccTemp) { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
515 /* The error accumulator turned over, so advance the Y coord */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
516 y1++; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
517 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
518 x1 += XDir; /* X-major, so always advance X */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
519 /* The IntensityBits most significant bits of ErrorAcc give us the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
520 intensity weighting for this pixel, and the complement of the \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
521 weighting for the paired pixel */ \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
522 Weighting = ErrorAcc >> 8; \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
523 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
524 a = DRAW_MUL(_a, (Weighting ^ 255)); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
525 r = DRAW_MUL(_r, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
526 g = DRAW_MUL(_g, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
527 b = DRAW_MUL(_b, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
528 inva = (a ^ 0xFF); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
529 blend_op(x1, y1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
530 } \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
531 { \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
532 a = DRAW_MUL(_a, Weighting); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
533 r = DRAW_MUL(_r, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
534 g = DRAW_MUL(_g, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
535 b = DRAW_MUL(_b, a); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
536 inva = (a ^ 0xFF); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
537 blend_op(x1, y1 + 1); \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
538 } \
3593
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
539 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
540 } \
3596
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
541 }
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
542
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
543 #ifdef AA_LINES
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
544 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
545 WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
546 #else
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
547 #define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
548 BLINE(x1, y1, x2, y2, opaque_op, draw_end)
f638ded38b8a Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Sam Lantinga <slouken@libsdl.org>
parents: 3594
diff changeset
549 #endif
3593
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
550
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
551 /*
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
552 * Define fill rect macro
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 */
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554
2900
3a9636c83849 Make it possible to switch algorithms in the future
Sam Lantinga <slouken@libsdl.org>
parents: 2899
diff changeset
555 #define FILLRECT(type, op) \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 do { \
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3063
diff changeset
557 int width = rect->w; \
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3063
diff changeset
558 int height = rect->h; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 int pitch = (dst->pitch / dst->format->BytesPerPixel); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 int skip = pitch - width; \
3536
0267b8b1595c Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents: 3063
diff changeset
561 type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 while (height--) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 { int n = (width+3)/4; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 switch (width & 3) { \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 case 0: do { op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 case 3: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 case 2: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 case 1: op; pixel++; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 } while ( --n > 0 ); \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 pixel += skip; \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 } \
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 } while (0)
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 /* vi: set ts=4 sw=4 expandtab: */