Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,32 @@ PG_UnlockMutex(SDL_mutex *mutex)
return 0;
}

#define PG_SURF_BitsPerPixel(surf) SDL_BITSPERPIXEL(surf->format)
// Implementation from SDL_GetMasksForPixelFormat, which is used by
// SDL_InitPixelFormatDetails in SDL_pixels.c
// Created to match surf->format->BitsPerPixel in SDL2,
// details->bits_per_pixel in SDL3.
static inline int
PG_SURF_BitsPerPixel(SDL_Surface *surf)
{
if (SDL_ISPIXELFORMAT_FOURCC(surf->format)) {
// however, some of these are packed formats, and can legit declare
// bits-per-pixel!
switch (surf->format) {
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
return 32;
default:
return 0; // oh well.
}
}

if (SDL_BYTESPERPIXEL(surf->format) <= 2) {
return SDL_BITSPERPIXEL(surf->format);
}
return SDL_BYTESPERPIXEL(surf->format) * 8;
}

#define PG_SURF_BytesPerPixel(surf) SDL_BYTESPERPIXEL(surf->format)
#define PG_FORMAT_BitsPerPixel(format) format->bits_per_pixel
#define PG_FORMAT_BytesPerPixel(format) format->bytes_per_pixel
Expand Down
Loading