comparison src/video/SDL_blendline.c @ 3536:0267b8b1595c

Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Dec 2009 15:56:56 +0000
parents 27d8b12e0e8e
children c8bed77b0386
comparison
equal deleted inserted replaced
3535:b403f790df65 3536:0267b8b1595c
193 193
194 int 194 int
195 SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, 195 SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
196 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) 196 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
197 { 197 {
198 SDL_PixelFormat *fmt = dst->format;
199
200 /* This function doesn't work on surfaces < 8 bpp */ 198 /* This function doesn't work on surfaces < 8 bpp */
201 if (dst->format->BitsPerPixel < 8) { 199 if (dst->format->BitsPerPixel < 8) {
202 SDL_SetError("SDL_BlendLine(): Unsupported surface format"); 200 SDL_SetError("SDL_BlendLine(): Unsupported surface format");
203 return (-1); 201 return (-1);
204 } 202 }
207 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { 205 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
208 return (0); 206 return (0);
209 } 207 }
210 208
211 209
212 if ((blendMode == SDL_BLENDMODE_BLEND) 210 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
213 || (blendMode == SDL_BLENDMODE_ADD)) {
214 r = DRAW_MUL(r, a); 211 r = DRAW_MUL(r, a);
215 g = DRAW_MUL(g, a); 212 g = DRAW_MUL(g, a);
216 b = DRAW_MUL(b, a); 213 b = DRAW_MUL(b, a);
217 } 214 }
218 215
219 switch (fmt->BitsPerPixel) { 216 switch (dst->format->BitsPerPixel) {
220 case 15: 217 case 15:
221 switch (fmt->Rmask) { 218 switch (dst->format->Rmask) {
222 case 0x7C00: 219 case 0x7C00:
223 return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g, 220 return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g,
224 b, a); 221 b, a);
225 } 222 }
226 break; 223 break;
227 case 16: 224 case 16:
228 switch (fmt->Rmask) { 225 switch (dst->format->Rmask) {
229 case 0xF800: 226 case 0xF800:
230 return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g, 227 return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g,
231 b, a); 228 b, a);
232 } 229 }
233 break; 230 break;
234 case 32: 231 case 32:
235 switch (fmt->Rmask) { 232 switch (dst->format->Rmask) {
236 case 0x00FF0000: 233 case 0x00FF0000:
237 if (!fmt->Amask) { 234 if (!dst->format->Amask) {
238 return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r, 235 return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r,
239 g, b, a); 236 g, b, a);
240 } else { 237 } else {
241 return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode, 238 return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode,
242 r, g, b, a); 239 r, g, b, a);
243 } 240 }
244 break; 241 break;
245 } 242 }
246 default: 243 break;
247 break; 244 default:
248 } 245 break;
249 246 }
250 if (!fmt->Amask) { 247
248 if (!dst->format->Amask) {
251 return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a); 249 return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
252 } else { 250 } else {
253 return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a); 251 return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
254 } 252 }
255 } 253 }
256 254
255 int
256 SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
257 int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
258 {
259 int i;
260 int x1, y1;
261 int x2, y2;
262 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;
264 int status = 0;
265
266 if (!dst) {
267 SDL_SetError("Passed NULL destination surface");
268 return -1;
269 }
270
271 /* This function doesn't work on surfaces < 8 bpp */
272 if (dst->format->BitsPerPixel < 8) {
273 SDL_SetError("SDL_BlendLines(): Unsupported surface format");
274 return -1;
275 }
276
277 if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
278 r = DRAW_MUL(r, a);
279 g = DRAW_MUL(g, a);
280 b = DRAW_MUL(b, a);
281 }
282
283 /* FIXME: Does this function pointer slow things down significantly? */
284 switch (dst->format->BitsPerPixel) {
285 case 15:
286 switch (dst->format->Rmask) {
287 case 0x7C00:
288 func = SDL_BlendLine_RGB555;
289 }
290 break;
291 case 16:
292 switch (dst->format->Rmask) {
293 case 0xF800:
294 func = SDL_BlendLine_RGB565;
295 }
296 break;
297 case 32:
298 switch (dst->format->Rmask) {
299 case 0x00FF0000:
300 if (!dst->format->Amask) {
301 func = SDL_BlendLine_RGB888;
302 } else {
303 func = SDL_BlendLine_ARGB8888;
304 }
305 break;
306 }
307 default:
308 break;
309 }
310
311 if (!func) {
312 if (!dst->format->Amask) {
313 func = SDL_BlendLine_RGB;
314 } else {
315 func = SDL_BlendLine_RGBA;
316 }
317 }
318
319 for (i = 1; i < count; ++i) {
320 x1 = points[i-1].x;
321 y1 = points[i-1].y;
322 x2 = points[i].x;
323 y2 = points[i].y;
324
325 /* Perform clipping */
326 /* 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)) {
328 continue;
329 }
330
331 status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
332 }
333 return status;
334 }
335
257 /* vi: set ts=4 sw=4 expandtab: */ 336 /* vi: set ts=4 sw=4 expandtab: */