@@ -108,6 +108,33 @@ PG_UnlockMutex(SDL_mutex *mutex)
108
108
#define PG_FORMAT_BytesPerPixel (format ) format->bytes_per_pixel
109
109
#define PG_SURF_FORMATENUM (surf ) surf->format
110
110
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
+
111
138
/* Mask to test if surface flags are in a fullscreen window. */
112
139
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN
113
140
@@ -176,6 +203,61 @@ PG_UnlockMutex(SDL_mutex *mutex)
176
203
#define PG_FORMAT_BytesPerPixel (format ) format->BytesPerPixel
177
204
#define PG_SURF_FORMATENUM (surf ) surf->format->format
178
205
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
+
179
261
/* Mask to test if surface flags are in a fullscreen window.
180
262
* SDL_WINDOW_FULLSCREEN_DESKTOP works here because it also contains
181
263
* SDL_WINDOW_FULLSCREEN. */
0 commit comments