More general approach to file descriptor types and flags.
[wine.git] / objects / palette.c
blobfa569970c2dd53eda4dc45d4a787029c4a122e65
1 /*
2 * GDI palette objects
4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1996 Alex Korobka
7 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
8 * Information in the "Undocumented Windows" is incorrect.
9 */
11 #include <stdlib.h>
12 #include <string.h>
14 #include "winbase.h"
15 #include "windef.h"
16 #include "wingdi.h"
17 #include "wine/winuser16.h"
18 #include "gdi.h"
19 #include "color.h"
20 #include "palette.h"
21 #include "debugtools.h"
22 #include "winerror.h"
24 DEFAULT_DEBUG_CHANNEL(palette);
26 PALETTE_DRIVER *PALETTE_Driver = NULL;
28 /* Pointers to USER implementation of SelectPalette/RealizePalette */
29 /* they will be patched by USER on startup */
30 FARPROC pfnSelectPalette = NULL;
31 FARPROC pfnRealizePalette = NULL;
33 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
35 static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
36 static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
39 /***********************************************************************
40 * PALETTE_Init
42 * Create the system palette.
44 HPALETTE16 PALETTE_Init(void)
46 int i;
47 HPALETTE16 hpalette;
48 LOGPALETTE * palPtr;
49 PALETTEOBJ* palObj;
50 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
52 /* create default palette (20 system colors) */
54 palPtr = HeapAlloc( GetProcessHeap(), 0,
55 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
56 if (!palPtr) return FALSE;
58 palPtr->palVersion = 0x300;
59 palPtr->palNumEntries = NB_RESERVED_COLORS;
60 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
62 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
63 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
64 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
65 palPtr->palPalEntry[i].peFlags = 0;
67 hpalette = CreatePalette16( palPtr );
68 HeapFree( GetProcessHeap(), 0, palPtr );
70 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
71 if (palObj)
73 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
74 ERR("Can not create palette mapping -- out of memory!\n");
75 GDI_ReleaseObj( hpalette );
77 return hpalette;
80 /***********************************************************************
81 * PALETTE_ValidateFlags
83 void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
85 int i = 0;
86 for( ; i<size ; i++ )
87 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
91 /***********************************************************************
92 * CreatePalette (GDI.360)
94 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
96 return CreatePalette( palette );
100 /***********************************************************************
101 * CreatePalette [GDI32.@] Creates a logical color palette
103 * RETURNS
104 * Success: Handle to logical palette
105 * Failure: NULL
107 HPALETTE WINAPI CreatePalette(
108 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
110 PALETTEOBJ * palettePtr;
111 HPALETTE hpalette;
112 int size;
114 if (!palette) return 0;
115 TRACE("entries=%i\n", palette->palNumEntries);
117 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
119 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
120 PALETTE_MAGIC, &hpalette ))) return 0;
121 memcpy( &palettePtr->logpalette, palette, size );
122 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
123 palettePtr->logpalette.palNumEntries);
124 palettePtr->mapping = NULL;
125 GDI_ReleaseObj( hpalette );
127 TRACE(" returning %04x\n", hpalette);
128 return hpalette;
132 /***********************************************************************
133 * CreateHalftonePalette [GDI.529] Creates a halftone palette
135 * RETURNS
136 * Success: Handle to logical halftone palette
137 * Failure: 0
139 HPALETTE16 WINAPI CreateHalftonePalette16(
140 HDC16 hdc) /* [in] Handle to device context */
142 return CreateHalftonePalette(hdc);
146 /***********************************************************************
147 * CreateHalftonePalette [GDI32.@] Creates a halftone palette
149 * RETURNS
150 * Success: Handle to logical halftone palette
151 * Failure: 0
153 * FIXME: not truly tested
155 HPALETTE WINAPI CreateHalftonePalette(
156 HDC hdc) /* [in] Handle to device context */
158 int i, r, g, b;
159 struct {
160 WORD Version;
161 WORD NumberOfEntries;
162 PALETTEENTRY aEntries[256];
163 } Palette;
165 Palette.Version = 0x300;
166 Palette.NumberOfEntries = 256;
167 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
169 for (r = 0; r < 6; r++) {
170 for (g = 0; g < 6; g++) {
171 for (b = 0; b < 6; b++) {
172 i = r + g*6 + b*36 + 10;
173 Palette.aEntries[i].peRed = r * 51;
174 Palette.aEntries[i].peGreen = g * 51;
175 Palette.aEntries[i].peBlue = b * 51;
180 for (i = 216; i < 246; i++) {
181 int v = (i - 216) * 8;
182 Palette.aEntries[i].peRed = v;
183 Palette.aEntries[i].peGreen = v;
184 Palette.aEntries[i].peBlue = v;
187 return CreatePalette((LOGPALETTE *)&Palette);
191 /***********************************************************************
192 * GetPaletteEntries (GDI.363)
194 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
195 UINT16 count, LPPALETTEENTRY entries )
197 return GetPaletteEntries( hpalette, start, count, entries );
201 /***********************************************************************
202 * GetPaletteEntries [GDI32.@] Retrieves palette entries
204 * RETURNS
205 * Success: Number of entries from logical palette
206 * Failure: 0
208 UINT WINAPI GetPaletteEntries(
209 HPALETTE hpalette, /* [in] Handle of logical palette */
210 UINT start, /* [in] First entry to receive */
211 UINT count, /* [in] Number of entries to receive */
212 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
214 PALETTEOBJ * palPtr;
215 UINT numEntries;
217 TRACE("hpal = %04x, count=%i\n", hpalette, count );
219 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
220 if (!palPtr) return 0;
222 numEntries = palPtr->logpalette.palNumEntries;
223 if (start+count > numEntries) count = numEntries - start;
224 if (entries)
226 if (start >= numEntries)
228 GDI_ReleaseObj( hpalette );
229 return 0;
231 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
232 count * sizeof(PALETTEENTRY) );
233 for( numEntries = 0; numEntries < count ; numEntries++ )
234 if (entries[numEntries].peFlags & 0xF0)
235 entries[numEntries].peFlags = 0;
238 GDI_ReleaseObj( hpalette );
239 return count;
243 /***********************************************************************
244 * SetPaletteEntries (GDI.364)
246 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
247 UINT16 count, LPPALETTEENTRY entries )
249 return SetPaletteEntries( hpalette, start, count, entries );
253 /***********************************************************************
254 * SetPaletteEntries [GDI32.@] Sets color values for range in palette
256 * RETURNS
257 * Success: Number of entries that were set
258 * Failure: 0
260 UINT WINAPI SetPaletteEntries(
261 HPALETTE hpalette, /* [in] Handle of logical palette */
262 UINT start, /* [in] Index of first entry to set */
263 UINT count, /* [in] Number of entries to set */
264 LPPALETTEENTRY entries) /* [in] Address of array of structures */
266 PALETTEOBJ * palPtr;
267 UINT numEntries;
269 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
271 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
272 if (!palPtr) return 0;
274 numEntries = palPtr->logpalette.palNumEntries;
275 if (start >= numEntries)
277 GDI_ReleaseObj( hpalette );
278 return 0;
280 if (start+count > numEntries) count = numEntries - start;
281 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
282 count * sizeof(PALETTEENTRY) );
283 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
284 palPtr->logpalette.palNumEntries);
285 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
286 palPtr->mapping = NULL;
287 GDI_ReleaseObj( hpalette );
288 return count;
292 /***********************************************************************
293 * ResizePalette (GDI.368)
295 BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
297 return ResizePalette( hPal, cEntries );
301 /***********************************************************************
302 * ResizePalette [GDI32.@] Resizes logical palette
304 * RETURNS
305 * Success: TRUE
306 * Failure: FALSE
308 BOOL WINAPI ResizePalette(
309 HPALETTE hPal, /* [in] Handle of logical palette */
310 UINT cEntries) /* [in] Number of entries in logical palette */
312 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
313 UINT cPrevEnt, prevVer;
314 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
315 int* mapping = NULL;
317 TRACE("hpal = %04x, prev = %i, new = %i\n",
318 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
319 cEntries );
320 if( !palPtr ) return FALSE;
321 cPrevEnt = palPtr->logpalette.palNumEntries;
322 prevVer = palPtr->logpalette.palVersion;
323 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
324 sizeof(int*) + sizeof(GDIOBJHDR);
325 size += sizeof(int*) + sizeof(GDIOBJHDR);
326 mapping = palPtr->mapping;
328 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
330 if( mapping )
332 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
333 mapping, cEntries * sizeof(int) );
334 if(newMap == NULL)
336 ERR("Can not resize mapping -- out of memory!\n");
337 GDI_ReleaseObj( hPal );
338 return FALSE;
340 palPtr->mapping = newMap;
343 if( cEntries > cPrevEnt )
345 if( mapping )
346 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
347 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
348 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
349 cEntries - cPrevEnt );
351 palPtr->logpalette.palNumEntries = cEntries;
352 palPtr->logpalette.palVersion = prevVer;
353 GDI_ReleaseObj( hPal );
354 return TRUE;
358 /***********************************************************************
359 * AnimatePalette (GDI.367)
361 void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
362 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
364 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
368 /***********************************************************************
369 * AnimatePalette [GDI32.@] Replaces entries in logical palette
371 * RETURNS
372 * Success: TRUE
373 * Failure: FALSE
375 * FIXME
376 * Should use existing mapping when animating a primary palette
378 BOOL WINAPI AnimatePalette(
379 HPALETTE hPal, /* [in] Handle to logical palette */
380 UINT StartIndex, /* [in] First entry in palette */
381 UINT NumEntries, /* [in] Count of entries in palette */
382 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
384 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
386 if( hPal != GetStockObject(DEFAULT_PALETTE) )
388 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
389 if (!palPtr) return FALSE;
391 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
393 UINT u;
394 for( u = 0; u < NumEntries; u++ )
395 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
396 PALETTE_Driver->
397 pSetMapping(palPtr, StartIndex, NumEntries,
398 hPal != hPrimaryPalette );
399 GDI_ReleaseObj( hPal );
400 return TRUE;
402 GDI_ReleaseObj( hPal );
404 return FALSE;
408 /***********************************************************************
409 * SetSystemPaletteUse (GDI.373)
411 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
413 return SetSystemPaletteUse( hdc, use );
417 /***********************************************************************
418 * SetSystemPaletteUse [GDI32.@]
420 * RETURNS
421 * Success: Previous system palette
422 * Failure: SYSPAL_ERROR
424 UINT WINAPI SetSystemPaletteUse(
425 HDC hdc, /* [in] Handle of device context */
426 UINT use) /* [in] Palette-usage flag */
428 UINT old = SystemPaletteUse;
429 FIXME("(%04x,%04x): stub\n", hdc, use );
430 SystemPaletteUse = use;
431 return old;
435 /***********************************************************************
436 * GetSystemPaletteUse (GDI.374)
438 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
440 return SystemPaletteUse;
444 /***********************************************************************
445 * GetSystemPaletteUse [GDI32.@] Gets state of system palette
447 * RETURNS
448 * Current state of system palette
450 UINT WINAPI GetSystemPaletteUse(
451 HDC hdc) /* [in] Handle of device context */
453 return SystemPaletteUse;
457 /***********************************************************************
458 * GetSystemPaletteEntries (GDI.375)
460 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
461 LPPALETTEENTRY entries )
463 return GetSystemPaletteEntries( hdc, start, count, entries );
467 /***********************************************************************
468 * GetSystemPaletteEntries [GDI32.@] Gets range of palette entries
470 * RETURNS
471 * Success: Number of entries retrieved from palette
472 * Failure: 0
474 UINT WINAPI GetSystemPaletteEntries(
475 HDC hdc, /* [in] Handle of device context */
476 UINT start, /* [in] Index of first entry to be retrieved */
477 UINT count, /* [in] Number of entries to be retrieved */
478 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
480 UINT i;
481 INT sizePalette = GetDeviceCaps( hdc, SIZEPALETTE );
483 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
485 if (!entries) return sizePalette;
486 if (start >= sizePalette) return 0;
487 if (start+count >= sizePalette) count = sizePalette - start;
489 for (i = 0; i < count; i++)
491 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
493 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
494 start + i, *(COLORREF*)(entries + i) );
496 return count;
500 /***********************************************************************
501 * GetNearestPaletteIndex (GDI.370)
503 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
505 return GetNearestPaletteIndex( hpalette, color );
509 /***********************************************************************
510 * GetNearestPaletteIndex [GDI32.@] Gets palette index for color
512 * NOTES
513 * Should index be initialized to CLR_INVALID instead of 0?
515 * RETURNS
516 * Success: Index of entry in logical palette
517 * Failure: CLR_INVALID
519 UINT WINAPI GetNearestPaletteIndex(
520 HPALETTE hpalette, /* [in] Handle of logical color palette */
521 COLORREF color) /* [in] Color to be matched */
523 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
524 UINT index = 0;
526 if( palObj )
528 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
529 palObj->logpalette.palNumEntries,
530 NULL, color, FALSE );
532 GDI_ReleaseObj( hpalette );
534 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
535 return index;
539 /***********************************************************************
540 * GetNearestColor (GDI.154)
542 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
544 return GetNearestColor( hdc, color );
548 /***********************************************************************
549 * GetNearestColor [GDI32.@] Gets a system color to match
551 * RETURNS
552 * Success: Color from system palette that corresponds to given color
553 * Failure: CLR_INVALID
555 COLORREF WINAPI GetNearestColor(
556 HDC hdc, /* [in] Handle of device context */
557 COLORREF color) /* [in] Color to be matched */
559 COLORREF nearest = CLR_INVALID;
560 DC *dc;
561 PALETTEOBJ *palObj;
563 if ( (dc = DC_GetDCPtr( hdc )) )
565 HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
566 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
567 if (!palObj) {
568 GDI_ReleaseObj( hdc );
569 return nearest;
572 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
573 palObj->logpalette.palNumEntries, color );
574 GDI_ReleaseObj( hpal );
575 GDI_ReleaseObj( hdc );
578 TRACE("(%06lx): returning %06lx\n", color, nearest );
579 return nearest;
583 /***********************************************************************
584 * PALETTE_GetObject
586 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
588 if (count > sizeof(WORD)) count = sizeof(WORD);
589 memcpy( buffer, &palette->logpalette.palNumEntries, count );
590 return count;
594 /***********************************************************************
595 * PALETTE_UnrealizeObject
597 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
599 if (palette->mapping)
601 HeapFree( GetProcessHeap(), 0, palette->mapping );
602 palette->mapping = NULL;
604 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
605 return TRUE;
609 /***********************************************************************
610 * PALETTE_DeleteObject
612 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
614 HeapFree( GetProcessHeap(), 0, palette->mapping );
615 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
616 return GDI_FreeObject( hpalette, palette );
620 /***********************************************************************
621 * GDISelectPalette (GDI.361)
623 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
625 HPALETTE16 prev;
626 DC *dc;
628 TRACE("%04x %04x\n", hdc, hpal );
630 if (GetObjectType(hpal) != OBJ_PAL)
632 WARN("invalid selected palette %04x\n",hpal);
633 return 0;
635 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
636 prev = dc->hPalette;
637 dc->hPalette = hpal;
638 GDI_ReleaseObj( hdc );
639 if (!wBkg) hPrimaryPalette = hpal;
640 return prev;
644 /***********************************************************************
645 * GDIRealizePalette (GDI.362)
647 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
649 PALETTEOBJ* palPtr;
650 int realized = 0;
651 DC* dc = DC_GetDCPtr( hdc );
653 if (!dc) return 0;
655 TRACE("%04x...\n", hdc );
657 if(dc->hPalette != hLastRealizedPalette )
659 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) {
660 realized = RealizeDefaultPalette16( hdc );
661 GDI_ReleaseObj( hdc );
662 return (UINT16)realized;
666 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC );
668 if (!palPtr) {
669 GDI_ReleaseObj( hdc );
670 FIXME("invalid selected palette %04x\n",dc->hPalette);
671 return 0;
674 realized = PALETTE_Driver->
675 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
676 (dc->hPalette != hPrimaryPalette) ||
677 (dc->hPalette == GetStockObject( DEFAULT_PALETTE )));
678 hLastRealizedPalette = dc->hPalette;
679 GDI_ReleaseObj( dc->hPalette );
681 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
682 hLastRealizedPalette);
683 GDI_ReleaseObj( hdc );
685 TRACE(" realized %i colors.\n", realized );
686 return (UINT16)realized;
690 /***********************************************************************
691 * RealizeDefaultPalette (GDI.365)
693 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
695 UINT16 ret = 0;
696 DC *dc;
697 PALETTEOBJ* palPtr;
699 TRACE("%04x\n", hdc );
701 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
703 if (!(dc->flags & DC_MEMORY))
705 palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
706 if (palPtr)
708 /* lookup is needed to account for SetSystemPaletteUse() stuff */
709 ret = PALETTE_Driver->pUpdateMapping(palPtr);
710 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
713 GDI_ReleaseObj( hdc );
714 return ret;
717 /***********************************************************************
718 * IsDCCurrentPalette (GDI.412)
720 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
722 DC *dc = DC_GetDCPtr( hDC );
723 if (dc)
725 BOOL bRet = dc->hPalette == hPrimaryPalette;
726 GDI_ReleaseObj( hDC );
727 return bRet;
729 return FALSE;
733 /***********************************************************************
734 * SelectPalette [GDI32.@] Selects logical palette into DC
736 * RETURNS
737 * Success: Previous logical palette
738 * Failure: NULL
740 HPALETTE WINAPI SelectPalette(
741 HDC hDC, /* [in] Handle of device context */
742 HPALETTE hPal, /* [in] Handle of logical color palette */
743 BOOL bForceBackground) /* [in] Foreground/background mode */
745 return pfnSelectPalette( hDC, hPal, bForceBackground );
749 /***********************************************************************
750 * RealizePalette [GDI32.@] Maps palette entries to system palette
752 * RETURNS
753 * Success: Number of entries in logical palette
754 * Failure: GDI_ERROR
756 UINT WINAPI RealizePalette(
757 HDC hDC) /* [in] Handle of device context */
759 return pfnRealizePalette( hDC );
763 typedef HWND WINAPI (*WindowFromDC_funcptr)( HDC );
764 typedef BOOL WINAPI (*RedrawWindow_funcptr)( HWND, const RECT *, HRGN, UINT );
766 /**********************************************************************
767 * UpdateColors [GDI32.@] Remaps current colors to logical palette
769 * RETURNS
770 * Success: TRUE
771 * Failure: FALSE
773 BOOL WINAPI UpdateColors(
774 HDC hDC) /* [in] Handle of device context */
776 HMODULE mod;
777 int size = GetDeviceCaps( hDC, SIZEPALETTE );
779 if (!size) return 0;
781 mod = GetModuleHandleA("user32.dll");
782 if (mod)
784 WindowFromDC_funcptr pWindowFromDC = (WindowFromDC_funcptr)GetProcAddress(mod,"WindowFromDC");
785 if (pWindowFromDC)
787 HWND hWnd = pWindowFromDC( hDC );
789 /* Docs say that we have to remap current drawable pixel by pixel
790 * but it would take forever given the speed of XGet/PutPixel.
792 if (hWnd && size)
794 RedrawWindow_funcptr pRedrawWindow = GetProcAddress( mod, "RedrawWindow" );
795 if (pRedrawWindow) pRedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
799 return 0x666;
803 /**********************************************************************
804 * UpdateColors (GDI.366)
806 INT16 WINAPI UpdateColors16( HDC16 hDC )
808 UpdateColors( hDC );
809 return TRUE;
813 /*********************************************************************
814 * SetMagicColors (GDI.606)
816 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
818 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
822 /**********************************************************************
823 * GetICMProfileA [GDI32.@]
825 * Returns the filename of the specified device context's color
826 * management profile, even if color management is not enabled
827 * for that DC.
829 * RETURNS
830 * TRUE if name copied succesfully OR lpszFilename is NULL
831 * FALSE if the buffer length pointed to by lpcbName is too small
833 * NOTE
834 * The buffer length pointed to by lpcbName is ALWAYS updated to
835 * the length required regardless of other actions this function
836 * may take.
838 * FIXME
839 * How does Windows assign these? Some registry key?
842 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
844 /*********************************************************************/
846 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
848 DWORD callerLen;
850 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
852 callerLen = *lpcbName;
854 /* all 3 behaviors require the required buffer size to be set */
855 *lpcbName = strlen(WINEICM);
857 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
858 if ((DWORD)lpszFilename == (DWORD)0x00000000)
859 return TRUE;
861 /* behavior 2: if buffer size too small, return size of string and error */
862 if (callerLen < strlen(WINEICM))
864 SetLastError(ERROR_INSUFFICIENT_BUFFER);
865 return FALSE;
868 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
869 strcpy(lpszFilename, WINEICM);
870 return TRUE;