Don't use SetPaletteEntries in AnimatePalette

Glenn Wurster gwurster at scs.carleton.ca
Thu Oct 14 23:37:18 CDT 2004


Authors:
  Doug Paul <doug at elemental.ath.cx>,
  Glenn Wurster <gwurster at scs.carleton.ca>

Description:
* SetPaletteEntries unrealized the palette at the end so the check at
the end of AnimatePalette would always fail, causing the new palette
to not be realized and actually be unrealized by a call to
AnimatePalette.
* AnimatePalette did not check peFlags to ensure that it was set to
PC_RESERVED.

Changelog:
 * Don't unrealize the palette by calling SetPaletteEntries
 * check peFlags for PC_RESERVED

Index: dlls/gdi/palette.c
===================================================================
RCS file: /home/wine/wine/dlls/gdi/palette.c,v
retrieving revision 1.1
diff -u -u -r1.1 palette.c
--- dlls/gdi/palette.c	21 Jul 2004 04:07:28 -0000	1.1
+++ dlls/gdi/palette.c	29 Sep 2004 04:46:45 -0000
@@ -446,7 +446,41 @@
 
     if( hPal != GetStockObject(DEFAULT_PALETTE) )
     {
-        if (!SetPaletteEntries( hPal, StartIndex, NumEntries, PaletteColors )) return FALSE;
+        PALETTEOBJ * palPtr;
+        UINT pal_entries;
+        const PALETTEENTRY *pptr = PaletteColors;
+
+        palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
+        if (!palPtr) return 0;
+
+        pal_entries = palPtr->logpalette.palNumEntries;
+        if (StartIndex >= pal_entries)
+        {
+          GDI_ReleaseObj( hPal );
+          return 0;
+        }
+        if (StartIndex+NumEntries > pal_entries) NumEntries = pal_entries - StartIndex;
+        
+        for (NumEntries += StartIndex; StartIndex < NumEntries; StartIndex++, pptr++) {
+          /* According to MSDN, only animate PC_RESERVED colours */
+          if (palPtr->logpalette.palPalEntry[StartIndex].peFlags & PC_RESERVED) {
+            TRACE("Animating colour (%d,%d,%d) to (%d,%d,%d)\n",
+              palPtr->logpalette.palPalEntry[StartIndex].peRed,
+              palPtr->logpalette.palPalEntry[StartIndex].peGreen,
+              palPtr->logpalette.palPalEntry[StartIndex].peBlue,
+              pptr->peRed, pptr->peGreen, pptr->peBlue);
+            memcpy( &palPtr->logpalette.palPalEntry[StartIndex], pptr,
+                    sizeof(PALETTEENTRY) );
+            PALETTE_ValidateFlags(&palPtr->logpalette.palPalEntry[StartIndex], 1);
+          } else {
+            TRACE("Not animating entry %d -- not PC_RESERVED\n", StartIndex);
+          }
+        }
+        
+        GDI_ReleaseObj( hPal );
+        
+        TRACE("pLastRealizedDC %p -- pLastRealizedDC->pRealizePalette %p\n",
+          pLastRealizedDC, pLastRealizedDC ? pLastRealizedDC->pRealizePalette : 0);
 
         if (pLastRealizedDC && pLastRealizedDC->pRealizePalette)
             pLastRealizedDC->pRealizePalette( NULL, hPal, hPal == hPrimaryPalette );
@@ -669,6 +703,7 @@
     }
     if (hLastRealizedPalette == handle)
     {
+        TRACE("unrealizing palette %p\n", handle);
         hLastRealizedPalette = 0;
         pLastRealizedDC = NULL;
     }
@@ -686,6 +721,7 @@
     HeapFree( GetProcessHeap(), 0, palette->mapping );
     if (hLastRealizedPalette == handle)
     {
+        TRACE("unrealizing palette %p\n", handle);
         hLastRealizedPalette = 0;
         pLastRealizedDC = NULL;
     }



More information about the wine-patches mailing list