Browse Source

pixels: Packed-pixel YUV formats can legit report bits-per-pixel.

This makes the existing SDL_SoftStretch code work with them, at least for
nearest-neighbor scaling; otherwise, it'll mangle the data trying to scale
it as 8bpp data without warning.
Ryan C. Gordon 1 year ago
parent
commit
3d2d5d18f3
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/video/SDL_pixels.c

+ 10 - 1
src/video/SDL_pixels.c

@@ -147,8 +147,17 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(Uint32 format, int *bpp, Uint32 *Rmask,
     /* Partial support for SDL_Surface with FOURCC */
     if (SDL_ISPIXELFORMAT_FOURCC(format)) {
         /* Not a format that uses masks */
-        *bpp = 0;
         *Rmask = *Gmask = *Bmask = *Amask = 0;
+        // however, some of these are packed formats, and can legit declare bits-per-pixel!
+        switch (format) {
+            case SDL_PIXELFORMAT_YUY2:
+            case SDL_PIXELFORMAT_UYVY:
+            case SDL_PIXELFORMAT_YVYU:
+                *bpp = 32;
+                break;
+            default:
+                *bpp = 0;  // oh well.
+        }
         return SDL_TRUE;
     }
 #else