From f1f81edbe7bba3d921695ea51151388104a9cb69 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 3 Feb 2011 02:45:29 -0800 Subject: [PATCH] Making the API simpler, moved the surface drawing functions to the software renderer. --- include/SDL_surface.h | 93 ---------- .../software}/SDL_blendfillrect.c | 3 +- .../software/SDL_blendfillrect.h} | 16 +- .../software}/SDL_blendline.c | 1 + .../software/SDL_blendline.h} | 36 +--- .../software}/SDL_blendpoint.c | 2 + src/render/software/SDL_blendpoint.h | 28 +++ src/{video => render/software}/SDL_draw.h | 2 +- src/{video => render/software}/SDL_drawline.c | 2 + src/render/software/SDL_drawline.h | 28 +++ .../software}/SDL_drawpoint.c | 1 + src/render/software/SDL_drawpoint.h | 28 +++ src/render/software/SDL_renderer_sw.c | 7 + src/video/SDL_blendrect.c | 75 -------- src/video/SDL_blit.h | 2 +- src/video/SDL_drawrect.c | 74 -------- test/automated/surface/surface.c | 165 ------------------ 17 files changed, 106 insertions(+), 457 deletions(-) rename src/{video => render/software}/SDL_blendfillrect.c (99%) rename src/{video/SDL_alphamult.h => render/software/SDL_blendfillrect.h} (69%) rename src/{video => render/software}/SDL_blendline.c (99%) rename src/{video/SDL_alphamult.c => render/software/SDL_blendline.h} (51%) rename src/{video => render/software}/SDL_blendpoint.c (99%) create mode 100644 src/render/software/SDL_blendpoint.h rename src/{video => render/software}/SDL_draw.h (99%) rename src/{video => render/software}/SDL_drawline.c (99%) create mode 100644 src/render/software/SDL_drawline.h rename src/{video => render/software}/SDL_drawpoint.c (99%) create mode 100644 src/render/software/SDL_drawpoint.h delete mode 100644 src/video/SDL_blendrect.c delete mode 100644 src/video/SDL_drawrect.c diff --git a/include/SDL_surface.h b/include/SDL_surface.h index 27f78ede3..9b6d24211 100644 --- a/include/SDL_surface.h +++ b/include/SDL_surface.h @@ -363,85 +363,6 @@ extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, Uint32 dst_format, void * dst, int dst_pitch); -/** - * Draws a point with \c color. - * - * The color should be a pixel of the format used by the surface, and - * can be generated by the SDL_MapRGB() function. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_DrawPoint - (SDL_Surface * dst, int x, int y, Uint32 color); -extern DECLSPEC int SDLCALL SDL_DrawPoints - (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/** - * Blends a point with an RGBA value. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_BlendPoint - (SDL_Surface * dst, int x, int y, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern DECLSPEC int SDLCALL SDL_BlendPoints - (SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/** - * Draws a line with \c color. - * - * The color should be a pixel of the format used by the surface, and - * can be generated by the SDL_MapRGB() function. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_DrawLine - (SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); -extern DECLSPEC int SDLCALL SDL_DrawLines - (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); - -/** - * Blends an RGBA value along a line. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_BlendLine - (SDL_Surface * dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern DECLSPEC int SDLCALL SDL_BlendLines - (SDL_Surface * dst, const SDL_Point * points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - -/** - * Draws the given rectangle with \c color. - * - * If \c rect is NULL, the whole surface will be outlined with \c color. - * - * The color should be a pixel of the format used by the surface, and - * can be generated by the SDL_MapRGB() function. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_DrawRect - (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color); -extern DECLSPEC int SDLCALL SDL_DrawRects - (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color); - -/** - * Blends an RGBA value into the outline of the given rectangle. - * - * If \c rect is NULL, the whole surface will have a blended outline. - * - * \return 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_BlendRect - (SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern DECLSPEC int SDLCALL SDL_BlendRects - (SDL_Surface * dst, const SDL_Rect ** rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - /** * Performs a fast fill of the given rectangle with \c color. * @@ -457,20 +378,6 @@ extern DECLSPEC int SDLCALL SDL_FillRect extern DECLSPEC int SDLCALL SDL_FillRects (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color); -/** - * Blends an RGBA value into the given rectangle. - * - * If \c rect is NULL, the whole surface will be blended with the color. - * - * \return This function returns 0 on success, or -1 on error. - */ -extern DECLSPEC int SDLCALL SDL_BlendFillRect - (SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern DECLSPEC int SDLCALL SDL_BlendFillRects - (SDL_Surface * dst, const SDL_Rect ** rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); - /** * Performs a fast blit from the source surface to the destination surface. * diff --git a/src/video/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c similarity index 99% rename from src/video/SDL_blendfillrect.c rename to src/render/software/SDL_blendfillrect.c index 24a30f5ec..228a70b56 100644 --- a/src/video/SDL_blendfillrect.c +++ b/src/render/software/SDL_blendfillrect.c @@ -21,8 +21,9 @@ */ #include "SDL_config.h" -#include "SDL_video.h" #include "SDL_draw.h" +#include "SDL_blendfillrect.h" + static int SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, diff --git a/src/video/SDL_alphamult.h b/src/render/software/SDL_blendfillrect.h similarity index 69% rename from src/video/SDL_alphamult.h rename to src/render/software/SDL_blendfillrect.h index e4796c286..81740be4f 100644 --- a/src/video/SDL_alphamult.h +++ b/src/render/software/SDL_blendfillrect.h @@ -19,20 +19,10 @@ Sam Lantinga slouken@libsdl.org */ +#include "SDL_config.h" -/* Functions to pre-multiply the alpha channel into the color channels */ -#define DEFINE_PREMULTIPLY_FUNC(fmt) \ -void \ -SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch); - -/* *INDENT-OFF* */ -DEFINE_PREMULTIPLY_FUNC(ARGB8888) -DEFINE_PREMULTIPLY_FUNC(RGBA8888) -DEFINE_PREMULTIPLY_FUNC(ABGR8888) -DEFINE_PREMULTIPLY_FUNC(BGRA8888) -/* *INDENT-ON* */ - -#undef DEFINE_PREMULTIPLY_FUNC +extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blendline.c b/src/render/software/SDL_blendline.c similarity index 99% rename from src/video/SDL_blendline.c rename to src/render/software/SDL_blendline.c index 26be908da..dce6a1a30 100644 --- a/src/video/SDL_blendline.c +++ b/src/render/software/SDL_blendline.c @@ -22,6 +22,7 @@ #include "SDL_config.h" #include "SDL_draw.h" +#include "SDL_blendline.h" static void diff --git a/src/video/SDL_alphamult.c b/src/render/software/SDL_blendline.h similarity index 51% rename from src/video/SDL_alphamult.c rename to src/render/software/SDL_blendline.h index 7b35a866a..4f3a61f6b 100644 --- a/src/video/SDL_alphamult.c +++ b/src/render/software/SDL_blendline.h @@ -21,40 +21,8 @@ */ #include "SDL_config.h" -#include "SDL_blit.h" -#include "SDL_alphamult.h" -/* Functions to pre-multiply the alpha channel into the color channels */ - -#define DEFINE_PREMULTIPLY_FUNC(fmt) \ -void \ -SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch) \ -{ \ - pitch /= 4; \ - while (h--) { \ - int n; \ - Uint32 *row = pixels; \ - Uint32 pixel; \ - unsigned r, g, b, a; \ - \ - for (n = w; n--; ) { \ - pixel = *row; \ - RGBA_FROM_##fmt(pixel, r, g, b, a); \ - r = (r * a) / 255; \ - g = (g * a) / 255; \ - b = (b * a) / 255; \ - fmt##_FROM_RGBA(*row, r, g, b, a); \ - ++row; \ - } \ - pixels += pitch; \ - } \ -} - -/* *INDENT-OFF* */ -DEFINE_PREMULTIPLY_FUNC(ARGB8888) -DEFINE_PREMULTIPLY_FUNC(RGBA8888) -DEFINE_PREMULTIPLY_FUNC(ABGR8888) -DEFINE_PREMULTIPLY_FUNC(BGRA8888) -/* *INDENT-ON* */ +extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c similarity index 99% rename from src/video/SDL_blendpoint.c rename to src/render/software/SDL_blendpoint.c index 8632c1e8a..40912ba4b 100644 --- a/src/video/SDL_blendpoint.c +++ b/src/render/software/SDL_blendpoint.c @@ -22,6 +22,8 @@ #include "SDL_config.h" #include "SDL_draw.h" +#include "SDL_blendpoint.h" + static int SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, diff --git a/src/render/software/SDL_blendpoint.h b/src/render/software/SDL_blendpoint.h new file mode 100644 index 000000000..8b27db080 --- /dev/null +++ b/src/render/software/SDL_blendpoint.h @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + + +extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_draw.h b/src/render/software/SDL_draw.h similarity index 99% rename from src/video/SDL_draw.h rename to src/render/software/SDL_draw.h index bace6e7a8..576955402 100644 --- a/src/video/SDL_draw.h +++ b/src/render/software/SDL_draw.h @@ -21,7 +21,7 @@ */ #include "SDL_config.h" -#include "SDL_blit.h" +#include "../../video/SDL_blit.h" /* This code assumes that r, g, b, a are the source color, * and in the blend and add case, the RGB values are premultiplied by a. diff --git a/src/video/SDL_drawline.c b/src/render/software/SDL_drawline.c similarity index 99% rename from src/video/SDL_drawline.c rename to src/render/software/SDL_drawline.c index bb6dbfe8a..72b86ba0d 100644 --- a/src/video/SDL_drawline.c +++ b/src/render/software/SDL_drawline.c @@ -22,6 +22,8 @@ #include "SDL_config.h" #include "SDL_draw.h" +#include "SDL_drawline.h" + static void SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color, diff --git a/src/render/software/SDL_drawline.h b/src/render/software/SDL_drawline.h new file mode 100644 index 000000000..89b4bbb27 --- /dev/null +++ b/src/render/software/SDL_drawline.h @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + + +extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); +extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c similarity index 99% rename from src/video/SDL_drawpoint.c rename to src/render/software/SDL_drawpoint.c index e6a8aad57..5f648eb86 100644 --- a/src/video/SDL_drawpoint.c +++ b/src/render/software/SDL_drawpoint.c @@ -22,6 +22,7 @@ #include "SDL_config.h" #include "SDL_draw.h" +#include "SDL_drawpoint.h" int diff --git a/src/render/software/SDL_drawpoint.h b/src/render/software/SDL_drawpoint.h new file mode 100644 index 000000000..ba4feec8e --- /dev/null +++ b/src/render/software/SDL_drawpoint.h @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + + +extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); +extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/render/software/SDL_renderer_sw.c b/src/render/software/SDL_renderer_sw.c index d82b92fb6..ffd02ee4d 100644 --- a/src/render/software/SDL_renderer_sw.c +++ b/src/render/software/SDL_renderer_sw.c @@ -24,6 +24,13 @@ #include "../SDL_sysrender.h" #include "../../video/SDL_pixels_c.h" +#include "SDL_draw.h" +#include "SDL_blendfillrect.h" +#include "SDL_blendline.h" +#include "SDL_blendpoint.h" +#include "SDL_drawline.h" +#include "SDL_drawpoint.h" + /* SDL surface based renderer implementation */ diff --git a/src/video/SDL_blendrect.c b/src/video/SDL_blendrect.c deleted file mode 100644 index 850177d47..000000000 --- a/src/video/SDL_blendrect.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_video.h" - - -int -SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - SDL_Rect full_rect; - SDL_Point points[5]; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = dst->w; - full_rect.h = dst->h; - rect = &full_rect; - } - - points[0].x = rect->x; - points[0].y = rect->y; - points[1].x = rect->x+rect->w-1; - points[1].y = rect->y; - points[2].x = rect->x+rect->w-1; - points[2].y = rect->y+rect->h-1; - points[3].x = rect->x; - points[3].y = rect->y+rect->h-1; - points[4].x = rect->x; - points[4].y = rect->y; - return SDL_BlendLines(dst, points, 5, blendMode, r, g, b, a); -} - -int -SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) -{ - int i; - - for (i = 0; i < count; ++i) { - if (SDL_BlendRect(dst, rects[i], blendMode, r, g, b, a) < 0) { - return -1; - } - } - return 0; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index c9e444014..19a74db98 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -47,7 +47,7 @@ #include "SDL_cpuinfo.h" #include "SDL_endian.h" -#include "SDL_video.h" +#include "SDL_surface.h" /* SDL blit copy flags */ #define SDL_COPY_MODULATE_COLOR 0x00000001 diff --git a/src/video/SDL_drawrect.c b/src/video/SDL_drawrect.c deleted file mode 100644 index 5685fa7aa..000000000 --- a/src/video/SDL_drawrect.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2010 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_video.h" - - -int -SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) -{ - SDL_Rect full_rect; - SDL_Point points[5]; - - if (!dst) { - SDL_SetError("Passed NULL destination surface"); - return -1; - } - - /* If 'rect' == NULL, then outline the whole surface */ - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = dst->w; - full_rect.h = dst->h; - rect = &full_rect; - } - - points[0].x = rect->x; - points[0].y = rect->y; - points[1].x = rect->x+rect->w-1; - points[1].y = rect->y; - points[2].x = rect->x+rect->w-1; - points[2].y = rect->y+rect->h-1; - points[3].x = rect->x; - points[3].y = rect->y+rect->h-1; - points[4].x = rect->x; - points[4].y = rect->y; - return SDL_DrawLines(dst, points, 5, color); -} - -int -SDL_DrawRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, - Uint32 color) -{ - int i; - - for (i = 0; i < count; ++i) { - if (SDL_DrawRect(dst, rects[i], color) < 0) { - return -1; - } - } - return 0; -} - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/test/automated/surface/surface.c b/test/automated/surface/surface.c index 24d92cddd..f8e055bac 100755 --- a/test/automated/surface/surface.c +++ b/test/automated/surface/surface.c @@ -26,8 +26,6 @@ */ /* Testcases. */ static void surface_testLoad( SDL_Surface *testsur ); -static void surface_testPrimitives( SDL_Surface *testsur ); -static void surface_testPrimitivesBlend( SDL_Surface *testsur ); static void surface_testBlit( SDL_Surface *testsur ); static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode ); static void surface_testBlitBlend( SDL_Surface *testsur ); @@ -84,167 +82,6 @@ static void surface_testLoad( SDL_Surface *testsur ) } -/** - * @brief Tests the SDL primitives for rendering. - */ -static void surface_testPrimitives( SDL_Surface *testsur ) -{ - int ret; - int x, y; - SDL_Rect rect; - - SDL_ATbegin( "Primitives Test" ); - - /* Clear surface. */ - ret = SDL_FillRect( testsur, NULL, - SDL_MapRGB( testsur->format, 0, 0, 0 ) ); - if (SDL_ATassert( "SDL_FillRect", ret == 0)) - return; - - /* Draw a rectangle. */ - rect.x = 40; - rect.y = 0; - rect.w = 40; - rect.h = 80; - ret = SDL_FillRect( testsur, &rect, - SDL_MapRGB( testsur->format, 13, 73, 200 ) ); - if (SDL_ATassert( "SDL_FillRect", ret == 0)) - return; - - /* Draw a rectangle. */ - rect.x = 10; - rect.y = 10; - rect.w = 60; - rect.h = 40; - ret = SDL_FillRect( testsur, &rect, - SDL_MapRGB( testsur->format, 200, 0, 100 ) ); - if (SDL_ATassert( "SDL_FillRect", ret == 0)) - return; - - /* Draw some points like so: - * X.X.X.X.. - * .X.X.X.X. - * X.X.X.X.. */ - for (y=0; y<3; y++) { - x = y % 2; - for (; x<80; x+=2) { - ret = SDL_DrawPoint( testsur, x, y, - SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) ); - if (SDL_ATassert( "SDL_DrawPoint", ret == 0)) - return; - } - } - - /* Draw some lines. */ - ret = SDL_DrawLine( testsur, 0, 30, 80, 30, - SDL_MapRGB( testsur->format, 0, 255, 0 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - ret = SDL_DrawLine( testsur, 40, 30, 40, 60, - SDL_MapRGB( testsur->format, 55, 55, 5 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - ret = SDL_DrawLine( testsur, 0, 0, 29, 29, - SDL_MapRGB( testsur->format, 5, 105, 105 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - ret = SDL_DrawLine( testsur, 29, 30, 0, 59, - SDL_MapRGB( testsur->format, 5, 105, 105 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - ret = SDL_DrawLine( testsur, 79, 0, 50, 29, - SDL_MapRGB( testsur->format, 5, 105, 105 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - ret = SDL_DrawLine( testsur, 79, 59, 50, 30, - SDL_MapRGB( testsur->format, 5, 105, 105 ) ); - if (SDL_ATassert( "SDL_DrawLine", ret == 0)) - return; - - /* See if it's the same. */ - if (SDL_ATassert( "Primitives output not the same.", - surface_compare( testsur, &img_primitives, 0 )==0 )) - return; - - SDL_ATend(); -} - - -/** - * @brief Tests the SDL primitives with alpha for rendering. - */ -static void surface_testPrimitivesBlend( SDL_Surface *testsur ) -{ - int ret; - int i, j; - SDL_Rect rect; - - SDL_ATbegin( "Primitives Blend Test" ); - - /* Clear surface. */ - ret = SDL_FillRect( testsur, NULL, - SDL_MapRGB( testsur->format, 0, 0, 0 ) ); - if (SDL_ATassert( "SDL_FillRect", ret == 0)) - return; - - /* Create some rectangles for each blend mode. */ - ret = SDL_BlendFillRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 ); - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0)) - return; - rect.x = 10; - rect.y = 25; - rect.w = 40; - rect.h = 25; - ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 ); - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0)) - return; - rect.x = 30; - rect.y = 40; - rect.w = 45; - rect.h = 15; - ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 ); - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0)) - return; - - /* Draw blended lines, lines for everyone. */ - for (i=0; iw; i+=2) { - ret = SDL_BlendLine( testsur, 0, 0, i, 59, - (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : - (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE, - 60+2*i, 240-2*i, 50, 3*i ); - if (SDL_ATassert( "SDL_BlendLine", ret == 0)) - return; - } - for (i=0; ih; i+=2) { - ret = SDL_BlendLine( testsur, 0, 0, 79, i, - (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : - (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE, - 60+2*i, 240-2*i, 50, 3*i ); - if (SDL_ATassert( "SDL_BlendLine", ret == 0)) - return; - } - - /* Draw points. */ - for (j=0; jh; j+=3) { - for (i=0; iw; i+=3) { - ret = SDL_BlendPoint( testsur, i, j, - ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : - ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE, - j*4, i*3, j*4, i*3 ); - if (SDL_ATassert( "SDL_BlendPoint", ret == 0)) - return; - } - } - - /* See if it's the same. */ - if (SDL_ATassert( "Primitives output not the same.", - surface_compare( testsur, &img_blend, 0 )==0 )) - return; - - SDL_ATend(); -} - - /** * @brief Tests some blitting routines. */ @@ -546,8 +383,6 @@ static void surface_testBlitBlend( SDL_Surface *testsur ) void surface_runTests( SDL_Surface *testsur ) { /* Software surface blitting. */ - surface_testPrimitives( testsur ); - surface_testPrimitivesBlend( testsur ); surface_testBlit( testsur ); surface_testBlitBlend( testsur ); }