mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-26 23:59:30 +00:00
Updates the SDL library to the latest standard bugfix release
This commit is contained in:
parent
cb766f2878
commit
083d2175ea
1280 changed files with 343926 additions and 179615 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,10 +25,8 @@
|
|||
#include "SDL_draw.h"
|
||||
#include "SDL_blendfillrect.h"
|
||||
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -52,9 +50,8 @@ SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -78,9 +75,8 @@ SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_RGB888(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -104,9 +100,8 @@ SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -130,9 +125,8 @@ SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
|
@ -181,9 +175,8 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
|
@ -213,13 +206,12 @@ SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_Rect clipped;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -280,17 +272,16 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
int i;
|
||||
int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
|
||||
int (*func)(SDL_Surface * dst, const SDL_Rect *rect,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +325,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
|||
break;
|
||||
}
|
||||
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendFillRect_RGB;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
|
||||
extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
#endif /* SDL_blendfillrect_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,11 +26,9 @@
|
|||
#include "SDL_blendline.h"
|
||||
#include "SDL_blendpoint.h"
|
||||
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGB2(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
const SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned r, g, b, a, inva;
|
||||
|
|
@ -133,10 +131,9 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGB555(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
unsigned r, g, b, a, inva;
|
||||
|
||||
|
|
@ -238,10 +235,9 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGB565(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
unsigned r, g, b, a, inva;
|
||||
|
||||
|
|
@ -343,10 +339,9 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGB4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
const SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned r, g, b, a, inva;
|
||||
|
|
@ -449,10 +444,9 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGBA4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
const SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned r, g, b, a, inva;
|
||||
|
|
@ -555,10 +549,9 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_RGB888(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
unsigned r, g, b, a, inva;
|
||||
|
||||
|
|
@ -660,10 +653,9 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_BlendLine_ARGB8888(SDL_Surface *dst, int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
unsigned r, g, b, a, inva;
|
||||
|
||||
|
|
@ -765,14 +757,13 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
}
|
||||
}
|
||||
|
||||
typedef void (*BlendLineFunc) (SDL_Surface * dst,
|
||||
int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
|
||||
SDL_bool draw_end);
|
||||
typedef void (*BlendLineFunc)(SDL_Surface *dst,
|
||||
int x1, int y1, int x2, int y2,
|
||||
SDL_BlendMode blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
|
||||
SDL_bool draw_end);
|
||||
|
||||
static BlendLineFunc
|
||||
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
|
||||
static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormat *fmt)
|
||||
{
|
||||
switch (fmt->BytesPerPixel) {
|
||||
case 2:
|
||||
|
|
@ -802,18 +793,17 @@ SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
BlendLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -827,9 +817,8 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
int i;
|
||||
int x1, y1;
|
||||
|
|
@ -837,18 +826,18 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
SDL_bool draw_end;
|
||||
BlendLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
for (i = 1; i < count; ++i) {
|
||||
x1 = points[i-1].x;
|
||||
y1 = points[i-1].y;
|
||||
x1 = points[i - 1].x;
|
||||
y1 = points[i - 1].y;
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
|
||||
|
|
@ -863,8 +852,8 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
|
||||
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
|
||||
}
|
||||
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
|
||||
SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
|
||||
if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
|
||||
SDL_BlendPoint(dst, points[count - 1].x, points[count - 1].y,
|
||||
blendMode, r, g, b, a);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
|
||||
extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
#endif /* SDL_blendline_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,10 +25,8 @@
|
|||
#include "SDL_draw.h"
|
||||
#include "SDL_blendpoint.h"
|
||||
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -52,9 +50,8 @@ SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -78,9 +75,8 @@ SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_RGB888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -104,9 +100,8 @@ SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
|
|
@ -130,9 +125,8 @@ SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
|
@ -181,9 +175,8 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
|
@ -213,11 +206,10 @@ SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Ui
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -274,9 +266,8 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
||||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
int minx, miny;
|
||||
int maxx, maxy;
|
||||
|
|
@ -286,7 +277,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
|
||||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +323,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
break;
|
||||
}
|
||||
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
if (!dst->format->Amask) {
|
||||
func = SDL_BlendPoint_RGB;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
|
||||
extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
extern int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
#endif /* SDL_blendpoint_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,77 +26,90 @@
|
|||
* and in the blend and add case, the RGB values are premultiplied by a.
|
||||
*/
|
||||
|
||||
#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
|
||||
#define DRAW_MUL(_a, _b) (((unsigned)(_a) * (_b)) / 255)
|
||||
|
||||
#define DRAW_FASTSETPIXEL(type) \
|
||||
*pixel = (type) color
|
||||
*pixel = (type)color
|
||||
|
||||
#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
|
||||
#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
|
||||
#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
|
||||
|
||||
#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
|
||||
*(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
|
||||
+ (x) * bpp) = (type) color
|
||||
*(type *)((Uint8 *)dst->pixels + (y)*dst->pitch + (x)*bpp) = (type)color
|
||||
|
||||
#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
|
||||
#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
|
||||
#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
|
||||
|
||||
#define DRAW_SETPIXEL(setpixel) \
|
||||
do { \
|
||||
unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
#define DRAW_SETPIXEL(setpixel) \
|
||||
do { \
|
||||
unsigned sr = r, sg = g, sb = b, sa = a; \
|
||||
(void)sa; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa = 0xFF; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(inva, sr) + r; \
|
||||
sg = DRAW_MUL(inva, sg) + g; \
|
||||
sb = DRAW_MUL(inva, sb) + b; \
|
||||
sa = DRAW_MUL(inva, sa) + a; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa = 0xFF; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(inva, sr) + r; \
|
||||
sg = DRAW_MUL(inva, sg) + g; \
|
||||
sb = DRAW_MUL(inva, sb) + b; \
|
||||
sa = DRAW_MUL(inva, sa) + a; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; (void) sa; \
|
||||
getpixel; \
|
||||
sr += r; if (sr > 0xff) sr = 0xff; \
|
||||
sg += g; if (sg > 0xff) sg = 0xff; \
|
||||
sb += b; if (sb > 0xff) sb = 0xff; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; \
|
||||
(void)sa; \
|
||||
getpixel; \
|
||||
sr += r; \
|
||||
if (sr > 0xff) \
|
||||
sr = 0xff; \
|
||||
sg += g; \
|
||||
if (sg > 0xff) \
|
||||
sg = 0xff; \
|
||||
sb += b; \
|
||||
if (sb > 0xff) \
|
||||
sb = 0xff; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; (void) sa; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(sr, r); \
|
||||
sg = DRAW_MUL(sg, g); \
|
||||
sb = DRAW_MUL(sb, b); \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; \
|
||||
(void)sa; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(sr, r); \
|
||||
sg = DRAW_MUL(sg, g); \
|
||||
sb = DRAW_MUL(sb, b); \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; sa = 0xFF; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); if (sr > 0xff) sr = 0xff; \
|
||||
sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); if (sg > 0xff) sg = 0xff; \
|
||||
sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); if (sb > 0xff) sb = 0xff; \
|
||||
sa = DRAW_MUL(sa, a) + DRAW_MUL(inva, sa); if (sa > 0xff) sa = 0xff; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
#define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; \
|
||||
(void)sa; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); \
|
||||
if (sr > 0xff) \
|
||||
sr = 0xff; \
|
||||
sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); \
|
||||
if (sg > 0xff) \
|
||||
sg = 0xff; \
|
||||
sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); \
|
||||
if (sb > 0xff) \
|
||||
sb = 0xff; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
|
||||
do { \
|
||||
type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
|
||||
+ (x) * bpp); \
|
||||
op; \
|
||||
} while (0)
|
||||
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
|
||||
do { \
|
||||
type *pixel = (type *)((Uint8 *)dst->pixels + (y)*dst->pitch + (x)*bpp); \
|
||||
op; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Define draw operators for RGB555
|
||||
|
|
@ -105,19 +118,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_RGB555 \
|
||||
DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_RGB555 \
|
||||
#define DRAW_SETPIXEL_BLEND_RGB555 \
|
||||
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_RGB555 \
|
||||
#define DRAW_SETPIXEL_ADD_RGB555 \
|
||||
DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_RGB555 \
|
||||
#define DRAW_SETPIXEL_MOD_RGB555 \
|
||||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB555 \
|
||||
#define DRAW_SETPIXEL_MUL_RGB555 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
|
|
@ -143,19 +156,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_RGB565 \
|
||||
DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_RGB565 \
|
||||
#define DRAW_SETPIXEL_BLEND_RGB565 \
|
||||
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_RGB565 \
|
||||
#define DRAW_SETPIXEL_ADD_RGB565 \
|
||||
DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_RGB565 \
|
||||
#define DRAW_SETPIXEL_MOD_RGB565 \
|
||||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB565 \
|
||||
#define DRAW_SETPIXEL_MUL_RGB565 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
|
|
@ -181,19 +194,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_RGB888 \
|
||||
DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_RGB888 \
|
||||
#define DRAW_SETPIXEL_BLEND_RGB888 \
|
||||
DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_RGB888 \
|
||||
#define DRAW_SETPIXEL_ADD_RGB888 \
|
||||
DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_RGB888 \
|
||||
#define DRAW_SETPIXEL_MOD_RGB888 \
|
||||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB888 \
|
||||
#define DRAW_SETPIXEL_MUL_RGB888 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
|
|
@ -219,19 +232,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_ARGB8888 \
|
||||
DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_ARGB8888 \
|
||||
#define DRAW_SETPIXEL_BLEND_ARGB8888 \
|
||||
DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_ARGB8888 \
|
||||
#define DRAW_SETPIXEL_ADD_ARGB8888 \
|
||||
DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_ARGB8888 \
|
||||
#define DRAW_SETPIXEL_MOD_ARGB8888 \
|
||||
DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_ARGB8888 \
|
||||
#define DRAW_SETPIXEL_MUL_ARGB8888 \
|
||||
DRAW_SETPIXEL_MUL(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
|
|
@ -257,19 +270,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_RGB \
|
||||
DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_RGB \
|
||||
#define DRAW_SETPIXEL_BLEND_RGB \
|
||||
DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_RGB \
|
||||
#define DRAW_SETPIXEL_ADD_RGB \
|
||||
DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_RGB \
|
||||
#define DRAW_SETPIXEL_MOD_RGB \
|
||||
DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB \
|
||||
#define DRAW_SETPIXEL_MUL_RGB \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
|
|
@ -303,7 +316,6 @@ do { \
|
|||
#define DRAW_SETPIXELXY4_MUL_RGB(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB)
|
||||
|
||||
|
||||
/*
|
||||
* Define draw operators for general RGBA
|
||||
*/
|
||||
|
|
@ -311,19 +323,19 @@ do { \
|
|||
#define DRAW_SETPIXEL_RGBA \
|
||||
DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_BLEND_RGBA \
|
||||
#define DRAW_SETPIXEL_BLEND_RGBA \
|
||||
DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_ADD_RGBA \
|
||||
#define DRAW_SETPIXEL_ADD_RGBA \
|
||||
DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MOD_RGBA \
|
||||
#define DRAW_SETPIXEL_MOD_RGBA \
|
||||
DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGBA \
|
||||
#define DRAW_SETPIXEL_MUL_RGBA \
|
||||
DRAW_SETPIXEL_MUL(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
|
|
@ -349,284 +361,301 @@ do { \
|
|||
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
|
||||
|
||||
/* Horizontal line */
|
||||
#define HLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (x1 <= x2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
length = draw_end ? (x2-x1+1) : (x2-x1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x2; \
|
||||
if (!draw_end) { \
|
||||
++pixel; \
|
||||
} \
|
||||
length = draw_end ? (x1-x2+1) : (x1-x2); \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
++pixel; \
|
||||
} \
|
||||
}
|
||||
#define HLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (x1 <= x2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
length = draw_end ? (x2 - x1 + 1) : (x2 - x1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x2; \
|
||||
if (!draw_end) { \
|
||||
++pixel; \
|
||||
} \
|
||||
length = draw_end ? (x1 - x2 + 1) : (x1 - x2); \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
++pixel; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Vertical line */
|
||||
#define VLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (y1 <= y2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
length = draw_end ? (y2-y1+1) : (y2-y1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y2 * pitch + x1; \
|
||||
if (!draw_end) { \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
length = draw_end ? (y1-y2+1) : (y1-y2); \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
}
|
||||
#define VLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (y1 <= y2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
length = draw_end ? (y2 - y1 + 1) : (y2 - y1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y2 * pitch + x1; \
|
||||
if (!draw_end) { \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
length = draw_end ? (y1 - y2 + 1) : (y1 - y2); \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Diagonal line */
|
||||
#define DLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (y1 <= y2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
if (x1 <= x2) { \
|
||||
++pitch; \
|
||||
} else { \
|
||||
--pitch; \
|
||||
} \
|
||||
length = (y2-y1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y2 * pitch + x2; \
|
||||
if (x2 <= x1) { \
|
||||
++pitch; \
|
||||
} else { \
|
||||
--pitch; \
|
||||
} \
|
||||
if (!draw_end) { \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
length = (y1-y2); \
|
||||
} \
|
||||
if (draw_end) { \
|
||||
++length; \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
}
|
||||
#define DLINE(type, op, draw_end) \
|
||||
{ \
|
||||
int length; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
type *pixel; \
|
||||
if (y1 <= y2) { \
|
||||
pixel = (type *)dst->pixels + y1 * pitch + x1; \
|
||||
if (x1 <= x2) { \
|
||||
++pitch; \
|
||||
} else { \
|
||||
--pitch; \
|
||||
} \
|
||||
length = (y2 - y1); \
|
||||
} else { \
|
||||
pixel = (type *)dst->pixels + y2 * pitch + x2; \
|
||||
if (x2 <= x1) { \
|
||||
++pitch; \
|
||||
} else { \
|
||||
--pitch; \
|
||||
} \
|
||||
if (!draw_end) { \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
length = (y1 - y2); \
|
||||
} \
|
||||
if (draw_end) { \
|
||||
++length; \
|
||||
} \
|
||||
while (length--) { \
|
||||
op; \
|
||||
pixel += pitch; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Bresenham's line algorithm */
|
||||
#define BLINE(x1, y1, x2, y2, op, draw_end) \
|
||||
{ \
|
||||
int i, deltax, deltay, numpixels; \
|
||||
int d, dinc1, dinc2; \
|
||||
int x, xinc1, xinc2; \
|
||||
int y, yinc1, yinc2; \
|
||||
\
|
||||
deltax = ABS(x2 - x1); \
|
||||
deltay = ABS(y2 - y1); \
|
||||
\
|
||||
if (deltax >= deltay) { \
|
||||
numpixels = deltax + 1; \
|
||||
d = (2 * deltay) - deltax; \
|
||||
dinc1 = deltay * 2; \
|
||||
dinc2 = (deltay - deltax) * 2; \
|
||||
xinc1 = 1; \
|
||||
xinc2 = 1; \
|
||||
yinc1 = 0; \
|
||||
yinc2 = 1; \
|
||||
} else { \
|
||||
numpixels = deltay + 1; \
|
||||
d = (2 * deltax) - deltay; \
|
||||
dinc1 = deltax * 2; \
|
||||
dinc2 = (deltax - deltay) * 2; \
|
||||
xinc1 = 0; \
|
||||
xinc2 = 1; \
|
||||
yinc1 = 1; \
|
||||
yinc2 = 1; \
|
||||
} \
|
||||
\
|
||||
if (x1 > x2) { \
|
||||
xinc1 = -xinc1; \
|
||||
xinc2 = -xinc2; \
|
||||
} \
|
||||
if (y1 > y2) { \
|
||||
yinc1 = -yinc1; \
|
||||
yinc2 = -yinc2; \
|
||||
} \
|
||||
\
|
||||
x = x1; \
|
||||
y = y1; \
|
||||
\
|
||||
if (!draw_end) { \
|
||||
--numpixels; \
|
||||
} \
|
||||
for (i = 0; i < numpixels; ++i) { \
|
||||
op(x, y); \
|
||||
if (d < 0) { \
|
||||
d += dinc1; \
|
||||
x += xinc1; \
|
||||
y += yinc1; \
|
||||
} else { \
|
||||
d += dinc2; \
|
||||
x += xinc2; \
|
||||
y += yinc2; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
{ \
|
||||
int i, deltax, deltay, numpixels; \
|
||||
int d, dinc1, dinc2; \
|
||||
int x, xinc1, xinc2; \
|
||||
int y, yinc1, yinc2; \
|
||||
\
|
||||
deltax = ABS(x2 - x1); \
|
||||
deltay = ABS(y2 - y1); \
|
||||
\
|
||||
if (deltax >= deltay) { \
|
||||
numpixels = deltax + 1; \
|
||||
d = (2 * deltay) - deltax; \
|
||||
dinc1 = deltay * 2; \
|
||||
dinc2 = (deltay - deltax) * 2; \
|
||||
xinc1 = 1; \
|
||||
xinc2 = 1; \
|
||||
yinc1 = 0; \
|
||||
yinc2 = 1; \
|
||||
} else { \
|
||||
numpixels = deltay + 1; \
|
||||
d = (2 * deltax) - deltay; \
|
||||
dinc1 = deltax * 2; \
|
||||
dinc2 = (deltax - deltay) * 2; \
|
||||
xinc1 = 0; \
|
||||
xinc2 = 1; \
|
||||
yinc1 = 1; \
|
||||
yinc2 = 1; \
|
||||
} \
|
||||
\
|
||||
if (x1 > x2) { \
|
||||
xinc1 = -xinc1; \
|
||||
xinc2 = -xinc2; \
|
||||
} \
|
||||
if (y1 > y2) { \
|
||||
yinc1 = -yinc1; \
|
||||
yinc2 = -yinc2; \
|
||||
} \
|
||||
\
|
||||
x = x1; \
|
||||
y = y1; \
|
||||
\
|
||||
if (!draw_end) { \
|
||||
--numpixels; \
|
||||
} \
|
||||
for (i = 0; i < numpixels; ++i) { \
|
||||
op(x, y); \
|
||||
if (d < 0) { \
|
||||
d += dinc1; \
|
||||
x += xinc1; \
|
||||
y += yinc1; \
|
||||
} else { \
|
||||
d += dinc2; \
|
||||
x += xinc2; \
|
||||
y += yinc2; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
|
||||
#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
|
||||
{ \
|
||||
Uint16 ErrorAdj, ErrorAcc; \
|
||||
Uint16 ErrorAccTemp, Weighting; \
|
||||
int DeltaX, DeltaY, Temp, XDir; \
|
||||
unsigned r, g, b, a, inva; \
|
||||
\
|
||||
/* Draw the initial pixel, which is always exactly intersected by \
|
||||
the line and so needs no weighting */ \
|
||||
opaque_op(x1, y1); \
|
||||
\
|
||||
/* Draw the final pixel, which is always exactly intersected by the line \
|
||||
and so needs no weighting */ \
|
||||
if (draw_end) { \
|
||||
opaque_op(x2, y2); \
|
||||
} \
|
||||
\
|
||||
/* Make sure the line runs top to bottom */ \
|
||||
if (y1 > y2) { \
|
||||
Temp = y1; y1 = y2; y2 = Temp; \
|
||||
Temp = x1; x1 = x2; x2 = Temp; \
|
||||
} \
|
||||
DeltaY = y2 - y1; \
|
||||
\
|
||||
if ((DeltaX = x2 - x1) >= 0) { \
|
||||
XDir = 1; \
|
||||
} else { \
|
||||
XDir = -1; \
|
||||
DeltaX = -DeltaX; /* make DeltaX positive */ \
|
||||
} \
|
||||
\
|
||||
/* line is not horizontal, diagonal, or vertical */ \
|
||||
ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
|
||||
\
|
||||
/* Is this an X-major or Y-major line? */ \
|
||||
if (DeltaY > DeltaX) { \
|
||||
/* Y-major line; calculate 16-bit fixed-point fractional part of a \
|
||||
pixel that X advances each time Y advances 1 pixel, truncating the \
|
||||
result so that we won't overrun the endpoint along the X axis */ \
|
||||
ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
|
||||
/* Draw all pixels other than the first and last */ \
|
||||
while (--DeltaY) { \
|
||||
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
|
||||
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
|
||||
if (ErrorAcc <= ErrorAccTemp) { \
|
||||
/* The error accumulator turned over, so advance the X coord */ \
|
||||
x1 += XDir; \
|
||||
} \
|
||||
y1++; /* Y-major, so always advance Y */ \
|
||||
/* The IntensityBits most significant bits of ErrorAcc give us the \
|
||||
intensity weighting for this pixel, and the complement of the \
|
||||
weighting for the paired pixel */ \
|
||||
Weighting = ErrorAcc >> 8; \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, (Weighting ^ 255)); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1); \
|
||||
} \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, Weighting); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1 + XDir, y1); \
|
||||
} \
|
||||
} \
|
||||
} else { \
|
||||
/* X-major line; calculate 16-bit fixed-point fractional part of a \
|
||||
pixel that Y advances each time X advances 1 pixel, truncating the \
|
||||
result to avoid overrunning the endpoint along the X axis */ \
|
||||
ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
|
||||
/* Draw all pixels other than the first and last */ \
|
||||
while (--DeltaX) { \
|
||||
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
|
||||
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
|
||||
if (ErrorAcc <= ErrorAccTemp) { \
|
||||
/* The error accumulator turned over, so advance the Y coord */ \
|
||||
y1++; \
|
||||
} \
|
||||
x1 += XDir; /* X-major, so always advance X */ \
|
||||
/* The IntensityBits most significant bits of ErrorAcc give us the \
|
||||
intensity weighting for this pixel, and the complement of the \
|
||||
weighting for the paired pixel */ \
|
||||
Weighting = ErrorAcc >> 8; \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, (Weighting ^ 255)); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1); \
|
||||
} \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, Weighting); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1 + 1); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
|
||||
{ \
|
||||
Uint16 ErrorAdj, ErrorAcc; \
|
||||
Uint16 ErrorAccTemp, Weighting; \
|
||||
int DeltaX, DeltaY, Temp, XDir; \
|
||||
unsigned r, g, b, a, inva; \
|
||||
\
|
||||
/* Draw the initial pixel, which is always exactly intersected by \
|
||||
the line and so needs no weighting */ \
|
||||
opaque_op(x1, y1); \
|
||||
\
|
||||
/* Draw the final pixel, which is always exactly intersected by the line \
|
||||
and so needs no weighting */ \
|
||||
if (draw_end) { \
|
||||
opaque_op(x2, y2); \
|
||||
} \
|
||||
\
|
||||
/* Make sure the line runs top to bottom */ \
|
||||
if (y1 > y2) { \
|
||||
Temp = y1; \
|
||||
y1 = y2; \
|
||||
y2 = Temp; \
|
||||
Temp = x1; \
|
||||
x1 = x2; \
|
||||
x2 = Temp; \
|
||||
} \
|
||||
DeltaY = y2 - y1; \
|
||||
\
|
||||
if ((DeltaX = x2 - x1) >= 0) { \
|
||||
XDir = 1; \
|
||||
} else { \
|
||||
XDir = -1; \
|
||||
DeltaX = -DeltaX; /* make DeltaX positive */ \
|
||||
} \
|
||||
\
|
||||
/* line is not horizontal, diagonal, or vertical */ \
|
||||
ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
|
||||
\
|
||||
/* Is this an X-major or Y-major line? */ \
|
||||
if (DeltaY > DeltaX) { \
|
||||
/* Y-major line; calculate 16-bit fixed-point fractional part of a \
|
||||
pixel that X advances each time Y advances 1 pixel, truncating the \
|
||||
result so that we won't overrun the endpoint along the X axis */ \
|
||||
ErrorAdj = ((unsigned long)DeltaX << 16) / (unsigned long)DeltaY; \
|
||||
/* Draw all pixels other than the first and last */ \
|
||||
while (--DeltaY) { \
|
||||
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
|
||||
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
|
||||
if (ErrorAcc <= ErrorAccTemp) { \
|
||||
/* The error accumulator turned over, so advance the X coord */ \
|
||||
x1 += XDir; \
|
||||
} \
|
||||
y1++; /* Y-major, so always advance Y */ \
|
||||
/* The IntensityBits most significant bits of ErrorAcc give us the \
|
||||
intensity weighting for this pixel, and the complement of the \
|
||||
weighting for the paired pixel */ \
|
||||
Weighting = ErrorAcc >> 8; \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, (Weighting ^ 255)); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1); \
|
||||
} \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, Weighting); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1 + XDir, y1); \
|
||||
} \
|
||||
} \
|
||||
} else { \
|
||||
/* X-major line; calculate 16-bit fixed-point fractional part of a \
|
||||
pixel that Y advances each time X advances 1 pixel, truncating the \
|
||||
result to avoid overrunning the endpoint along the X axis */ \
|
||||
ErrorAdj = ((unsigned long)DeltaY << 16) / (unsigned long)DeltaX; \
|
||||
/* Draw all pixels other than the first and last */ \
|
||||
while (--DeltaX) { \
|
||||
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
|
||||
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
|
||||
if (ErrorAcc <= ErrorAccTemp) { \
|
||||
/* The error accumulator turned over, so advance the Y coord */ \
|
||||
y1++; \
|
||||
} \
|
||||
x1 += XDir; /* X-major, so always advance X */ \
|
||||
/* The IntensityBits most significant bits of ErrorAcc give us the \
|
||||
intensity weighting for this pixel, and the complement of the \
|
||||
weighting for the paired pixel */ \
|
||||
Weighting = ErrorAcc >> 8; \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, (Weighting ^ 255)); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1); \
|
||||
} \
|
||||
{ \
|
||||
a = DRAW_MUL(_a, Weighting); \
|
||||
r = DRAW_MUL(_r, a); \
|
||||
g = DRAW_MUL(_g, a); \
|
||||
b = DRAW_MUL(_b, a); \
|
||||
inva = (a ^ 0xFF); \
|
||||
blend_op(x1, y1 + 1); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef AA_LINES
|
||||
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
|
||||
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
|
||||
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
|
||||
#else
|
||||
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
|
||||
BLINE(x1, y1, x2, y2, opaque_op, draw_end)
|
||||
BLINE(x1, y1, x2, y2, opaque_op, draw_end)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define fill rect macro
|
||||
*/
|
||||
|
||||
#define FILLRECT(type, op) \
|
||||
do { \
|
||||
int width = rect->w; \
|
||||
int height = rect->h; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
int skip = pitch - width; \
|
||||
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
|
||||
while (height--) { \
|
||||
{ int n = (width+3)/4; \
|
||||
switch (width & 3) { \
|
||||
case 0: do { op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 3: op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 2: op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 1: op; pixel++; \
|
||||
} while ( --n > 0 ); \
|
||||
} \
|
||||
} \
|
||||
pixel += skip; \
|
||||
} \
|
||||
} while (0)
|
||||
#define FILLRECT(type, op) \
|
||||
do { \
|
||||
int width = rect->w; \
|
||||
int height = rect->h; \
|
||||
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
|
||||
int skip = pitch - width; \
|
||||
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
|
||||
while (height--) { \
|
||||
{ \
|
||||
int n = (width + 3) / 4; \
|
||||
switch (width & 3) { \
|
||||
case 0: \
|
||||
do { \
|
||||
op; \
|
||||
pixel++; \
|
||||
SDL_FALLTHROUGH; \
|
||||
case 3: \
|
||||
op; \
|
||||
pixel++; \
|
||||
SDL_FALLTHROUGH; \
|
||||
case 2: \
|
||||
op; \
|
||||
pixel++; \
|
||||
SDL_FALLTHROUGH; \
|
||||
case 1: \
|
||||
op; \
|
||||
pixel++; \
|
||||
} while (--n > 0); \
|
||||
} \
|
||||
} \
|
||||
pixel += skip; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,10 +26,8 @@
|
|||
#include "SDL_drawline.h"
|
||||
#include "SDL_drawpoint.h"
|
||||
|
||||
|
||||
static void
|
||||
SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
if (y1 == y2) {
|
||||
int length;
|
||||
|
|
@ -37,13 +35,13 @@ SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
Uint8 *pixel;
|
||||
if (x1 <= x2) {
|
||||
pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
|
||||
length = draw_end ? (x2-x1+1) : (x2-x1);
|
||||
length = draw_end ? (x2 - x1 + 1) : (x2 - x1);
|
||||
} else {
|
||||
pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
|
||||
if (!draw_end) {
|
||||
++pixel;
|
||||
}
|
||||
length = draw_end ? (x1-x2+1) : (x1-x2);
|
||||
length = draw_end ? (x1 - x2 + 1) : (x1 - x2);
|
||||
}
|
||||
SDL_memset(pixel, color, length);
|
||||
} else if (x1 == x2) {
|
||||
|
|
@ -55,9 +53,8 @@ SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
if (y1 == y2) {
|
||||
HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
|
||||
|
|
@ -67,7 +64,7 @@ SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
|
||||
} else {
|
||||
Uint8 _r, _g, _b, _a;
|
||||
const SDL_PixelFormat * fmt = dst->format;
|
||||
const SDL_PixelFormat *fmt = dst->format;
|
||||
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
|
||||
if (fmt->Rmask == 0x7C00) {
|
||||
AALINE(x1, y1, x2, y2,
|
||||
|
|
@ -85,9 +82,8 @@ SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color,
|
||||
SDL_bool draw_end)
|
||||
{
|
||||
if (y1 == y2) {
|
||||
HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
|
||||
|
|
@ -97,7 +93,7 @@ SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
|
||||
} else {
|
||||
Uint8 _r, _g, _b, _a;
|
||||
const SDL_PixelFormat * fmt = dst->format;
|
||||
const SDL_PixelFormat *fmt = dst->format;
|
||||
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
|
||||
if (fmt->Rmask == 0x00FF0000) {
|
||||
if (!fmt->Amask) {
|
||||
|
|
@ -117,12 +113,11 @@ SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
|
|||
}
|
||||
}
|
||||
|
||||
typedef void (*DrawLineFunc) (SDL_Surface * dst,
|
||||
int x1, int y1, int x2, int y2,
|
||||
Uint32 color, SDL_bool draw_end);
|
||||
typedef void (*DrawLineFunc)(SDL_Surface *dst,
|
||||
int x1, int y1, int x2, int y2,
|
||||
Uint32 color, SDL_bool draw_end);
|
||||
|
||||
static DrawLineFunc
|
||||
SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
|
||||
static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
|
||||
{
|
||||
switch (fmt->BytesPerPixel) {
|
||||
case 1:
|
||||
|
|
@ -138,17 +133,16 @@ SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
||||
int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
|
||||
{
|
||||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +156,8 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
Uint32 color)
|
||||
int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
|
||||
Uint32 color)
|
||||
{
|
||||
int i;
|
||||
int x1, y1;
|
||||
|
|
@ -172,18 +165,18 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
SDL_bool draw_end;
|
||||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawLines(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
if (!func) {
|
||||
if (func == NULL) {
|
||||
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
|
||||
}
|
||||
|
||||
for (i = 1; i < count; ++i) {
|
||||
x1 = points[i-1].x;
|
||||
y1 = points[i-1].y;
|
||||
x1 = points[i - 1].x;
|
||||
y1 = points[i - 1].y;
|
||||
x2 = points[i].x;
|
||||
y2 = points[i].y;
|
||||
|
||||
|
|
@ -198,8 +191,8 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
|
||||
func(dst, x1, y1, x2, y2, color, draw_end);
|
||||
}
|
||||
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
|
||||
SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
|
||||
if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
|
||||
SDL_DrawPoint(dst, points[count - 1].x, points[count - 1].y, color);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
|
||||
extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
|
||||
extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
|
||||
extern int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color);
|
||||
extern int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
|
||||
|
||||
#endif /* SDL_drawline_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,11 +25,9 @@
|
|||
#include "SDL_draw.h"
|
||||
#include "SDL_drawpoint.h"
|
||||
|
||||
|
||||
int
|
||||
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
||||
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
|
||||
{
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
|
||||
}
|
||||
|
||||
|
|
@ -61,16 +59,15 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
||||
Uint32 color)
|
||||
int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
|
||||
Uint32 color)
|
||||
{
|
||||
int minx, miny;
|
||||
int maxx, maxy;
|
||||
int i;
|
||||
int x, y;
|
||||
|
||||
if (!dst) {
|
||||
if (dst == NULL) {
|
||||
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,9 +24,8 @@
|
|||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
|
||||
extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color);
|
||||
extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
|
||||
extern int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color);
|
||||
extern int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
|
||||
|
||||
#endif /* SDL_drawpoint_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -50,11 +50,9 @@ typedef struct
|
|||
SDL_Surface *window;
|
||||
} SW_RenderData;
|
||||
|
||||
|
||||
static SDL_Surface *
|
||||
SW_ActivateRenderer(SDL_Renderer * renderer)
|
||||
static SDL_Surface *SW_ActivateRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
if (!data->surface) {
|
||||
data->surface = data->window;
|
||||
|
|
@ -68,10 +66,9 @@ SW_ActivateRenderer(SDL_Renderer * renderer)
|
|||
return data->surface;
|
||||
}
|
||||
|
||||
static void
|
||||
SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
||||
static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||
data->surface = NULL;
|
||||
|
|
@ -79,10 +76,9 @@ SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
|
||||
static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
if (data->surface) {
|
||||
if (w) {
|
||||
|
|
@ -95,21 +91,19 @@ SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
|
|||
}
|
||||
|
||||
if (renderer->window) {
|
||||
SDL_GetWindowSize(renderer->window, w, h);
|
||||
SDL_GetWindowSizeInPixels(renderer->window, w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SDL_SetError("Software renderer doesn't have an output surface");
|
||||
}
|
||||
|
||||
static int
|
||||
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
int bpp;
|
||||
Uint32 Rmask, Gmask, Bmask, Amask;
|
||||
|
||||
if (!SDL_PixelFormatEnumToMasks
|
||||
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
||||
if (!SDL_PixelFormatEnumToMasks(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
|
||||
return SDL_SetError("Unknown texture format");
|
||||
}
|
||||
|
||||
|
|
@ -133,81 +127,76 @@ SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, const void *pixels, int pitch)
|
||||
static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
const SDL_Rect *rect, const void *pixels, int pitch)
|
||||
{
|
||||
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
|
||||
Uint8 *src, *dst;
|
||||
int row;
|
||||
size_t length;
|
||||
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
if (SDL_MUSTLOCK(surface)) {
|
||||
SDL_LockSurface(surface);
|
||||
src = (Uint8 *) pixels;
|
||||
dst = (Uint8 *) surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel;
|
||||
length = rect->w * surface->format->BytesPerPixel;
|
||||
}
|
||||
src = (Uint8 *)pixels;
|
||||
dst = (Uint8 *)surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel;
|
||||
length = (size_t)rect->w * surface->format->BytesPerPixel;
|
||||
for (row = 0; row < rect->h; ++row) {
|
||||
SDL_memcpy(dst, src, length);
|
||||
src += pitch;
|
||||
dst += surface->pitch;
|
||||
}
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
if (SDL_MUSTLOCK(surface)) {
|
||||
SDL_UnlockSurface(surface);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, void **pixels, int *pitch)
|
||||
static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
const SDL_Rect *rect, void **pixels, int *pitch)
|
||||
{
|
||||
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
|
||||
|
||||
*pixels =
|
||||
(void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel);
|
||||
(void *)((Uint8 *)surface->pixels + rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel);
|
||||
*pitch = surface->pitch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
static void SW_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
if (texture) {
|
||||
data->surface = (SDL_Surface *) texture->driverdata;
|
||||
data->surface = (SDL_Surface *)texture->driverdata;
|
||||
} else {
|
||||
data->surface = data->window;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
|
||||
static int SW_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
return 0; /* nothing to do in this backend. */
|
||||
return 0; /* nothing to do in this backend. */
|
||||
}
|
||||
|
||||
static int
|
||||
SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
|
||||
{
|
||||
SDL_Point *verts = (SDL_Point *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Point), 0, &cmd->data.draw.first);
|
||||
SDL_Point *verts = (SDL_Point *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Point), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -221,13 +210,12 @@ SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
|
||||
{
|
||||
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, count * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
|
||||
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -243,19 +231,18 @@ SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRe
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
||||
static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const SDL_Rect *srcrect, const SDL_FRect *dstrect)
|
||||
{
|
||||
SDL_Rect *verts = (SDL_Rect *) SDL_AllocateRenderVertices(renderer, 2 * sizeof (SDL_Rect), 0, &cmd->data.draw.first);
|
||||
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
SDL_memcpy(verts, srcrect, sizeof (SDL_Rect));
|
||||
SDL_copyp(verts, srcrect);
|
||||
verts++;
|
||||
|
||||
verts->x = (int)dstrect->x;
|
||||
|
|
@ -277,27 +264,26 @@ typedef struct CopyExData
|
|||
float scale_y;
|
||||
} CopyExData;
|
||||
|
||||
static int
|
||||
SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const SDL_Rect *srcrect, const SDL_FRect *dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
{
|
||||
CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first);
|
||||
CopyExData *verts = (CopyExData *)SDL_AllocateRenderVertices(renderer, sizeof(CopyExData), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
SDL_memcpy(&verts->srcrect, srcrect, sizeof (SDL_Rect));
|
||||
SDL_copyp(&verts->srcrect, srcrect);
|
||||
|
||||
verts->dstrect.x = (int)dstrect->x;
|
||||
verts->dstrect.y = (int)dstrect->y;
|
||||
verts->dstrect.w = (int)dstrect->w;
|
||||
verts->dstrect.h = (int)dstrect->h;
|
||||
verts->angle = angle;
|
||||
SDL_memcpy(&verts->center, center, sizeof (SDL_FPoint));
|
||||
SDL_copyp(&verts->center, center);
|
||||
verts->flip = flip;
|
||||
verts->scale_x = scale_x;
|
||||
verts->scale_y = scale_y;
|
||||
|
|
@ -305,18 +291,17 @@ SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
|
||||
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
|
||||
static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
|
||||
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
int retval;
|
||||
/* Renderer scaling, if needed */
|
||||
if (scale_x != 1.0f || scale_y != 1.0f) {
|
||||
SDL_Rect r;
|
||||
r.x = (int)((float) dstrect->x * scale_x);
|
||||
r.y = (int)((float) dstrect->y * scale_y);
|
||||
r.w = (int)((float) dstrect->w * scale_x);
|
||||
r.h = (int)((float) dstrect->h * scale_y);
|
||||
r.x = (int)((float)dstrect->x * scale_x);
|
||||
r.y = (int)((float)dstrect->y * scale_y);
|
||||
r.w = (int)((float)dstrect->w * scale_x);
|
||||
r.h = (int)((float)dstrect->h * scale_y);
|
||||
retval = SDL_PrivateUpperBlitScaled(src, srcrect, surface, &r, scaleMode);
|
||||
} else {
|
||||
retval = SDL_BlitSurface(src, srcrect, surface, dstrect);
|
||||
|
|
@ -324,12 +309,11 @@ Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Re
|
|||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_Rect * final_rect,
|
||||
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture,
|
||||
const SDL_Rect *srcrect, const SDL_Rect *final_rect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
{
|
||||
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Surface *src = (SDL_Surface *)texture->driverdata;
|
||||
SDL_Rect tmp_rect;
|
||||
SDL_Surface *src_clone, *src_rotated, *src_scaled;
|
||||
SDL_Surface *mask = NULL, *mask_rotated = NULL;
|
||||
|
|
@ -340,7 +324,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
int blitRequired = SDL_FALSE;
|
||||
int isOpaque = SDL_FALSE;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -439,18 +423,18 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
double cangle, sangle;
|
||||
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, center,
|
||||
&rect_dest, &cangle, &sangle);
|
||||
&rect_dest, &cangle, &sangle);
|
||||
src_rotated = SDLgfx_rotateSurface(src_clone, angle,
|
||||
(texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
(texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (src_rotated == NULL) {
|
||||
retval = -1;
|
||||
}
|
||||
if (!retval && mask != NULL) {
|
||||
/* The mask needed for the NONE blend mode gets rotated with the same parameters. */
|
||||
mask_rotated = SDLgfx_rotateSurface(mask, angle,
|
||||
SDL_FALSE, 0, 0,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
SDL_FALSE, 0, 0,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (mask_rotated == NULL) {
|
||||
retval = -1;
|
||||
}
|
||||
|
|
@ -533,7 +517,6 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
typedef struct GeometryFillData
|
||||
{
|
||||
SDL_Point dst;
|
||||
|
|
@ -547,19 +530,18 @@ typedef struct GeometryCopyData
|
|||
SDL_Color color;
|
||||
} GeometryCopyData;
|
||||
|
||||
static int
|
||||
SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
void *verts;
|
||||
int sz = texture ? sizeof (GeometryCopyData) : sizeof (GeometryFillData);
|
||||
size_t sz = texture != NULL ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
|
||||
|
||||
verts = (void *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -567,7 +549,7 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
if (texture) {
|
||||
GeometryCopyData *ptr = (GeometryCopyData *) verts;
|
||||
GeometryCopyData *ptr = (GeometryCopyData *)verts;
|
||||
for (i = 0; i < count; i++) {
|
||||
int j;
|
||||
float *xy_;
|
||||
|
|
@ -583,10 +565,10 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
j = i;
|
||||
}
|
||||
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
xy_ = (float *)((char *)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char *)color + j * color_stride);
|
||||
|
||||
uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
uv_ = (float *)((char *)uv + j * uv_stride);
|
||||
|
||||
ptr->src.x = (int)(uv_[0] * texture->w);
|
||||
ptr->src.y = (int)(uv_[1] * texture->h);
|
||||
|
|
@ -598,9 +580,9 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
ptr->color = col_;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GeometryFillData *ptr = (GeometryFillData *) verts;
|
||||
GeometryFillData *ptr = (GeometryFillData *)verts;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int j;
|
||||
|
|
@ -616,8 +598,8 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
j = i;
|
||||
}
|
||||
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
xy_ = (float *)((char *)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char *)color + j * color_stride);
|
||||
|
||||
ptr->dst.x = (int)(xy_[0] * scale_x);
|
||||
ptr->dst.y = (int)(xy_[1] * scale_y);
|
||||
|
|
@ -626,13 +608,12 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
|
|||
ptr->color = col_;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
||||
static void PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
||||
{
|
||||
const Uint8 r = cmd->data.draw.r;
|
||||
const Uint8 g = cmd->data.draw.g;
|
||||
|
|
@ -640,7 +621,7 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
|||
const Uint8 a = cmd->data.draw.a;
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
|
||||
const SDL_bool colormod = ((r & g & b) != 0xFF);
|
||||
const SDL_bool alphamod = (a != 0xFF);
|
||||
const SDL_bool blending = ((blend == SDL_BLENDMODE_ADD) || (blend == SDL_BLENDMODE_MOD) || (blend == SDL_BLENDMODE_MUL));
|
||||
|
|
@ -655,13 +636,12 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
|||
SDL_SetSurfaceBlendMode(surface, blend);
|
||||
}
|
||||
|
||||
static void
|
||||
SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
|
||||
static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
|
||||
{
|
||||
if (drawstate->surface_cliprect_dirty) {
|
||||
const SDL_Rect *viewport = drawstate->viewport;
|
||||
const SDL_Rect *cliprect = drawstate->cliprect;
|
||||
SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
|
||||
SDL_assert_release(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
|
||||
|
||||
if (cliprect != NULL) {
|
||||
SDL_Rect clip_rect;
|
||||
|
|
@ -678,13 +658,12 @@ SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
{
|
||||
SDL_Surface *surface = SW_ActivateRenderer(renderer);
|
||||
SW_DrawStateCache drawstate;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -733,7 +712,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -760,7 +739,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -787,7 +766,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
|
|
@ -815,7 +794,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
dstrect->x += drawstate.viewport->x;
|
||||
dstrect->y += drawstate.viewport->y;
|
||||
}
|
||||
|
|
@ -873,7 +852,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
copydata->dstrect.x += drawstate.viewport->x;
|
||||
copydata->dstrect.y += drawstate.viewport->y;
|
||||
}
|
||||
|
|
@ -901,7 +880,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
|
|
@ -924,7 +903,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
GeometryFillData *ptr = (GeometryFillData *) verts;
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
if (drawstate.viewport != NULL && (drawstate.viewport->x || drawstate.viewport->y)) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
|
|
@ -952,15 +931,14 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
Uint32 format, void * pixels, int pitch)
|
||||
static int SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
Uint32 format, void *pixels, int pitch)
|
||||
{
|
||||
SDL_Surface *surface = SW_ActivateRenderer(renderer);
|
||||
Uint32 src_format;
|
||||
void *src_pixels;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -968,67 +946,64 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
* SDL_RenderReadPixels.
|
||||
*/
|
||||
|
||||
if (rect->x < 0 || rect->x+rect->w > surface->w ||
|
||||
rect->y < 0 || rect->y+rect->h > surface->h) {
|
||||
if (rect->x < 0 || rect->x + rect->w > surface->w ||
|
||||
rect->y < 0 || rect->y + rect->h > surface->h) {
|
||||
return SDL_SetError("Tried to read outside of surface bounds");
|
||||
}
|
||||
|
||||
src_format = surface->format->format;
|
||||
src_pixels = (void*)((Uint8 *) surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel);
|
||||
src_pixels = (void *)((Uint8 *)surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel);
|
||||
|
||||
return SDL_ConvertPixels(rect->w, rect->h,
|
||||
src_format, src_pixels, surface->pitch,
|
||||
format, pixels, pitch);
|
||||
}
|
||||
|
||||
static void
|
||||
SW_RenderPresent(SDL_Renderer * renderer)
|
||||
static int SW_RenderPresent(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_Window *window = renderer->window;
|
||||
|
||||
if (window) {
|
||||
SDL_UpdateWindowSurface(window);
|
||||
if (window == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
static void
|
||||
SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
static void SW_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Surface *surface = (SDL_Surface *)texture->driverdata;
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
static void
|
||||
SW_DestroyRenderer(SDL_Renderer * renderer)
|
||||
static void SW_DestroyRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
SW_RenderData *data = (SW_RenderData *)renderer->driverdata;
|
||||
|
||||
SDL_free(data);
|
||||
SDL_free(renderer);
|
||||
}
|
||||
|
||||
SDL_Renderer *
|
||||
SW_CreateRendererForSurface(SDL_Surface * surface)
|
||||
SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
SW_RenderData *data;
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
SDL_InvalidParamError("surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
|
||||
if (renderer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
|
||||
if (!data) {
|
||||
data = (SW_RenderData *)SDL_calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
SW_DestroyRenderer(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
|
|
@ -1045,9 +1020,9 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
renderer->SetTextureScaleMode = SW_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = SW_SetRenderTarget;
|
||||
renderer->QueueSetViewport = SW_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = SW_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = SW_QueueDrawPoints; /* lines and points queue vertices the same way. */
|
||||
renderer->QueueDrawLines = SW_QueueDrawPoints; /* lines and points queue vertices the same way. */
|
||||
renderer->QueueFillRects = SW_QueueFillRects;
|
||||
renderer->QueueCopy = SW_QueueCopy;
|
||||
renderer->QueueCopyEx = SW_QueueCopyEx;
|
||||
|
|
@ -1065,8 +1040,7 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
return renderer;
|
||||
}
|
||||
|
||||
static SDL_Renderer *
|
||||
SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
static SDL_Renderer *SW_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
{
|
||||
const char *hint;
|
||||
SDL_Surface *surface;
|
||||
|
|
@ -1074,7 +1048,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
/* Set the vsync hint based on our flags, if it's not already set */
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
||||
if (!hint || !*hint) {
|
||||
if (hint == NULL || !*hint) {
|
||||
no_hint_set = SDL_TRUE;
|
||||
} else {
|
||||
no_hint_set = SDL_FALSE;
|
||||
|
|
@ -1091,7 +1065,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
|
||||
}
|
||||
|
||||
if (!surface) {
|
||||
if (surface == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return SW_CreateRendererForSurface(surface);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
#ifndef SDL_render_sw_c_h_
|
||||
#define SDL_render_sw_c_h_
|
||||
|
||||
extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface);
|
||||
extern SDL_Renderer *SW_CreateRendererForSurface(SDL_Surface *surface);
|
||||
|
||||
#endif /* SDL_render_sw_c_h_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
|
|||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#if defined(__WIN32__) || defined(__GDK__)
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -47,7 +47,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
|
|||
/* !
|
||||
\brief A 32 bit RGBA pixel.
|
||||
*/
|
||||
typedef struct tColorRGBA {
|
||||
typedef struct tColorRGBA
|
||||
{
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
|
|
@ -57,7 +58,8 @@ typedef struct tColorRGBA {
|
|||
/* !
|
||||
\brief A 8bit Y/palette pixel.
|
||||
*/
|
||||
typedef struct tColorY {
|
||||
typedef struct tColorY
|
||||
{
|
||||
Uint8 y;
|
||||
} tColorY;
|
||||
|
||||
|
|
@ -76,8 +78,7 @@ to a situation where the program can segfault.
|
|||
/* !
|
||||
\brief Returns colorkey info for a surface
|
||||
*/
|
||||
static Uint32
|
||||
get_colorkey(SDL_Surface *src)
|
||||
static Uint32 get_colorkey(SDL_Surface *src)
|
||||
{
|
||||
Uint32 key = 0;
|
||||
if (SDL_HasColorKey(src)) {
|
||||
|
|
@ -87,8 +88,8 @@ get_colorkey(SDL_Surface *src)
|
|||
}
|
||||
|
||||
/* rotate (sx, sy) by (angle, center) into (dx, dy) */
|
||||
static void
|
||||
rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy) {
|
||||
static void rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy)
|
||||
{
|
||||
sx -= center->x;
|
||||
sy -= center->y;
|
||||
|
||||
|
|
@ -111,9 +112,8 @@ rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint
|
|||
\param sangle The cosine of the angle
|
||||
|
||||
*/
|
||||
void
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle)
|
||||
void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle)
|
||||
{
|
||||
int minx, maxx, miny, maxy;
|
||||
double radangle;
|
||||
|
|
@ -129,16 +129,16 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
|||
/*
|
||||
* Determine destination width and height by rotating a source box, at pixel center
|
||||
*/
|
||||
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
|
||||
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
|
||||
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
|
||||
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
|
||||
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
|
||||
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
|
||||
rotate(width - 0.5, height - 0.5, sinangle, cosangle, center, &x3, &y3);
|
||||
|
||||
minx = (int)SDL_floor( SDL_min( SDL_min(x0, x1), SDL_min(x2, x3) ) );
|
||||
maxx = (int)SDL_ceil( SDL_max( SDL_max(x0, x1), SDL_max(x2, x3) ) );
|
||||
minx = (int)SDL_floor(SDL_min(SDL_min(x0, x1), SDL_min(x2, x3)));
|
||||
maxx = (int)SDL_ceil(SDL_max(SDL_max(x0, x1), SDL_max(x2, x3)));
|
||||
|
||||
miny = (int)SDL_floor( SDL_min( SDL_min(y0, y1), SDL_min(y2, y3) ) );
|
||||
maxy = (int)SDL_ceil( SDL_max( SDL_max(y0, y1), SDL_max(y2, y3) ) );
|
||||
miny = (int)SDL_floor(SDL_min(SDL_min(y0, y1), SDL_min(y2, y3)));
|
||||
maxy = (int)SDL_ceil(SDL_max(SDL_max(y0, y1), SDL_max(y2, y3)));
|
||||
|
||||
rect_dest->w = maxx - minx;
|
||||
rect_dest->h = maxy - miny;
|
||||
|
|
@ -151,17 +151,20 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
|||
|
||||
{
|
||||
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle/90);
|
||||
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle / 90);
|
||||
if (angle90 == angle / 90) { /* if the angle is a multiple of 90 degrees */
|
||||
angle90 %= 4;
|
||||
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if(angle90 & 1) {
|
||||
rect_dest->w = height;
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
}
|
||||
|
||||
if (angle90 & 1) {
|
||||
rect_dest->w = height;
|
||||
rect_dest->h = width;
|
||||
*cangle = 0;
|
||||
*sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
|
||||
} else {
|
||||
rect_dest->w = width;
|
||||
rect_dest->w = width;
|
||||
rect_dest->h = height;
|
||||
*cangle = angle90 == 0 ? 1 : -1;
|
||||
*sangle = 0;
|
||||
|
|
@ -171,19 +174,37 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
|||
}
|
||||
|
||||
/* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
|
||||
static void
|
||||
computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
|
||||
int *sincx, int *sincy, int *signx, int *signy)
|
||||
static void computeSourceIncrements90(SDL_Surface *src, int bpp, int angle, int flipx, int flipy,
|
||||
int *sincx, int *sincy, int *signx, int *signy)
|
||||
{
|
||||
int pitch = flipy ? -src->pitch : src->pitch;
|
||||
if (flipx) {
|
||||
bpp = -bpp;
|
||||
}
|
||||
switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
|
||||
case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
|
||||
case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
|
||||
case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
|
||||
case 0:
|
||||
*sincx = bpp;
|
||||
*sincy = pitch - src->w * *sincx;
|
||||
*signx = *signy = 1;
|
||||
break;
|
||||
case 1:
|
||||
*sincx = -pitch;
|
||||
*sincy = bpp - *sincx * src->h;
|
||||
*signx = 1;
|
||||
*signy = -1;
|
||||
break;
|
||||
case 2:
|
||||
*sincx = -bpp;
|
||||
*sincy = -src->w * *sincx - pitch;
|
||||
*signx = *signy = -1;
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
*sincx = pitch;
|
||||
*sincy = -*sincx * src->h - bpp;
|
||||
*signx = -1;
|
||||
*signy = 1;
|
||||
break;
|
||||
}
|
||||
if (flipx) {
|
||||
*signx = -*signx;
|
||||
|
|
@ -194,34 +215,34 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int
|
|||
}
|
||||
|
||||
/* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
|
||||
#define TRANSFORM_SURFACE_90(pixelType) \
|
||||
int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
|
||||
Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
|
||||
#define TRANSFORM_SURFACE_90(pixelType) \
|
||||
int dy, dincy = dst->pitch - dst->w * sizeof(pixelType), sincx, sincy, signx, signy; \
|
||||
Uint8 *sp = (Uint8 *)src->pixels, *dp = (Uint8 *)dst->pixels, *de; \
|
||||
\
|
||||
computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
|
||||
if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
|
||||
if (signy < 0) sp += (src->h-1)*src->pitch; \
|
||||
if (signx < 0) \
|
||||
sp += (src->w - 1) * sizeof(pixelType); \
|
||||
if (signy < 0) \
|
||||
sp += (src->h - 1) * src->pitch; \
|
||||
\
|
||||
for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
|
||||
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use SDL_memcpy */ \
|
||||
SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
|
||||
sp += dst->w*sizeof(pixelType); \
|
||||
dp += dst->w*sizeof(pixelType); \
|
||||
SDL_memcpy(dp, sp, dst->w * sizeof(pixelType)); \
|
||||
sp += dst->w * sizeof(pixelType); \
|
||||
dp += dst->w * sizeof(pixelType); \
|
||||
} else { \
|
||||
for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
|
||||
*(pixelType*)dp = *(pixelType*)sp; \
|
||||
for (de = dp + dst->w * sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
|
||||
*(pixelType *)dp = *(pixelType *)sp; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
static void
|
||||
transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
|
||||
static void transformSurfaceRGBA90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
|
||||
{
|
||||
TRANSFORM_SURFACE_90(tColorRGBA);
|
||||
}
|
||||
|
||||
static void
|
||||
transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
|
||||
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
|
||||
{
|
||||
TRANSFORM_SURFACE_90(tColorY);
|
||||
}
|
||||
|
|
@ -247,32 +268,31 @@ Assumes dst surface was allocated with the correct dimensions.
|
|||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
int flipx, int flipy, int smooth,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
static void transformSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst, int isin, int icos,
|
||||
int flipx, int flipy, int smooth,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorRGBA c00, c01, c10, c11, cswap;
|
||||
tColorRGBA *pc, *sp;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
const int fp_half = (1 << 15);
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
* Variable setup
|
||||
*/
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorRGBA*) dst->pixels;
|
||||
pc = (tColorRGBA *)dst->pixels;
|
||||
gap = dst->pitch - dst->w * 4;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Switch between interpolating and non-interpolating code
|
||||
*/
|
||||
* Switch between interpolating and non-interpolating code
|
||||
*/
|
||||
if (smooth) {
|
||||
int y;
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
|
|
@ -284,30 +304,42 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
|||
for (x = 0; x < dst->w; x++) {
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh - dy;
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w - 1)) && (dy < (src->h - 1))) {
|
||||
int ex, ey;
|
||||
int t1, t2;
|
||||
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
|
||||
sp = (tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx;
|
||||
c00 = *sp;
|
||||
sp += 1;
|
||||
c01 = *sp;
|
||||
sp += (src->pitch/4);
|
||||
sp += (src->pitch / 4);
|
||||
c11 = *sp;
|
||||
sp -= 1;
|
||||
c10 = *sp;
|
||||
if (flipx) {
|
||||
cswap = c00; c00=c01; c01=cswap;
|
||||
cswap = c10; c10=c11; c11=cswap;
|
||||
cswap = c00;
|
||||
c00 = c01;
|
||||
c01 = cswap;
|
||||
cswap = c10;
|
||||
c10 = c11;
|
||||
c11 = cswap;
|
||||
}
|
||||
if (flipy) {
|
||||
cswap = c00; c00=c10; c10=cswap;
|
||||
cswap = c01; c01=c11; c11=cswap;
|
||||
cswap = c00;
|
||||
c00 = c10;
|
||||
c10 = cswap;
|
||||
cswap = c01;
|
||||
c01 = c11;
|
||||
c11 = cswap;
|
||||
}
|
||||
/*
|
||||
* Interpolate colors
|
||||
*/
|
||||
* Interpolate colors
|
||||
*/
|
||||
ex = (sdx & 0xffff);
|
||||
ey = (sdy & 0xffff);
|
||||
t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
|
||||
|
|
@ -327,7 +359,7 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
|||
sdy += isin;
|
||||
pc++;
|
||||
}
|
||||
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||
pc = (tColorRGBA *)((Uint8 *)pc + gap);
|
||||
}
|
||||
} else {
|
||||
int y;
|
||||
|
|
@ -341,15 +373,19 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
|||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if(flipx) dx = sw - dx;
|
||||
if(flipy) dy = sh - dy;
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
*pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
|
||||
}
|
||||
sdx += icos;
|
||||
sdy += isin;
|
||||
pc++;
|
||||
}
|
||||
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||
pc = (tColorRGBA *)((Uint8 *)pc + gap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -372,35 +408,34 @@ Assumes dst surface was allocated with the correct dimensions.
|
|||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int isin, int icos, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorY *pc;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
const int fp_half = (1 << 15);
|
||||
int y;
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
* Variable setup
|
||||
*/
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorY*) dst->pixels;
|
||||
pc = (tColorY *)dst->pixels;
|
||||
gap = dst->pitch - dst->w;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), (size_t)dst->pitch * dst->h);
|
||||
/*
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
int x;
|
||||
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
|
||||
|
|
@ -411,8 +446,12 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
|
|||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh- dy;
|
||||
if (flipx) {
|
||||
dx = sw - dx;
|
||||
}
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
*pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
|
||||
}
|
||||
sdx += icos;
|
||||
|
|
@ -423,7 +462,6 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
|
||||
|
||||
|
|
@ -450,9 +488,8 @@ When using the NONE and MOD modes, color and alpha modulation must be applied be
|
|||
|
||||
*/
|
||||
|
||||
SDL_Surface *
|
||||
SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
|
||||
SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
|
||||
{
|
||||
SDL_Surface *rz_dst;
|
||||
int is8bit, angle90;
|
||||
|
|
@ -463,8 +500,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
|||
double sangleinv, cangleinv;
|
||||
|
||||
/* Sanity check */
|
||||
if (src == NULL)
|
||||
if (src == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (SDL_HasColorKey(src)) {
|
||||
if (SDL_GetColorKey(src, &colorkey) == 0) {
|
||||
|
|
@ -473,12 +511,13 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
|||
}
|
||||
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
|
||||
is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
|
||||
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
|
||||
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Calculate target factors from sine/cosine and zoom */
|
||||
sangleinv = sangle*65536.0;
|
||||
cangleinv = cangle*65536.0;
|
||||
sangleinv = sangle * 65536.0;
|
||||
cangleinv = cangle * 65536.0;
|
||||
|
||||
/* Alloc space to completely contain the rotated surface */
|
||||
rz_dst = NULL;
|
||||
|
|
@ -501,8 +540,9 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
|||
}
|
||||
|
||||
/* Check target */
|
||||
if (rz_dst == NULL)
|
||||
if (rz_dst == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Adjust for guard rows */
|
||||
rz_dst->h = rect_dest->h;
|
||||
|
|
@ -539,17 +579,20 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
|||
* the off-by-one problem in transformSurfaceRGBA that expresses itself when the rotation is near
|
||||
* multiples of 90 degrees.
|
||||
*/
|
||||
angle90 = (int)(angle/90);
|
||||
if (angle90 == angle/90) {
|
||||
angle90 = (int)(angle / 90);
|
||||
if (angle90 == angle / 90) {
|
||||
angle90 %= 4;
|
||||
if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
}
|
||||
|
||||
} else {
|
||||
angle90 = -1;
|
||||
}
|
||||
|
||||
if (is8bit) {
|
||||
/* Call the 8-bit transformation routine to do the rotation */
|
||||
if(angle90 >= 0) {
|
||||
if (angle90 >= 0) {
|
||||
transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
transformSurfaceY(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
|
|
@ -561,7 +604,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
|||
transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
transformSurfaceRGBA(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy, smooth, rect_dest, center);
|
||||
flipx, flipy, smooth, rect_dest, center);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -22,9 +22,9 @@
|
|||
#ifndef SDL_rotate_h_
|
||||
#define SDL_rotate_h_
|
||||
|
||||
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center);
|
||||
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center);
|
||||
extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle);
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle);
|
||||
|
||||
#endif /* SDL_rotate_h_ */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -33,16 +33,15 @@
|
|||
* But, if increased too much, it overflows (srcx, srcy) coordinates used for filling with texture.
|
||||
* (which could be turned to int64).
|
||||
*/
|
||||
#define FP_BITS 1
|
||||
#define FP_BITS 1
|
||||
|
||||
#define COLOR_EQ(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a)
|
||||
|
||||
#define COLOR_EQ(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a)
|
||||
|
||||
static void SDL_BlitTriangle_Slow(SDL_BlitInfo * info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform);
|
||||
static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform);
|
||||
|
||||
#if 0
|
||||
int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3])
|
||||
|
|
@ -114,7 +113,8 @@ static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void trianglepoint_2_fixedpoint(SDL_Point *a) {
|
||||
void trianglepoint_2_fixedpoint(SDL_Point *a)
|
||||
{
|
||||
a->x <<= FP_BITS;
|
||||
a->y <<= FP_BITS;
|
||||
}
|
||||
|
|
@ -146,7 +146,6 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
|
|||
r->h = (max_y - min_y);
|
||||
}
|
||||
|
||||
|
||||
/* Triangle rendering, using Barycentric coordinates (w0, w1, w2)
|
||||
*
|
||||
* The cross product isn't computed from scratch at each iteration,
|
||||
|
|
@ -154,53 +153,51 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
|
|||
*
|
||||
*/
|
||||
|
||||
#define TRIANGLE_BEGIN_LOOP \
|
||||
{ \
|
||||
int x, y; \
|
||||
for (y = 0; y < dstrect.h; y++) { \
|
||||
/* y start */ \
|
||||
int w0 = w0_row; \
|
||||
int w1 = w1_row; \
|
||||
int w2 = w2_row; \
|
||||
for (x = 0; x < dstrect.w; x++) { \
|
||||
/* In triangle */ \
|
||||
if (w0 + bias_w0 >= 0 && w1 + bias_w1 >= 0 && w2 + bias_w2 >= 0) { \
|
||||
Uint8 *dptr = (Uint8 *) dst_ptr + x * dstbpp; \
|
||||
|
||||
#define TRIANGLE_BEGIN_LOOP \
|
||||
{ \
|
||||
int x, y; \
|
||||
for (y = 0; y < dstrect.h; y++) { \
|
||||
/* y start */ \
|
||||
int w0 = w0_row; \
|
||||
int w1 = w1_row; \
|
||||
int w2 = w2_row; \
|
||||
for (x = 0; x < dstrect.w; x++) { \
|
||||
/* In triangle */ \
|
||||
if (w0 + bias_w0 >= 0 && w1 + bias_w1 >= 0 && w2 + bias_w2 >= 0) { \
|
||||
Uint8 *dptr = (Uint8 *)dst_ptr + x * dstbpp;
|
||||
|
||||
/* Use 64 bits precision to prevent overflow when interpolating color / texture with wide triangles */
|
||||
#define TRIANGLE_GET_TEXTCOORD \
|
||||
int srcx = (int)(((Sint64)w0 * s2s0_x + (Sint64)w1 * s2s1_x + s2_x_area.x) / area); \
|
||||
int srcy = (int)(((Sint64)w0 * s2s0_y + (Sint64)w1 * s2s1_y + s2_x_area.y) / area); \
|
||||
#define TRIANGLE_GET_TEXTCOORD \
|
||||
int srcx = (int)(((Sint64)w0 * s2s0_x + (Sint64)w1 * s2s1_x + s2_x_area.x) / area); \
|
||||
int srcy = (int)(((Sint64)w0 * s2s0_y + (Sint64)w1 * s2s1_y + s2_x_area.y) / area);
|
||||
|
||||
#define TRIANGLE_GET_MAPPED_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
|
||||
int color = SDL_MapRGBA(format, r, g, b, a); \
|
||||
#define TRIANGLE_GET_MAPPED_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
|
||||
int color = SDL_MapRGBA(format, r, g, b, a);
|
||||
|
||||
#define TRIANGLE_GET_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
|
||||
#define TRIANGLE_GET_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area);
|
||||
|
||||
|
||||
#define TRIANGLE_END_LOOP \
|
||||
} \
|
||||
/* x += 1 */ \
|
||||
w0 += d2d1_y; \
|
||||
w1 += d0d2_y; \
|
||||
w2 += d1d0_y; \
|
||||
} \
|
||||
/* y += 1 */ \
|
||||
w0_row += d1d2_x; \
|
||||
w1_row += d2d0_x; \
|
||||
w2_row += d0d1_x; \
|
||||
dst_ptr += dst_pitch; \
|
||||
} \
|
||||
} \
|
||||
#define TRIANGLE_END_LOOP \
|
||||
} \
|
||||
/* x += 1 */ \
|
||||
w0 += d2d1_y; \
|
||||
w1 += d0d2_y; \
|
||||
w2 += d1d0_y; \
|
||||
} \
|
||||
/* y += 1 */ \
|
||||
w0_row += d1d2_x; \
|
||||
w1_row += d2d0_x; \
|
||||
w2_row += d0d1_x; \
|
||||
dst_ptr += dst_pitch; \
|
||||
} \
|
||||
}
|
||||
|
||||
int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2)
|
||||
{
|
||||
|
|
@ -265,12 +262,11 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
SDL_IntersectRect(&dstrect, &rect, &dstrect);
|
||||
}
|
||||
|
||||
|
||||
if (blend != SDL_BLENDMODE_NONE) {
|
||||
int format = dst->format->format;
|
||||
|
||||
/* need an alpha format */
|
||||
if (! dst->format->Amask) {
|
||||
if (!dst->format->Amask) {
|
||||
format = SDL_PIXELFORMAT_ARGB8888;
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +319,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
}
|
||||
|
||||
/* Handle anti-clockwise triangles */
|
||||
if (! is_clockwise) {
|
||||
if (!is_clockwise) {
|
||||
d2d1_y *= -1;
|
||||
d0d2_y *= -1;
|
||||
d1d0_y *= -1;
|
||||
|
|
@ -346,7 +342,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
if (dst->format->Amask) {
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
} else {
|
||||
//color = SDL_MapRGB(tmp->format, c0.r, c0.g, c0.b);
|
||||
// color = SDL_MapRGB(tmp->format, c0.r, c0.g, c0.b);
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -362,7 +358,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
} else if (dstbpp == 3) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
Uint8 *s = (Uint8*)&color;
|
||||
Uint8 *s = (Uint8 *)&color;
|
||||
dptr[0] = s[0];
|
||||
dptr[1] = s[1];
|
||||
dptr[2] = s[2];
|
||||
|
|
@ -397,7 +393,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
|
|||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_MAPPED_COLOR
|
||||
Uint8 *s = (Uint8*)&color;
|
||||
Uint8 *s = (Uint8 *)&color;
|
||||
dptr[0] = s[0];
|
||||
dptr[1] = s[1];
|
||||
dptr[2] = s[2];
|
||||
|
|
@ -433,18 +429,12 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int SDL_SW_BlitTriangle(
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2)
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2)
|
||||
{
|
||||
int ret = 0;
|
||||
int src_locked = 0;
|
||||
|
|
@ -520,20 +510,32 @@ int SDL_SW_BlitTriangle(
|
|||
maxx = srcrect.x + srcrect.w;
|
||||
maxy = srcrect.y + srcrect.h;
|
||||
if (srcrect.w > 0) {
|
||||
if (s0->x == maxx) s0->x--;
|
||||
if (s1->x == maxx) s1->x--;
|
||||
if (s2->x == maxx) s2->x--;
|
||||
if (s0->x == maxx) {
|
||||
s0->x--;
|
||||
}
|
||||
if (s1->x == maxx) {
|
||||
s1->x--;
|
||||
}
|
||||
if (s2->x == maxx) {
|
||||
s2->x--;
|
||||
}
|
||||
}
|
||||
if (srcrect.h > 0) {
|
||||
if (s0->y == maxy) s0->y--;
|
||||
if (s1->y == maxy) s1->y--;
|
||||
if (s2->y == maxy) s2->y--;
|
||||
if (s0->y == maxy) {
|
||||
s0->y--;
|
||||
}
|
||||
if (s1->y == maxy) {
|
||||
s1->y--;
|
||||
}
|
||||
if (s2->y == maxy) {
|
||||
s2->y--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_uniform) {
|
||||
// SDL_GetSurfaceColorMod(src, &r, &g, &b);
|
||||
has_modulation = c0.r != 255 || c0.g != 255 || c0.b != 255 || c0.a != 255;;
|
||||
has_modulation = c0.r != 255 || c0.g != 255 || c0.b != 255 || c0.a != 255;
|
||||
} else {
|
||||
has_modulation = SDL_TRUE;
|
||||
}
|
||||
|
|
@ -572,7 +574,6 @@ int SDL_SW_BlitTriangle(
|
|||
d0d2_y = (d2->y - d0->y) << FP_BITS;
|
||||
d1d0_y = (d0->y - d1->y) << FP_BITS;
|
||||
|
||||
|
||||
d1d2_x = (d2->x - d1->x) << FP_BITS;
|
||||
d2d0_x = (d0->x - d2->x) << FP_BITS;
|
||||
d0d1_x = (d1->x - d0->x) << FP_BITS;
|
||||
|
|
@ -596,7 +597,7 @@ int SDL_SW_BlitTriangle(
|
|||
}
|
||||
|
||||
/* Handle anti-clockwise triangles */
|
||||
if (! is_clockwise) {
|
||||
if (!is_clockwise) {
|
||||
d2d1_y *= -1;
|
||||
d0d2_y *= -1;
|
||||
d1d0_y *= -1;
|
||||
|
|
@ -617,7 +618,7 @@ int SDL_SW_BlitTriangle(
|
|||
s2_x_area.x = s2->x * area;
|
||||
s2_x_area.y = s2->y * area;
|
||||
|
||||
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || ! is_uniform) {
|
||||
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || !is_uniform) {
|
||||
/* Use SDL_BlitTriangle_Slow */
|
||||
|
||||
SDL_BlitInfo *info = &src->map->info;
|
||||
|
|
@ -639,12 +640,11 @@ int SDL_SW_BlitTriangle(
|
|||
tmp_info.b = c0.b;
|
||||
tmp_info.a = c0.a;
|
||||
|
||||
|
||||
tmp_info.flags &= ~(SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA);
|
||||
|
||||
if (c0.r != 255 || c1.r != 255 || c2.r != 255 ||
|
||||
c0.g != 255 || c1.g != 255 || c2.g != 255 ||
|
||||
c0.b != 255 || c1.b != 255 || c2.b != 255) {
|
||||
if (c0.r != 255 || c1.r != 255 || c2.r != 255 ||
|
||||
c0.g != 255 || c1.g != 255 || c2.g != 255 ||
|
||||
c0.b != 255 || c1.b != 255 || c2.b != 255) {
|
||||
tmp_info.flags |= SDL_COPY_MODULATE_COLOR;
|
||||
}
|
||||
|
||||
|
|
@ -655,17 +655,17 @@ int SDL_SW_BlitTriangle(
|
|||
tmp_info.colorkey = info->colorkey;
|
||||
|
||||
/* src */
|
||||
tmp_info.src = (Uint8 *) src_ptr;
|
||||
tmp_info.src = (Uint8 *)src_ptr;
|
||||
tmp_info.src_pitch = src_pitch;
|
||||
|
||||
/* dst */
|
||||
tmp_info.dst = (Uint8 *) dst_ptr;
|
||||
tmp_info.dst = dst_ptr;
|
||||
tmp_info.dst_pitch = dst_pitch;
|
||||
|
||||
SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, area, bias_w0, bias_w1, bias_w2,
|
||||
d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x,
|
||||
s2s0_x, s2s1_x, s2s0_y, s2s1_y, w0_row, w1_row, w2_row,
|
||||
c0, c1, c2, is_uniform);
|
||||
d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x,
|
||||
s2s0_x, s2s1_x, s2s0_y, s2s1_y, w0_row, w1_row, w2_row,
|
||||
c0, c1, c2, is_uniform);
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
|
@ -674,7 +674,7 @@ int SDL_SW_BlitTriangle(
|
|||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint32 *sptr = (Uint32 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
Uint32 *sptr = (Uint32 *)((Uint8 *)src_ptr + srcy * src_pitch);
|
||||
*(Uint32 *)dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
|
|
@ -682,7 +682,7 @@ int SDL_SW_BlitTriangle(
|
|||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
|
||||
dptr[0] = sptr[3 * srcx];
|
||||
dptr[1] = sptr[3 * srcx + 1];
|
||||
dptr[2] = sptr[3 * srcx + 2];
|
||||
|
|
@ -692,7 +692,7 @@ int SDL_SW_BlitTriangle(
|
|||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint16 *sptr = (Uint16 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
Uint16 *sptr = (Uint16 *)((Uint8 *)src_ptr + srcy * src_pitch);
|
||||
*(Uint16 *)dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
|
|
@ -700,7 +700,7 @@ int SDL_SW_BlitTriangle(
|
|||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
|
||||
*dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
|
|
@ -717,13 +717,13 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#define FORMAT_ALPHA 0
|
||||
#define FORMAT_NO_ALPHA -1
|
||||
#define FORMAT_2101010 1
|
||||
#define FORMAT_HAS_ALPHA(format) format == 0
|
||||
#define FORMAT_HAS_NO_ALPHA(format) format < 0
|
||||
static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
|
||||
#define FORMAT_ALPHA 0
|
||||
#define FORMAT_NO_ALPHA -1
|
||||
#define FORMAT_2101010 1
|
||||
#define FORMAT_HAS_ALPHA(format) format == 0
|
||||
#define FORMAT_HAS_NO_ALPHA(format) format < 0
|
||||
static int SDL_INLINE detect_format(SDL_PixelFormat *pf)
|
||||
{
|
||||
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
|
||||
return FORMAT_2101010;
|
||||
} else if (pf->Amask) {
|
||||
|
|
@ -733,12 +733,11 @@ static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform)
|
||||
static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform)
|
||||
{
|
||||
const int flags = info->flags;
|
||||
Uint32 modulateR = info->r;
|
||||
|
|
@ -759,7 +758,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
Uint32 ckey = info->colorkey & rgbmask;
|
||||
|
||||
Uint8 *dst_ptr = info->dst;
|
||||
int dst_pitch = info->dst_pitch;;
|
||||
int dst_pitch = info->dst_pitch;
|
||||
|
||||
srcfmt_val = detect_format(src_fmt);
|
||||
dstfmt_val = detect_format(dst_fmt);
|
||||
|
|
@ -784,7 +783,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
/* srcpixel isn't set for 24 bpp */
|
||||
if (srcbpp == 3) {
|
||||
srcpixel = (srcR << src_fmt->Rshift) |
|
||||
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
|
||||
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
|
||||
}
|
||||
if ((srcpixel & rgbmask) == ckey) {
|
||||
continue;
|
||||
|
|
@ -801,7 +800,7 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
|
||||
}
|
||||
|
||||
if (! is_uniform) {
|
||||
if (!is_uniform) {
|
||||
TRIANGLE_GET_COLOR
|
||||
modulateR = r;
|
||||
modulateG = g;
|
||||
|
|
@ -840,14 +839,17 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
break;
|
||||
case SDL_COPY_ADD:
|
||||
dstR = srcR + dstR;
|
||||
if (dstR > 255)
|
||||
if (dstR > 255) {
|
||||
dstR = 255;
|
||||
}
|
||||
dstG = srcG + dstG;
|
||||
if (dstG > 255)
|
||||
if (dstG > 255) {
|
||||
dstG = 255;
|
||||
}
|
||||
dstB = srcB + dstB;
|
||||
if (dstB > 255)
|
||||
if (dstB > 255) {
|
||||
dstB = 255;
|
||||
}
|
||||
break;
|
||||
case SDL_COPY_MOD:
|
||||
dstR = (srcR * dstR) / 255;
|
||||
|
|
@ -856,17 +858,17 @@ SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
|||
break;
|
||||
case SDL_COPY_MUL:
|
||||
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
|
||||
if (dstR > 255)
|
||||
if (dstR > 255) {
|
||||
dstR = 255;
|
||||
}
|
||||
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
|
||||
if (dstG > 255)
|
||||
if (dstG > 255) {
|
||||
dstG = 255;
|
||||
}
|
||||
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
|
||||
if (dstB > 255)
|
||||
if (dstB > 255) {
|
||||
dstB = 255;
|
||||
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
|
||||
if (dstA > 255)
|
||||
dstA = 255;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,15 +25,15 @@
|
|||
#include "../../SDL_internal.h"
|
||||
|
||||
extern int SDL_SW_FillTriangle(SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
|
||||
extern int SDL_SW_BlitTriangle(
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
|
||||
extern void trianglepoint_2_fixedpoint(SDL_Point *a);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue