4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1996 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
23 * Information in the "Undocumented Windows" is incorrect.
32 #include "wine/winuser16.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(palette);
41 PALETTE_DRIVER *PALETTE_Driver = NULL;
43 /* Pointers to USER implementation of SelectPalette/RealizePalette */
44 /* they will be patched by USER on startup */
45 FARPROC pfnSelectPalette = NULL;
46 FARPROC pfnRealizePalette = NULL;
48 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
50 static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
51 static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
54 /***********************************************************************
57 * Create the system palette.
59 HPALETTE16 PALETTE_Init(void)
65 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
67 /* create default palette (20 system colors) */
69 palPtr = HeapAlloc( GetProcessHeap(), 0,
70 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
71 if (!palPtr) return FALSE;
73 palPtr->palVersion = 0x300;
74 palPtr->palNumEntries = NB_RESERVED_COLORS;
75 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
77 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
78 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
79 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
80 palPtr->palPalEntry[i].peFlags = 0;
82 hpalette = CreatePalette16( palPtr );
83 HeapFree( GetProcessHeap(), 0, palPtr );
85 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
88 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
89 ERR("Can not create palette mapping -- out of memory!\n");
90 GDI_ReleaseObj( hpalette );
95 /***********************************************************************
96 * PALETTE_ValidateFlags
98 void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
101 for( ; i<size ; i++ )
102 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
106 /***********************************************************************
107 * CreatePalette (GDI.360)
109 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
111 return CreatePalette( palette );
115 /***********************************************************************
116 * CreatePalette [GDI32.@] Creates a logical color palette
119 * Success: Handle to logical palette
122 HPALETTE WINAPI CreatePalette(
123 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
125 PALETTEOBJ * palettePtr;
129 if (!palette) return 0;
130 TRACE("entries=%i\n", palette->palNumEntries);
132 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
134 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
135 PALETTE_MAGIC, &hpalette ))) return 0;
136 memcpy( &palettePtr->logpalette, palette, size );
137 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
138 palettePtr->logpalette.palNumEntries);
139 palettePtr->mapping = NULL;
140 GDI_ReleaseObj( hpalette );
142 TRACE(" returning %04x\n", hpalette);
147 /***********************************************************************
148 * CreateHalftonePalette [GDI.529] Creates a halftone palette
151 * Success: Handle to logical halftone palette
154 HPALETTE16 WINAPI CreateHalftonePalette16(
155 HDC16 hdc) /* [in] Handle to device context */
157 return CreateHalftonePalette(hdc);
161 /***********************************************************************
162 * CreateHalftonePalette [GDI32.@] Creates a halftone palette
165 * Success: Handle to logical halftone palette
168 * FIXME: This simply creates the halftone palette dirived from runing
169 * tests on an windows NT machine. this is assuming a color depth
170 * of greater that 256 color. On a 256 color device the halftone
171 * palette will be differnt and this funtion will be incorrect
173 HPALETTE WINAPI CreateHalftonePalette(
174 HDC hdc) /* [in] Handle to device context */
179 WORD NumberOfEntries;
180 PALETTEENTRY aEntries[256];
183 Palette.Version = 0x300;
184 Palette.NumberOfEntries = 256;
185 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
187 Palette.NumberOfEntries = 20;
189 for (i = 0; i < Palette.NumberOfEntries; i++)
191 Palette.aEntries[i].peRed=0xff;
192 Palette.aEntries[i].peGreen=0xff;
193 Palette.aEntries[i].peBlue=0xff;
194 Palette.aEntries[i].peFlags=0x00;
197 Palette.aEntries[0].peRed=0x00;
198 Palette.aEntries[0].peBlue=0x00;
199 Palette.aEntries[0].peGreen=0x00;
202 for (i=1; i <= 6; i++)
204 Palette.aEntries[i].peRed=(i%2)?0x80:0;
205 Palette.aEntries[i].peGreen=(i==2)?0x80:(i==3)?0x80:(i==6)?0x80:0;
206 Palette.aEntries[i].peBlue=(i>3)?0x80:0;
209 for (i=7; i <= 12; i++)
214 Palette.aEntries[i].peRed=0xc0;
215 Palette.aEntries[i].peBlue=0xc0;
216 Palette.aEntries[i].peGreen=0xc0;
219 Palette.aEntries[i].peRed=0xc0;
220 Palette.aEntries[i].peGreen=0xdc;
221 Palette.aEntries[i].peBlue=0xc0;
224 Palette.aEntries[i].peRed=0xa6;
225 Palette.aEntries[i].peGreen=0xca;
226 Palette.aEntries[i].peBlue=0xf0;
229 Palette.aEntries[i].peRed=0xff;
230 Palette.aEntries[i].peGreen=0xfb;
231 Palette.aEntries[i].peBlue=0xf0;
234 Palette.aEntries[i].peRed=0xa0;
235 Palette.aEntries[i].peGreen=0xa0;
236 Palette.aEntries[i].peBlue=0xa4;
239 Palette.aEntries[i].peRed=0x80;
240 Palette.aEntries[i].peGreen=0x80;
241 Palette.aEntries[i].peBlue=0x80;
245 for (i=13; i <= 18; i++)
247 Palette.aEntries[i].peRed=(i%2)?0xff:0;
248 Palette.aEntries[i].peGreen=(i==14)?0xff:(i==15)?0xff:(i==18)?0xff:0;
249 Palette.aEntries[i].peBlue=(i>15)?0xff:0x00;
252 return CreatePalette((LOGPALETTE *)&Palette);
256 /***********************************************************************
257 * GetPaletteEntries (GDI.363)
259 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
260 UINT16 count, LPPALETTEENTRY entries )
262 return GetPaletteEntries( hpalette, start, count, entries );
266 /***********************************************************************
267 * GetPaletteEntries [GDI32.@] Retrieves palette entries
270 * Success: Number of entries from logical palette
273 UINT WINAPI GetPaletteEntries(
274 HPALETTE hpalette, /* [in] Handle of logical palette */
275 UINT start, /* [in] First entry to receive */
276 UINT count, /* [in] Number of entries to receive */
277 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
282 TRACE("hpal = %04x, count=%i\n", hpalette, count );
284 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
285 if (!palPtr) return 0;
287 /* NOTE: not documented but test show this to be the case */
290 int rc = palPtr->logpalette.palNumEntries;
291 GDI_ReleaseObj( hpalette );
295 numEntries = palPtr->logpalette.palNumEntries;
296 if (start+count > numEntries) count = numEntries - start;
299 if (start >= numEntries)
301 GDI_ReleaseObj( hpalette );
304 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
305 count * sizeof(PALETTEENTRY) );
306 for( numEntries = 0; numEntries < count ; numEntries++ )
307 if (entries[numEntries].peFlags & 0xF0)
308 entries[numEntries].peFlags = 0;
311 GDI_ReleaseObj( hpalette );
316 /***********************************************************************
317 * SetPaletteEntries (GDI.364)
319 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
320 UINT16 count, LPPALETTEENTRY entries )
322 return SetPaletteEntries( hpalette, start, count, entries );
326 /***********************************************************************
327 * SetPaletteEntries [GDI32.@] Sets color values for range in palette
330 * Success: Number of entries that were set
333 UINT WINAPI SetPaletteEntries(
334 HPALETTE hpalette, /* [in] Handle of logical palette */
335 UINT start, /* [in] Index of first entry to set */
336 UINT count, /* [in] Number of entries to set */
337 LPPALETTEENTRY entries) /* [in] Address of array of structures */
342 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
344 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
345 if (!palPtr) return 0;
347 numEntries = palPtr->logpalette.palNumEntries;
348 if (start >= numEntries)
350 GDI_ReleaseObj( hpalette );
353 if (start+count > numEntries) count = numEntries - start;
354 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
355 count * sizeof(PALETTEENTRY) );
356 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
357 palPtr->logpalette.palNumEntries);
358 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
359 palPtr->mapping = NULL;
360 GDI_ReleaseObj( hpalette );
365 /***********************************************************************
366 * ResizePalette (GDI.368)
368 BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
370 return ResizePalette( hPal, cEntries );
374 /***********************************************************************
375 * ResizePalette [GDI32.@] Resizes logical palette
381 BOOL WINAPI ResizePalette(
382 HPALETTE hPal, /* [in] Handle of logical palette */
383 UINT cEntries) /* [in] Number of entries in logical palette */
385 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
386 UINT cPrevEnt, prevVer;
387 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
390 TRACE("hpal = %04x, prev = %i, new = %i\n",
391 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
393 if( !palPtr ) return FALSE;
394 cPrevEnt = palPtr->logpalette.palNumEntries;
395 prevVer = palPtr->logpalette.palVersion;
396 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
397 sizeof(int*) + sizeof(GDIOBJHDR);
398 size += sizeof(int*) + sizeof(GDIOBJHDR);
399 mapping = palPtr->mapping;
401 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
405 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
406 mapping, cEntries * sizeof(int) );
409 ERR("Can not resize mapping -- out of memory!\n");
410 GDI_ReleaseObj( hPal );
413 palPtr->mapping = newMap;
416 if( cEntries > cPrevEnt )
419 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
420 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
421 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
422 cEntries - cPrevEnt );
424 palPtr->logpalette.palNumEntries = cEntries;
425 palPtr->logpalette.palVersion = prevVer;
426 GDI_ReleaseObj( hPal );
431 /***********************************************************************
432 * AnimatePalette (GDI.367)
434 void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
435 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
437 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
441 /***********************************************************************
442 * AnimatePalette [GDI32.@] Replaces entries in logical palette
449 * Should use existing mapping when animating a primary palette
451 BOOL WINAPI AnimatePalette(
452 HPALETTE hPal, /* [in] Handle to logical palette */
453 UINT StartIndex, /* [in] First entry in palette */
454 UINT NumEntries, /* [in] Count of entries in palette */
455 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
457 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
459 if( hPal != GetStockObject(DEFAULT_PALETTE) )
461 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
462 if (!palPtr) return FALSE;
464 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
467 for( u = 0; u < NumEntries; u++ )
468 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
470 pSetMapping(palPtr, StartIndex, NumEntries,
471 hPal != hPrimaryPalette );
472 GDI_ReleaseObj( hPal );
475 GDI_ReleaseObj( hPal );
481 /***********************************************************************
482 * SetSystemPaletteUse (GDI.373)
484 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
486 return SetSystemPaletteUse( hdc, use );
490 /***********************************************************************
491 * SetSystemPaletteUse [GDI32.@]
494 * Success: Previous system palette
495 * Failure: SYSPAL_ERROR
497 UINT WINAPI SetSystemPaletteUse(
498 HDC hdc, /* [in] Handle of device context */
499 UINT use) /* [in] Palette-usage flag */
501 UINT old = SystemPaletteUse;
502 FIXME("(%04x,%04x): stub\n", hdc, use );
503 SystemPaletteUse = use;
508 /***********************************************************************
509 * GetSystemPaletteUse (GDI.374)
511 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
513 return SystemPaletteUse;
517 /***********************************************************************
518 * GetSystemPaletteUse [GDI32.@] Gets state of system palette
521 * Current state of system palette
523 UINT WINAPI GetSystemPaletteUse(
524 HDC hdc) /* [in] Handle of device context */
526 return SystemPaletteUse;
530 /***********************************************************************
531 * GetSystemPaletteEntries (GDI.375)
533 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
534 LPPALETTEENTRY entries )
536 return GetSystemPaletteEntries( hdc, start, count, entries );
540 /***********************************************************************
541 * GetSystemPaletteEntries [GDI32.@] Gets range of palette entries
544 * Success: Number of entries retrieved from palette
547 UINT WINAPI GetSystemPaletteEntries(
548 HDC hdc, /* [in] Handle of device context */
549 UINT start, /* [in] Index of first entry to be retrieved */
550 UINT count, /* [in] Number of entries to be retrieved */
551 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
554 INT sizePalette = GetDeviceCaps( hdc, SIZEPALETTE );
556 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
558 if (!entries) return sizePalette;
559 if (start >= sizePalette) return 0;
560 if (start+count >= sizePalette) count = sizePalette - start;
562 for (i = 0; i < count; i++)
564 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
566 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
567 start + i, *(COLORREF*)(entries + i) );
573 /***********************************************************************
574 * GetNearestPaletteIndex (GDI.370)
576 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
578 return GetNearestPaletteIndex( hpalette, color );
582 /***********************************************************************
583 * GetNearestPaletteIndex [GDI32.@] Gets palette index for color
586 * Should index be initialized to CLR_INVALID instead of 0?
589 * Success: Index of entry in logical palette
590 * Failure: CLR_INVALID
592 UINT WINAPI GetNearestPaletteIndex(
593 HPALETTE hpalette, /* [in] Handle of logical color palette */
594 COLORREF color) /* [in] Color to be matched */
596 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
601 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
602 palObj->logpalette.palNumEntries,
603 NULL, color, FALSE );
605 GDI_ReleaseObj( hpalette );
607 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
612 /***********************************************************************
613 * GetNearestColor (GDI.154)
615 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
617 return GetNearestColor( hdc, color );
621 /***********************************************************************
622 * GetNearestColor [GDI32.@] Gets a system color to match
625 * Success: Color from system palette that corresponds to given color
626 * Failure: CLR_INVALID
628 COLORREF WINAPI GetNearestColor(
629 HDC hdc, /* [in] Handle of device context */
630 COLORREF color) /* [in] Color to be matched */
632 COLORREF nearest = CLR_INVALID;
636 if(!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)) {
639 if ( (dc = DC_GetDCPtr( hdc )) )
641 HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
642 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
644 GDI_ReleaseObj( hdc );
648 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
649 palObj->logpalette.palNumEntries, color );
650 GDI_ReleaseObj( hpal );
651 GDI_ReleaseObj( hdc );
654 TRACE("(%06lx): returning %06lx\n", color, nearest );
659 /***********************************************************************
662 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
664 if (count > sizeof(WORD)) count = sizeof(WORD);
665 memcpy( buffer, &palette->logpalette.palNumEntries, count );
670 /***********************************************************************
671 * PALETTE_UnrealizeObject
673 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
675 if (palette->mapping)
677 HeapFree( GetProcessHeap(), 0, palette->mapping );
678 palette->mapping = NULL;
680 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
685 /***********************************************************************
686 * PALETTE_DeleteObject
688 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
690 HeapFree( GetProcessHeap(), 0, palette->mapping );
691 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
692 return GDI_FreeObject( hpalette, palette );
696 /***********************************************************************
697 * GDISelectPalette (GDI.361)
699 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
704 TRACE("%04x %04x\n", hdc, hpal );
706 if (GetObjectType(hpal) != OBJ_PAL)
708 WARN("invalid selected palette %04x\n",hpal);
711 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
714 GDI_ReleaseObj( hdc );
715 if (!wBkg) hPrimaryPalette = hpal;
720 /***********************************************************************
721 * GDIRealizePalette (GDI.362)
723 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
727 DC* dc = DC_GetDCPtr( hdc );
731 TRACE("%04x...\n", hdc );
733 if(dc->hPalette != hLastRealizedPalette )
735 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) {
736 realized = RealizeDefaultPalette16( hdc );
737 GDI_ReleaseObj( hdc );
738 return (UINT16)realized;
742 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC );
745 GDI_ReleaseObj( hdc );
746 FIXME("invalid selected palette %04x\n",dc->hPalette);
750 realized = PALETTE_Driver->
751 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
752 (dc->hPalette != hPrimaryPalette) ||
753 (dc->hPalette == GetStockObject( DEFAULT_PALETTE )));
754 hLastRealizedPalette = dc->hPalette;
755 GDI_ReleaseObj( dc->hPalette );
757 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
758 hLastRealizedPalette);
759 GDI_ReleaseObj( hdc );
761 TRACE(" realized %i colors.\n", realized );
762 return (UINT16)realized;
766 /***********************************************************************
767 * RealizeDefaultPalette (GDI.365)
769 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
775 TRACE("%04x\n", hdc );
777 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
779 if (!(dc->flags & DC_MEMORY))
781 palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
784 /* lookup is needed to account for SetSystemPaletteUse() stuff */
785 ret = PALETTE_Driver->pUpdateMapping(palPtr);
786 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
789 GDI_ReleaseObj( hdc );
793 /***********************************************************************
794 * IsDCCurrentPalette (GDI.412)
796 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
798 DC *dc = DC_GetDCPtr( hDC );
801 BOOL bRet = dc->hPalette == hPrimaryPalette;
802 GDI_ReleaseObj( hDC );
809 /***********************************************************************
810 * SelectPalette [GDI32.@] Selects logical palette into DC
813 * Success: Previous logical palette
816 HPALETTE WINAPI SelectPalette(
817 HDC hDC, /* [in] Handle of device context */
818 HPALETTE hPal, /* [in] Handle of logical color palette */
819 BOOL bForceBackground) /* [in] Foreground/background mode */
821 return pfnSelectPalette( hDC, hPal, bForceBackground );
825 /***********************************************************************
826 * RealizePalette [GDI32.@] Maps palette entries to system palette
829 * Success: Number of entries in logical palette
832 UINT WINAPI RealizePalette(
833 HDC hDC) /* [in] Handle of device context */
835 return pfnRealizePalette( hDC );
839 typedef HWND (WINAPI *WindowFromDC_funcptr)( HDC );
840 typedef BOOL (WINAPI *RedrawWindow_funcptr)( HWND, const RECT *, HRGN, UINT );
842 /**********************************************************************
843 * UpdateColors [GDI32.@] Remaps current colors to logical palette
849 BOOL WINAPI UpdateColors(
850 HDC hDC) /* [in] Handle of device context */
853 int size = GetDeviceCaps( hDC, SIZEPALETTE );
857 mod = GetModuleHandleA("user32.dll");
860 WindowFromDC_funcptr pWindowFromDC = (WindowFromDC_funcptr)GetProcAddress(mod,"WindowFromDC");
863 HWND hWnd = pWindowFromDC( hDC );
865 /* Docs say that we have to remap current drawable pixel by pixel
866 * but it would take forever given the speed of XGet/PutPixel.
870 RedrawWindow_funcptr pRedrawWindow = GetProcAddress( mod, "RedrawWindow" );
871 if (pRedrawWindow) pRedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
879 /**********************************************************************
880 * UpdateColors (GDI.366)
882 INT16 WINAPI UpdateColors16( HDC16 hDC )
889 /*********************************************************************
890 * SetMagicColors (GDI.606)
892 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
894 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
898 /**********************************************************************
899 * GetICMProfileA [GDI32.@]
901 * Returns the filename of the specified device context's color
902 * management profile, even if color management is not enabled
906 * TRUE if name copied succesfully OR lpszFilename is NULL
907 * FALSE if the buffer length pointed to by lpcbName is too small
910 * The buffer length pointed to by lpcbName is ALWAYS updated to
911 * the length required regardless of other actions this function
915 * How does Windows assign these? Some registry key?
918 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
920 /*********************************************************************/
922 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
926 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
928 callerLen = *lpcbName;
930 /* all 3 behaviors require the required buffer size to be set */
931 *lpcbName = strlen(WINEICM);
933 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
934 if ((DWORD)lpszFilename == (DWORD)0x00000000)
937 /* behavior 2: if buffer size too small, return size of string and error */
938 if (callerLen < strlen(WINEICM))
940 SetLastError(ERROR_INSUFFICIENT_BUFFER);
944 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
945 strcpy(lpszFilename, WINEICM);