Skip to content

Commit 4cfa7cc

Browse files
Starbuck5ankith26
andcommittedJan 26, 2025
Add more pixelformat compat symbols
Co-Authored-By: Ankith <itsankith26@gmail.com>
1 parent 9825809 commit 4cfa7cc

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
 

‎src_c/_pygame.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ PG_UnlockMutex(SDL_mutex *mutex)
108108
#define PG_FORMAT_BytesPerPixel(format) format->bytes_per_pixel
109109
#define PG_SURF_FORMATENUM(surf) surf->format
110110

111+
#define PG_FORMAT_R_LOSS(format) (8 - format->Rbits)
112+
#define PG_FORMAT_G_LOSS(format) (8 - format->Gbits)
113+
#define PG_FORMAT_B_LOSS(format) (8 - format->Bbits)
114+
#define PG_FORMAT_A_LOSS(format) (8 - format->Abits)
115+
116+
#define PG_PixelFormat const SDL_PixelFormatDetails
117+
118+
static inline bool
119+
PG_GetSurfaceDetails(SDL_Surface *surf, PG_PixelFormat **format_p,
120+
SDL_Palette **palette_p)
121+
{
122+
*palette_p = SDL_GetSurfacePalette(surf);
123+
*format_p = SDL_GetPixelFormatDetails(surf->format);
124+
return *format_p != NULL;
125+
}
126+
127+
static inline PG_PixelFormat *
128+
PG_GetSurfaceFormat(SDL_Surface *surf)
129+
{
130+
return SDL_GetPixelFormatDetails(surf->format);
131+
}
132+
133+
#define PG_GetRGBA SDL_GetRGBA
134+
#define PG_GetRGB SDL_GetRGB
135+
#define PG_MapRGBA SDL_MapRGBA
136+
#define PG_MapRGB SDL_MapRGB
137+
111138
/* Mask to test if surface flags are in a fullscreen window. */
112139
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN
113140

@@ -176,6 +203,61 @@ PG_UnlockMutex(SDL_mutex *mutex)
176203
#define PG_FORMAT_BytesPerPixel(format) format->BytesPerPixel
177204
#define PG_SURF_FORMATENUM(surf) surf->format->format
178205

206+
#define PG_FORMAT_R_LOSS(format) format->Rloss
207+
#define PG_FORMAT_G_LOSS(format) format->Gloss
208+
#define PG_FORMAT_B_LOSS(format) format->Bloss
209+
#define PG_FORMAT_A_LOSS(format) format->Aloss
210+
211+
#define PG_PixelFormat SDL_PixelFormat
212+
213+
static inline bool
214+
PG_GetSurfaceDetails(SDL_Surface *surf, PG_PixelFormat **format_p,
215+
SDL_Palette **palette_p)
216+
{
217+
*format_p = surf->format;
218+
*palette_p = surf->format->palette;
219+
return true;
220+
}
221+
222+
static inline PG_PixelFormat *
223+
PG_GetSurfaceFormat(SDL_Surface *surf)
224+
{
225+
return surf->format;
226+
}
227+
228+
// NOTE:
229+
// palette is part of the format in SDL2, so these functions below have it
230+
// as a separate parameter to be consistent with the SDL3 signature.
231+
// They are ignoring the palette parameter, but not the palette data.
232+
233+
static inline void
234+
PG_GetRGBA(Uint32 pixel, PG_PixelFormat *format, const SDL_Palette *palette,
235+
Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
236+
{
237+
SDL_GetRGBA(pixel, format, r, g, b, a);
238+
}
239+
240+
static inline void
241+
PG_GetRGB(Uint32 pixel, PG_PixelFormat *format, const SDL_Palette *palette,
242+
Uint8 *r, Uint8 *g, Uint8 *b)
243+
{
244+
SDL_GetRGB(pixel, format, r, g, b);
245+
}
246+
247+
static inline Uint32
248+
PG_MapRGBA(PG_PixelFormat *format, const SDL_Palette *palette, Uint8 r,
249+
Uint8 g, Uint8 b, Uint8 a)
250+
{
251+
return SDL_MapRGBA(format, r, g, b, a);
252+
}
253+
254+
static inline Uint32
255+
PG_MapRGB(PG_PixelFormat *format, const SDL_Palette *palette, Uint8 r, Uint8 g,
256+
Uint8 b)
257+
{
258+
return SDL_MapRGB(format, r, g, b);
259+
}
260+
179261
/* Mask to test if surface flags are in a fullscreen window.
180262
* SDL_WINDOW_FULLSCREEN_DESKTOP works here because it also contains
181263
* SDL_WINDOW_FULLSCREEN. */

0 commit comments

Comments
 (0)