-Import tkreuzer's time implementation from AMD64 branch
[reactos.git] / reactos / subsystems / win32 / win32k / include / palette.h
1 #ifndef _WIN32K_PALETTE_H
2 #define _WIN32K_PALETTE_H
3
4 #include <include/dc.h>
5
6 #define NO_MAPPING
7
8 #define PALETTE_FIXED 0x0001 /* read-only colormap - have to use XAllocColor (if not virtual) */
9 #define PALETTE_VIRTUAL 0x0002 /* no mapping needed - pixel == pixel color */
10
11 #define PALETTE_PRIVATE 0x1000 /* private colormap, identity mapping */
12 #define PALETTE_WHITESET 0x2000
13
14 // Palette mode flags
15 #ifndef __WINDDI_H // Defined in ddk/winddi.h
16 #define PAL_INDEXED 0x00000001 // Indexed palette
17 #define PAL_BITFIELDS 0x00000002 // Bit fields used for DIB, DIB section
18 #define PAL_RGB 0x00000004 // Red, green, blue
19 #define PAL_BGR 0x00000008 // Blue, green, red
20 #define PAL_CMYK 0x00000010 // Cyan, magenta, yellow, black
21 #endif
22 #define PAL_DC 0x00000100
23 #define PAL_FIXED 0x00000200 // Can't be changed
24 #define PAL_FREE 0x00000400
25 #define PAL_MANAGED 0x00000800
26 #define PAL_NOSTATIC 0x00001000
27 #define PAL_MONOCHROME 0x00002000 // Two colors only
28 #define PAL_BRUSHHACK 0x00004000
29 #define PAL_DIBSECTION 0x00008000 // Used for a DIB section
30 #define PAL_NOSTATIC256 0x00010000
31 #define PAL_HT 0x00100000 // Halftone palette
32 #define PAL_RGB16_555 0x00200000 // 16-bit RGB in 555 format
33 #define PAL_RGB16_565 0x00400000 // 16-bit RGB in 565 format
34 #define PAL_GAMMACORRECTION 0x00800000 // Correct colors
35
36
37 typedef struct _PALETTE
38 {
39 /* Header for all gdi objects in the handle table.
40 Do not (re)move this. */
41 BASEOBJECT BaseObject;
42
43 PALOBJ PalObj;
44 XLATEOBJ *logicalToSystem;
45 HPALETTE Self;
46 ULONG Mode; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
47 ULONG NumColors;
48 PALETTEENTRY *IndexedColors;
49 ULONG RedMask;
50 ULONG GreenMask;
51 ULONG BlueMask;
52 ULONG ulRedShift;
53 ULONG ulGreenShift;
54 ULONG ulBlueShift;
55 HDEV hPDev;
56 } PALETTE, *PPALETTE;
57
58 extern PALETTE gpalRGB, gpalBGR, gpalMono;
59
60
61 HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
62 ULONG NumColors,
63 ULONG *Colors,
64 ULONG Red,
65 ULONG Green,
66 ULONG Blue);
67 HPALETTE FASTCALL PALETTE_AllocPaletteIndexedRGB(ULONG NumColors,
68 CONST RGBQUAD *Colors);
69 #define PALETTE_FreePalette(pPalette) GDIOBJ_FreeObj((POBJ)pPalette, GDIObjType_PAL_TYPE)
70 #define PALETTE_FreePaletteByHandle(hPalette) GDIOBJ_FreeObjByHandle((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE)
71 #define PALETTE_LockPalette(hPalette) ((PPALETTE)GDIOBJ_LockObj((HGDIOBJ)hPalette, GDI_OBJECT_TYPE_PALETTE))
72 #define PALETTE_UnlockPalette(pPalette) GDIOBJ_UnlockObjByPtr((POBJ)pPalette)
73
74 #define PALETTE_ShareLockPalette(hpal) \
75 ((PPALETTE)GDIOBJ_ShareLockObj((HGDIOBJ)hpal, GDI_OBJECT_TYPE_PALETTE))
76 #define PALETTE_ShareUnlockPalette(ppal) \
77 GDIOBJ_ShareUnlockObjByPtr(&ppal->BaseObject)
78
79 BOOL INTERNAL_CALL PALETTE_Cleanup(PVOID ObjectBody);
80
81 HPALETTE FASTCALL PALETTE_Init (VOID);
82 VOID FASTCALL PALETTE_ValidateFlags (PALETTEENTRY* lpPalE, INT size);
83 #ifndef NO_MAPPING
84 INT APIENTRY PALETTE_SetMapping(PALOBJ* palPtr, UINT uStart, UINT uNum, BOOL mapOnly);
85 #endif
86 INT FASTCALL PALETTE_ToPhysical (PDC dc, COLORREF color);
87
88 INT FASTCALL PALETTE_GetObject(PPALETTE pGdiObject, INT cbCount, LPLOGBRUSH lpBuffer);
89 ULONG NTAPI PALETTE_ulGetNearestPaletteIndex(PALETTE* ppal, ULONG iColor);
90 ULONG NTAPI PALETTE_ulGetNearestIndex(PALETTE* ppal, ULONG iColor);
91 VOID NTAPI PALETTE_vGetBitMasks(PPALETTE ppal, PULONG pulColors);
92
93 PPALETTEENTRY FASTCALL ReturnSystemPalette (VOID);
94 HPALETTE FASTCALL GdiSelectPalette(HDC, HPALETTE, BOOL);
95
96 ULONG
97 FORCEINLINE
98 CalculateShift(ULONG ulMask1, ULONG ulMask2)
99 {
100 ULONG ulShift1, ulShift2;
101 BitScanReverse(&ulShift1, ulMask1);
102 BitScanReverse(&ulShift2, ulMask2);
103 ulShift2 -= ulShift1;
104 if ((INT)ulShift2 < 0) ulShift2 += 32;
105 return ulShift2;
106 }
107
108 FORCEINLINE
109 ULONG
110 PALETTE_ulGetRGBColorFromIndex(PPALETTE ppal, ULONG ulIndex)
111 {
112 return RGB(ppal->IndexedColors[ulIndex].peRed,
113 ppal->IndexedColors[ulIndex].peGreen,
114 ppal->IndexedColors[ulIndex].peBlue);
115 }
116
117 #endif /* not _WIN32K_PALETTE_H */