[WIN32K]
[reactos.git] / reactos / win32ss / gdi / ntgdi / dibobj.c
index 36bfa4d..bd7999a 100644 (file)
@@ -260,23 +260,26 @@ IntSetDIBits(
     EXLATEOBJ  exlo;
     PPALETTE    ppalDIB = 0;
     ULONG cjSizeImage;
+    BOOL bCompressed;
 
-    if (!bmi) return 0;
+    if (!bmi || !Bits) return 0;
 
-    /* Check if the header provided an image size */
-    if (bmi->bmiHeader.biSizeImage != 0)
-    {
-        /* Use the given size */
-        cjSizeImage = bmi->bmiHeader.biSizeImage;
-    }
-    /* Otherwise check for uncompressed formats */
-    else if ((bmi->bmiHeader.biCompression == BI_RGB) ||
+    /* Check for uncompressed formats */
+    if ((bmi->bmiHeader.biCompression == BI_RGB) ||
              (bmi->bmiHeader.biCompression == BI_BITFIELDS))
     {
         /* Calculate the image size */
         cjSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
                                            ScanLines,
                                            bmi->bmiHeader.biBitCount);
+        bCompressed = FALSE;
+    }
+    /* Check if the header provided an image size */
+    else if (bmi->bmiHeader.biSizeImage != 0)
+    {
+        /* Use the given size */
+        cjSizeImage = bmi->bmiHeader.biSizeImage;
+        bCompressed = TRUE;
     }
     else
     {
@@ -293,6 +296,8 @@ IntSetDIBits(
         return 0;
     }
 
+    /* We cannot use the provided buffer for uncompressed bits, since they
+       might not be aligned correctly! */
     SourceBitmap = GreCreateBitmapEx(bmi->bmiHeader.biWidth,
                                      ScanLines,
                                      0,
@@ -300,7 +305,7 @@ IntSetDIBits(
                                                   bmi->bmiHeader.biCompression),
                                      bmi->bmiHeader.biHeight < 0 ? BMF_TOPDOWN : 0,
                                      cjSizeImage,
-                                     (PVOID)Bits,
+                                     bCompressed ? (PVOID)Bits : NULL,
                                      0);
     if (!SourceBitmap)
     {
@@ -318,6 +323,17 @@ IntSetDIBits(
         goto cleanup;
     }
 
+    /* Check for uncompressed bits */
+    if (!bCompressed)
+    {
+        /* Copy the bitmap bits */
+        if (!UnsafeSetBitmapBits(psurfSrc, cjMaxBits, Bits))
+        {
+            DPRINT1("Error: Could not set bitmap bits\n");
+            goto cleanup;
+        }
+    }
+
     /* Create a palette for the DIB */
     ppalDIB = CreateDIBPalette(bmi, DC, ColorUse);
     if (!ppalDIB)
@@ -341,8 +357,6 @@ IntSetDIBits(
     ptSrc.x = 0;
     ptSrc.y = 0;
 
-    NT_ASSERT(psurfSrc->SurfObj.cjBits <= cjMaxBits);
-
     result = IntEngCopyBits(&psurfDst->SurfObj,
                             &psurfSrc->SurfObj,
                             NULL,
@@ -1456,6 +1470,11 @@ NtGdiCreateDIBitmapInternal(
     PBYTE safeBits = NULL;
     HBITMAP hbmResult = NULL;
 
+    if (pjInit == NULL)
+    {
+        fInit &= ~CBM_INIT;
+    }
+
     if(pjInit && (fInit & CBM_INIT))
     {
         if (cjMaxBits == 0) return NULL;