ReactOS 0.4.16-dev-2207-geb15453
palette.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for palette.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define PAL_SETPOWNER   0x8000
 
#define MAX_PALCOLORS   65536
 

Functions

unsigned short GetNumberOfBits (unsigned int dwMask)
 
NTSTATUS NTAPI InitPaletteImpl (VOID)
 
VOID FASTCALL PALETTE_ValidateFlags (PALETTEENTRY *lpPalE, INT size)
 
PPALETTE NTAPI PALETTE_AllocPalette (_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
 
PPALETTE NTAPI PALETTE_AllocPalWithHandle (_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
 
VOID NTAPI PALETTE_vCleanup (PVOID ObjectBody)
 
INT FASTCALL PALETTE_GetObject (PPALETTE ppal, INT cbCount, LPLOGBRUSH lpBuffer)
 
ULONG NTAPI PALETTE_ulGetNearestPaletteIndex (PALETTE *ppal, ULONG iColor)
 
ULONG NTAPI PALETTE_ulGetNearestBitFieldsIndex (PALETTE *ppal, ULONG ulColor)
 
ULONG NTAPI PALETTE_ulGetNearestIndex (PALETTE *ppal, ULONG ulColor)
 
VOID NTAPI PALETTE_vGetBitMasks (PPALETTE ppal, PULONG pulColors)
 
VOID FASTCALL ColorCorrection (PPALETTE PalGDI, PPALETTEENTRY PaletteEntry, ULONG Colors)
 
HPALETTE APIENTRY EngCreatePalette (ULONG iMode, ULONG cColors, ULONG *pulColors, ULONG flRed, ULONG flGreen, ULONG flBlue)
 
BOOL APIENTRY EngDeletePalette (IN HPALETTE hpal)
 
ULONG APIENTRY PALOBJ_cGetColors (PALOBJ *PalObj, ULONG Start, ULONG Colors, ULONG *PaletteEntry)
 
HPALETTE NTAPI GreCreatePaletteInternal (IN LPLOGPALETTE pLogPal, IN UINT cEntries)
 
HPALETTE APIENTRY NtGdiCreatePaletteInternal (IN LPLOGPALETTE plogpalUser, IN UINT cEntries)
 
HPALETTE APIENTRY NtGdiCreateHalftonePalette (HDC hDC)
 
BOOL APIENTRY NtGdiResizePalette (HPALETTE hpal, UINT Entries)
 
BOOL APIENTRY NtGdiGetColorAdjustment (HDC hdc, LPCOLORADJUSTMENT pca)
 
BOOL APIENTRY NtGdiSetColorAdjustment (HDC hdc, LPCOLORADJUSTMENT pca)
 
COLORREF APIENTRY NtGdiGetNearestColor (_In_ HDC hDC, _In_ COLORREF Color)
 
UINT APIENTRY NtGdiGetNearestPaletteIndex (HPALETTE hpal, COLORREF crColor)
 
UINT FASTCALL IntGdiRealizePalette (HDC hDC)
 
UINT APIENTRY IntAnimatePalette (HPALETTE hPal, UINT StartIndex, UINT NumEntries, CONST PPALETTEENTRY PaletteColors)
 
UINT APIENTRY IntGetPaletteEntries (HPALETTE hpal, UINT StartIndex, UINT Entries, LPPALETTEENTRY pe)
 
UINT APIENTRY IntGetSystemPaletteEntries (HDC hDC, UINT StartIndex, UINT Entries, LPPALETTEENTRY pe)
 
UINT APIENTRY IntSetPaletteEntries (HPALETTE hpal, UINT Start, UINT Entries, CONST LPPALETTEENTRY pe)
 
ULONG APIENTRY GreGetSetColorTable (HDC hdc, ULONG iStartIndex, ULONG cEntries, RGBQUAD *prgbColors, BOOL bSet)
 
__kernel_entry LONG APIENTRY NtGdiDoPalette (_In_ HGDIOBJ hObj, _In_ WORD iStart, _In_ WORD cEntries, _When_(bInbound!=0, _In_reads_bytes_(cEntries *sizeof(PALETTEENTRY))) _When_(bInbound==0, _Out_writes_bytes_(cEntries *sizeof(PALETTEENTRY))) LPVOID pUnsafeEntries, _In_ DWORD iFunc, _In_ BOOL bInbound)
 
UINT APIENTRY NtGdiSetSystemPaletteUse (HDC hDC, UINT Usage)
 
UINT APIENTRY NtGdiGetSystemPaletteUse (HDC hDC)
 
BOOL APIENTRY NtGdiUpdateColors (HDC hDC)
 
BOOL APIENTRY NtGdiUnrealizeObject (HGDIOBJ hgdiobj)
 
__kernel_entry HPALETTE APIENTRY NtGdiEngCreatePalette (_In_ ULONG iMode, _In_ ULONG cColors, _In_ ULONG *pulColors, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
 
__kernel_entry BOOL APIENTRY NtGdiEngDeletePalette (_In_ HPALETTE hPal)
 

Variables

static UINT SystemPaletteUse = SYSPAL_NOSTATIC
 
PALETTE gpalRGB
 
PALETTE gpalBGR
 
PALETTE gpalRGB555
 
PALETTE gpalRGB565
 
PALETTEgppalMono
 
PALETTEgppalDefault
 
PPALETTE appalSurfaceDefault [11]
 
const PALETTEENTRY g_sysPalTemplate [NB_RESERVED_COLORS]
 

Macro Definition Documentation

◆ MAX_PALCOLORS

#define MAX_PALCOLORS   65536

Definition at line 16 of file palette.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file palette.c.

◆ PAL_SETPOWNER

#define PAL_SETPOWNER   0x8000

Definition at line 15 of file palette.c.

Function Documentation

◆ ColorCorrection()

VOID FASTCALL ColorCorrection ( PPALETTE  PalGDI,
PPALETTEENTRY  PaletteEntry,
ULONG  Colors 
)

Definition at line 357 of file palette.c.

358{
359 PPDEVOBJ ppdev = (PPDEVOBJ)PalGDI->hPDev;
360
361 if (!ppdev) return;
362
363 if (ppdev->flFlags & PDEV_GAMMARAMP_TABLE)
364 {
365 ULONG i;
366 PGAMMARAMP GammaRamp = (PGAMMARAMP)ppdev->pvGammaRamp;
367 for ( i = 0; i < Colors; i++)
368 {
369 PaletteEntry[i].peRed += GammaRamp->Red[i];
370 PaletteEntry[i].peGreen += GammaRamp->Green[i];
371 PaletteEntry[i].peBlue += GammaRamp->Blue[i];
372 }
373 }
374 return;
375}
Colors
Definition: ansiprsr.h:4
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
if(dx< 0)
Definition: linetemp.h:194
struct _PDEVOBJ * PPDEVOBJ
Definition: mdevobj.h:6
#define for
Definition: utility.h:88
@ PDEV_GAMMARAMP_TABLE
Definition: pdevobj.h:17
WORD Red[256]
Definition: winddi.h:775
WORD Blue[256]
Definition: winddi.h:777
WORD Green[256]
Definition: winddi.h:776
HDEV hPDev
Definition: palette.h:49
FLONG flFlags
Definition: pdevobj.h:87
PVOID pvGammaRamp
Definition: pdevobj.h:106
uint32_t ULONG
Definition: typedefs.h:59
struct _GAMMARAMP * PGAMMARAMP

Referenced by PALOBJ_cGetColors().

◆ EngCreatePalette()

HPALETTE APIENTRY EngCreatePalette ( ULONG  iMode,
ULONG  cColors,
ULONG pulColors,
ULONG  flRed,
ULONG  flGreen,
ULONG  flBlue 
)

Display Driver Interface

Definition at line 384 of file palette.c.

391{
392 PPALETTE ppal;
393 HPALETTE hpal;
394
395 ppal = PALETTE_AllocPalette(iMode, cColors, (PPALETTEENTRY)pulColors, flRed, flGreen, flBlue);
396 if (!ppal) return NULL;
397
399 if (!hpal)
400 {
401 DPRINT1("Could not insert palette into handle table.\n");
403 return NULL;
404 }
405
407 return hpal;
408}
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
BASEOBJECT BaseObject
Definition: palette.h:36
VOID NTAPI GDIOBJ_vFreeObject(POBJ pobj)
Definition: gdiobj.c:603
HGDIOBJ NTAPI GDIOBJ_hInsertObject(POBJ pobj, ULONG ulOwner)
Definition: gdiobj.c:919
PPALETTE NTAPI PALETTE_AllocPalette(_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
Definition: palette.c:135
#define PALETTE_UnlockPalette(pPalette)
Definition: palette.h:56
_In_ ULONG iMode
Definition: winddi.h:3520

◆ EngDeletePalette()

BOOL APIENTRY EngDeletePalette ( IN HPALETTE  hpal)

Definition at line 415 of file palette.c.

416{
417 PPALETTE ppal;
418
419 ppal = PALETTE_ShareLockPalette(hpal);
420 if (!ppal) return FALSE;
421
423
424 return TRUE;
425}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1118
#define PALETTE_ShareLockPalette(hpal)
Definition: palette.h:57

◆ GetNumberOfBits()

unsigned short GetNumberOfBits ( unsigned int  dwMask)

Definition at line 54 of file palette.c.

55{
56 unsigned short wBits;
57 for (wBits = 0; dwMask; dwMask = dwMask & (dwMask - 1))
58 wBits++;
59 return wBits;
60}

◆ GreCreatePaletteInternal()

HPALETTE NTAPI GreCreatePaletteInternal ( IN LPLOGPALETTE  pLogPal,
IN UINT  cEntries 
)

Systemcall Interface

Definition at line 457 of file palette.c.

460{
461 HPALETTE hpal = NULL;
462 PPALETTE ppal;
463
464 pLogPal->palNumEntries = cEntries;
466 cEntries,
467 pLogPal->palPalEntry,
468 0, 0, 0);
469
470 if (ppal != NULL)
471 {
473
474 hpal = ppal->BaseObject.hHmgr;
476 }
477
478 return hpal;
479}
HGDIOBJ hHmgr(VOID)
Definition: baseobj.hpp:95
ULONG NumColors
Definition: palette.h:41
PALETTEENTRY * IndexedColors
Definition: palette.h:42
VOID FASTCALL PALETTE_ValidateFlags(PALETTEENTRY *lpPalE, INT size)
Definition: palette.c:125
PPALETTE NTAPI PALETTE_AllocPalWithHandle(_In_ ULONG iMode, _In_ ULONG cColors, _In_opt_ const PALETTEENTRY *pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)
Definition: palette.c:212
#define PAL_INDEXED
Definition: winddi.h:1561
_In_ UINT _In_ UINT cEntries
Definition: wingdi.h:4067

◆ GreGetSetColorTable()

ULONG APIENTRY GreGetSetColorTable ( HDC  hdc,
ULONG  iStartIndex,
ULONG  cEntries,
RGBQUAD prgbColors,
BOOL  bSet 
)

Definition at line 999 of file palette.c.

1005{
1006 PDC pdc;
1007 PSURFACE psurf;
1008 PPALETTE ppal = NULL;
1009 ULONG i, iEndIndex, iResult = 0;
1010
1011 /* Lock the DC */
1012 pdc = DC_LockDc(hdc);
1013 if (!pdc)
1014 {
1015 return 0;
1016 }
1017
1018 /* Get the surface from the DC */
1019 psurf = pdc->dclevel.pSurface;
1020
1021 /* Check if we have the default surface */
1022 if (psurf == NULL)
1023 {
1024 /* Use a mono palette */
1025 if (!bSet)
1026 ppal = gppalMono;
1027 }
1028 else if (psurf->SurfObj.iType == STYPE_BITMAP)
1029 {
1030 /* Get the palette of the surface */
1031 ppal = psurf->ppal;
1032 }
1033
1034 /* Check if this is an indexed palette and the range is ok */
1035 if (ppal && (ppal->flFlags & PAL_INDEXED) &&
1036 (iStartIndex < ppal->NumColors))
1037 {
1038 /* Calculate the end of the operation */
1039 iEndIndex = min(iStartIndex + cEntries, ppal->NumColors);
1040
1041 /* Check what operation to perform */
1042 if (bSet)
1043 {
1044 /* Loop all colors and set the palette entries */
1045 for (i = iStartIndex; i < iEndIndex; i++, prgbColors++)
1046 {
1047 ppal->IndexedColors[i].peRed = prgbColors->rgbRed;
1048 ppal->IndexedColors[i].peGreen = prgbColors->rgbGreen;
1049 ppal->IndexedColors[i].peBlue = prgbColors->rgbBlue;
1050 }
1051
1052 /* Mark the dc brushes invalid */
1053 pdc->pdcattr->ulDirty_ |= DIRTY_FILL|DIRTY_LINE|
1055 }
1056 else
1057 {
1058 /* Loop all colors and get the palette entries */
1059 for (i = iStartIndex; i < iEndIndex; i++, prgbColors++)
1060 {
1061 prgbColors->rgbRed = ppal->IndexedColors[i].peRed;
1062 prgbColors->rgbGreen = ppal->IndexedColors[i].peGreen;
1063 prgbColors->rgbBlue = ppal->IndexedColors[i].peBlue;
1064 prgbColors->rgbReserved = 0;
1065 }
1066 }
1067
1068 /* Calculate how many entries were modified */
1069 iResult = iEndIndex - iStartIndex;
1070 }
1071
1072 /* Unlock the DC */
1073 DC_UnlockDc(pdc);
1074
1075 return iResult;
1076}
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:238
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:220
HDC hdc
Definition: main.c:9
#define min(a, b)
Definition: monoChain.cc:55
#define DIRTY_FILL
Definition: ntgdihdl.h:123
#define DIRTY_TEXT
Definition: ntgdihdl.h:125
#define DIRTY_LINE
Definition: ntgdihdl.h:124
#define DIRTY_BACKGROUND
Definition: ntgdihdl.h:126
Definition: polytest.cpp:41
FLONG flFlags
Definition: palette.h:40
SURFOBJ SurfObj
Definition: surface.h:8
struct _PALETTE *const ppal
Definition: surface.h:11
USHORT iType
Definition: winddi.h:1216
PALETTE * gppalMono
Definition: palette.c:20
#define STYPE_BITMAP
Definition: winddi.h:1175

Referenced by NtGdiDoPalette().

◆ InitPaletteImpl()

NTSTATUS NTAPI InitPaletteImpl ( VOID  )

Definition at line 66 of file palette.c.

67{
68 // Create default palette (20 system colors)
70 20,
72 0, 0, 0);
75
76 /* palette_size = visual->map_entries; */
77
79 gpalRGB.RedMask = RGB(0xFF, 0x00, 0x00);
80 gpalRGB.GreenMask = RGB(0x00, 0xFF, 0x00);
81 gpalRGB.BlueMask = RGB(0x00, 0x00, 0xFF);
84
86 gpalBGR.RedMask = RGB(0x00, 0x00, 0xFF);
87 gpalBGR.GreenMask = RGB(0x00, 0xFF, 0x00);
88 gpalBGR.BlueMask = RGB(0xFF, 0x00, 0x00);
91
93 gpalRGB555.RedMask = 0x7C00;
94 gpalRGB555.GreenMask = 0x3E0;
95 gpalRGB555.BlueMask = 0x1F;
98
100 gpalRGB565.RedMask = 0xF800;
101 gpalRGB565.GreenMask = 0x7E0;
102 gpalRGB565.BlueMask = 0x1F;
105
109
110 /* Initialize default surface palettes */
121
122 return STATUS_SUCCESS;
123}
#define RGB(r, g, b)
Definition: precomp.h:67
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT BaseFlags
Definition: gdiobj.h:46
ULONG ulShareCount
Definition: gdiobj.h:42
ULONG BlueMask
Definition: palette.h:45
ULONG GreenMask
Definition: palette.h:44
ULONG RedMask
Definition: palette.h:43
VOID NTAPI GDIOBJ_vReferenceObjectByPointer(POBJ pobj)
Definition: gdiobj.c:741
const PALETTEENTRY g_sysPalTemplate[NB_RESERVED_COLORS]
Definition: palette.c:23
PPALETTE appalSurfaceDefault[11]
Definition: palette.c:21
PALETTE gpalRGB555
Definition: palette.c:20
PALETTE gpalRGB
Definition: palette.c:20
PALETTE * gppalDefault
Definition: palette.c:20
PALETTE gpalBGR
Definition: palette.c:20
PALETTE gpalRGB565
Definition: palette.c:20
FORCEINLINE VOID PALETTE_vSetRGBColorForIndex(PPALETTE ppal, ULONG ulIndex, COLORREF crColor)
Definition: palette.h:152
@ PAL_MONOCHROME
Definition: palette.h:22
@ PAL_RGB16_565
Definition: palette.h:28
@ PAL_RGB16_555
Definition: palette.h:27
#define BMF_16BPP
Definition: winddi.h:358
#define BMF_8BPP
Definition: winddi.h:357
#define PAL_RGB
Definition: winddi.h:1563
#define BMF_1BPP
Definition: winddi.h:355
#define PAL_BITFIELDS
Definition: winddi.h:1562
#define BMF_PNG
Definition: winddi.h:364
#define BMF_24BPP
Definition: winddi.h:359
#define BMF_32BPP
Definition: winddi.h:360
#define PAL_BGR
Definition: winddi.h:1564
#define BMF_8RLE
Definition: winddi.h:362
#define BMF_4RLE
Definition: winddi.h:361
#define BMF_4BPP
Definition: winddi.h:356
#define BMF_JPEG
Definition: winddi.h:363

Referenced by DriverEntry().

◆ IntAnimatePalette()

UINT APIENTRY IntAnimatePalette ( HPALETTE  hPal,
UINT  StartIndex,
UINT  NumEntries,
CONST PPALETTEENTRY  PaletteColors 
)

Definition at line 790 of file palette.c.

794{
795 UINT ret = 0;
796
798 {
799 PPALETTE palPtr;
801 const PALETTEENTRY *pptr = PaletteColors;
802
803 palPtr = PALETTE_ShareLockPalette(hPal);
804 if (!palPtr) return FALSE;
805
806 pal_entries = palPtr->NumColors;
807 if (StartIndex >= pal_entries)
808 {
810 return FALSE;
811 }
812 if (StartIndex+NumEntries > pal_entries) NumEntries = pal_entries - StartIndex;
813
814 for (NumEntries += StartIndex; StartIndex < NumEntries; StartIndex++, pptr++)
815 {
816 /* According to MSDN, only animate PC_RESERVED colours */
817 if (palPtr->IndexedColors[StartIndex].peFlags & PC_RESERVED)
818 {
819 memcpy( &palPtr->IndexedColors[StartIndex], pptr,
820 sizeof(PALETTEENTRY) );
821 ret++;
822 PALETTE_ValidateFlags(&palPtr->IndexedColors[StartIndex], 1);
823 }
824 }
825
827
828#if 0
829/* FIXME: This is completely broken! We cannot call UserGetDesktopWindow
830 without first acquiring the USER lock. But the whole process here is
831 screwed anyway. Instead of messing with the desktop DC, we need to
832 check, whether the palette is associated with a PDEV and whether that
833 PDEV supports palette operations. Then we need to call pfnDrvSetPalette.
834 But since IntGdiRealizePalette() is not even implemented for direct DCs,
835 we can as well just do nothing, that will at least not ASSERT!
836 I leave the whole thing here, to scare people away, who want to "fix" it. */
837
838 /* Immediately apply the new palette if current window uses it */
839 Wnd = UserGetDesktopWindow();
840 hDC = UserGetWindowDC(Wnd);
841 dc = DC_LockDc(hDC);
842 if (NULL != dc)
843 {
844 if (dc->dclevel.hpal == hPal)
845 {
848 }
849 else
851 }
852 UserReleaseDC(Wnd,hDC, FALSE);
853#endif // 0
854 }
855 return ret;
856}
static HDC hDC
Definition: 3dtext.c:33
HDC dc
Definition: cylfrac.c:34
return ret
Definition: mutex.c:146
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
int pal_entries[256]
Definition: uimain.c:52
HDC FASTCALL UserGetWindowDC(PWND Wnd)
Definition: windc.c:947
INT FASTCALL UserReleaseDC(PWND Window, HDC hDc, BOOL EndPaint)
Definition: windc.c:918
UINT FASTCALL IntGdiRealizePalette(HDC hDC)
Definition: palette.c:740
#define PALETTE_ShareUnlockPalette(ppal)
Definition: palette.h:59
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1403
#define PC_RESERVED
Definition: wingdi.h:882
#define DEFAULT_PALETTE
Definition: wingdi.h:913

Referenced by NtGdiDoPalette().

◆ IntGdiRealizePalette()

UINT FASTCALL IntGdiRealizePalette ( HDC  hDC)

FIXME: shouldn't dereference pSurface while the PDEV is not locked

Definition at line 740 of file palette.c.

741{
742 UINT realize = 0;
743 PDC pdc;
744 PALETTE *ppalSurf, *ppalDC;
745
746 pdc = DC_LockDc(hDC);
747 if (!pdc)
748 {
750 return 0;
751 }
752
753 if (!pdc->dclevel.pSurface)
754 {
755 goto cleanup;
756 }
757
758 if (pdc->dctype == DCTYPE_DIRECT)
759 {
760 static BOOL g_WarnedOnce = FALSE;
761 if (!g_WarnedOnce)
762 {
763 g_WarnedOnce = TRUE;
765 }
766 goto cleanup;
767 }
768
770 ppalSurf = pdc->dclevel.pSurface->ppal;
771 ppalDC = pdc->dclevel.ppal;
772
773 if (!(ppalSurf->flFlags & PAL_INDEXED))
774 {
775 // FIXME: Set error?
776 goto cleanup;
777 }
778
779 ASSERT(ppalDC->flFlags & PAL_INDEXED);
780
781 DPRINT1("RealizePalette unimplemented for %s\n",
782 (pdc->dctype == DCTYPE_MEMORY ? "memory managed DCs" : "device DCs"));
783
784cleanup:
785 DC_UnlockDc(pdc);
786 return realize;
787}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
@ DCTYPE_DIRECT
Definition: dc.h:41
@ DCTYPE_MEMORY
Definition: dc.h:42
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
static void cleanup(void)
Definition: main.c:1335
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ASSERT(a)
Definition: mode.c:44
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22

Referenced by IntAnimatePalette(), and UserRealizePalette().

◆ IntGetPaletteEntries()

UINT APIENTRY IntGetPaletteEntries ( HPALETTE  hpal,
UINT  StartIndex,
UINT  Entries,
LPPALETTEENTRY  pe 
)

Definition at line 859 of file palette.c.

864{
865 PPALETTE palGDI;
866 UINT numEntries;
867
868 palGDI = (PPALETTE) PALETTE_ShareLockPalette(hpal);
869 if (NULL == palGDI)
870 {
871 return 0;
872 }
873
874 numEntries = palGDI->NumColors;
875 if (NULL != pe)
876 {
877 if (numEntries < StartIndex + Entries)
878 {
879 Entries = numEntries - StartIndex;
880 }
881 if (numEntries <= StartIndex)
882 {
884 return 0;
885 }
886 memcpy(pe, palGDI->IndexedColors + StartIndex, Entries * sizeof(PALETTEENTRY));
887 }
888 else
889 {
890 Entries = numEntries;
891 }
892
894 return Entries;
895}
static const ENTRY Entries[]
struct _PALETTE * PPALETTE

Referenced by NtGdiDoPalette().

◆ IntGetSystemPaletteEntries()

UINT APIENTRY IntGetSystemPaletteEntries ( HDC  hDC,
UINT  StartIndex,
UINT  Entries,
LPPALETTEENTRY  pe 
)

Definition at line 898 of file palette.c.

902{
903 PPALETTE palGDI = NULL;
904 PDC dc = NULL;
905 UINT EntriesSize = 0;
906 UINT Ret = 0;
907
908 if (Entries == 0)
909 {
911 return 0;
912 }
913
914 if (pe != NULL)
915 {
916 EntriesSize = Entries * sizeof(pe[0]);
917 if (Entries != EntriesSize / sizeof(pe[0]))
918 {
919 /* Integer overflow! */
921 return 0;
922 }
923 }
924
925 if (!(dc = DC_LockDc(hDC)))
926 {
928 return 0;
929 }
930
931 palGDI = PALETTE_ShareLockPalette(dc->dclevel.hpal);
932 if (palGDI != NULL)
933 {
934 if (pe != NULL)
935 {
936 if (StartIndex >= palGDI->NumColors)
937 Entries = 0;
938 else if (Entries > palGDI->NumColors - StartIndex)
939 Entries = palGDI->NumColors - StartIndex;
940
941 memcpy(pe,
942 palGDI->IndexedColors + StartIndex,
943 Entries * sizeof(pe[0]));
944
945 Ret = Entries;
946 }
947 else
948 {
949 Ret = dc->ppdev->gdiinfo.ulNumPalReg;
950 }
951 }
952
953 if (palGDI != NULL)
955
956 if (dc != NULL)
958
959 return Ret;
960}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101

Referenced by NtGdiDoPalette().

◆ IntSetPaletteEntries()

UINT APIENTRY IntSetPaletteEntries ( HPALETTE  hpal,
UINT  Start,
UINT  Entries,
CONST LPPALETTEENTRY  pe 
)

Definition at line 964 of file palette.c.

969{
970 PPALETTE palGDI;
971 ULONG numEntries;
972
973 if (GDI_HANDLE_IS_STOCKOBJ(hpal))
974 {
975 return 0;
976 }
977
978 palGDI = PALETTE_ShareLockPalette(hpal);
979 if (!palGDI) return 0;
980
981 numEntries = palGDI->NumColors;
982 if (Start >= numEntries)
983 {
985 return 0;
986 }
987 if (numEntries < Start + Entries)
988 {
989 Entries = numEntries - Start;
990 }
991 memcpy(palGDI->IndexedColors + Start, pe, Entries * sizeof(PALETTEENTRY));
993
994 return Entries;
995}
return pTarget Start()
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37

Referenced by NtGdiDoPalette().

◆ NtGdiCreateHalftonePalette()

HPALETTE APIENTRY NtGdiCreateHalftonePalette ( HDC  hDC)

Definition at line 527 of file palette.c.

528{
529 int i, r, g, b;
530 PALETTEENTRY PalEntries[256];
531 PPALETTE ppal;
532 PDC pdc;
533 HPALETTE hpal = NULL;
534
535 pdc = DC_LockDc(hDC);
536 if (!pdc)
537 {
539 return NULL;
540 }
541
542 RtlZeroMemory(PalEntries, sizeof(PalEntries));
543
544 /* First and last ten entries are default ones */
545 for (i = 0; i < 10; i++)
546 {
547 PalEntries[i].peRed = g_sysPalTemplate[i].peRed;
548 PalEntries[i].peGreen = g_sysPalTemplate[i].peGreen;
549 PalEntries[i].peBlue = g_sysPalTemplate[i].peBlue;
550
551 PalEntries[246 + i].peRed = g_sysPalTemplate[10 + i].peRed;
552 PalEntries[246 + i].peGreen = g_sysPalTemplate[10 + i].peGreen;
553 PalEntries[246 + i].peBlue = g_sysPalTemplate[10 + i].peBlue;
554 }
555
556 ppal = PALETTE_ShareLockPalette(pdc->dclevel.hpal);
557 if (ppal && (ppal->flFlags & PAL_INDEXED))
558 {
559 /* FIXME: optimize the palette for the current palette */
561 }
562 else
563 {
564 for (r = 0; r < 6; r++)
565 {
566 for (g = 0; g < 6; g++)
567 {
568 for (b = 0; b < 6; b++)
569 {
570 i = r + g*6 + b*36 + 10;
571 PalEntries[i].peRed = r * 51;
572 PalEntries[i].peGreen = g * 51;
573 PalEntries[i].peBlue = b * 51;
574 }
575 }
576 }
577
578 for (i = 216; i < 246; i++)
579 {
580 int v = (i - 216) << 3;
581 PalEntries[i].peRed = v;
582 PalEntries[i].peGreen = v;
583 PalEntries[i].peBlue = v;
584 }
585 }
586
587 if (ppal)
589
590 DC_UnlockDc(pdc);
591
592 ppal = PALETTE_AllocPalWithHandle(PAL_INDEXED, 256, PalEntries, 0, 0, 0);
593 if (ppal)
594 {
595 hpal = ppal->BaseObject.hHmgr;
597 }
598
599 return hpal;
600}
const GLdouble * v
Definition: gl.h:2040
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean g
Definition: glext.h:6204
#define b
Definition: ke_i.h:79
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ NtGdiCreatePaletteInternal()

HPALETTE APIENTRY NtGdiCreatePaletteInternal ( IN LPLOGPALETTE  plogpalUser,
IN UINT  cEntries 
)

Definition at line 486 of file palette.c.

489{
490 HPALETTE hpal = NULL;
491 PPALETTE ppal;
492 ULONG i, cjSize;
493
495 if (ppal == NULL)
496 {
497 return NULL;
498 }
499
500 cjSize = FIELD_OFFSET(LOGPALETTE, palPalEntry[cEntries]);
501
503 {
504 ProbeForRead(plogpalUser, cjSize, 1);
505
506 for (i = 0; i < cEntries; i++)
507 {
508 ppal->IndexedColors[i] = plogpalUser->palPalEntry[i];
509 }
510 }
512 {
514 _SEH2_YIELD(return NULL);
515 }
516 _SEH2_END;
517
519 hpal = ppal->BaseObject.hHmgr;
521
522 return hpal;
523}
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:184
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ ULONG cjSize
Definition: winddi.h:3634

◆ NtGdiDoPalette()

__kernel_entry LONG APIENTRY NtGdiDoPalette ( _In_ HGDIOBJ  hObj,
_In_ WORD  iStart,
_In_ WORD  cEntries,
_When_(bInbound!=0, _In_reads_bytes_(cEntries *sizeof(PALETTEENTRY))) _When_(bInbound==0, _Out_writes_bytes_(cEntries *sizeof(PALETTEENTRY))) LPVOID  pUnsafeEntries,
_In_ DWORD  iFunc,
_In_ BOOL  bInbound 
)

Definition at line 1081 of file palette.c.

1089{
1090 LONG ret;
1091 LPVOID pEntries = NULL;
1092 SIZE_T cjSize;
1093
1094 if (pUnsafeEntries)
1095 {
1096 if (cEntries == 0)
1097 return 0;
1098
1099 cjSize = cEntries * sizeof(PALETTEENTRY);
1101 if (!pEntries)
1102 return 0;
1103
1104 if (bInbound)
1105 {
1106 _SEH2_TRY
1107 {
1108 ProbeForRead(pUnsafeEntries, cjSize, 1);
1109 memcpy(pEntries, pUnsafeEntries, cjSize);
1110 }
1112 {
1113 ExFreePoolWithTag(pEntries, TAG_PALETTE);
1114 _SEH2_YIELD(return 0);
1115 }
1116 _SEH2_END
1117 }
1118 else
1119 {
1120 /* Zero it out, so we don't accidentally leak kernel data */
1121 RtlZeroMemory(pEntries, cjSize);
1122 }
1123 }
1124
1125 ret = 0;
1126 switch(iFunc)
1127 {
1128 case GdiPalAnimate:
1129 if (pEntries)
1130 ret = IntAnimatePalette((HPALETTE)hObj, iStart, cEntries, (CONST PPALETTEENTRY)pEntries);
1131 break;
1132
1133 case GdiPalSetEntries:
1134 if (pEntries)
1135 ret = IntSetPaletteEntries((HPALETTE)hObj, iStart, cEntries, (CONST LPPALETTEENTRY)pEntries);
1136 break;
1137
1138 case GdiPalGetEntries:
1139 ret = IntGetPaletteEntries((HPALETTE)hObj, iStart, cEntries, (LPPALETTEENTRY)pEntries);
1140 break;
1141
1144 break;
1145
1147 if (pEntries)
1148 ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, TRUE);
1149 break;
1150
1152 if (pEntries)
1153 ret = GreGetSetColorTable((HDC)hObj, iStart, cEntries, (RGBQUAD*)pEntries, FALSE);
1154 break;
1155 }
1156
1157 if (pEntries)
1158 {
1159 if (!bInbound && (ret > 0))
1160 {
1161 cjSize = min(cEntries, ret) * sizeof(PALETTEENTRY);
1162 _SEH2_TRY
1163 {
1164 ProbeForWrite(pUnsafeEntries, cjSize, 1);
1165 memcpy(pUnsafeEntries, pEntries, cjSize);
1166 }
1168 {
1169 ret = 0;
1170 }
1171 _SEH2_END
1172 }
1173 ExFreePoolWithTag(pEntries, TAG_PALETTE);
1174 }
1175
1176 return ret;
1177}
ULONG RGBQUAD
Definition: precomp.h:47
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static HDC
Definition: imagelist.c:88
@ GdiPalSetColorTable
Definition: ntgdityp.h:32
@ GdiPalGetColorTable
Definition: ntgdityp.h:33
@ GdiPalSetEntries
Definition: ntgdityp.h:29
@ GdiPalAnimate
Definition: ntgdityp.h:28
@ GdiPalGetEntries
Definition: ntgdityp.h:30
@ GdiPalGetSystemEntries
Definition: ntgdityp.h:31
#define CONST
Definition: pedump.c:81
long LONG
Definition: pedump.c:60
ULONG_PTR SIZE_T
Definition: typedefs.h:80
ULONG APIENTRY GreGetSetColorTable(HDC hdc, ULONG iStartIndex, ULONG cEntries, RGBQUAD *prgbColors, BOOL bSet)
Definition: palette.c:999
UINT APIENTRY IntGetPaletteEntries(HPALETTE hpal, UINT StartIndex, UINT Entries, LPPALETTEENTRY pe)
Definition: palette.c:859
UINT APIENTRY IntSetPaletteEntries(HPALETTE hpal, UINT Start, UINT Entries, CONST LPPALETTEENTRY pe)
Definition: palette.c:964
UINT APIENTRY IntGetSystemPaletteEntries(HDC hDC, UINT StartIndex, UINT Entries, LPPALETTEENTRY pe)
Definition: palette.c:898
UINT APIENTRY IntAnimatePalette(HPALETTE hPal, UINT StartIndex, UINT NumEntries, CONST PPALETTEENTRY PaletteColors)
Definition: palette.c:790
#define TAG_PALETTE
Definition: tags.h:26
struct tagPALETTEENTRY PALETTEENTRY
_In_ UINT iStart
Definition: wingdi.h:4066

Referenced by AnimatePalette(), GetDIBColorTable(), GetPaletteEntries(), GetSystemPaletteEntries(), SetDIBColorTable(), SetPaletteEntries(), Test_NtGdiDoPalette_GdiPalAnimate(), Test_NtGdiDoPalette_GdiPalGetEntries(), Test_NtGdiDoPalette_GdiPalSetEntries(), and Test_NtGdiDoPalette_SetDIBColorTable().

◆ NtGdiEngCreatePalette()

__kernel_entry HPALETTE APIENTRY NtGdiEngCreatePalette ( _In_ ULONG  iMode,
_In_ ULONG  cColors,
_In_ ULONG pulColors,
_In_ FLONG  flRed,
_In_ FLONG  flGreen,
_In_ FLONG  flBlue 
)

Definition at line 1276 of file palette.c.

1283{
1284 HPALETTE hPal = NULL;
1285 ULONG *pulcSafe, ulColors[WINDDI_MAXSETPALETTECOLORS];
1286
1287 if ( cColors > MAX_PALCOLORS ) return NULL;
1288
1289 if ( cColors <= WINDDI_MAXSETPALETTECOLORS )
1290 {
1291 pulcSafe = ulColors;
1292 }
1293 else
1294 {
1295 pulcSafe = ExAllocatePoolWithTag(PagedPool, cColors * sizeof(ULONG), GDITAG_UMPD );
1296 }
1297
1298 _SEH2_TRY
1299 {
1300 ProbeForRead( pulColors, cColors * sizeof(ULONG), 1);
1301 RtlCopyMemory( pulcSafe, pulColors, cColors * sizeof(ULONG) );
1302 }
1304 {
1306 if ( cColors > WINDDI_MAXSETPALETTECOLORS ) ExFreePoolWithTag( pulcSafe, GDITAG_UMPD );
1307 _SEH2_YIELD(return hPal);
1308 }
1309 _SEH2_END;
1310
1311 hPal = EngCreatePalette( iMode/*|PAL_SETPOWNER*/, cColors, pulcSafe, flRed, flGreen, flBlue );
1312
1313 if ( cColors > WINDDI_MAXSETPALETTECOLORS ) ExFreePoolWithTag( pulcSafe, GDITAG_UMPD );
1314
1315 return hPal;
1316}
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:31
#define MAX_PALCOLORS
Definition: palette.c:16
#define GDITAG_UMPD
Definition: tags.h:175
#define WINDDI_MAXSETPALETTECOLORS
Definition: winddi.h:4006
_Must_inspect_result_ ENGAPI HPALETTE APIENTRY EngCreatePalette(_In_ ULONG iMode, _In_ ULONG cColors, _In_ ULONG *pulColors, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue)

Referenced by START_TEST().

◆ NtGdiEngDeletePalette()

__kernel_entry BOOL APIENTRY NtGdiEngDeletePalette ( _In_ HPALETTE  hPal)

Definition at line 1321 of file palette.c.

1323{
1324 return EngDeletePalette(hPal);
1325}
ENGAPI BOOL APIENTRY EngDeletePalette(_In_ _Post_ptr_invalid_ HPALETTE hpal)

◆ NtGdiGetColorAdjustment()

BOOL APIENTRY NtGdiGetColorAdjustment ( HDC  hdc,
LPCOLORADJUSTMENT  pca 
)

Definition at line 651 of file palette.c.

654{
656 return FALSE;
657}

◆ NtGdiGetNearestColor()

COLORREF APIENTRY NtGdiGetNearestColor ( _In_ HDC  hDC,
_In_ COLORREF  Color 
)

FIXME: shouldn't dereference pSurface while the PDEV is not locked

Definition at line 671 of file palette.c.

674{
675 COLORREF nearest = CLR_INVALID;
676 PDC dc;
677 EXLATEOBJ exlo;
678 PPALETTE ppal;
679
680 dc = DC_LockDc(hDC);
681
682 if(dc == NULL)
683 {
685 return CLR_INVALID;
686 }
687
689 if(dc->dclevel.pSurface == NULL)
690 ppal = gppalMono;
691 else
692 ppal = dc->dclevel.pSurface->ppal;
693
694 /* Translate the color to the DC format */
696
697 /* XLATE it back to RGB color space */
699 ppal,
700 &gpalRGB,
701 0,
702 RGB(0xff, 0xff, 0xff),
703 RGB(0, 0, 0));
704
705 nearest = XLATEOBJ_iXlate(&exlo.xlo, Color);
706
707 EXLATEOBJ_vCleanup(&exlo);
708
709 /* We're done */
711
712 return nearest;
713}
ULONG TranslateCOLORREF(PDC pdc, COLORREF crColor)
Definition: dcutil.c:869
XLATEOBJ xlo
Definition: xlateobj.h:21
ENGAPI ULONG APIENTRY XLATEOBJ_iXlate(_In_ XLATEOBJ *pxlo, _In_ ULONG iColor)
Definition: xlateobj.c:909
DWORD COLORREF
Definition: windef.h:100
#define CLR_INVALID
Definition: wingdi.h:883
VOID NTAPI EXLATEOBJ_vInitialize(_Out_ PEXLATEOBJ pexlo, _In_opt_ PALETTE *ppalSrc, _In_opt_ PALETTE *ppalDst, _In_ COLORREF crSrcBackColor, _In_ COLORREF crDstBackColor, _In_ COLORREF crDstForeColor)
Definition: xlateobj.c:491
VOID NTAPI EXLATEOBJ_vCleanup(_Inout_ PEXLATEOBJ pexlo)
Definition: xlateobj.c:894

◆ NtGdiGetNearestPaletteIndex()

UINT APIENTRY NtGdiGetNearestPaletteIndex ( HPALETTE  hpal,
COLORREF  crColor 
)

Definition at line 717 of file palette.c.

720{
722 UINT index = 0;
723
724 if (ppal)
725 {
726 if (ppal->flFlags & PAL_INDEXED)
727 {
728 /* Return closest match for the given RGB color */
730 }
731 // else SetLastError ?
733 }
734
735 return index;
736}
#define index(s, c)
Definition: various.h:29
GLuint index
Definition: glext.h:6031
ULONG NTAPI PALETTE_ulGetNearestPaletteIndex(PALETTE *ppal, ULONG iColor)
Definition: palette.c:264

◆ NtGdiGetSystemPaletteUse()

UINT APIENTRY NtGdiGetSystemPaletteUse ( HDC  hDC)

Definition at line 1207 of file palette.c.

1208{
1209 return SystemPaletteUse;
1210}
static UINT SystemPaletteUse
Definition: palette.c:18

◆ NtGdiResizePalette()

BOOL APIENTRY NtGdiResizePalette ( HPALETTE  hpal,
UINT  Entries 
)

Definition at line 604 of file palette.c.

607{
608/* PALOBJ *palPtr = (PALOBJ*)AccessUserObject(hPal);
609 UINT cPrevEnt, prevVer;
610 INT prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
611 XLATEOBJ *XlateObj = NULL;
612
613 if(!palPtr) return FALSE;
614 cPrevEnt = palPtr->logpalette->palNumEntries;
615 prevVer = palPtr->logpalette->palVersion;
616 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) + sizeof(int*) + sizeof(GDIOBJHDR);
617 size += sizeof(int*) + sizeof(GDIOBJHDR);
618 XlateObj = palPtr->logicalToSystem;
619
620 if (!(palPtr = GDI_ReallocObject(size, hPal, palPtr))) return FALSE;
621
622 if(XlateObj)
623 {
624 XLATEOBJ *NewXlateObj = (int*) HeapReAlloc(GetProcessHeap(), 0, XlateObj, cEntries * sizeof(int));
625 if(NewXlateObj == NULL)
626 {
627 ERR("Can not resize logicalToSystem -- out of memory!\n");
628 GDI_ReleaseObj( hPal );
629 return FALSE;
630 }
631 palPtr->logicalToSystem = NewXlateObj;
632 }
633
634 if(cEntries > cPrevEnt)
635 {
636 if(XlateObj) memset(palPtr->logicalToSystem + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
637 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
638 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize), cEntries - cPrevEnt );
639 }
640 palPtr->logpalette->palNumEntries = cEntries;
641 palPtr->logpalette->palVersion = prevVer;
642// GDI_ReleaseObj( hPal );
643 return TRUE; */
644
646 return FALSE;
647}

◆ NtGdiSetColorAdjustment()

BOOL APIENTRY NtGdiSetColorAdjustment ( HDC  hdc,
LPCOLORADJUSTMENT  pca 
)

Definition at line 661 of file palette.c.

664{
666 return FALSE;
667}

◆ NtGdiSetSystemPaletteUse()

UINT APIENTRY NtGdiSetSystemPaletteUse ( HDC  hDC,
UINT  Usage 
)

Definition at line 1180 of file palette.c.

1181{
1182 UINT old = SystemPaletteUse;
1183
1184 /* Device doesn't support colour palettes */
1186 return SYSPAL_ERROR;
1187 }
1188
1189 switch (Usage)
1190 {
1191 case SYSPAL_NOSTATIC:
1192 case SYSPAL_NOSTATIC256:
1193 case SYSPAL_STATIC:
1195 break;
1196
1197 default:
1198 old=SYSPAL_ERROR;
1199 break;
1200 }
1201
1202 return old;
1203}
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
__kernel_entry W32KAPI INT APIENTRY NtGdiGetDeviceCaps(_In_ HDC hdc, _In_ INT i)
#define RASTERCAPS
Definition: wingdi.h:745
#define SYSPAL_ERROR
Definition: wingdi.h:927
#define SYSPAL_STATIC
Definition: wingdi.h:926
#define SYSPAL_NOSTATIC
Definition: wingdi.h:925
#define SYSPAL_NOSTATIC256
Definition: wingdi.h:21
#define RC_PALETTE
Definition: wingdi.h:790

◆ NtGdiUnrealizeObject()

BOOL APIENTRY NtGdiUnrealizeObject ( HGDIOBJ  hgdiobj)

Definition at line 1251 of file palette.c.

1252{
1253 BOOL Ret = FALSE;
1254 PPALETTE palGDI;
1255
1256 if ( !hgdiobj ||
1257 GDI_HANDLE_IS_STOCKOBJ(hgdiobj) ||
1259 return Ret;
1260
1261 palGDI = PALETTE_ShareLockPalette(hgdiobj);
1262 if (!palGDI) return FALSE;
1263
1264 // FIXME!!
1265 // Need to do something!!!
1266 // Zero out Current and Old Translated pointers?
1267 //
1268 Ret = TRUE;
1270 return Ret;
1271}
#define GDI_OBJECT_TYPE_PALETTE
Definition: gdi.h:49
#define GDI_HANDLE_IS_TYPE(h, t)
Definition: gdi.h:34

◆ NtGdiUpdateColors()

BOOL APIENTRY NtGdiUpdateColors ( HDC  hDC)

Definition at line 1214 of file palette.c.

1215{
1216 PWND Wnd;
1217 BOOL calledFromUser, ret;
1219
1220 calledFromUser = UserIsEntered();
1221
1222 if (!calledFromUser){
1224 }
1225
1227 if (Wnd == NULL)
1228 {
1230
1231 if (!calledFromUser){
1232 UserLeave();
1233 }
1234
1235 return FALSE;
1236 }
1237
1238 UserRefObjectCo(Wnd, &Ref);
1240 UserDerefObjectCo(Wnd);
1241
1242 if (!calledFromUser){
1243 UserLeave();
1244 }
1245
1246 return ret;
1247}
HWND FASTCALL IntWindowFromDC(HDC hDc)
Definition: windc.c:894
BOOL FASTCALL UserIsEntered(VOID)
Definition: ntuser.c:225
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:258
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:249
static __inline VOID UserDerefObjectCo(PVOID obj)
Definition: object.h:43
static __inline VOID UserRefObjectCo(PVOID obj, PUSER_REFERENCE_ENTRY UserReferenceEntry)
Definition: object.h:27
Definition: object.h:4
Definition: ntuser.h:694
BOOL FASTCALL co_UserRedrawWindow(PWND Window, const RECTL *UpdateRect, PREGION UpdateRgn, ULONG Flags)
Definition: painting.c:895
PWND FASTCALL UserGetWindowObject(HWND hWnd)
Definition: window.c:124
#define ERROR_INVALID_WINDOW_HANDLE
Definition: winerror.h:1226
#define RDW_INVALIDATE
Definition: winuser.h:1225

◆ PALETTE_AllocPalette()

PPALETTE NTAPI PALETTE_AllocPalette ( _In_ ULONG  iMode,
_In_ ULONG  cColors,
_In_opt_ const PALETTEENTRY pEntries,
_In_ FLONG  flRed,
_In_ FLONG  flGreen,
_In_ FLONG  flBlue 
)

Definition at line 135 of file palette.c.

142{
143 PPALETTE ppal;
144 ULONG fl = 0, cjSize = sizeof(PALETTE);
145
146 /* Check if the palette has entries */
147 if (iMode & PAL_INDEXED)
148 {
149 /* Check color count */
150 if ((cColors == 0) || (cColors > 1024)) return NULL;
151
152 /* Mark 2 color indexed palettes as monochrome */
153 if (cColors == 2) iMode |= PAL_MONOCHROME;
154
155 /* Allocate enough space for the palete entries */
156 cjSize += cColors * sizeof(PALETTEENTRY);
157 }
158 else
159 {
160 /* There are no palette entries */
161 cColors = 0;
162
163 /* We can use the lookaside list */
165 }
166
167 /* Allocate the object (without a handle!) */
169 if (!ppal)
170 {
171 return NULL;
172 }
173
174 /* Set mode, color count and entry pointer */
175 ppal->flFlags = iMode;
176 ppal->NumColors = cColors;
177 ppal->IndexedColors = ppal->apalColors;
178
179 /* Check what kind of palette this is */
180 if (iMode & PAL_INDEXED)
181 {
182 /* Check if we got a color array */
183 if (pEntries)
184 {
185 /* Copy the entries */
186 RtlCopyMemory(ppal->IndexedColors, pEntries, cColors * sizeof(pEntries[0]));
187 }
188 }
189 else if (iMode & PAL_BITFIELDS)
190 {
191 /* Copy the color masks */
192 ppal->RedMask = flRed;
193 ppal->GreenMask = flGreen;
194 ppal->BlueMask = flBlue;
195
196 /* Check what masks we have and set optimization flags */
197 if ((flRed == 0x7c00) && (flGreen == 0x3E0) && (flBlue == 0x1F))
198 ppal->flFlags |= PAL_RGB16_555;
199 else if ((flRed == 0xF800) && (flGreen == 0x7E0) && (flBlue == 0x1F))
200 ppal->flFlags |= PAL_RGB16_565;
201 else if ((flRed == 0xFF0000) && (flGreen == 0xFF00) && (flBlue == 0xFF))
202 ppal->flFlags |= PAL_BGR;
203 else if ((flRed == 0xFF) && (flGreen == 0xFF00) && (flBlue == 0xFF0000))
204 ppal->flFlags |= PAL_RGB;
205 }
206
207 return ppal;
208}
@ BASEFLAG_LOOKASIDE
Definition: gdiobj.h:58
@ GDIObjType_PAL_TYPE
Definition: ntgdityp.h:128
PALETTEENTRY apalColors[0]
Definition: palette.h:50
POBJ NTAPI GDIOBJ_AllocateObject(UCHAR objt, ULONG cjSize, FLONG fl)
Definition: gdiobj.c:569
struct _PALETTE PALETTE
_In_ FLONG fl
Definition: winddi.h:1279

Referenced by CreateDIBPalette(), EngCreatePalette(), FixupDIBBrushPalette(), InitPaletteImpl(), NtGdiDdDDICreateDCFromMemory(), and PALETTE_AllocPalWithHandle().

◆ PALETTE_AllocPalWithHandle()

PPALETTE NTAPI PALETTE_AllocPalWithHandle ( _In_ ULONG  iMode,
_In_ ULONG  cColors,
_In_opt_ const PALETTEENTRY pEntries,
_In_ FLONG  flRed,
_In_ FLONG  flGreen,
_In_ FLONG  flBlue 
)

Definition at line 212 of file palette.c.

219{
220 PPALETTE ppal;
221
222 /* Allocate the palette without a handle */
223 ppal = PALETTE_AllocPalette(iMode, cColors, pEntries, flRed, flGreen, flBlue);
224 if (!ppal) return NULL;
225
226 /* Insert the palette into the handle table */
228 {
229 DPRINT1("Could not insert palette into handle table.\n");
231 return NULL;
232 }
233
234 return ppal;
235}
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117

Referenced by DIB_MapPaletteColors(), GreCreatePaletteInternal(), InitPaletteImpl(), NtGdiCreateHalftonePalette(), and NtGdiCreatePaletteInternal().

◆ PALETTE_GetObject()

INT FASTCALL PALETTE_GetObject ( PPALETTE  ppal,
INT  cbCount,
LPLOGBRUSH  lpBuffer 
)

Definition at line 250 of file palette.c.

251{
252 if (!lpBuffer)
253 {
254 return sizeof(WORD);
255 }
256
257 if ((UINT)cbCount < sizeof(WORD)) return 0;
258 *((WORD*)lpBuffer) = (WORD)ppal->NumColors;
259 return sizeof(WORD);
260}
unsigned short WORD
Definition: ntddk_ex.h:93
static int cbCount
Definition: fiber.c:54
_Out_ LPWSTR lpBuffer
Definition: netsh.h:68

Referenced by GreGetObject().

◆ PALETTE_ulGetNearestBitFieldsIndex()

ULONG NTAPI PALETTE_ulGetNearestBitFieldsIndex ( PALETTE ppal,
ULONG  ulColor 
)

Definition at line 298 of file palette.c.

299{
300 ULONG ulNewColor;
302
303 // FIXME: HACK, should be stored already
304 ppal->ulRedShift = CalculateShift(RGB(0xff,0,0), ppal->RedMask);
305 ppal->ulGreenShift = CalculateShift(RGB(0,0xff,0), ppal->GreenMask);
306 ppal->ulBlueShift = CalculateShift(RGB(0,0,0xff), ppal->BlueMask);
307
308 ulNewColor = _rotl(ulColor, ppal->ulRedShift) & ppal->RedMask;
309 ulNewColor |= _rotl(ulColor, ppal->ulGreenShift) & ppal->GreenMask;
310 ulNewColor |= _rotl(ulColor, ppal->ulBlueShift) & ppal->BlueMask;
311
312 return ulNewColor;
313}
_ACRTIMP unsigned int __cdecl _rotl(unsigned int, int)
Definition: rot.c:43
ULONG ulGreenShift
Definition: palette.h:47
ULONG ulBlueShift
Definition: palette.h:48
ULONG ulRedShift
Definition: palette.h:46
FORCEINLINE ULONG CalculateShift(ULONG ulMask1, ULONG ulMask2)
Definition: palette.h:130

Referenced by PALETTE_ulGetNearestIndex().

◆ PALETTE_ulGetNearestIndex()

ULONG NTAPI PALETTE_ulGetNearestIndex ( PALETTE ppal,
ULONG  ulColor 
)

Definition at line 317 of file palette.c.

318{
319 if (ppal->flFlags & PAL_RGB)
320 return ulColor;
321 if (ppal->flFlags & PAL_BGR)
322 return RGB(GetBValue(ulColor), GetGValue(ulColor), GetRValue(ulColor));
323 if (ppal->flFlags & PAL_INDEXED) // Use fl & PALINDEXED
324 return PALETTE_ulGetNearestPaletteIndex(ppal, ulColor);
325 else
326 return PALETTE_ulGetNearestBitFieldsIndex(ppal, ulColor);
327}
#define GetBValue(quad)
Definition: precomp.h:71
#define GetGValue(quad)
Definition: precomp.h:70
#define GetRValue(quad)
Definition: precomp.h:69
ULONG NTAPI PALETTE_ulGetNearestBitFieldsIndex(PALETTE *ppal, ULONG ulColor)
Definition: palette.c:298

Referenced by EXLATEOBJ_vInitialize(), and TranslateCOLORREF().

◆ PALETTE_ulGetNearestPaletteIndex()

ULONG NTAPI PALETTE_ulGetNearestPaletteIndex ( PALETTE ppal,
ULONG  iColor 
)

Definition at line 264 of file palette.c.

265{
266 ULONG ulDiff, ulColorDiff, ulMinimalDiff = 0xFFFFFF;
267 ULONG i, ulBestIndex = 0;
268 PALETTEENTRY peColor = *(PPALETTEENTRY)&iColor;
269 ASSERT(ppal->flFlags & PAL_INDEXED);
270
271 /* Loop all palette entries */
272 for (i = 0; i < ppal->NumColors; i++)
273 {
274 /* Calculate distance in the color cube */
275 ulDiff = peColor.peRed - ppal->IndexedColors[i].peRed;
276 ulColorDiff = ulDiff * ulDiff;
277 ulDiff = peColor.peGreen - ppal->IndexedColors[i].peGreen;
278 ulColorDiff += ulDiff * ulDiff;
279 ulDiff = peColor.peBlue - ppal->IndexedColors[i].peBlue;
280 ulColorDiff += ulDiff * ulDiff;
281
282 /* Check for a better match */
283 if (ulColorDiff < ulMinimalDiff)
284 {
285 ulBestIndex = i;
286 ulMinimalDiff = ulColorDiff;
287
288 /* Break on exact match */
289 if (ulMinimalDiff == 0) break;
290 }
291 }
292
293 return ulBestIndex;
294}
struct tagPALETTEENTRY * PPALETTEENTRY
_In_ ULONG iColor
Definition: xlateobj.h:17

Referenced by EBRUSHOBJ_vSetSolidRGBColor(), EXLATEOBJ_vInitialize(), NtGdiGetNearestPaletteIndex(), and PALETTE_ulGetNearestIndex().

◆ PALETTE_ValidateFlags()

VOID FASTCALL PALETTE_ValidateFlags ( PALETTEENTRY lpPalE,
INT  size 
)

Definition at line 125 of file palette.c.

126{
127 int i = 0;
128 for (; i<size ; i++)
129 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
130}
#define PC_SYS_USED
Definition: color.h:3
GLsizeiptr size
Definition: glext.h:5919

Referenced by GreCreatePaletteInternal(), IntAnimatePalette(), and NtGdiCreatePaletteInternal().

◆ PALETTE_vCleanup()

VOID NTAPI PALETTE_vCleanup ( PVOID  ObjectBody)

Definition at line 239 of file palette.c.

240{
241 PPALETTE pPal = (PPALETTE)ObjectBody;
242 if (pPal->IndexedColors && pPal->IndexedColors != pPal->apalColors)
243 {
245 }
246}

◆ PALETTE_vGetBitMasks()

VOID NTAPI PALETTE_vGetBitMasks ( PPALETTE  ppal,
PULONG  pulColors 
)

Definition at line 331 of file palette.c.

332{
333 ASSERT(pulColors);
334
335 if (ppal->flFlags & PAL_INDEXED || ppal->flFlags & PAL_RGB)
336 {
337 pulColors[0] = RGB(0xFF, 0x00, 0x00);
338 pulColors[1] = RGB(0x00, 0xFF, 0x00);
339 pulColors[2] = RGB(0x00, 0x00, 0xFF);
340 }
341 else if (ppal->flFlags & PAL_BGR)
342 {
343 pulColors[0] = RGB(0x00, 0x00, 0xFF);
344 pulColors[1] = RGB(0x00, 0xFF, 0x00);
345 pulColors[2] = RGB(0xFF, 0x00, 0x00);
346 }
347 else if (ppal->flFlags & PAL_BITFIELDS)
348 {
349 pulColors[0] = ppal->RedMask;
350 pulColors[1] = ppal->GreenMask;
351 pulColors[2] = ppal->BlueMask;
352 }
353}

Referenced by EXLATEOBJ_vInitialize().

◆ PALOBJ_cGetColors()

ULONG APIENTRY PALOBJ_cGetColors ( PALOBJ PalObj,
ULONG  Start,
ULONG  Colors,
ULONG PaletteEntry 
)

Definition at line 432 of file palette.c.

433{
434 PALETTE *PalGDI;
435
436 PalGDI = (PALETTE*)PalObj;
437
438 if (Start >= PalGDI->NumColors)
439 return 0;
440
441 Colors = min(Colors, PalGDI->NumColors - Start);
442
443 /* NOTE: PaletteEntry ULONGs are in the same order as PALETTEENTRY. */
444 RtlCopyMemory(PaletteEntry, PalGDI->IndexedColors + Start, sizeof(ULONG) * Colors);
445
446 if (PalGDI->flFlags & PAL_GAMMACORRECTION)
447 ColorCorrection(PalGDI, (PPALETTEENTRY)PaletteEntry, Colors);
448
449 return Colors;
450}
VOID FASTCALL ColorCorrection(PPALETTE PalGDI, PPALETTEENTRY PaletteEntry, ULONG Colors)
Definition: palette.c:357
@ PAL_GAMMACORRECTION
Definition: palette.h:29

Variable Documentation

◆ appalSurfaceDefault

PPALETTE appalSurfaceDefault[11]

Definition at line 21 of file palette.c.

Referenced by InitPaletteImpl(), and SURFACE_AllocSurface().

◆ g_sysPalTemplate

Initial value:
=
{
{ 0x00, 0x00, 0x00, PC_SYS_USED },
{ 0x80, 0x00, 0x00, PC_SYS_USED },
{ 0x00, 0x80, 0x00, PC_SYS_USED },
{ 0x80, 0x80, 0x00, PC_SYS_USED },
{ 0x00, 0x00, 0x80, PC_SYS_USED },
{ 0x80, 0x00, 0x80, PC_SYS_USED },
{ 0x00, 0x80, 0x80, PC_SYS_USED },
{ 0xc0, 0xc0, 0xc0, PC_SYS_USED },
{ 0xc0, 0xdc, 0xc0, PC_SYS_USED },
{ 0xa6, 0xca, 0xf0, PC_SYS_USED },
{ 0xff, 0xfb, 0xf0, PC_SYS_USED },
{ 0xa0, 0xa0, 0xa4, PC_SYS_USED },
{ 0x80, 0x80, 0x80, PC_SYS_USED },
{ 0xff, 0x00, 0x00, PC_SYS_USED },
{ 0x00, 0xff, 0x00, PC_SYS_USED },
{ 0xff, 0xff, 0x00, PC_SYS_USED },
{ 0x00, 0x00, 0xff, PC_SYS_USED },
{ 0xff, 0x00, 0xff, PC_SYS_USED },
{ 0x00, 0xff, 0xff, PC_SYS_USED },
{ 0xff, 0xff, 0xff, PC_SYS_USED }
}

Definition at line 23 of file palette.c.

Referenced by InitPaletteImpl(), and NtGdiCreateHalftonePalette().

◆ gpalBGR

PALETTE gpalBGR

Definition at line 20 of file palette.c.

Referenced by InitPaletteImpl().

◆ gpalRGB

◆ gpalRGB555

PALETTE gpalRGB555

Definition at line 20 of file palette.c.

Referenced by InitPaletteImpl().

◆ gpalRGB565

PALETTE gpalRGB565

Definition at line 20 of file palette.c.

Referenced by InitPaletteImpl().

◆ gppalDefault

PALETTE * gppalDefault

Definition at line 20 of file palette.c.

Referenced by CreateDIBPalette(), CreateStockObjects(), EBRUSHOBJ_vInit(), and InitPaletteImpl().

◆ gppalMono

◆ SystemPaletteUse

UINT SystemPaletteUse = SYSPAL_NOSTATIC
static

Definition at line 18 of file palette.c.

Referenced by NtGdiGetSystemPaletteUse(), and NtGdiSetSystemPaletteUse().