Fixes for upside-down DIBs.

diff --git a/graphics/metafiledrv/objects.c b/graphics/metafiledrv/objects.c
index ebdb49d..d64c02e 100644
--- a/graphics/metafiledrv/objects.c
+++ b/graphics/metafiledrv/objects.c
@@ -74,7 +74,7 @@
 		return FALSE;
 	    }
 
-	    bmSize = bm.bmHeight * DIB_GetDIBWidthBytes(bm.bmWidth, 1);
+	    bmSize = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, 1);
 
 	    len = sizeof(METARECORD) +  sizeof(WORD) + sizeof(BITMAPINFO) + 
 	      sizeof(RGBQUAD) + bmSize;
@@ -106,9 +106,9 @@
 	if (info->bmiHeader.biCompression)
             bmSize = info->bmiHeader.biSizeImage;
         else
-	    bmSize = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
-					  info->bmiHeader.biBitCount) 
-	               * info->bmiHeader.biHeight;
+	    bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
+					  info->bmiHeader.biHeight,
+					  info->bmiHeader.biBitCount);
 	biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush->lbColor)); 
 	len = sizeof(METARECORD) + biSize + bmSize + 2;
 	mr = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, len);
diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c
index 3ee6496..2ff7a19 100644
--- a/graphics/x11drv/dib.c
+++ b/graphics/x11drv/dib.c
@@ -1880,9 +1880,10 @@
   LeaveCriticalSection( &X11DRV_CritSection );
   
   if(info->bmiHeader.biSizeImage == 0) /* Fill in biSizeImage */
-    info->bmiHeader.biSizeImage = info->bmiHeader.biHeight *
-      DIB_GetDIBWidthBytes( info->bmiHeader.biWidth,
-			    info->bmiHeader.biBitCount );
+    info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(
+					 info->bmiHeader.biWidth,
+					 info->bmiHeader.biHeight,
+					 info->bmiHeader.biBitCount );
 
   if(bbits - (BYTE *)bits > info->bmiHeader.biSizeImage)
     ERR(bitmap, "Buffer overrun. Please investigate.\n");
diff --git a/include/bitmap.h b/include/bitmap.h
index f7a8902..45399a3 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -55,6 +55,7 @@
 
   /* objects/dib.c */
 extern int DIB_GetDIBWidthBytes( int width, int depth );
+extern int DIB_GetDIBImageBytes( int width, int height, int depth );
 extern int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse );
 extern int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
                               int *height, WORD *bpp, WORD *compr );
diff --git a/objects/brush.c b/objects/brush.c
index ebe4e97..baaec06 100644
--- a/objects/brush.c
+++ b/objects/brush.c
@@ -114,9 +114,9 @@
     if (info->bmiHeader.biCompression)
         size = info->bmiHeader.biSizeImage;
     else
-	size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
-				    info->bmiHeader.biBitCount) *
-	       info->bmiHeader.biHeight;
+	size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
+				    info->bmiHeader.biHeight,
+				    info->bmiHeader.biBitCount);
     size += DIB_BitmapInfoSize( info, coloruse );
 
     if (!(logbrush.lbHatch = (INT16)GlobalAlloc16( GMEM_MOVEABLE, size )))
@@ -164,9 +164,9 @@
     if (info->bmiHeader.biCompression)
         size = info->bmiHeader.biSizeImage;
     else
-	size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
-				    info->bmiHeader.biBitCount) *
-	       info->bmiHeader.biHeight;
+	size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
+				    info->bmiHeader.biHeight,
+				    info->bmiHeader.biBitCount);
     size += DIB_BitmapInfoSize( info, coloruse );
 
     if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
@@ -204,7 +204,8 @@
     BITMAPINFO  *newInfo;
     INT size;
     
-    TRACE(gdi, "%p\n", info );
+    TRACE(gdi, "%p %ldx%ld %dbpp\n", info, info->bmiHeader.biWidth,
+	  info->bmiHeader.biHeight,  info->bmiHeader.biBitCount);
 
       /* Make a copy of the bitmap */
 
@@ -212,9 +213,9 @@
     if (info->bmiHeader.biCompression)
         size = info->bmiHeader.biSizeImage;
     else
-	size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
-				    info->bmiHeader.biBitCount) *
-	       info->bmiHeader.biHeight;
+	size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
+				    info->bmiHeader.biHeight,
+				    info->bmiHeader.biBitCount);
     size += DIB_BitmapInfoSize( info, coloruse );
 
     if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index 33ed6cf..7509af6 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -524,9 +524,10 @@
 		CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS );
 	    if( hXorBits )
 	    {
-		char* bits = (char *)bmi + size + bmi->bmiHeader.biHeight *
-				DIB_GetDIBWidthBytes(bmi->bmiHeader.biWidth,
-						     bmi->bmiHeader.biBitCount) / 2;
+		char* bits = (char *)bmi + size +
+			DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
+					     bmi->bmiHeader.biHeight,
+					     bmi->bmiHeader.biBitCount) / 2;
 
 		pInfo->bmiHeader.biBitCount = 1;
 	        if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
diff --git a/objects/dib.c b/objects/dib.c
index 917b849..3f4fabc 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -40,6 +40,16 @@
     return 4 * words;
 }
 
+/***********************************************************************
+ *           DIB_GetDIBImageBytes
+ *
+ * Return the number of bytes used to hold the image in a DIB bitmap.
+ */
+int DIB_GetDIBImageBytes( int width, int height, int depth )
+{
+    return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
+}
+
 
 /***********************************************************************
  *           DIB_BitmapInfoSize
@@ -537,16 +547,18 @@
 	    info->bmiHeader.biHeight = bmp->bitmap.bmHeight;
 	    info->bmiHeader.biPlanes = 1;
 	    info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel;
-	    info->bmiHeader.biSizeImage = bmp->bitmap.bmHeight *
-                             DIB_GetDIBWidthBytes( bmp->bitmap.bmWidth,
-                                                   bmp->bitmap.bmBitsPixel );
+	    info->bmiHeader.biSizeImage = 
+                             DIB_GetDIBImageBytes( bmp->bitmap.bmWidth,
+						   bmp->bitmap.bmHeight,
+						   bmp->bitmap.bmBitsPixel );
 	    info->bmiHeader.biCompression = 0;
 	}
 	else
 	{
-	    info->bmiHeader.biSizeImage = info->bmiHeader.biHeight *
-	                    DIB_GetDIBWidthBytes( info->bmiHeader.biWidth,
-						  info->bmiHeader.biBitCount );
+	    info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(
+					       info->bmiHeader.biWidth,
+					       info->bmiHeader.biHeight,
+					       info->bmiHeader.biBitCount );
 	}
     }