2008-12-20 13:14:28 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2010-01-24 21:10:53 +00:00
|
|
|
Copyright (C) 1997-2010 Sam Lantinga
|
2008-12-20 13:14:28 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
|
|
|
#include "SDL_video.h"
|
2008-12-21 08:28:25 +00:00
|
|
|
#include "SDL_draw.h"
|
2008-12-20 13:14:28 +00:00
|
|
|
|
2008-12-21 08:28:25 +00:00
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-20 13:14:28 +00:00
|
|
|
{
|
2008-12-21 08:28:25 +00:00
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
2008-12-20 13:14:28 +00:00
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-12-20 13:14:28 +00:00
|
|
|
|
2008-12-21 08:28:25 +00:00
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:28:25 +00:00
|
|
|
{
|
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
2008-12-20 13:14:28 +00:00
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-12-20 13:14:28 +00:00
|
|
|
|
2008-12-21 08:28:25 +00:00
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:28:25 +00:00
|
|
|
{
|
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
|
2008-12-21 08:28:25 +00:00
|
|
|
break;
|
2008-12-20 23:19:20 +00:00
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-21 08:55:06 +00:00
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:55:06 +00:00
|
|
|
{
|
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
|
2008-12-21 08:55:06 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
|
2008-12-21 08:55:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
|
2008-12-21 08:55:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-21 08:28:25 +00:00
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:28:25 +00:00
|
|
|
{
|
|
|
|
SDL_PixelFormat *fmt = dst->format;
|
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (fmt->BytesPerPixel) {
|
|
|
|
case 2:
|
2008-12-20 23:19:20 +00:00
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
2008-12-21 08:28:25 +00:00
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
|
|
|
case 4:
|
2008-12-20 23:19:20 +00:00
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
2008-12-21 08:28:25 +00:00
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:28:25 +00:00
|
|
|
{
|
|
|
|
SDL_PixelFormat *fmt = dst->format;
|
|
|
|
unsigned inva = 0xff - a;
|
|
|
|
|
|
|
|
switch (fmt->BytesPerPixel) {
|
|
|
|
case 4:
|
2008-12-20 23:19:20 +00:00
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
2008-12-21 08:28:25 +00:00
|
|
|
default:
|
2008-12-21 08:59:56 +00:00
|
|
|
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
|
2008-12-20 23:19:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
return 0;
|
2008-12-20 23:19:20 +00:00
|
|
|
default:
|
|
|
|
SDL_Unsupported();
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2008-12-21 08:28:25 +00:00
|
|
|
{
|
2009-12-09 15:56:56 +00:00
|
|
|
SDL_Rect clipped;
|
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
SDL_SetError("Passed NULL destination surface");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-21 08:28:25 +00:00
|
|
|
|
|
|
|
/* This function doesn't work on surfaces < 8 bpp */
|
2009-12-09 15:56:56 +00:00
|
|
|
if (dst->format->BitsPerPixel < 8) {
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
|
2009-12-09 15:56:56 +00:00
|
|
|
return -1;
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 15:56:56 +00:00
|
|
|
/* If 'rect' == NULL, then fill the whole surface */
|
|
|
|
if (rect) {
|
2008-12-21 08:28:25 +00:00
|
|
|
/* Perform clipping */
|
2009-12-09 15:56:56 +00:00
|
|
|
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
|
|
|
|
return 0;
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
rect = &clipped;
|
2008-12-21 08:28:25 +00:00
|
|
|
} else {
|
2009-12-09 15:56:56 +00:00
|
|
|
rect = &dst->clip_rect;
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 15:56:56 +00:00
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
|
2008-12-21 08:28:25 +00:00
|
|
|
r = DRAW_MUL(r, a);
|
|
|
|
g = DRAW_MUL(g, a);
|
|
|
|
b = DRAW_MUL(b, a);
|
|
|
|
}
|
|
|
|
|
2009-12-09 15:56:56 +00:00
|
|
|
switch (dst->format->BitsPerPixel) {
|
2008-12-21 08:28:25 +00:00
|
|
|
case 15:
|
2009-12-09 15:56:56 +00:00
|
|
|
switch (dst->format->Rmask) {
|
2008-12-21 08:28:25 +00:00
|
|
|
case 0x7C00:
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
2009-12-09 15:56:56 +00:00
|
|
|
switch (dst->format->Rmask) {
|
2008-12-21 08:28:25 +00:00
|
|
|
case 0xF800:
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 32:
|
2009-12-09 15:56:56 +00:00
|
|
|
switch (dst->format->Rmask) {
|
2008-12-21 08:28:25 +00:00
|
|
|
case 0x00FF0000:
|
2009-12-09 15:56:56 +00:00
|
|
|
if (!dst->format->Amask) {
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:55:06 +00:00
|
|
|
} else {
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
break;
|
2008-12-21 08:28:25 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-12-09 15:56:56 +00:00
|
|
|
if (!dst->format->Amask) {
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:28:25 +00:00
|
|
|
} else {
|
2009-12-18 07:03:09 +00:00
|
|
|
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
2009-12-09 15:56:56 +00:00
|
|
|
{
|
|
|
|
SDL_Rect clipped;
|
|
|
|
int i;
|
|
|
|
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
|
2010-12-12 15:19:05 -08:00
|
|
|
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
2009-12-09 15:56:56 +00:00
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
SDL_SetError("Passed NULL destination surface");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function doesn't work on surfaces < 8 bpp */
|
|
|
|
if (dst->format->BitsPerPixel < 8) {
|
2009-12-18 07:03:09 +00:00
|
|
|
SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
|
2009-12-09 15:56:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
|
|
|
|
r = DRAW_MUL(r, a);
|
|
|
|
g = DRAW_MUL(g, a);
|
|
|
|
b = DRAW_MUL(b, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Does this function pointer slow things down significantly? */
|
|
|
|
switch (dst->format->BitsPerPixel) {
|
|
|
|
case 15:
|
|
|
|
switch (dst->format->Rmask) {
|
|
|
|
case 0x7C00:
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_RGB555;
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
switch (dst->format->Rmask) {
|
|
|
|
case 0xF800:
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_RGB565;
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
switch (dst->format->Rmask) {
|
|
|
|
case 0x00FF0000:
|
|
|
|
if (!dst->format->Amask) {
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_RGB888;
|
2009-12-09 15:56:56 +00:00
|
|
|
} else {
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_ARGB8888;
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!func) {
|
|
|
|
if (!dst->format->Amask) {
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_RGB;
|
2009-12-09 15:56:56 +00:00
|
|
|
} else {
|
2009-12-18 07:03:09 +00:00
|
|
|
func = SDL_BlendFillRect_RGBA;
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const SDL_Rect * rect = rects[i];
|
|
|
|
|
|
|
|
/* If 'rect' == NULL, then fill the whole surface */
|
|
|
|
if (rect) {
|
|
|
|
/* Perform clipping */
|
|
|
|
if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rect = &clipped;
|
|
|
|
} else {
|
|
|
|
rect = &dst->clip_rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = func(dst, rect, blendMode, r, g, b, a);
|
2008-12-21 08:28:25 +00:00
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
return status;
|
2008-12-20 13:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|