2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI Palette Functions
5 * FILE: subsys/win32k/eng/palette.c
6 * PROGRAMERS: Jason Filby
15 static UINT SystemPaletteUse
= SYSPAL_NOSTATIC
; /* the program need save the pallete and restore it */
17 PALETTE gpalRGB
, gpalBGR
, gpalMono
;
19 const PALETTEENTRY g_sysPalTemplate
[NB_RESERVED_COLORS
] =
21 // first 10 entries in the system palette
22 // red green blue flags
23 { 0x00, 0x00, 0x00, PC_SYS_USED
},
24 { 0x80, 0x00, 0x00, PC_SYS_USED
},
25 { 0x00, 0x80, 0x00, PC_SYS_USED
},
26 { 0x80, 0x80, 0x00, PC_SYS_USED
},
27 { 0x00, 0x00, 0x80, PC_SYS_USED
},
28 { 0x80, 0x00, 0x80, PC_SYS_USED
},
29 { 0x00, 0x80, 0x80, PC_SYS_USED
},
30 { 0xc0, 0xc0, 0xc0, PC_SYS_USED
},
31 { 0xc0, 0xdc, 0xc0, PC_SYS_USED
},
32 { 0xa6, 0xca, 0xf0, PC_SYS_USED
},
34 // ... c_min/2 dynamic colorcells
35 // ... gap (for sparse palettes)
36 // ... c_min/2 dynamic colorcells
38 { 0xff, 0xfb, 0xf0, PC_SYS_USED
},
39 { 0xa0, 0xa0, 0xa4, PC_SYS_USED
},
40 { 0x80, 0x80, 0x80, PC_SYS_USED
},
41 { 0xff, 0x00, 0x00, PC_SYS_USED
},
42 { 0x00, 0xff, 0x00, PC_SYS_USED
},
43 { 0xff, 0xff, 0x00, PC_SYS_USED
},
44 { 0x00, 0x00, 0xff, PC_SYS_USED
},
45 { 0xff, 0x00, 0xff, PC_SYS_USED
},
46 { 0x00, 0xff, 0xff, PC_SYS_USED
},
47 { 0xff, 0xff, 0xff, PC_SYS_USED
} // last 10
50 unsigned short GetNumberOfBits(unsigned int dwMask
)
53 for (wBits
= 0; dwMask
; dwMask
= dwMask
& (dwMask
- 1))
58 // Create the system palette
59 HPALETTE FASTCALL
PALETTE_Init(VOID
)
68 // create default palette (20 system colors)
69 palPtr
= ExAllocatePoolWithTag(PagedPool
,
71 (NB_RESERVED_COLORS
* sizeof(PALETTEENTRY
)),
73 if (!palPtr
) return FALSE
;
75 palPtr
->palVersion
= 0x300;
76 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
77 for (i
=0; i
<NB_RESERVED_COLORS
; i
++)
79 palPtr
->palPalEntry
[i
].peRed
= g_sysPalTemplate
[i
].peRed
;
80 palPtr
->palPalEntry
[i
].peGreen
= g_sysPalTemplate
[i
].peGreen
;
81 palPtr
->palPalEntry
[i
].peBlue
= g_sysPalTemplate
[i
].peBlue
;
82 palPtr
->palPalEntry
[i
].peFlags
= 0;
85 hpalette
= NtGdiCreatePaletteInternal(palPtr
,NB_RESERVED_COLORS
);
86 ExFreePoolWithTag(palPtr
, TAG_PALETTE
);
89 palObj
= (PALOBJ
*)PALETTE_LockPalette(hpalette
);
92 if (!(palObj
->mapping
= ExAllocatePool(PagedPool
, sizeof(int) * 20)))
94 DbgPrint("Win32k: Can not create palette mapping -- out of memory!");
97 PALETTE_UnlockPalette(palObj
);
101 /* palette_size = visual->map_entries; */
103 gpalRGB
.Mode
= PAL_RGB
;
104 gpalRGB
.RedMask
= RGB(0xFF, 0x00, 0x00);
105 gpalRGB
.GreenMask
= RGB(0x00, 0xFF, 0x00);
106 gpalRGB
.BlueMask
= RGB(0x00, 0x00, 0xFF);
108 gpalBGR
.Mode
= PAL_BGR
;
109 gpalBGR
.RedMask
= RGB(0x00, 0x00, 0xFF);
110 gpalBGR
.GreenMask
= RGB(0x00, 0xFF, 0x00);
111 gpalBGR
.BlueMask
= RGB(0xFF, 0x00, 0x00);
113 memset(&gpalMono
, 0, sizeof(PALETTE
));
114 gpalMono
.Mode
= PAL_MONOCHROME
;
119 VOID FASTCALL
PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, INT size
)
123 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
128 PALETTE_AllocPalette(ULONG Mode
,
138 PalGDI
= (PPALETTE
)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_PALETTE
);
144 NewPalette
= PalGDI
->BaseObject
.hHmgr
;
146 PalGDI
->Self
= NewPalette
;
151 PalGDI
->IndexedColors
= ExAllocatePoolWithTag(PagedPool
,
152 sizeof(PALETTEENTRY
) * NumColors
,
154 if (NULL
== PalGDI
->IndexedColors
)
156 PALETTE_UnlockPalette(PalGDI
);
157 PALETTE_FreePaletteByHandle(NewPalette
);
160 RtlCopyMemory(PalGDI
->IndexedColors
, Colors
, sizeof(PALETTEENTRY
) * NumColors
);
163 if (PAL_INDEXED
== Mode
)
165 PalGDI
->NumColors
= NumColors
;
167 else if (PAL_BITFIELDS
== Mode
)
169 PalGDI
->RedMask
= Red
;
170 PalGDI
->GreenMask
= Green
;
171 PalGDI
->BlueMask
= Blue
;
173 if (Red
== 0x7c00 && Green
== 0x3E0 && Blue
== 0x1F)
174 PalGDI
->Mode
|= PAL_RGB16_555
;
175 else if (Red
== 0xF800 && Green
== 0x7E0 && Blue
== 0x1F)
176 PalGDI
->Mode
|= PAL_RGB16_565
;
179 PALETTE_UnlockPalette(PalGDI
);
186 PALETTE_AllocPaletteIndexedRGB(ULONG NumColors
,
187 CONST RGBQUAD
*Colors
)
193 PalGDI
= (PPALETTE
)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_PALETTE
);
199 NewPalette
= PalGDI
->BaseObject
.hHmgr
;
201 PalGDI
->Self
= NewPalette
;
202 PalGDI
->Mode
= PAL_INDEXED
;
204 PalGDI
->IndexedColors
= ExAllocatePoolWithTag(PagedPool
,
205 sizeof(PALETTEENTRY
) * NumColors
,
207 if (NULL
== PalGDI
->IndexedColors
)
209 PALETTE_UnlockPalette(PalGDI
);
210 PALETTE_FreePaletteByHandle(NewPalette
);
214 for (i
= 0; i
< NumColors
; i
++)
216 PalGDI
->IndexedColors
[i
].peRed
= Colors
[i
].rgbRed
;
217 PalGDI
->IndexedColors
[i
].peGreen
= Colors
[i
].rgbGreen
;
218 PalGDI
->IndexedColors
[i
].peBlue
= Colors
[i
].rgbBlue
;
219 PalGDI
->IndexedColors
[i
].peFlags
= 0;
222 PalGDI
->NumColors
= NumColors
;
224 PALETTE_UnlockPalette(PalGDI
);
230 PALETTE_Cleanup(PVOID ObjectBody
)
232 PPALETTE pPal
= (PPALETTE
)ObjectBody
;
233 if (NULL
!= pPal
->IndexedColors
)
235 ExFreePool(pPal
->IndexedColors
);
242 PALETTE_GetObject(PPALETTE ppal
, INT cbCount
, LPLOGBRUSH lpBuffer
)
249 if ((UINT
)cbCount
< sizeof(WORD
)) return 0;
250 *((WORD
*)lpBuffer
) = (WORD
)ppal
->NumColors
;
256 PALETTE_ulGetNearestPaletteIndex(PALETTE
* ppal
, ULONG iColor
)
258 ULONG ulDiff
, ulColorDiff
, ulMinimalDiff
= 0xFFFFFF;
259 ULONG i
, ulBestIndex
= 0;
260 PALETTEENTRY peColor
= *(PPALETTEENTRY
)&iColor
;
262 /* Loop all palette entries, break on exact match */
263 for (i
= 0; i
< ppal
->NumColors
&& ulMinimalDiff
!= 0; i
++)
265 /* Calculate distance in the color cube */
266 ulDiff
= peColor
.peRed
- ppal
->IndexedColors
[i
].peRed
;
267 ulColorDiff
= ulDiff
* ulDiff
;
268 ulDiff
= peColor
.peGreen
- ppal
->IndexedColors
[i
].peGreen
;
269 ulColorDiff
+= ulDiff
* ulDiff
;
270 ulDiff
= peColor
.peBlue
- ppal
->IndexedColors
[i
].peBlue
;
271 ulColorDiff
+= ulDiff
* ulDiff
;
273 /* Check for a better match */
274 if (ulColorDiff
< ulMinimalDiff
)
277 ulMinimalDiff
= ulColorDiff
;
286 PALETTE_ulGetNearestBitFieldsIndex(PALETTE
* ppal
, ULONG ulColor
)
290 // FIXME: HACK, should be stored already
291 ppal
->ulRedShift
= CalculateShift(RGB(0xff,0,0), ppal
->RedMask
);
292 ppal
->ulGreenShift
= CalculateShift(RGB(0,0xff,0), ppal
->GreenMask
);
293 ppal
->ulBlueShift
= CalculateShift(RGB(0,0,0xff), ppal
->BlueMask
);
295 ulNewColor
= _rotl(ulColor
, ppal
->ulRedShift
) & ppal
->RedMask
;
296 ulNewColor
|= _rotl(ulColor
, ppal
->ulGreenShift
) & ppal
->GreenMask
;
297 ulNewColor
|= _rotl(ulColor
, ppal
->ulBlueShift
) & ppal
->BlueMask
;
304 PALETTE_ulGetNearestIndex(PALETTE
* ppal
, ULONG ulColor
)
306 if (ppal
->Mode
& PAL_INDEXED
) // use fl & PALINDEXED
307 return PALETTE_ulGetNearestPaletteIndex(ppal
, ulColor
);
309 return PALETTE_ulGetNearestBitFieldsIndex(ppal
, ulColor
);
314 PALETTE_vGetBitMasks(PPALETTE ppal
, PULONG pulColors
)
318 if (ppal
->Mode
& PAL_INDEXED
|| ppal
->Mode
& PAL_RGB
)
320 pulColors
[0] = RGB(0xFF, 0x00, 0x00);
321 pulColors
[1] = RGB(0x00, 0xFF, 0x00);
322 pulColors
[2] = RGB(0x00, 0x00, 0xFF);
324 else if (ppal
->Mode
& PAL_BGR
)
326 pulColors
[0] = RGB(0x00, 0x00, 0xFF);
327 pulColors
[1] = RGB(0x00, 0xFF, 0x00);
328 pulColors
[2] = RGB(0xFF, 0x00, 0x00);
330 else if (ppal
->Mode
& PAL_BITFIELDS
)
332 pulColors
[0] = ppal
->RedMask
;
333 pulColors
[1] = ppal
->GreenMask
;
334 pulColors
[2] = ppal
->BlueMask
;
340 ColorCorrection(PPALETTE PalGDI
, PPALETTEENTRY PaletteEntry
, ULONG Colors
)
342 PPDEVOBJ ppdev
= (PPDEVOBJ
)PalGDI
->hPDev
;
346 if (ppdev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
349 PGAMMARAMP GammaRamp
= (PGAMMARAMP
)ppdev
->pvGammaRamp
;
350 for ( i
= 0; i
< Colors
; i
++)
352 PaletteEntry
[i
].peRed
+= GammaRamp
->Red
[i
];
353 PaletteEntry
[i
].peGreen
+= GammaRamp
->Green
[i
];
354 PaletteEntry
[i
].peBlue
+= GammaRamp
->Blue
[i
];
360 /** Display Driver Interface **************************************************/
377 Palette
= PALETTE_AllocPalette(Mode
, NumColors
, Colors
, Red
, Green
, Blue
);
380 GDIOBJ_SetOwnership(Palette
, NULL
);
391 EngDeletePalette(IN HPALETTE Palette
)
393 GDIOBJ_SetOwnership(Palette
, PsGetCurrentProcess());
395 return PALETTE_FreePaletteByHandle(Palette
);
403 PALOBJ_cGetColors(PALOBJ
*PalObj
, ULONG Start
, ULONG Colors
, ULONG
*PaletteEntry
)
407 PalGDI
= (PALETTE
*)PalObj
;
408 /* PalGDI = (PALETTE*)AccessInternalObjectFromUserObject(PalObj); */
410 if (Start
>= PalGDI
->NumColors
)
413 Colors
= min(Colors
, PalGDI
->NumColors
- Start
);
415 /* NOTE: PaletteEntry ULONGs are in the same order as PALETTEENTRY. */
416 RtlCopyMemory(PaletteEntry
, PalGDI
->IndexedColors
+ Start
, sizeof(ULONG
) * Colors
);
418 if (PalGDI
->Mode
& PAL_GAMMACORRECTION
)
419 ColorCorrection(PalGDI
, (PPALETTEENTRY
)PaletteEntry
, Colors
);
425 /** Systemcall Interface ******************************************************/
431 NtGdiCreatePaletteInternal ( IN LPLOGPALETTE pLogPal
, IN UINT cEntries
)
436 pLogPal
->palNumEntries
= cEntries
;
437 NewPalette
= PALETTE_AllocPalette( PAL_INDEXED
,
439 (PULONG
)pLogPal
->palPalEntry
,
442 if (NewPalette
== NULL
)
447 PalGDI
= (PPALETTE
) PALETTE_LockPalette(NewPalette
);
450 PALETTE_ValidateFlags(PalGDI
->IndexedColors
, PalGDI
->NumColors
);
451 PALETTE_UnlockPalette(PalGDI
);
455 /* FIXME - Handle PalGDI == NULL!!!! */
456 DPRINT1("waring PalGDI is NULL \n");
461 HPALETTE APIENTRY
NtGdiCreateHalftonePalette(HDC hDC
)
466 WORD NumberOfEntries
;
467 PALETTEENTRY aEntries
[256];
470 Palette
.Version
= 0x300;
471 Palette
.NumberOfEntries
= 256;
472 if (IntGetSystemPaletteEntries(hDC
, 0, 256, Palette
.aEntries
) == 0)
474 /* from wine, more that 256 color math */
475 Palette
.NumberOfEntries
= 20;
476 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
478 Palette
.aEntries
[i
].peRed
=0xff;
479 Palette
.aEntries
[i
].peGreen
=0xff;
480 Palette
.aEntries
[i
].peBlue
=0xff;
481 Palette
.aEntries
[i
].peFlags
=0x00;
484 Palette
.aEntries
[0].peRed
=0x00;
485 Palette
.aEntries
[0].peBlue
=0x00;
486 Palette
.aEntries
[0].peGreen
=0x00;
489 for (i
=1; i
<= 6; i
++)
491 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
492 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
493 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
496 for (i
=7; i
<= 12; i
++)
501 Palette
.aEntries
[i
].peRed
=0xc0;
502 Palette
.aEntries
[i
].peBlue
=0xc0;
503 Palette
.aEntries
[i
].peGreen
=0xc0;
506 Palette
.aEntries
[i
].peRed
=0xc0;
507 Palette
.aEntries
[i
].peGreen
=0xdc;
508 Palette
.aEntries
[i
].peBlue
=0xc0;
511 Palette
.aEntries
[i
].peRed
=0xa6;
512 Palette
.aEntries
[i
].peGreen
=0xca;
513 Palette
.aEntries
[i
].peBlue
=0xf0;
516 Palette
.aEntries
[i
].peRed
=0xff;
517 Palette
.aEntries
[i
].peGreen
=0xfb;
518 Palette
.aEntries
[i
].peBlue
=0xf0;
521 Palette
.aEntries
[i
].peRed
=0xa0;
522 Palette
.aEntries
[i
].peGreen
=0xa0;
523 Palette
.aEntries
[i
].peBlue
=0xa4;
526 Palette
.aEntries
[i
].peRed
=0x80;
527 Palette
.aEntries
[i
].peGreen
=0x80;
528 Palette
.aEntries
[i
].peBlue
=0x80;
532 for (i
=13; i
<= 18; i
++)
534 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
535 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
536 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
541 /* 256 color table */
542 for (r
= 0; r
< 6; r
++)
543 for (g
= 0; g
< 6; g
++)
544 for (b
= 0; b
< 6; b
++)
546 i
= r
+ g
*6 + b
*36 + 10;
547 Palette
.aEntries
[i
].peRed
= r
* 51;
548 Palette
.aEntries
[i
].peGreen
= g
* 51;
549 Palette
.aEntries
[i
].peBlue
= b
* 51;
552 for (i
= 216; i
< 246; i
++)
554 int v
= (i
- 216) << 3;
555 Palette
.aEntries
[i
].peRed
= v
;
556 Palette
.aEntries
[i
].peGreen
= v
;
557 Palette
.aEntries
[i
].peBlue
= v
;
561 return NtGdiCreatePaletteInternal((LOGPALETTE
*)&Palette
, Palette
.NumberOfEntries
);
570 /* PALOBJ *palPtr = (PALOBJ*)AccessUserObject(hPal);
571 UINT cPrevEnt, prevVer;
572 INT prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
573 XLATEOBJ *XlateObj = NULL;
575 if(!palPtr) return FALSE;
576 cPrevEnt = palPtr->logpalette->palNumEntries;
577 prevVer = palPtr->logpalette->palVersion;
578 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) + sizeof(int*) + sizeof(GDIOBJHDR);
579 size += sizeof(int*) + sizeof(GDIOBJHDR);
580 XlateObj = palPtr->logicalToSystem;
582 if (!(palPtr = GDI_ReallocObject(size, hPal, palPtr))) return FALSE;
586 XLATEOBJ *NewXlateObj = (int*) HeapReAlloc(GetProcessHeap(), 0, XlateObj, cEntries * sizeof(int));
587 if(NewXlateObj == NULL)
589 ERR("Can not resize logicalToSystem -- out of memory!");
590 GDI_ReleaseObj( hPal );
593 palPtr->logicalToSystem = NewXlateObj;
596 if(cEntries > cPrevEnt)
598 if(XlateObj) memset(palPtr->logicalToSystem + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
599 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
600 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize), cEntries - cPrevEnt );
602 palPtr->logpalette->palNumEntries = cEntries;
603 palPtr->logpalette->palVersion = prevVer;
604 // GDI_ReleaseObj( hPal );
613 NtGdiGetColorAdjustment(
615 LPCOLORADJUSTMENT pca
)
623 NtGdiSetColorAdjustment(
625 LPCOLORADJUSTMENT pca
)
631 COLORREF APIENTRY
NtGdiGetNearestColor(HDC hDC
, COLORREF Color
)
633 COLORREF nearest
= CLR_INVALID
;
636 LONG RBits
, GBits
, BBits
;
641 HPALETTE hpal
= dc
->dclevel
.hpal
;
642 palGDI
= (PPALETTE
) PALETTE_LockPalette(hpal
);
649 if (palGDI
->Mode
& PAL_INDEXED
)
652 index
= PALETTE_ulGetNearestPaletteIndex(palGDI
, Color
);
653 nearest
= PALETTE_ulGetRGBColorFromIndex(palGDI
, index
);
655 else if (palGDI
->Mode
& PAL_RGB
|| palGDI
->Mode
& PAL_BGR
)
659 else if (palGDI
->Mode
& PAL_BITFIELDS
)
661 RBits
= 8 - GetNumberOfBits(palGDI
->RedMask
);
662 GBits
= 8 - GetNumberOfBits(palGDI
->GreenMask
);
663 BBits
= 8 - GetNumberOfBits(palGDI
->BlueMask
);
665 (GetRValue(Color
) >> RBits
) << RBits
,
666 (GetGValue(Color
) >> GBits
) << GBits
,
667 (GetBValue(Color
) >> BBits
) << BBits
);
669 PALETTE_UnlockPalette(palGDI
);
678 NtGdiGetNearestPaletteIndex(
682 PPALETTE ppal
= (PPALETTE
) PALETTE_LockPalette(hpal
);
687 if (ppal
->Mode
& PAL_INDEXED
)
689 /* Return closest match for the given RGB color */
690 index
= PALETTE_ulGetNearestPaletteIndex(ppal
, crColor
);
692 // else SetLastError ?
693 PALETTE_UnlockPalette(ppal
);
701 IntGdiRealizePalette(HDC hDC
)
704 * This function doesn't do any real work now and there's plenty
708 PPALETTE palGDI
, sysGDI
;
711 HPALETTE systemPalette
;
712 USHORT sysMode
, palMode
;
717 systemPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
718 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
722 DPRINT1("IntGdiRealizePalette(): palGDI is NULL, exiting\n");
727 sysGDI
= PALETTE_LockPalette(systemPalette
);
731 DPRINT1("IntGdiRealizePalette(): sysGDI is NULL, exiting\n");
732 PALETTE_UnlockPalette(palGDI
);
737 // The RealizePalette function modifies the palette for the device associated with the specified device context. If the
738 // device context is a memory DC, the color table for the bitmap selected into the DC is modified. If the device
739 // context is a display DC, the physical palette for that device is modified.
740 if(dc
->dctype
== DC_TYPE_MEMORY
)
743 DPRINT1("RealizePalette unimplemented for memory managed DCs\n");
746 DPRINT1("RealizePalette unimplemented for device DCs\n");
749 // need to pass this to IntEngCreateXlate with palettes unlocked
750 sysMode
= sysGDI
->Mode
;
751 palMode
= palGDI
->Mode
;
752 PALETTE_UnlockPalette(sysGDI
);
753 PALETTE_UnlockPalette(palGDI
);
761 IntAnimatePalette(HPALETTE hPal
,
764 CONST PPALETTEENTRY PaletteColors
)
768 if( hPal
!= NtGdiGetStockObject(DEFAULT_PALETTE
) )
775 const PALETTEENTRY
*pptr
= PaletteColors
;
777 palPtr
= (PPALETTE
)PALETTE_LockPalette(hPal
);
778 if (!palPtr
) return FALSE
;
780 pal_entries
= palPtr
->NumColors
;
781 if (StartIndex
>= pal_entries
)
783 PALETTE_UnlockPalette(palPtr
);
786 if (StartIndex
+NumEntries
> pal_entries
) NumEntries
= pal_entries
- StartIndex
;
788 for (NumEntries
+= StartIndex
; StartIndex
< NumEntries
; StartIndex
++, pptr
++)
790 /* According to MSDN, only animate PC_RESERVED colours */
791 if (palPtr
->IndexedColors
[StartIndex
].peFlags
& PC_RESERVED
)
793 memcpy( &palPtr
->IndexedColors
[StartIndex
], pptr
,
794 sizeof(PALETTEENTRY
) );
796 PALETTE_ValidateFlags(&palPtr
->IndexedColors
[StartIndex
], 1);
800 PALETTE_UnlockPalette(palPtr
);
802 /* Immediately apply the new palette if current window uses it */
803 Wnd
= UserGetDesktopWindow();
804 hDC
= UserGetWindowDC(Wnd
);
808 if (dc
->dclevel
.hpal
== hPal
)
811 IntGdiRealizePalette(hDC
);
816 UserReleaseDC(Wnd
,hDC
, FALSE
);
822 IntGetPaletteEntries(
831 palGDI
= (PPALETTE
) PALETTE_LockPalette(hpal
);
837 numEntries
= palGDI
->NumColors
;
840 if (numEntries
< StartIndex
+ Entries
)
842 Entries
= numEntries
- StartIndex
;
844 if (numEntries
<= StartIndex
)
846 PALETTE_UnlockPalette(palGDI
);
849 memcpy(pe
, palGDI
->IndexedColors
+ StartIndex
, Entries
* sizeof(PALETTEENTRY
));
853 Entries
= numEntries
;
856 PALETTE_UnlockPalette(palGDI
);
861 IntGetSystemPaletteEntries(HDC hDC
,
866 PPALETTE palGDI
= NULL
;
868 UINT EntriesSize
= 0;
873 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
879 EntriesSize
= Entries
* sizeof(pe
[0]);
880 if (Entries
!= EntriesSize
/ sizeof(pe
[0]))
882 /* Integer overflow! */
883 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
888 if (!(dc
= DC_LockDc(hDC
)))
890 SetLastWin32Error(ERROR_INVALID_HANDLE
);
894 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
899 if (StartIndex
>= palGDI
->NumColors
)
901 else if (Entries
> palGDI
->NumColors
- StartIndex
)
902 Entries
= palGDI
->NumColors
- StartIndex
;
905 palGDI
->IndexedColors
+ StartIndex
,
906 Entries
* sizeof(pe
[0]));
912 Ret
= dc
->ppdev
->gdiinfo
.ulNumPalReg
;
917 PALETTE_UnlockPalette(palGDI
);
927 IntSetPaletteEntries(
931 CONST LPPALETTEENTRY pe
)
936 if ((UINT
)hpal
& GDI_HANDLE_STOCK_MASK
)
941 palGDI
= PALETTE_LockPalette(hpal
);
942 if (!palGDI
) return 0;
944 numEntries
= palGDI
->NumColors
;
945 if (Start
>= numEntries
)
947 PALETTE_UnlockPalette(palGDI
);
950 if (numEntries
< Start
+ Entries
)
952 Entries
= numEntries
- Start
;
954 memcpy(palGDI
->IndexedColors
+ Start
, pe
, Entries
* sizeof(PALETTEENTRY
));
955 PALETTE_UnlockPalette(palGDI
);
967 IN LPVOID pUnsafeEntries
,
972 LPVOID pEntries
= NULL
;
974 /* FIXME: Handle bInbound correctly */
977 (pUnsafeEntries
== NULL
|| cEntries
== 0))
984 pEntries
= ExAllocatePool(PagedPool
, cEntries
* sizeof(PALETTEENTRY
));
991 ProbeForRead(pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
), 1);
992 memcpy(pEntries
, pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
));
994 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
996 ExFreePool(pEntries
);
997 _SEH2_YIELD(return 0);
1008 ret
= IntAnimatePalette((HPALETTE
)hObj
, iStart
, cEntries
, (CONST PPALETTEENTRY
)pEntries
);
1011 case GdiPalSetEntries
:
1013 ret
= IntSetPaletteEntries((HPALETTE
)hObj
, iStart
, cEntries
, (CONST LPPALETTEENTRY
)pEntries
);
1016 case GdiPalGetEntries
:
1017 ret
= IntGetPaletteEntries((HPALETTE
)hObj
, iStart
, cEntries
, (LPPALETTEENTRY
)pEntries
);
1020 case GdiPalGetSystemEntries
:
1021 ret
= IntGetSystemPaletteEntries((HDC
)hObj
, iStart
, cEntries
, (LPPALETTEENTRY
)pEntries
);
1024 case GdiPalSetColorTable
:
1026 ret
= IntSetDIBColorTable((HDC
)hObj
, iStart
, cEntries
, (RGBQUAD
*)pEntries
);
1029 case GdiPalGetColorTable
:
1031 ret
= IntGetDIBColorTable((HDC
)hObj
, iStart
, cEntries
, (RGBQUAD
*)pEntries
);
1041 ProbeForWrite(pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
), 1);
1042 memcpy(pUnsafeEntries
, pEntries
, cEntries
* sizeof(PALETTEENTRY
));
1044 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1050 ExFreePool(pEntries
);
1057 NtGdiSetSystemPaletteUse(HDC hDC
, UINT Usage
)
1059 UINT old
= SystemPaletteUse
;
1061 /* Device doesn't support colour palettes */
1062 if (!(NtGdiGetDeviceCaps(hDC
, RASTERCAPS
) & RC_PALETTE
)) {
1063 return SYSPAL_ERROR
;
1068 case SYSPAL_NOSTATIC
:
1069 case SYSPAL_NOSTATIC256
:
1071 SystemPaletteUse
= Usage
;
1084 NtGdiGetSystemPaletteUse(HDC hDC
)
1086 return SystemPaletteUse
;
1091 NtGdiUpdateColors(HDC hDC
)
1094 BOOL calledFromUser
, ret
;
1095 USER_REFERENCE_ENTRY Ref
;
1097 calledFromUser
= UserIsEntered();
1099 if (!calledFromUser
){
1100 UserEnterExclusive();
1103 Wnd
= UserGetWindowObject(IntWindowFromDC(hDC
));
1106 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1108 if (!calledFromUser
){
1115 UserRefObjectCo(Wnd
, &Ref
);
1116 ret
= co_UserRedrawWindow(Wnd
, NULL
, 0, RDW_INVALIDATE
);
1117 UserDerefObjectCo(Wnd
);
1119 if (!calledFromUser
){
1128 NtGdiUnrealizeObject(HGDIOBJ hgdiobj
)
1134 ((UINT
)hgdiobj
& GDI_HANDLE_STOCK_MASK
) ||
1135 !GDI_HANDLE_IS_TYPE(hgdiobj
, GDI_OBJECT_TYPE_PALETTE
) )
1138 palGDI
= PALETTE_LockPalette(hgdiobj
);
1139 if (!palGDI
) return FALSE
;
1142 // Need to do something!!!
1143 // Zero out Current and Old Translated pointers?
1146 PALETTE_UnlockPalette(palGDI
);