- NtGdiSetDIBitsToDeviceInternal: use bitmap's palette if it exists instead of always...
authorAleksey Bragin <aleksey@reactos.org>
Thu, 2 Apr 2009 17:25:56 +0000 (17:25 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Thu, 2 Apr 2009 17:25:56 +0000 (17:25 +0000)
See issue #4326 for more details.

svn path=/trunk/; revision=40331

reactos/subsystems/win32/win32k/objects/dibobj.c

index e59bf9d..8112553 100644 (file)
@@ -437,6 +437,7 @@ NtGdiSetDIBitsToDeviceInternal(
     PDC pDC;
     HBITMAP hSourceBitmap = NULL;
     SURFOBJ *pDestSurf, *pSourceSurf = NULL;
+    SURFACE *pSurf;
     RECTL rcDest;
     POINTL ptSource;
     INT DIBWidth;
@@ -476,14 +477,19 @@ NtGdiSetDIBitsToDeviceInternal(
         return 0;
     }
 
-    pDestSurf = EngLockSurface((HSURF)pDC->rosdc.hBitmap);
-    if (!pDestSurf)
+    /* Use destination palette obtained from the DC by default */
+    DDBPalette = pDC->ppdev->DevInfo.hpalDefault;
+
+    /* Try to use hDIBPalette if it exists */
+    pSurf = SURFACE_LockSurface(pDC->rosdc.hBitmap);
+    if (pSurf && pSurf->hDIBPalette)
     {
-        /* FIXME: SetLastError ? */
-        DC_UnlockDc(pDC);
-        return 0;
+        DDBPalette = pSurf->hDIBPalette;
+        SURFACE_UnlockSurface(pSurf);
     }
 
+    pDestSurf = EngLockSurface((HSURF)pDC->rosdc.hBitmap);
+
     rcDest.left = XDest;
     rcDest.top = YDest;
     if (bTransformCoordinates)
@@ -521,8 +527,8 @@ NtGdiSetDIBitsToDeviceInternal(
        goto Exit;
     }
 
-    /* Obtain destination palette from the DC */
-    pDCPalette = PALETTE_LockPalette(pDC->ppdev->DevInfo.hpalDefault);
+    /* Obtain destination palette */
+    pDCPalette = PALETTE_LockPalette(DDBPalette);
     if (!pDCPalette)
     {
        SetLastWin32Error(ERROR_INVALID_HANDLE);
@@ -531,7 +537,6 @@ NtGdiSetDIBitsToDeviceInternal(
     }
 
     DDBPaletteType = pDCPalette->Mode;
-    DDBPalette = pDC->ppdev->DevInfo.hpalDefault;
     PALETTE_UnlockPalette(pDCPalette);
 
     DIBPalette = BuildDIBPalette(bmi, (PINT)&DIBPaletteType);