Fix the bitmap info size computation when masks are present.
authorAlexandre Julliard <julliard@winehq.org>
Fri, 14 May 2010 15:17:46 +0000 (17:17 +0200)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 14 May 2010 15:17:46 +0000 (17:17 +0200)
dlls/gdi32/dib.c
dlls/user32/cursoricon.c
dlls/winex11.drv/dib.c

index 1b34a341043649e6521ec5181f05623b4ec2554e..b19cb9d47b326c8963b17697ce65dd5b7a430052 100644 (file)
@@ -123,7 +123,7 @@ int DIB_GetDIBImageBytes( int width, int height, int depth )
  */
 int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
 {
-    int colors, masks = 0;
+    unsigned int colors, size, masks = 0;
 
     if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
     {
@@ -139,8 +139,8 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
         if (!colors && (info->bmiHeader.biBitCount <= 8))
             colors = 1 << info->bmiHeader.biBitCount;
         if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
-        return info->bmiHeader.biSize + masks * sizeof(DWORD) + colors *
-               ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
+        size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
+        return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
     }
 }
 
index 96827c26fa4c8099e111f570e578c480cf71a6f4..8cccbbe4adf36362b6c9192d8edf12ddcaf6efb5 100644 (file)
@@ -304,7 +304,7 @@ static int get_dib_width_bytes( int width, int depth )
  */
 static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
 {
-    int colors, masks = 0;
+    unsigned int colors, size, masks = 0;
 
     if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
     {
@@ -321,8 +321,8 @@ static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
         if (!colors && (info->bmiHeader.biBitCount <= 8))
             colors = 1 << info->bmiHeader.biBitCount;
         if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
-        return info->bmiHeader.biSize + masks * sizeof(DWORD) + colors *
-               ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
+        size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
+        return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
     }
 }
 
index 95e3511791e680a7942158b9257835645238c47a..cf58e8bd1fcbc90f378f0006b1a218cf46e9346c 100644 (file)
@@ -193,7 +193,7 @@ static int X11DRV_DIB_GetDIBImageBytes( int width, int height, int depth )
  */
 int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
 {
-    unsigned int colors, masks = 0;
+    unsigned int colors, size, masks = 0;
 
     if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
     {
@@ -208,8 +208,8 @@ int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
         if (!colors && (info->bmiHeader.biBitCount <= 8))
             colors = 1 << info->bmiHeader.biBitCount;
         if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
-        return info->bmiHeader.biSize + masks * sizeof(DWORD) + colors *
-               ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
+        size = max( info->bmiHeader.biSize, sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) );
+        return size + colors * ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
     }
 }