* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id: color.c,v 1.42 2004/05/22 22:07:42 navaraf Exp $ */
+/* $Id$ */
#include <w32k.h>
// FIXME: Use PXLATEOBJ logicalToSystem instead of int *mapping
#endif
//static HPALETTE hLastRealizedPalette = 0; // UnrealizeObject() needs it
+
+static UINT SystemPaletteUse = SYSPAL_NOSTATIC; /* the program need save the palate and restore it */
+
const PALETTEENTRY COLOR_sysPalTemplate[NB_RESERVED_COLORS] =
{
// first 10 entries in the system palette
{ 0x00, 0x80, 0x80, PC_SYS_USED },
{ 0xc0, 0xc0, 0xc0, PC_SYS_USED },
{ 0xc0, 0xdc, 0xc0, PC_SYS_USED },
- { 0xa6, 0xca, 0xf0, PC_SYS_USED },
+ { 0xd4, 0xd0, 0xc7, PC_SYS_USED },
// ... c_min/2 dynamic colorcells
// ... gap (for sparse palettes)
// ... c_min/2 dynamic colorcells
{ 0xff, 0xfb, 0xf0, PC_SYS_USED },
- { 0xa0, 0xa0, 0xa4, PC_SYS_USED },
+ { 0x3a, 0x6e, 0xa5, PC_SYS_USED },
{ 0x80, 0x80, 0x80, PC_SYS_USED },
{ 0xff, 0x00, 0x00, PC_SYS_USED },
{ 0x00, 0xff, 0x00, PC_SYS_USED },
return (const PALETTEENTRY*)&COLOR_sysPalTemplate;
}
-BOOL STDCALL NtGdiAnimatePalette(HPALETTE hPalette, UINT uStartIndex,
- UINT uEntries, CONST PPALETTEENTRY ppe)
+BOOL STDCALL NtGdiAnimatePalette(HPALETTE hPal, UINT StartIndex,
+ UINT NumEntries, CONST PPALETTEENTRY PaletteColors)
{
- UNIMPLEMENTED;
- SetLastWin32Error(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ if( hPal != NtGdiGetStockObject(DEFAULT_PALETTE) )
+ {
+ PPALGDI palPtr;
+ UINT pal_entries;
+ HDC hDC;
+ PDC dc;
+ HWND hHwd;
+ const PALETTEENTRY *pptr = PaletteColors;
+
+ palPtr = (PPALGDI)PALETTE_LockPalette(hPal);
+ if (!palPtr) return FALSE;
+
+ pal_entries = palPtr->NumColors;
+ if (StartIndex >= pal_entries)
+ {
+ PALETTE_UnlockPalette(hPal);
+ return FALSE;
+ }
+ 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->IndexedColors[StartIndex].peFlags & PC_RESERVED) {
+ memcpy( &palPtr->IndexedColors[StartIndex], pptr,
+ sizeof(PALETTEENTRY) );
+ PALETTE_ValidateFlags(&palPtr->IndexedColors[StartIndex], 1);
+ }
+ }
+
+ PALETTE_UnlockPalette(hPal);
+
+ /* Immediately apply the new palette if current window uses it */
+ hHwd = NtUserGetDesktopWindow();
+ hDC = (HDC)NtUserGetWindowDC(hHwd);
+ dc = DC_LockDc(hDC);
+ if (NULL != dc)
+ {
+ if (dc->w.hPalette == hPal)
+ {
+ DC_UnlockDc(hDC);
+ NtGdiRealizePalette(hDC);
+ }
+ else
+ DC_UnlockDc(hDC);
+ }
+ NtUserReleaseDC(hHwd,hDC);
+ }
+ return TRUE;
}
HPALETTE STDCALL NtGdiCreateHalftonePalette(HDC hDC)
0, 0, 0);
PalGDI = (PPALGDI) PALETTE_LockPalette(NewPalette);
+ /* FIXME - Handle PalGDI == NULL!!!! */
PALETTE_ValidateFlags(PalGDI->IndexedColors, PalGDI->NumColors);
PalGDI->logicalToSystem = NULL;
BOOL STDCALL NtGdiGetColorAdjustment(HDC hDC,
LPCOLORADJUSTMENT ca)
{
- UNIMPLEMENTED;
+ UNIMPLEMENTED;
+ return FALSE;
}
unsigned short GetNumberOfBits(unsigned int dwMask)
if (NULL != palGDI)
{
/* Return closest match for the given RGB color */
- index = COLOR_PaletteLookupPixel((LPPALETTEENTRY)palGDI->IndexedColors, palGDI->NumColors, NULL, Color, FALSE);
+ index = COLOR_PaletteLookupPixel(palGDI->IndexedColors, palGDI->NumColors, NULL, Color, FALSE);
PALETTE_UnlockPalette(hpal);
}
PALETTE_UnlockPalette(hpal);
return 0;
}
- memcpy(pe, &palGDI->IndexedColors[StartIndex], Entries * sizeof(PALETTEENTRY));
+ memcpy(pe, palGDI->IndexedColors + StartIndex, Entries * sizeof(PALETTEENTRY));
for (numEntries = 0; numEntries < Entries; numEntries++)
{
if (pe[numEntries].peFlags & 0xF0)
}
UINT STDCALL NtGdiGetSystemPaletteUse(HDC hDC)
-{
- UNIMPLEMENTED;
- return 0;
+{
+ return SystemPaletteUse;
}
/*!
* of bugd in it (calling SetPalette for high/true-color modes,
* using DEFAULT_PALETTE instead of the device palette, ...).
*/
-#if 1
- DPRINT1("NtGdiRealizePalette is unimplemented\n");
- return 0;
-#else
+
PALOBJ *palPtr, *sysPtr;
PPALGDI palGDI, sysGDI;
int realized = 0;
PDC dc;
HPALETTE systemPalette;
- PSURFGDI SurfGDI;
BOOLEAN success;
USHORT sysMode, palMode;
if (!dc)
return 0;
- SurfGDI = (PSURFGDI)AccessInternalObject((ULONG)dc->Surface);
systemPalette = NtGdiGetStockObject((INT)DEFAULT_PALETTE);
palGDI = PALETTE_LockPalette(dc->w.hPalette);
palPtr = (PALOBJ*) palGDI;
+ /* FIXME - Handle palGDI == NULL!!!! */
// Step 1: Create mapping of system palette\DC palette
#ifndef NO_MAPPING
sysGDI = PALETTE_LockPalette(systemPalette);
sysPtr = (PALOBJ*) sysGDI;
+ /* FIXME - Handle sysGDI == NULL!!!!! */
// Step 2:
// The RealizePalette function modifies the palette for the device associated with the specified device context. If the
// Memory managed DC
DbgPrint("win32k: realizepalette unimplemented step 2 for DC_MEMORY");
} else {
- if(SurfGDI->SetPalette)
+ if( ((GDIDEVICE *)dc->GDIDevice)->DriverFunctions.SetPalette)
{
- IntLockGDIDriver(SurfGDI);
- ASSERT(sysGDI->NumColors <= 256);
- success = SurfGDI->SetPalette(dc->PDev, sysPtr, 0, 0, sysGDI->NumColors);
- IntUnLockGDIDriver(SurfGDI);
+ ASSERT(palGDI->NumColors <= 256);
+ success = ((GDIDEVICE *)dc->GDIDevice)->DriverFunctions.SetPalette(
+ dc->PDev, palPtr, 0, 0, palGDI->NumColors);
}
}
DC_UnlockDc(hDC);
return realized;
-#endif
}
BOOL STDCALL NtGdiResizePalette(HPALETTE hpal,
return TRUE; */
UNIMPLEMENTED;
+ return FALSE;
}
/*!
BOOL ForceBackground)
{
PDC dc;
- HPALETTE oldPal;
+ HPALETTE oldPal = NULL;
PPALGDI PalGDI;
// FIXME: mark the palette as a [fore\back]ground pal
PalGDI = PALETTE_LockPalette(hpal);
if (NULL != PalGDI)
{
- PALETTE_UnlockPalette(hpal);
- oldPal = dc->w.hPalette;
- dc->w.hPalette = hpal;
+ /* Is this a valid palette for this depth? */
+ if ((dc->w.bitsPerPixel <= 8 && PAL_INDEXED == PalGDI->Mode)
+ || (8 < dc->w.bitsPerPixel && PAL_INDEXED != PalGDI->Mode))
+ {
+ PALETTE_UnlockPalette(hpal);
+ oldPal = dc->w.hPalette;
+ dc->w.hPalette = hpal;
+ }
+ else
+ {
+ PALETTE_UnlockPalette(hpal);
+ oldPal = NULL;
+ }
}
else
{
BOOL STDCALL NtGdiSetColorAdjustment(HDC hDC,
CONST LPCOLORADJUSTMENT ca)
{
- UNIMPLEMENTED;
+ UNIMPLEMENTED;
+ return FALSE;
}
UINT STDCALL NtGdiSetPaletteEntries(HPALETTE hpal,
{
Entries = numEntries - Start;
}
- memcpy(&palGDI->IndexedColors[Start], pe, Entries * sizeof(PALETTEENTRY));
+ memcpy(palGDI->IndexedColors + Start, pe, Entries * sizeof(PALETTEENTRY));
PALETTE_ValidateFlags(palGDI->IndexedColors, palGDI->NumColors);
ExFreePool(palGDI->logicalToSystem);
palGDI->logicalToSystem = NULL;
UINT STDCALL
NtGdiSetSystemPaletteUse(HDC hDC, UINT Usage)
{
- UNIMPLEMENTED;
+ UINT old = SystemPaletteUse;
+
+ /* Device doesn't support colour palettes */
+ if (!(NtGdiGetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)) {
+ return SYSPAL_ERROR;
+ }
+
+ switch (Usage)
+ {
+ case SYSPAL_NOSTATIC:
+ case SYSPAL_NOSTATIC256:
+ case SYSPAL_STATIC:
+ SystemPaletteUse = Usage;
+ break;
+
+ default:
+ old=SYSPAL_ERROR;
+ break;
+ }
+
+ return old;
}
BOOL STDCALL
NtGdiUnrealizeObject(HGDIOBJ hgdiobj)
{
UNIMPLEMENTED;
+ return FALSE;
}
BOOL STDCALL
{
HWND hWnd;
- hWnd = IntWindowFromDC(hDC);
+ hWnd = (HWND)NtUserCallOneParam((DWORD)hDC, ONEPARAM_ROUTINE_WINDOWFROMDC);
if (hWnd == NULL)
{
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
for( i = 0; i < size && diff ; i++ )
{
+#if 0
if(!(palPalEntry[i].peFlags & PC_SYS_USED) || (skipReserved && palPalEntry[i].peFlags & PC_SYS_RESERVED))
continue;
+#endif
- r = palPalEntry[i].peRed - GetRValue(col);
- g = palPalEntry[i].peGreen - GetGValue(col);
- b = palPalEntry[i].peBlue - GetBValue(col);
+ r = abs((SHORT)palPalEntry[i].peRed - GetRValue(col));
+ g = abs((SHORT)palPalEntry[i].peGreen - GetGValue(col));
+ b = abs((SHORT)palPalEntry[i].peBlue - GetBValue(col));
r = r*r + g*g + b*b;
COLORREF STDCALL COLOR_LookupNearestColor( PALETTEENTRY* palPalEntry, int size, COLORREF color )
{
-#if 1
INT index;
index = COLOR_PaletteLookupPixel(palPalEntry, size, NULL, color, FALSE);
palPalEntry[index].peRed,
palPalEntry[index].peGreen,
palPalEntry[index].peBlue);
-#else
- unsigned char spec_type = color >> 24;
- int i;
- PALETTEENTRY *COLOR_sysPal = (PALETTEENTRY*)ReturnSystemPalette();
-
- // we need logical palette for PALETTERGB and PALETTEINDEX colorrefs
-
- if( spec_type == 2 ) /* PALETTERGB */
- color = *(COLORREF*)(palPalEntry + COLOR_PaletteLookupPixel(palPalEntry,size,NULL,color,FALSE));
-
- else if( spec_type == 1 ) /* PALETTEINDEX */
- {
- if( (i = color & 0x0000ffff) >= size )
- {
- DbgPrint("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color, i);
- color = *(COLORREF*)palPalEntry;
- }
- else color = *(COLORREF*)(palPalEntry + i);
- }
-
- color &= 0x00ffffff;
- return (0x00ffffff & *(COLORREF*)(COLOR_sysPal + COLOR_PaletteLookupPixel(COLOR_sysPal, 256, NULL, color, FALSE)));
-#endif
}
int STDCALL COLOR_PaletteLookupExactIndex( PALETTEENTRY* palPalEntry, int size,