Simplified SDL_Surface

SDL_Surface has been simplified and internal details are no longer in the public structure.

The `format` member of SDL_Surface is now an enumerated pixel format value. You can get the full details of the pixel format by calling `SDL_GetPixelFormatDetails(surface->format)`. You can get the palette associated with the surface by calling SDL_GetSurfacePalette(). You can get the clip rectangle by calling SDL_GetSurfaceClipRect().

SDL_PixelFormat has been renamed SDL_PixelFormatDetails and just describes the pixel format, it does not include a palette for indexed pixel types.

SDL_PixelFormatEnum has been renamed SDL_PixelFormat and is used instead of Uint32 for API functions that refer to pixel format by enumerated value.

SDL_MapRGB(), SDL_MapRGBA(), SDL_GetRGB(), and SDL_GetRGBA() take an optional palette parameter for indexed color lookups.
This commit is contained in:
Sam Lantinga
2024-07-08 14:59:18 -07:00
parent 40ed098ce8
commit 2ba76dbe80
123 changed files with 1865 additions and 1838 deletions

View File

@@ -128,7 +128,7 @@ static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -178,7 +178,7 @@ static int 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)
{
SDL_PixelFormat *fmt = dst->format;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -211,24 +211,24 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
{
SDL_Rect clipped;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (SDL_BITSPERPIXEL(dst->format) < 8) {
return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
}
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
/* Perform clipping */
if (!SDL_GetRectIntersection(rect, &dst->clip_rect, &clipped)) {
if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) {
return 0;
}
rect = &clipped;
} else {
rect = &dst->clip_rect;
rect = &dst->internal->clip_rect;
}
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -237,23 +237,23 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
b = DRAW_MUL(b, a);
}
switch (dst->format->bits_per_pixel) {
switch (dst->internal->format->bits_per_pixel) {
case 15:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x7C00:
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
}
break;
case 16:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0xF800:
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
}
break;
case 32:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
return SDL_BlendFillRect_XRGB8888(dst, rect, blendMode, r, g, b, a);
} else {
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
@@ -265,7 +265,7 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
break;
}
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
} else {
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
@@ -281,12 +281,12 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
}
@@ -297,23 +297,23 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
/* FIXME: Does this function pointer slow things down significantly? */
switch (dst->format->bits_per_pixel) {
switch (dst->internal->format->bits_per_pixel) {
case 15:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x7C00:
func = SDL_BlendFillRect_RGB555;
}
break;
case 16:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0xF800:
func = SDL_BlendFillRect_RGB565;
}
break;
case 32:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
func = SDL_BlendFillRect_XRGB8888;
} else {
func = SDL_BlendFillRect_ARGB8888;
@@ -326,7 +326,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
if (!func) {
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
func = SDL_BlendFillRect_RGB;
} else {
func = SDL_BlendFillRect_RGBA;
@@ -335,7 +335,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
for (i = 0; i < count; ++i) {
/* Perform clipping */
if (!SDL_GetRectIntersection(&rects[i], &dst->clip_rect, &rect)) {
if (!SDL_GetRectIntersection(&rects[i], &dst->internal->clip_rect, &rect)) {
continue;
}
status = func(dst, &rect, blendMode, r, g, b, a);

View File

@@ -30,7 +30,7 @@ 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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -343,7 +343,7 @@ 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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -448,7 +448,7 @@ 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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -763,7 +763,7 @@ typedef void (*BlendLineFunc)(SDL_Surface *dst,
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_PixelFormatDetails *fmt)
{
switch (fmt->bytes_per_pixel) {
case 2:
@@ -798,18 +798,18 @@ int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
{
BlendLineFunc func;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendLine(): dst");
}
func = SDL_CalculateBlendLineFunc(dst->format);
func = SDL_CalculateBlendLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
@@ -826,11 +826,11 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_bool draw_end;
BlendLineFunc func;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
}
func = SDL_CalculateBlendLineFunc(dst->format);
func = SDL_CalculateBlendLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
}
@@ -843,7 +843,7 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}

View File

@@ -128,7 +128,7 @@ static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode
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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -178,7 +178,7 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen
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;
const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -209,19 +209,19 @@ static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode ble
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (SDL_BITSPERPIXEL(dst->format) < 8) {
return SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
}
/* Perform clipping */
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
}
@@ -231,23 +231,23 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
b = DRAW_MUL(b, a);
}
switch (dst->format->bits_per_pixel) {
switch (dst->internal->format->bits_per_pixel) {
case 15:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x7C00:
return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
}
break;
case 16:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0xF800:
return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
}
break;
case 32:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
return SDL_BlendPoint_XRGB8888(dst, x, y, blendMode, r, g, b, a);
} else {
return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a);
@@ -259,7 +259,7 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
break;
}
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
} else {
return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
@@ -277,12 +277,12 @@ int 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 (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
}
@@ -293,25 +293,25 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
}
/* FIXME: Does this function pointer slow things down significantly? */
switch (dst->format->bits_per_pixel) {
switch (dst->internal->format->bits_per_pixel) {
case 15:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x7C00:
func = SDL_BlendPoint_RGB555;
break;
}
break;
case 16:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0xF800:
func = SDL_BlendPoint_RGB565;
break;
}
break;
case 32:
switch (dst->format->Rmask) {
switch (dst->internal->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
func = SDL_BlendPoint_XRGB8888;
} else {
func = SDL_BlendPoint_ARGB8888;
@@ -324,17 +324,17 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
}
if (!func) {
if (!dst->format->Amask) {
if (!dst->internal->format->Amask) {
func = SDL_BlendPoint_RGB;
} else {
func = SDL_BlendPoint_RGBA;
}
}
minx = dst->clip_rect.x;
maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
miny = dst->clip_rect.y;
maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
minx = dst->internal->clip_rect.x;
maxx = dst->internal->clip_rect.x + dst->internal->clip_rect.w - 1;
miny = dst->internal->clip_rect.y;
maxy = dst->internal->clip_rect.y + dst->internal->clip_rect.h - 1;
for (i = 0; i < count; ++i) {
x = points[i].x;

View File

@@ -364,7 +364,7 @@
#define HLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -386,7 +386,7 @@
#define VLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -408,7 +408,7 @@
#define DLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -628,7 +628,7 @@
do { \
int width = rect->w; \
int height = rect->h; \
int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
int skip = pitch - width; \
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
while (height--) { \

View File

@@ -31,7 +31,7 @@ static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
{
if (y1 == y2) {
int length;
int pitch = (dst->pitch / dst->format->bytes_per_pixel);
int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel);
Uint8 *pixel;
if (x1 <= x2) {
pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
@@ -64,8 +64,8 @@ static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat *fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
const SDL_PixelFormatDetails *fmt = dst->internal->format;
SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x7C00) {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
@@ -93,8 +93,8 @@ static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat *fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
const SDL_PixelFormatDetails *fmt = dst->internal->format;
SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x00FF0000) {
if (!fmt->Amask) {
AALINE(x1, y1, x2, y2,
@@ -117,7 +117,7 @@ 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_PixelFormatDetails *fmt)
{
switch (fmt->bytes_per_pixel) {
case 1:
@@ -137,18 +137,18 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
{
DrawLineFunc func;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawLine(): dst");
}
func = SDL_CalculateDrawLineFunc(dst->format);
func = SDL_CalculateDrawLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
@@ -165,11 +165,11 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_bool draw_end;
DrawLineFunc func;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawLines(): dst");
}
func = SDL_CalculateDrawLineFunc(dst->format);
func = SDL_CalculateDrawLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
}
@@ -182,7 +182,7 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}

View File

@@ -27,23 +27,23 @@
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
{
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
}
/* Perform clipping */
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
}
switch (dst->format->bytes_per_pixel) {
switch (dst->internal->format->bytes_per_pixel) {
case 1:
DRAW_FASTSETPIXELXY1(x, y);
break;
@@ -67,19 +67,19 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
int i;
int x, y;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->bits_per_pixel < 8) {
if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
}
minx = dst->clip_rect.x;
maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
miny = dst->clip_rect.y;
maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
minx = dst->internal->clip_rect.x;
maxx = dst->internal->clip_rect.x + dst->internal->clip_rect.w - 1;
miny = dst->internal->clip_rect.y;
maxy = dst->internal->clip_rect.y + dst->internal->clip_rect.h - 1;
for (i = 0; i < count; ++i) {
x = points[i].x;
@@ -89,7 +89,7 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
continue;
}
switch (dst->format->bytes_per_pixel) {
switch (dst->internal->format->bytes_per_pixel) {
case 1:
DRAW_FASTSETPIXELXY1(x, y);
break;

View File

@@ -104,7 +104,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format);
Uint8 r, g, b, a;
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return SDL_SetError("Cannot create surface");
}
texture->driverdata = surface;
@@ -119,7 +119,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
/* Only RLE encode textures without an alpha channel since the RLE coder
* discards the color values of pixels with an alpha value of zero.
*/
if (texture->access == SDL_TEXTUREACCESS_STATIC && !surface->format->Amask) {
if (texture->access == SDL_TEXTUREACCESS_STATIC && !SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
SDL_SetSurfaceRLE(surface, 1);
}
@@ -140,8 +140,8 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
src = (Uint8 *)pixels;
dst = (Uint8 *)surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->bytes_per_pixel;
length = (size_t)rect->w * surface->format->bytes_per_pixel;
rect->x * surface->internal->format->bytes_per_pixel;
length = (size_t)rect->w * surface->internal->format->bytes_per_pixel;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
@@ -160,7 +160,7 @@ static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
*pixels =
(void *)((Uint8 *)surface->pixels + rect->y * surface->pitch +
rect->x * surface->format->bytes_per_pixel);
rect->x * surface->internal->format->bytes_per_pixel);
*pitch = surface->pitch;
return 0;
}
@@ -328,7 +328,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
int blitRequired = SDL_FALSE;
int isOpaque = SDL_FALSE;
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return -1;
}
@@ -347,7 +347,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
/* Clone the source surface but use its pixel buffer directly.
* The original source surface must be treated as read-only.
*/
src_clone = SDL_CreateSurfaceFrom(src->pixels, src->w, src->h, src->pitch, src->format->format);
src_clone = SDL_CreateSurfaceFrom(src->w, src->h, src->format, src->pixels, src->pitch);
if (!src_clone) {
if (SDL_MUSTLOCK(src)) {
SDL_UnlockSurface(src);
@@ -360,7 +360,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);
/* SDLgfx_rotateSurface only accepts 32-bit surfaces with a 8888 layout. Everything else has to be converted. */
if (src->format->bits_per_pixel != 32 || SDL_PIXELLAYOUT(src->format->format) != SDL_PACKEDLAYOUT_8888 || !src->format->Amask) {
if (src->internal->format->bits_per_pixel != 32 || SDL_PIXELLAYOUT(src->format) != SDL_PACKEDLAYOUT_8888 || !SDL_ISPIXELFORMAT_ALPHA(src->format)) {
blitRequired = SDL_TRUE;
}
@@ -382,7 +382,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
}
/* Opaque surfaces are much easier to handle with the NONE blend mode. */
if (blendmode == SDL_BLENDMODE_NONE && !src->format->Amask && alphaMod == 255) {
if (blendmode == SDL_BLENDMODE_NONE && !SDL_ISPIXELFORMAT_ALPHA(src->format) && alphaMod == 255) {
isOpaque = SDL_TRUE;
}
@@ -482,15 +482,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
* mode modulates the colors with the alpha channel, a surface without an alpha mask needs
* to be created. This makes all source pixels opaque and the colors get copied correctly.
*/
SDL_Surface *src_rotated_rgb;
SDL_PixelFormatEnum f = SDL_GetPixelFormatEnumForMasks(src_rotated->format->bits_per_pixel,
src_rotated->format->Rmask,
src_rotated->format->Gmask,
src_rotated->format->Bmask,
0);
src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h,
src_rotated->pitch, f);
SDL_Surface *src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->w, src_rotated->h, src_rotated->format, src_rotated->pixels, src_rotated->pitch);
if (!src_rotated_rgb) {
retval = -1;
} else {
@@ -680,7 +672,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SW_DrawStateCache drawstate;
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return -1;
}
@@ -725,7 +717,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
const Uint8 a = (Uint8)SDL_roundf(SDL_clamp(cmd->data.color.color.a, 0.0f, 1.0f) * 255.0f);
/* By definition the clear ignores the clip rect */
SDL_SetSurfaceClipRect(surface, NULL);
SDL_FillSurfaceRect(surface, NULL, SDL_MapRGBA(surface->format, r, g, b, a));
SDL_FillSurfaceRect(surface, NULL, SDL_MapSurfaceRGBA(surface, r, g, b, a));
drawstate.surface_cliprect_dirty = SDL_TRUE;
break;
}
@@ -751,7 +743,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
SDL_DrawPoints(surface, verts, count, SDL_MapSurfaceRGBA(surface, r, g, b, a));
} else {
SDL_BlendPoints(surface, verts, count, blend, r, g, b, a);
}
@@ -779,7 +771,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
SDL_DrawLines(surface, verts, count, SDL_MapSurfaceRGBA(surface, r, g, b, a));
} else {
SDL_BlendLines(surface, verts, count, blend, r, g, b, a);
}
@@ -807,7 +799,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
SDL_FillSurfaceRects(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
SDL_FillSurfaceRects(surface, verts, count, SDL_MapSurfaceRGBA(surface, r, g, b, a));
} else {
SDL_BlendFillRects(surface, verts, count, blend, r, g, b, a);
}
@@ -842,7 +834,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
/* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */
if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) {
SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format);
SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format);
/* Scale to an intermediate surface, then blit */
if (tmp) {
SDL_Rect r;
@@ -971,7 +963,7 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
SDL_Surface *surface = SW_ActivateRenderer(renderer);
void *pixels;
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return NULL;
}
@@ -987,9 +979,9 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
pixels = (void *)((Uint8 *)surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->bytes_per_pixel);
rect->x * surface->internal->format->bytes_per_pixel);
return SDL_DuplicatePixels(rect->w, rect->h, surface->format->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch);
return SDL_DuplicatePixels(rect->w, rect->h, surface->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch);
}
static int SW_RenderPresent(SDL_Renderer *renderer)
@@ -1020,7 +1012,7 @@ static void SW_DestroyRenderer(SDL_Renderer *renderer)
SDL_free(data);
}
static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormat format)
{
/* Prefer the format used by the framebuffer by default. */
SDL_AddSupportedTextureFormat(renderer, format);
@@ -1119,7 +1111,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
{
SW_RenderData *data;
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
@@ -1160,7 +1152,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
renderer->name = SW_RenderDriver.name;
SW_SelectBestFormats(renderer, surface->format->format);
SW_SelectBestFormats(renderer, surface->format);
SDL_SetupRendererColorspace(renderer, create_props);
@@ -1193,7 +1185,7 @@ static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
}
if (!surface) {
if (!SDL_SurfaceValid(surface)) {
return -1;
}

View File

@@ -36,11 +36,10 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
#include "../../core/windows/SDL_windows.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "SDL_rotate.h"
#include "../../video/SDL_blit.h"
/* ---- Internally used structures */
/**
@@ -491,14 +490,13 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
{
SDL_Surface *rz_dst;
int is8bit, angle90;
int i;
SDL_BlendMode blendmode;
Uint32 colorkey = 0;
int colorKeyAvailable = SDL_FALSE;
double sangleinv, cangleinv;
/* Sanity check */
if (!src) {
if (!SDL_SurfaceValid(src)) {
return NULL;
}
@@ -508,8 +506,8 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
}
}
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
is8bit = src->format->bits_per_pixel == 8 && colorKeyAvailable;
if (!(is8bit || (src->format->bits_per_pixel == 32 && src->format->Amask))) {
is8bit = src->internal->format->bits_per_pixel == 8 && colorKeyAvailable;
if (!(is8bit || (src->internal->format->bits_per_pixel == 32 && SDL_ISPIXELFORMAT_ALPHA(src->format)))) {
return NULL;
}
@@ -521,18 +519,13 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
rz_dst = NULL;
if (is8bit) {
/* Target surface is 8 bit */
rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format);
if (rz_dst) {
if (src->format->palette) {
for (i = 0; i < src->format->palette->ncolors; i++) {
rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
}
rz_dst->format->palette->ncolors = src->format->palette->ncolors;
}
SDL_SetSurfacePalette(rz_dst, src->internal->palette);
}
} else {
/* Target surface is 32 bit with source RGBA ordering */
rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format);
}
/* Check target */
@@ -555,7 +548,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
/* Without a colorkey, the target texture has to be white for the MOD and MUL blend mode so
* that the pixels outside the rotated area don't affect the destination surface.
*/
colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0);
colorkey = SDL_MapSurfaceRGBA(rz_dst, 255, 255, 255, 0);
SDL_FillSurfaceRect(rz_dst, NULL, colorkey);
/* Setting a white colorkey for the destination surface makes the final blit discard
* all pixels outside of the rotated area. This doesn't interfere with anything because

View File

@@ -190,7 +190,7 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
Uint8 g = (Uint8)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
Uint8 b = (Uint8)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
Uint8 a = (Uint8)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
Uint32 color = SDL_MapRGBA(format, r, g, b, a);
Uint32 color = SDL_MapRGBA(format, palette, r, g, b, a);
#define TRIANGLE_GET_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
@@ -235,7 +235,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
SDL_Surface *tmp = NULL;
if (!dst) {
if (!SDL_SurfaceValid(dst)) {
return -1;
}
@@ -278,10 +278,10 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
if (blend != SDL_BLENDMODE_NONE) {
SDL_PixelFormatEnum format = dst->format->format;
SDL_PixelFormat format = dst->format;
/* need an alpha format */
if (!dst->format->Amask) {
if (!SDL_ISPIXELFORMAT_ALPHA(format)) {
format = SDL_PIXELFORMAT_ARGB8888;
}
@@ -293,19 +293,19 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
if (blend == SDL_BLENDMODE_MOD) {
Uint32 c = SDL_MapRGBA(tmp->format, 255, 255, 255, 255);
Uint32 c = SDL_MapSurfaceRGBA(tmp, 255, 255, 255, 255);
SDL_FillSurfaceRect(tmp, NULL, c);
}
SDL_SetSurfaceBlendMode(tmp, blend);
dstbpp = tmp->format->bytes_per_pixel;
dstbpp = tmp->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)tmp->pixels;
dst_pitch = tmp->pitch;
} else {
/* Write directly to destination surface */
dstbpp = dst->format->bytes_per_pixel;
dstbpp = dst->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
dst_pitch = dst->pitch;
}
@@ -359,9 +359,9 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
if (is_uniform) {
Uint32 color;
if (tmp) {
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
color = SDL_MapSurfaceRGBA(tmp, c0.r, c0.g, c0.b, c0.a);
} else {
color = SDL_MapRGBA(dst->format, c0.r, c0.g, c0.b, c0.a);
color = SDL_MapSurfaceRGBA(dst, c0.r, c0.g, c0.b, c0.a);
}
if (dstbpp == 4) {
@@ -393,9 +393,14 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
TRIANGLE_END_LOOP
}
} else {
SDL_PixelFormat *format = dst->format;
const SDL_PixelFormatDetails *format;
SDL_Palette *palette;
if (tmp) {
format = tmp->format;
format = tmp->internal->format;
palette = tmp->internal->palette;
} else {
format = dst->internal->format;
palette = dst->internal->palette;
}
if (dstbpp == 4) {
TRIANGLE_BEGIN_LOOP
@@ -481,10 +486,10 @@ int SDL_SW_BlitTriangle(
int has_modulation;
if (!src) {
if (!SDL_SurfaceValid(src)) {
return SDL_InvalidParamError("src");
}
if (!src) {
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("dst");
}
@@ -578,7 +583,7 @@ int SDL_SW_BlitTriangle(
}
/* Set destination pointer */
dstbpp = dst->format->bytes_per_pixel;
dstbpp = dst->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
dst_pitch = dst->pitch;
@@ -653,16 +658,16 @@ int SDL_SW_BlitTriangle(
goto end;
}
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || !is_uniform) {
if (blend != SDL_BLENDMODE_NONE || src->format != dst->format || has_modulation || !is_uniform) {
/* Use SDL_BlitTriangle_Slow */
SDL_BlitInfo *info = &src->map->info;
SDL_BlitInfo *info = &src->internal->map.info;
SDL_BlitInfo tmp_info;
SDL_zero(tmp_info);
tmp_info.src_fmt = src->format;
tmp_info.dst_fmt = dst->format;
tmp_info.src_fmt = src->internal->format;
tmp_info.dst_fmt = dst->internal->format;
tmp_info.flags = info->flags;
/*
tmp_info.r = info->r;
@@ -766,7 +771,7 @@ end:
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
static int detect_format(SDL_PixelFormat *pf)
static int detect_format(const SDL_PixelFormatDetails *pf)
{
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
return FORMAT_2101010;
@@ -792,8 +797,8 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
Uint32 srcR, srcG, srcB, srcA;
Uint32 dstpixel;
Uint32 dstR, dstG, dstB, dstA;
SDL_PixelFormat *src_fmt = info->src_fmt;
SDL_PixelFormat *dst_fmt = info->dst_fmt;
const SDL_PixelFormatDetails *src_fmt = info->src_fmt;
const SDL_PixelFormatDetails *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->bytes_per_pixel;
int dstbpp = dst_fmt->bytes_per_pixel;
int srcfmt_val;