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.
17 #include "wine/winuser16.h"
21 #include "debugtools.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 /***********************************************************************
42 * Create the system palette.
44 HPALETTE16
PALETTE_Init(void)
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
);
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
);
80 /***********************************************************************
81 * PALETTE_ValidateFlags
83 void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
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
104 * Success: Handle to logical palette
107 HPALETTE WINAPI
CreatePalette(
108 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
110 PALETTEOBJ
* palettePtr
;
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
);
132 /***********************************************************************
133 * CreateHalftonePalette [GDI.529] Creates a halftone palette
136 * Success: Handle to logical halftone palette
139 HPALETTE16 WINAPI
CreateHalftonePalette16(
140 HDC16 hdc
) /* [in] Handle to device context */
142 return CreateHalftonePalette(hdc
);
146 /***********************************************************************
147 * CreateHalftonePalette [GDI32.@] Creates a halftone palette
150 * Success: Handle to logical halftone palette
153 * FIXME: This simply creates the halftone palette dirived from runing
154 * tests on an windows NT machine. this is assuming a color depth
155 * of greater that 256 color. On a 256 color device the halftone
156 * palette will be differnt and this funtion will be incorrect
158 HPALETTE WINAPI
CreateHalftonePalette(
159 HDC hdc
) /* [in] Handle to device context */
164 WORD NumberOfEntries
;
165 PALETTEENTRY aEntries
[256];
168 Palette
.Version
= 0x300;
169 Palette
.NumberOfEntries
= 256;
170 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
172 Palette
.NumberOfEntries
= 20;
174 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
176 Palette
.aEntries
[i
].peRed
=0xff;
177 Palette
.aEntries
[i
].peGreen
=0xff;
178 Palette
.aEntries
[i
].peBlue
=0xff;
179 Palette
.aEntries
[i
].peFlags
=0x00;
182 Palette
.aEntries
[0].peRed
=0x00;
183 Palette
.aEntries
[0].peBlue
=0x00;
184 Palette
.aEntries
[0].peGreen
=0x00;
187 for (i
=1; i
<= 6; i
++)
189 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
190 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
191 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
194 for (i
=7; i
<= 12; i
++)
199 Palette
.aEntries
[i
].peRed
=0xc0;
200 Palette
.aEntries
[i
].peBlue
=0xc0;
201 Palette
.aEntries
[i
].peGreen
=0xc0;
204 Palette
.aEntries
[i
].peRed
=0xc0;
205 Palette
.aEntries
[i
].peGreen
=0xdc;
206 Palette
.aEntries
[i
].peBlue
=0xc0;
209 Palette
.aEntries
[i
].peRed
=0xa6;
210 Palette
.aEntries
[i
].peGreen
=0xca;
211 Palette
.aEntries
[i
].peBlue
=0xf0;
214 Palette
.aEntries
[i
].peRed
=0xff;
215 Palette
.aEntries
[i
].peGreen
=0xfb;
216 Palette
.aEntries
[i
].peBlue
=0xf0;
219 Palette
.aEntries
[i
].peRed
=0xa0;
220 Palette
.aEntries
[i
].peGreen
=0xa0;
221 Palette
.aEntries
[i
].peBlue
=0xa4;
224 Palette
.aEntries
[i
].peRed
=0x80;
225 Palette
.aEntries
[i
].peGreen
=0x80;
226 Palette
.aEntries
[i
].peBlue
=0x80;
230 for (i
=13; i
<= 18; i
++)
232 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
233 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
234 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
237 return CreatePalette((LOGPALETTE
*)&Palette
);
241 /***********************************************************************
242 * GetPaletteEntries (GDI.363)
244 UINT16 WINAPI
GetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
245 UINT16 count
, LPPALETTEENTRY entries
)
247 return GetPaletteEntries( hpalette
, start
, count
, entries
);
251 /***********************************************************************
252 * GetPaletteEntries [GDI32.@] Retrieves palette entries
255 * Success: Number of entries from logical palette
258 UINT WINAPI
GetPaletteEntries(
259 HPALETTE hpalette
, /* [in] Handle of logical palette */
260 UINT start
, /* [in] First entry to receive */
261 UINT count
, /* [in] Number of entries to receive */
262 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
267 TRACE("hpal = %04x, count=%i\n", hpalette
, count
);
269 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
270 if (!palPtr
) return 0;
272 /* NOTE: not documented but test show this to be the case */
275 int rc
= palPtr
->logpalette
.palNumEntries
;
276 GDI_ReleaseObj( hpalette
);
280 numEntries
= palPtr
->logpalette
.palNumEntries
;
281 if (start
+count
> numEntries
) count
= numEntries
- start
;
284 if (start
>= numEntries
)
286 GDI_ReleaseObj( hpalette
);
289 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
290 count
* sizeof(PALETTEENTRY
) );
291 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
292 if (entries
[numEntries
].peFlags
& 0xF0)
293 entries
[numEntries
].peFlags
= 0;
296 GDI_ReleaseObj( hpalette
);
301 /***********************************************************************
302 * SetPaletteEntries (GDI.364)
304 UINT16 WINAPI
SetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
305 UINT16 count
, LPPALETTEENTRY entries
)
307 return SetPaletteEntries( hpalette
, start
, count
, entries
);
311 /***********************************************************************
312 * SetPaletteEntries [GDI32.@] Sets color values for range in palette
315 * Success: Number of entries that were set
318 UINT WINAPI
SetPaletteEntries(
319 HPALETTE hpalette
, /* [in] Handle of logical palette */
320 UINT start
, /* [in] Index of first entry to set */
321 UINT count
, /* [in] Number of entries to set */
322 LPPALETTEENTRY entries
) /* [in] Address of array of structures */
327 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette
,start
,count
);
329 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
330 if (!palPtr
) return 0;
332 numEntries
= palPtr
->logpalette
.palNumEntries
;
333 if (start
>= numEntries
)
335 GDI_ReleaseObj( hpalette
);
338 if (start
+count
> numEntries
) count
= numEntries
- start
;
339 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
340 count
* sizeof(PALETTEENTRY
) );
341 PALETTE_ValidateFlags(palPtr
->logpalette
.palPalEntry
,
342 palPtr
->logpalette
.palNumEntries
);
343 HeapFree( GetProcessHeap(), 0, palPtr
->mapping
);
344 palPtr
->mapping
= NULL
;
345 GDI_ReleaseObj( hpalette
);
350 /***********************************************************************
351 * ResizePalette (GDI.368)
353 BOOL16 WINAPI
ResizePalette16( HPALETTE16 hPal
, UINT16 cEntries
)
355 return ResizePalette( hPal
, cEntries
);
359 /***********************************************************************
360 * ResizePalette [GDI32.@] Resizes logical palette
366 BOOL WINAPI
ResizePalette(
367 HPALETTE hPal
, /* [in] Handle of logical palette */
368 UINT cEntries
) /* [in] Number of entries in logical palette */
370 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
371 UINT cPrevEnt
, prevVer
;
372 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
375 TRACE("hpal = %04x, prev = %i, new = %i\n",
376 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1,
378 if( !palPtr
) return FALSE
;
379 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
380 prevVer
= palPtr
->logpalette
.palVersion
;
381 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
382 sizeof(int*) + sizeof(GDIOBJHDR
);
383 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
384 mapping
= palPtr
->mapping
;
386 if (!(palPtr
= GDI_ReallocObject( size
, hPal
, palPtr
))) return FALSE
;
390 int *newMap
= (int*) HeapReAlloc(GetProcessHeap(), 0,
391 mapping
, cEntries
* sizeof(int) );
394 ERR("Can not resize mapping -- out of memory!\n");
395 GDI_ReleaseObj( hPal
);
398 palPtr
->mapping
= newMap
;
401 if( cEntries
> cPrevEnt
)
404 memset(palPtr
->mapping
+ cPrevEnt
, 0, (cEntries
- cPrevEnt
)*sizeof(int));
405 memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
406 PALETTE_ValidateFlags((PALETTEENTRY
*)((BYTE
*)palPtr
+ prevsize
),
407 cEntries
- cPrevEnt
);
409 palPtr
->logpalette
.palNumEntries
= cEntries
;
410 palPtr
->logpalette
.palVersion
= prevVer
;
411 GDI_ReleaseObj( hPal
);
416 /***********************************************************************
417 * AnimatePalette (GDI.367)
419 void WINAPI
AnimatePalette16( HPALETTE16 hPal
, UINT16 StartIndex
,
420 UINT16 NumEntries
, const PALETTEENTRY
* PaletteColors
)
422 AnimatePalette( hPal
, StartIndex
, NumEntries
, PaletteColors
);
426 /***********************************************************************
427 * AnimatePalette [GDI32.@] Replaces entries in logical palette
434 * Should use existing mapping when animating a primary palette
436 BOOL WINAPI
AnimatePalette(
437 HPALETTE hPal
, /* [in] Handle to logical palette */
438 UINT StartIndex
, /* [in] First entry in palette */
439 UINT NumEntries
, /* [in] Count of entries in palette */
440 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
442 TRACE("%04x (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
444 if( hPal
!= GetStockObject(DEFAULT_PALETTE
) )
446 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr(hPal
, PALETTE_MAGIC
);
447 if (!palPtr
) return FALSE
;
449 if( (StartIndex
+ NumEntries
) <= palPtr
->logpalette
.palNumEntries
)
452 for( u
= 0; u
< NumEntries
; u
++ )
453 palPtr
->logpalette
.palPalEntry
[u
+ StartIndex
] = PaletteColors
[u
];
455 pSetMapping(palPtr
, StartIndex
, NumEntries
,
456 hPal
!= hPrimaryPalette
);
457 GDI_ReleaseObj( hPal
);
460 GDI_ReleaseObj( hPal
);
466 /***********************************************************************
467 * SetSystemPaletteUse (GDI.373)
469 UINT16 WINAPI
SetSystemPaletteUse16( HDC16 hdc
, UINT16 use
)
471 return SetSystemPaletteUse( hdc
, use
);
475 /***********************************************************************
476 * SetSystemPaletteUse [GDI32.@]
479 * Success: Previous system palette
480 * Failure: SYSPAL_ERROR
482 UINT WINAPI
SetSystemPaletteUse(
483 HDC hdc
, /* [in] Handle of device context */
484 UINT use
) /* [in] Palette-usage flag */
486 UINT old
= SystemPaletteUse
;
487 FIXME("(%04x,%04x): stub\n", hdc
, use
);
488 SystemPaletteUse
= use
;
493 /***********************************************************************
494 * GetSystemPaletteUse (GDI.374)
496 UINT16 WINAPI
GetSystemPaletteUse16( HDC16 hdc
)
498 return SystemPaletteUse
;
502 /***********************************************************************
503 * GetSystemPaletteUse [GDI32.@] Gets state of system palette
506 * Current state of system palette
508 UINT WINAPI
GetSystemPaletteUse(
509 HDC hdc
) /* [in] Handle of device context */
511 return SystemPaletteUse
;
515 /***********************************************************************
516 * GetSystemPaletteEntries (GDI.375)
518 UINT16 WINAPI
GetSystemPaletteEntries16( HDC16 hdc
, UINT16 start
, UINT16 count
,
519 LPPALETTEENTRY entries
)
521 return GetSystemPaletteEntries( hdc
, start
, count
, entries
);
525 /***********************************************************************
526 * GetSystemPaletteEntries [GDI32.@] Gets range of palette entries
529 * Success: Number of entries retrieved from palette
532 UINT WINAPI
GetSystemPaletteEntries(
533 HDC hdc
, /* [in] Handle of device context */
534 UINT start
, /* [in] Index of first entry to be retrieved */
535 UINT count
, /* [in] Number of entries to be retrieved */
536 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
539 INT sizePalette
= GetDeviceCaps( hdc
, SIZEPALETTE
);
541 TRACE("hdc=%04x,start=%i,count=%i\n", hdc
,start
,count
);
543 if (!entries
) return sizePalette
;
544 if (start
>= sizePalette
) return 0;
545 if (start
+count
>= sizePalette
) count
= sizePalette
- start
;
547 for (i
= 0; i
< count
; i
++)
549 *(COLORREF
*)(entries
+ i
) = COLOR_GetSystemPaletteEntry( start
+ i
);
551 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
552 start
+ i
, *(COLORREF
*)(entries
+ i
) );
558 /***********************************************************************
559 * GetNearestPaletteIndex (GDI.370)
561 UINT16 WINAPI
GetNearestPaletteIndex16( HPALETTE16 hpalette
, COLORREF color
)
563 return GetNearestPaletteIndex( hpalette
, color
);
567 /***********************************************************************
568 * GetNearestPaletteIndex [GDI32.@] Gets palette index for color
571 * Should index be initialized to CLR_INVALID instead of 0?
574 * Success: Index of entry in logical palette
575 * Failure: CLR_INVALID
577 UINT WINAPI
GetNearestPaletteIndex(
578 HPALETTE hpalette
, /* [in] Handle of logical color palette */
579 COLORREF color
) /* [in] Color to be matched */
581 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
586 index
= COLOR_PaletteLookupPixel(palObj
->logpalette
.palPalEntry
,
587 palObj
->logpalette
.palNumEntries
,
588 NULL
, color
, FALSE
);
590 GDI_ReleaseObj( hpalette
);
592 TRACE("(%04x,%06lx): returning %d\n", hpalette
, color
, index
);
597 /***********************************************************************
598 * GetNearestColor (GDI.154)
600 COLORREF WINAPI
GetNearestColor16( HDC16 hdc
, COLORREF color
)
602 return GetNearestColor( hdc
, color
);
606 /***********************************************************************
607 * GetNearestColor [GDI32.@] Gets a system color to match
610 * Success: Color from system palette that corresponds to given color
611 * Failure: CLR_INVALID
613 COLORREF WINAPI
GetNearestColor(
614 HDC hdc
, /* [in] Handle of device context */
615 COLORREF color
) /* [in] Color to be matched */
617 COLORREF nearest
= CLR_INVALID
;
621 if ( (dc
= DC_GetDCPtr( hdc
)) )
623 HPALETTE hpal
= (dc
->hPalette
)? dc
->hPalette
: GetStockObject( DEFAULT_PALETTE
);
624 palObj
= GDI_GetObjPtr( hpal
, PALETTE_MAGIC
);
626 GDI_ReleaseObj( hdc
);
630 nearest
= COLOR_LookupNearestColor( palObj
->logpalette
.palPalEntry
,
631 palObj
->logpalette
.palNumEntries
, color
);
632 GDI_ReleaseObj( hpal
);
633 GDI_ReleaseObj( hdc
);
636 TRACE("(%06lx): returning %06lx\n", color
, nearest
);
641 /***********************************************************************
644 int PALETTE_GetObject( PALETTEOBJ
* palette
, int count
, LPSTR buffer
)
646 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
647 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
652 /***********************************************************************
653 * PALETTE_UnrealizeObject
655 BOOL
PALETTE_UnrealizeObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
657 if (palette
->mapping
)
659 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
660 palette
->mapping
= NULL
;
662 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
667 /***********************************************************************
668 * PALETTE_DeleteObject
670 BOOL
PALETTE_DeleteObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
672 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
673 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
674 return GDI_FreeObject( hpalette
, palette
);
678 /***********************************************************************
679 * GDISelectPalette (GDI.361)
681 HPALETTE16 WINAPI
GDISelectPalette16( HDC16 hdc
, HPALETTE16 hpal
, WORD wBkg
)
686 TRACE("%04x %04x\n", hdc
, hpal
);
688 if (GetObjectType(hpal
) != OBJ_PAL
)
690 WARN("invalid selected palette %04x\n",hpal
);
693 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
696 GDI_ReleaseObj( hdc
);
697 if (!wBkg
) hPrimaryPalette
= hpal
;
702 /***********************************************************************
703 * GDIRealizePalette (GDI.362)
705 UINT16 WINAPI
GDIRealizePalette16( HDC16 hdc
)
709 DC
* dc
= DC_GetDCPtr( hdc
);
713 TRACE("%04x...\n", hdc
);
715 if(dc
->hPalette
!= hLastRealizedPalette
)
717 if( dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
)) {
718 realized
= RealizeDefaultPalette16( hdc
);
719 GDI_ReleaseObj( hdc
);
720 return (UINT16
)realized
;
724 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( dc
->hPalette
, PALETTE_MAGIC
);
727 GDI_ReleaseObj( hdc
);
728 FIXME("invalid selected palette %04x\n",dc
->hPalette
);
732 realized
= PALETTE_Driver
->
733 pSetMapping(palPtr
,0,palPtr
->logpalette
.palNumEntries
,
734 (dc
->hPalette
!= hPrimaryPalette
) ||
735 (dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
)));
736 hLastRealizedPalette
= dc
->hPalette
;
737 GDI_ReleaseObj( dc
->hPalette
);
739 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
740 hLastRealizedPalette
);
741 GDI_ReleaseObj( hdc
);
743 TRACE(" realized %i colors.\n", realized
);
744 return (UINT16
)realized
;
748 /***********************************************************************
749 * RealizeDefaultPalette (GDI.365)
751 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
757 TRACE("%04x\n", hdc
);
759 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
761 if (!(dc
->flags
& DC_MEMORY
))
763 palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE
), PALETTE_MAGIC
);
766 /* lookup is needed to account for SetSystemPaletteUse() stuff */
767 ret
= PALETTE_Driver
->pUpdateMapping(palPtr
);
768 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE
) );
771 GDI_ReleaseObj( hdc
);
775 /***********************************************************************
776 * IsDCCurrentPalette (GDI.412)
778 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
780 DC
*dc
= DC_GetDCPtr( hDC
);
783 BOOL bRet
= dc
->hPalette
== hPrimaryPalette
;
784 GDI_ReleaseObj( hDC
);
791 /***********************************************************************
792 * SelectPalette [GDI32.@] Selects logical palette into DC
795 * Success: Previous logical palette
798 HPALETTE WINAPI
SelectPalette(
799 HDC hDC
, /* [in] Handle of device context */
800 HPALETTE hPal
, /* [in] Handle of logical color palette */
801 BOOL bForceBackground
) /* [in] Foreground/background mode */
803 return pfnSelectPalette( hDC
, hPal
, bForceBackground
);
807 /***********************************************************************
808 * RealizePalette [GDI32.@] Maps palette entries to system palette
811 * Success: Number of entries in logical palette
814 UINT WINAPI
RealizePalette(
815 HDC hDC
) /* [in] Handle of device context */
817 return pfnRealizePalette( hDC
);
821 typedef HWND
WINAPI (*WindowFromDC_funcptr
)( HDC
);
822 typedef BOOL
WINAPI (*RedrawWindow_funcptr
)( HWND
, const RECT
*, HRGN
, UINT
);
824 /**********************************************************************
825 * UpdateColors [GDI32.@] Remaps current colors to logical palette
831 BOOL WINAPI
UpdateColors(
832 HDC hDC
) /* [in] Handle of device context */
835 int size
= GetDeviceCaps( hDC
, SIZEPALETTE
);
839 mod
= GetModuleHandleA("user32.dll");
842 WindowFromDC_funcptr pWindowFromDC
= (WindowFromDC_funcptr
)GetProcAddress(mod
,"WindowFromDC");
845 HWND hWnd
= pWindowFromDC( hDC
);
847 /* Docs say that we have to remap current drawable pixel by pixel
848 * but it would take forever given the speed of XGet/PutPixel.
852 RedrawWindow_funcptr pRedrawWindow
= GetProcAddress( mod
, "RedrawWindow" );
853 if (pRedrawWindow
) pRedrawWindow( hWnd
, NULL
, 0, RDW_INVALIDATE
);
861 /**********************************************************************
862 * UpdateColors (GDI.366)
864 INT16 WINAPI
UpdateColors16( HDC16 hDC
)
871 /*********************************************************************
872 * SetMagicColors (GDI.606)
874 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
876 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
880 /**********************************************************************
881 * GetICMProfileA [GDI32.@]
883 * Returns the filename of the specified device context's color
884 * management profile, even if color management is not enabled
888 * TRUE if name copied succesfully OR lpszFilename is NULL
889 * FALSE if the buffer length pointed to by lpcbName is too small
892 * The buffer length pointed to by lpcbName is ALWAYS updated to
893 * the length required regardless of other actions this function
897 * How does Windows assign these? Some registry key?
900 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
902 /*********************************************************************/
904 BOOL WINAPI
GetICMProfileA(HDC hDC
, LPDWORD lpcbName
, LPSTR lpszFilename
)
908 FIXME("(%04x, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
910 callerLen
= *lpcbName
;
912 /* all 3 behaviors require the required buffer size to be set */
913 *lpcbName
= strlen(WINEICM
);
915 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
916 if ((DWORD
)lpszFilename
== (DWORD
)0x00000000)
919 /* behavior 2: if buffer size too small, return size of string and error */
920 if (callerLen
< strlen(WINEICM
))
922 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
926 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
927 strcpy(lpszFilename
, WINEICM
);