7777
7878#define PG_CreateSurface SDL_CreateSurface
7979#define PG_CreateSurfaceFrom SDL_CreateSurfaceFrom
80- #define PG_ConvertSurface SDL_ConvertSurface
8180#define PG_ConvertSurfaceFormat SDL_ConvertSurface
8281
82+ /* Convert surface using palette and format of dst */
83+ static inline SDL_Surface *
84+ PG_ConvertSurface (SDL_Surface * surface , SDL_Surface * dst )
85+ {
86+ return SDL_ConvertSurfaceAndColorspace (surface , dst -> format ,
87+ SDL_GetSurfacePalette (dst ),
88+ SDL_GetSurfaceColorspace (dst ), 0 );
89+ }
90+
8391#define PG_PixelFormatEnum SDL_PixelFormat
8492
8593#define PG_SurfaceHasRLE SDL_SurfaceHasRLE
@@ -144,11 +152,23 @@ PG_SURF_BitsPerPixel(SDL_Surface *surf)
144152
145153#define PG_PixelFormat const SDL_PixelFormatDetails
146154
155+ static inline SDL_Palette *
156+ PG_GetSurfacePalette (SDL_Surface * surf )
157+ {
158+ SDL_Palette * ret = SDL_GetSurfacePalette (surf );
159+ if (!ret && SDL_ISPIXELFORMAT_INDEXED (surf -> format )) {
160+ /* Palette doesn't exist but is expected, so create it.
161+ * SDL will associate the newly created palette with the surface */
162+ ret = SDL_CreateSurfacePalette (surf );
163+ }
164+ return ret ;
165+ }
166+
147167static inline bool
148168PG_GetSurfaceDetails (SDL_Surface * surf , PG_PixelFormat * * format_p ,
149169 SDL_Palette * * palette_p )
150170{
151- * palette_p = SDL_GetSurfacePalette (surf );
171+ * palette_p = PG_GetSurfacePalette (surf );
152172 * format_p = SDL_GetPixelFormatDetails (surf -> format );
153173 return * format_p != NULL ;
154174}
@@ -159,7 +179,6 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
159179 return SDL_GetPixelFormatDetails (surf -> format );
160180}
161181
162- #define PG_GetSurfacePalette SDL_GetSurfacePalette
163182#define PG_SetPaletteColors SDL_SetPaletteColors
164183#define PG_SetSurfacePalette SDL_SetSurfacePalette
165184#define PG_SetSurfaceColorKey SDL_SetSurfaceColorKey
@@ -215,10 +234,15 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
215234 SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, format)
216235#define PG_CreateSurfaceFrom (width , height , format , pixels , pitch ) \
217236 SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, 0, pitch, format)
218- #define PG_ConvertSurface (src , fmt ) SDL_ConvertSurface(src, fmt, 0)
219237#define PG_ConvertSurfaceFormat (src , pixel_format ) \
220238 SDL_ConvertSurfaceFormat(src, pixel_format, 0)
221239
240+ static inline SDL_Surface *
241+ PG_ConvertSurface (SDL_Surface * surface , SDL_Surface * dst )
242+ {
243+ return SDL_ConvertSurface (surface , dst -> format , 0 );
244+ }
245+
222246#define PG_PixelFormatEnum SDL_PixelFormatEnum
223247
224248#define PG_SoftStretchNearest (src , srcrect , dst , dstrect ) \
0 commit comments