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