Skip to content

Commit ef726d9

Browse files
committed
Port SDL_SetSurfacePalette
1 parent 872c3dc commit ef726d9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src_c/_pygame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
133133

134134
#define PG_GetSurfacePalette SDL_GetSurfacePalette
135135
#define PG_SetPaletteColors SDL_SetPaletteColors
136+
#define PG_SetSurfacePalette SDL_SetSurfacePalette
136137
#define PG_SetSurfaceColorKey SDL_SetSurfaceColorKey
137138
#define PG_SetSurfaceBlendMode SDL_SetSurfaceBlendMode
138139
#define PG_GetSurfaceBlendMode SDL_GetSurfaceBlendMode
@@ -250,6 +251,12 @@ PG_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
250251
return SDL_SetPaletteColors(palette, colors, firstcolor, ncolors) == 0;
251252
}
252253

254+
static inline bool
255+
PG_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
256+
{
257+
return SDL_SetSurfacePalette(surface, palette) == 0;
258+
}
259+
253260
static inline bool
254261
PG_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key)
255262
{

src_c/image.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,9 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle)
17951795
}
17961796

17971797
if (h.has_cmap) {
1798-
#if SDL_VERSION_ATLEAST(3, 0, 0)
1799-
if (!SDL_SetSurfacePalette(linebuf, surf_palette))
1800-
#else
1801-
if (SDL_SetSurfacePalette(linebuf, surf_palette) < 0)
1802-
#endif
1798+
if (!PG_SetSurfacePalette(linebuf, surf_palette)) {
18031799
goto error; /* SDL error already set. */
1800+
}
18041801
}
18051802

18061803
if (rle) {

src_c/surface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,7 @@ surf_subsurface(PyObject *self, PyObject *args)
32363236
SDL_FreeSurface(sub);
32373237
return NULL;
32383238
}
3239-
if (SDL_SetSurfacePalette(sub, pal) != 0) {
3239+
if (!PG_SetSurfacePalette(sub, pal)) {
32403240
PyErr_SetString(pgExc_SDLError, SDL_GetError());
32413241
SDL_FreePalette(pal);
32423242
SDL_FreeSurface(sub);

0 commit comments

Comments
 (0)