Mercurial > sdl-ios-xcode
diff src/video/SDL_blendrect.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 | 3a9636c83849 |
children |
line wrap: on
line diff
--- a/src/video/SDL_blendrect.c Mon Dec 07 10:08:24 2009 +0000 +++ b/src/video/SDL_blendrect.c Wed Dec 09 15:56:56 2009 +0000 @@ -25,7 +25,7 @@ #include "SDL_draw.h" static int -SDL_BlendRect_RGB555(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -48,7 +48,7 @@ } static int -SDL_BlendRect_RGB565(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -71,7 +71,7 @@ } static int -SDL_BlendRect_RGB888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -94,7 +94,7 @@ } static int -SDL_BlendRect_ARGB8888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -117,7 +117,7 @@ } static int -SDL_BlendRect_RGB(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; @@ -163,7 +163,7 @@ } static int -SDL_BlendRect_RGBA(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; @@ -193,68 +193,155 @@ } int -SDL_BlendRect(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) +SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - SDL_PixelFormat *fmt = dst->format; + SDL_Rect clipped; - /* This function doesn't work on surfaces < 8 bpp */ - if (fmt->BitsPerPixel < 8) { - SDL_SetError("SDL_BlendRect(): Unsupported surface format"); - return (-1); + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; } - /* If 'dstrect' == NULL, then fill the whole surface */ - if (dstrect) { - /* Perform clipping */ - if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { - return (0); - } - } else { - dstrect = &dst->clip_rect; + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_BlendRect(): Unsupported surface format"); + return -1; } - if ((blendMode == SDL_BLENDMODE_BLEND) - || (blendMode == SDL_BLENDMODE_ADD)) { + /* If 'rect' == NULL, then fill the whole surface */ + if (rect) { + /* Perform clipping */ + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { + return 0; + } + rect = &clipped; + } else { + rect = &dst->clip_rect; + } + + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } - switch (fmt->BitsPerPixel) { + switch (dst->format->BitsPerPixel) { case 15: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x7C00: - return SDL_BlendRect_RGB555(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGB555(dst, rect, blendMode, r, g, b, a); } break; case 16: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0xF800: - return SDL_BlendRect_RGB565(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGB565(dst, rect, blendMode, r, g, b, a); } break; case 32: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x00FF0000: - if (!fmt->Amask) { - return SDL_BlendRect_RGB888(dst, dstrect, blendMode, r, g, b, - a); + if (!dst->format->Amask) { + return SDL_BlendRect_RGB888(dst, rect, blendMode, r, g, b, a); } else { - return SDL_BlendRect_ARGB8888(dst, dstrect, blendMode, r, g, - b, a); + return SDL_BlendRect_ARGB8888(dst, rect, blendMode, r, g, b, a); } break; } + break; default: break; } - if (!fmt->Amask) { - return SDL_BlendRect_RGB(dst, dstrect, blendMode, r, g, b, a); + if (!dst->format->Amask) { + return SDL_BlendRect_RGB(dst, rect, blendMode, r, g, b, a); } else { - return SDL_BlendRect_RGBA(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGBA(dst, rect, blendMode, r, g, b, a); } } +int +SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + SDL_Rect clipped; + int i; + int (*func)(SDL_Surface * dst, const SDL_Rect * rect, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + int status = 0; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_BlendRects(): Unsupported surface format"); + return -1; + } + + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { + r = DRAW_MUL(r, a); + g = DRAW_MUL(g, a); + b = DRAW_MUL(b, a); + } + + /* FIXME: Does this function pointer slow things down significantly? */ + switch (dst->format->BitsPerPixel) { + case 15: + switch (dst->format->Rmask) { + case 0x7C00: + func = SDL_BlendRect_RGB555; + } + break; + case 16: + switch (dst->format->Rmask) { + case 0xF800: + func = SDL_BlendRect_RGB565; + } + break; + case 32: + switch (dst->format->Rmask) { + case 0x00FF0000: + if (!dst->format->Amask) { + func = SDL_BlendRect_RGB888; + } else { + func = SDL_BlendRect_ARGB8888; + } + break; + } + break; + default: + break; + } + + if (!func) { + if (!dst->format->Amask) { + func = SDL_BlendRect_RGB; + } else { + func = SDL_BlendRect_RGBA; + } + } + + for (i = 0; i < count; ++i) { + const SDL_Rect * rect = rects[i]; + + /* If 'rect' == NULL, then fill the whole surface */ + if (rect) { + /* Perform clipping */ + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { + continue; + } + rect = &clipped; + } else { + rect = &dst->clip_rect; + } + + status = func(dst, rect, blendMode, r, g, b, a); + } + return status; +} + /* vi: set ts=4 sw=4 expandtab: */