Removed redundant thread priority defines.
[wine/testsucceed.git] / objects / palette.c
blob046fe310204294f0ad8148d95358d787ad8ffbee
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 "dc.h"
21 #include "palette.h"
22 #include "debugtools.h"
23 #include "callback.h"
24 #include "winerror.h"
26 DEFAULT_DEBUG_CHANNEL(palette);
28 PALETTE_DRIVER *PALETTE_Driver = NULL;
30 /* Pointers to USER implementation of SelectPalette/RealizePalette */
31 /* they will be patched by USER on startup */
32 FARPROC pfnSelectPalette = NULL;
33 FARPROC pfnRealizePalette = NULL;
35 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
37 static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
38 static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
41 /***********************************************************************
42 * PALETTE_Init
44 * Create the system palette.
46 HPALETTE16 PALETTE_Init(void)
48 int i;
49 HPALETTE16 hpalette;
50 LOGPALETTE * palPtr;
51 PALETTEOBJ* palObj;
52 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
54 /* create default palette (20 system colors) */
56 palPtr = HeapAlloc( GetProcessHeap(), 0,
57 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
58 if (!palPtr) return FALSE;
60 palPtr->palVersion = 0x300;
61 palPtr->palNumEntries = NB_RESERVED_COLORS;
62 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
64 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
65 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
66 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
67 palPtr->palPalEntry[i].peFlags = 0;
69 hpalette = CreatePalette16( palPtr );
70 HeapFree( GetProcessHeap(), 0, palPtr );
72 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
73 if (palObj)
75 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
76 ERR("Can not create palette mapping -- out of memory!");
77 GDI_ReleaseObj( hpalette );
79 return hpalette;
82 /***********************************************************************
83 * PALETTE_ValidateFlags
85 void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
87 int i = 0;
88 for( ; i<size ; i++ )
89 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
93 /***********************************************************************
94 * CreatePalette16 (GDI.360)
96 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
98 return CreatePalette( palette );
102 /***********************************************************************
103 * CreatePalette [GDI32.53] Creates a logical color palette
105 * RETURNS
106 * Success: Handle to logical palette
107 * Failure: NULL
109 HPALETTE WINAPI CreatePalette(
110 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
112 PALETTEOBJ * palettePtr;
113 HPALETTE hpalette;
114 int size;
116 if (!palette) return 0;
117 TRACE("entries=%i\n", palette->palNumEntries);
119 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
121 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
122 PALETTE_MAGIC, &hpalette ))) return 0;
123 memcpy( &palettePtr->logpalette, palette, size );
124 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
125 palettePtr->logpalette.palNumEntries);
126 palettePtr->mapping = NULL;
127 GDI_ReleaseObj( hpalette );
129 TRACE(" returning %04x\n", hpalette);
130 return hpalette;
134 /***********************************************************************
135 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
137 * RETURNS
138 * Success: Handle to logical halftone palette
139 * Failure: 0
141 HPALETTE16 WINAPI CreateHalftonePalette16(
142 HDC16 hdc) /* [in] Handle to device context */
144 return CreateHalftonePalette(hdc);
148 /***********************************************************************
149 * CreateHalftonePalette [GDI32.47] Creates a halftone palette
151 * RETURNS
152 * Success: Handle to logical halftone palette
153 * Failure: 0
155 * FIXME: not truly tested
157 HPALETTE WINAPI CreateHalftonePalette(
158 HDC hdc) /* [in] Handle to device context */
160 int i, r, g, b;
161 struct {
162 WORD Version;
163 WORD NumberOfEntries;
164 PALETTEENTRY aEntries[256];
165 } Palette = {
166 0x300, 256
169 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
170 return CreatePalette((LOGPALETTE *)&Palette);
172 for (r = 0; r < 6; r++) {
173 for (g = 0; g < 6; g++) {
174 for (b = 0; b < 6; b++) {
175 i = r + g*6 + b*36 + 10;
176 Palette.aEntries[i].peRed = r * 51;
177 Palette.aEntries[i].peGreen = g * 51;
178 Palette.aEntries[i].peBlue = b * 51;
183 for (i = 216; i < 246; i++) {
184 int v = (i - 216) * 8;
185 Palette.aEntries[i].peRed = v;
186 Palette.aEntries[i].peGreen = v;
187 Palette.aEntries[i].peBlue = v;
190 return CreatePalette((LOGPALETTE *)&Palette);
194 /***********************************************************************
195 * GetPaletteEntries16 (GDI.363)
197 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
198 UINT16 count, LPPALETTEENTRY entries )
200 return GetPaletteEntries( hpalette, start, count, entries );
204 /***********************************************************************
205 * GetPaletteEntries [GDI32.209] Retrieves palette entries
207 * RETURNS
208 * Success: Number of entries from logical palette
209 * Failure: 0
211 UINT WINAPI GetPaletteEntries(
212 HPALETTE hpalette, /* [in] Handle of logical palette */
213 UINT start, /* [in] First entry to receive */
214 UINT count, /* [in] Number of entries to receive */
215 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
217 PALETTEOBJ * palPtr;
218 INT numEntries;
220 TRACE("hpal = %04x, count=%i\n", hpalette, count );
222 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
223 if (!palPtr) return 0;
225 numEntries = palPtr->logpalette.palNumEntries;
226 if (start+count > numEntries) count = numEntries - start;
227 if (entries)
229 if (start >= numEntries)
231 GDI_ReleaseObj( hpalette );
232 return 0;
234 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
235 count * sizeof(PALETTEENTRY) );
236 for( numEntries = 0; numEntries < count ; numEntries++ )
237 if (entries[numEntries].peFlags & 0xF0)
238 entries[numEntries].peFlags = 0;
241 GDI_ReleaseObj( hpalette );
242 return count;
246 /***********************************************************************
247 * SetPaletteEntries16 (GDI.364)
249 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
250 UINT16 count, LPPALETTEENTRY entries )
252 return SetPaletteEntries( hpalette, start, count, entries );
256 /***********************************************************************
257 * SetPaletteEntries [GDI32.326] Sets color values for range in palette
259 * RETURNS
260 * Success: Number of entries that were set
261 * Failure: 0
263 UINT WINAPI SetPaletteEntries(
264 HPALETTE hpalette, /* [in] Handle of logical palette */
265 UINT start, /* [in] Index of first entry to set */
266 UINT count, /* [in] Number of entries to set */
267 LPPALETTEENTRY entries) /* [in] Address of array of structures */
269 PALETTEOBJ * palPtr;
270 INT numEntries;
272 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
274 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
275 if (!palPtr) return 0;
277 numEntries = palPtr->logpalette.palNumEntries;
278 if (start >= numEntries)
280 GDI_ReleaseObj( hpalette );
281 return 0;
283 if (start+count > numEntries) count = numEntries - start;
284 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
285 count * sizeof(PALETTEENTRY) );
286 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
287 palPtr->logpalette.palNumEntries);
288 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
289 palPtr->mapping = NULL;
290 GDI_ReleaseObj( hpalette );
291 return count;
295 /***********************************************************************
296 * ResizePalette16 (GDI.368)
298 BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
300 return ResizePalette( hPal, cEntries );
304 /***********************************************************************
305 * ResizePalette [GDI32.289] Resizes logical palette
307 * RETURNS
308 * Success: TRUE
309 * Failure: FALSE
311 BOOL WINAPI ResizePalette(
312 HPALETTE hPal, /* [in] Handle of logical palette */
313 UINT cEntries) /* [in] Number of entries in logical palette */
315 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
316 UINT cPrevEnt, prevVer;
317 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
318 int* mapping = NULL;
320 TRACE("hpal = %04x, prev = %i, new = %i\n",
321 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
322 cEntries );
323 if( !palPtr ) return FALSE;
324 cPrevEnt = palPtr->logpalette.palNumEntries;
325 prevVer = palPtr->logpalette.palVersion;
326 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
327 sizeof(int*) + sizeof(GDIOBJHDR);
328 size += sizeof(int*) + sizeof(GDIOBJHDR);
329 mapping = palPtr->mapping;
331 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
333 if( mapping )
335 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
336 mapping, cEntries * sizeof(int) );
337 if(newMap == NULL)
339 ERR("Can not resize mapping -- out of memory!");
340 GDI_ReleaseObj( hPal );
341 return FALSE;
343 palPtr->mapping = newMap;
346 if( cEntries > cPrevEnt )
348 if( mapping )
349 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
350 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
351 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
352 cEntries - cPrevEnt );
354 palPtr->logpalette.palNumEntries = cEntries;
355 palPtr->logpalette.palVersion = prevVer;
356 GDI_ReleaseObj( hPal );
357 return TRUE;
361 /***********************************************************************
362 * AnimatePalette16 (GDI.367)
364 void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
365 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
367 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
371 /***********************************************************************
372 * AnimatePalette [GDI32.6] Replaces entries in logical palette
374 * RETURNS
375 * Success: TRUE
376 * Failure: FALSE
378 * FIXME
379 * Should use existing mapping when animating a primary palette
381 BOOL WINAPI AnimatePalette(
382 HPALETTE hPal, /* [in] Handle to logical palette */
383 UINT StartIndex, /* [in] First entry in palette */
384 UINT NumEntries, /* [in] Count of entries in palette */
385 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
387 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
389 if( hPal != STOCK_DEFAULT_PALETTE )
391 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
392 if (!palPtr) return FALSE;
394 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
396 UINT u;
397 for( u = 0; u < NumEntries; u++ )
398 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
399 PALETTE_Driver->
400 pSetMapping(palPtr, StartIndex, NumEntries,
401 hPal != hPrimaryPalette );
402 GDI_ReleaseObj( hPal );
403 return TRUE;
405 GDI_ReleaseObj( hPal );
407 return FALSE;
411 /***********************************************************************
412 * SetSystemPaletteUse16 (GDI.373)
414 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
416 return SetSystemPaletteUse( hdc, use );
420 /***********************************************************************
421 * SetSystemPaletteUse [GDI32.335]
423 * RETURNS
424 * Success: Previous system palette
425 * Failure: SYSPAL_ERROR
427 UINT WINAPI SetSystemPaletteUse(
428 HDC hdc, /* [in] Handle of device context */
429 UINT use) /* [in] Palette-usage flag */
431 UINT old = SystemPaletteUse;
432 FIXME("(%04x,%04x): stub\n", hdc, use );
433 SystemPaletteUse = use;
434 return old;
438 /***********************************************************************
439 * GetSystemPaletteUse16 (GDI.374)
441 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
443 return SystemPaletteUse;
447 /***********************************************************************
448 * GetSystemPaletteUse [GDI32.223] Gets state of system palette
450 * RETURNS
451 * Current state of system palette
453 UINT WINAPI GetSystemPaletteUse(
454 HDC hdc) /* [in] Handle of device context */
456 return SystemPaletteUse;
460 /***********************************************************************
461 * GetSystemPaletteEntries16 (GDI.375)
463 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
464 LPPALETTEENTRY entries )
466 return GetSystemPaletteEntries( hdc, start, count, entries );
470 /***********************************************************************
471 * GetSystemPaletteEntries [GDI32.222] Gets range of palette entries
473 * RETURNS
474 * Success: Number of entries retrieved from palette
475 * Failure: 0
477 UINT WINAPI GetSystemPaletteEntries(
478 HDC hdc, /* [in] Handle of device context */
479 UINT start, /* [in] Index of first entry to be retrieved */
480 UINT count, /* [in] Number of entries to be retrieved */
481 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
483 UINT i;
484 DC *dc;
486 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
488 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
490 if (!entries)
492 count = dc->w.devCaps->sizePalette;
493 goto done;
496 if (start >= dc->w.devCaps->sizePalette)
498 count = 0;
499 goto done;
502 if (start+count >= dc->w.devCaps->sizePalette)
503 count = dc->w.devCaps->sizePalette - start;
504 for (i = 0; i < count; i++)
506 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
508 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
509 start + i, *(COLORREF*)(entries + i) );
511 done:
512 GDI_ReleaseObj( hdc );
513 return count;
517 /***********************************************************************
518 * GetNearestPaletteIndex16 (GDI.370)
520 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
522 return GetNearestPaletteIndex( hpalette, color );
526 /***********************************************************************
527 * GetNearestPaletteIndex [GDI32.203] Gets palette index for color
529 * NOTES
530 * Should index be initialized to CLR_INVALID instead of 0?
532 * RETURNS
533 * Success: Index of entry in logical palette
534 * Failure: CLR_INVALID
536 UINT WINAPI GetNearestPaletteIndex(
537 HPALETTE hpalette, /* [in] Handle of logical color palette */
538 COLORREF color) /* [in] Color to be matched */
540 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
541 UINT index = 0;
543 if( palObj )
545 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
546 palObj->logpalette.palNumEntries,
547 NULL, color, FALSE );
549 GDI_ReleaseObj( hpalette );
551 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
552 return index;
556 /***********************************************************************
557 * GetNearestColor16 (GDI.154)
559 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
561 return GetNearestColor( hdc, color );
565 /***********************************************************************
566 * GetNearestColor [GDI32.202] Gets a system color to match
568 * RETURNS
569 * Success: Color from system palette that corresponds to given color
570 * Failure: CLR_INVALID
572 COLORREF WINAPI GetNearestColor(
573 HDC hdc, /* [in] Handle of device context */
574 COLORREF color) /* [in] Color to be matched */
576 COLORREF nearest = CLR_INVALID;
577 DC *dc;
578 PALETTEOBJ *palObj;
580 if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
582 HPALETTE hpal = (dc->w.hPalette)? dc->w.hPalette : STOCK_DEFAULT_PALETTE;
583 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
584 if (!palObj) {
585 GDI_ReleaseObj( hdc );
586 return nearest;
589 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
590 palObj->logpalette.palNumEntries, color );
591 GDI_ReleaseObj( hpal );
592 GDI_ReleaseObj( hdc );
595 TRACE("(%06lx): returning %06lx\n", color, nearest );
596 return nearest;
600 /***********************************************************************
601 * PALETTE_GetObject
603 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
605 if (count > sizeof(WORD)) count = sizeof(WORD);
606 memcpy( buffer, &palette->logpalette.palNumEntries, count );
607 return count;
611 /***********************************************************************
612 * PALETTE_UnrealizeObject
614 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
616 if (palette->mapping)
618 HeapFree( GetProcessHeap(), 0, palette->mapping );
619 palette->mapping = NULL;
621 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
622 return TRUE;
626 /***********************************************************************
627 * PALETTE_DeleteObject
629 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
631 HeapFree( GetProcessHeap(), 0, palette->mapping );
632 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
633 return GDI_FreeObject( hpalette, palette );
637 /***********************************************************************
638 * GDISelectPalette (GDI.361)
640 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
642 HPALETTE16 prev;
643 DC *dc;
645 TRACE("%04x %04x\n", hdc, hpal );
647 if (GetObjectType(hpal) != OBJ_PAL)
649 WARN("invalid selected palette %04x\n",hpal);
650 return 0;
652 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
653 prev = dc->w.hPalette;
654 dc->w.hPalette = hpal;
655 GDI_ReleaseObj( hdc );
656 if (!wBkg) hPrimaryPalette = hpal;
657 return prev;
661 /***********************************************************************
662 * GDIRealizePalette (GDI.362)
664 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
666 PALETTEOBJ* palPtr;
667 int realized = 0;
668 DC* dc = DC_GetDCPtr( hdc );
670 if (!dc) return 0;
672 TRACE("%04x...\n", hdc );
674 if(dc->w.hPalette != hLastRealizedPalette )
676 if( dc->w.hPalette == STOCK_DEFAULT_PALETTE ) {
677 realized = RealizeDefaultPalette16( hdc );
678 GDI_ReleaseObj( hdc );
679 return (UINT16)realized;
683 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
685 if (!palPtr) {
686 GDI_ReleaseObj( hdc );
687 FIXME("invalid selected palette %04x\n",dc->w.hPalette);
688 return 0;
691 realized = PALETTE_Driver->
692 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
693 (dc->w.hPalette != hPrimaryPalette) ||
694 (dc->w.hPalette == STOCK_DEFAULT_PALETTE));
695 hLastRealizedPalette = dc->w.hPalette;
696 GDI_ReleaseObj( dc->w.hPalette );
698 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
699 hLastRealizedPalette);
700 GDI_ReleaseObj( hdc );
702 TRACE(" realized %i colors.\n", realized );
703 return (UINT16)realized;
707 /***********************************************************************
708 * RealizeDefaultPalette (GDI.365)
710 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
712 UINT16 ret = 0;
713 DC *dc;
714 PALETTEOBJ* palPtr;
716 TRACE("%04x\n", hdc );
718 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
720 if (!(dc->w.flags & DC_MEMORY))
722 palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
723 if (palPtr)
725 /* lookup is needed to account for SetSystemPaletteUse() stuff */
726 ret = PALETTE_Driver->pUpdateMapping(palPtr);
727 GDI_ReleaseObj( STOCK_DEFAULT_PALETTE );
730 GDI_ReleaseObj( hdc );
731 return ret;
734 /***********************************************************************
735 * IsDCCurrentPalette (GDI.412)
737 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
739 DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
740 if (dc)
742 BOOL bRet = dc->w.hPalette == hPrimaryPalette;
743 GDI_ReleaseObj( hDC );
744 return bRet;
746 return FALSE;
750 /***********************************************************************
751 * SelectPalette [GDI32.300] Selects logical palette into DC
753 * RETURNS
754 * Success: Previous logical palette
755 * Failure: NULL
757 HPALETTE WINAPI SelectPalette(
758 HDC hDC, /* [in] Handle of device context */
759 HPALETTE hPal, /* [in] Handle of logical color palette */
760 BOOL bForceBackground) /* [in] Foreground/background mode */
762 return pfnSelectPalette( hDC, hPal, bForceBackground );
766 /***********************************************************************
767 * RealizePalette [GDI32.280] Maps palette entries to system palette
769 * RETURNS
770 * Success: Number of entries in logical palette
771 * Failure: GDI_ERROR
773 UINT WINAPI RealizePalette(
774 HDC hDC) /* [in] Handle of device context */
776 return pfnRealizePalette( hDC );
780 /**********************************************************************
781 * UpdateColors16 (GDI.366)
783 INT16 WINAPI UpdateColors16( HDC16 hDC )
785 DC *dc;
786 HWND hWnd;
787 int size;
789 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return 0;
790 size = dc->w.devCaps->sizePalette;
791 GDI_ReleaseObj( hDC );
792 hWnd = Callout.WindowFromDC( hDC );
794 /* Docs say that we have to remap current drawable pixel by pixel
795 * but it would take forever given the speed of XGet/PutPixel.
797 if (hWnd && size)
798 Callout.RedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
800 return 0x666;
804 /**********************************************************************
805 * UpdateColors [GDI32.359] Remaps current colors to logical palette
807 * RETURNS
808 * Success: TRUE
809 * Failure: FALSE
811 BOOL WINAPI UpdateColors(
812 HDC hDC) /* [in] Handle of device context */
814 UpdateColors16( hDC );
815 return TRUE;
819 /*********************************************************************
820 * SetMagicColors16 (GDI.606)
822 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
824 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
828 /**********************************************************************
829 * GetICMProfileA [GDI32.316]
831 * Returns the filename of the specified device context's color
832 * management profile, even if color management is not enabled
833 * for that DC.
835 * RETURNS
836 * TRUE if name copied succesfully OR lpszFilename is NULL
837 * FALSE if the buffer length pointed to by lpcbName is too small
839 * NOTE
840 * The buffer length pointed to by lpcbName is ALWAYS updated to
841 * the length required regardless of other actions this function
842 * may take.
844 * FIXME
845 * How does Windows assign these? Some registry key?
848 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
850 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
852 DWORD callerLen;
854 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
856 callerLen = *lpcbName;
858 /* all 3 behaviors require the required buffer size to be set */
859 *lpcbName = strlen(WINEICM);
861 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
862 if ((DWORD)lpszFilename == (DWORD)0x00000000)
863 return TRUE;
865 /* behavior 2: if buffer size too small, return size of string and error */
866 if (callerLen < strlen(WINEICM))
868 SetLastError(ERROR_INSUFFICIENT_BUFFER);
869 return FALSE;
872 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
873 strcpy(lpszFilename, WINEICM);
874 return TRUE;