File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,32 @@ PG_UnlockMutex(SDL_mutex *mutex)
105105 return 0 ;
106106}
107107
108- #define PG_SURF_BitsPerPixel (surf ) SDL_BITSPERPIXEL(surf->format)
108+ // Implementation from SDL_GetMasksForPixelFormat, which is used by
109+ // SDL_InitPixelFormatDetails in SDL_pixels.c
110+ // Created to match surf->format->BitsPerPixel in SDL2,
111+ // details->bits_per_pixel in SDL3.
112+ static inline int
113+ PG_SURF_BitsPerPixel (SDL_Surface * surf )
114+ {
115+ if (SDL_ISPIXELFORMAT_FOURCC (surf -> format )) {
116+ // however, some of these are packed formats, and can legit declare
117+ // bits-per-pixel!
118+ switch (surf -> format ) {
119+ case SDL_PIXELFORMAT_YUY2 :
120+ case SDL_PIXELFORMAT_UYVY :
121+ case SDL_PIXELFORMAT_YVYU :
122+ return 32 ;
123+ default :
124+ return 0 ; // oh well.
125+ }
126+ }
127+
128+ if (SDL_BYTESPERPIXEL (surf -> format ) <= 2 ) {
129+ return SDL_BITSPERPIXEL (surf -> format );
130+ }
131+ return SDL_BYTESPERPIXEL (surf -> format ) * 8 ;
132+ }
133+
109134#define PG_SURF_BytesPerPixel (surf ) SDL_BYTESPERPIXEL(surf->format)
110135#define PG_FORMAT_BitsPerPixel (format ) format->bits_per_pixel
111136#define PG_FORMAT_BytesPerPixel (format ) format->bytes_per_pixel
You can’t perform that action at this time.
0 commit comments