Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Making the API simpler, moved the surface drawing functions to the so…
Browse files Browse the repository at this point in the history
…ftware renderer.
  • Loading branch information
slouken committed Feb 3, 2011
1 parent 84534c1 commit f1f81ed
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 457 deletions.
93 changes: 0 additions & 93 deletions include/SDL_surface.h
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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: */
Expand Up @@ -22,6 +22,7 @@
#include "SDL_config.h"

#include "SDL_draw.h"
#include "SDL_blendline.h"


static void
Expand Down
36 changes: 2 additions & 34 deletions src/video/SDL_alphamult.c → src/render/software/SDL_blendline.h
Expand Up @@ -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: */
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions 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: */
2 changes: 1 addition & 1 deletion src/video/SDL_draw.h → src/render/software/SDL_draw.h
Expand Up @@ -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.
Expand Down
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions 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: */
Expand Up @@ -22,6 +22,7 @@
#include "SDL_config.h"

#include "SDL_draw.h"
#include "SDL_drawpoint.h"


int
Expand Down
28 changes: 28 additions & 0 deletions 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: */
7 changes: 7 additions & 0 deletions src/render/software/SDL_renderer_sw.c
Expand Up @@ -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 */

Expand Down

0 comments on commit f1f81ed

Please sign in to comment.