Added separate server pipe to wait on blocking server calls.
[wine/multimedia.git] / objects / palette.c
blob78ed5b61d80f75d91cdaa97263554586772d8854
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!");
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 * CreatePalette16 (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 * CreateHalftonePalette16 [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 * GetPaletteEntries16 (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 * SetPaletteEntries16 (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 * ResizePalette16 (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!");
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 * AnimatePalette16 (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 * SetSystemPaletteUse16 (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 * GetSystemPaletteUse16 (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 * GetSystemPaletteEntries16 (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 DC *dc;
483 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
485 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
487 if (!entries)
489 count = dc->devCaps->sizePalette;
490 goto done;
493 if (start >= dc->devCaps->sizePalette)
495 count = 0;
496 goto done;
499 if (start+count >= dc->devCaps->sizePalette)
500 count = dc->devCaps->sizePalette - start;
501 for (i = 0; i < count; i++)
503 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
505 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
506 start + i, *(COLORREF*)(entries + i) );
508 done:
509 GDI_ReleaseObj( hdc );
510 return count;
514 /***********************************************************************
515 * GetNearestPaletteIndex16 (GDI.370)
517 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
519 return GetNearestPaletteIndex( hpalette, color );
523 /***********************************************************************
524 * GetNearestPaletteIndex [GDI32.@] Gets palette index for color
526 * NOTES
527 * Should index be initialized to CLR_INVALID instead of 0?
529 * RETURNS
530 * Success: Index of entry in logical palette
531 * Failure: CLR_INVALID
533 UINT WINAPI GetNearestPaletteIndex(
534 HPALETTE hpalette, /* [in] Handle of logical color palette */
535 COLORREF color) /* [in] Color to be matched */
537 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
538 UINT index = 0;
540 if( palObj )
542 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
543 palObj->logpalette.palNumEntries,
544 NULL, color, FALSE );
546 GDI_ReleaseObj( hpalette );
548 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
549 return index;
553 /***********************************************************************
554 * GetNearestColor16 (GDI.154)
556 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
558 return GetNearestColor( hdc, color );
562 /***********************************************************************
563 * GetNearestColor [GDI32.@] Gets a system color to match
565 * RETURNS
566 * Success: Color from system palette that corresponds to given color
567 * Failure: CLR_INVALID
569 COLORREF WINAPI GetNearestColor(
570 HDC hdc, /* [in] Handle of device context */
571 COLORREF color) /* [in] Color to be matched */
573 COLORREF nearest = CLR_INVALID;
574 DC *dc;
575 PALETTEOBJ *palObj;
577 if ( (dc = DC_GetDCPtr( hdc )) )
579 HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
580 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
581 if (!palObj) {
582 GDI_ReleaseObj( hdc );
583 return nearest;
586 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
587 palObj->logpalette.palNumEntries, color );
588 GDI_ReleaseObj( hpal );
589 GDI_ReleaseObj( hdc );
592 TRACE("(%06lx): returning %06lx\n", color, nearest );
593 return nearest;
597 /***********************************************************************
598 * PALETTE_GetObject
600 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
602 if (count > sizeof(WORD)) count = sizeof(WORD);
603 memcpy( buffer, &palette->logpalette.palNumEntries, count );
604 return count;
608 /***********************************************************************
609 * PALETTE_UnrealizeObject
611 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
613 if (palette->mapping)
615 HeapFree( GetProcessHeap(), 0, palette->mapping );
616 palette->mapping = NULL;
618 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
619 return TRUE;
623 /***********************************************************************
624 * PALETTE_DeleteObject
626 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
628 HeapFree( GetProcessHeap(), 0, palette->mapping );
629 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
630 return GDI_FreeObject( hpalette, palette );
634 /***********************************************************************
635 * GDISelectPalette (GDI.361)
637 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
639 HPALETTE16 prev;
640 DC *dc;
642 TRACE("%04x %04x\n", hdc, hpal );
644 if (GetObjectType(hpal) != OBJ_PAL)
646 WARN("invalid selected palette %04x\n",hpal);
647 return 0;
649 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
650 prev = dc->hPalette;
651 dc->hPalette = hpal;
652 GDI_ReleaseObj( hdc );
653 if (!wBkg) hPrimaryPalette = hpal;
654 return prev;
658 /***********************************************************************
659 * GDIRealizePalette (GDI.362)
661 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
663 PALETTEOBJ* palPtr;
664 int realized = 0;
665 DC* dc = DC_GetDCPtr( hdc );
667 if (!dc) return 0;
669 TRACE("%04x...\n", hdc );
671 if(dc->hPalette != hLastRealizedPalette )
673 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) {
674 realized = RealizeDefaultPalette16( hdc );
675 GDI_ReleaseObj( hdc );
676 return (UINT16)realized;
680 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC );
682 if (!palPtr) {
683 GDI_ReleaseObj( hdc );
684 FIXME("invalid selected palette %04x\n",dc->hPalette);
685 return 0;
688 realized = PALETTE_Driver->
689 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
690 (dc->hPalette != hPrimaryPalette) ||
691 (dc->hPalette == GetStockObject( DEFAULT_PALETTE )));
692 hLastRealizedPalette = dc->hPalette;
693 GDI_ReleaseObj( dc->hPalette );
695 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
696 hLastRealizedPalette);
697 GDI_ReleaseObj( hdc );
699 TRACE(" realized %i colors.\n", realized );
700 return (UINT16)realized;
704 /***********************************************************************
705 * RealizeDefaultPalette (GDI.365)
707 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
709 UINT16 ret = 0;
710 DC *dc;
711 PALETTEOBJ* palPtr;
713 TRACE("%04x\n", hdc );
715 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
717 if (!(dc->flags & DC_MEMORY))
719 palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
720 if (palPtr)
722 /* lookup is needed to account for SetSystemPaletteUse() stuff */
723 ret = PALETTE_Driver->pUpdateMapping(palPtr);
724 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
727 GDI_ReleaseObj( hdc );
728 return ret;
731 /***********************************************************************
732 * IsDCCurrentPalette (GDI.412)
734 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
736 DC *dc = DC_GetDCPtr( hDC );
737 if (dc)
739 BOOL bRet = dc->hPalette == hPrimaryPalette;
740 GDI_ReleaseObj( hDC );
741 return bRet;
743 return FALSE;
747 /***********************************************************************
748 * SelectPalette [GDI32.@] Selects logical palette into DC
750 * RETURNS
751 * Success: Previous logical palette
752 * Failure: NULL
754 HPALETTE WINAPI SelectPalette(
755 HDC hDC, /* [in] Handle of device context */
756 HPALETTE hPal, /* [in] Handle of logical color palette */
757 BOOL bForceBackground) /* [in] Foreground/background mode */
759 return pfnSelectPalette( hDC, hPal, bForceBackground );
763 /***********************************************************************
764 * RealizePalette [GDI32.@] Maps palette entries to system palette
766 * RETURNS
767 * Success: Number of entries in logical palette
768 * Failure: GDI_ERROR
770 UINT WINAPI RealizePalette(
771 HDC hDC) /* [in] Handle of device context */
773 return pfnRealizePalette( hDC );
777 typedef HWND WINAPI (*WindowFromDC_funcptr)( HDC );
778 typedef BOOL WINAPI (*RedrawWindow_funcptr)( HWND, const RECT *, HRGN, UINT );
780 /**********************************************************************
781 * UpdateColors16 (DISPLAY.366)
782 * UpdateColors16 (GDI.366)
784 INT16 WINAPI UpdateColors16( HDC16 hDC )
786 HMODULE mod;
787 DC *dc;
788 int size;
790 if (!(dc = DC_GetDCPtr( hDC ))) return 0;
791 size = dc->devCaps->sizePalette;
792 GDI_ReleaseObj( hDC );
794 mod = GetModuleHandleA("user32.dll");
795 if (mod)
797 WindowFromDC_funcptr pWindowFromDC = (WindowFromDC_funcptr)GetProcAddress(mod,"WindowFromDC");
798 if (pWindowFromDC)
800 HWND hWnd = pWindowFromDC( hDC );
802 /* Docs say that we have to remap current drawable pixel by pixel
803 * but it would take forever given the speed of XGet/PutPixel.
805 if (hWnd && size)
807 RedrawWindow_funcptr pRedrawWindow = GetProcAddress( mod, "RedrawWindow" );
808 if (pRedrawWindow) pRedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
812 return 0x666;
816 /**********************************************************************
817 * UpdateColors [GDI32.@] Remaps current colors to logical palette
819 * RETURNS
820 * Success: TRUE
821 * Failure: FALSE
823 BOOL WINAPI UpdateColors(
824 HDC hDC) /* [in] Handle of device context */
826 UpdateColors16( hDC );
827 return TRUE;
831 /*********************************************************************
832 * SetMagicColors16 (GDI.606)
834 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
836 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
840 /**********************************************************************
841 * GetICMProfileA [GDI32.@]
843 * Returns the filename of the specified device context's color
844 * management profile, even if color management is not enabled
845 * for that DC.
847 * RETURNS
848 * TRUE if name copied succesfully OR lpszFilename is NULL
849 * FALSE if the buffer length pointed to by lpcbName is too small
851 * NOTE
852 * The buffer length pointed to by lpcbName is ALWAYS updated to
853 * the length required regardless of other actions this function
854 * may take.
856 * FIXME
857 * How does Windows assign these? Some registry key?
860 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
862 /*********************************************************************/
864 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
866 DWORD callerLen;
868 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
870 callerLen = *lpcbName;
872 /* all 3 behaviors require the required buffer size to be set */
873 *lpcbName = strlen(WINEICM);
875 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
876 if ((DWORD)lpszFilename == (DWORD)0x00000000)
877 return TRUE;
879 /* behavior 2: if buffer size too small, return size of string and error */
880 if (callerLen < strlen(WINEICM))
882 SetLastError(ERROR_INSUFFICIENT_BUFFER);
883 return FALSE;
886 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
887 strcpy(lpszFilename, WINEICM);
888 return TRUE;