Skip to content

Commit 9e4941e

Browse files
committed
Port SDL_SetPaletteColors int->bool return
1 parent 4d94b75 commit 9e4941e

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

src_c/_pygame.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
131131
}
132132

133133
#define PG_GetSurfacePalette SDL_GetSurfacePalette
134+
#define PG_SetPaletteColors SDL_SetPaletteColors
134135

135136
#define PG_GetRGBA SDL_GetRGBA
136137
#define PG_GetRGB SDL_GetRGB
@@ -233,6 +234,13 @@ PG_GetSurfacePalette(SDL_Surface *surf)
233234
return surf->format->palette;
234235
}
235236

237+
static inline bool
238+
PG_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
239+
int firstcolor, int ncolors)
240+
{
241+
return SDL_SetPaletteColors(palette, colors, firstcolor, ncolors) == 0;
242+
}
243+
236244
// NOTE:
237245
// palette is part of the format in SDL2, so these functions below have it
238246
// as a separate parameter to be consistent with the SDL3 signature.

src_c/freetype/ft_render.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ _PGFT_Render_NewSurface(FreeTypeInstance *ft, pgFontObject *fontobj,
494494
colors[0].g = ~colors[1].g;
495495
colors[0].b = ~colors[1].b;
496496
colors[0].a = SDL_ALPHA_OPAQUE;
497-
if (SDL_SetPaletteColors(palette, colors, 0, 2)) {
497+
if (!PG_SetPaletteColors(palette, colors, 0, 2)) {
498498
PyErr_Format(PyExc_SystemError,
499499
"Pygame bug in _PGFT_Render_NewSurface: %.200s",
500500
SDL_GetError());

src_c/pixelcopy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,8 @@ make_surface(PyObject *self, PyObject *arg)
12101210
if (SDL_ISPIXELFORMAT_INDEXED(PG_SURF_FORMATENUM(surf))) {
12111211
/* Give the surface something other than an all white palette.
12121212
* */
1213-
if (SDL_SetPaletteColors(palette, default_palette_colors, 0,
1214-
default_palette_size - 1) != 0) {
1213+
if (!PG_SetPaletteColors(palette, default_palette_colors, 0,
1214+
default_palette_size - 1)) {
12151215
PyErr_SetString(pgExc_SDLError, SDL_GetError());
12161216
SDL_FreeSurface(surf);
12171217
return 0;

src_c/surface.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
674674
/* Give the surface something other than an all white palette.
675675
* */
676676
SDL_Palette *surf_palette = SDL_CreateSurfacePalette(surface);
677-
if (SDL_SetPaletteColors(surf_palette, default_palette_colors, 0,
678-
default_palette_size - 1) != 0) {
677+
if (!PG_SetPaletteColors(surf_palette, default_palette_colors, 0,
678+
default_palette_size - 1)) {
679679
PyErr_SetString(pgExc_SDLError, SDL_GetError());
680680
SDL_FreeSurface(surface);
681681
return -1;
@@ -858,9 +858,9 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
858858
if (SDL_ISPIXELFORMAT_INDEXED(PG_SURF_FORMATENUM(surface))) {
859859
/* Give the surface something other than an all white palette.
860860
* */
861-
if (SDL_SetPaletteColors(surface->format->palette,
861+
if (!PG_SetPaletteColors(surface->format->palette,
862862
default_palette_colors, 0,
863-
default_palette_size - 1) != 0) {
863+
default_palette_size - 1)) {
864864
PyErr_SetString(pgExc_SDLError, SDL_GetError());
865865
SDL_FreeSurface(surface);
866866
return -1;
@@ -1332,7 +1332,7 @@ surf_set_palette(PyObject *self, PyObject *seq)
13321332
}
13331333

13341334
if (!pal) {
1335-
return RAISE(pgExc_SDLError, "Surface is not palettitized\n");
1335+
return RAISE(pgExc_SDLError, "Surface is not palettized\n");
13361336
}
13371337
old_colors = pal->colors;
13381338

@@ -1360,8 +1360,7 @@ surf_set_palette(PyObject *self, PyObject *seq)
13601360
colors[i].a = (unsigned char)old_colors[i].a;
13611361
}
13621362

1363-
ecode = SDL_SetPaletteColors(pal, colors, 0, len);
1364-
if (ecode != 0) {
1363+
if (!PG_SetPaletteColors(pal, colors, 0, len)) {
13651364
return RAISE(pgExc_SDLError, SDL_GetError());
13661365
}
13671366
Py_RETURN_NONE;
@@ -1405,7 +1404,7 @@ surf_set_palette_at(PyObject *self, PyObject *args)
14051404
color.b = rgba[2];
14061405
color.a = pal->colors[_index].a; /* May be a colorkey color. */
14071406

1408-
if (SDL_SetPaletteColors(pal, &color, _index, 1) != 0) {
1407+
if (!PG_SetPaletteColors(pal, &color, _index, 1)) {
14091408
return RAISE(pgExc_SDLError, SDL_GetError());
14101409
}
14111410

@@ -3232,7 +3231,7 @@ surf_subsurface(PyObject *self, PyObject *args)
32323231
SDL_FreeSurface(sub);
32333232
return NULL;
32343233
}
3235-
if (SDL_SetPaletteColors(pal, colors, 0, ncolors) != 0) {
3234+
if (!PG_SetPaletteColors(pal, colors, 0, ncolors)) {
32363235
PyErr_SetString(pgExc_SDLError, SDL_GetError());
32373236
SDL_FreePalette(pal);
32383237
SDL_FreeSurface(sub);

src_c/transform.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
158158
return NULL;
159159
}
160160

161-
if (SDL_SetPaletteColors(newsurf_palette, surf_palette->colors, 0,
162-
surf_palette->ncolors) != 0) {
161+
if (!PG_SetPaletteColors(newsurf_palette, surf_palette->colors, 0,
162+
surf_palette->ncolors)) {
163163
PyErr_SetString(pgExc_SDLError, SDL_GetError());
164164
SDL_FreeSurface(newsurf);
165165
return NULL;

0 commit comments

Comments
 (0)