Mercurial > sdl-ios-xcode
comparison src/video/SDL_blendline.c @ 3594:c8bed77b0386
Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Fixed line drawing so when blending a sequence of lines there are no overlapping pixels drawn.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 18 Dec 2009 07:41:59 +0000 |
parents | 0267b8b1595c |
children | f638ded38b8a |
comparison
equal
deleted
inserted
replaced
3593:b931bcfd94a0 | 3594:c8bed77b0386 |
---|---|
23 | 23 |
24 #include "SDL_draw.h" | 24 #include "SDL_draw.h" |
25 | 25 |
26 static int | 26 static int |
27 SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 27 SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
28 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 28 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
29 SDL_bool draw_end) | |
29 { | 30 { |
30 unsigned inva = 0xff - a; | 31 unsigned inva = 0xff - a; |
31 | 32 |
32 switch (blendMode) { | 33 switch (blendMode) { |
33 case SDL_BLENDMODE_BLEND: | 34 case SDL_BLENDMODE_BLEND: |
34 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555); | 35 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555, draw_end); |
35 break; | 36 break; |
36 case SDL_BLENDMODE_ADD: | 37 case SDL_BLENDMODE_ADD: |
37 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555); | 38 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555, draw_end); |
38 break; | 39 break; |
39 case SDL_BLENDMODE_MOD: | 40 case SDL_BLENDMODE_MOD: |
40 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555); | 41 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555, draw_end); |
41 break; | 42 break; |
42 default: | 43 default: |
43 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555); | 44 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555, draw_end); |
44 break; | 45 break; |
45 } | 46 } |
46 return 0; | 47 return 0; |
47 } | 48 } |
48 | 49 |
49 static int | 50 static int |
50 SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 51 SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
51 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 52 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
53 SDL_bool draw_end) | |
52 { | 54 { |
53 unsigned inva = 0xff - a; | 55 unsigned inva = 0xff - a; |
54 | 56 |
55 switch (blendMode) { | 57 switch (blendMode) { |
56 case SDL_BLENDMODE_BLEND: | 58 case SDL_BLENDMODE_BLEND: |
57 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565); | 59 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565, draw_end); |
58 break; | 60 break; |
59 case SDL_BLENDMODE_ADD: | 61 case SDL_BLENDMODE_ADD: |
60 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565); | 62 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565, draw_end); |
61 break; | 63 break; |
62 case SDL_BLENDMODE_MOD: | 64 case SDL_BLENDMODE_MOD: |
63 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565); | 65 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565, draw_end); |
64 break; | 66 break; |
65 default: | 67 default: |
66 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565); | 68 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565, draw_end); |
67 break; | 69 break; |
68 } | 70 } |
69 return 0; | 71 return 0; |
70 } | 72 } |
71 | 73 |
72 static int | 74 static int |
73 SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 75 SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
74 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 76 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
77 SDL_bool draw_end) | |
75 { | 78 { |
76 unsigned inva = 0xff - a; | 79 unsigned inva = 0xff - a; |
77 | 80 |
78 switch (blendMode) { | 81 switch (blendMode) { |
79 case SDL_BLENDMODE_BLEND: | 82 case SDL_BLENDMODE_BLEND: |
80 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888); | 83 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888, draw_end); |
81 break; | 84 break; |
82 case SDL_BLENDMODE_ADD: | 85 case SDL_BLENDMODE_ADD: |
83 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888); | 86 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888, draw_end); |
84 break; | 87 break; |
85 case SDL_BLENDMODE_MOD: | 88 case SDL_BLENDMODE_MOD: |
86 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888); | 89 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888, draw_end); |
87 break; | 90 break; |
88 default: | 91 default: |
89 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888); | 92 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888, draw_end); |
90 break; | 93 break; |
91 } | 94 } |
92 return 0; | 95 return 0; |
93 } | 96 } |
94 | 97 |
95 static int | 98 static int |
96 SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 99 SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
97 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 100 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
101 SDL_bool draw_end) | |
98 { | 102 { |
99 unsigned inva = 0xff - a; | 103 unsigned inva = 0xff - a; |
100 | 104 |
101 switch (blendMode) { | 105 switch (blendMode) { |
102 case SDL_BLENDMODE_BLEND: | 106 case SDL_BLENDMODE_BLEND: |
103 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888); | 107 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end); |
104 break; | 108 break; |
105 case SDL_BLENDMODE_ADD: | 109 case SDL_BLENDMODE_ADD: |
106 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888); | 110 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888, draw_end); |
107 break; | 111 break; |
108 case SDL_BLENDMODE_MOD: | 112 case SDL_BLENDMODE_MOD: |
109 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888); | 113 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888, draw_end); |
110 break; | 114 break; |
111 default: | 115 default: |
112 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888); | 116 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888, draw_end); |
113 break; | 117 break; |
114 } | 118 } |
115 return 0; | 119 return 0; |
116 } | 120 } |
117 | 121 |
118 static int | 122 static int |
119 SDL_BlendLine_RGB(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 123 SDL_BlendLine_RGB(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
120 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 124 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
125 SDL_bool draw_end) | |
121 { | 126 { |
122 SDL_PixelFormat *fmt = dst->format; | 127 SDL_PixelFormat *fmt = dst->format; |
123 unsigned inva = 0xff - a; | 128 unsigned inva = 0xff - a; |
124 | 129 |
125 switch (fmt->BytesPerPixel) { | 130 switch (fmt->BytesPerPixel) { |
126 case 2: | 131 case 2: |
127 switch (blendMode) { | 132 switch (blendMode) { |
128 case SDL_BLENDMODE_BLEND: | 133 case SDL_BLENDMODE_BLEND: |
129 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB); | 134 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB, draw_end); |
130 break; | 135 break; |
131 case SDL_BLENDMODE_ADD: | 136 case SDL_BLENDMODE_ADD: |
132 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB); | 137 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB, draw_end); |
133 break; | 138 break; |
134 case SDL_BLENDMODE_MOD: | 139 case SDL_BLENDMODE_MOD: |
135 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB); | 140 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB, draw_end); |
136 break; | 141 break; |
137 default: | 142 default: |
138 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB); | 143 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB, draw_end); |
139 break; | 144 break; |
140 } | 145 } |
141 return 0; | 146 return 0; |
142 case 4: | 147 case 4: |
143 switch (blendMode) { | 148 switch (blendMode) { |
144 case SDL_BLENDMODE_BLEND: | 149 case SDL_BLENDMODE_BLEND: |
145 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB); | 150 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB, draw_end); |
146 break; | 151 break; |
147 case SDL_BLENDMODE_ADD: | 152 case SDL_BLENDMODE_ADD: |
148 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB); | 153 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB, draw_end); |
149 break; | 154 break; |
150 case SDL_BLENDMODE_MOD: | 155 case SDL_BLENDMODE_MOD: |
151 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB); | 156 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB, draw_end); |
152 break; | 157 break; |
153 default: | 158 default: |
154 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB); | 159 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB, draw_end); |
155 break; | 160 break; |
156 } | 161 } |
157 return 0; | 162 return 0; |
158 default: | 163 default: |
159 SDL_Unsupported(); | 164 SDL_Unsupported(); |
161 } | 166 } |
162 } | 167 } |
163 | 168 |
164 static int | 169 static int |
165 SDL_BlendLine_RGBA(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 170 SDL_BlendLine_RGBA(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
166 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 171 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
172 SDL_bool draw_end) | |
167 { | 173 { |
168 SDL_PixelFormat *fmt = dst->format; | 174 SDL_PixelFormat *fmt = dst->format; |
169 unsigned inva = 0xff - a; | 175 unsigned inva = 0xff - a; |
170 | 176 |
171 switch (fmt->BytesPerPixel) { | 177 switch (fmt->BytesPerPixel) { |
172 case 4: | 178 case 4: |
173 switch (blendMode) { | 179 switch (blendMode) { |
174 case SDL_BLENDMODE_BLEND: | 180 case SDL_BLENDMODE_BLEND: |
175 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA); | 181 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA, draw_end); |
176 break; | 182 break; |
177 case SDL_BLENDMODE_ADD: | 183 case SDL_BLENDMODE_ADD: |
178 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA); | 184 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA, draw_end); |
179 break; | 185 break; |
180 case SDL_BLENDMODE_MOD: | 186 case SDL_BLENDMODE_MOD: |
181 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA); | 187 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA, draw_end); |
182 break; | 188 break; |
183 default: | 189 default: |
184 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA); | 190 DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA, draw_end); |
185 break; | 191 break; |
186 } | 192 } |
187 return 0; | 193 return 0; |
188 default: | 194 default: |
189 SDL_Unsupported(); | 195 SDL_Unsupported(); |
216 switch (dst->format->BitsPerPixel) { | 222 switch (dst->format->BitsPerPixel) { |
217 case 15: | 223 case 15: |
218 switch (dst->format->Rmask) { | 224 switch (dst->format->Rmask) { |
219 case 0x7C00: | 225 case 0x7C00: |
220 return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g, | 226 return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g, |
221 b, a); | 227 b, a, SDL_TRUE); |
222 } | 228 } |
223 break; | 229 break; |
224 case 16: | 230 case 16: |
225 switch (dst->format->Rmask) { | 231 switch (dst->format->Rmask) { |
226 case 0xF800: | 232 case 0xF800: |
227 return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g, | 233 return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g, |
228 b, a); | 234 b, a, SDL_TRUE); |
229 } | 235 } |
230 break; | 236 break; |
231 case 32: | 237 case 32: |
232 switch (dst->format->Rmask) { | 238 switch (dst->format->Rmask) { |
233 case 0x00FF0000: | 239 case 0x00FF0000: |
234 if (!dst->format->Amask) { | 240 if (!dst->format->Amask) { |
235 return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r, | 241 return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r, |
236 g, b, a); | 242 g, b, a, SDL_TRUE); |
237 } else { | 243 } else { |
238 return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode, | 244 return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode, |
239 r, g, b, a); | 245 r, g, b, a, SDL_TRUE); |
240 } | 246 } |
241 break; | 247 break; |
242 } | 248 } |
243 break; | 249 break; |
244 default: | 250 default: |
245 break; | 251 break; |
246 } | 252 } |
247 | 253 |
248 if (!dst->format->Amask) { | 254 if (!dst->format->Amask) { |
249 return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a); | 255 return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, |
256 r, g, b, a, SDL_TRUE); | |
250 } else { | 257 } else { |
251 return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a); | 258 return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, |
259 r, g, b, a, SDL_TRUE); | |
252 } | 260 } |
253 } | 261 } |
254 | 262 |
255 int | 263 int |
256 SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, | 264 SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, |
258 { | 266 { |
259 int i; | 267 int i; |
260 int x1, y1; | 268 int x1, y1; |
261 int x2, y2; | 269 int x2, y2; |
262 int (*func)(SDL_Surface * dst, int x1, int y1, int x2, int y2, | 270 int (*func)(SDL_Surface * dst, int x1, int y1, int x2, int y2, |
263 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; | 271 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
272 SDL_bool draw_end) = NULL; | |
264 int status = 0; | 273 int status = 0; |
265 | 274 |
266 if (!dst) { | 275 if (!dst) { |
267 SDL_SetError("Passed NULL destination surface"); | 276 SDL_SetError("Passed NULL destination surface"); |
268 return -1; | 277 return -1; |
326 /* FIXME: We don't actually want to clip, as it may change line slope */ | 335 /* FIXME: We don't actually want to clip, as it may change line slope */ |
327 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | 336 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { |
328 continue; | 337 continue; |
329 } | 338 } |
330 | 339 |
331 status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a); | 340 status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_FALSE); |
341 } | |
342 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { | |
343 SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, r, g, b, a); | |
332 } | 344 } |
333 return status; | 345 return status; |
334 } | 346 } |
335 | 347 |
336 /* vi: set ts=4 sw=4 expandtab: */ | 348 /* vi: set ts=4 sw=4 expandtab: */ |