rename 'pixel' params of SDL_GetRGB, SDL_GetRGBA and SDL_LookupRGBAColor

Reference issue: https://github.com/libsdl-org/SDL/issues/12749.
This commit is contained in:
Ozkan Sezer 2025-04-07 15:50:25 +03:00 committed by Ozkan Sezer
parent 83b261ae83
commit 433704e774
3 changed files with 37 additions and 37 deletions

View File

@ -1379,7 +1379,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *for
* (e.g., a completely white pixel in 16-bit RGB565 format would return [0xff,
* 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
*
* \param pixel a pixel value.
* \param pixelvalue a pixel value.
* \param format a pointer to SDL_PixelFormatDetails describing the pixel
* format.
* \param palette an optional palette for indexed formats, may be NULL.
@ -1397,7 +1397,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormatDetails *for
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
/**
* Get RGBA values from a pixel in the specified format.
@ -1410,7 +1410,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatD
* If the surface has no alpha component, the alpha will be returned as 0xff
* (100% opaque).
*
* \param pixel a pixel value.
* \param pixelvalue a pixel value.
* \param format a pointer to SDL_PixelFormatDetails describing the pixel
* format.
* \param palette an optional palette for indexed formats, may be NULL.
@ -1429,7 +1429,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatD
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
/* Ends C function definitions when using C++ */

View File

@ -1153,19 +1153,19 @@ Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
return pixel;
}
Uint8 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixel, const SDL_Palette *pal)
Uint8 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixelvalue, const SDL_Palette *pal)
{
Uint8 color_index = 0;
const void *value;
if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixel, &value)) {
if (SDL_FindInHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, &value)) {
color_index = (Uint8)(uintptr_t)value;
} else {
Uint8 r = (Uint8)((pixel >> 24) & 0xFF);
Uint8 g = (Uint8)((pixel >> 16) & 0xFF);
Uint8 b = (Uint8)((pixel >> 8) & 0xFF);
Uint8 a = (Uint8)((pixel >> 0) & 0xFF);
Uint8 r = (Uint8)((pixelvalue >> 24) & 0xFF);
Uint8 g = (Uint8)((pixelvalue >> 16) & 0xFF);
Uint8 b = (Uint8)((pixelvalue >> 8) & 0xFF);
Uint8 a = (Uint8)((pixelvalue >> 0) & 0xFF);
color_index = SDL_FindColor(pal, r, g, b, a);
SDL_InsertIntoHashTable(palette_map, (const void *)(uintptr_t)pixel, (const void *)(uintptr_t)color_index, true);
SDL_InsertIntoHashTable(palette_map, (const void *)(uintptr_t)pixelvalue, (const void *)(uintptr_t)color_index, true);
}
return color_index;
}
@ -1274,7 +1274,7 @@ Uint32 SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *pale
}
}
void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b)
void SDL_GetRGB(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b)
{
Uint8 unused;
@ -1294,10 +1294,10 @@ void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Pa
}
if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
if (palette && pixel < (unsigned)palette->ncolors) {
*r = palette->colors[pixel].r;
*g = palette->colors[pixel].g;
*b = palette->colors[pixel].b;
if (palette && pixelvalue < (unsigned)palette->ncolors) {
*r = palette->colors[pixelvalue].r;
*g = palette->colors[pixelvalue].g;
*b = palette->colors[pixelvalue].b;
} else {
*r = *g = *b = 0;
}
@ -1306,24 +1306,24 @@ void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Pa
if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
unsigned v;
v = (pixel & format->Rmask) >> format->Rshift;
v = (pixelvalue & format->Rmask) >> format->Rshift;
*r = (Uint8)(v >> 2);
v = (pixel & format->Gmask) >> format->Gshift;
v = (pixelvalue & format->Gmask) >> format->Gshift;
*g = (Uint8)(v >> 2);
v = (pixel & format->Bmask) >> format->Bshift;
v = (pixelvalue & format->Bmask) >> format->Bshift;
*b = (Uint8)(v >> 2);
} else {
unsigned v;
v = (pixel & format->Rmask) >> format->Rshift;
v = (pixelvalue & format->Rmask) >> format->Rshift;
*r = SDL_expand_byte[format->Rbits][v];
v = (pixel & format->Gmask) >> format->Gshift;
v = (pixelvalue & format->Gmask) >> format->Gshift;
*g = SDL_expand_byte[format->Gbits][v];
v = (pixel & format->Bmask) >> format->Bshift;
v = (pixelvalue & format->Bmask) >> format->Bshift;
*b = SDL_expand_byte[format->Bbits][v];
}
}
void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
void SDL_GetRGBA(Uint32 pixelvalue, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
{
Uint8 unused;
@ -1346,11 +1346,11 @@ void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_P
}
if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
if (palette && pixel < (unsigned)palette->ncolors) {
*r = palette->colors[pixel].r;
*g = palette->colors[pixel].g;
*b = palette->colors[pixel].b;
*a = palette->colors[pixel].a;
if (palette && pixelvalue < (unsigned)palette->ncolors) {
*r = palette->colors[pixelvalue].r;
*g = palette->colors[pixelvalue].g;
*b = palette->colors[pixelvalue].b;
*a = palette->colors[pixelvalue].a;
} else {
*r = *g = *b = *a = 0;
}
@ -1359,23 +1359,23 @@ void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_P
if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
unsigned v;
v = (pixel & format->Rmask) >> format->Rshift;
v = (pixelvalue & format->Rmask) >> format->Rshift;
*r = (Uint8)(v >> 2);
v = (pixel & format->Gmask) >> format->Gshift;
v = (pixelvalue & format->Gmask) >> format->Gshift;
*g = (Uint8)(v >> 2);
v = (pixel & format->Bmask) >> format->Bshift;
v = (pixelvalue & format->Bmask) >> format->Bshift;
*b = (Uint8)(v >> 2);
v = (pixel & format->Amask) >> format->Ashift;
v = (pixelvalue & format->Amask) >> format->Ashift;
*a = SDL_expand_byte[format->Abits][v];
} else {
unsigned v;
v = (pixel & format->Rmask) >> format->Rshift;
v = (pixelvalue & format->Rmask) >> format->Rshift;
*r = SDL_expand_byte[format->Rbits][v];
v = (pixel & format->Gmask) >> format->Gshift;
v = (pixelvalue & format->Gmask) >> format->Gshift;
*g = SDL_expand_byte[format->Gbits][v];
v = (pixel & format->Bmask) >> format->Bshift;
v = (pixelvalue & format->Bmask) >> format->Bshift;
*b = SDL_expand_byte[format->Bbits][v];
v = (pixel & format->Amask) >> format->Ashift;
v = (pixelvalue & format->Amask) >> format->Ashift;
*a = SDL_expand_byte[format->Abits][v];
}
}

View File

@ -50,7 +50,7 @@ extern bool SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst);
// Miscellaneous functions
extern void SDL_DitherPalette(SDL_Palette *palette);
extern Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern Uint8 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixel, const SDL_Palette *pal);
extern Uint8 SDL_LookupRGBAColor(SDL_HashTable *palette_map, Uint32 pixelvalue, const SDL_Palette *pal);
extern void SDL_DetectPalette(const SDL_Palette *pal, bool *is_opaque, bool *has_alpha_channel);
extern SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormat format, SDL_Colorspace colorspace, void *pixels, int pitch);