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
)
65 // create default palette (20 system colors)
66 palPtr
= ExAllocatePoolWithTag(PagedPool
,
68 (NB_RESERVED_COLORS
* sizeof(PALETTEENTRY
)),
70 if (!palPtr
) return FALSE
;
72 palPtr
->palVersion
= 0x300;
73 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
74 for (i
=0; i
<NB_RESERVED_COLORS
; i
++)
76 palPtr
->palPalEntry
[i
].peRed
= g_sysPalTemplate
[i
].peRed
;
77 palPtr
->palPalEntry
[i
].peGreen
= g_sysPalTemplate
[i
].peGreen
;
78 palPtr
->palPalEntry
[i
].peBlue
= g_sysPalTemplate
[i
].peBlue
;
79 palPtr
->palPalEntry
[i
].peFlags
= 0;
82 hpalette
= NtGdiCreatePaletteInternal(palPtr
,NB_RESERVED_COLORS
);
83 ExFreePoolWithTag(palPtr
, TAG_PALETTE
);
85 /* palette_size = visual->map_entries; */
87 gpalRGB
.Mode
= PAL_RGB
;
88 gpalRGB
.RedMask
= RGB(0xFF, 0x00, 0x00);
89 gpalRGB
.GreenMask
= RGB(0x00, 0xFF, 0x00);
90 gpalRGB
.BlueMask
= RGB(0x00, 0x00, 0xFF);
92 gpalBGR
.Mode
= PAL_BGR
;
93 gpalBGR
.RedMask
= RGB(0x00, 0x00, 0xFF);
94 gpalBGR
.GreenMask
= RGB(0x00, 0xFF, 0x00);
95 gpalBGR
.BlueMask
= RGB(0xFF, 0x00, 0x00);
97 memset(&gpalMono
, 0, sizeof(PALETTE
));
98 gpalMono
.Mode
= PAL_MONOCHROME
;
103 VOID FASTCALL
PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, INT size
)
107 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
112 PALETTE_AllocPalette(ULONG Mode
,
122 PalGDI
= (PPALETTE
)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_PALETTE
);
128 NewPalette
= PalGDI
->BaseObject
.hHmgr
;
130 PalGDI
->Self
= NewPalette
;
135 PalGDI
->IndexedColors
= ExAllocatePoolWithTag(PagedPool
,
136 sizeof(PALETTEENTRY
) * NumColors
,
138 if (NULL
== PalGDI
->IndexedColors
)
140 PALETTE_UnlockPalette(PalGDI
);
141 PALETTE_FreePaletteByHandle(NewPalette
);
144 RtlCopyMemory(PalGDI
->IndexedColors
, Colors
, sizeof(PALETTEENTRY
) * NumColors
);
147 if (PAL_INDEXED
== Mode
)
149 PalGDI
->NumColors
= NumColors
;
151 else if (PAL_BITFIELDS
== Mode
)
153 PalGDI
->RedMask
= Red
;
154 PalGDI
->GreenMask
= Green
;
155 PalGDI
->BlueMask
= Blue
;
157 if (Red
== 0x7c00 && Green
== 0x3E0 && Blue
== 0x1F)
158 PalGDI
->Mode
|= PAL_RGB16_555
;
159 else if (Red
== 0xF800 && Green
== 0x7E0 && Blue
== 0x1F)
160 PalGDI
->Mode
|= PAL_RGB16_565
;
163 PALETTE_UnlockPalette(PalGDI
);
170 PALETTE_AllocPaletteIndexedRGB(ULONG NumColors
,
171 CONST RGBQUAD
*Colors
)
177 PalGDI
= (PPALETTE
)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_PALETTE
);
183 NewPalette
= PalGDI
->BaseObject
.hHmgr
;
185 PalGDI
->Self
= NewPalette
;
186 PalGDI
->Mode
= PAL_INDEXED
;
188 PalGDI
->IndexedColors
= ExAllocatePoolWithTag(PagedPool
,
189 sizeof(PALETTEENTRY
) * NumColors
,
191 if (NULL
== PalGDI
->IndexedColors
)
193 PALETTE_UnlockPalette(PalGDI
);
194 PALETTE_FreePaletteByHandle(NewPalette
);
198 for (i
= 0; i
< NumColors
; i
++)
200 PalGDI
->IndexedColors
[i
].peRed
= Colors
[i
].rgbRed
;
201 PalGDI
->IndexedColors
[i
].peGreen
= Colors
[i
].rgbGreen
;
202 PalGDI
->IndexedColors
[i
].peBlue
= Colors
[i
].rgbBlue
;
203 PalGDI
->IndexedColors
[i
].peFlags
= 0;
206 PalGDI
->NumColors
= NumColors
;
208 PALETTE_UnlockPalette(PalGDI
);
214 PALETTE_Cleanup(PVOID ObjectBody
)
216 PPALETTE pPal
= (PPALETTE
)ObjectBody
;
217 if (NULL
!= pPal
->IndexedColors
)
219 ExFreePoolWithTag(pPal
->IndexedColors
, TAG_PALETTE
);
226 PALETTE_GetObject(PPALETTE ppal
, INT cbCount
, LPLOGBRUSH lpBuffer
)
233 if ((UINT
)cbCount
< sizeof(WORD
)) return 0;
234 *((WORD
*)lpBuffer
) = (WORD
)ppal
->NumColors
;
240 PALETTE_ulGetNearestPaletteIndex(PALETTE
* ppal
, ULONG iColor
)
242 ULONG ulDiff
, ulColorDiff
, ulMinimalDiff
= 0xFFFFFF;
243 ULONG i
, ulBestIndex
= 0;
244 PALETTEENTRY peColor
= *(PPALETTEENTRY
)&iColor
;
246 /* Loop all palette entries, break on exact match */
247 for (i
= 0; i
< ppal
->NumColors
&& ulMinimalDiff
!= 0; i
++)
249 /* Calculate distance in the color cube */
250 ulDiff
= peColor
.peRed
- ppal
->IndexedColors
[i
].peRed
;
251 ulColorDiff
= ulDiff
* ulDiff
;
252 ulDiff
= peColor
.peGreen
- ppal
->IndexedColors
[i
].peGreen
;
253 ulColorDiff
+= ulDiff
* ulDiff
;
254 ulDiff
= peColor
.peBlue
- ppal
->IndexedColors
[i
].peBlue
;
255 ulColorDiff
+= ulDiff
* ulDiff
;
257 /* Check for a better match */
258 if (ulColorDiff
< ulMinimalDiff
)
261 ulMinimalDiff
= ulColorDiff
;
270 PALETTE_ulGetNearestBitFieldsIndex(PALETTE
* ppal
, ULONG ulColor
)
274 // FIXME: HACK, should be stored already
275 ppal
->ulRedShift
= CalculateShift(RGB(0xff,0,0), ppal
->RedMask
);
276 ppal
->ulGreenShift
= CalculateShift(RGB(0,0xff,0), ppal
->GreenMask
);
277 ppal
->ulBlueShift
= CalculateShift(RGB(0,0,0xff), ppal
->BlueMask
);
279 ulNewColor
= _rotl(ulColor
, ppal
->ulRedShift
) & ppal
->RedMask
;
280 ulNewColor
|= _rotl(ulColor
, ppal
->ulGreenShift
) & ppal
->GreenMask
;
281 ulNewColor
|= _rotl(ulColor
, ppal
->ulBlueShift
) & ppal
->BlueMask
;
288 PALETTE_ulGetNearestIndex(PALETTE
* ppal
, ULONG ulColor
)
290 if (ppal
->Mode
& PAL_INDEXED
) // use fl & PALINDEXED
291 return PALETTE_ulGetNearestPaletteIndex(ppal
, ulColor
);
293 return PALETTE_ulGetNearestBitFieldsIndex(ppal
, ulColor
);
298 PALETTE_vGetBitMasks(PPALETTE ppal
, PULONG pulColors
)
302 if (ppal
->Mode
& PAL_INDEXED
|| ppal
->Mode
& PAL_RGB
)
304 pulColors
[0] = RGB(0xFF, 0x00, 0x00);
305 pulColors
[1] = RGB(0x00, 0xFF, 0x00);
306 pulColors
[2] = RGB(0x00, 0x00, 0xFF);
308 else if (ppal
->Mode
& PAL_BGR
)
310 pulColors
[0] = RGB(0x00, 0x00, 0xFF);
311 pulColors
[1] = RGB(0x00, 0xFF, 0x00);
312 pulColors
[2] = RGB(0xFF, 0x00, 0x00);
314 else if (ppal
->Mode
& PAL_BITFIELDS
)
316 pulColors
[0] = ppal
->RedMask
;
317 pulColors
[1] = ppal
->GreenMask
;
318 pulColors
[2] = ppal
->BlueMask
;
324 ColorCorrection(PPALETTE PalGDI
, PPALETTEENTRY PaletteEntry
, ULONG Colors
)
326 PPDEVOBJ ppdev
= (PPDEVOBJ
)PalGDI
->hPDev
;
330 if (ppdev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
333 PGAMMARAMP GammaRamp
= (PGAMMARAMP
)ppdev
->pvGammaRamp
;
334 for ( i
= 0; i
< Colors
; i
++)
336 PaletteEntry
[i
].peRed
+= GammaRamp
->Red
[i
];
337 PaletteEntry
[i
].peGreen
+= GammaRamp
->Green
[i
];
338 PaletteEntry
[i
].peBlue
+= GammaRamp
->Blue
[i
];
344 /** Display Driver Interface **************************************************/
361 Palette
= PALETTE_AllocPalette(Mode
, NumColors
, Colors
, Red
, Green
, Blue
);
364 GDIOBJ_SetOwnership(Palette
, NULL
);
375 EngDeletePalette(IN HPALETTE Palette
)
377 GDIOBJ_SetOwnership(Palette
, PsGetCurrentProcess());
379 return PALETTE_FreePaletteByHandle(Palette
);
387 PALOBJ_cGetColors(PALOBJ
*PalObj
, ULONG Start
, ULONG Colors
, ULONG
*PaletteEntry
)
391 PalGDI
= (PALETTE
*)PalObj
;
392 /* PalGDI = (PALETTE*)AccessInternalObjectFromUserObject(PalObj); */
394 if (Start
>= PalGDI
->NumColors
)
397 Colors
= min(Colors
, PalGDI
->NumColors
- Start
);
399 /* NOTE: PaletteEntry ULONGs are in the same order as PALETTEENTRY. */
400 RtlCopyMemory(PaletteEntry
, PalGDI
->IndexedColors
+ Start
, sizeof(ULONG
) * Colors
);
402 if (PalGDI
->Mode
& PAL_GAMMACORRECTION
)
403 ColorCorrection(PalGDI
, (PPALETTEENTRY
)PaletteEntry
, Colors
);
409 /** Systemcall Interface ******************************************************/
415 NtGdiCreatePaletteInternal ( IN LPLOGPALETTE pLogPal
, IN UINT cEntries
)
420 pLogPal
->palNumEntries
= cEntries
;
421 NewPalette
= PALETTE_AllocPalette( PAL_INDEXED
,
423 (PULONG
)pLogPal
->palPalEntry
,
426 if (NewPalette
== NULL
)
431 PalGDI
= (PPALETTE
) PALETTE_LockPalette(NewPalette
);
434 PALETTE_ValidateFlags(PalGDI
->IndexedColors
, PalGDI
->NumColors
);
435 PALETTE_UnlockPalette(PalGDI
);
439 /* FIXME - Handle PalGDI == NULL!!!! */
440 DPRINT1("PalGDI is NULL\n");
445 HPALETTE APIENTRY
NtGdiCreateHalftonePalette(HDC hDC
)
450 WORD NumberOfEntries
;
451 PALETTEENTRY aEntries
[256];
454 Palette
.Version
= 0x300;
455 Palette
.NumberOfEntries
= 256;
456 if (IntGetSystemPaletteEntries(hDC
, 0, 256, Palette
.aEntries
) == 0)
458 /* from wine, more that 256 color math */
459 Palette
.NumberOfEntries
= 20;
460 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
462 Palette
.aEntries
[i
].peRed
=0xff;
463 Palette
.aEntries
[i
].peGreen
=0xff;
464 Palette
.aEntries
[i
].peBlue
=0xff;
465 Palette
.aEntries
[i
].peFlags
=0x00;
468 Palette
.aEntries
[0].peRed
=0x00;
469 Palette
.aEntries
[0].peBlue
=0x00;
470 Palette
.aEntries
[0].peGreen
=0x00;
473 for (i
=1; i
<= 6; i
++)
475 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
476 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
477 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
480 for (i
=7; i
<= 12; i
++)
485 Palette
.aEntries
[i
].peRed
=0xc0;
486 Palette
.aEntries
[i
].peBlue
=0xc0;
487 Palette
.aEntries
[i
].peGreen
=0xc0;
490 Palette
.aEntries
[i
].peRed
=0xc0;
491 Palette
.aEntries
[i
].peGreen
=0xdc;
492 Palette
.aEntries
[i
].peBlue
=0xc0;
495 Palette
.aEntries
[i
].peRed
=0xa6;
496 Palette
.aEntries
[i
].peGreen
=0xca;
497 Palette
.aEntries
[i
].peBlue
=0xf0;
500 Palette
.aEntries
[i
].peRed
=0xff;
501 Palette
.aEntries
[i
].peGreen
=0xfb;
502 Palette
.aEntries
[i
].peBlue
=0xf0;
505 Palette
.aEntries
[i
].peRed
=0xa0;
506 Palette
.aEntries
[i
].peGreen
=0xa0;
507 Palette
.aEntries
[i
].peBlue
=0xa4;
510 Palette
.aEntries
[i
].peRed
=0x80;
511 Palette
.aEntries
[i
].peGreen
=0x80;
512 Palette
.aEntries
[i
].peBlue
=0x80;
516 for (i
=13; i
<= 18; i
++)
518 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
519 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
520 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
525 /* 256 color table */
526 for (r
= 0; r
< 6; r
++)
527 for (g
= 0; g
< 6; g
++)
528 for (b
= 0; b
< 6; b
++)
530 i
= r
+ g
*6 + b
*36 + 10;
531 Palette
.aEntries
[i
].peRed
= r
* 51;
532 Palette
.aEntries
[i
].peGreen
= g
* 51;
533 Palette
.aEntries
[i
].peBlue
= b
* 51;
536 for (i
= 216; i
< 246; i
++)
538 int v
= (i
- 216) << 3;
539 Palette
.aEntries
[i
].peRed
= v
;
540 Palette
.aEntries
[i
].peGreen
= v
;
541 Palette
.aEntries
[i
].peBlue
= v
;
545 return NtGdiCreatePaletteInternal((LOGPALETTE
*)&Palette
, Palette
.NumberOfEntries
);
554 /* PALOBJ *palPtr = (PALOBJ*)AccessUserObject(hPal);
555 UINT cPrevEnt, prevVer;
556 INT prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
557 XLATEOBJ *XlateObj = NULL;
559 if(!palPtr) return FALSE;
560 cPrevEnt = palPtr->logpalette->palNumEntries;
561 prevVer = palPtr->logpalette->palVersion;
562 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) + sizeof(int*) + sizeof(GDIOBJHDR);
563 size += sizeof(int*) + sizeof(GDIOBJHDR);
564 XlateObj = palPtr->logicalToSystem;
566 if (!(palPtr = GDI_ReallocObject(size, hPal, palPtr))) return FALSE;
570 XLATEOBJ *NewXlateObj = (int*) HeapReAlloc(GetProcessHeap(), 0, XlateObj, cEntries * sizeof(int));
571 if(NewXlateObj == NULL)
573 ERR("Can not resize logicalToSystem -- out of memory!");
574 GDI_ReleaseObj( hPal );
577 palPtr->logicalToSystem = NewXlateObj;
580 if(cEntries > cPrevEnt)
582 if(XlateObj) memset(palPtr->logicalToSystem + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
583 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
584 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize), cEntries - cPrevEnt );
586 palPtr->logpalette->palNumEntries = cEntries;
587 palPtr->logpalette->palVersion = prevVer;
588 // GDI_ReleaseObj( hPal );
597 NtGdiGetColorAdjustment(
599 LPCOLORADJUSTMENT pca
)
607 NtGdiSetColorAdjustment(
609 LPCOLORADJUSTMENT pca
)
615 COLORREF APIENTRY
NtGdiGetNearestColor(HDC hDC
, COLORREF Color
)
617 COLORREF nearest
= CLR_INVALID
;
620 LONG RBits
, GBits
, BBits
;
625 HPALETTE hpal
= dc
->dclevel
.hpal
;
626 palGDI
= (PPALETTE
) PALETTE_LockPalette(hpal
);
633 if (palGDI
->Mode
& PAL_INDEXED
)
636 index
= PALETTE_ulGetNearestPaletteIndex(palGDI
, Color
);
637 nearest
= PALETTE_ulGetRGBColorFromIndex(palGDI
, index
);
639 else if (palGDI
->Mode
& PAL_RGB
|| palGDI
->Mode
& PAL_BGR
)
643 else if (palGDI
->Mode
& PAL_BITFIELDS
)
645 RBits
= 8 - GetNumberOfBits(palGDI
->RedMask
);
646 GBits
= 8 - GetNumberOfBits(palGDI
->GreenMask
);
647 BBits
= 8 - GetNumberOfBits(palGDI
->BlueMask
);
649 (GetRValue(Color
) >> RBits
) << RBits
,
650 (GetGValue(Color
) >> GBits
) << GBits
,
651 (GetBValue(Color
) >> BBits
) << BBits
);
653 PALETTE_UnlockPalette(palGDI
);
662 NtGdiGetNearestPaletteIndex(
666 PPALETTE ppal
= (PPALETTE
) PALETTE_LockPalette(hpal
);
671 if (ppal
->Mode
& PAL_INDEXED
)
673 /* Return closest match for the given RGB color */
674 index
= PALETTE_ulGetNearestPaletteIndex(ppal
, crColor
);
676 // else SetLastError ?
677 PALETTE_UnlockPalette(ppal
);
685 IntGdiRealizePalette(HDC hDC
)
688 * This function doesn't do any real work now and there's plenty
692 PPALETTE palGDI
, sysGDI
;
695 HPALETTE systemPalette
;
700 systemPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
701 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
705 DPRINT1("IntGdiRealizePalette(): palGDI is NULL, exiting\n");
710 sysGDI
= PALETTE_LockPalette(systemPalette
);
714 DPRINT1("IntGdiRealizePalette(): sysGDI is NULL, exiting\n");
715 PALETTE_UnlockPalette(palGDI
);
720 // The RealizePalette function modifies the palette for the device associated with the specified device context. If the
721 // device context is a memory DC, the color table for the bitmap selected into the DC is modified. If the device
722 // context is a display DC, the physical palette for that device is modified.
723 if(dc
->dctype
== DC_TYPE_MEMORY
)
726 DPRINT1("RealizePalette unimplemented for memory managed DCs\n");
729 DPRINT1("RealizePalette unimplemented for device DCs\n");
732 // need to pass this to IntEngCreateXlate with palettes unlocked
733 PALETTE_UnlockPalette(sysGDI
);
734 PALETTE_UnlockPalette(palGDI
);
742 IntAnimatePalette(HPALETTE hPal
,
745 CONST PPALETTEENTRY PaletteColors
)
749 if( hPal
!= NtGdiGetStockObject(DEFAULT_PALETTE
) )
756 const PALETTEENTRY
*pptr
= PaletteColors
;
758 palPtr
= (PPALETTE
)PALETTE_LockPalette(hPal
);
759 if (!palPtr
) return FALSE
;
761 pal_entries
= palPtr
->NumColors
;
762 if (StartIndex
>= pal_entries
)
764 PALETTE_UnlockPalette(palPtr
);
767 if (StartIndex
+NumEntries
> pal_entries
) NumEntries
= pal_entries
- StartIndex
;
769 for (NumEntries
+= StartIndex
; StartIndex
< NumEntries
; StartIndex
++, pptr
++)
771 /* According to MSDN, only animate PC_RESERVED colours */
772 if (palPtr
->IndexedColors
[StartIndex
].peFlags
& PC_RESERVED
)
774 memcpy( &palPtr
->IndexedColors
[StartIndex
], pptr
,
775 sizeof(PALETTEENTRY
) );
777 PALETTE_ValidateFlags(&palPtr
->IndexedColors
[StartIndex
], 1);
781 PALETTE_UnlockPalette(palPtr
);
783 /* Immediately apply the new palette if current window uses it */
784 Wnd
= UserGetDesktopWindow();
785 hDC
= UserGetWindowDC(Wnd
);
789 if (dc
->dclevel
.hpal
== hPal
)
792 IntGdiRealizePalette(hDC
);
797 UserReleaseDC(Wnd
,hDC
, FALSE
);
803 IntGetPaletteEntries(
812 palGDI
= (PPALETTE
) PALETTE_LockPalette(hpal
);
818 numEntries
= palGDI
->NumColors
;
821 if (numEntries
< StartIndex
+ Entries
)
823 Entries
= numEntries
- StartIndex
;
825 if (numEntries
<= StartIndex
)
827 PALETTE_UnlockPalette(palGDI
);
830 memcpy(pe
, palGDI
->IndexedColors
+ StartIndex
, Entries
* sizeof(PALETTEENTRY
));
834 Entries
= numEntries
;
837 PALETTE_UnlockPalette(palGDI
);
842 IntGetSystemPaletteEntries(HDC hDC
,
847 PPALETTE palGDI
= NULL
;
849 UINT EntriesSize
= 0;
854 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
860 EntriesSize
= Entries
* sizeof(pe
[0]);
861 if (Entries
!= EntriesSize
/ sizeof(pe
[0]))
863 /* Integer overflow! */
864 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
869 if (!(dc
= DC_LockDc(hDC
)))
871 SetLastWin32Error(ERROR_INVALID_HANDLE
);
875 palGDI
= PALETTE_LockPalette(dc
->dclevel
.hpal
);
880 if (StartIndex
>= palGDI
->NumColors
)
882 else if (Entries
> palGDI
->NumColors
- StartIndex
)
883 Entries
= palGDI
->NumColors
- StartIndex
;
886 palGDI
->IndexedColors
+ StartIndex
,
887 Entries
* sizeof(pe
[0]));
893 Ret
= dc
->ppdev
->gdiinfo
.ulNumPalReg
;
898 PALETTE_UnlockPalette(palGDI
);
908 IntSetPaletteEntries(
912 CONST LPPALETTEENTRY pe
)
917 if ((UINT
)hpal
& GDI_HANDLE_STOCK_MASK
)
922 palGDI
= PALETTE_LockPalette(hpal
);
923 if (!palGDI
) return 0;
925 numEntries
= palGDI
->NumColors
;
926 if (Start
>= numEntries
)
928 PALETTE_UnlockPalette(palGDI
);
931 if (numEntries
< Start
+ Entries
)
933 Entries
= numEntries
- Start
;
935 memcpy(palGDI
->IndexedColors
+ Start
, pe
, Entries
* sizeof(PALETTEENTRY
));
936 PALETTE_UnlockPalette(palGDI
);
948 IN LPVOID pUnsafeEntries
,
953 LPVOID pEntries
= NULL
;
955 /* FIXME: Handle bInbound correctly */
958 (pUnsafeEntries
== NULL
|| cEntries
== 0))
965 pEntries
= ExAllocatePoolWithTag(PagedPool
, cEntries
* sizeof(PALETTEENTRY
), TAG_PALETTE
);
972 ProbeForRead(pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
), 1);
973 memcpy(pEntries
, pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
));
975 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
977 ExFreePoolWithTag(pEntries
, TAG_PALETTE
);
978 _SEH2_YIELD(return 0);
989 ret
= IntAnimatePalette((HPALETTE
)hObj
, iStart
, cEntries
, (CONST PPALETTEENTRY
)pEntries
);
992 case GdiPalSetEntries
:
994 ret
= IntSetPaletteEntries((HPALETTE
)hObj
, iStart
, cEntries
, (CONST LPPALETTEENTRY
)pEntries
);
997 case GdiPalGetEntries
:
998 ret
= IntGetPaletteEntries((HPALETTE
)hObj
, iStart
, cEntries
, (LPPALETTEENTRY
)pEntries
);
1001 case GdiPalGetSystemEntries
:
1002 ret
= IntGetSystemPaletteEntries((HDC
)hObj
, iStart
, cEntries
, (LPPALETTEENTRY
)pEntries
);
1005 case GdiPalSetColorTable
:
1007 ret
= IntSetDIBColorTable((HDC
)hObj
, iStart
, cEntries
, (RGBQUAD
*)pEntries
);
1010 case GdiPalGetColorTable
:
1012 ret
= IntGetDIBColorTable((HDC
)hObj
, iStart
, cEntries
, (RGBQUAD
*)pEntries
);
1022 ProbeForWrite(pUnsafeEntries
, cEntries
* sizeof(PALETTEENTRY
), 1);
1023 memcpy(pUnsafeEntries
, pEntries
, cEntries
* sizeof(PALETTEENTRY
));
1025 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1031 ExFreePoolWithTag(pEntries
, TAG_PALETTE
);
1038 NtGdiSetSystemPaletteUse(HDC hDC
, UINT Usage
)
1040 UINT old
= SystemPaletteUse
;
1042 /* Device doesn't support colour palettes */
1043 if (!(NtGdiGetDeviceCaps(hDC
, RASTERCAPS
) & RC_PALETTE
)) {
1044 return SYSPAL_ERROR
;
1049 case SYSPAL_NOSTATIC
:
1050 case SYSPAL_NOSTATIC256
:
1052 SystemPaletteUse
= Usage
;
1065 NtGdiGetSystemPaletteUse(HDC hDC
)
1067 return SystemPaletteUse
;
1072 NtGdiUpdateColors(HDC hDC
)
1075 BOOL calledFromUser
, ret
;
1076 USER_REFERENCE_ENTRY Ref
;
1078 calledFromUser
= UserIsEntered();
1080 if (!calledFromUser
){
1081 UserEnterExclusive();
1084 Wnd
= UserGetWindowObject(IntWindowFromDC(hDC
));
1087 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1089 if (!calledFromUser
){
1096 UserRefObjectCo(Wnd
, &Ref
);
1097 ret
= co_UserRedrawWindow(Wnd
, NULL
, 0, RDW_INVALIDATE
);
1098 UserDerefObjectCo(Wnd
);
1100 if (!calledFromUser
){
1109 NtGdiUnrealizeObject(HGDIOBJ hgdiobj
)
1115 ((UINT
)hgdiobj
& GDI_HANDLE_STOCK_MASK
) ||
1116 !GDI_HANDLE_IS_TYPE(hgdiobj
, GDI_OBJECT_TYPE_PALETTE
) )
1119 palGDI
= PALETTE_LockPalette(hgdiobj
);
1120 if (!palGDI
) return FALSE
;
1123 // Need to do something!!!
1124 // Zero out Current and Old Translated pointers?
1127 PALETTE_UnlockPalette(palGDI
);