Florian Forster to sdl
authorSam Lantinga
Wed, 19 Jan 2011 16:06:47 -0800
changeset 5043da347bfed240
parent 5042 8c39b82dc7b0
child 5044 4913042e8572
Florian Forster to sdl

in SDL 1.3 (revision 5508 from SVN), the method used to calculate the
bits per pixel from a “int format” differ between “SDL_ListModes” (which
always uses the “SDL_BITSPERPIXEL” macro) and “SDL_PixelFormatEnumTo-
Masks” (which uses either “SDL_BITSPERPIXEL” or “SDL_BYTESPERPIXEL * 8”,
depending on the value of “SDL_BYTESPERPIXEL”).

Because the values are later compared in “SDL_ListModes” this may lead
to some valid video modes not being returned. In my case the only mode
returned by “SDL_GetNumDisplayModes” was dismissed and NULL was
returned. (This led to the calling application sticking its head in the
sand.)

The attached patch copies the method used within “SDL_PixelFormatEnumTo-
Masks” to “SDL_ListModes”. This solved the problem for me though I don't
fully understand the method used by “SDL_PixelFormatEnumToMasks”.
src/SDL_compat.c
     1.1 --- a/src/SDL_compat.c	Wed Jan 19 16:02:15 2011 -0800
     1.2 +++ b/src/SDL_compat.c	Wed Jan 19 16:06:47 2011 -0800
     1.3 @@ -155,11 +155,21 @@
     1.4      modes = NULL;
     1.5      for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
     1.6          SDL_DisplayMode mode;
     1.7 +        int bpp;
     1.8 +
     1.9          SDL_GetDisplayMode(i, &mode);
    1.10          if (!mode.w || !mode.h) {
    1.11              return (SDL_Rect **) (-1);
    1.12          }
    1.13 -        if (SDL_BITSPERPIXEL(mode.format) != format->BitsPerPixel) {
    1.14 +        
    1.15 +        /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */
    1.16 +        if (SDL_BYTESPERPIXEL(mode.format) <= 2) {
    1.17 +            bpp = SDL_BITSPERPIXEL(mode.format);
    1.18 +        } else {
    1.19 +            bpp = SDL_BYTESPERPIXEL(mode.format) * 8;
    1.20 +        }
    1.21 +
    1.22 +        if (bpp != format->BitsPerPixel) {
    1.23              continue;
    1.24          }
    1.25          if (nmodes > 0 && modes[nmodes - 1]->w == mode.w