[GDI32]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 27 Feb 2011 17:20:02 +0000 (17:20 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sun, 27 Feb 2011 17:20:02 +0000 (17:20 +0000)
In GetDIBits convert a BITMAPCOREHEADER to a BITMAPINFOHEADER before calling win32k, like done in other places. Convert it back after. This allows to simplify NtGdiGetDIBitsInternal (not done yet)

svn path=/trunk/; revision=50918

reactos/dll/win32/gdi32/objects/bitmap.c

index 969beb6..6788a9d 100644 (file)
@@ -410,6 +410,33 @@ CreateCompatibleBitmap(
     return CreateDIBSection(hDC, (CONST BITMAPINFO *)&dibs.dsBmih, 0, NULL, NULL, 0);
 }
 
     return CreateDIBSection(hDC, (CONST BITMAPINFO *)&dibs.dsBmih, 0, NULL, NULL, 0);
 }
 
+void
+ConvertBackBitmapInfo(PBITMAPINFO pbmi, PBITMAPINFO pbmiConverted)
+{
+    /* Check if we converted from PBITMAPCOREINFO */
+    if (pbmiConverted != pbmi)
+    {
+        PBITMAPCOREINFO pbci = (PBITMAPCOREINFO)pbmi;
+
+        /* Convert back header */
+        pbci->bmciHeader.biSize = sizeof(BITMAPCOREHEADER);
+        pbci->bmciHeader.bcWidth = pbmiConverted->bmiHeader.biWidth;
+        pbci->bmciHeader.bcHeight = pbmiConverted->bmiHeader.biHeight;
+        pbci->bmciHeader.bcPlanes = 1;
+        pbci->bmciHeader.bcBitCount = pbmiConverted->bmiHeader.biBitCount;
+
+        /* Convert back colors */
+        for (i = 0; i < pbmiConverted->bmiHeader.biClrUsed; i++)
+        {
+            pbci->bmciColors.rgbtRed = pbmiConverted->bmiColors.rgbRed;
+            pbci->bmciColors.rgbtGreen = pbmiConverted->bmiColors.rgbGreen;
+            pbci->bmciColors.rgbtBlue = pbmiConverted->bmiColors.rgbBlue;
+        }
+
+        /* Free memory */
+        RtlFreeHeap(RtlGetProcessHeap(), 0, pbmiConverted);
+    }
+}
 
 INT
 WINAPI
 
 INT
 WINAPI
@@ -422,8 +449,9 @@ GetDIBits(
     LPBITMAPINFO lpbmi,
     UINT uUsage)
 {
     LPBITMAPINFO lpbmi,
     UINT uUsage)
 {
-    UINT cjBmpScanSize;
-    UINT cjInfoSize;
+    PBITMAPINFO pbmiConverted;
+    UINT cjBmpScanSize, cjInfoSize;
+    INT iResult;
 
     if (!hDC || !GdiIsHandleValid((HGDIOBJ)hDC) || !lpbmi)
     {
 
     if (!hDC || !GdiIsHandleValid((HGDIOBJ)hDC) || !lpbmi)
     {
@@ -431,15 +459,22 @@ GetDIBits(
         return 0;
     }
 
         return 0;
     }
 
+    /* Convert BITMAPINFO to a proper format */
+    pbmiConverted = ConvertBitmapInfo(lpbmi, uUsage, &cjInfoSize, FALSE);
+    if (!pbmiConverted)
+    {
+        GdiSetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+
     cjBmpScanSize = DIB_BitmapMaxBitsSize(lpbmi, cScanLines);
     cjBmpScanSize = DIB_BitmapMaxBitsSize(lpbmi, cScanLines);
-    cjInfoSize = DIB_BitmapInfoSize(lpbmi, uUsage);
 
 
-    if ( lpvBits )
+    if (lpvBits)
     {
     {
-        if ( lpbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
+        if (lpbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER))
         {
         {
-            if ( lpbmi->bmiHeader.biCompression == BI_JPEG ||
-                    lpbmi->bmiHeader.biCompression == BI_PNG )
+            if (lpbmi->bmiHeader.biCompression == BI_JPEG ||
+                lpbmi->bmiHeader.biCompression == BI_PNG)
             {
                 SetLastError(ERROR_INVALID_PARAMETER);
                 return 0;
             {
                 SetLastError(ERROR_INVALID_PARAMETER);
                 return 0;
@@ -447,17 +482,22 @@ GetDIBits(
         }
     }
 
         }
     }
 
-    return NtGdiGetDIBitsInternal(hDC,
-                                  hbmp,
-                                  uStartScan,
-                                  cScanLines,
-                                  lpvBits,
-                                  lpbmi,
-                                  uUsage,
-                                  cjBmpScanSize,
-                                  cjInfoSize);
+    iResult = NtGdiGetDIBitsInternal(hDC,
+                                     hbmp,
+                                     uStartScan,
+                                     cScanLines,
+                                     lpvBits,
+                                     pbmiConverted,
+                                     uUsage,
+                                     cjBmpScanSize,
+                                     cjInfoSize);
+
+    ConvertBackBitmapInfo(lpbmi, pbmiConverted);
+
+    return iResult;
 }
 
 }
 
+
 /*
  * @implemented
  */
 /*
  * @implemented
  */