Mercurial > sdl-ios-xcode
annotate src/video/SDL_draw.h @ 5148:2f44e6969a59
Split the rendering API out into a separate header file.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Feb 2011 15:02:21 -0800 |
parents | e743b9c3f6d6 |
children |
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 |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
2898
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 | 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 | 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_SETPIXELXY(x, y, type, bpp, op) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 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
|
75 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
|
76 + (x) * bpp); \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 op; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 } while (0) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 /* |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 * Define draw operators for RGB555 |
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 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 #define DRAW_SETPIXEL_RGB555 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 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
|
86 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 #define DRAW_SETPIXEL_BLEND_RGB555 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 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
|
89 RGB555_FROM_RGB(*pixel, sr, sg, sb)) |
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_SETPIXEL_ADD_RGB555 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 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
|
93 RGB555_FROM_RGB(*pixel, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 #define DRAW_SETPIXELXY_RGB555(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 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
|
97 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 #define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 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
|
100 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 #define DRAW_SETPIXELXY_ADD_RGB555(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 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
|
103 |
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 operators for RGB565 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 */ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 #define DRAW_SETPIXEL_RGB565 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 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
|
110 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 #define DRAW_SETPIXEL_BLEND_RGB565 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 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
|
113 RGB565_FROM_RGB(*pixel, sr, sg, sb)) |
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_SETPIXEL_ADD_RGB565 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 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
|
117 RGB565_FROM_RGB(*pixel, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 #define DRAW_SETPIXELXY_RGB565(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 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
|
121 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 #define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 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
|
124 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 #define DRAW_SETPIXELXY_ADD_RGB565(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 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
|
127 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 /* |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 * Define draw operators for RGB888 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 */ |
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_RGB888 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 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
|
134 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 #define DRAW_SETPIXEL_BLEND_RGB888 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 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
|
137 RGB888_FROM_RGB(*pixel, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 #define DRAW_SETPIXEL_ADD_RGB888 \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 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
|
141 RGB888_FROM_RGB(*pixel, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 #define DRAW_SETPIXELXY_RGB888(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 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
|
145 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 #define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 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
|
148 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 #define DRAW_SETPIXELXY_ADD_RGB888(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 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
|
151 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 /* |
2899
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
153 * Define draw operators for ARGB8888 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
154 */ |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
155 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
156 #define DRAW_SETPIXEL_ARGB8888 \ |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
157 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
|
158 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
159 #define DRAW_SETPIXEL_BLEND_ARGB8888 \ |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
160 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
|
161 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
|
162 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
163 #define DRAW_SETPIXEL_ADD_ARGB8888 \ |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
164 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
|
165 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
|
166 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
167 #define DRAW_SETPIXELXY_ARGB8888(x, y) \ |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
168 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
|
169 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
170 #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
|
171 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
|
172 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
173 #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
|
174 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
|
175 |
a0c837a16e4c
Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents:
2898
diff
changeset
|
176 /* |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 * Define draw operators for general RGB |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 */ |
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_SETPIXEL_RGB \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 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
|
182 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 #define DRAW_SETPIXEL_BLEND_RGB \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 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
|
185 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 #define DRAW_SETPIXEL_ADD_RGB \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 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
|
189 PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 #define DRAW_SETPIXELXY2_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 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
|
193 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 #define DRAW_SETPIXELXY4_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 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
|
196 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 #define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 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
|
199 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 #define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 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
|
202 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 #define DRAW_SETPIXELXY2_ADD_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 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
|
205 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 #define DRAW_SETPIXELXY4_ADD_RGB(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 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
|
208 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 /* |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 * Define draw operators for general RGBA |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 */ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 #define DRAW_SETPIXEL_RGBA \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 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
|
216 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 #define DRAW_SETPIXEL_BLEND_RGBA \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 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
|
219 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
|
220 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 #define DRAW_SETPIXEL_ADD_RGBA \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 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
|
223 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
|
224 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 #define DRAW_SETPIXELXY4_RGBA(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 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
|
227 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 #define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 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
|
230 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 #define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 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
|
233 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 /* |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 * Define line drawing macro |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 */ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 #define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
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
|
240 /* 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
|
241 #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
|
242 { \ |
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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 } 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
|
250 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
|
251 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
|
252 ++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
|
253 } \ |
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
|
254 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
|
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
|
256 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
|
257 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
|
258 ++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
|
259 } \ |
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
|
260 } |
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
|
261 |
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
|
262 /* 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
|
263 #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
|
264 { \ |
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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 } 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
|
272 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
|
273 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
|
274 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
|
275 } \ |
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
|
276 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
|
277 } \ |
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
|
278 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
|
279 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
|
280 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
|
281 } \ |
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
|
282 } |
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
|
283 |
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
|
284 /* 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
|
285 #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
|
286 { \ |
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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 ++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
|
294 } 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
|
295 --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
|
296 } \ |
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 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
|
298 } 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
|
299 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
|
300 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
|
301 ++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
|
302 } 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
|
303 --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
|
304 } \ |
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 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
|
306 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
|
307 } \ |
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 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
|
309 } \ |
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 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
|
311 ++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 } \ |
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 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
|
314 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
|
315 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
|
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 } |
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 |
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 /* 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
|
320 #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
|
321 { \ |
2903
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
327 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
|
328 deltay = ABS(y2 - y1); \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 \ |
2903
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
330 if (deltax >= deltay) { \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
331 numpixels = deltax + 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
332 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
|
333 dinc1 = deltay * 2; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
334 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
|
335 xinc1 = 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
336 xinc2 = 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
337 yinc1 = 0; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
338 yinc2 = 1; \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 } else { \ |
2903
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
340 numpixels = deltay + 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
341 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
|
342 dinc1 = deltax * 2; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
343 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
|
344 xinc1 = 0; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
345 xinc2 = 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
346 yinc1 = 1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
347 yinc2 = 1; \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 } \ |
2903
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
349 \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
350 if (x1 > x2) { \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
351 xinc1 = -xinc1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
352 xinc2 = -xinc2; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
353 } \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
354 if (y1 > y2) { \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
355 yinc1 = -yinc1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
356 yinc2 = -yinc2; \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 } \ |
2903
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
358 \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
359 x = x1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
360 y = y1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
361 \ |
3594
c8bed77b0386
Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents:
3593
diff
changeset
|
362 if (!draw_end) { \ |
c8bed77b0386
Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents:
3593
diff
changeset
|
363 --numpixels; \ |
c8bed77b0386
Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Sam Lantinga <slouken@libsdl.org>
parents:
3593
diff
changeset
|
364 } \ |
3063
9f2482d6662c
Fixed off by one error in line drawing code
Sam Lantinga <slouken@libsdl.org>
parents:
2918
diff
changeset
|
365 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
|
366 op(x, y); \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
367 if (d < 0) { \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
368 d += dinc1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
369 x += xinc1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
370 y += yinc1; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
371 } else { \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
372 d += dinc2; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
373 x += xinc2; \ |
e426c4fc9cf7
Working Bresenham line drawing algorithm. We can optimize later, if needed.
Sam Lantinga <slouken@libsdl.org>
parents:
2901
diff
changeset
|
374 y += yinc2; \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 } \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 } \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 } |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 |
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
|
379 /* 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
|
380 #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
|
381 { \ |
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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 \ |
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
|
387 /* 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
|
388 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
|
389 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
|
390 \ |
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
|
391 /* 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
|
392 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
|
393 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
|
394 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
|
395 } \ |
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
|
396 \ |
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
|
397 /* 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
|
398 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
|
399 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
|
400 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
|
401 } \ |
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
|
402 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
|
403 \ |
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
|
404 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
|
405 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
|
406 } 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
|
407 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
|
408 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
|
409 } \ |
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
|
410 \ |
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
|
411 /* 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
|
412 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
|
413 \ |
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
|
414 /* 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
|
415 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
|
416 /* 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
|
417 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
|
418 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
|
419 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
|
420 /* 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 /* 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
|
426 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
|
427 } \ |
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
|
428 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
|
429 /* 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
|
430 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
|
431 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
|
432 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
|
433 { \ |
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 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 } \ |
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 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 } \ |
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 } \ |
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 } 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
|
451 /* 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
|
452 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
|
453 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
|
454 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
|
455 /* 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 /* 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
|
461 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
|
462 } \ |
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 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
|
464 /* 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
|
465 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
|
466 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
|
467 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
|
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 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 } \ |
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 { \ |
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 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 } \ |
3593
b931bcfd94a0
In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
484 } \ |
b931bcfd94a0
In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
485 } \ |
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
|
486 } |
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 |
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 #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
|
489 #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
|
490 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
|
491 #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
|
492 #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
|
493 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
|
494 #endif |
3593
b931bcfd94a0
In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
495 |
b931bcfd94a0
In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
496 /* |
b931bcfd94a0
In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
497 * Define fill rect macro |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 */ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 |
2900
3a9636c83849
Make it possible to switch algorithms in the future
Sam Lantinga <slouken@libsdl.org>
parents:
2899
diff
changeset
|
500 #define FILLRECT(type, op) \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 do { \ |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3063
diff
changeset
|
502 int width = rect->w; \ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3063
diff
changeset
|
503 int height = rect->h; \ |
2898
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 int pitch = (dst->pitch / dst->format->BytesPerPixel); \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 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
|
506 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
|
507 while (height--) { \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 { int n = (width+3)/4; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 switch (width & 3) { \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 case 0: do { op; pixel++; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 case 3: op; pixel++; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 case 2: op; pixel++; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 case 1: op; pixel++; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 } while ( --n > 0 ); \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 } \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 } \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 pixel += skip; \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 } \ |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 } while (0) |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 |
e40448bc7727
Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 /* vi: set ts=4 sw=4 expandtab: */ |