It's possible to select an (indexed) palette into a bitfield (e.g. 16 bit
deep) DC. This palette will be used when calling CreateDIBSection with
DIB_PAL_COLORS usage. Fixes bug 1077.
Modified: trunk/reactos/include/win32k/dc.h
Modified: trunk/reactos/subsys/win32k/objects/color.c
Modified: trunk/reactos/subsys/win32k/objects/dc.c
Modified: trunk/reactos/subsys/win32k/objects/dib.c

Modified: trunk/reactos/include/win32k/dc.h
--- trunk/reactos/include/win32k/dc.h	2005-12-08 17:09:47 UTC (rev 19966)
+++ trunk/reactos/include/win32k/dc.h	2005-12-08 17:34:48 UTC (rev 19967)
@@ -100,6 +100,8 @@
   INT  saveLevel;
   BOOL IsIC;
 
+  HPALETTE PalIndexed;
+
   WIN_DC_INFO  w;
 } DC, *PDC;
 

Modified: trunk/reactos/subsys/win32k/objects/color.c
--- trunk/reactos/subsys/win32k/objects/color.c	2005-12-08 17:09:47 UTC (rev 19966)
+++ trunk/reactos/subsys/win32k/objects/color.c	2005-12-08 17:34:48 UTC (rev 19967)
@@ -509,6 +509,12 @@
               oldPal = dc->w.hPalette;
               dc->w.hPalette = hpal;
             }
+          else if (8 < dc->w.bitsPerPixel && PAL_INDEXED == PalGDI->Mode)
+            {
+              PALETTE_UnlockPalette(PalGDI);
+              oldPal = dc->PalIndexed;
+              dc->PalIndexed = hpal;
+            }
           else
             {
               PALETTE_UnlockPalette(PalGDI);

Modified: trunk/reactos/subsys/win32k/objects/dc.c
--- trunk/reactos/subsys/win32k/objects/dc.c	2005-12-08 17:09:47 UTC (rev 19966)
+++ trunk/reactos/subsys/win32k/objects/dc.c	2005-12-08 17:34:48 UTC (rev 19967)
@@ -222,6 +222,7 @@
   NewDC->w.hFirstBitmap = hBitmap;
   NewDC->GDIDevice      = OrigDC->GDIDevice;
 
+  NewDC->PalIndexed = OrigDC->PalIndexed;
   NewDC->w.hPalette = OrigDC->w.hPalette;
   NewDC->w.textColor = OrigDC->w.textColor;
   NewDC->w.textAlign = OrigDC->w.textAlign;
@@ -905,6 +906,7 @@
 
   if (! CreateAsIC)
   {
+    NewDC->PalIndexed = NtGdiGetStockObject(DEFAULT_PALETTE);
     NewDC->w.hPalette = NewDC->DevInfo->hpalDefault;
     NewDC->w.ROPmode = R2_COPYPEN;
 
@@ -1315,6 +1317,7 @@
 #if 0
   newdc->w.hDevice          = dc->w.hDevice;
 #endif
+  newdc->PalIndexed         = dc->PalIndexed;
   newdc->w.hPalette         = dc->w.hPalette;
   newdc->w.totalExtent      = dc->w.totalExtent;
   newdc->w.bitsPerPixel     = dc->w.bitsPerPixel;
@@ -1440,6 +1443,7 @@
 	dc->vportOrgY          = dcs->vportOrgY;
 	dc->vportExtX          = dcs->vportExtX;
 	dc->vportExtY          = dcs->vportExtY;
+        dc->PalIndexed         = dcs->PalIndexed;
 
 	if (!(dc->w.flags & DC_MEMORY))
 	{

Modified: trunk/reactos/subsys/win32k/objects/dib.c
--- trunk/reactos/subsys/win32k/objects/dib.c	2005-12-08 17:09:47 UTC (rev 19966)
+++ trunk/reactos/subsys/win32k/objects/dib.c	2005-12-08 17:34:48 UTC (rev 19967)
@@ -1108,7 +1108,11 @@
   if (palGDI->Mode != PAL_INDEXED)
     {
       PALETTE_UnlockPalette(palGDI);
-      return NULL;
+      palGDI = PALETTE_LockPalette(dc->PalIndexed);
+      if (palGDI->Mode != PAL_INDEXED)
+        {
+          return NULL;
+        }
     }
 
   nNumColors = 1 << lpbmi->bmiHeader.biBitCount;