Making the API simpler, moved the surface drawing functions to the software renderer.
1.1 --- a/include/SDL_surface.h Thu Feb 03 02:42:50 2011 -0800
1.2 +++ b/include/SDL_surface.h Thu Feb 03 02:45:29 2011 -0800
1.3 @@ -364,85 +364,6 @@
1.4 void * dst, int dst_pitch);
1.5
1.6 /**
1.7 - * Draws a point with \c color.
1.8 - *
1.9 - * The color should be a pixel of the format used by the surface, and
1.10 - * can be generated by the SDL_MapRGB() function.
1.11 - *
1.12 - * \return 0 on success, or -1 on error.
1.13 - */
1.14 -extern DECLSPEC int SDLCALL SDL_DrawPoint
1.15 - (SDL_Surface * dst, int x, int y, Uint32 color);
1.16 -extern DECLSPEC int SDLCALL SDL_DrawPoints
1.17 - (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
1.18 -
1.19 -/**
1.20 - * Blends a point with an RGBA value.
1.21 - *
1.22 - * \return 0 on success, or -1 on error.
1.23 - */
1.24 -extern DECLSPEC int SDLCALL SDL_BlendPoint
1.25 - (SDL_Surface * dst, int x, int y,
1.26 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.27 -extern DECLSPEC int SDLCALL SDL_BlendPoints
1.28 - (SDL_Surface * dst, const SDL_Point * points, int count,
1.29 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.30 -
1.31 -/**
1.32 - * Draws a line with \c color.
1.33 - *
1.34 - * The color should be a pixel of the format used by the surface, and
1.35 - * can be generated by the SDL_MapRGB() function.
1.36 - *
1.37 - * \return 0 on success, or -1 on error.
1.38 - */
1.39 -extern DECLSPEC int SDLCALL SDL_DrawLine
1.40 - (SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
1.41 -extern DECLSPEC int SDLCALL SDL_DrawLines
1.42 - (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
1.43 -
1.44 -/**
1.45 - * Blends an RGBA value along a line.
1.46 - *
1.47 - * \return 0 on success, or -1 on error.
1.48 - */
1.49 -extern DECLSPEC int SDLCALL SDL_BlendLine
1.50 - (SDL_Surface * dst, int x1, int y1, int x2, int y2,
1.51 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.52 -extern DECLSPEC int SDLCALL SDL_BlendLines
1.53 - (SDL_Surface * dst, const SDL_Point * points, int count,
1.54 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.55 -
1.56 -/**
1.57 - * Draws the given rectangle with \c color.
1.58 - *
1.59 - * If \c rect is NULL, the whole surface will be outlined with \c color.
1.60 - *
1.61 - * The color should be a pixel of the format used by the surface, and
1.62 - * can be generated by the SDL_MapRGB() function.
1.63 - *
1.64 - * \return 0 on success, or -1 on error.
1.65 - */
1.66 -extern DECLSPEC int SDLCALL SDL_DrawRect
1.67 - (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
1.68 -extern DECLSPEC int SDLCALL SDL_DrawRects
1.69 - (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
1.70 -
1.71 -/**
1.72 - * Blends an RGBA value into the outline of the given rectangle.
1.73 - *
1.74 - * If \c rect is NULL, the whole surface will have a blended outline.
1.75 - *
1.76 - * \return 0 on success, or -1 on error.
1.77 - */
1.78 -extern DECLSPEC int SDLCALL SDL_BlendRect
1.79 - (SDL_Surface * dst, const SDL_Rect * rect,
1.80 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.81 -extern DECLSPEC int SDLCALL SDL_BlendRects
1.82 - (SDL_Surface * dst, const SDL_Rect ** rects, int count,
1.83 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.84 -
1.85 -/**
1.86 * Performs a fast fill of the given rectangle with \c color.
1.87 *
1.88 * If \c rect is NULL, the whole surface will be filled with \c color.
1.89 @@ -458,20 +379,6 @@
1.90 (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
1.91
1.92 /**
1.93 - * Blends an RGBA value into the given rectangle.
1.94 - *
1.95 - * If \c rect is NULL, the whole surface will be blended with the color.
1.96 - *
1.97 - * \return This function returns 0 on success, or -1 on error.
1.98 - */
1.99 -extern DECLSPEC int SDLCALL SDL_BlendFillRect
1.100 - (SDL_Surface * dst, const SDL_Rect * rect,
1.101 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.102 -extern DECLSPEC int SDLCALL SDL_BlendFillRects
1.103 - (SDL_Surface * dst, const SDL_Rect ** rects, int count,
1.104 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
1.105 -
1.106 -/**
1.107 * Performs a fast blit from the source surface to the destination surface.
1.108 *
1.109 * This assumes that the source and destination rectangles are
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/render/software/SDL_blendfillrect.c Thu Feb 03 02:45:29 2011 -0800
2.3 @@ -0,0 +1,327 @@
2.4 +/*
2.5 + SDL - Simple DirectMedia Layer
2.6 + Copyright (C) 1997-2010 Sam Lantinga
2.7 +
2.8 + This library is free software; you can redistribute it and/or
2.9 + modify it under the terms of the GNU Lesser General Public
2.10 + License as published by the Free Software Foundation; either
2.11 + version 2.1 of the License, or (at your option) any later version.
2.12 +
2.13 + This library is distributed in the hope that it will be useful,
2.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2.16 + Lesser General Public License for more details.
2.17 +
2.18 + You should have received a copy of the GNU Lesser General Public
2.19 + License along with this library; if not, write to the Free Software
2.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2.21 +
2.22 + Sam Lantinga
2.23 + slouken@libsdl.org
2.24 +*/
2.25 +#include "SDL_config.h"
2.26 +
2.27 +#include "SDL_draw.h"
2.28 +#include "SDL_blendfillrect.h"
2.29 +
2.30 +
2.31 +static int
2.32 +SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
2.33 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.34 +{
2.35 + unsigned inva = 0xff - a;
2.36 +
2.37 + switch (blendMode) {
2.38 + case SDL_BLENDMODE_BLEND:
2.39 + FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
2.40 + break;
2.41 + case SDL_BLENDMODE_ADD:
2.42 + FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
2.43 + break;
2.44 + default:
2.45 + FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
2.46 + break;
2.47 + }
2.48 + return 0;
2.49 +}
2.50 +
2.51 +static int
2.52 +SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
2.53 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.54 +{
2.55 + unsigned inva = 0xff - a;
2.56 +
2.57 + switch (blendMode) {
2.58 + case SDL_BLENDMODE_BLEND:
2.59 + FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
2.60 + break;
2.61 + case SDL_BLENDMODE_ADD:
2.62 + FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
2.63 + break;
2.64 + default:
2.65 + FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
2.66 + break;
2.67 + }
2.68 + return 0;
2.69 +}
2.70 +
2.71 +static int
2.72 +SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
2.73 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.74 +{
2.75 + unsigned inva = 0xff - a;
2.76 +
2.77 + switch (blendMode) {
2.78 + case SDL_BLENDMODE_BLEND:
2.79 + FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
2.80 + break;
2.81 + case SDL_BLENDMODE_ADD:
2.82 + FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
2.83 + break;
2.84 + default:
2.85 + FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
2.86 + break;
2.87 + }
2.88 + return 0;
2.89 +}
2.90 +
2.91 +static int
2.92 +SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
2.93 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.94 +{
2.95 + unsigned inva = 0xff - a;
2.96 +
2.97 + switch (blendMode) {
2.98 + case SDL_BLENDMODE_BLEND:
2.99 + FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
2.100 + break;
2.101 + case SDL_BLENDMODE_ADD:
2.102 + FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
2.103 + break;
2.104 + default:
2.105 + FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
2.106 + break;
2.107 + }
2.108 + return 0;
2.109 +}
2.110 +
2.111 +static int
2.112 +SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
2.113 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.114 +{
2.115 + SDL_PixelFormat *fmt = dst->format;
2.116 + unsigned inva = 0xff - a;
2.117 +
2.118 + switch (fmt->BytesPerPixel) {
2.119 + case 2:
2.120 + switch (blendMode) {
2.121 + case SDL_BLENDMODE_BLEND:
2.122 + FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
2.123 + break;
2.124 + case SDL_BLENDMODE_ADD:
2.125 + FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
2.126 + break;
2.127 + default:
2.128 + FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
2.129 + break;
2.130 + }
2.131 + return 0;
2.132 + case 4:
2.133 + switch (blendMode) {
2.134 + case SDL_BLENDMODE_BLEND:
2.135 + FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
2.136 + break;
2.137 + case SDL_BLENDMODE_ADD:
2.138 + FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
2.139 + break;
2.140 + default:
2.141 + FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
2.142 + break;
2.143 + }
2.144 + return 0;
2.145 + default:
2.146 + SDL_Unsupported();
2.147 + return -1;
2.148 + }
2.149 +}
2.150 +
2.151 +static int
2.152 +SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
2.153 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.154 +{
2.155 + SDL_PixelFormat *fmt = dst->format;
2.156 + unsigned inva = 0xff - a;
2.157 +
2.158 + switch (fmt->BytesPerPixel) {
2.159 + case 4:
2.160 + switch (blendMode) {
2.161 + case SDL_BLENDMODE_BLEND:
2.162 + FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
2.163 + break;
2.164 + case SDL_BLENDMODE_ADD:
2.165 + FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
2.166 + break;
2.167 + default:
2.168 + FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
2.169 + break;
2.170 + }
2.171 + return 0;
2.172 + default:
2.173 + SDL_Unsupported();
2.174 + return -1;
2.175 + }
2.176 +}
2.177 +
2.178 +int
2.179 +SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
2.180 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.181 +{
2.182 + SDL_Rect clipped;
2.183 +
2.184 + if (!dst) {
2.185 + SDL_SetError("Passed NULL destination surface");
2.186 + return -1;
2.187 + }
2.188 +
2.189 + /* This function doesn't work on surfaces < 8 bpp */
2.190 + if (dst->format->BitsPerPixel < 8) {
2.191 + SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
2.192 + return -1;
2.193 + }
2.194 +
2.195 + /* If 'rect' == NULL, then fill the whole surface */
2.196 + if (rect) {
2.197 + /* Perform clipping */
2.198 + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
2.199 + return 0;
2.200 + }
2.201 + rect = &clipped;
2.202 + } else {
2.203 + rect = &dst->clip_rect;
2.204 + }
2.205 +
2.206 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
2.207 + r = DRAW_MUL(r, a);
2.208 + g = DRAW_MUL(g, a);
2.209 + b = DRAW_MUL(b, a);
2.210 + }
2.211 +
2.212 + switch (dst->format->BitsPerPixel) {
2.213 + case 15:
2.214 + switch (dst->format->Rmask) {
2.215 + case 0x7C00:
2.216 + return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
2.217 + }
2.218 + break;
2.219 + case 16:
2.220 + switch (dst->format->Rmask) {
2.221 + case 0xF800:
2.222 + return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
2.223 + }
2.224 + break;
2.225 + case 32:
2.226 + switch (dst->format->Rmask) {
2.227 + case 0x00FF0000:
2.228 + if (!dst->format->Amask) {
2.229 + return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
2.230 + } else {
2.231 + return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
2.232 + }
2.233 + break;
2.234 + }
2.235 + break;
2.236 + default:
2.237 + break;
2.238 + }
2.239 +
2.240 + if (!dst->format->Amask) {
2.241 + return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
2.242 + } else {
2.243 + return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
2.244 + }
2.245 +}
2.246 +
2.247 +int
2.248 +SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
2.249 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
2.250 +{
2.251 + SDL_Rect clipped;
2.252 + int i;
2.253 + int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
2.254 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
2.255 + int status = 0;
2.256 +
2.257 + if (!dst) {
2.258 + SDL_SetError("Passed NULL destination surface");
2.259 + return -1;
2.260 + }
2.261 +
2.262 + /* This function doesn't work on surfaces < 8 bpp */
2.263 + if (dst->format->BitsPerPixel < 8) {
2.264 + SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
2.265 + return -1;
2.266 + }
2.267 +
2.268 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
2.269 + r = DRAW_MUL(r, a);
2.270 + g = DRAW_MUL(g, a);
2.271 + b = DRAW_MUL(b, a);
2.272 + }
2.273 +
2.274 + /* FIXME: Does this function pointer slow things down significantly? */
2.275 + switch (dst->format->BitsPerPixel) {
2.276 + case 15:
2.277 + switch (dst->format->Rmask) {
2.278 + case 0x7C00:
2.279 + func = SDL_BlendFillRect_RGB555;
2.280 + }
2.281 + break;
2.282 + case 16:
2.283 + switch (dst->format->Rmask) {
2.284 + case 0xF800:
2.285 + func = SDL_BlendFillRect_RGB565;
2.286 + }
2.287 + break;
2.288 + case 32:
2.289 + switch (dst->format->Rmask) {
2.290 + case 0x00FF0000:
2.291 + if (!dst->format->Amask) {
2.292 + func = SDL_BlendFillRect_RGB888;
2.293 + } else {
2.294 + func = SDL_BlendFillRect_ARGB8888;
2.295 + }
2.296 + break;
2.297 + }
2.298 + break;
2.299 + default:
2.300 + break;
2.301 + }
2.302 +
2.303 + if (!func) {
2.304 + if (!dst->format->Amask) {
2.305 + func = SDL_BlendFillRect_RGB;
2.306 + } else {
2.307 + func = SDL_BlendFillRect_RGBA;
2.308 + }
2.309 + }
2.310 +
2.311 + for (i = 0; i < count; ++i) {
2.312 + const SDL_Rect * rect = rects[i];
2.313 +
2.314 + /* If 'rect' == NULL, then fill the whole surface */
2.315 + if (rect) {
2.316 + /* Perform clipping */
2.317 + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
2.318 + continue;
2.319 + }
2.320 + rect = &clipped;
2.321 + } else {
2.322 + rect = &dst->clip_rect;
2.323 + }
2.324 +
2.325 + status = func(dst, rect, blendMode, r, g, b, a);
2.326 + }
2.327 + return status;
2.328 +}
2.329 +
2.330 +/* vi: set ts=4 sw=4 expandtab: */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/render/software/SDL_blendfillrect.h Thu Feb 03 02:45:29 2011 -0800
3.3 @@ -0,0 +1,28 @@
3.4 +/*
3.5 + SDL - Simple DirectMedia Layer
3.6 + Copyright (C) 1997-2010 Sam Lantinga
3.7 +
3.8 + This library is free software; you can redistribute it and/or
3.9 + modify it under the terms of the GNU Lesser General Public
3.10 + License as published by the Free Software Foundation; either
3.11 + version 2.1 of the License, or (at your option) any later version.
3.12 +
3.13 + This library is distributed in the hope that it will be useful,
3.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3.16 + Lesser General Public License for more details.
3.17 +
3.18 + You should have received a copy of the GNU Lesser General Public
3.19 + License along with this library; if not, write to the Free Software
3.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3.21 +
3.22 + Sam Lantinga
3.23 + slouken@libsdl.org
3.24 +*/
3.25 +#include "SDL_config.h"
3.26 +
3.27 +
3.28 +extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
3.29 +extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
3.30 +
3.31 +/* vi: set ts=4 sw=4 expandtab: */
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/render/software/SDL_blendline.c Thu Feb 03 02:45:29 2011 -0800
4.3 @@ -0,0 +1,683 @@
4.4 +/*
4.5 + SDL - Simple DirectMedia Layer
4.6 + Copyright (C) 1997-2010 Sam Lantinga
4.7 +
4.8 + This library is free software; you can redistribute it and/or
4.9 + modify it under the terms of the GNU Lesser General Public
4.10 + License as published by the Free Software Foundation; either
4.11 + version 2.1 of the License, or (at your option) any later version.
4.12 +
4.13 + This library is distributed in the hope that it will be useful,
4.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4.16 + Lesser General Public License for more details.
4.17 +
4.18 + You should have received a copy of the GNU Lesser General Public
4.19 + License along with this library; if not, write to the Free Software
4.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4.21 +
4.22 + Sam Lantinga
4.23 + slouken@libsdl.org
4.24 +*/
4.25 +#include "SDL_config.h"
4.26 +
4.27 +#include "SDL_draw.h"
4.28 +#include "SDL_blendline.h"
4.29 +
4.30 +
4.31 +static void
4.32 +SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.33 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.34 + SDL_bool draw_end)
4.35 +{
4.36 + const SDL_PixelFormat *fmt = dst->format;
4.37 + unsigned r, g, b, a, inva;
4.38 +
4.39 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.40 + r = DRAW_MUL(_r, _a);
4.41 + g = DRAW_MUL(_g, _a);
4.42 + b = DRAW_MUL(_b, _a);
4.43 + a = _a;
4.44 + } else {
4.45 + r = _r;
4.46 + g = _g;
4.47 + b = _b;
4.48 + a = _a;
4.49 + }
4.50 + inva = (a ^ 0xff);
4.51 +
4.52 + if (y1 == y2) {
4.53 + switch (blendMode) {
4.54 + case SDL_BLENDMODE_BLEND:
4.55 + HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.56 + break;
4.57 + case SDL_BLENDMODE_ADD:
4.58 + HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.59 + break;
4.60 + default:
4.61 + HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
4.62 + break;
4.63 + }
4.64 + } else if (x1 == x2) {
4.65 + switch (blendMode) {
4.66 + case SDL_BLENDMODE_BLEND:
4.67 + VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.68 + break;
4.69 + case SDL_BLENDMODE_ADD:
4.70 + VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.71 + break;
4.72 + default:
4.73 + VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
4.74 + break;
4.75 + }
4.76 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.77 + switch (blendMode) {
4.78 + case SDL_BLENDMODE_BLEND:
4.79 + DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.80 + break;
4.81 + case SDL_BLENDMODE_ADD:
4.82 + DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.83 + break;
4.84 + default:
4.85 + DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
4.86 + break;
4.87 + }
4.88 + } else {
4.89 + switch (blendMode) {
4.90 + case SDL_BLENDMODE_BLEND:
4.91 + AALINE(x1, y1, x2, y2,
4.92 + DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
4.93 + draw_end);
4.94 + break;
4.95 + case SDL_BLENDMODE_ADD:
4.96 + AALINE(x1, y1, x2, y2,
4.97 + DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
4.98 + draw_end);
4.99 + break;
4.100 + default:
4.101 + AALINE(x1, y1, x2, y2,
4.102 + DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
4.103 + draw_end);
4.104 + break;
4.105 + }
4.106 + }
4.107 +}
4.108 +
4.109 +static void
4.110 +SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.111 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.112 + SDL_bool draw_end)
4.113 +{
4.114 + const SDL_PixelFormat *fmt = dst->format;
4.115 + unsigned r, g, b, a, inva;
4.116 +
4.117 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.118 + r = DRAW_MUL(_r, _a);
4.119 + g = DRAW_MUL(_g, _a);
4.120 + b = DRAW_MUL(_b, _a);
4.121 + a = _a;
4.122 + } else {
4.123 + r = _r;
4.124 + g = _g;
4.125 + b = _b;
4.126 + a = _a;
4.127 + }
4.128 + inva = (a ^ 0xff);
4.129 +
4.130 + if (y1 == y2) {
4.131 + switch (blendMode) {
4.132 + case SDL_BLENDMODE_BLEND:
4.133 + HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
4.134 + break;
4.135 + case SDL_BLENDMODE_ADD:
4.136 + HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
4.137 + break;
4.138 + default:
4.139 + HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
4.140 + break;
4.141 + }
4.142 + } else if (x1 == x2) {
4.143 + switch (blendMode) {
4.144 + case SDL_BLENDMODE_BLEND:
4.145 + VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
4.146 + break;
4.147 + case SDL_BLENDMODE_ADD:
4.148 + VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
4.149 + break;
4.150 + default:
4.151 + VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
4.152 + break;
4.153 + }
4.154 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.155 + switch (blendMode) {
4.156 + case SDL_BLENDMODE_BLEND:
4.157 + DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
4.158 + break;
4.159 + case SDL_BLENDMODE_ADD:
4.160 + DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
4.161 + break;
4.162 + default:
4.163 + DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
4.164 + break;
4.165 + }
4.166 + } else {
4.167 + switch (blendMode) {
4.168 + case SDL_BLENDMODE_BLEND:
4.169 + AALINE(x1, y1, x2, y2,
4.170 + DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
4.171 + draw_end);
4.172 + break;
4.173 + case SDL_BLENDMODE_ADD:
4.174 + AALINE(x1, y1, x2, y2,
4.175 + DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
4.176 + draw_end);
4.177 + break;
4.178 + default:
4.179 + AALINE(x1, y1, x2, y2,
4.180 + DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
4.181 + draw_end);
4.182 + break;
4.183 + }
4.184 + }
4.185 +}
4.186 +
4.187 +static void
4.188 +SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.189 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.190 + SDL_bool draw_end)
4.191 +{
4.192 + const SDL_PixelFormat *fmt = dst->format;
4.193 + unsigned r, g, b, a, inva;
4.194 +
4.195 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.196 + r = DRAW_MUL(_r, _a);
4.197 + g = DRAW_MUL(_g, _a);
4.198 + b = DRAW_MUL(_b, _a);
4.199 + a = _a;
4.200 + } else {
4.201 + r = _r;
4.202 + g = _g;
4.203 + b = _b;
4.204 + a = _a;
4.205 + }
4.206 + inva = (a ^ 0xff);
4.207 +
4.208 + if (y1 == y2) {
4.209 + switch (blendMode) {
4.210 + case SDL_BLENDMODE_BLEND:
4.211 + HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
4.212 + break;
4.213 + case SDL_BLENDMODE_ADD:
4.214 + HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
4.215 + break;
4.216 + default:
4.217 + HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
4.218 + break;
4.219 + }
4.220 + } else if (x1 == x2) {
4.221 + switch (blendMode) {
4.222 + case SDL_BLENDMODE_BLEND:
4.223 + VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
4.224 + break;
4.225 + case SDL_BLENDMODE_ADD:
4.226 + VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
4.227 + break;
4.228 + default:
4.229 + VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
4.230 + break;
4.231 + }
4.232 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.233 + switch (blendMode) {
4.234 + case SDL_BLENDMODE_BLEND:
4.235 + DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
4.236 + break;
4.237 + case SDL_BLENDMODE_ADD:
4.238 + DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
4.239 + break;
4.240 + default:
4.241 + DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
4.242 + break;
4.243 + }
4.244 + } else {
4.245 + switch (blendMode) {
4.246 + case SDL_BLENDMODE_BLEND:
4.247 + AALINE(x1, y1, x2, y2,
4.248 + DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
4.249 + draw_end);
4.250 + break;
4.251 + case SDL_BLENDMODE_ADD:
4.252 + AALINE(x1, y1, x2, y2,
4.253 + DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
4.254 + draw_end);
4.255 + break;
4.256 + default:
4.257 + AALINE(x1, y1, x2, y2,
4.258 + DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
4.259 + draw_end);
4.260 + break;
4.261 + }
4.262 + }
4.263 +}
4.264 +
4.265 +static void
4.266 +SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.267 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.268 + SDL_bool draw_end)
4.269 +{
4.270 + const SDL_PixelFormat *fmt = dst->format;
4.271 + unsigned r, g, b, a, inva;
4.272 +
4.273 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.274 + r = DRAW_MUL(_r, _a);
4.275 + g = DRAW_MUL(_g, _a);
4.276 + b = DRAW_MUL(_b, _a);
4.277 + a = _a;
4.278 + } else {
4.279 + r = _r;
4.280 + g = _g;
4.281 + b = _b;
4.282 + a = _a;
4.283 + }
4.284 + inva = (a ^ 0xff);
4.285 +
4.286 + if (y1 == y2) {
4.287 + switch (blendMode) {
4.288 + case SDL_BLENDMODE_BLEND:
4.289 + HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.290 + break;
4.291 + case SDL_BLENDMODE_ADD:
4.292 + HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.293 + break;
4.294 + default:
4.295 + HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
4.296 + break;
4.297 + }
4.298 + } else if (x1 == x2) {
4.299 + switch (blendMode) {
4.300 + case SDL_BLENDMODE_BLEND:
4.301 + VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.302 + break;
4.303 + case SDL_BLENDMODE_ADD:
4.304 + VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.305 + break;
4.306 + default:
4.307 + VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
4.308 + break;
4.309 + }
4.310 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.311 + switch (blendMode) {
4.312 + case SDL_BLENDMODE_BLEND:
4.313 + DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
4.314 + break;
4.315 + case SDL_BLENDMODE_ADD:
4.316 + DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
4.317 + break;
4.318 + default:
4.319 + DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
4.320 + break;
4.321 + }
4.322 + } else {
4.323 + switch (blendMode) {
4.324 + case SDL_BLENDMODE_BLEND:
4.325 + AALINE(x1, y1, x2, y2,
4.326 + DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
4.327 + draw_end);
4.328 + break;
4.329 + case SDL_BLENDMODE_ADD:
4.330 + AALINE(x1, y1, x2, y2,
4.331 + DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
4.332 + draw_end);
4.333 + break;
4.334 + default:
4.335 + AALINE(x1, y1, x2, y2,
4.336 + DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
4.337 + draw_end);
4.338 + break;
4.339 + }
4.340 + }
4.341 +}
4.342 +
4.343 +static void
4.344 +SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.345 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.346 + SDL_bool draw_end)
4.347 +{
4.348 + const SDL_PixelFormat *fmt = dst->format;
4.349 + unsigned r, g, b, a, inva;
4.350 +
4.351 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.352 + r = DRAW_MUL(_r, _a);
4.353 + g = DRAW_MUL(_g, _a);
4.354 + b = DRAW_MUL(_b, _a);
4.355 + a = _a;
4.356 + } else {
4.357 + r = _r;
4.358 + g = _g;
4.359 + b = _b;
4.360 + a = _a;
4.361 + }
4.362 + inva = (a ^ 0xff);
4.363 +
4.364 + if (y1 == y2) {
4.365 + switch (blendMode) {
4.366 + case SDL_BLENDMODE_BLEND:
4.367 + HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
4.368 + break;
4.369 + case SDL_BLENDMODE_ADD:
4.370 + HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
4.371 + break;
4.372 + default:
4.373 + HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
4.374 + break;
4.375 + }
4.376 + } else if (x1 == x2) {
4.377 + switch (blendMode) {
4.378 + case SDL_BLENDMODE_BLEND:
4.379 + VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
4.380 + break;
4.381 + case SDL_BLENDMODE_ADD:
4.382 + VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
4.383 + break;
4.384 + default:
4.385 + VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
4.386 + break;
4.387 + }
4.388 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.389 + switch (blendMode) {
4.390 + case SDL_BLENDMODE_BLEND:
4.391 + DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
4.392 + break;
4.393 + case SDL_BLENDMODE_ADD:
4.394 + DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
4.395 + break;
4.396 + default:
4.397 + DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
4.398 + break;
4.399 + }
4.400 + } else {
4.401 + switch (blendMode) {
4.402 + case SDL_BLENDMODE_BLEND:
4.403 + AALINE(x1, y1, x2, y2,
4.404 + DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
4.405 + draw_end);
4.406 + break;
4.407 + case SDL_BLENDMODE_ADD:
4.408 + AALINE(x1, y1, x2, y2,
4.409 + DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
4.410 + draw_end);
4.411 + break;
4.412 + default:
4.413 + AALINE(x1, y1, x2, y2,
4.414 + DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
4.415 + draw_end);
4.416 + break;
4.417 + }
4.418 + }
4.419 +}
4.420 +
4.421 +static void
4.422 +SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.423 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.424 + SDL_bool draw_end)
4.425 +{
4.426 + const SDL_PixelFormat *fmt = dst->format;
4.427 + unsigned r, g, b, a, inva;
4.428 +
4.429 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.430 + r = DRAW_MUL(_r, _a);
4.431 + g = DRAW_MUL(_g, _a);
4.432 + b = DRAW_MUL(_b, _a);
4.433 + a = _a;
4.434 + } else {
4.435 + r = _r;
4.436 + g = _g;
4.437 + b = _b;
4.438 + a = _a;
4.439 + }
4.440 + inva = (a ^ 0xff);
4.441 +
4.442 + if (y1 == y2) {
4.443 + switch (blendMode) {
4.444 + case SDL_BLENDMODE_BLEND:
4.445 + HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
4.446 + break;
4.447 + case SDL_BLENDMODE_ADD:
4.448 + HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
4.449 + break;
4.450 + default:
4.451 + HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
4.452 + break;
4.453 + }
4.454 + } else if (x1 == x2) {
4.455 + switch (blendMode) {
4.456 + case SDL_BLENDMODE_BLEND:
4.457 + VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
4.458 + break;
4.459 + case SDL_BLENDMODE_ADD:
4.460 + VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
4.461 + break;
4.462 + default:
4.463 + VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
4.464 + break;
4.465 + }
4.466 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.467 + switch (blendMode) {
4.468 + case SDL_BLENDMODE_BLEND:
4.469 + DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
4.470 + break;
4.471 + case SDL_BLENDMODE_ADD:
4.472 + DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
4.473 + break;
4.474 + default:
4.475 + DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
4.476 + break;
4.477 + }
4.478 + } else {
4.479 + switch (blendMode) {
4.480 + case SDL_BLENDMODE_BLEND:
4.481 + AALINE(x1, y1, x2, y2,
4.482 + DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
4.483 + draw_end);
4.484 + break;
4.485 + case SDL_BLENDMODE_ADD:
4.486 + AALINE(x1, y1, x2, y2,
4.487 + DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
4.488 + draw_end);
4.489 + break;
4.490 + default:
4.491 + AALINE(x1, y1, x2, y2,
4.492 + DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
4.493 + draw_end);
4.494 + break;
4.495 + }
4.496 + }
4.497 +}
4.498 +
4.499 +static void
4.500 +SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.501 + SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
4.502 + SDL_bool draw_end)
4.503 +{
4.504 + const SDL_PixelFormat *fmt = dst->format;
4.505 + unsigned r, g, b, a, inva;
4.506 +
4.507 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
4.508 + r = DRAW_MUL(_r, _a);
4.509 + g = DRAW_MUL(_g, _a);
4.510 + b = DRAW_MUL(_b, _a);
4.511 + a = _a;
4.512 + } else {
4.513 + r = _r;
4.514 + g = _g;
4.515 + b = _b;
4.516 + a = _a;
4.517 + }
4.518 + inva = (a ^ 0xff);
4.519 +
4.520 + if (y1 == y2) {
4.521 + switch (blendMode) {
4.522 + case SDL_BLENDMODE_BLEND:
4.523 + HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
4.524 + break;
4.525 + case SDL_BLENDMODE_ADD:
4.526 + HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
4.527 + break;
4.528 + default:
4.529 + HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
4.530 + break;
4.531 + }
4.532 + } else if (x1 == x2) {
4.533 + switch (blendMode) {
4.534 + case SDL_BLENDMODE_BLEND:
4.535 + VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
4.536 + break;
4.537 + case SDL_BLENDMODE_ADD:
4.538 + VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
4.539 + break;
4.540 + default:
4.541 + VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
4.542 + break;
4.543 + }
4.544 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
4.545 + switch (blendMode) {
4.546 + case SDL_BLENDMODE_BLEND:
4.547 + DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
4.548 + break;
4.549 + case SDL_BLENDMODE_ADD:
4.550 + DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
4.551 + break;
4.552 + default:
4.553 + DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
4.554 + break;
4.555 + }
4.556 + } else {
4.557 + switch (blendMode) {
4.558 + case SDL_BLENDMODE_BLEND:
4.559 + AALINE(x1, y1, x2, y2,
4.560 + DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
4.561 + draw_end);
4.562 + break;
4.563 + case SDL_BLENDMODE_ADD:
4.564 + AALINE(x1, y1, x2, y2,
4.565 + DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
4.566 + draw_end);
4.567 + break;
4.568 + default:
4.569 + AALINE(x1, y1, x2, y2,
4.570 + DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
4.571 + draw_end);
4.572 + break;
4.573 + }
4.574 + }
4.575 +}
4.576 +
4.577 +typedef void (*BlendLineFunc) (SDL_Surface * dst,
4.578 + int x1, int y1, int x2, int y2,
4.579 + SDL_BlendMode blendMode,
4.580 + Uint8 r, Uint8 g, Uint8 b, Uint8 a,
4.581 + SDL_bool draw_end);
4.582 +
4.583 +static BlendLineFunc
4.584 +SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
4.585 +{
4.586 + switch (fmt->BytesPerPixel) {
4.587 + case 2:
4.588 + if (fmt->Rmask == 0x7C00) {
4.589 + return SDL_BlendLine_RGB555;
4.590 + } else if (fmt->Rmask == 0xF800) {
4.591 + return SDL_BlendLine_RGB565;
4.592 + } else {
4.593 + return SDL_BlendLine_RGB2;
4.594 + }
4.595 + break;
4.596 + case 4:
4.597 + if (fmt->Rmask == 0x00FF0000) {
4.598 + if (fmt->Amask) {
4.599 + return SDL_BlendLine_ARGB8888;
4.600 + } else {
4.601 + return SDL_BlendLine_RGB888;
4.602 + }
4.603 + } else {
4.604 + if (fmt->Amask) {
4.605 + return SDL_BlendLine_RGBA4;
4.606 + } else {
4.607 + return SDL_BlendLine_RGB4;
4.608 + }
4.609 + }
4.610 + }
4.611 + return NULL;
4.612 +}
4.613 +
4.614 +int
4.615 +SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
4.616 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
4.617 +{
4.618 + BlendLineFunc func;
4.619 +
4.620 + if (!dst) {
4.621 + SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
4.622 + return -1;
4.623 + }
4.624 +
4.625 + func = SDL_CalculateBlendLineFunc(dst->format);
4.626 + if (!func) {
4.627 + SDL_SetError("SDL_BlendLine(): Unsupported surface format");
4.628 + return -1;
4.629 + }
4.630 +
4.631 + /* Perform clipping */
4.632 + /* FIXME: We don't actually want to clip, as it may change line slope */
4.633 + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
4.634 + return 0;
4.635 + }
4.636 +
4.637 + func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
4.638 + return 0;
4.639 +}
4.640 +
4.641 +int
4.642 +SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
4.643 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
4.644 +{
4.645 + int i;
4.646 + int x1, y1;
4.647 + int x2, y2;
4.648 + SDL_bool draw_end;
4.649 + BlendLineFunc func;
4.650 +
4.651 + if (!dst) {
4.652 + SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
4.653 + return -1;
4.654 + }
4.655 +
4.656 + func = SDL_CalculateBlendLineFunc(dst->format);
4.657 + if (!func) {
4.658 + SDL_SetError("SDL_BlendLines(): Unsupported surface format");
4.659 + return -1;
4.660 + }
4.661 +
4.662 + for (i = 1; i < count; ++i) {
4.663 + x1 = points[i-1].x;
4.664 + y1 = points[i-1].y;
4.665 + x2 = points[i].x;
4.666 + y2 = points[i].y;
4.667 +
4.668 + /* Perform clipping */
4.669 + /* FIXME: We don't actually want to clip, as it may change line slope */
4.670 + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
4.671 + continue;
4.672 + }
4.673 +
4.674 + /* Draw the end if it was clipped */
4.675 + draw_end = (x2 != points[i].x || y2 != points[i].y);
4.676 +
4.677 + func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
4.678 + }
4.679 + if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
4.680 + SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
4.681 + blendMode, r, g, b, a);
4.682 + }
4.683 + return 0;
4.684 +}
4.685 +
4.686 +/* vi: set ts=4 sw=4 expandtab: */
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/src/render/software/SDL_blendline.h Thu Feb 03 02:45:29 2011 -0800
5.3 @@ -0,0 +1,28 @@
5.4 +/*
5.5 + SDL - Simple DirectMedia Layer
5.6 + Copyright (C) 1997-2010 Sam Lantinga
5.7 +
5.8 + This library is free software; you can redistribute it and/or
5.9 + modify it under the terms of the GNU Lesser General Public
5.10 + License as published by the Free Software Foundation; either
5.11 + version 2.1 of the License, or (at your option) any later version.
5.12 +
5.13 + This library is distributed in the hope that it will be useful,
5.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
5.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5.16 + Lesser General Public License for more details.
5.17 +
5.18 + You should have received a copy of the GNU Lesser General Public
5.19 + License along with this library; if not, write to the Free Software
5.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5.21 +
5.22 + Sam Lantinga
5.23 + slouken@libsdl.org
5.24 +*/
5.25 +#include "SDL_config.h"
5.26 +
5.27 +
5.28 +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);
5.29 +extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
5.30 +
5.31 +/* vi: set ts=4 sw=4 expandtab: */
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/src/render/software/SDL_blendpoint.c Thu Feb 03 02:45:29 2011 -0800
6.3 @@ -0,0 +1,325 @@
6.4 +/*
6.5 + SDL - Simple DirectMedia Layer
6.6 + Copyright (C) 1997-2010 Sam Lantinga
6.7 +
6.8 + This library is free software; you can redistribute it and/or
6.9 + modify it under the terms of the GNU Lesser General Public
6.10 + License as published by the Free Software Foundation; either
6.11 + version 2.1 of the License, or (at your option) any later version.
6.12 +
6.13 + This library is distributed in the hope that it will be useful,
6.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
6.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6.16 + Lesser General Public License for more details.
6.17 +
6.18 + You should have received a copy of the GNU Lesser General Public
6.19 + License along with this library; if not, write to the Free Software
6.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6.21 +
6.22 + Sam Lantinga
6.23 + slouken@libsdl.org
6.24 +*/
6.25 +#include "SDL_config.h"
6.26 +
6.27 +#include "SDL_draw.h"
6.28 +#include "SDL_blendpoint.h"
6.29 +
6.30 +
6.31 +static int
6.32 +SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.33 + Uint8 g, Uint8 b, Uint8 a)
6.34 +{
6.35 + unsigned inva = 0xff - a;
6.36 +
6.37 + switch (blendMode) {
6.38 + case SDL_BLENDMODE_BLEND:
6.39 + DRAW_SETPIXELXY_BLEND_RGB555(x, y);
6.40 + break;
6.41 + case SDL_BLENDMODE_ADD:
6.42 + DRAW_SETPIXELXY_ADD_RGB555(x, y);
6.43 + break;
6.44 + default:
6.45 + DRAW_SETPIXELXY_RGB555(x, y);
6.46 + break;
6.47 + }
6.48 + return 0;
6.49 +}
6.50 +
6.51 +static int
6.52 +SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.53 + Uint8 g, Uint8 b, Uint8 a)
6.54 +{
6.55 + unsigned inva = 0xff - a;
6.56 +
6.57 + switch (blendMode) {
6.58 + case SDL_BLENDMODE_BLEND:
6.59 + DRAW_SETPIXELXY_BLEND_RGB565(x, y);
6.60 + break;
6.61 + case SDL_BLENDMODE_ADD:
6.62 + DRAW_SETPIXELXY_ADD_RGB565(x, y);
6.63 + break;
6.64 + default:
6.65 + DRAW_SETPIXELXY_RGB565(x, y);
6.66 + break;
6.67 + }
6.68 + return 0;
6.69 +}
6.70 +
6.71 +static int
6.72 +SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.73 + Uint8 g, Uint8 b, Uint8 a)
6.74 +{
6.75 + unsigned inva = 0xff - a;
6.76 +
6.77 + switch (blendMode) {
6.78 + case SDL_BLENDMODE_BLEND:
6.79 + DRAW_SETPIXELXY_BLEND_RGB888(x, y);
6.80 + break;
6.81 + case SDL_BLENDMODE_ADD:
6.82 + DRAW_SETPIXELXY_ADD_RGB888(x, y);
6.83 + break;
6.84 + default:
6.85 + DRAW_SETPIXELXY_RGB888(x, y);
6.86 + break;
6.87 + }
6.88 + return 0;
6.89 +}
6.90 +
6.91 +static int
6.92 +SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
6.93 + Uint8 r, Uint8 g, Uint8 b, Uint8 a)
6.94 +{
6.95 + unsigned inva = 0xff - a;
6.96 +
6.97 + switch (blendMode) {
6.98 + case SDL_BLENDMODE_BLEND:
6.99 + DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
6.100 + break;
6.101 + case SDL_BLENDMODE_ADD:
6.102 + DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
6.103 + break;
6.104 + default:
6.105 + DRAW_SETPIXELXY_ARGB8888(x, y);
6.106 + break;
6.107 + }
6.108 + return 0;
6.109 +}
6.110 +
6.111 +static int
6.112 +SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.113 + Uint8 g, Uint8 b, Uint8 a)
6.114 +{
6.115 + SDL_PixelFormat *fmt = dst->format;
6.116 + unsigned inva = 0xff - a;
6.117 +
6.118 + switch (fmt->BytesPerPixel) {
6.119 + case 2:
6.120 + switch (blendMode) {
6.121 + case SDL_BLENDMODE_BLEND:
6.122 + DRAW_SETPIXELXY2_BLEND_RGB(x, y);
6.123 + break;
6.124 + case SDL_BLENDMODE_ADD:
6.125 + DRAW_SETPIXELXY2_ADD_RGB(x, y);
6.126 + break;
6.127 + default:
6.128 + DRAW_SETPIXELXY2_RGB(x, y);
6.129 + break;
6.130 + }
6.131 + return 0;
6.132 + case 4:
6.133 + switch (blendMode) {
6.134 + case SDL_BLENDMODE_BLEND:
6.135 + DRAW_SETPIXELXY4_BLEND_RGB(x, y);
6.136 + break;
6.137 + case SDL_BLENDMODE_ADD:
6.138 + DRAW_SETPIXELXY4_ADD_RGB(x, y);
6.139 + break;
6.140 + default:
6.141 + DRAW_SETPIXELXY4_RGB(x, y);
6.142 + break;
6.143 + }
6.144 + return 0;
6.145 + default:
6.146 + SDL_Unsupported();
6.147 + return -1;
6.148 + }
6.149 +}
6.150 +
6.151 +static int
6.152 +SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.153 + Uint8 g, Uint8 b, Uint8 a)
6.154 +{
6.155 + SDL_PixelFormat *fmt = dst->format;
6.156 + unsigned inva = 0xff - a;
6.157 +
6.158 + switch (fmt->BytesPerPixel) {
6.159 + case 4:
6.160 + switch (blendMode) {
6.161 + case SDL_BLENDMODE_BLEND:
6.162 + DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
6.163 + break;
6.164 + case SDL_BLENDMODE_ADD:
6.165 + DRAW_SETPIXELXY4_ADD_RGBA(x, y);
6.166 + break;
6.167 + default:
6.168 + DRAW_SETPIXELXY4_RGBA(x, y);
6.169 + break;
6.170 + }
6.171 + return 0;
6.172 + default:
6.173 + SDL_Unsupported();
6.174 + return -1;
6.175 + }
6.176 +}
6.177 +
6.178 +int
6.179 +SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
6.180 + Uint8 g, Uint8 b, Uint8 a)
6.181 +{
6.182 + if (!dst) {
6.183 + SDL_SetError("Passed NULL destination surface");
6.184 + return -1;
6.185 + }
6.186 +
6.187 + /* This function doesn't work on surfaces < 8 bpp */
6.188 + if (dst->format->BitsPerPixel < 8) {
6.189 + SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
6.190 + return -1;
6.191 + }
6.192 +
6.193 + /* Perform clipping */
6.194 + if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
6.195 + x >= (dst->clip_rect.x + dst->clip_rect.w) ||
6.196 + y >= (dst->clip_rect.y + dst->clip_rect.h)) {
6.197 + return 0;
6.198 + }
6.199 +
6.200 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
6.201 + r = DRAW_MUL(r, a);
6.202 + g = DRAW_MUL(g, a);
6.203 + b = DRAW_MUL(b, a);
6.204 + }
6.205 +
6.206 + switch (dst->format->BitsPerPixel) {
6.207 + case 15:
6.208 + switch (dst->format->Rmask) {
6.209 + case 0x7C00:
6.210 + return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
6.211 + }
6.212 + break;
6.213 + case 16:
6.214 + switch (dst->format->Rmask) {
6.215 + case 0xF800:
6.216 + return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
6.217 + }
6.218 + break;
6.219 + case 32:
6.220 + switch (dst->format->Rmask) {
6.221 + case 0x00FF0000:
6.222 + if (!dst->format->Amask) {
6.223 + return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b,
6.224 + a);
6.225 + } else {
6.226 + return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b,
6.227 + a);
6.228 + }
6.229 + break;
6.230 + }
6.231 + break;
6.232 + default:
6.233 + break;
6.234 + }
6.235 +
6.236 + if (!dst->format->Amask) {
6.237 + return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
6.238 + } else {
6.239 + return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
6.240 + }
6.241 +}
6.242 +
6.243 +int
6.244 +SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
6.245 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
6.246 +{
6.247 + int minx, miny;
6.248 + int maxx, maxy;
6.249 + int i;
6.250 + int x, y;
6.251 + int (*func)(SDL_Surface * dst, int x, int y,
6.252 + SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
6.253 + int status = 0;
6.254 +
6.255 + if (!dst) {
6.256 + SDL_SetError("Passed NULL destination surface");
6.257 + return -1;
6.258 + }
6.259 +
6.260 + /* This function doesn't work on surfaces < 8 bpp */
6.261 + if (dst->format->BitsPerPixel < 8) {
6.262 + SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
6.263 + return (-1);
6.264 + }
6.265 +
6.266 + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
6.267 + r = DRAW_MUL(r, a);
6.268 + g = DRAW_MUL(g, a);
6.269 + b = DRAW_MUL(b, a);
6.270 + }
6.271 +
6.272 + /* FIXME: Does this function pointer slow things down significantly? */
6.273 + switch (dst->format->BitsPerPixel) {
6.274 + case 15:
6.275 + switch (dst->format->Rmask) {
6.276 + case 0x7C00:
6.277 + func = SDL_BlendPoint_RGB555;
6.278 + break;
6.279 + }
6.280 + break;
6.281 + case 16:
6.282 + switch (dst->format->Rmask) {
6.283 + case 0xF800:
6.284 + func = SDL_BlendPoint_RGB565;
6.285 + break;
6.286 + }
6.287 + break;
6.288 + case 32:
6.289 + switch (dst->format->Rmask) {
6.290 + case 0x00FF0000:
6.291 + if (!dst->format->Amask) {
6.292 + func = SDL_BlendPoint_RGB888;
6.293 + } else {
6.294 + func = SDL_BlendPoint_ARGB8888;
6.295 + }
6.296 + break;
6.297 + }
6.298 + break;
6.299 + default:
6.300 + break;
6.301 + }
6.302 +
6.303 + if (!func) {
6.304 + if (!dst->format->Amask) {
6.305 + func = SDL_BlendPoint_RGB;
6.306 + } else {
6.307 + func = SDL_BlendPoint_RGBA;
6.308 + }
6.309 + }
6.310 +
6.311 + minx = dst->clip_rect.x;
6.312 + maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
6.313 + miny = dst->clip_rect.y;
6.314 + maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
6.315 +
6.316 + for (i = 0; i < count; ++i) {
6.317 + x = points[i].x;
6.318 + y = points[i].y;
6.319 +
6.320 + if (x < minx || x > maxx || y < miny || y > maxy) {
6.321 + continue;
6.322 + }
6.323 + status = func(dst, x, y, blendMode, r, g, b, a);
6.324 + }
6.325 + return status;
6.326 +}
6.327 +
6.328 +/* vi: set ts=4 sw=4 expandtab: */
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/src/render/software/SDL_blendpoint.h Thu Feb 03 02:45:29 2011 -0800
7.3 @@ -0,0 +1,28 @@
7.4 +/*
7.5 + SDL - Simple DirectMedia Layer
7.6 + Copyright (C) 1997-2010 Sam Lantinga
7.7 +
7.8 + This library is free software; you can redistribute it and/or
7.9 + modify it under the terms of the GNU Lesser General Public
7.10 + License as published by the Free Software Foundation; either
7.11 + version 2.1 of the License, or (at your option) any later version.
7.12 +
7.13 + This library is distributed in the hope that it will be useful,
7.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7.16 + Lesser General Public License for more details.
7.17 +
7.18 + You should have received a copy of the GNU Lesser General Public
7.19 + License along with this library; if not, write to the Free Software
7.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7.21 +
7.22 + Sam Lantinga
7.23 + slouken@libsdl.org
7.24 +*/
7.25 +#include "SDL_config.h"
7.26 +
7.27 +
7.28 +extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
7.29 +extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
7.30 +
7.31 +/* vi: set ts=4 sw=4 expandtab: */
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/src/render/software/SDL_draw.h Thu Feb 03 02:45:29 2011 -0800
8.3 @@ -0,0 +1,521 @@
8.4 +/*
8.5 + SDL - Simple DirectMedia Layer
8.6 + Copyright (C) 1997-2010 Sam Lantinga
8.7 +
8.8 + This library is free software; you can redistribute it and/or
8.9 + modify it under the terms of the GNU Lesser General Public
8.10 + License as published by the Free Software Foundation; either
8.11 + version 2.1 of the License, or (at your option) any later version.
8.12 +
8.13 + This library is distributed in the hope that it will be useful,
8.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8.16 + Lesser General Public License for more details.
8.17 +
8.18 + You should have received a copy of the GNU Lesser General Public
8.19 + License along with this library; if not, write to the Free Software
8.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8.21 +
8.22 + Sam Lantinga
8.23 + slouken@libsdl.org
8.24 +*/
8.25 +#include "SDL_config.h"
8.26 +
8.27 +#include "../../video/SDL_blit.h"
8.28 +
8.29 +/* This code assumes that r, g, b, a are the source color,
8.30 + * and in the blend and add case, the RGB values are premultiplied by a.
8.31 + */
8.32 +
8.33 +#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
8.34 +
8.35 +#define DRAW_FASTSETPIXEL(type) \
8.36 + *pixel = (type) color
8.37 +
8.38 +#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
8.39 +#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
8.40 +#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
8.41 +
8.42 +#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
8.43 + *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
8.44 + + (x) * bpp) = (type) color
8.45 +
8.46 +#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
8.47 +#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
8.48 +#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
8.49 +
8.50 +#define DRAW_SETPIXEL(setpixel) \
8.51 +do { \
8.52 + unsigned sr = r, sg = g, sb = b, sa = a; \
8.53 + setpixel; \
8.54 +} while (0)
8.55 +
8.56 +#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
8.57 +do { \
8.58 + unsigned sr, sg, sb, sa; sa; \
8.59 + getpixel; \
8.60 + sr = DRAW_MUL(inva, sr) + r; \
8.61 + sg = DRAW_MUL(inva, sg) + g; \
8.62 + sb = DRAW_MUL(inva, sb) + b; \
8.63 + setpixel; \
8.64 +} while (0)
8.65 +
8.66 +#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
8.67 +do { \
8.68 + unsigned sr, sg, sb, sa; sa; \
8.69 + getpixel; \
8.70 + sr += r; if (sr > 0xff) sr = 0xff; \
8.71 + sg += g; if (sg > 0xff) sg = 0xff; \
8.72 + sb += b; if (sb > 0xff) sb = 0xff; \
8.73 + setpixel; \
8.74 +} while (0)
8.75 +
8.76 +#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
8.77 +do { \
8.78 + type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
8.79 + + (x) * bpp); \
8.80 + op; \
8.81 +} while (0)
8.82 +
8.83 +/*
8.84 + * Define draw operators for RGB555
8.85 + */
8.86 +
8.87 +#define DRAW_SETPIXEL_RGB555 \
8.88 + DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
8.89 +
8.90 +#define DRAW_SETPIXEL_BLEND_RGB555 \
8.91 + DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
8.92 + RGB555_FROM_RGB(*pixel, sr, sg, sb))
8.93 +
8.94 +#define DRAW_SETPIXEL_ADD_RGB555 \
8.95 + DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
8.96 + RGB555_FROM_RGB(*pixel, sr, sg, sb))
8.97 +
8.98 +#define DRAW_SETPIXELXY_RGB555(x, y) \
8.99 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
8.100 +
8.101 +#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
8.102 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
8.103 +
8.104 +#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
8.105 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
8.106 +
8.107 +/*
8.108 + * Define draw operators for RGB565
8.109 + */
8.110 +
8.111 +#define DRAW_SETPIXEL_RGB565 \
8.112 + DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
8.113 +
8.114 +#define DRAW_SETPIXEL_BLEND_RGB565 \
8.115 + DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
8.116 + RGB565_FROM_RGB(*pixel, sr, sg, sb))
8.117 +
8.118 +#define DRAW_SETPIXEL_ADD_RGB565 \
8.119 + DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
8.120 + RGB565_FROM_RGB(*pixel, sr, sg, sb))
8.121 +
8.122 +#define DRAW_SETPIXELXY_RGB565(x, y) \
8.123 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
8.124 +
8.125 +#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
8.126 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
8.127 +
8.128 +#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
8.129 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
8.130 +
8.131 +/*
8.132 + * Define draw operators for RGB888
8.133 + */
8.134 +
8.135 +#define DRAW_SETPIXEL_RGB888 \
8.136 + DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
8.137 +
8.138 +#define DRAW_SETPIXEL_BLEND_RGB888 \
8.139 + DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
8.140 + RGB888_FROM_RGB(*pixel, sr, sg, sb))
8.141 +
8.142 +#define DRAW_SETPIXEL_ADD_RGB888 \
8.143 + DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
8.144 + RGB888_FROM_RGB(*pixel, sr, sg, sb))
8.145 +
8.146 +#define DRAW_SETPIXELXY_RGB888(x, y) \
8.147 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
8.148 +
8.149 +#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
8.150 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
8.151 +
8.152 +#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
8.153 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
8.154 +
8.155 +/*
8.156 + * Define draw operators for ARGB8888
8.157 + */
8.158 +
8.159 +#define DRAW_SETPIXEL_ARGB8888 \
8.160 + DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
8.161 +
8.162 +#define DRAW_SETPIXEL_BLEND_ARGB8888 \
8.163 + DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
8.164 + ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
8.165 +
8.166 +#define DRAW_SETPIXEL_ADD_ARGB8888 \
8.167 + DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
8.168 + ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
8.169 +
8.170 +#define DRAW_SETPIXELXY_ARGB8888(x, y) \
8.171 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
8.172 +
8.173 +#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
8.174 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
8.175 +
8.176 +#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
8.177 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
8.178 +
8.179 +/*
8.180 + * Define draw operators for general RGB
8.181 + */
8.182 +
8.183 +#define DRAW_SETPIXEL_RGB \
8.184 + DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
8.185 +
8.186 +#define DRAW_SETPIXEL_BLEND_RGB \
8.187 + DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
8.188 + PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
8.189 +
8.190 +#define DRAW_SETPIXEL_ADD_RGB \
8.191 + DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
8.192 + PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
8.193 +
8.194 +#define DRAW_SETPIXELXY2_RGB(x, y) \
8.195 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
8.196 +
8.197 +#define DRAW_SETPIXELXY4_RGB(x, y) \
8.198 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
8.199 +
8.200 +#define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
8.201 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
8.202 +
8.203 +#define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
8.204 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
8.205 +
8.206 +#define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
8.207 + DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
8.208 +
8.209 +#define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
8.210 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
8.211 +
8.212 +
8.213 +/*
8.214 + * Define draw operators for general RGBA
8.215 + */
8.216 +
8.217 +#define DRAW_SETPIXEL_RGBA \
8.218 + DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
8.219 +
8.220 +#define DRAW_SETPIXEL_BLEND_RGBA \
8.221 + DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
8.222 + PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
8.223 +
8.224 +#define DRAW_SETPIXEL_ADD_RGBA \
8.225 + DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
8.226 + PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
8.227 +
8.228 +#define DRAW_SETPIXELXY4_RGBA(x, y) \
8.229 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
8.230 +
8.231 +#define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
8.232 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
8.233 +
8.234 +#define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
8.235 + DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
8.236 +
8.237 +/*
8.238 + * Define line drawing macro
8.239 + */
8.240 +
8.241 +#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
8.242 +
8.243 +/* Horizontal line */
8.244 +#define HLINE(type, op, draw_end) \
8.245 +{ \
8.246 + int length; \
8.247 + int pitch = (dst->pitch / dst->format->BytesPerPixel); \
8.248 + type *pixel; \
8.249 + if (x1 <= x2) { \
8.250 + pixel = (type *)dst->pixels + y1 * pitch + x1; \
8.251 + length = draw_end ? (x2-x1+1) : (x2-x1); \
8.252 + } else { \
8.253 + pixel = (type *)dst->pixels + y1 * pitch + x2; \
8.254 + if (!draw_end) { \
8.255 + ++pixel; \
8.256 + } \
8.257 + length = draw_end ? (x1-x2+1) : (x1-x2); \
8.258 + } \
8.259 + while (length--) { \
8.260 + op; \
8.261 + ++pixel; \
8.262 + } \
8.263 +}
8.264 +
8.265 +/* Vertical line */
8.266 +#define VLINE(type, op, draw_end) \
8.267 +{ \
8.268 + int length; \
8.269 + int pitch = (dst->pitch / dst->format->BytesPerPixel); \
8.270 + type *pixel; \
8.271 + if (y1 <= y2) { \
8.272 + pixel = (type *)dst->pixels + y1 * pitch + x1; \
8.273 + length = draw_end ? (y2-y1+1) : (y2-y1); \
8.274 + } else { \
8.275 + pixel = (type *)dst->pixels + y2 * pitch + x1; \
8.276 + if (!draw_end) { \
8.277 + pixel += pitch; \
8.278 + } \
8.279 + length = draw_end ? (y1-y2+1) : (y1-y2); \
8.280 + } \
8.281 + while (length--) { \
8.282 + op; \
8.283 + pixel += pitch; \
8.284 + } \
8.285 +}
8.286 +
8.287 +/* Diagonal line */
8.288 +#define DLINE(type, op, draw_end) \
8.289 +{ \
8.290 + int length; \
8.291 + int pitch = (dst->pitch / dst->format->BytesPerPixel); \
8.292 + type *pixel; \
8.293 + if (y1 <= y2) { \
8.294 + pixel = (type *)dst->pixels + y1 * pitch + x1; \
8.295 + if (x1 <= x2) { \
8.296 + ++pitch; \
8.297 + } else { \
8.298 + --pitch; \
8.299 + } \
8.300 + length = (y2-y1); \
8.301 + } else { \
8.302 + pixel = (type *)dst->pixels + y2 * pitch + x2; \
8.303 + if (x2 <= x1) { \
8.304 + ++pitch; \
8.305 + } else { \
8.306 + --pitch; \
8.307 + } \
8.308 + if (!draw_end) { \
8.309 + pixel += pitch; \
8.310 + } \
8.311 + length = (y1-y2); \
8.312 + } \
8.313 + if (draw_end) { \
8.314 + ++length; \
8.315 + } \
8.316 + while (length--) { \
8.317 + op; \
8.318 + pixel += pitch; \
8.319 + } \
8.320 +}
8.321 +
8.322 +/* Bresenham's line algorithm */
8.323 +#define BLINE(x1, y1, x2, y2, op, draw_end) \
8.324 +{ \
8.325 + int i, deltax, deltay, numpixels; \
8.326 + int d, dinc1, dinc2; \
8.327 + int x, xinc1, xinc2; \
8.328 + int y, yinc1, yinc2; \
8.329 + \
8.330 + deltax = ABS(x2 - x1); \
8.331 + deltay = ABS(y2 - y1); \
8.332 + \
8.333 + if (deltax >= deltay) { \
8.334 + numpixels = deltax + 1; \
8.335 + d = (2 * deltay) - deltax; \
8.336 + dinc1 = deltay * 2; \
8.337 + dinc2 = (deltay - deltax) * 2; \
8.338 + xinc1 = 1; \
8.339 + xinc2 = 1; \
8.340 + yinc1 = 0; \
8.341 + yinc2 = 1; \
8.342 + } else { \
8.343 + numpixels = deltay + 1; \
8.344 + d = (2 * deltax) - deltay; \
8.345 + dinc1 = deltax * 2; \
8.346 + dinc2 = (deltax - deltay) * 2; \
8.347 + xinc1 = 0; \
8.348 + xinc2 = 1; \
8.349 + yinc1 = 1; \
8.350 + yinc2 = 1; \
8.351 + } \
8.352 + \
8.353 + if (x1 > x2) { \
8.354 + xinc1 = -xinc1; \
8.355 + xinc2 = -xinc2; \
8.356 + } \
8.357 + if (y1 > y2) { \
8.358 + yinc1 = -yinc1; \
8.359 + yinc2 = -yinc2; \
8.360 + } \
8.361 + \
8.362 + x = x1; \
8.363 + y = y1; \
8.364 + \
8.365 + if (!draw_end) { \
8.366 + --numpixels; \
8.367 + } \
8.368 + for (i = 0; i < numpixels; ++i) { \
8.369 + op(x, y); \
8.370 + if (d < 0) { \
8.371 + d += dinc1; \
8.372 + x += xinc1; \
8.373 + y += yinc1; \
8.374 + } else { \
8.375 + d += dinc2; \
8.376 + x += xinc2; \
8.377 + y += yinc2; \
8.378 + } \
8.379 + } \
8.380 +}
8.381 +
8.382 +/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
8.383 +#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
8.384 +{ \
8.385 + Uint16 ErrorAdj, ErrorAcc; \
8.386 + Uint16 ErrorAccTemp, Weighting; \
8.387 + int DeltaX, DeltaY, Temp, XDir; \
8.388 + unsigned r, g, b, a, inva; \
8.389 + \
8.390 + /* Draw the initial pixel, which is always exactly intersected by \
8.391 + the line and so needs no weighting */ \
8.392 + opaque_op(x1, y1); \
8.393 + \
8.394 + /* Draw the final pixel, which is always exactly intersected by the line \
8.395 + and so needs no weighting */ \
8.396 + if (draw_end) { \
8.397 + opaque_op(x2, y2); \
8.398 + } \
8.399 + \
8.400 + /* Make sure the line runs top to bottom */ \
8.401 + if (y1 > y2) { \
8.402 + Temp = y1; y1 = y2; y2 = Temp; \
8.403 + Temp = x1; x1 = x2; x2 = Temp; \
8.404 + } \
8.405 + DeltaY = y2 - y1; \
8.406 + \
8.407 + if ((DeltaX = x2 - x1) >= 0) { \
8.408 + XDir = 1; \
8.409 + } else { \
8.410 + XDir = -1; \
8.411 + DeltaX = -DeltaX; /* make DeltaX positive */ \
8.412 + } \
8.413 + \
8.414 + /* line is not horizontal, diagonal, or vertical */ \
8.415 + ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
8.416 + \
8.417 + /* Is this an X-major or Y-major line? */ \
8.418 + if (DeltaY > DeltaX) { \
8.419 + /* Y-major line; calculate 16-bit fixed-point fractional part of a \
8.420 + pixel that X advances each time Y advances 1 pixel, truncating the \
8.421 + result so that we won't overrun the endpoint along the X axis */ \
8.422 + ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
8.423 + /* Draw all pixels other than the first and last */ \
8.424 + while (--DeltaY) { \
8.425 + ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
8.426 + ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
8.427 + if (ErrorAcc <= ErrorAccTemp) { \
8.428 + /* The error accumulator turned over, so advance the X coord */ \
8.429 + x1 += XDir; \
8.430 + } \
8.431 + y1++; /* Y-major, so always advance Y */ \
8.432 + /* The IntensityBits most significant bits of ErrorAcc give us the \
8.433 + intensity weighting for this pixel, and the complement of the \
8.434 + weighting for the paired pixel */ \
8.435 + Weighting = ErrorAcc >> 8; \
8.436 + { \
8.437 + a = DRAW_MUL(_a, (Weighting ^ 255)); \
8.438 + r = DRAW_MUL(_r, a); \
8.439 + g = DRAW_MUL(_g, a); \
8.440 + b = DRAW_MUL(_b, a); \
8.441 + inva = (a ^ 0xFF); \
8.442 + blend_op(x1, y1); \
8.443 + } \
8.444 + { \
8.445 + a = DRAW_MUL(_a, Weighting); \
8.446 + r = DRAW_MUL(_r, a); \
8.447 + g = DRAW_MUL(_g, a); \
8.448 + b = DRAW_MUL(_b, a); \
8.449 + inva = (a ^ 0xFF); \
8.450 + blend_op(x1 + XDir, y1); \
8.451 + } \
8.452 + } \
8.453 + } else { \
8.454 + /* X-major line; calculate 16-bit fixed-point fractional part of a \
8.455 + pixel that Y advances each time X advances 1 pixel, truncating the \
8.456 + result to avoid overrunning the endpoint along the X axis */ \
8.457 + ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
8.458 + /* Draw all pixels other than the first and last */ \
8.459 + while (--DeltaX) { \
8.460 + ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
8.461 + ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
8.462 + if (ErrorAcc <= ErrorAccTemp) { \
8.463 + /* The error accumulator turned over, so advance the Y coord */ \
8.464 + y1++; \
8.465 + } \
8.466 + x1 += XDir; /* X-major, so always advance X */ \
8.467 + /* The IntensityBits most significant bits of ErrorAcc give us the \
8.468 + intensity weighting for this pixel, and the complement of the \
8.469 + weighting for the paired pixel */ \
8.470 + Weighting = ErrorAcc >> 8; \
8.471 + { \
8.472 + a = DRAW_MUL(_a, (Weighting ^ 255)); \
8.473 + r = DRAW_MUL(_r, a); \
8.474 + g = DRAW_MUL(_g, a); \
8.475 + b = DRAW_MUL(_b, a); \
8.476 + inva = (a ^ 0xFF); \
8.477 + blend_op(x1, y1); \
8.478 + } \
8.479 + { \
8.480 + a = DRAW_MUL(_a, Weighting); \
8.481 + r = DRAW_MUL(_r, a); \
8.482 + g = DRAW_MUL(_g, a); \
8.483 + b = DRAW_MUL(_b, a); \
8.484 + inva = (a ^ 0xFF); \
8.485 + blend_op(x1, y1 + 1); \
8.486 + } \
8.487 + } \
8.488 + } \
8.489 +}
8.490 +
8.491 +#ifdef AA_LINES
8.492 +#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
8.493 + WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
8.494 +#else
8.495 +#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
8.496 + BLINE(x1, y1, x2, y2, opaque_op, draw_end)
8.497 +#endif
8.498 +
8.499 +/*
8.500 + * Define fill rect macro
8.501 + */
8.502 +
8.503 +#define FILLRECT(type, op) \
8.504 +do { \
8.505 + int width = rect->w; \
8.506 + int height = rect->h; \
8.507 + int pitch = (dst->pitch / dst->format->BytesPerPixel); \
8.508 + int skip = pitch - width; \
8.509 + type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
8.510 + while (height--) { \
8.511 + { int n = (width+3)/4; \
8.512 + switch (width & 3) { \
8.513 + case 0: do { op; pixel++; \
8.514 + case 3: op; pixel++; \
8.515 + case 2: op; pixel++; \
8.516 + case 1: op; pixel++; \
8.517 + } while ( --n > 0 ); \
8.518 + } \
8.519 + } \
8.520 + pixel += skip; \
8.521 + } \
8.522 +} while (0)
8.523 +
8.524 +/* vi: set ts=4 sw=4 expandtab: */
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/src/render/software/SDL_drawline.c Thu Feb 03 02:45:29 2011 -0800
9.3 @@ -0,0 +1,210 @@
9.4 +/*
9.5 + SDL - Simple DirectMedia Layer
9.6 + Copyright (C) 1997-2010 Sam Lantinga
9.7 +
9.8 + This library is free software; you can redistribute it and/or
9.9 + modify it under the terms of the GNU Lesser General Public
9.10 + License as published by the Free Software Foundation; either
9.11 + version 2.1 of the License, or (at your option) any later version.
9.12 +
9.13 + This library is distributed in the hope that it will be useful,
9.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
9.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9.16 + Lesser General Public License for more details.
9.17 +
9.18 + You should have received a copy of the GNU Lesser General Public
9.19 + License along with this library; if not, write to the Free Software
9.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9.21 +
9.22 + Sam Lantinga
9.23 + slouken@libsdl.org
9.24 +*/
9.25 +#include "SDL_config.h"
9.26 +
9.27 +#include "SDL_draw.h"
9.28 +#include "SDL_drawline.h"
9.29 +
9.30 +
9.31 +static void
9.32 +SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
9.33 + SDL_bool draw_end)
9.34 +{
9.35 + if (y1 == y2) {
9.36 + //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
9.37 + int length;
9.38 + int pitch = (dst->pitch / dst->format->BytesPerPixel);
9.39 + Uint8 *pixel;
9.40 + if (x1 <= x2) {
9.41 + pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
9.42 + length = draw_end ? (x2-x1+1) : (x2-x1);
9.43 + } else {
9.44 + pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
9.45 + if (!draw_end) {
9.46 + ++pixel;
9.47 + }
9.48 + length = draw_end ? (x1-x2+1) : (x1-x2);
9.49 + }
9.50 + SDL_memset(pixel, color, length);
9.51 + } else if (x1 == x2) {
9.52 + VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
9.53 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
9.54 + DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
9.55 + } else {
9.56 + BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
9.57 + }
9.58 +}
9.59 +
9.60 +static void
9.61 +SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
9.62 + SDL_bool draw_end)
9.63 +{
9.64 + if (y1 == y2) {
9.65 + HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
9.66 + } else if (x1 == x2) {
9.67 + VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
9.68 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
9.69 + DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
9.70 + } else {
9.71 + Uint8 _r, _g, _b, _a;
9.72 + const SDL_PixelFormat * fmt = dst->format;
9.73 + SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
9.74 + if (fmt->Rmask == 0x7C00) {
9.75 + AALINE(x1, y1, x2, y2,
9.76 + DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
9.77 + draw_end);
9.78 + } else if (fmt->Rmask == 0xF800) {
9.79 + AALINE(x1, y1, x2, y2,
9.80 + DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
9.81 + draw_end);
9.82 + } else {
9.83 + AALINE(x1, y1, x2, y2,
9.84 + DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
9.85 + draw_end);
9.86 + }
9.87 + }
9.88 +}
9.89 +
9.90 +static void
9.91 +SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
9.92 + SDL_bool draw_end)
9.93 +{
9.94 + if (y1 == y2) {
9.95 + HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
9.96 + } else if (x1 == x2) {
9.97 + VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
9.98 + } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
9.99 + DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
9.100 + } else {
9.101 + Uint8 _r, _g, _b, _a;
9.102 + const SDL_PixelFormat * fmt = dst->format;
9.103 + SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
9.104 + if (fmt->Rmask == 0x00FF0000) {
9.105 + if (!fmt->Amask) {
9.106 + AALINE(x1, y1, x2, y2,
9.107 + DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
9.108 + draw_end);
9.109 + } else {
9.110 + AALINE(x1, y1, x2, y2,
9.111 + DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
9.112 + draw_end);
9.113 + }
9.114 + } else {
9.115 + AALINE(x1, y1, x2, y2,
9.116 + DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
9.117 + draw_end);
9.118 + }
9.119 + }
9.120 +}
9.121 +
9.122 +typedef void (*DrawLineFunc) (SDL_Surface * dst,
9.123 + int x1, int y1, int x2, int y2,
9.124 + Uint32 color, SDL_bool draw_end);
9.125 +
9.126 +static DrawLineFunc
9.127 +SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
9.128 +{
9.129 + switch (fmt->BytesPerPixel) {
9.130 + case 1:
9.131 + if (fmt->BitsPerPixel < 8) {
9.132 + break;
9.133 + }
9.134 + return SDL_DrawLine1;
9.135 + case 2:
9.136 + return SDL_DrawLine2;
9.137 + case 4:
9.138 + return SDL_DrawLine4;
9.139 + }
9.140 + return NULL;
9.141 +}
9.142 +
9.143 +int
9.144 +SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
9.145 +{
9.146 + DrawLineFunc func;
9.147 +
9.148 + if (!dst) {
9.149 + SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
9.150 + return -1;
9.151 + }
9.152 +
9.153 + func = SDL_CalculateDrawLineFunc(dst->format);
9.154 + if (!func) {
9.155 + SDL_SetError("SDL_DrawLine(): Unsupported surface format");
9.156 + return -1;
9.157 + }
9.158 +
9.159 + /* Perform clipping */
9.160 + /* FIXME: We don't actually want to clip, as it may change line slope */
9.161 + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
9.162 + return 0;
9.163 + }
9.164 +
9.165 + func(dst, x1, y1, x2, y2, color, SDL_TRUE);
9.166 + return 0;
9.167 +}
9.168 +
9.169 +int
9.170 +SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
9.171 + Uint32 color)
9.172 +{
9.173 + int i;
9.174 + int x1, y1;
9.175 + int x2, y2;
9.176 + SDL_bool draw_end;
9.177 + DrawLineFunc func;
9.178 +
9.179 + if (!dst) {
9.180 + SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
9.181 + return -1;
9.182 + }
9.183 +
9.184 + func = SDL_CalculateDrawLineFunc(dst->format);
9.185 + if (!func) {
9.186 + SDL_SetError("SDL_DrawLines(): Unsupported surface format");
9.187 + return -1;
9.188 + }
9.189 +
9.190 + for (i = 1; i < count; ++i) {
9.191 + x1 = points[i-1].x;
9.192 + y1 = points[i-1].y;
9.193 + x2 = points[i].x;
9.194 + y2 = points[i].y;
9.195 +
9.196 + /* Perform clipping */
9.197 + /* FIXME: We don't actually want to clip, as it may change line slope */
9.198 + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
9.199 + continue;
9.200 + }
9.201 +
9.202 + /* Draw the end if it was clipped */
9.203 + draw_end = (x2 != points[i].x || y2 != points[i].y);
9.204 +
9.205 + func(dst, x1, y1, x2, y2, color, draw_end);
9.206 + }
9.207 + if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
9.208 + SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
9.209 + }
9.210 + return 0;
9.211 +}
9.212 +
9.213 +/* vi: set ts=4 sw=4 expandtab: */
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/src/render/software/SDL_drawline.h Thu Feb 03 02:45:29 2011 -0800
10.3 @@ -0,0 +1,28 @@
10.4 +/*
10.5 + SDL - Simple DirectMedia Layer
10.6 + Copyright (C) 1997-2010 Sam Lantinga
10.7 +
10.8 + This library is free software; you can redistribute it and/or
10.9 + modify it under the terms of the GNU Lesser General Public
10.10 + License as published by the Free Software Foundation; either
10.11 + version 2.1 of the License, or (at your option) any later version.
10.12 +
10.13 + This library is distributed in the hope that it will be useful,
10.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10.16 + Lesser General Public License for more details.
10.17 +
10.18 + You should have received a copy of the GNU Lesser General Public
10.19 + License along with this library; if not, write to the Free Software
10.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
10.21 +
10.22 + Sam Lantinga
10.23 + slouken@libsdl.org
10.24 +*/
10.25 +#include "SDL_config.h"
10.26 +
10.27 +
10.28 +extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
10.29 +extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
10.30 +
10.31 +/* vi: set ts=4 sw=4 expandtab: */
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/render/software/SDL_drawpoint.c Thu Feb 03 02:45:29 2011 -0800
11.3 @@ -0,0 +1,117 @@
11.4 +/*
11.5 + SDL - Simple DirectMedia Layer
11.6 + Copyright (C) 1997-2010 Sam Lantinga
11.7 +
11.8 + This library is free software; you can redistribute it and/or
11.9 + modify it under the terms of the GNU Lesser General Public
11.10 + License as published by the Free Software Foundation; either
11.11 + version 2.1 of the License, or (at your option) any later version.
11.12 +
11.13 + This library is distributed in the hope that it will be useful,
11.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11.16 + Lesser General Public License for more details.
11.17 +
11.18 + You should have received a copy of the GNU Lesser General Public
11.19 + License along with this library; if not, write to the Free Software
11.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11.21 +
11.22 + Sam Lantinga
11.23 + slouken@libsdl.org
11.24 +*/
11.25 +#include "SDL_config.h"
11.26 +
11.27 +#include "SDL_draw.h"
11.28 +#include "SDL_drawpoint.h"
11.29 +
11.30 +
11.31 +int
11.32 +SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
11.33 +{
11.34 + if (!dst) {
11.35 + SDL_SetError("Passed NULL destination surface");
11.36 + return -1;
11.37 + }
11.38 +
11.39 + /* This function doesn't work on surfaces < 8 bpp */
11.40 + if (dst->format->BitsPerPixel < 8) {
11.41 + SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
11.42 + return -1;
11.43 + }
11.44 +
11.45 + /* Perform clipping */
11.46 + if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
11.47 + x >= (dst->clip_rect.x + dst->clip_rect.w) ||
11.48 + y >= (dst->clip_rect.y + dst->clip_rect.h)) {
11.49 + return 0;
11.50 + }
11.51 +
11.52 + switch (dst->format->BytesPerPixel) {
11.53 + case 1:
11.54 + DRAW_FASTSETPIXELXY1(x, y);
11.55 + break;
11.56 + case 2:
11.57 + DRAW_FASTSETPIXELXY2(x, y);
11.58 + break;
11.59 + case 3:
11.60 + SDL_Unsupported();
11.61 + return -1;
11.62 + case 4:
11.63 + DRAW_FASTSETPIXELXY4(x, y);
11.64 + break;
11.65 + }
11.66 + return 0;
11.67 +}
11.68 +
11.69 +int
11.70 +SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
11.71 + Uint32 color)
11.72 +{
11.73 + int minx, miny;
11.74 + int maxx, maxy;
11.75 + int i;
11.76 + int x, y;
11.77 +
11.78 + if (!dst) {
11.79 + SDL_SetError("Passed NULL destination surface");
11.80 + return -1;
11.81 + }
11.82 +
11.83 + /* This function doesn't work on surfaces < 8 bpp */
11.84 + if (dst->format->BitsPerPixel < 8) {
11.85 + SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
11.86 + return -1;
11.87 + }
11.88 +
11.89 + minx = dst->clip_rect.x;
11.90 + maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
11.91 + miny = dst->clip_rect.y;
11.92 + maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
11.93 +
11.94 + for (i = 0; i < count; ++i) {
11.95 + x = points[i].x;
11.96 + y = points[i].y;
11.97 +
11.98 + if (x < minx || x > maxx || y < miny || y > maxy) {
11.99 + continue;
11.100 + }
11.101 +
11.102 + switch (dst->format->BytesPerPixel) {
11.103 + case 1:
11.104 + DRAW_FASTSETPIXELXY1(x, y);
11.105 + break;
11.106 + case 2:
11.107 + DRAW_FASTSETPIXELXY2(x, y);
11.108 + break;
11.109 + case 3:
11.110 + SDL_Unsupported();
11.111 + return -1;
11.112 + case 4:
11.113 + DRAW_FASTSETPIXELXY4(x, y);
11.114 + break;
11.115 + }
11.116 + }
11.117 + return 0;
11.118 +}
11.119 +
11.120 +/* vi: set ts=4 sw=4 expandtab: */
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/src/render/software/SDL_drawpoint.h Thu Feb 03 02:45:29 2011 -0800
12.3 @@ -0,0 +1,28 @@
12.4 +/*
12.5 + SDL - Simple DirectMedia Layer
12.6 + Copyright (C) 1997-2010 Sam Lantinga
12.7 +
12.8 + This library is free software; you can redistribute it and/or
12.9 + modify it under the terms of the GNU Lesser General Public
12.10 + License as published by the Free Software Foundation; either
12.11 + version 2.1 of the License, or (at your option) any later version.
12.12 +
12.13 + This library is distributed in the hope that it will be useful,
12.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
12.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12.16 + Lesser General Public License for more details.
12.17 +
12.18 + You should have received a copy of the GNU Lesser General Public
12.19 + License along with this library; if not, write to the Free Software
12.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12.21 +
12.22 + Sam Lantinga
12.23 + slouken@libsdl.org
12.24 +*/
12.25 +#include "SDL_config.h"
12.26 +
12.27 +
12.28 +extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color);
12.29 +extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
12.30 +
12.31 +/* vi: set ts=4 sw=4 expandtab: */
13.1 --- a/src/render/software/SDL_renderer_sw.c Thu Feb 03 02:42:50 2011 -0800
13.2 +++ b/src/render/software/SDL_renderer_sw.c Thu Feb 03 02:45:29 2011 -0800
13.3 @@ -24,6 +24,13 @@
13.4 #include "../SDL_sysrender.h"
13.5 #include "../../video/SDL_pixels_c.h"
13.6
13.7 +#include "SDL_draw.h"
13.8 +#include "SDL_blendfillrect.h"
13.9 +#include "SDL_blendline.h"
13.10 +#include "SDL_blendpoint.h"
13.11 +#include "SDL_drawline.h"
13.12 +#include "SDL_drawpoint.h"
13.13 +
13.14
13.15 /* SDL surface based renderer implementation */
13.16
14.1 --- a/src/video/SDL_alphamult.c Thu Feb 03 02:42:50 2011 -0800
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,60 +0,0 @@
14.4 -/*
14.5 - SDL - Simple DirectMedia Layer
14.6 - Copyright (C) 1997-2010 Sam Lantinga
14.7 -
14.8 - This library is free software; you can redistribute it and/or
14.9 - modify it under the terms of the GNU Lesser General Public
14.10 - License as published by the Free Software Foundation; either
14.11 - version 2.1 of the License, or (at your option) any later version.
14.12 -
14.13 - This library is distributed in the hope that it will be useful,
14.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
14.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14.16 - Lesser General Public License for more details.
14.17 -
14.18 - You should have received a copy of the GNU Lesser General Public
14.19 - License along with this library; if not, write to the Free Software
14.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14.21 -
14.22 - Sam Lantinga
14.23 - slouken@libsdl.org
14.24 -*/
14.25 -#include "SDL_config.h"
14.26 -
14.27 -#include "SDL_blit.h"
14.28 -#include "SDL_alphamult.h"
14.29 -
14.30 -/* Functions to pre-multiply the alpha channel into the color channels */
14.31 -
14.32 -#define DEFINE_PREMULTIPLY_FUNC(fmt) \
14.33 -void \
14.34 -SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch) \
14.35 -{ \
14.36 - pitch /= 4; \
14.37 - while (h--) { \
14.38 - int n; \
14.39 - Uint32 *row = pixels; \
14.40 - Uint32 pixel; \
14.41 - unsigned r, g, b, a; \
14.42 - \
14.43 - for (n = w; n--; ) { \
14.44 - pixel = *row; \
14.45 - RGBA_FROM_##fmt(pixel, r, g, b, a); \
14.46 - r = (r * a) / 255; \
14.47 - g = (g * a) / 255; \
14.48 - b = (b * a) / 255; \
14.49 - fmt##_FROM_RGBA(*row, r, g, b, a); \
14.50 - ++row; \
14.51 - } \
14.52 - pixels += pitch; \
14.53 - } \
14.54 -}
14.55 -
14.56 -/* *INDENT-OFF* */
14.57 -DEFINE_PREMULTIPLY_FUNC(ARGB8888)
14.58 -DEFINE_PREMULTIPLY_FUNC(RGBA8888)
14.59 -DEFINE_PREMULTIPLY_FUNC(ABGR8888)
14.60 -DEFINE_PREMULTIPLY_FUNC(BGRA8888)
14.61 -/* *INDENT-ON* */
14.62 -
14.63 -/* vi: set ts=4 sw=4 expandtab: */
15.1 --- a/src/video/SDL_alphamult.h Thu Feb 03 02:42:50 2011 -0800
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,38 +0,0 @@
15.4 -/*
15.5 - SDL - Simple DirectMedia Layer
15.6 - Copyright (C) 1997-2010 Sam Lantinga
15.7 -
15.8 - This library is free software; you can redistribute it and/or
15.9 - modify it under the terms of the GNU Lesser General Public
15.10 - License as published by the Free Software Foundation; either
15.11 - version 2.1 of the License, or (at your option) any later version.
15.12 -
15.13 - This library is distributed in the hope that it will be useful,
15.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
15.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15.16 - Lesser General Public License for more details.
15.17 -
15.18 - You should have received a copy of the GNU Lesser General Public
15.19 - License along with this library; if not, write to the Free Software
15.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15.21 -
15.22 - Sam Lantinga
15.23 - slouken@libsdl.org
15.24 -*/
15.25 -
15.26 -/* Functions to pre-multiply the alpha channel into the color channels */
15.27 -
15.28 -#define DEFINE_PREMULTIPLY_FUNC(fmt) \
15.29 -void \
15.30 -SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch);
15.31 -
15.32 -/* *INDENT-OFF* */
15.33 -DEFINE_PREMULTIPLY_FUNC(ARGB8888)
15.34 -DEFINE_PREMULTIPLY_FUNC(RGBA8888)
15.35 -DEFINE_PREMULTIPLY_FUNC(ABGR8888)
15.36 -DEFINE_PREMULTIPLY_FUNC(BGRA8888)
15.37 -/* *INDENT-ON* */
15.38 -
15.39 -#undef DEFINE_PREMULTIPLY_FUNC
15.40 -
15.41 -/* vi: set ts=4 sw=4 expandtab: */
16.1 --- a/src/video/SDL_blendfillrect.c Thu Feb 03 02:42:50 2011 -0800
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,326 +0,0 @@
16.4 -/*
16.5 - SDL - Simple DirectMedia Layer
16.6 - Copyright (C) 1997-2010 Sam Lantinga
16.7 -
16.8 - This library is free software; you can redistribute it and/or
16.9 - modify it under the terms of the GNU Lesser General Public
16.10 - License as published by the Free Software Foundation; either
16.11 - version 2.1 of the License, or (at your option) any later version.
16.12 -
16.13 - This library is distributed in the hope that it will be useful,
16.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
16.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16.16 - Lesser General Public License for more details.
16.17 -
16.18 - You should have received a copy of the GNU Lesser General Public
16.19 - License along with this library; if not, write to the Free Software
16.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16.21 -
16.22 - Sam Lantinga
16.23 - slouken@libsdl.org
16.24 -*/
16.25 -#include "SDL_config.h"
16.26 -
16.27 -#include "SDL_video.h"
16.28 -#include "SDL_draw.h"
16.29 -
16.30 -static int
16.31 -SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
16.32 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.33 -{
16.34 - unsigned inva = 0xff - a;
16.35 -
16.36 - switch (blendMode) {
16.37 - case SDL_BLENDMODE_BLEND:
16.38 - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
16.39 - break;
16.40 - case SDL_BLENDMODE_ADD:
16.41 - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
16.42 - break;
16.43 - default:
16.44 - FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
16.45 - break;
16.46 - }
16.47 - return 0;
16.48 -}
16.49 -
16.50 -static int
16.51 -SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
16.52 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.53 -{
16.54 - unsigned inva = 0xff - a;
16.55 -
16.56 - switch (blendMode) {
16.57 - case SDL_BLENDMODE_BLEND:
16.58 - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
16.59 - break;
16.60 - case SDL_BLENDMODE_ADD:
16.61 - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
16.62 - break;
16.63 - default:
16.64 - FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
16.65 - break;
16.66 - }
16.67 - return 0;
16.68 -}
16.69 -
16.70 -static int
16.71 -SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
16.72 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.73 -{
16.74 - unsigned inva = 0xff - a;
16.75 -
16.76 - switch (blendMode) {
16.77 - case SDL_BLENDMODE_BLEND:
16.78 - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
16.79 - break;
16.80 - case SDL_BLENDMODE_ADD:
16.81 - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
16.82 - break;
16.83 - default:
16.84 - FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
16.85 - break;
16.86 - }
16.87 - return 0;
16.88 -}
16.89 -
16.90 -static int
16.91 -SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
16.92 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.93 -{
16.94 - unsigned inva = 0xff - a;
16.95 -
16.96 - switch (blendMode) {
16.97 - case SDL_BLENDMODE_BLEND:
16.98 - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
16.99 - break;
16.100 - case SDL_BLENDMODE_ADD:
16.101 - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
16.102 - break;
16.103 - default:
16.104 - FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
16.105 - break;
16.106 - }
16.107 - return 0;
16.108 -}
16.109 -
16.110 -static int
16.111 -SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
16.112 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.113 -{
16.114 - SDL_PixelFormat *fmt = dst->format;
16.115 - unsigned inva = 0xff - a;
16.116 -
16.117 - switch (fmt->BytesPerPixel) {
16.118 - case 2:
16.119 - switch (blendMode) {
16.120 - case SDL_BLENDMODE_BLEND:
16.121 - FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
16.122 - break;
16.123 - case SDL_BLENDMODE_ADD:
16.124 - FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
16.125 - break;
16.126 - default:
16.127 - FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
16.128 - break;
16.129 - }
16.130 - return 0;
16.131 - case 4:
16.132 - switch (blendMode) {
16.133 - case SDL_BLENDMODE_BLEND:
16.134 - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
16.135 - break;
16.136 - case SDL_BLENDMODE_ADD:
16.137 - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
16.138 - break;
16.139 - default:
16.140 - FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
16.141 - break;
16.142 - }
16.143 - return 0;
16.144 - default:
16.145 - SDL_Unsupported();
16.146 - return -1;
16.147 - }
16.148 -}
16.149 -
16.150 -static int
16.151 -SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
16.152 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.153 -{
16.154 - SDL_PixelFormat *fmt = dst->format;
16.155 - unsigned inva = 0xff - a;
16.156 -
16.157 - switch (fmt->BytesPerPixel) {
16.158 - case 4:
16.159 - switch (blendMode) {
16.160 - case SDL_BLENDMODE_BLEND:
16.161 - FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
16.162 - break;
16.163 - case SDL_BLENDMODE_ADD:
16.164 - FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
16.165 - break;
16.166 - default:
16.167 - FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
16.168 - break;
16.169 - }
16.170 - return 0;
16.171 - default:
16.172 - SDL_Unsupported();
16.173 - return -1;
16.174 - }
16.175 -}
16.176 -
16.177 -int
16.178 -SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
16.179 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.180 -{
16.181 - SDL_Rect clipped;
16.182 -
16.183 - if (!dst) {
16.184 - SDL_SetError("Passed NULL destination surface");
16.185 - return -1;
16.186 - }
16.187 -
16.188 - /* This function doesn't work on surfaces < 8 bpp */
16.189 - if (dst->format->BitsPerPixel < 8) {
16.190 - SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
16.191 - return -1;
16.192 - }
16.193 -
16.194 - /* If 'rect' == NULL, then fill the whole surface */
16.195 - if (rect) {
16.196 - /* Perform clipping */
16.197 - if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
16.198 - return 0;
16.199 - }
16.200 - rect = &clipped;
16.201 - } else {
16.202 - rect = &dst->clip_rect;
16.203 - }
16.204 -
16.205 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
16.206 - r = DRAW_MUL(r, a);
16.207 - g = DRAW_MUL(g, a);
16.208 - b = DRAW_MUL(b, a);
16.209 - }
16.210 -
16.211 - switch (dst->format->BitsPerPixel) {
16.212 - case 15:
16.213 - switch (dst->format->Rmask) {
16.214 - case 0x7C00:
16.215 - return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
16.216 - }
16.217 - break;
16.218 - case 16:
16.219 - switch (dst->format->Rmask) {
16.220 - case 0xF800:
16.221 - return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
16.222 - }
16.223 - break;
16.224 - case 32:
16.225 - switch (dst->format->Rmask) {
16.226 - case 0x00FF0000:
16.227 - if (!dst->format->Amask) {
16.228 - return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
16.229 - } else {
16.230 - return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
16.231 - }
16.232 - break;
16.233 - }
16.234 - break;
16.235 - default:
16.236 - break;
16.237 - }
16.238 -
16.239 - if (!dst->format->Amask) {
16.240 - return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
16.241 - } else {
16.242 - return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
16.243 - }
16.244 -}
16.245 -
16.246 -int
16.247 -SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
16.248 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
16.249 -{
16.250 - SDL_Rect clipped;
16.251 - int i;
16.252 - int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
16.253 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
16.254 - int status = 0;
16.255 -
16.256 - if (!dst) {
16.257 - SDL_SetError("Passed NULL destination surface");
16.258 - return -1;
16.259 - }
16.260 -
16.261 - /* This function doesn't work on surfaces < 8 bpp */
16.262 - if (dst->format->BitsPerPixel < 8) {
16.263 - SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
16.264 - return -1;
16.265 - }
16.266 -
16.267 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
16.268 - r = DRAW_MUL(r, a);
16.269 - g = DRAW_MUL(g, a);
16.270 - b = DRAW_MUL(b, a);
16.271 - }
16.272 -
16.273 - /* FIXME: Does this function pointer slow things down significantly? */
16.274 - switch (dst->format->BitsPerPixel) {
16.275 - case 15:
16.276 - switch (dst->format->Rmask) {
16.277 - case 0x7C00:
16.278 - func = SDL_BlendFillRect_RGB555;
16.279 - }
16.280 - break;
16.281 - case 16:
16.282 - switch (dst->format->Rmask) {
16.283 - case 0xF800:
16.284 - func = SDL_BlendFillRect_RGB565;
16.285 - }
16.286 - break;
16.287 - case 32:
16.288 - switch (dst->format->Rmask) {
16.289 - case 0x00FF0000:
16.290 - if (!dst->format->Amask) {
16.291 - func = SDL_BlendFillRect_RGB888;
16.292 - } else {
16.293 - func = SDL_BlendFillRect_ARGB8888;
16.294 - }
16.295 - break;
16.296 - }
16.297 - break;
16.298 - default:
16.299 - break;
16.300 - }
16.301 -
16.302 - if (!func) {
16.303 - if (!dst->format->Amask) {
16.304 - func = SDL_BlendFillRect_RGB;
16.305 - } else {
16.306 - func = SDL_BlendFillRect_RGBA;
16.307 - }
16.308 - }
16.309 -
16.310 - for (i = 0; i < count; ++i) {
16.311 - const SDL_Rect * rect = rects[i];
16.312 -
16.313 - /* If 'rect' == NULL, then fill the whole surface */
16.314 - if (rect) {
16.315 - /* Perform clipping */
16.316 - if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
16.317 - continue;
16.318 - }
16.319 - rect = &clipped;
16.320 - } else {
16.321 - rect = &dst->clip_rect;
16.322 - }
16.323 -
16.324 - status = func(dst, rect, blendMode, r, g, b, a);
16.325 - }
16.326 - return status;
16.327 -}
16.328 -
16.329 -/* vi: set ts=4 sw=4 expandtab: */
17.1 --- a/src/video/SDL_blendline.c Thu Feb 03 02:42:50 2011 -0800
17.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
17.3 @@ -1,682 +0,0 @@
17.4 -/*
17.5 - SDL - Simple DirectMedia Layer
17.6 - Copyright (C) 1997-2010 Sam Lantinga
17.7 -
17.8 - This library is free software; you can redistribute it and/or
17.9 - modify it under the terms of the GNU Lesser General Public
17.10 - License as published by the Free Software Foundation; either
17.11 - version 2.1 of the License, or (at your option) any later version.
17.12 -
17.13 - This library is distributed in the hope that it will be useful,
17.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
17.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17.16 - Lesser General Public License for more details.
17.17 -
17.18 - You should have received a copy of the GNU Lesser General Public
17.19 - License along with this library; if not, write to the Free Software
17.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17.21 -
17.22 - Sam Lantinga
17.23 - slouken@libsdl.org
17.24 -*/
17.25 -#include "SDL_config.h"
17.26 -
17.27 -#include "SDL_draw.h"
17.28 -
17.29 -
17.30 -static void
17.31 -SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.32 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.33 - SDL_bool draw_end)
17.34 -{
17.35 - const SDL_PixelFormat *fmt = dst->format;
17.36 - unsigned r, g, b, a, inva;
17.37 -
17.38 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.39 - r = DRAW_MUL(_r, _a);
17.40 - g = DRAW_MUL(_g, _a);
17.41 - b = DRAW_MUL(_b, _a);
17.42 - a = _a;
17.43 - } else {
17.44 - r = _r;
17.45 - g = _g;
17.46 - b = _b;
17.47 - a = _a;
17.48 - }
17.49 - inva = (a ^ 0xff);
17.50 -
17.51 - if (y1 == y2) {
17.52 - switch (blendMode) {
17.53 - case SDL_BLENDMODE_BLEND:
17.54 - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.55 - break;
17.56 - case SDL_BLENDMODE_ADD:
17.57 - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.58 - break;
17.59 - default:
17.60 - HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
17.61 - break;
17.62 - }
17.63 - } else if (x1 == x2) {
17.64 - switch (blendMode) {
17.65 - case SDL_BLENDMODE_BLEND:
17.66 - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.67 - break;
17.68 - case SDL_BLENDMODE_ADD:
17.69 - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.70 - break;
17.71 - default:
17.72 - VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
17.73 - break;
17.74 - }
17.75 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.76 - switch (blendMode) {
17.77 - case SDL_BLENDMODE_BLEND:
17.78 - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.79 - break;
17.80 - case SDL_BLENDMODE_ADD:
17.81 - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.82 - break;
17.83 - default:
17.84 - DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
17.85 - break;
17.86 - }
17.87 - } else {
17.88 - switch (blendMode) {
17.89 - case SDL_BLENDMODE_BLEND:
17.90 - AALINE(x1, y1, x2, y2,
17.91 - DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
17.92 - draw_end);
17.93 - break;
17.94 - case SDL_BLENDMODE_ADD:
17.95 - AALINE(x1, y1, x2, y2,
17.96 - DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
17.97 - draw_end);
17.98 - break;
17.99 - default:
17.100 - AALINE(x1, y1, x2, y2,
17.101 - DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
17.102 - draw_end);
17.103 - break;
17.104 - }
17.105 - }
17.106 -}
17.107 -
17.108 -static void
17.109 -SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.110 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.111 - SDL_bool draw_end)
17.112 -{
17.113 - const SDL_PixelFormat *fmt = dst->format;
17.114 - unsigned r, g, b, a, inva;
17.115 -
17.116 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.117 - r = DRAW_MUL(_r, _a);
17.118 - g = DRAW_MUL(_g, _a);
17.119 - b = DRAW_MUL(_b, _a);
17.120 - a = _a;
17.121 - } else {
17.122 - r = _r;
17.123 - g = _g;
17.124 - b = _b;
17.125 - a = _a;
17.126 - }
17.127 - inva = (a ^ 0xff);
17.128 -
17.129 - if (y1 == y2) {
17.130 - switch (blendMode) {
17.131 - case SDL_BLENDMODE_BLEND:
17.132 - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
17.133 - break;
17.134 - case SDL_BLENDMODE_ADD:
17.135 - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
17.136 - break;
17.137 - default:
17.138 - HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
17.139 - break;
17.140 - }
17.141 - } else if (x1 == x2) {
17.142 - switch (blendMode) {
17.143 - case SDL_BLENDMODE_BLEND:
17.144 - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
17.145 - break;
17.146 - case SDL_BLENDMODE_ADD:
17.147 - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
17.148 - break;
17.149 - default:
17.150 - VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
17.151 - break;
17.152 - }
17.153 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.154 - switch (blendMode) {
17.155 - case SDL_BLENDMODE_BLEND:
17.156 - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
17.157 - break;
17.158 - case SDL_BLENDMODE_ADD:
17.159 - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
17.160 - break;
17.161 - default:
17.162 - DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
17.163 - break;
17.164 - }
17.165 - } else {
17.166 - switch (blendMode) {
17.167 - case SDL_BLENDMODE_BLEND:
17.168 - AALINE(x1, y1, x2, y2,
17.169 - DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
17.170 - draw_end);
17.171 - break;
17.172 - case SDL_BLENDMODE_ADD:
17.173 - AALINE(x1, y1, x2, y2,
17.174 - DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
17.175 - draw_end);
17.176 - break;
17.177 - default:
17.178 - AALINE(x1, y1, x2, y2,
17.179 - DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
17.180 - draw_end);
17.181 - break;
17.182 - }
17.183 - }
17.184 -}
17.185 -
17.186 -static void
17.187 -SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.188 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.189 - SDL_bool draw_end)
17.190 -{
17.191 - const SDL_PixelFormat *fmt = dst->format;
17.192 - unsigned r, g, b, a, inva;
17.193 -
17.194 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.195 - r = DRAW_MUL(_r, _a);
17.196 - g = DRAW_MUL(_g, _a);
17.197 - b = DRAW_MUL(_b, _a);
17.198 - a = _a;
17.199 - } else {
17.200 - r = _r;
17.201 - g = _g;
17.202 - b = _b;
17.203 - a = _a;
17.204 - }
17.205 - inva = (a ^ 0xff);
17.206 -
17.207 - if (y1 == y2) {
17.208 - switch (blendMode) {
17.209 - case SDL_BLENDMODE_BLEND:
17.210 - HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
17.211 - break;
17.212 - case SDL_BLENDMODE_ADD:
17.213 - HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
17.214 - break;
17.215 - default:
17.216 - HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
17.217 - break;
17.218 - }
17.219 - } else if (x1 == x2) {
17.220 - switch (blendMode) {
17.221 - case SDL_BLENDMODE_BLEND:
17.222 - VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
17.223 - break;
17.224 - case SDL_BLENDMODE_ADD:
17.225 - VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
17.226 - break;
17.227 - default:
17.228 - VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
17.229 - break;
17.230 - }
17.231 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.232 - switch (blendMode) {
17.233 - case SDL_BLENDMODE_BLEND:
17.234 - DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
17.235 - break;
17.236 - case SDL_BLENDMODE_ADD:
17.237 - DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
17.238 - break;
17.239 - default:
17.240 - DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
17.241 - break;
17.242 - }
17.243 - } else {
17.244 - switch (blendMode) {
17.245 - case SDL_BLENDMODE_BLEND:
17.246 - AALINE(x1, y1, x2, y2,
17.247 - DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
17.248 - draw_end);
17.249 - break;
17.250 - case SDL_BLENDMODE_ADD:
17.251 - AALINE(x1, y1, x2, y2,
17.252 - DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
17.253 - draw_end);
17.254 - break;
17.255 - default:
17.256 - AALINE(x1, y1, x2, y2,
17.257 - DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
17.258 - draw_end);
17.259 - break;
17.260 - }
17.261 - }
17.262 -}
17.263 -
17.264 -static void
17.265 -SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.266 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.267 - SDL_bool draw_end)
17.268 -{
17.269 - const SDL_PixelFormat *fmt = dst->format;
17.270 - unsigned r, g, b, a, inva;
17.271 -
17.272 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.273 - r = DRAW_MUL(_r, _a);
17.274 - g = DRAW_MUL(_g, _a);
17.275 - b = DRAW_MUL(_b, _a);
17.276 - a = _a;
17.277 - } else {
17.278 - r = _r;
17.279 - g = _g;
17.280 - b = _b;
17.281 - a = _a;
17.282 - }
17.283 - inva = (a ^ 0xff);
17.284 -
17.285 - if (y1 == y2) {
17.286 - switch (blendMode) {
17.287 - case SDL_BLENDMODE_BLEND:
17.288 - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.289 - break;
17.290 - case SDL_BLENDMODE_ADD:
17.291 - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.292 - break;
17.293 - default:
17.294 - HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
17.295 - break;
17.296 - }
17.297 - } else if (x1 == x2) {
17.298 - switch (blendMode) {
17.299 - case SDL_BLENDMODE_BLEND:
17.300 - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.301 - break;
17.302 - case SDL_BLENDMODE_ADD:
17.303 - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.304 - break;
17.305 - default:
17.306 - VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
17.307 - break;
17.308 - }
17.309 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.310 - switch (blendMode) {
17.311 - case SDL_BLENDMODE_BLEND:
17.312 - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
17.313 - break;
17.314 - case SDL_BLENDMODE_ADD:
17.315 - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
17.316 - break;
17.317 - default:
17.318 - DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
17.319 - break;
17.320 - }
17.321 - } else {
17.322 - switch (blendMode) {
17.323 - case SDL_BLENDMODE_BLEND:
17.324 - AALINE(x1, y1, x2, y2,
17.325 - DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
17.326 - draw_end);
17.327 - break;
17.328 - case SDL_BLENDMODE_ADD:
17.329 - AALINE(x1, y1, x2, y2,
17.330 - DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
17.331 - draw_end);
17.332 - break;
17.333 - default:
17.334 - AALINE(x1, y1, x2, y2,
17.335 - DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
17.336 - draw_end);
17.337 - break;
17.338 - }
17.339 - }
17.340 -}
17.341 -
17.342 -static void
17.343 -SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.344 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.345 - SDL_bool draw_end)
17.346 -{
17.347 - const SDL_PixelFormat *fmt = dst->format;
17.348 - unsigned r, g, b, a, inva;
17.349 -
17.350 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.351 - r = DRAW_MUL(_r, _a);
17.352 - g = DRAW_MUL(_g, _a);
17.353 - b = DRAW_MUL(_b, _a);
17.354 - a = _a;
17.355 - } else {
17.356 - r = _r;
17.357 - g = _g;
17.358 - b = _b;
17.359 - a = _a;
17.360 - }
17.361 - inva = (a ^ 0xff);
17.362 -
17.363 - if (y1 == y2) {
17.364 - switch (blendMode) {
17.365 - case SDL_BLENDMODE_BLEND:
17.366 - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
17.367 - break;
17.368 - case SDL_BLENDMODE_ADD:
17.369 - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
17.370 - break;
17.371 - default:
17.372 - HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
17.373 - break;
17.374 - }
17.375 - } else if (x1 == x2) {
17.376 - switch (blendMode) {
17.377 - case SDL_BLENDMODE_BLEND:
17.378 - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
17.379 - break;
17.380 - case SDL_BLENDMODE_ADD:
17.381 - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
17.382 - break;
17.383 - default:
17.384 - VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
17.385 - break;
17.386 - }
17.387 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.388 - switch (blendMode) {
17.389 - case SDL_BLENDMODE_BLEND:
17.390 - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
17.391 - break;
17.392 - case SDL_BLENDMODE_ADD:
17.393 - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
17.394 - break;
17.395 - default:
17.396 - DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
17.397 - break;
17.398 - }
17.399 - } else {
17.400 - switch (blendMode) {
17.401 - case SDL_BLENDMODE_BLEND:
17.402 - AALINE(x1, y1, x2, y2,
17.403 - DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
17.404 - draw_end);
17.405 - break;
17.406 - case SDL_BLENDMODE_ADD:
17.407 - AALINE(x1, y1, x2, y2,
17.408 - DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
17.409 - draw_end);
17.410 - break;
17.411 - default:
17.412 - AALINE(x1, y1, x2, y2,
17.413 - DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
17.414 - draw_end);
17.415 - break;
17.416 - }
17.417 - }
17.418 -}
17.419 -
17.420 -static void
17.421 -SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.422 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.423 - SDL_bool draw_end)
17.424 -{
17.425 - const SDL_PixelFormat *fmt = dst->format;
17.426 - unsigned r, g, b, a, inva;
17.427 -
17.428 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.429 - r = DRAW_MUL(_r, _a);
17.430 - g = DRAW_MUL(_g, _a);
17.431 - b = DRAW_MUL(_b, _a);
17.432 - a = _a;
17.433 - } else {
17.434 - r = _r;
17.435 - g = _g;
17.436 - b = _b;
17.437 - a = _a;
17.438 - }
17.439 - inva = (a ^ 0xff);
17.440 -
17.441 - if (y1 == y2) {
17.442 - switch (blendMode) {
17.443 - case SDL_BLENDMODE_BLEND:
17.444 - HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
17.445 - break;
17.446 - case SDL_BLENDMODE_ADD:
17.447 - HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
17.448 - break;
17.449 - default:
17.450 - HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
17.451 - break;
17.452 - }
17.453 - } else if (x1 == x2) {
17.454 - switch (blendMode) {
17.455 - case SDL_BLENDMODE_BLEND:
17.456 - VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
17.457 - break;
17.458 - case SDL_BLENDMODE_ADD:
17.459 - VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
17.460 - break;
17.461 - default:
17.462 - VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
17.463 - break;
17.464 - }
17.465 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.466 - switch (blendMode) {
17.467 - case SDL_BLENDMODE_BLEND:
17.468 - DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
17.469 - break;
17.470 - case SDL_BLENDMODE_ADD:
17.471 - DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
17.472 - break;
17.473 - default:
17.474 - DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
17.475 - break;
17.476 - }
17.477 - } else {
17.478 - switch (blendMode) {
17.479 - case SDL_BLENDMODE_BLEND:
17.480 - AALINE(x1, y1, x2, y2,
17.481 - DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
17.482 - draw_end);
17.483 - break;
17.484 - case SDL_BLENDMODE_ADD:
17.485 - AALINE(x1, y1, x2, y2,
17.486 - DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
17.487 - draw_end);
17.488 - break;
17.489 - default:
17.490 - AALINE(x1, y1, x2, y2,
17.491 - DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
17.492 - draw_end);
17.493 - break;
17.494 - }
17.495 - }
17.496 -}
17.497 -
17.498 -static void
17.499 -SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.500 - SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
17.501 - SDL_bool draw_end)
17.502 -{
17.503 - const SDL_PixelFormat *fmt = dst->format;
17.504 - unsigned r, g, b, a, inva;
17.505 -
17.506 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
17.507 - r = DRAW_MUL(_r, _a);
17.508 - g = DRAW_MUL(_g, _a);
17.509 - b = DRAW_MUL(_b, _a);
17.510 - a = _a;
17.511 - } else {
17.512 - r = _r;
17.513 - g = _g;
17.514 - b = _b;
17.515 - a = _a;
17.516 - }
17.517 - inva = (a ^ 0xff);
17.518 -
17.519 - if (y1 == y2) {
17.520 - switch (blendMode) {
17.521 - case SDL_BLENDMODE_BLEND:
17.522 - HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
17.523 - break;
17.524 - case SDL_BLENDMODE_ADD:
17.525 - HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
17.526 - break;
17.527 - default:
17.528 - HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
17.529 - break;
17.530 - }
17.531 - } else if (x1 == x2) {
17.532 - switch (blendMode) {
17.533 - case SDL_BLENDMODE_BLEND:
17.534 - VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
17.535 - break;
17.536 - case SDL_BLENDMODE_ADD:
17.537 - VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
17.538 - break;
17.539 - default:
17.540 - VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
17.541 - break;
17.542 - }
17.543 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
17.544 - switch (blendMode) {
17.545 - case SDL_BLENDMODE_BLEND:
17.546 - DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
17.547 - break;
17.548 - case SDL_BLENDMODE_ADD:
17.549 - DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
17.550 - break;
17.551 - default:
17.552 - DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
17.553 - break;
17.554 - }
17.555 - } else {
17.556 - switch (blendMode) {
17.557 - case SDL_BLENDMODE_BLEND:
17.558 - AALINE(x1, y1, x2, y2,
17.559 - DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
17.560 - draw_end);
17.561 - break;
17.562 - case SDL_BLENDMODE_ADD:
17.563 - AALINE(x1, y1, x2, y2,
17.564 - DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
17.565 - draw_end);
17.566 - break;
17.567 - default:
17.568 - AALINE(x1, y1, x2, y2,
17.569 - DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
17.570 - draw_end);
17.571 - break;
17.572 - }
17.573 - }
17.574 -}
17.575 -
17.576 -typedef void (*BlendLineFunc) (SDL_Surface * dst,
17.577 - int x1, int y1, int x2, int y2,
17.578 - SDL_BlendMode blendMode,
17.579 - Uint8 r, Uint8 g, Uint8 b, Uint8 a,
17.580 - SDL_bool draw_end);
17.581 -
17.582 -static BlendLineFunc
17.583 -SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
17.584 -{
17.585 - switch (fmt->BytesPerPixel) {
17.586 - case 2:
17.587 - if (fmt->Rmask == 0x7C00) {
17.588 - return SDL_BlendLine_RGB555;
17.589 - } else if (fmt->Rmask == 0xF800) {
17.590 - return SDL_BlendLine_RGB565;
17.591 - } else {
17.592 - return SDL_BlendLine_RGB2;
17.593 - }
17.594 - break;
17.595 - case 4:
17.596 - if (fmt->Rmask == 0x00FF0000) {
17.597 - if (fmt->Amask) {
17.598 - return SDL_BlendLine_ARGB8888;
17.599 - } else {
17.600 - return SDL_BlendLine_RGB888;
17.601 - }
17.602 - } else {
17.603 - if (fmt->Amask) {
17.604 - return SDL_BlendLine_RGBA4;
17.605 - } else {
17.606 - return SDL_BlendLine_RGB4;
17.607 - }
17.608 - }
17.609 - }
17.610 - return NULL;
17.611 -}
17.612 -
17.613 -int
17.614 -SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
17.615 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
17.616 -{
17.617 - BlendLineFunc func;
17.618 -
17.619 - if (!dst) {
17.620 - SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
17.621 - return -1;
17.622 - }
17.623 -
17.624 - func = SDL_CalculateBlendLineFunc(dst->format);
17.625 - if (!func) {
17.626 - SDL_SetError("SDL_BlendLine(): Unsupported surface format");
17.627 - return -1;
17.628 - }
17.629 -
17.630 - /* Perform clipping */
17.631 - /* FIXME: We don't actually want to clip, as it may change line slope */
17.632 - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
17.633 - return 0;
17.634 - }
17.635 -
17.636 - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
17.637 - return 0;
17.638 -}
17.639 -
17.640 -int
17.641 -SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
17.642 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
17.643 -{
17.644 - int i;
17.645 - int x1, y1;
17.646 - int x2, y2;
17.647 - SDL_bool draw_end;
17.648 - BlendLineFunc func;
17.649 -
17.650 - if (!dst) {
17.651 - SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
17.652 - return -1;
17.653 - }
17.654 -
17.655 - func = SDL_CalculateBlendLineFunc(dst->format);
17.656 - if (!func) {
17.657 - SDL_SetError("SDL_BlendLines(): Unsupported surface format");
17.658 - return -1;
17.659 - }
17.660 -
17.661 - for (i = 1; i < count; ++i) {
17.662 - x1 = points[i-1].x;
17.663 - y1 = points[i-1].y;
17.664 - x2 = points[i].x;
17.665 - y2 = points[i].y;
17.666 -
17.667 - /* Perform clipping */
17.668 - /* FIXME: We don't actually want to clip, as it may change line slope */
17.669 - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
17.670 - continue;
17.671 - }
17.672 -
17.673 - /* Draw the end if it was clipped */
17.674 - draw_end = (x2 != points[i].x || y2 != points[i].y);
17.675 -
17.676 - func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
17.677 - }
17.678 - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
17.679 - SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
17.680 - blendMode, r, g, b, a);
17.681 - }
17.682 - return 0;
17.683 -}
17.684 -
17.685 -/* vi: set ts=4 sw=4 expandtab: */
18.1 --- a/src/video/SDL_blendpoint.c Thu Feb 03 02:42:50 2011 -0800
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,323 +0,0 @@
18.4 -/*
18.5 - SDL - Simple DirectMedia Layer
18.6 - Copyright (C) 1997-2010 Sam Lantinga
18.7 -
18.8 - This library is free software; you can redistribute it and/or
18.9 - modify it under the terms of the GNU Lesser General Public
18.10 - License as published by the Free Software Foundation; either
18.11 - version 2.1 of the License, or (at your option) any later version.
18.12 -
18.13 - This library is distributed in the hope that it will be useful,
18.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
18.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18.16 - Lesser General Public License for more details.
18.17 -
18.18 - You should have received a copy of the GNU Lesser General Public
18.19 - License along with this library; if not, write to the Free Software
18.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18.21 -
18.22 - Sam Lantinga
18.23 - slouken@libsdl.org
18.24 -*/
18.25 -#include "SDL_config.h"
18.26 -
18.27 -#include "SDL_draw.h"
18.28 -
18.29 -static int
18.30 -SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.31 - Uint8 g, Uint8 b, Uint8 a)
18.32 -{
18.33 - unsigned inva = 0xff - a;
18.34 -
18.35 - switch (blendMode) {
18.36 - case SDL_BLENDMODE_BLEND:
18.37 - DRAW_SETPIXELXY_BLEND_RGB555(x, y);
18.38 - break;
18.39 - case SDL_BLENDMODE_ADD:
18.40 - DRAW_SETPIXELXY_ADD_RGB555(x, y);
18.41 - break;
18.42 - default:
18.43 - DRAW_SETPIXELXY_RGB555(x, y);
18.44 - break;
18.45 - }
18.46 - return 0;
18.47 -}
18.48 -
18.49 -static int
18.50 -SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.51 - Uint8 g, Uint8 b, Uint8 a)
18.52 -{
18.53 - unsigned inva = 0xff - a;
18.54 -
18.55 - switch (blendMode) {
18.56 - case SDL_BLENDMODE_BLEND:
18.57 - DRAW_SETPIXELXY_BLEND_RGB565(x, y);
18.58 - break;
18.59 - case SDL_BLENDMODE_ADD:
18.60 - DRAW_SETPIXELXY_ADD_RGB565(x, y);
18.61 - break;
18.62 - default:
18.63 - DRAW_SETPIXELXY_RGB565(x, y);
18.64 - break;
18.65 - }
18.66 - return 0;
18.67 -}
18.68 -
18.69 -static int
18.70 -SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.71 - Uint8 g, Uint8 b, Uint8 a)
18.72 -{
18.73 - unsigned inva = 0xff - a;
18.74 -
18.75 - switch (blendMode) {
18.76 - case SDL_BLENDMODE_BLEND:
18.77 - DRAW_SETPIXELXY_BLEND_RGB888(x, y);
18.78 - break;
18.79 - case SDL_BLENDMODE_ADD:
18.80 - DRAW_SETPIXELXY_ADD_RGB888(x, y);
18.81 - break;
18.82 - default:
18.83 - DRAW_SETPIXELXY_RGB888(x, y);
18.84 - break;
18.85 - }
18.86 - return 0;
18.87 -}
18.88 -
18.89 -static int
18.90 -SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
18.91 - Uint8 r, Uint8 g, Uint8 b, Uint8 a)
18.92 -{
18.93 - unsigned inva = 0xff - a;
18.94 -
18.95 - switch (blendMode) {
18.96 - case SDL_BLENDMODE_BLEND:
18.97 - DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
18.98 - break;
18.99 - case SDL_BLENDMODE_ADD:
18.100 - DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
18.101 - break;
18.102 - default:
18.103 - DRAW_SETPIXELXY_ARGB8888(x, y);
18.104 - break;
18.105 - }
18.106 - return 0;
18.107 -}
18.108 -
18.109 -static int
18.110 -SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.111 - Uint8 g, Uint8 b, Uint8 a)
18.112 -{
18.113 - SDL_PixelFormat *fmt = dst->format;
18.114 - unsigned inva = 0xff - a;
18.115 -
18.116 - switch (fmt->BytesPerPixel) {
18.117 - case 2:
18.118 - switch (blendMode) {
18.119 - case SDL_BLENDMODE_BLEND:
18.120 - DRAW_SETPIXELXY2_BLEND_RGB(x, y);
18.121 - break;
18.122 - case SDL_BLENDMODE_ADD:
18.123 - DRAW_SETPIXELXY2_ADD_RGB(x, y);
18.124 - break;
18.125 - default:
18.126 - DRAW_SETPIXELXY2_RGB(x, y);
18.127 - break;
18.128 - }
18.129 - return 0;
18.130 - case 4:
18.131 - switch (blendMode) {
18.132 - case SDL_BLENDMODE_BLEND:
18.133 - DRAW_SETPIXELXY4_BLEND_RGB(x, y);
18.134 - break;
18.135 - case SDL_BLENDMODE_ADD:
18.136 - DRAW_SETPIXELXY4_ADD_RGB(x, y);
18.137 - break;
18.138 - default:
18.139 - DRAW_SETPIXELXY4_RGB(x, y);
18.140 - break;
18.141 - }
18.142 - return 0;
18.143 - default:
18.144 - SDL_Unsupported();
18.145 - return -1;
18.146 - }
18.147 -}
18.148 -
18.149 -static int
18.150 -SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.151 - Uint8 g, Uint8 b, Uint8 a)
18.152 -{
18.153 - SDL_PixelFormat *fmt = dst->format;
18.154 - unsigned inva = 0xff - a;
18.155 -
18.156 - switch (fmt->BytesPerPixel) {
18.157 - case 4:
18.158 - switch (blendMode) {
18.159 - case SDL_BLENDMODE_BLEND:
18.160 - DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
18.161 - break;
18.162 - case SDL_BLENDMODE_ADD:
18.163 - DRAW_SETPIXELXY4_ADD_RGBA(x, y);
18.164 - break;
18.165 - default:
18.166 - DRAW_SETPIXELXY4_RGBA(x, y);
18.167 - break;
18.168 - }
18.169 - return 0;
18.170 - default:
18.171 - SDL_Unsupported();
18.172 - return -1;
18.173 - }
18.174 -}
18.175 -
18.176 -int
18.177 -SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
18.178 - Uint8 g, Uint8 b, Uint8 a)
18.179 -{
18.180 - if (!dst) {
18.181 - SDL_SetError("Passed NULL destination surface");
18.182 - return -1;
18.183 - }
18.184 -
18.185 - /* This function doesn't work on surfaces < 8 bpp */
18.186 - if (dst->format->BitsPerPixel < 8) {
18.187 - SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
18.188 - return -1;
18.189 - }
18.190 -
18.191 - /* Perform clipping */
18.192 - if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
18.193 - x >= (dst->clip_rect.x + dst->clip_rect.w) ||
18.194 - y >= (dst->clip_rect.y + dst->clip_rect.h)) {
18.195 - return 0;
18.196 - }
18.197 -
18.198 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
18.199 - r = DRAW_MUL(r, a);
18.200 - g = DRAW_MUL(g, a);
18.201 - b = DRAW_MUL(b, a);
18.202 - }
18.203 -
18.204 - switch (dst->format->BitsPerPixel) {
18.205 - case 15:
18.206 - switch (dst->format->Rmask) {
18.207 - case 0x7C00:
18.208 - return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
18.209 - }
18.210 - break;
18.211 - case 16:
18.212 - switch (dst->format->Rmask) {
18.213 - case 0xF800:
18.214 - return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
18.215 - }
18.216 - break;
18.217 - case 32:
18.218 - switch (dst->format->Rmask) {
18.219 - case 0x00FF0000:
18.220 - if (!dst->format->Amask) {
18.221 - return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b,
18.222 - a);
18.223 - } else {
18.224 - return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b,
18.225 - a);
18.226 - }
18.227 - break;
18.228 - }
18.229 - break;
18.230 - default:
18.231 - break;
18.232 - }
18.233 -
18.234 - if (!dst->format->Amask) {
18.235 - return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
18.236 - } else {
18.237 - return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
18.238 - }
18.239 -}
18.240 -
18.241 -int
18.242 -SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
18.243 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
18.244 -{
18.245 - int minx, miny;
18.246 - int maxx, maxy;
18.247 - int i;
18.248 - int x, y;
18.249 - int (*func)(SDL_Surface * dst, int x, int y,
18.250 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
18.251 - int status = 0;
18.252 -
18.253 - if (!dst) {
18.254 - SDL_SetError("Passed NULL destination surface");
18.255 - return -1;
18.256 - }
18.257 -
18.258 - /* This function doesn't work on surfaces < 8 bpp */
18.259 - if (dst->format->BitsPerPixel < 8) {
18.260 - SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
18.261 - return (-1);
18.262 - }
18.263 -
18.264 - if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
18.265 - r = DRAW_MUL(r, a);
18.266 - g = DRAW_MUL(g, a);
18.267 - b = DRAW_MUL(b, a);
18.268 - }
18.269 -
18.270 - /* FIXME: Does this function pointer slow things down significantly? */
18.271 - switch (dst->format->BitsPerPixel) {
18.272 - case 15:
18.273 - switch (dst->format->Rmask) {
18.274 - case 0x7C00:
18.275 - func = SDL_BlendPoint_RGB555;
18.276 - break;
18.277 - }
18.278 - break;
18.279 - case 16:
18.280 - switch (dst->format->Rmask) {
18.281 - case 0xF800:
18.282 - func = SDL_BlendPoint_RGB565;
18.283 - break;
18.284 - }
18.285 - break;
18.286 - case 32:
18.287 - switch (dst->format->Rmask) {
18.288 - case 0x00FF0000:
18.289 - if (!dst->format->Amask) {
18.290 - func = SDL_BlendPoint_RGB888;
18.291 - } else {
18.292 - func = SDL_BlendPoint_ARGB8888;
18.293 - }
18.294 - break;
18.295 - }
18.296 - break;
18.297 - default:
18.298 - break;
18.299 - }
18.300 -
18.301 - if (!func) {
18.302 - if (!dst->format->Amask) {
18.303 - func = SDL_BlendPoint_RGB;
18.304 - } else {
18.305 - func = SDL_BlendPoint_RGBA;
18.306 - }
18.307 - }
18.308 -
18.309 - minx = dst->clip_rect.x;
18.310 - maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
18.311 - miny = dst->clip_rect.y;
18.312 - maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
18.313 -
18.314 - for (i = 0; i < count; ++i) {
18.315 - x = points[i].x;
18.316 - y = points[i].y;
18.317 -
18.318 - if (x < minx || x > maxx || y < miny || y > maxy) {
18.319 - continue;
18.320 - }
18.321 - status = func(dst, x, y, blendMode, r, g, b, a);
18.322 - }
18.323 - return status;
18.324 -}
18.325 -
18.326 -/* vi: set ts=4 sw=4 expandtab: */
19.1 --- a/src/video/SDL_blendrect.c Thu Feb 03 02:42:50 2011 -0800
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,75 +0,0 @@
19.4 -/*
19.5 - SDL - Simple DirectMedia Layer
19.6 - Copyright (C) 1997-2010 Sam Lantinga
19.7 -
19.8 - This library is free software; you can redistribute it and/or
19.9 - modify it under the terms of the GNU Lesser General Public
19.10 - License as published by the Free Software Foundation; either
19.11 - version 2.1 of the License, or (at your option) any later version.
19.12 -
19.13 - This library is distributed in the hope that it will be useful,
19.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
19.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19.16 - Lesser General Public License for more details.
19.17 -
19.18 - You should have received a copy of the GNU Lesser General Public
19.19 - License along with this library; if not, write to the Free Software
19.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19.21 -
19.22 - Sam Lantinga
19.23 - slouken@libsdl.org
19.24 -*/
19.25 -#include "SDL_config.h"
19.26 -
19.27 -#include "SDL_video.h"
19.28 -
19.29 -
19.30 -int
19.31 -SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect,
19.32 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
19.33 -{
19.34 - SDL_Rect full_rect;
19.35 - SDL_Point points[5];
19.36 -
19.37 - if (!dst) {
19.38 - SDL_SetError("Passed NULL destination surface");
19.39 - return -1;
19.40 - }
19.41 -
19.42 - /* If 'rect' == NULL, then outline the whole surface */
19.43 - if (!rect) {
19.44 - full_rect.x = 0;
19.45 - full_rect.y = 0;
19.46 - full_rect.w = dst->w;
19.47 - full_rect.h = dst->h;
19.48 - rect = &full_rect;
19.49 - }
19.50 -
19.51 - points[0].x = rect->x;
19.52 - points[0].y = rect->y;
19.53 - points[1].x = rect->x+rect->w-1;
19.54 - points[1].y = rect->y;
19.55 - points[2].x = rect->x+rect->w-1;
19.56 - points[2].y = rect->y+rect->h-1;
19.57 - points[3].x = rect->x;
19.58 - points[3].y = rect->y+rect->h-1;
19.59 - points[4].x = rect->x;
19.60 - points[4].y = rect->y;
19.61 - return SDL_BlendLines(dst, points, 5, blendMode, r, g, b, a);
19.62 -}
19.63 -
19.64 -int
19.65 -SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
19.66 - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
19.67 -{
19.68 - int i;
19.69 -
19.70 - for (i = 0; i < count; ++i) {
19.71 - if (SDL_BlendRect(dst, rects[i], blendMode, r, g, b, a) < 0) {
19.72 - return -1;
19.73 - }
19.74 - }
19.75 - return 0;
19.76 -}
19.77 -
19.78 -/* vi: set ts=4 sw=4 expandtab: */
20.1 --- a/src/video/SDL_blit.h Thu Feb 03 02:42:50 2011 -0800
20.2 +++ b/src/video/SDL_blit.h Thu Feb 03 02:45:29 2011 -0800
20.3 @@ -47,7 +47,7 @@
20.4
20.5 #include "SDL_cpuinfo.h"
20.6 #include "SDL_endian.h"
20.7 -#include "SDL_video.h"
20.8 +#include "SDL_surface.h"
20.9
20.10 /* SDL blit copy flags */
20.11 #define SDL_COPY_MODULATE_COLOR 0x00000001
21.1 --- a/src/video/SDL_draw.h Thu Feb 03 02:42:50 2011 -0800
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,521 +0,0 @@
21.4 -/*
21.5 - SDL - Simple DirectMedia Layer
21.6 - Copyright (C) 1997-2010 Sam Lantinga
21.7 -
21.8 - This library is free software; you can redistribute it and/or
21.9 - modify it under the terms of the GNU Lesser General Public
21.10 - License as published by the Free Software Foundation; either
21.11 - version 2.1 of the License, or (at your option) any later version.
21.12 -
21.13 - This library is distributed in the hope that it will be useful,
21.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
21.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21.16 - Lesser General Public License for more details.
21.17 -
21.18 - You should have received a copy of the GNU Lesser General Public
21.19 - License along with this library; if not, write to the Free Software
21.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21.21 -
21.22 - Sam Lantinga
21.23 - slouken@libsdl.org
21.24 -*/
21.25 -#include "SDL_config.h"
21.26 -
21.27 -#include "SDL_blit.h"
21.28 -
21.29 -/* This code assumes that r, g, b, a are the source color,
21.30 - * and in the blend and add case, the RGB values are premultiplied by a.
21.31 - */
21.32 -
21.33 -#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
21.34 -
21.35 -#define DRAW_FASTSETPIXEL(type) \
21.36 - *pixel = (type) color
21.37 -
21.38 -#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
21.39 -#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
21.40 -#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
21.41 -
21.42 -#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
21.43 - *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
21.44 - + (x) * bpp) = (type) color
21.45 -
21.46 -#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
21.47 -#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
21.48 -#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
21.49 -
21.50 -#define DRAW_SETPIXEL(setpixel) \
21.51 -do { \
21.52 - unsigned sr = r, sg = g, sb = b, sa = a; \
21.53 - setpixel; \
21.54 -} while (0)
21.55 -
21.56 -#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
21.57 -do { \
21.58 - unsigned sr, sg, sb, sa; sa; \
21.59 - getpixel; \
21.60 - sr = DRAW_MUL(inva, sr) + r; \
21.61 - sg = DRAW_MUL(inva, sg) + g; \
21.62 - sb = DRAW_MUL(inva, sb) + b; \
21.63 - setpixel; \
21.64 -} while (0)
21.65 -
21.66 -#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
21.67 -do { \
21.68 - unsigned sr, sg, sb, sa; sa; \
21.69 - getpixel; \
21.70 - sr += r; if (sr > 0xff) sr = 0xff; \
21.71 - sg += g; if (sg > 0xff) sg = 0xff; \
21.72 - sb += b; if (sb > 0xff) sb = 0xff; \
21.73 - setpixel; \
21.74 -} while (0)
21.75 -
21.76 -#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
21.77 -do { \
21.78 - type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
21.79 - + (x) * bpp); \
21.80 - op; \
21.81 -} while (0)
21.82 -
21.83 -/*
21.84 - * Define draw operators for RGB555
21.85 - */
21.86 -
21.87 -#define DRAW_SETPIXEL_RGB555 \
21.88 - DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
21.89 -
21.90 -#define DRAW_SETPIXEL_BLEND_RGB555 \
21.91 - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
21.92 - RGB555_FROM_RGB(*pixel, sr, sg, sb))
21.93 -
21.94 -#define DRAW_SETPIXEL_ADD_RGB555 \
21.95 - DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
21.96 - RGB555_FROM_RGB(*pixel, sr, sg, sb))
21.97 -
21.98 -#define DRAW_SETPIXELXY_RGB555(x, y) \
21.99 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
21.100 -
21.101 -#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
21.102 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
21.103 -
21.104 -#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
21.105 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
21.106 -
21.107 -/*
21.108 - * Define draw operators for RGB565
21.109 - */
21.110 -
21.111 -#define DRAW_SETPIXEL_RGB565 \
21.112 - DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
21.113 -
21.114 -#define DRAW_SETPIXEL_BLEND_RGB565 \
21.115 - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
21.116 - RGB565_FROM_RGB(*pixel, sr, sg, sb))
21.117 -
21.118 -#define DRAW_SETPIXEL_ADD_RGB565 \
21.119 - DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
21.120 - RGB565_FROM_RGB(*pixel, sr, sg, sb))
21.121 -
21.122 -#define DRAW_SETPIXELXY_RGB565(x, y) \
21.123 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
21.124 -
21.125 -#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
21.126 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
21.127 -
21.128 -#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
21.129 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
21.130 -
21.131 -/*
21.132 - * Define draw operators for RGB888
21.133 - */
21.134 -
21.135 -#define DRAW_SETPIXEL_RGB888 \
21.136 - DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
21.137 -
21.138 -#define DRAW_SETPIXEL_BLEND_RGB888 \
21.139 - DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
21.140 - RGB888_FROM_RGB(*pixel, sr, sg, sb))
21.141 -
21.142 -#define DRAW_SETPIXEL_ADD_RGB888 \
21.143 - DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
21.144 - RGB888_FROM_RGB(*pixel, sr, sg, sb))
21.145 -
21.146 -#define DRAW_SETPIXELXY_RGB888(x, y) \
21.147 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
21.148 -
21.149 -#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
21.150 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
21.151 -
21.152 -#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
21.153 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
21.154 -
21.155 -/*
21.156 - * Define draw operators for ARGB8888
21.157 - */
21.158 -
21.159 -#define DRAW_SETPIXEL_ARGB8888 \
21.160 - DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
21.161 -
21.162 -#define DRAW_SETPIXEL_BLEND_ARGB8888 \
21.163 - DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
21.164 - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
21.165 -
21.166 -#define DRAW_SETPIXEL_ADD_ARGB8888 \
21.167 - DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
21.168 - ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
21.169 -
21.170 -#define DRAW_SETPIXELXY_ARGB8888(x, y) \
21.171 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
21.172 -
21.173 -#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
21.174 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
21.175 -
21.176 -#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
21.177 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
21.178 -
21.179 -/*
21.180 - * Define draw operators for general RGB
21.181 - */
21.182 -
21.183 -#define DRAW_SETPIXEL_RGB \
21.184 - DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
21.185 -
21.186 -#define DRAW_SETPIXEL_BLEND_RGB \
21.187 - DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
21.188 - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
21.189 -
21.190 -#define DRAW_SETPIXEL_ADD_RGB \
21.191 - DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
21.192 - PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
21.193 -
21.194 -#define DRAW_SETPIXELXY2_RGB(x, y) \
21.195 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
21.196 -
21.197 -#define DRAW_SETPIXELXY4_RGB(x, y) \
21.198 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
21.199 -
21.200 -#define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
21.201 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
21.202 -
21.203 -#define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
21.204 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
21.205 -
21.206 -#define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
21.207 - DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
21.208 -
21.209 -#define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
21.210 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
21.211 -
21.212 -
21.213 -/*
21.214 - * Define draw operators for general RGBA
21.215 - */
21.216 -
21.217 -#define DRAW_SETPIXEL_RGBA \
21.218 - DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
21.219 -
21.220 -#define DRAW_SETPIXEL_BLEND_RGBA \
21.221 - DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
21.222 - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
21.223 -
21.224 -#define DRAW_SETPIXEL_ADD_RGBA \
21.225 - DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
21.226 - PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
21.227 -
21.228 -#define DRAW_SETPIXELXY4_RGBA(x, y) \
21.229 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
21.230 -
21.231 -#define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
21.232 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
21.233 -
21.234 -#define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
21.235 - DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
21.236 -
21.237 -/*
21.238 - * Define line drawing macro
21.239 - */
21.240 -
21.241 -#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
21.242 -
21.243 -/* Horizontal line */
21.244 -#define HLINE(type, op, draw_end) \
21.245 -{ \
21.246 - int length; \
21.247 - int pitch = (dst->pitch / dst->format->BytesPerPixel); \
21.248 - type *pixel; \
21.249 - if (x1 <= x2) { \
21.250 - pixel = (type *)dst->pixels + y1 * pitch + x1; \
21.251 - length = draw_end ? (x2-x1+1) : (x2-x1); \
21.252 - } else { \
21.253 - pixel = (type *)dst->pixels + y1 * pitch + x2; \
21.254 - if (!draw_end) { \
21.255 - ++pixel; \
21.256 - } \
21.257 - length = draw_end ? (x1-x2+1) : (x1-x2); \
21.258 - } \
21.259 - while (length--) { \
21.260 - op; \
21.261 - ++pixel; \
21.262 - } \
21.263 -}
21.264 -
21.265 -/* Vertical line */
21.266 -#define VLINE(type, op, draw_end) \
21.267 -{ \
21.268 - int length; \
21.269 - int pitch = (dst->pitch / dst->format->BytesPerPixel); \
21.270 - type *pixel; \
21.271 - if (y1 <= y2) { \
21.272 - pixel = (type *)dst->pixels + y1 * pitch + x1; \
21.273 - length = draw_end ? (y2-y1+1) : (y2-y1); \
21.274 - } else { \
21.275 - pixel = (type *)dst->pixels + y2 * pitch + x1; \
21.276 - if (!draw_end) { \
21.277 - pixel += pitch; \
21.278 - } \
21.279 - length = draw_end ? (y1-y2+1) : (y1-y2); \
21.280 - } \
21.281 - while (length--) { \
21.282 - op; \
21.283 - pixel += pitch; \
21.284 - } \
21.285 -}
21.286 -
21.287 -/* Diagonal line */
21.288 -#define DLINE(type, op, draw_end) \
21.289 -{ \
21.290 - int length; \
21.291 - int pitch = (dst->pitch / dst->format->BytesPerPixel); \
21.292 - type *pixel; \
21.293 - if (y1 <= y2) { \
21.294 - pixel = (type *)dst->pixels + y1 * pitch + x1; \
21.295 - if (x1 <= x2) { \
21.296 - ++pitch; \
21.297 - } else { \
21.298 - --pitch; \
21.299 - } \
21.300 - length = (y2-y1); \
21.301 - } else { \
21.302 - pixel = (type *)dst->pixels + y2 * pitch + x2; \
21.303 - if (x2 <= x1) { \
21.304 - ++pitch; \
21.305 - } else { \
21.306 - --pitch; \
21.307 - } \
21.308 - if (!draw_end) { \
21.309 - pixel += pitch; \
21.310 - } \
21.311 - length = (y1-y2); \
21.312 - } \
21.313 - if (draw_end) { \
21.314 - ++length; \
21.315 - } \
21.316 - while (length--) { \
21.317 - op; \
21.318 - pixel += pitch; \
21.319 - } \
21.320 -}
21.321 -
21.322 -/* Bresenham's line algorithm */
21.323 -#define BLINE(x1, y1, x2, y2, op, draw_end) \
21.324 -{ \
21.325 - int i, deltax, deltay, numpixels; \
21.326 - int d, dinc1, dinc2; \
21.327 - int x, xinc1, xinc2; \
21.328 - int y, yinc1, yinc2; \
21.329 - \
21.330 - deltax = ABS(x2 - x1); \
21.331 - deltay = ABS(y2 - y1); \
21.332 - \
21.333 - if (deltax >= deltay) { \
21.334 - numpixels = deltax + 1; \
21.335 - d = (2 * deltay) - deltax; \
21.336 - dinc1 = deltay * 2; \
21.337 - dinc2 = (deltay - deltax) * 2; \
21.338 - xinc1 = 1; \
21.339 - xinc2 = 1; \
21.340 - yinc1 = 0; \
21.341 - yinc2 = 1; \
21.342 - } else { \
21.343 - numpixels = deltay + 1; \
21.344 - d = (2 * deltax) - deltay; \
21.345 - dinc1 = deltax * 2; \
21.346 - dinc2 = (deltax - deltay) * 2; \
21.347 - xinc1 = 0; \
21.348 - xinc2 = 1; \
21.349 - yinc1 = 1; \
21.350 - yinc2 = 1; \
21.351 - } \
21.352 - \
21.353 - if (x1 > x2) { \
21.354 - xinc1 = -xinc1; \
21.355 - xinc2 = -xinc2; \
21.356 - } \
21.357 - if (y1 > y2) { \
21.358 - yinc1 = -yinc1; \
21.359 - yinc2 = -yinc2; \
21.360 - } \
21.361 - \
21.362 - x = x1; \
21.363 - y = y1; \
21.364 - \
21.365 - if (!draw_end) { \
21.366 - --numpixels; \
21.367 - } \
21.368 - for (i = 0; i < numpixels; ++i) { \
21.369 - op(x, y); \
21.370 - if (d < 0) { \
21.371 - d += dinc1; \
21.372 - x += xinc1; \
21.373 - y += yinc1; \
21.374 - } else { \
21.375 - d += dinc2; \
21.376 - x += xinc2; \
21.377 - y += yinc2; \
21.378 - } \
21.379 - } \
21.380 -}
21.381 -
21.382 -/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
21.383 -#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
21.384 -{ \
21.385 - Uint16 ErrorAdj, ErrorAcc; \
21.386 - Uint16 ErrorAccTemp, Weighting; \
21.387 - int DeltaX, DeltaY, Temp, XDir; \
21.388 - unsigned r, g, b, a, inva; \
21.389 - \
21.390 - /* Draw the initial pixel, which is always exactly intersected by \
21.391 - the line and so needs no weighting */ \
21.392 - opaque_op(x1, y1); \
21.393 - \
21.394 - /* Draw the final pixel, which is always exactly intersected by the line \
21.395 - and so needs no weighting */ \
21.396 - if (draw_end) { \
21.397 - opaque_op(x2, y2); \
21.398 - } \
21.399 - \
21.400 - /* Make sure the line runs top to bottom */ \
21.401 - if (y1 > y2) { \
21.402 - Temp = y1; y1 = y2; y2 = Temp; \
21.403 - Temp = x1; x1 = x2; x2 = Temp; \
21.404 - } \
21.405 - DeltaY = y2 - y1; \
21.406 - \
21.407 - if ((DeltaX = x2 - x1) >= 0) { \
21.408 - XDir = 1; \
21.409 - } else { \
21.410 - XDir = -1; \
21.411 - DeltaX = -DeltaX; /* make DeltaX positive */ \
21.412 - } \
21.413 - \
21.414 - /* line is not horizontal, diagonal, or vertical */ \
21.415 - ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
21.416 - \
21.417 - /* Is this an X-major or Y-major line? */ \
21.418 - if (DeltaY > DeltaX) { \
21.419 - /* Y-major line; calculate 16-bit fixed-point fractional part of a \
21.420 - pixel that X advances each time Y advances 1 pixel, truncating the \
21.421 - result so that we won't overrun the endpoint along the X axis */ \
21.422 - ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
21.423 - /* Draw all pixels other than the first and last */ \
21.424 - while (--DeltaY) { \
21.425 - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
21.426 - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
21.427 - if (ErrorAcc <= ErrorAccTemp) { \
21.428 - /* The error accumulator turned over, so advance the X coord */ \
21.429 - x1 += XDir; \
21.430 - } \
21.431 - y1++; /* Y-major, so always advance Y */ \
21.432 - /* The IntensityBits most significant bits of ErrorAcc give us the \
21.433 - intensity weighting for this pixel, and the complement of the \
21.434 - weighting for the paired pixel */ \
21.435 - Weighting = ErrorAcc >> 8; \
21.436 - { \
21.437 - a = DRAW_MUL(_a, (Weighting ^ 255)); \
21.438 - r = DRAW_MUL(_r, a); \
21.439 - g = DRAW_MUL(_g, a); \
21.440 - b = DRAW_MUL(_b, a); \
21.441 - inva = (a ^ 0xFF); \
21.442 - blend_op(x1, y1); \
21.443 - } \
21.444 - { \
21.445 - a = DRAW_MUL(_a, Weighting); \
21.446 - r = DRAW_MUL(_r, a); \
21.447 - g = DRAW_MUL(_g, a); \
21.448 - b = DRAW_MUL(_b, a); \
21.449 - inva = (a ^ 0xFF); \
21.450 - blend_op(x1 + XDir, y1); \
21.451 - } \
21.452 - } \
21.453 - } else { \
21.454 - /* X-major line; calculate 16-bit fixed-point fractional part of a \
21.455 - pixel that Y advances each time X advances 1 pixel, truncating the \
21.456 - result to avoid overrunning the endpoint along the X axis */ \
21.457 - ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
21.458 - /* Draw all pixels other than the first and last */ \
21.459 - while (--DeltaX) { \
21.460 - ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
21.461 - ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
21.462 - if (ErrorAcc <= ErrorAccTemp) { \
21.463 - /* The error accumulator turned over, so advance the Y coord */ \
21.464 - y1++; \
21.465 - } \
21.466 - x1 += XDir; /* X-major, so always advance X */ \
21.467 - /* The IntensityBits most significant bits of ErrorAcc give us the \
21.468 - intensity weighting for this pixel, and the complement of the \
21.469 - weighting for the paired pixel */ \
21.470 - Weighting = ErrorAcc >> 8; \
21.471 - { \
21.472 - a = DRAW_MUL(_a, (Weighting ^ 255)); \
21.473 - r = DRAW_MUL(_r, a); \
21.474 - g = DRAW_MUL(_g, a); \
21.475 - b = DRAW_MUL(_b, a); \
21.476 - inva = (a ^ 0xFF); \
21.477 - blend_op(x1, y1); \
21.478 - } \
21.479 - { \
21.480 - a = DRAW_MUL(_a, Weighting); \
21.481 - r = DRAW_MUL(_r, a); \
21.482 - g = DRAW_MUL(_g, a); \
21.483 - b = DRAW_MUL(_b, a); \
21.484 - inva = (a ^ 0xFF); \
21.485 - blend_op(x1, y1 + 1); \
21.486 - } \
21.487 - } \
21.488 - } \
21.489 -}
21.490 -
21.491 -#ifdef AA_LINES
21.492 -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
21.493 - WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
21.494 -#else
21.495 -#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
21.496 - BLINE(x1, y1, x2, y2, opaque_op, draw_end)
21.497 -#endif
21.498 -
21.499 -/*
21.500 - * Define fill rect macro
21.501 - */
21.502 -
21.503 -#define FILLRECT(type, op) \
21.504 -do { \
21.505 - int width = rect->w; \
21.506 - int height = rect->h; \
21.507 - int pitch = (dst->pitch / dst->format->BytesPerPixel); \
21.508 - int skip = pitch - width; \
21.509 - type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
21.510 - while (height--) { \
21.511 - { int n = (width+3)/4; \
21.512 - switch (width & 3) { \
21.513 - case 0: do { op; pixel++; \
21.514 - case 3: op; pixel++; \
21.515 - case 2: op; pixel++; \
21.516 - case 1: op; pixel++; \
21.517 - } while ( --n > 0 ); \
21.518 - } \
21.519 - } \
21.520 - pixel += skip; \
21.521 - } \
21.522 -} while (0)
21.523 -
21.524 -/* vi: set ts=4 sw=4 expandtab: */
22.1 --- a/src/video/SDL_drawline.c Thu Feb 03 02:42:50 2011 -0800
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,208 +0,0 @@
22.4 -/*
22.5 - SDL - Simple DirectMedia Layer
22.6 - Copyright (C) 1997-2010 Sam Lantinga
22.7 -
22.8 - This library is free software; you can redistribute it and/or
22.9 - modify it under the terms of the GNU Lesser General Public
22.10 - License as published by the Free Software Foundation; either
22.11 - version 2.1 of the License, or (at your option) any later version.
22.12 -
22.13 - This library is distributed in the hope that it will be useful,
22.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
22.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22.16 - Lesser General Public License for more details.
22.17 -
22.18 - You should have received a copy of the GNU Lesser General Public
22.19 - License along with this library; if not, write to the Free Software
22.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22.21 -
22.22 - Sam Lantinga
22.23 - slouken@libsdl.org
22.24 -*/
22.25 -#include "SDL_config.h"
22.26 -
22.27 -#include "SDL_draw.h"
22.28 -
22.29 -static void
22.30 -SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
22.31 - SDL_bool draw_end)
22.32 -{
22.33 - if (y1 == y2) {
22.34 - //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
22.35 - int length;
22.36 - int pitch = (dst->pitch / dst->format->BytesPerPixel);
22.37 - Uint8 *pixel;
22.38 - if (x1 <= x2) {
22.39 - pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
22.40 - length = draw_end ? (x2-x1+1) : (x2-x1);
22.41 - } else {
22.42 - pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
22.43 - if (!draw_end) {
22.44 - ++pixel;
22.45 - }
22.46 - length = draw_end ? (x1-x2+1) : (x1-x2);
22.47 - }
22.48 - SDL_memset(pixel, color, length);
22.49 - } else if (x1 == x2) {
22.50 - VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
22.51 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
22.52 - DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
22.53 - } else {
22.54 - BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
22.55 - }
22.56 -}
22.57 -
22.58 -static void
22.59 -SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
22.60 - SDL_bool draw_end)
22.61 -{
22.62 - if (y1 == y2) {
22.63 - HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
22.64 - } else if (x1 == x2) {
22.65 - VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
22.66 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
22.67 - DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
22.68 - } else {
22.69 - Uint8 _r, _g, _b, _a;
22.70 - const SDL_PixelFormat * fmt = dst->format;
22.71 - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
22.72 - if (fmt->Rmask == 0x7C00) {
22.73 - AALINE(x1, y1, x2, y2,
22.74 - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
22.75 - draw_end);
22.76 - } else if (fmt->Rmask == 0xF800) {
22.77 - AALINE(x1, y1, x2, y2,
22.78 - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
22.79 - draw_end);
22.80 - } else {
22.81 - AALINE(x1, y1, x2, y2,
22.82 - DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
22.83 - draw_end);
22.84 - }
22.85 - }
22.86 -}
22.87 -
22.88 -static void
22.89 -SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
22.90 - SDL_bool draw_end)
22.91 -{
22.92 - if (y1 == y2) {
22.93 - HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
22.94 - } else if (x1 == x2) {
22.95 - VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
22.96 - } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
22.97 - DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
22.98 - } else {
22.99 - Uint8 _r, _g, _b, _a;
22.100 - const SDL_PixelFormat * fmt = dst->format;
22.101 - SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
22.102 - if (fmt->Rmask == 0x00FF0000) {
22.103 - if (!fmt->Amask) {
22.104 - AALINE(x1, y1, x2, y2,
22.105 - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
22.106 - draw_end);
22.107 - } else {
22.108 - AALINE(x1, y1, x2, y2,
22.109 - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
22.110 - draw_end);
22.111 - }
22.112 - } else {
22.113 - AALINE(x1, y1, x2, y2,
22.114 - DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
22.115 - draw_end);
22.116 - }
22.117 - }
22.118 -}
22.119 -
22.120 -typedef void (*DrawLineFunc) (SDL_Surface * dst,
22.121 - int x1, int y1, int x2, int y2,
22.122 - Uint32 color, SDL_bool draw_end);
22.123 -
22.124 -static DrawLineFunc
22.125 -SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
22.126 -{
22.127 - switch (fmt->BytesPerPixel) {
22.128 - case 1:
22.129 - if (fmt->BitsPerPixel < 8) {
22.130 - break;
22.131 - }
22.132 - return SDL_DrawLine1;
22.133 - case 2:
22.134 - return SDL_DrawLine2;
22.135 - case 4:
22.136 - return SDL_DrawLine4;
22.137 - }
22.138 - return NULL;
22.139 -}
22.140 -
22.141 -int
22.142 -SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
22.143 -{
22.144 - DrawLineFunc func;
22.145 -
22.146 - if (!dst) {
22.147 - SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
22.148 - return -1;
22.149 - }
22.150 -
22.151 - func = SDL_CalculateDrawLineFunc(dst->format);
22.152 - if (!func) {
22.153 - SDL_SetError("SDL_DrawLine(): Unsupported surface format");
22.154 - return -1;
22.155 - }
22.156 -
22.157 - /* Perform clipping */
22.158 - /* FIXME: We don't actually want to clip, as it may change line slope */
22.159 - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
22.160 - return 0;
22.161 - }
22.162 -
22.163 - func(dst, x1, y1, x2, y2, color, SDL_TRUE);
22.164 - return 0;
22.165 -}
22.166 -
22.167 -int
22.168 -SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
22.169 - Uint32 color)
22.170 -{
22.171 - int i;
22.172 - int x1, y1;
22.173 - int x2, y2;
22.174 - SDL_bool draw_end;
22.175 - DrawLineFunc func;
22.176 -
22.177 - if (!dst) {
22.178 - SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
22.179 - return -1;
22.180 - }
22.181 -
22.182 - func = SDL_CalculateDrawLineFunc(dst->format);
22.183 - if (!func) {
22.184 - SDL_SetError("SDL_DrawLines(): Unsupported surface format");
22.185 - return -1;
22.186 - }
22.187 -
22.188 - for (i = 1; i < count; ++i) {
22.189 - x1 = points[i-1].x;
22.190 - y1 = points[i-1].y;
22.191 - x2 = points[i].x;
22.192 - y2 = points[i].y;
22.193 -
22.194 - /* Perform clipping */
22.195 - /* FIXME: We don't actually want to clip, as it may change line slope */
22.196 - if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
22.197 - continue;
22.198 - }
22.199 -
22.200 - /* Draw the end if it was clipped */
22.201 - draw_end = (x2 != points[i].x || y2 != points[i].y);
22.202 -
22.203 - func(dst, x1, y1, x2, y2, color, draw_end);
22.204 - }
22.205 - if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
22.206 - SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
22.207 - }
22.208 - return 0;
22.209 -}
22.210 -
22.211 -/* vi: set ts=4 sw=4 expandtab: */
23.1 --- a/src/video/SDL_drawpoint.c Thu Feb 03 02:42:50 2011 -0800
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,116 +0,0 @@
23.4 -/*
23.5 - SDL - Simple DirectMedia Layer
23.6 - Copyright (C) 1997-2010 Sam Lantinga
23.7 -
23.8 - This library is free software; you can redistribute it and/or
23.9 - modify it under the terms of the GNU Lesser General Public
23.10 - License as published by the Free Software Foundation; either
23.11 - version 2.1 of the License, or (at your option) any later version.
23.12 -
23.13 - This library is distributed in the hope that it will be useful,
23.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
23.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23.16 - Lesser General Public License for more details.
23.17 -
23.18 - You should have received a copy of the GNU Lesser General Public
23.19 - License along with this library; if not, write to the Free Software
23.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23.21 -
23.22 - Sam Lantinga
23.23 - slouken@libsdl.org
23.24 -*/
23.25 -#include "SDL_config.h"
23.26 -
23.27 -#include "SDL_draw.h"
23.28 -
23.29 -
23.30 -int
23.31 -SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
23.32 -{
23.33 - if (!dst) {
23.34 - SDL_SetError("Passed NULL destination surface");
23.35 - return -1;
23.36 - }
23.37 -
23.38 - /* This function doesn't work on surfaces < 8 bpp */
23.39 - if (dst->format->BitsPerPixel < 8) {
23.40 - SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
23.41 - return -1;
23.42 - }
23.43 -
23.44 - /* Perform clipping */
23.45 - if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
23.46 - x >= (dst->clip_rect.x + dst->clip_rect.w) ||
23.47 - y >= (dst->clip_rect.y + dst->clip_rect.h)) {
23.48 - return 0;
23.49 - }
23.50 -
23.51 - switch (dst->format->BytesPerPixel) {
23.52 - case 1:
23.53 - DRAW_FASTSETPIXELXY1(x, y);
23.54 - break;
23.55 - case 2:
23.56 - DRAW_FASTSETPIXELXY2(x, y);
23.57 - break;
23.58 - case 3:
23.59 - SDL_Unsupported();
23.60 - return -1;
23.61 - case 4:
23.62 - DRAW_FASTSETPIXELXY4(x, y);
23.63 - break;
23.64 - }
23.65 - return 0;
23.66 -}
23.67 -
23.68 -int
23.69 -SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
23.70 - Uint32 color)
23.71 -{
23.72 - int minx, miny;
23.73 - int maxx, maxy;
23.74 - int i;
23.75 - int x, y;
23.76 -
23.77 - if (!dst) {
23.78 - SDL_SetError("Passed NULL destination surface");
23.79 - return -1;
23.80 - }
23.81 -
23.82 - /* This function doesn't work on surfaces < 8 bpp */
23.83 - if (dst->format->BitsPerPixel < 8) {
23.84 - SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
23.85 - return -1;
23.86 - }
23.87 -
23.88 - minx = dst->clip_rect.x;
23.89 - maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
23.90 - miny = dst->clip_rect.y;
23.91 - maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
23.92 -
23.93 - for (i = 0; i < count; ++i) {
23.94 - x = points[i].x;
23.95 - y = points[i].y;
23.96 -
23.97 - if (x < minx || x > maxx || y < miny || y > maxy) {
23.98 - continue;
23.99 - }
23.100 -
23.101 - switch (dst->format->BytesPerPixel) {
23.102 - case 1:
23.103 - DRAW_FASTSETPIXELXY1(x, y);
23.104 - break;
23.105 - case 2:
23.106 - DRAW_FASTSETPIXELXY2(x, y);
23.107 - break;
23.108 - case 3:
23.109 - SDL_Unsupported();
23.110 - return -1;
23.111 - case 4:
23.112 - DRAW_FASTSETPIXELXY4(x, y);
23.113 - break;
23.114 - }
23.115 - }
23.116 - return 0;
23.117 -}
23.118 -
23.119 -/* vi: set ts=4 sw=4 expandtab: */
24.1 --- a/src/video/SDL_drawrect.c Thu Feb 03 02:42:50 2011 -0800
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,74 +0,0 @@
24.4 -/*
24.5 - SDL - Simple DirectMedia Layer
24.6 - Copyright (C) 1997-2010 Sam Lantinga
24.7 -
24.8 - This library is free software; you can redistribute it and/or
24.9 - modify it under the terms of the GNU Lesser General Public
24.10 - License as published by the Free Software Foundation; either
24.11 - version 2.1 of the License, or (at your option) any later version.
24.12 -
24.13 - This library is distributed in the hope that it will be useful,
24.14 - but WITHOUT ANY WARRANTY; without even the implied warranty of
24.15 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24.16 - Lesser General Public License for more details.
24.17 -
24.18 - You should have received a copy of the GNU Lesser General Public
24.19 - License along with this library; if not, write to the Free Software
24.20 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24.21 -
24.22 - Sam Lantinga
24.23 - slouken@libsdl.org
24.24 -*/
24.25 -#include "SDL_config.h"
24.26 -
24.27 -#include "SDL_video.h"
24.28 -
24.29 -
24.30 -int
24.31 -SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
24.32 -{
24.33 - SDL_Rect full_rect;
24.34 - SDL_Point points[5];
24.35 -
24.36 - if (!dst) {
24.37 - SDL_SetError("Passed NULL destination surface");
24.38 - return -1;
24.39 - }
24.40 -
24.41 - /* If 'rect' == NULL, then outline the whole surface */
24.42 - if (!rect) {
24.43 - full_rect.x = 0;
24.44 - full_rect.y = 0;
24.45 - full_rect.w = dst->w;
24.46 - full_rect.h = dst->h;
24.47 - rect = &full_rect;
24.48 - }
24.49 -
24.50 - points[0].x = rect->x;
24.51 - points[0].y = rect->y;
24.52 - points[1].x = rect->x+rect->w-1;
24.53 - points[1].y = rect->y;
24.54 - points[2].x = rect->x+rect->w-1;
24.55 - points[2].y = rect->y+rect->h-1;
24.56 - points[3].x = rect->x;
24.57 - points[3].y = rect->y+rect->h-1;
24.58 - points[4].x = rect->x;
24.59 - points[4].y = rect->y;
24.60 - return SDL_DrawLines(dst, points, 5, color);
24.61 -}
24.62 -
24.63 -int
24.64 -SDL_DrawRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
24.65 - Uint32 color)
24.66 -{
24.67 - int i;
24.68 -
24.69 - for (i = 0; i < count; ++i) {
24.70 - if (SDL_DrawRect(dst, rects[i], color) < 0) {
24.71 - return -1;
24.72 - }
24.73 - }
24.74 - return 0;
24.75 -}
24.76 -
24.77 -/* vi: set ts=4 sw=4 expandtab: */
25.1 --- a/test/automated/surface/surface.c Thu Feb 03 02:42:50 2011 -0800
25.2 +++ b/test/automated/surface/surface.c Thu Feb 03 02:45:29 2011 -0800
25.3 @@ -26,8 +26,6 @@
25.4 */
25.5 /* Testcases. */
25.6 static void surface_testLoad( SDL_Surface *testsur );
25.7 -static void surface_testPrimitives( SDL_Surface *testsur );
25.8 -static void surface_testPrimitivesBlend( SDL_Surface *testsur );
25.9 static void surface_testBlit( SDL_Surface *testsur );
25.10 static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode );
25.11 static void surface_testBlitBlend( SDL_Surface *testsur );
25.12 @@ -85,167 +83,6 @@
25.13
25.14
25.15 /**
25.16 - * @brief Tests the SDL primitives for rendering.
25.17 - */
25.18 -static void surface_testPrimitives( SDL_Surface *testsur )
25.19 -{
25.20 - int ret;
25.21 - int x, y;
25.22 - SDL_Rect rect;
25.23 -
25.24 - SDL_ATbegin( "Primitives Test" );
25.25 -
25.26 - /* Clear surface. */
25.27 - ret = SDL_FillRect( testsur, NULL,
25.28 - SDL_MapRGB( testsur->format, 0, 0, 0 ) );
25.29 - if (SDL_ATassert( "SDL_FillRect", ret == 0))
25.30 - return;
25.31 -
25.32 - /* Draw a rectangle. */
25.33 - rect.x = 40;
25.34 - rect.y = 0;
25.35 - rect.w = 40;
25.36 - rect.h = 80;
25.37 - ret = SDL_FillRect( testsur, &rect,
25.38 - SDL_MapRGB( testsur->format, 13, 73, 200 ) );
25.39 - if (SDL_ATassert( "SDL_FillRect", ret == 0))
25.40 - return;
25.41 -
25.42 - /* Draw a rectangle. */
25.43 - rect.x = 10;
25.44 - rect.y = 10;
25.45 - rect.w = 60;
25.46 - rect.h = 40;
25.47 - ret = SDL_FillRect( testsur, &rect,
25.48 - SDL_MapRGB( testsur->format, 200, 0, 100 ) );
25.49 - if (SDL_ATassert( "SDL_FillRect", ret == 0))
25.50 - return;
25.51 -
25.52 - /* Draw some points like so:
25.53 - * X.X.X.X..
25.54 - * .X.X.X.X.
25.55 - * X.X.X.X.. */
25.56 - for (y=0; y<3; y++) {
25.57 - x = y % 2;
25.58 - for (; x<80; x+=2) {
25.59 - ret = SDL_DrawPoint( testsur, x, y,
25.60 - SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) );
25.61 - if (SDL_ATassert( "SDL_DrawPoint", ret == 0))
25.62 - return;
25.63 - }
25.64 - }
25.65 -
25.66 - /* Draw some lines. */
25.67 - ret = SDL_DrawLine( testsur, 0, 30, 80, 30,
25.68 - SDL_MapRGB( testsur->format, 0, 255, 0 ) );
25.69 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.70 - return;
25.71 - ret = SDL_DrawLine( testsur, 40, 30, 40, 60,
25.72 - SDL_MapRGB( testsur->format, 55, 55, 5 ) );
25.73 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.74 - return;
25.75 - ret = SDL_DrawLine( testsur, 0, 0, 29, 29,
25.76 - SDL_MapRGB( testsur->format, 5, 105, 105 ) );
25.77 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.78 - return;
25.79 - ret = SDL_DrawLine( testsur, 29, 30, 0, 59,
25.80 - SDL_MapRGB( testsur->format, 5, 105, 105 ) );
25.81 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.82 - return;
25.83 - ret = SDL_DrawLine( testsur, 79, 0, 50, 29,
25.84 - SDL_MapRGB( testsur->format, 5, 105, 105 ) );
25.85 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.86 - return;
25.87 - ret = SDL_DrawLine( testsur, 79, 59, 50, 30,
25.88 - SDL_MapRGB( testsur->format, 5, 105, 105 ) );
25.89 - if (SDL_ATassert( "SDL_DrawLine", ret == 0))
25.90 - return;
25.91 -
25.92 - /* See if it's the same. */
25.93 - if (SDL_ATassert( "Primitives output not the same.",
25.94 - surface_compare( testsur, &img_primitives, 0 )==0 ))
25.95 - return;
25.96 -
25.97 - SDL_ATend();
25.98 -}
25.99 -
25.100 -
25.101 -/**
25.102 - * @brief Tests the SDL primitives with alpha for rendering.
25.103 - */
25.104 -static void surface_testPrimitivesBlend( SDL_Surface *testsur )
25.105 -{
25.106 - int ret;
25.107 - int i, j;
25.108 - SDL_Rect rect;
25.109 -
25.110 - SDL_ATbegin( "Primitives Blend Test" );
25.111 -
25.112 - /* Clear surface. */
25.113 - ret = SDL_FillRect( testsur, NULL,
25.114 - SDL_MapRGB( testsur->format, 0, 0, 0 ) );
25.115 - if (SDL_ATassert( "SDL_FillRect", ret == 0))
25.116 - return;
25.117 -
25.118 - /* Create some rectangles for each blend mode. */
25.119 - ret = SDL_BlendFillRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
25.120 - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
25.121 - return;
25.122 - rect.x = 10;
25.123 - rect.y = 25;
25.124 - rect.w = 40;
25.125 - rect.h = 25;
25.126 - ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
25.127 - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
25.128 - return;
25.129 - rect.x = 30;
25.130 - rect.y = 40;
25.131 - rect.w = 45;
25.132 - rect.h = 15;
25.133 - ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
25.134 - if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
25.135 - return;
25.136 -
25.137 - /* Draw blended lines, lines for everyone. */
25.138 - for (i=0; i<testsur->w; i+=2) {
25.139 - ret = SDL_BlendLine( testsur, 0, 0, i, 59,
25.140 - (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
25.141 - (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
25.142 - 60+2*i, 240-2*i, 50, 3*i );
25.143 - if (SDL_ATassert( "SDL_BlendLine", ret == 0))
25.144 - return;
25.145 - }
25.146 - for (i=0; i<testsur->h; i+=2) {
25.147 - ret = SDL_BlendLine( testsur, 0, 0, 79, i,
25.148 - (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
25.149 - (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
25.150 - 60+2*i, 240-2*i, 50, 3*i );
25.151 - if (SDL_ATassert( "SDL_BlendLine", ret == 0))
25.152 - return;
25.153 - }
25.154 -
25.155 - /* Draw points. */
25.156 - for (j=0; j<testsur->h; j+=3) {
25.157 - for (i=0; i<testsur->w; i+=3) {
25.158 - ret = SDL_BlendPoint( testsur, i, j,
25.159 - ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
25.160 - ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
25.161 - j*4, i*3, j*4, i*3 );
25.162 - if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
25.163 - return;
25.164 - }
25.165 - }
25.166 -
25.167 - /* See if it's the same. */
25.168 - if (SDL_ATassert( "Primitives output not the same.",
25.169 - surface_compare( testsur, &img_blend, 0 )==0 ))
25.170 - return;
25.171 -
25.172 - SDL_ATend();
25.173 -}
25.174 -
25.175 -
25.176 -/**
25.177 * @brief Tests some blitting routines.
25.178 */
25.179 static void surface_testBlit( SDL_Surface *testsur )
25.180 @@ -546,8 +383,6 @@
25.181 void surface_runTests( SDL_Surface *testsur )
25.182 {
25.183 /* Software surface blitting. */
25.184 - surface_testPrimitives( testsur );
25.185 - surface_testPrimitivesBlend( testsur );
25.186 surface_testBlit( testsur );
25.187 surface_testBlitBlend( testsur );
25.188 }