4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1996 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
23 * Information in the "Undocumented Windows" is incorrect.
34 #include "wine/winuser16.h"
36 #include "gdi_private.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(palette);
42 static INT PALETTE_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
43 static BOOL PALETTE_UnrealizeObject( HGDIOBJ handle, void *obj );
44 static BOOL PALETTE_DeleteObject( HGDIOBJ handle, void *obj );
46 static const struct gdi_obj_funcs palette_funcs =
48 NULL, /* pSelectObject */
49 PALETTE_GetObject, /* pGetObject16 */
50 PALETTE_GetObject, /* pGetObjectA */
51 PALETTE_GetObject, /* pGetObjectW */
52 PALETTE_UnrealizeObject, /* pUnrealizeObject */
53 PALETTE_DeleteObject /* pDeleteObject */
56 /* Pointers to USER implementation of SelectPalette/RealizePalette */
57 /* they will be patched by USER on startup */
58 HPALETTE (WINAPI *pfnSelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd ) = GDISelectPalette;
59 UINT (WINAPI *pfnRealizePalette)(HDC hdc) = GDIRealizePalette;
61 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
63 static HPALETTE hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
64 static HPALETTE hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
65 static const DC_FUNCTIONS *pLastRealizedDC;
67 static const PALETTEENTRY sys_pal_template[NB_RESERVED_COLORS] =
69 /* first 10 entries in the system palette */
70 /* red green blue flags */
71 { 0x00, 0x00, 0x00, 0 },
72 { 0x80, 0x00, 0x00, 0 },
73 { 0x00, 0x80, 0x00, 0 },
74 { 0x80, 0x80, 0x00, 0 },
75 { 0x00, 0x00, 0x80, 0 },
76 { 0x80, 0x00, 0x80, 0 },
77 { 0x00, 0x80, 0x80, 0 },
78 { 0xc0, 0xc0, 0xc0, 0 },
79 { 0xc0, 0xdc, 0xc0, 0 },
80 { 0xa6, 0xca, 0xf0, 0 },
82 /* ... c_min/2 dynamic colorcells */
84 /* ... gap (for sparse palettes) */
86 /* ... c_min/2 dynamic colorcells */
88 { 0xff, 0xfb, 0xf0, 0 },
89 { 0xa0, 0xa0, 0xa4, 0 },
90 { 0x80, 0x80, 0x80, 0 },
91 { 0xff, 0x00, 0x00, 0 },
92 { 0x00, 0xff, 0x00, 0 },
93 { 0xff, 0xff, 0x00, 0 },
94 { 0x00, 0x00, 0xff, 0 },
95 { 0xff, 0x00, 0xff, 0 },
96 { 0x00, 0xff, 0xff, 0 },
97 { 0xff, 0xff, 0xff, 0 } /* last 10 */
100 /***********************************************************************
103 * Create the system palette.
105 HPALETTE PALETTE_Init(void)
111 /* create default palette (20 system colors) */
113 palPtr = HeapAlloc( GetProcessHeap(), 0,
114 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
115 if (!palPtr) return FALSE;
117 palPtr->palVersion = 0x300;
118 palPtr->palNumEntries = NB_RESERVED_COLORS;
119 memcpy( palPtr->palPalEntry, sys_pal_template, sizeof(sys_pal_template) );
120 hpalette = CreatePalette( palPtr );
121 HeapFree( GetProcessHeap(), 0, palPtr );
123 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
126 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * NB_RESERVED_COLORS )))
127 ERR("Cannot create palette mapping -- out of memory!\n");
128 GDI_ReleaseObj( hpalette );
133 /***********************************************************************
134 * PALETTE_ValidateFlags
136 static void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
139 for( ; i<size ; i++ )
140 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
144 /***********************************************************************
145 * CreatePalette [GDI32.@]
147 * Creates a logical color palette.
150 * Success: Handle to logical palette
153 HPALETTE WINAPI CreatePalette(
154 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
156 PALETTEOBJ * palettePtr;
160 if (!palette) return 0;
161 TRACE("entries=%i\n", palette->palNumEntries);
163 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
165 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
166 PALETTE_MAGIC, (HGDIOBJ *)&hpalette,
167 &palette_funcs ))) return 0;
168 memcpy( &palettePtr->logpalette, palette, size );
169 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
170 palettePtr->logpalette.palNumEntries);
171 palettePtr->mapping = NULL;
172 GDI_ReleaseObj( hpalette );
174 TRACE(" returning %p\n", hpalette);
179 /***********************************************************************
180 * CreateHalftonePalette [GDI32.@]
182 * Creates a halftone palette.
185 * Success: Handle to logical halftone palette
188 * FIXME: This simply creates the halftone palette derived from running
189 * tests on a windows NT machine. This is assuming a color depth
190 * of greater that 256 color. On a 256 color device the halftone
191 * palette will be different and this function will be incorrect
193 HPALETTE WINAPI CreateHalftonePalette(
194 HDC hdc) /* [in] Handle to device context */
199 WORD NumberOfEntries;
200 PALETTEENTRY aEntries[256];
203 Palette.Version = 0x300;
204 Palette.NumberOfEntries = 256;
205 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
207 Palette.NumberOfEntries = 20;
209 for (i = 0; i < Palette.NumberOfEntries; i++)
211 Palette.aEntries[i].peRed=0xff;
212 Palette.aEntries[i].peGreen=0xff;
213 Palette.aEntries[i].peBlue=0xff;
214 Palette.aEntries[i].peFlags=0x00;
217 Palette.aEntries[0].peRed=0x00;
218 Palette.aEntries[0].peBlue=0x00;
219 Palette.aEntries[0].peGreen=0x00;
222 for (i=1; i <= 6; i++)
224 Palette.aEntries[i].peRed=(i%2)?0x80:0;
225 Palette.aEntries[i].peGreen=(i==2)?0x80:(i==3)?0x80:(i==6)?0x80:0;
226 Palette.aEntries[i].peBlue=(i>3)?0x80:0;
229 for (i=7; i <= 12; i++)
234 Palette.aEntries[i].peRed=0xc0;
235 Palette.aEntries[i].peBlue=0xc0;
236 Palette.aEntries[i].peGreen=0xc0;
239 Palette.aEntries[i].peRed=0xc0;
240 Palette.aEntries[i].peGreen=0xdc;
241 Palette.aEntries[i].peBlue=0xc0;
244 Palette.aEntries[i].peRed=0xa6;
245 Palette.aEntries[i].peGreen=0xca;
246 Palette.aEntries[i].peBlue=0xf0;
249 Palette.aEntries[i].peRed=0xff;
250 Palette.aEntries[i].peGreen=0xfb;
251 Palette.aEntries[i].peBlue=0xf0;
254 Palette.aEntries[i].peRed=0xa0;
255 Palette.aEntries[i].peGreen=0xa0;
256 Palette.aEntries[i].peBlue=0xa4;
259 Palette.aEntries[i].peRed=0x80;
260 Palette.aEntries[i].peGreen=0x80;
261 Palette.aEntries[i].peBlue=0x80;
265 for (i=13; i <= 18; i++)
267 Palette.aEntries[i].peRed=(i%2)?0xff:0;
268 Palette.aEntries[i].peGreen=(i==14)?0xff:(i==15)?0xff:(i==18)?0xff:0;
269 Palette.aEntries[i].peBlue=(i>15)?0xff:0x00;
272 return CreatePalette((LOGPALETTE *)&Palette);
276 /***********************************************************************
277 * GetPaletteEntries [GDI32.@]
279 * Retrieves palette entries.
282 * Success: Number of entries from logical palette
285 UINT WINAPI GetPaletteEntries(
286 HPALETTE hpalette, /* [in] Handle of logical palette */
287 UINT start, /* [in] First entry to receive */
288 UINT count, /* [in] Number of entries to receive */
289 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
294 TRACE("hpal = %p, count=%i\n", hpalette, count );
296 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
297 if (!palPtr) return 0;
299 /* NOTE: not documented but test show this to be the case */
302 int rc = palPtr->logpalette.palNumEntries;
303 GDI_ReleaseObj( hpalette );
307 numEntries = palPtr->logpalette.palNumEntries;
308 if (start+count > numEntries) count = numEntries - start;
311 if (start >= numEntries)
313 GDI_ReleaseObj( hpalette );
316 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
317 count * sizeof(PALETTEENTRY) );
318 for( numEntries = 0; numEntries < count ; numEntries++ )
319 if (entries[numEntries].peFlags & 0xF0)
320 entries[numEntries].peFlags = 0;
323 GDI_ReleaseObj( hpalette );
328 /***********************************************************************
329 * SetPaletteEntries [GDI32.@]
331 * Sets color values for range in palette.
334 * Success: Number of entries that were set
337 UINT WINAPI SetPaletteEntries(
338 HPALETTE hpalette, /* [in] Handle of logical palette */
339 UINT start, /* [in] Index of first entry to set */
340 UINT count, /* [in] Number of entries to set */
341 const PALETTEENTRY *entries) /* [in] Address of array of structures */
346 TRACE("hpal=%p,start=%i,count=%i\n",hpalette,start,count );
348 if (hpalette == GetStockObject(DEFAULT_PALETTE)) return 0;
349 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
350 if (!palPtr) return 0;
352 numEntries = palPtr->logpalette.palNumEntries;
353 if (start >= numEntries)
355 GDI_ReleaseObj( hpalette );
358 if (start+count > numEntries) count = numEntries - start;
359 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
360 count * sizeof(PALETTEENTRY) );
361 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
362 palPtr->logpalette.palNumEntries);
363 UnrealizeObject( hpalette );
364 GDI_ReleaseObj( hpalette );
369 /***********************************************************************
370 * ResizePalette [GDI32.@]
372 * Resizes logical palette.
378 BOOL WINAPI ResizePalette(
379 HPALETTE hPal, /* [in] Handle of logical palette */
380 UINT cEntries) /* [in] Number of entries in logical palette */
382 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
383 UINT cPrevEnt, prevVer;
384 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
387 TRACE("hpal = %p, prev = %i, new = %i\n",
388 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1, cEntries );
389 if( !palPtr ) return FALSE;
390 cPrevEnt = palPtr->logpalette.palNumEntries;
391 prevVer = palPtr->logpalette.palVersion;
392 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
393 sizeof(int*) + sizeof(GDIOBJHDR);
394 size += sizeof(int*) + sizeof(GDIOBJHDR);
395 mapping = palPtr->mapping;
397 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
401 int *newMap = HeapReAlloc(GetProcessHeap(), 0, mapping, cEntries * sizeof(int) );
404 ERR("Cannot resize mapping -- out of memory!\n");
405 GDI_ReleaseObj( hPal );
408 palPtr->mapping = newMap;
411 if( cEntries > cPrevEnt )
414 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
415 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
416 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
417 cEntries - cPrevEnt );
419 palPtr->logpalette.palNumEntries = cEntries;
420 palPtr->logpalette.palVersion = prevVer;
421 GDI_ReleaseObj( hPal );
426 /***********************************************************************
427 * AnimatePalette [GDI32.@]
429 * Replaces entries in logical palette.
436 * Should use existing mapping when animating a primary palette
438 BOOL WINAPI AnimatePalette(
439 HPALETTE hPal, /* [in] Handle to logical palette */
440 UINT StartIndex, /* [in] First entry in palette */
441 UINT NumEntries, /* [in] Count of entries in palette */
442 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
444 TRACE("%p (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
446 if( hPal != GetStockObject(DEFAULT_PALETTE) )
450 const PALETTEENTRY *pptr = PaletteColors;
452 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
453 if (!palPtr) return 0;
455 pal_entries = palPtr->logpalette.palNumEntries;
456 if (StartIndex >= pal_entries)
458 GDI_ReleaseObj( hPal );
461 if (StartIndex+NumEntries > pal_entries) NumEntries = pal_entries - StartIndex;
463 for (NumEntries += StartIndex; StartIndex < NumEntries; StartIndex++, pptr++) {
464 /* According to MSDN, only animate PC_RESERVED colours */
465 if (palPtr->logpalette.palPalEntry[StartIndex].peFlags & PC_RESERVED) {
466 TRACE("Animating colour (%d,%d,%d) to (%d,%d,%d)\n",
467 palPtr->logpalette.palPalEntry[StartIndex].peRed,
468 palPtr->logpalette.palPalEntry[StartIndex].peGreen,
469 palPtr->logpalette.palPalEntry[StartIndex].peBlue,
470 pptr->peRed, pptr->peGreen, pptr->peBlue);
471 memcpy( &palPtr->logpalette.palPalEntry[StartIndex], pptr,
472 sizeof(PALETTEENTRY) );
473 PALETTE_ValidateFlags(&palPtr->logpalette.palPalEntry[StartIndex], 1);
475 TRACE("Not animating entry %d -- not PC_RESERVED\n", StartIndex);
479 GDI_ReleaseObj( hPal );
481 TRACE("pLastRealizedDC %p -- pLastRealizedDC->pRealizePalette %p\n",
482 pLastRealizedDC, pLastRealizedDC ? pLastRealizedDC->pRealizePalette : 0);
484 if (pLastRealizedDC && pLastRealizedDC->pRealizePalette)
485 pLastRealizedDC->pRealizePalette( NULL, hPal, hPal == hPrimaryPalette );
491 /***********************************************************************
492 * SetSystemPaletteUse [GDI32.@]
495 * Success: Previous system palette
496 * Failure: SYSPAL_ERROR
498 UINT WINAPI SetSystemPaletteUse(
499 HDC hdc, /* [in] Handle of device context */
500 UINT use) /* [in] Palette-usage flag */
502 UINT old = SystemPaletteUse;
504 /* Device doesn't support colour palettes */
505 if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)) {
510 case SYSPAL_NOSTATIC:
511 case SYSPAL_NOSTATIC256: /* WINVER >= 0x0500 */
513 SystemPaletteUse = use;
521 /***********************************************************************
522 * GetSystemPaletteUse [GDI32.@]
524 * Gets state of system palette.
527 * Current state of system palette
529 UINT WINAPI GetSystemPaletteUse(
530 HDC hdc) /* [in] Handle of device context */
532 return SystemPaletteUse;
536 /***********************************************************************
537 * GetSystemPaletteEntries [GDI32.@]
539 * Gets range of palette entries.
542 * Success: Number of entries retrieved from palette
545 UINT WINAPI GetSystemPaletteEntries(
546 HDC hdc, /* [in] Handle of device context */
547 UINT start, /* [in] Index of first entry to be retrieved */
548 UINT count, /* [in] Number of entries to be retrieved */
549 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
554 TRACE("hdc=%p,start=%i,count=%i\n", hdc,start,count);
556 if ((dc = DC_GetDCPtr( hdc )))
558 if (dc->funcs->pGetSystemPaletteEntries)
559 ret = dc->funcs->pGetSystemPaletteEntries( dc->physDev, start, count, entries );
560 GDI_ReleaseObj( hdc );
566 /***********************************************************************
567 * GetNearestPaletteIndex [GDI32.@]
569 * Gets palette index for color.
572 * Should index be initialized to CLR_INVALID instead of 0?
575 * Success: Index of entry in logical palette
576 * Failure: CLR_INVALID
578 UINT WINAPI GetNearestPaletteIndex(
579 HPALETTE hpalette, /* [in] Handle of logical color palette */
580 COLORREF color) /* [in] Color to be matched */
582 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
587 int i, diff = 0x7fffffff;
589 PALETTEENTRY* entry = palObj->logpalette.palPalEntry;
591 for( i = 0; i < palObj->logpalette.palNumEntries && diff ; i++, entry++)
593 if (!(entry->peFlags & PC_SYS_USED)) continue;
595 r = entry->peRed - GetRValue(color);
596 g = entry->peGreen - GetGValue(color);
597 b = entry->peBlue - GetBValue(color);
601 if( r < diff ) { index = i; diff = r; }
603 GDI_ReleaseObj( hpalette );
605 TRACE("(%p,%06lx): returning %d\n", hpalette, color, index );
610 /***********************************************************************
611 * GetNearestColor [GDI32.@]
613 * Gets a system color to match.
616 * Success: Color from system palette that corresponds to given color
617 * Failure: CLR_INVALID
619 COLORREF WINAPI GetNearestColor(
620 HDC hdc, /* [in] Handle of device context */
621 COLORREF color) /* [in] Color to be matched */
623 unsigned char spec_type;
627 if (!(dc = DC_GetDCPtr( hdc ))) return CLR_INVALID;
629 if (dc->funcs->pGetNearestColor)
631 nearest = dc->funcs->pGetNearestColor( dc->physDev, color );
632 GDI_ReleaseObj( hdc );
636 if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE))
638 GDI_ReleaseObj( hdc );
642 spec_type = color >> 24;
643 if (spec_type == 1 || spec_type == 2)
645 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
649 HPALETTE hpal = dc->hPalette ? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
651 if (spec_type == 2) /* PALETTERGB */
652 index = GetNearestPaletteIndex( hpal, color );
653 else /* PALETTEINDEX */
654 index = LOWORD(color);
656 if (!GetPaletteEntries( hpal, index, 1, &entry ))
658 WARN("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color, index );
659 if (!GetPaletteEntries( hpal, 0, 1, &entry ))
661 GDI_ReleaseObj( hdc );
665 color = RGB( entry.peRed, entry.peGreen, entry.peBlue );
667 nearest = color & 0x00ffffff;
668 GDI_ReleaseObj( hdc );
670 TRACE("(%06lx): returning %06lx\n", color, nearest );
675 /***********************************************************************
678 static INT PALETTE_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
680 PALETTEOBJ *palette = obj;
685 if (count > sizeof(WORD)) count = sizeof(WORD);
686 memcpy( buffer, &palette->logpalette.palNumEntries, count );
691 /***********************************************************************
692 * PALETTE_UnrealizeObject
694 static BOOL PALETTE_UnrealizeObject( HGDIOBJ handle, void *obj )
696 PALETTEOBJ *palette = obj;
698 HeapFree( GetProcessHeap(), 0, palette->mapping );
699 palette->mapping = NULL;
701 if (hLastRealizedPalette == handle)
703 TRACE("unrealizing palette %p\n", handle);
704 hLastRealizedPalette = 0;
705 pLastRealizedDC = NULL;
711 /***********************************************************************
712 * PALETTE_DeleteObject
714 static BOOL PALETTE_DeleteObject( HGDIOBJ handle, void *obj )
716 PALETTEOBJ *palette = obj;
718 HeapFree( GetProcessHeap(), 0, palette->mapping );
719 if (hLastRealizedPalette == handle)
721 TRACE("unrealizing palette %p\n", handle);
722 hLastRealizedPalette = 0;
723 pLastRealizedDC = NULL;
725 return GDI_FreeObject( handle, obj );
729 /***********************************************************************
730 * GDISelectPalette (Not a Windows API)
732 HPALETTE WINAPI GDISelectPalette( HDC hdc, HPALETTE hpal, WORD wBkg)
737 TRACE("%p %p\n", hdc, hpal );
739 if (GetObjectType(hpal) != OBJ_PAL)
741 WARN("invalid selected palette %p\n",hpal);
744 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
746 if (dc->funcs->pSelectPalette) hpal = dc->funcs->pSelectPalette( dc->physDev, hpal, FALSE );
750 if (!wBkg) hPrimaryPalette = hpal;
753 GDI_ReleaseObj( hdc );
758 /***********************************************************************
759 * GDIRealizePalette (Not a Windows API)
761 UINT WINAPI GDIRealizePalette( HDC hdc )
764 DC* dc = DC_GetDCPtr( hdc );
768 TRACE("%p...\n", hdc );
770 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE ))
772 if (dc->funcs->pRealizeDefaultPalette)
773 realized = dc->funcs->pRealizeDefaultPalette( dc->physDev );
775 else if(dc->hPalette != hLastRealizedPalette )
777 if (dc->funcs->pRealizePalette)
778 realized = dc->funcs->pRealizePalette( dc->physDev, dc->hPalette,
779 (dc->hPalette == hPrimaryPalette) );
780 hLastRealizedPalette = dc->hPalette;
781 pLastRealizedDC = dc->funcs;
783 else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette);
785 GDI_ReleaseObj( hdc );
786 TRACE(" realized %i colors.\n", realized );
791 /***********************************************************************
792 * RealizeDefaultPalette (GDI.365)
794 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
799 TRACE("%04x\n", hdc );
801 if (!(dc = DC_GetDCPtr( HDC_32(hdc) ))) return 0;
803 if (dc->funcs->pRealizeDefaultPalette) ret = dc->funcs->pRealizeDefaultPalette( dc->physDev );
804 GDI_ReleaseObj( HDC_32(hdc) );
808 /***********************************************************************
809 * IsDCCurrentPalette (GDI.412)
811 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
813 DC *dc = DC_GetDCPtr( HDC_32(hDC) );
816 BOOL bRet = dc->hPalette == hPrimaryPalette;
817 GDI_ReleaseObj( HDC_32(hDC) );
824 /***********************************************************************
825 * SelectPalette [GDI32.@]
827 * Selects logical palette into DC.
830 * Success: Previous logical palette
833 HPALETTE WINAPI SelectPalette(
834 HDC hDC, /* [in] Handle of device context */
835 HPALETTE hPal, /* [in] Handle of logical color palette */
836 BOOL bForceBackground) /* [in] Foreground/background mode */
838 return pfnSelectPalette( hDC, hPal, bForceBackground );
842 /***********************************************************************
843 * RealizePalette [GDI32.@]
845 * Maps palette entries to system palette.
848 * Success: Number of entries in logical palette
851 UINT WINAPI RealizePalette(
852 HDC hDC) /* [in] Handle of device context */
854 return pfnRealizePalette( hDC );
858 typedef HWND (WINAPI *WindowFromDC_funcptr)( HDC );
859 typedef BOOL (WINAPI *RedrawWindow_funcptr)( HWND, const RECT *, HRGN, UINT );
861 /**********************************************************************
862 * UpdateColors [GDI32.@]
864 * Remaps current colors to logical palette.
870 BOOL WINAPI UpdateColors(
871 HDC hDC) /* [in] Handle of device context */
874 int size = GetDeviceCaps( hDC, SIZEPALETTE );
878 mod = GetModuleHandleA("user32.dll");
881 WindowFromDC_funcptr pWindowFromDC = (WindowFromDC_funcptr)GetProcAddress(mod,"WindowFromDC");
884 HWND hWnd = pWindowFromDC( hDC );
886 /* Docs say that we have to remap current drawable pixel by pixel
887 * but it would take forever given the speed of XGet/PutPixel.
891 RedrawWindow_funcptr pRedrawWindow = GetProcAddress( mod, "RedrawWindow" );
892 if (pRedrawWindow) pRedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
900 /*********************************************************************
901 * SetMagicColors (GDI.606)
903 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
905 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
909 /**********************************************************************
910 * GetICMProfileA [GDI32.@]
912 * Returns the filename of the specified device context's color
913 * management profile, even if color management is not enabled
917 * TRUE if name copied successfully OR lpszFilename is NULL
918 * FALSE if the buffer length pointed to by lpcbName is too small
921 * The buffer length pointed to by lpcbName is ALWAYS updated to
922 * the length required regardless of other actions this function
926 * How does Windows assign these? Some registry key?
930 /*********************************************************************/
932 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
935 static const char icm[] = "winefake.icm";
937 FIXME("(%p, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
939 callerLen = *lpcbName;
941 /* all 3 behaviors require the required buffer size to be set */
942 *lpcbName = sizeof(icm);
944 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
945 if (!lpszFilename) return TRUE;
947 /* behavior 2: if buffer size too small, return size of string and error */
948 if (callerLen < sizeof(icm))
950 SetLastError(ERROR_INSUFFICIENT_BUFFER);
954 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
955 memcpy(lpszFilename, icm, sizeof(icm));
959 /**********************************************************************
960 * GetICMProfileW [GDI32.@]
962 BOOL WINAPI GetICMProfileW(HDC hDC, LPDWORD lpcbName, LPWSTR lpszFilename)
965 static const WCHAR icm[] = { 'w','i','n','e','f','a','k','e','.','i','c','m', 0 };
967 FIXME("(%p, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
969 callerLen = *lpcbName;
971 /* all 3 behaviors require the required buffer size to be set */
972 *lpcbName = sizeof(icm) / sizeof(WCHAR);
974 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
975 if (!lpszFilename) return TRUE;
977 /* behavior 2: if buffer size too small, return size of string and error */
978 if (callerLen < sizeof(icm)/sizeof(WCHAR))
980 SetLastError(ERROR_INSUFFICIENT_BUFFER);
984 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
985 memcpy(lpszFilename, icm, sizeof(icm));
989 /**********************************************************************
990 * GetLogColorSpaceA [GDI32.@]
993 BOOL WINAPI GetLogColorSpaceA(HCOLORSPACE hColorSpace, LPLOGCOLORSPACEA lpBuffer, DWORD nSize)
995 FIXME("%p %p 0x%08lx: stub!\n", hColorSpace, lpBuffer, nSize);
999 /**********************************************************************
1000 * GetLogColorSpaceW [GDI32.@]
1003 BOOL WINAPI GetLogColorSpaceW(HCOLORSPACE hColorSpace, LPLOGCOLORSPACEW lpBuffer, DWORD nSize)
1005 FIXME("%p %p 0x%08lx: stub!\n", hColorSpace, lpBuffer, nSize);
1009 /**********************************************************************
1010 * SetICMProfileA [GDI32.@]
1013 BOOL WINAPI SetICMProfileA(HDC hDC, LPSTR lpszFilename)
1015 FIXME("hDC %p filename '%s': stub!\n", hDC, debugstr_a(lpszFilename));
1016 return TRUE; /* success */
1019 /**********************************************************************
1020 * SetICMProfileA [GDI32.@]
1023 BOOL WINAPI SetICMProfileW(HDC hDC, LPWSTR lpszFilename)
1025 FIXME("hDC %p filename '%s': stub!\n", hDC, debugstr_w(lpszFilename));
1026 return TRUE; /* success */
1029 /**********************************************************************
1030 * UpdateICMRegKeyA [GDI32.@]
1033 BOOL WINAPI UpdateICMRegKeyA(DWORD dwReserved, LPSTR lpszCMID, LPSTR lpszFileName, UINT nCommand)
1035 FIXME("(0x%08lx, %s, %s, 0x%08x): stub!\n", dwReserved, debugstr_a(lpszCMID),
1036 debugstr_a(lpszFileName), nCommand);
1037 return TRUE; /* success */
1040 /**********************************************************************
1041 * UpdateICMRegKeyW [GDI32.@]
1044 BOOL WINAPI UpdateICMRegKeyW(DWORD dwReserved, LPWSTR lpszCMID, LPWSTR lpszFileName, UINT nCommand)
1046 FIXME("(0x%08lx, %s, %s, 0x%08x): stub!\n", dwReserved, debugstr_w(lpszCMID),
1047 debugstr_w(lpszFileName), nCommand);
1048 return TRUE; /* success */