Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added RenderPiont() API

Merged the drawing tests into a single test program
  • Loading branch information
slouken committed Dec 21, 2008
1 parent afe44a7 commit 819d01955884eb431a7d2835fca19e95653bb103
@@ -365,6 +365,25 @@ extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);

/*
* This function draws a point with 'color'
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
* This function returns 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawPoint
(SDL_Surface * dst, int x, int y, Uint32 color);

/*
* This function blends a point with an RGBA value
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
* This function returns 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendPoint
(SDL_Surface * dst, int x, int y, int blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);

/*
* This function draws a line with 'color'
* The color should be a pixel of the format used by the surface, and
@@ -1196,6 +1196,18 @@ extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode);
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);

/**
* \fn int SDL_RenderPoint(int x, int y)
*
* \brief Draw a point on the current rendering target.
*
* \param x The x coordinate of the point
* \param y The y coordinate of the point
*
* \return 0 on success, or -1 if there is no rendering context current
*/
extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y);

/**
* \fn int SDL_RenderLine(int x1, int y1, int x2, int y2)
*
@@ -1208,7 +1220,6 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
*
* \return 0 on success, or -1 if there is no rendering context current
*/

extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2);

/**
@@ -0,0 +1,256 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"

#include "SDL_draw.h"

static int
SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;

switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY_BLEND_RGB555(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY_ADD_RGB555(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY_MOD_RGB555(x, y);
break;
default:
DRAW_SETPIXELXY_RGB555(x, y);
break;
}
return 0;
}

static int
SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;

switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY_BLEND_RGB565(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY_ADD_RGB565(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY_MOD_RGB565(x, y);
break;
default:
DRAW_SETPIXELXY_RGB565(x, y);
break;
}
return 0;
}

static int
SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;

switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY_BLEND_RGB888(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY_ADD_RGB888(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY_MOD_RGB888(x, y);
break;
default:
DRAW_SETPIXELXY_RGB888(x, y);
break;
}
return 0;
}

static int
SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, int blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;

switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY_MOD_ARGB8888(x, y);
break;
default:
DRAW_SETPIXELXY_ARGB8888(x, y);
break;
}
return 0;
}

static int
SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;

switch (fmt->BytesPerPixel) {
case 2:
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY2_BLEND_RGB(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY2_ADD_RGB(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY2_MOD_RGB(x, y);
break;
default:
DRAW_SETPIXELXY2_RGB(x, y);
break;
}
return 0;
case 4:
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY4_BLEND_RGB(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY4_ADD_RGB(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY4_MOD_RGB(x, y);
break;
default:
DRAW_SETPIXELXY4_RGB(x, y);
break;
}
return 0;
default:
SDL_Unsupported();
return -1;
}
}

static int
SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a;

switch (fmt->BytesPerPixel) {
case 4:
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
break;
case SDL_BLENDMODE_ADD:
DRAW_SETPIXELXY4_ADD_RGBA(x, y);
break;
case SDL_BLENDMODE_MOD:
DRAW_SETPIXELXY4_MOD_RGBA(x, y);
break;
default:
DRAW_SETPIXELXY4_RGBA(x, y);
break;
}
return 0;
default:
SDL_Unsupported();
return -1;
}
}

int
SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
SDL_PixelFormat *fmt = dst->format;

/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
return (-1);
}

/* Perform clipping */
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
return 0;
}

if ((blendMode == SDL_BLENDMODE_BLEND)
|| (blendMode == SDL_BLENDMODE_ADD)) {
r = DRAW_MUL(r, a);
g = DRAW_MUL(g, a);
b = DRAW_MUL(b, a);
}

switch (fmt->BitsPerPixel) {
case 15:
switch (fmt->Rmask) {
case 0x7C00:
return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
}
break;
case 16:
switch (fmt->Rmask) {
case 0xF800:
return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
}
break;
case 32:
switch (fmt->Rmask) {
case 0x00FF0000:
if (!fmt->Amask) {
return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b,
a);
} else {
return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b,
a);
}
break;
}
default:
break;
}

if (!fmt->Amask) {
return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
} else {
return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
}
}

/* vi: set ts=4 sw=4 expandtab: */
@@ -29,6 +29,13 @@

#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)

#define DRAW_FASTSETPIXEL(x, y, type, bpp, color) \
*(type *)(dst->pixels + y * dst->pitch + x * bpp) = (type) color

#define DRAW_FASTSETPIXEL1(x, y) DRAW_FASTSETPIXEL(x, y, Uint8, 1, color);
#define DRAW_FASTSETPIXEL2(x, y) DRAW_FASTSETPIXEL(x, y, Uint16, 2, color);
#define DRAW_FASTSETPIXEL4(x, y) DRAW_FASTSETPIXEL(x, y, Uint32, 4, color);

#define DRAW_SETPIXEL(setpixel) \
do { \
unsigned sr = r, sg = g, sb = b, sa = a; \
@@ -23,13 +23,8 @@

#include "SDL_draw.h"

#define SETPIXEL(x, y, type, bpp, color) \
*(type *)(dst->pixels + y * dst->pitch + x * bpp) = (type) color

#define SETPIXEL1(x, y) SETPIXEL(x, y, Uint8, 1, color);
#define SETPIXEL2(x, y) SETPIXEL(x, y, Uint16, 2, color);
#define SETPIXEL4(x, y) SETPIXEL(x, y, Uint32, 4, color);

int
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
{
/* This function doesn't work on surfaces < 8 bpp */
@@ -47,16 +42,16 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)

switch (dst->format->BytesPerPixel) {
case 1:
DRAWLINE(x1, y1, x2, y2, SETPIXEL1);
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
break;
case 2:
DRAWLINE(x1, y1, x2, y2, SETPIXEL2);
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
DRAWLINE(x1, y1, x2, y2, SETPIXEL4);
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
break;
}
return 0;

0 comments on commit 819d019

Please sign in to comment.