Author: gschneider
Date: Sun Dec 27 14:02:19 2009
New Revision: 44768
URL: 
http://svn.reactos.org/svn/reactos?rev=44768&view=rev
Log:
[win32k]
- Create DIB section palettes with the number of colors mapped from the logical palette
- Validate logical palette access, set to black for invalid indices
- gdi32:palette test now succeeds
Modified:
    trunk/reactos/subsystems/win32/win32k/objects/dibobj.c
Modified: trunk/reactos/subsystems/win32/win32k/objects/dibobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1] Sun Dec 27
14:02:19 2009
@@ -1358,6 +1358,7 @@
     RGBQUAD *lpRGB;
     HANDLE hSecure;
     DWORD dsBitfields[3] = {0};
+    ULONG ColorCount;
     DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
            bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
@@ -1439,9 +1440,18 @@
     hSecure = (HANDLE)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!!
     if (usage == DIB_PAL_COLORS)
+    {
         lpRGB = DIB_MapPaletteColors(dc, bmi);
+    }
     else
+    {
         lpRGB = bmi->bmiColors;
+    }
+    ColorCount = bi->biClrUsed;
+    if (ColorCount == 0)
+    {
+        ColorCount = 1 << bi->biBitCount;
+    }
     /* Set dsBitfields values */
     if (usage == DIB_PAL_COLORS || bi->biBitCount <= 8)
@@ -1528,12 +1538,16 @@
     bmp->biClrImportant = bi->biClrImportant;
     if (bi->biClrUsed != 0)
-        bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(bi->biClrUsed, lpRGB);
+    {
+        bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(ColorCount, lpRGB);
+    }
     else
+    {
         bmp->hDIBPalette = PALETTE_AllocPalette(PAL_BITFIELDS, 0, NULL,
                                                 dsBitfields[0],
                                                 dsBitfields[1],
                                                 dsBitfields[2]);
+    }
     // Clean up in case of errors
     if (!res || !bmp || !bm.bmBits)
@@ -1671,9 +1685,18 @@
     for (i = 0; i < nNumColors; i++)
     {
-        lpRGB[i].rgbRed = palGDI->IndexedColors[*lpIndex].peRed;
-        lpRGB[i].rgbGreen = palGDI->IndexedColors[*lpIndex].peGreen;
-        lpRGB[i].rgbBlue = palGDI->IndexedColors[*lpIndex].peBlue;
+        if (*lpIndex < palGDI->NumColors)
+        {
+            lpRGB[i].rgbRed = palGDI->IndexedColors[*lpIndex].peRed;
+            lpRGB[i].rgbGreen = palGDI->IndexedColors[*lpIndex].peGreen;
+            lpRGB[i].rgbBlue = palGDI->IndexedColors[*lpIndex].peBlue;
+        }
+        else
+        {
+            lpRGB[i].rgbRed = 0;
+            lpRGB[i].rgbGreen = 0;
+            lpRGB[i].rgbBlue = 0;
+        }
         lpRGB[i].rgbReserved = 0;
         lpIndex++;
     }