Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'
This commit is contained in:
83
external/sdl/SDL/src/video/SDL_pixels.c
vendored
83
external/sdl/SDL/src/video/SDL_pixels.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 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
|
||||
@@ -89,6 +89,8 @@ const char *SDL_GetPixelFormatName(Uint32 format)
|
||||
|
||||
CASE(SDL_PIXELFORMAT_INDEX1LSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX1MSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX2LSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX2MSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX4LSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX4MSB)
|
||||
CASE(SDL_PIXELFORMAT_INDEX8)
|
||||
@@ -117,7 +119,10 @@ const char *SDL_GetPixelFormatName(Uint32 format)
|
||||
CASE(SDL_PIXELFORMAT_RGBA8888)
|
||||
CASE(SDL_PIXELFORMAT_ABGR8888)
|
||||
CASE(SDL_PIXELFORMAT_BGRA8888)
|
||||
CASE(SDL_PIXELFORMAT_XRGB2101010)
|
||||
CASE(SDL_PIXELFORMAT_XBGR2101010)
|
||||
CASE(SDL_PIXELFORMAT_ARGB2101010)
|
||||
CASE(SDL_PIXELFORMAT_ABGR2101010)
|
||||
CASE(SDL_PIXELFORMAT_YV12)
|
||||
CASE(SDL_PIXELFORMAT_IYUV)
|
||||
CASE(SDL_PIXELFORMAT_YUY2)
|
||||
@@ -306,6 +311,9 @@ Uint32 SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint3
|
||||
case 1:
|
||||
/* SDL defaults to MSB ordering */
|
||||
return SDL_PIXELFORMAT_INDEX1MSB;
|
||||
case 2:
|
||||
/* SDL defaults to MSB ordering */
|
||||
return SDL_PIXELFORMAT_INDEX2MSB;
|
||||
case 4:
|
||||
/* SDL defaults to MSB ordering */
|
||||
return SDL_PIXELFORMAT_INDEX4MSB;
|
||||
@@ -440,6 +448,20 @@ Uint32 SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint3
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 30:
|
||||
if (Rmask == 0x3FF00000 &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x000003FF &&
|
||||
Amask == 0x00000000) {
|
||||
return SDL_PIXELFORMAT_XRGB2101010;
|
||||
}
|
||||
if (Rmask == 0x000003FF &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x3FF00000 &&
|
||||
Amask == 0x00000000) {
|
||||
return SDL_PIXELFORMAT_XBGR2101010;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
if (Rmask == 0) {
|
||||
return SDL_PIXELFORMAT_XRGB8888;
|
||||
@@ -492,12 +514,31 @@ Uint32 SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint3
|
||||
Amask == 0x000000FF) {
|
||||
return SDL_PIXELFORMAT_BGRA8888;
|
||||
}
|
||||
if (Rmask == 0x3FF00000 &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x000003FF &&
|
||||
Amask == 0x00000000) {
|
||||
return SDL_PIXELFORMAT_XRGB2101010;
|
||||
}
|
||||
if (Rmask == 0x000003FF &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x3FF00000 &&
|
||||
Amask == 0x00000000) {
|
||||
return SDL_PIXELFORMAT_XBGR2101010;
|
||||
}
|
||||
if (Rmask == 0x3FF00000 &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x000003FF &&
|
||||
Amask == 0xC0000000) {
|
||||
return SDL_PIXELFORMAT_ARGB2101010;
|
||||
}
|
||||
if (Rmask == 0x000003FF &&
|
||||
Gmask == 0x000FFC00 &&
|
||||
Bmask == 0x3FF00000 &&
|
||||
Amask == 0xC0000000) {
|
||||
return SDL_PIXELFORMAT_ABGR2101010;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return SDL_PIXELFORMAT_UNKNOWN;
|
||||
}
|
||||
@@ -522,9 +563,8 @@ SDL_PixelFormat *SDL_CreatePixelFormat(Uint32 pixel_format)
|
||||
|
||||
/* Allocate an empty pixel format structure, and initialize it */
|
||||
format = SDL_malloc(sizeof(*format));
|
||||
if (format == NULL) {
|
||||
if (!format) {
|
||||
SDL_AtomicUnlock(&formats_lock);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
if (SDL_InitFormat(format, pixel_format) < 0) {
|
||||
@@ -620,7 +660,7 @@ void SDL_DestroyPixelFormat(SDL_PixelFormat *format)
|
||||
{
|
||||
SDL_PixelFormat *prev;
|
||||
|
||||
if (format == NULL) {
|
||||
if (!format) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -663,15 +703,13 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
|
||||
}
|
||||
|
||||
palette = (SDL_Palette *)SDL_malloc(sizeof(*palette));
|
||||
if (palette == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
if (!palette) {
|
||||
return NULL;
|
||||
}
|
||||
palette->colors =
|
||||
(SDL_Color *)SDL_malloc(ncolors * sizeof(*palette->colors));
|
||||
if (!palette->colors) {
|
||||
SDL_free(palette);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
palette->ncolors = ncolors;
|
||||
@@ -685,7 +723,7 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
|
||||
|
||||
int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
|
||||
{
|
||||
if (format == NULL) {
|
||||
if (!format) {
|
||||
return SDL_InvalidParamError("SDL_SetPixelFormatPalette(): format");
|
||||
}
|
||||
|
||||
@@ -716,7 +754,7 @@ int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
|
||||
int status = 0;
|
||||
|
||||
/* Verify the parameters */
|
||||
if (palette == NULL) {
|
||||
if (!palette) {
|
||||
return -1;
|
||||
}
|
||||
if (ncolors > (palette->ncolors - firstcolor)) {
|
||||
@@ -738,7 +776,7 @@ int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
|
||||
|
||||
void SDL_DestroyPalette(SDL_Palette *palette)
|
||||
{
|
||||
if (palette == NULL) {
|
||||
if (!palette) {
|
||||
return;
|
||||
}
|
||||
if (--palette->refcount > 0) {
|
||||
@@ -859,7 +897,7 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
|
||||
SDL_InvalidParamError("format");
|
||||
return 0;
|
||||
}
|
||||
if (format->palette == NULL) {
|
||||
if (!format->palette) {
|
||||
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
|
||||
} else {
|
||||
return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
|
||||
@@ -874,7 +912,7 @@ Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
|
||||
SDL_InvalidParamError("format");
|
||||
return 0;
|
||||
}
|
||||
if (format->palette == NULL) {
|
||||
if (!format->palette) {
|
||||
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
|
||||
} else {
|
||||
return SDL_FindColor(format->palette, r, g, b, a);
|
||||
@@ -884,7 +922,7 @@ Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
|
||||
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
|
||||
Uint8 *b)
|
||||
{
|
||||
if (format->palette == NULL) {
|
||||
if (!format->palette) {
|
||||
unsigned v;
|
||||
v = (pixel & format->Rmask) >> format->Rshift;
|
||||
*r = SDL_expand_byte[format->Rloss][v];
|
||||
@@ -906,7 +944,7 @@ void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
|
||||
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format,
|
||||
Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
|
||||
{
|
||||
if (format->palette == NULL) {
|
||||
if (!format->palette) {
|
||||
unsigned v;
|
||||
v = (pixel & format->Rmask) >> format->Rshift;
|
||||
*r = SDL_expand_byte[format->Rloss][v];
|
||||
@@ -947,8 +985,7 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
|
||||
*identical = 0;
|
||||
}
|
||||
map = (Uint8 *)SDL_calloc(256, sizeof(Uint8));
|
||||
if (map == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
if (!map) {
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < src->ncolors; ++i) {
|
||||
@@ -970,8 +1007,7 @@ static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod,
|
||||
|
||||
bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
|
||||
map = (Uint8 *)SDL_calloc(256, bpp);
|
||||
if (map == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
if (!map) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1006,8 +1042,7 @@ SDL_BlitMap *SDL_AllocBlitMap(void)
|
||||
|
||||
/* Allocate the empty map */
|
||||
map = (SDL_BlitMap *)SDL_calloc(1, sizeof(*map));
|
||||
if (map == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
if (!map) {
|
||||
return NULL;
|
||||
}
|
||||
map->info.r = 0xFF;
|
||||
@@ -1035,7 +1070,7 @@ void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
|
||||
|
||||
void SDL_InvalidateMap(SDL_BlitMap *map)
|
||||
{
|
||||
if (map == NULL) {
|
||||
if (!map) {
|
||||
return;
|
||||
}
|
||||
if (map->dst) {
|
||||
@@ -1074,7 +1109,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
||||
map->info.table =
|
||||
Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
|
||||
if (!map->identity) {
|
||||
if (map->info.table == NULL) {
|
||||
if (!map->info.table) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1086,7 +1121,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
||||
map->info.table =
|
||||
Map1toN(srcfmt, src->map->info.r, src->map->info.g,
|
||||
src->map->info.b, src->map->info.a, dstfmt);
|
||||
if (map->info.table == NULL) {
|
||||
if (!map->info.table) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1095,7 +1130,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
||||
/* BitField --> Palette */
|
||||
map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
|
||||
if (!map->identity) {
|
||||
if (map->info.table == NULL) {
|
||||
if (!map->info.table) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user