[WIN32K]
[reactos.git] / reactos / subsystems / win32 / win32k / objects / dibobj.c
index 6ab2f6c..1a26cd6 100644 (file)
@@ -193,9 +193,8 @@ IntGetDIBColorTable(
 {
     PDC dc;
     PSURFACE psurf;
-    PPALETTE PalGDI;
+    PPALETTE ppal;
     UINT Index, Count = 0;
-    ULONG biBitCount;
 
     if (!(dc = DC_LockDc(hDC))) return 0;
     if (dc->dctype == DC_TYPE_INFO)
@@ -219,33 +218,22 @@ IntGetDIBColorTable(
         return 0;
     }
 
-    biBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
-    if (biBitCount <= 8 &&
-            StartIndex < (1 << biBitCount))
-    {
-        if (StartIndex + Entries > (1 << biBitCount))
-            Entries = (1 << biBitCount) - StartIndex;
+    ppal = psurf->ppal;
+    ASSERT(ppal);
 
-        if (psurf->ppal == NULL)
-        {
-            DC_UnlockDc(dc);
-            EngSetLastError(ERROR_INVALID_HANDLE);
-            return 0;
-        }
-
-        PalGDI = PALETTE_LockPalette(psurf->ppal->BaseObject.hHmgr);
+    if (ppal->flFlags & PAL_INDEXED)
+    {
 
         for (Index = StartIndex;
-             Index < StartIndex + Entries && Index < PalGDI->NumColors;
+             Index < StartIndex + Entries && Index < ppal->NumColors;
              Index++)
         {
-            Colors[Index - StartIndex].rgbRed = PalGDI->IndexedColors[Index].peRed;
-            Colors[Index - StartIndex].rgbGreen = PalGDI->IndexedColors[Index].peGreen;
-            Colors[Index - StartIndex].rgbBlue = PalGDI->IndexedColors[Index].peBlue;
+            Colors[Index - StartIndex].rgbRed = ppal->IndexedColors[Index].peRed;
+            Colors[Index - StartIndex].rgbGreen = ppal->IndexedColors[Index].peGreen;
+            Colors[Index - StartIndex].rgbBlue = ppal->IndexedColors[Index].peBlue;
             Colors[Index - StartIndex].rgbReserved = 0;
             Count++;
         }
-        PALETTE_UnlockPalette(PalGDI);
     }
 
     DC_UnlockDc(dc);
@@ -649,7 +637,7 @@ NtGdiGetDIBitsInternal(
     }
 
     /* Get a pointer to the source bitmap object */
-    psurf = SURFACE_LockSurface(hBitmap);
+    psurf = SURFACE_ShareLockSurface(hBitmap);
     if (psurf == NULL)
     {
         ScanLines = 0;
@@ -944,18 +932,35 @@ NtGdiGetDIBitsInternal(
                        goto done ;
                }
 
-               psurfDest = SURFACE_LockSurface(hBmpDest);
+               psurfDest = SURFACE_ShareLockSurface(hBmpDest);
 
                rcDest.left = 0;
                rcDest.top = 0;
                rcDest.bottom = ScanLines;
                rcDest.right = psurf->SurfObj.sizlBitmap.cx;
 
-               srcPoint.x = 0;
-               srcPoint.y = height < 0 ?
-                       psurf->SurfObj.sizlBitmap.cy - (StartScan + ScanLines) : StartScan;
+        srcPoint.x = 0;
+
+        if(height < 0)
+        {
+            srcPoint.y = 0;
+
+            if(ScanLines <= StartScan)
+            {
+                ScanLines = 1;
+                SURFACE_ShareUnlockSurface(psurfDest);
+                GreDeleteObject(hBmpDest);
+                goto done;
+            }
+
+            ScanLines -= StartScan;
+        }
+        else
+        {
+            srcPoint.y = StartScan;
+        }
 
-               EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0, 0, 0);
+               EXLATEOBJ_vInitialize(&exlo, psurf->ppal, psurfDest->ppal, 0xffffff, 0xffffff, 0);
 
                ret = IntEngCopyBits(&psurfDest->SurfObj,
                                                         &psurf->SurfObj,
@@ -964,6 +969,8 @@ NtGdiGetDIBitsInternal(
                                                         &rcDest,
                                                         &srcPoint);
 
+        SURFACE_ShareUnlockSurface(psurfDest);
+
                if(!ret)
                        ScanLines = 0;
                else
@@ -994,7 +1001,7 @@ NtGdiGetDIBitsInternal(
 done:
 
        if(pDC) DC_UnlockDc(pDC);
-       if(psurf) SURFACE_UnlockSurface(psurf);
+       if(psurf) SURFACE_ShareUnlockSurface(psurf);
        if(pbmci) DIB_FreeConvertedBitmapInfo(Info, (BITMAPINFO*)pbmci);
 
        return ScanLines;
@@ -1043,13 +1050,6 @@ NtGdiStretchDIBitsInternal(
         return 0;
     }
 
-    if (!(pdc = DC_LockDc(hDC)))
-    {
-        ExFreePoolWithTag(safeBits, TAG_DIB);
-        EngSetLastError(ERROR_INVALID_HANDLE);
-        return 0;
-    }
-
     _SEH2_TRY
     {
         ProbeForRead(BitsInfo, cjMaxInfo, 1);
@@ -1076,6 +1076,13 @@ NtGdiStretchDIBitsInternal(
 
     hBitmap = NtGdiGetDCObject(hDC, OBJ_BITMAP);
 
+    if (!(pdc = DC_LockDc(hDC)))
+    {
+        ExFreePoolWithTag(safeBits, TAG_DIB);
+        EngSetLastError(ERROR_INVALID_HANDLE);
+        return 0;
+    }
+
     if (XDest == 0 && YDest == 0 && XSrc == 0 && XSrc == 0 &&
         DestWidth == SrcWidth && DestHeight == SrcHeight &&
         compr == BI_RGB &&
@@ -1091,21 +1098,24 @@ NtGdiStretchDIBitsInternal(
         {
             /* fast path */
             ret = IntSetDIBits(pdc, hBitmap, 0, height, safeBits, BitsInfo, Usage);
+            DC_UnlockDc(pdc);
             goto cleanup;
         }
     }
 
     /* slow path - need to use StretchBlt */
 
-    hdcMem = NtGdiCreateCompatibleDC(hDC);
     hBitmap = DIB_CreateDIBSection(pdc, BitsInfo, Usage, &pvBits, NULL, 0, 0);
+    DC_UnlockDc(pdc);
+
     if(!hBitmap)
     {
         DPRINT1("Error, failed to create a DIB section\n");
-        NtGdiDeleteObjectApp(hdcMem);
         goto cleanup;
     }
 
+    hdcMem = NtGdiCreateCompatibleDC(hDC);
+
     RtlCopyMemory(pvBits, safeBits, cjMaxBits);
     hOldBitmap = NtGdiSelectBitmap(hdcMem, hBitmap);
 
@@ -1123,7 +1133,6 @@ NtGdiStretchDIBitsInternal(
 
 cleanup:
     ExFreePoolWithTag(safeBits, TAG_DIB);
-    DC_UnlockDc(pdc);
     return ret;
 }
 
@@ -1750,29 +1759,32 @@ BuildDIBPalette(CONST BITMAPINFO *bmi)
     else if (bmi->bmiHeader.biCompression == BI_BITFIELDS)
     {
         paletteType = PAL_BITFIELDS;
-        RedMask = pdwColors[0];
-        GreenMask = pdwColors[1];
-        BlueMask = pdwColors[2];
+        if (bmi->bmiHeader.biSize >= sizeof(BITMAPV4HEADER))
+        {
+            PBITMAPV4HEADER pV4Header = (PBITMAPV4HEADER)&bmi->bmiHeader;
+            RedMask = pV4Header->bV4RedMask;
+            GreenMask = pV4Header->bV4GreenMask;
+            BlueMask = pV4Header->bV4BlueMask;
+        }
+        else
+        {
+            RedMask = pdwColors[0];
+            GreenMask = pdwColors[1];
+            BlueMask = pdwColors[2];
+        }
     }
     else
     {
         paletteType = PAL_BITFIELDS;
         switch (bits)
         {
-            case 15:
+            case 16:
                 paletteType |= PAL_RGB16_555;
                 RedMask = 0x7C00;
                 GreenMask = 0x03E0;
                 BlueMask = 0x001F;
                 break;
 
-            case 16:
-                paletteType |= PAL_RGB16_565;
-                RedMask = 0xF800;
-                GreenMask = 0x07E0;
-                BlueMask = 0x001F;
-                break;
-
             case 24:
             case 32:
                 paletteType |= PAL_BGR;