xref: /reactos/win32ss/gdi/gdi32/objects/palette.c (revision 7353af1e)
1 #include <precomp.h>
2 
3 #define NDEBUG
4 #include <debug.h>
5 
6 
7 #define NB_RESERVED_COLORS  20   /* number of fixed colors in system palette */
8 
9 static const PALETTEENTRY sys_pal_template[NB_RESERVED_COLORS] =
10 {
11     /* first 10 entries in the system palette */
12     /* red  green blue  flags */
13     { 0x00, 0x00, 0x00, 0 },
14     { 0x80, 0x00, 0x00, 0 },
15     { 0x00, 0x80, 0x00, 0 },
16     { 0x80, 0x80, 0x00, 0 },
17     { 0x00, 0x00, 0x80, 0 },
18     { 0x80, 0x00, 0x80, 0 },
19     { 0x00, 0x80, 0x80, 0 },
20     { 0xc0, 0xc0, 0xc0, 0 },
21     { 0xc0, 0xdc, 0xc0, 0 },
22     { 0xa6, 0xca, 0xf0, 0 },
23 
24     /* ... c_min/2 dynamic colorcells */
25 
26     /* ... gap (for sparse palettes) */
27 
28     /* ... c_min/2 dynamic colorcells */
29 
30     { 0xff, 0xfb, 0xf0, 0 },
31     { 0xa0, 0xa0, 0xa4, 0 },
32     { 0x80, 0x80, 0x80, 0 },
33     { 0xff, 0x00, 0x00, 0 },
34     { 0x00, 0xff, 0x00, 0 },
35     { 0xff, 0xff, 0x00, 0 },
36     { 0x00, 0x00, 0xff, 0 },
37     { 0xff, 0x00, 0xff, 0 },
38     { 0x00, 0xff, 0xff, 0 },
39     { 0xff, 0xff, 0xff, 0 }     /* last 10 */
40 };
41 
42 BOOL
43 WINAPI
44 AnimatePalette(HPALETTE hpal,
45                UINT iStartIndex,
46                UINT cEntries,
47                const PALETTEENTRY *ppe)
48 {
49     return NtGdiDoPalette(hpal, iStartIndex, cEntries, (PALETTEENTRY*)ppe, GdiPalAnimate, TRUE);
50 }
51 
52 HPALETTE
53 WINAPI
54 CreatePalette(CONST LOGPALETTE * plpal)
55 {
56     return NtGdiCreatePaletteInternal((LPLOGPALETTE)plpal, plpal->palNumEntries);
57 }
58 
59 /*
60  * @implemented
61  */
62 UINT
63 WINAPI
64 GetPaletteEntries(HPALETTE hpal,
65                   UINT iStartIndex,
66                   UINT cEntries,
67                   LPPALETTEENTRY ppe)
68 {
69     return NtGdiDoPalette(hpal, iStartIndex, cEntries, ppe, GdiPalGetEntries, FALSE);
70 }
71 
72 UINT
73 WINAPI
74 SetPaletteEntries(HPALETTE hpal,
75                   UINT iStartIndex,
76                   UINT cEntries,
77                   const PALETTEENTRY *ppe)
78 {
79     return NtGdiDoPalette(hpal, iStartIndex, cEntries, (PALETTEENTRY*)ppe, GdiPalSetEntries, TRUE);
80 }
81 
82 UINT
83 WINAPI
84 GetSystemPaletteEntries(HDC hDC,
85                         UINT iStartIndex,
86                         UINT cEntries,
87                         LPPALETTEENTRY ppe)
88 {
89     PALETTEENTRY ippe[256];
90 
91     if ((INT)cEntries >= 0)
92     {
93         if (GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)
94         {
95             return NtGdiDoPalette(hDC,
96                                   iStartIndex,
97                                   cEntries,
98                                   ppe,
99                                   GdiPalGetSystemEntries,
100                                   FALSE);
101         }
102         else if (ppe)
103         {
104             RtlCopyMemory(ippe, sys_pal_template, 10 * sizeof(PALETTEENTRY));
105             RtlCopyMemory(&ippe[246], &sys_pal_template[10], 10 * sizeof(PALETTEENTRY));
106             RtlZeroMemory(&ippe[10], sizeof(ippe) - 20 * sizeof(PALETTEENTRY));
107 
108             if (iStartIndex < 256)
109             {
110                 RtlCopyMemory(ppe,
111                               &ippe[iStartIndex],
112                               min(256 - iStartIndex, cEntries) *
113                               sizeof(PALETTEENTRY));
114             }
115         }
116     }
117 
118     return 0;
119 }
120 
121 UINT
122 WINAPI
123 GetDIBColorTable(HDC hDC,
124                  UINT iStartIndex,
125                  UINT cEntries,
126                  RGBQUAD *pColors)
127 {
128     if (cEntries)
129         return NtGdiDoPalette(hDC, iStartIndex, cEntries, pColors, GdiPalGetColorTable, FALSE);
130     return 0;
131 }
132 
133 /*
134  * @implemented
135  */
136 UINT
137 WINAPI
138 RealizePalette(
139     _In_ HDC hdc) /* [in] Handle of device context */
140 {
141     if (GDI_HANDLE_GET_TYPE(hdc) == GDILoObjType_LO_METADC16_TYPE)
142     {
143        return METADC_RealizePalette(hdc);
144     }
145 
146     if (GDI_HANDLE_GET_TYPE(hdc) != GDILoObjType_LO_DC_TYPE)
147     {
148         return GDI_ERROR;
149     }
150 
151     return UserRealizePalette(hdc);
152 }
153 
154 /*
155  * @implemented
156  */
157 BOOL
158 WINAPI
159 ResizePalette(
160     HPALETTE	hPalette,
161     UINT		nEntries
162 )
163 {
164     return NtGdiResizePalette(hPalette, nEntries);
165 }
166 
167 /*
168  * @implemented
169  */
170 UINT
171 WINAPI
172 SetDIBColorTable(HDC hDC,
173                  UINT iStartIndex,
174                  UINT cEntries,
175                  const RGBQUAD *pColors)
176 {
177     UINT retValue=0;
178 
179     if (cEntries)
180     {
181         retValue = NtGdiDoPalette(hDC, iStartIndex, cEntries, (RGBQUAD*)pColors, GdiPalSetColorTable, TRUE);
182     }
183 
184     return retValue;
185 }
186 
187 /*
188  * @implemented
189  */
190 BOOL
191 WINAPI
192 UpdateColors(
193     HDC	hdc
194 )
195 {
196     ((PW32CLIENTINFO)NtCurrentTeb()->Win32ClientInfo)->cSpins = 0;
197     return NtGdiUpdateColors(hdc);
198 }
199 
200 /*
201  * @unimplemented
202  */
203 BOOL
204 WINAPI
205 ColorCorrectPalette(HDC hDC,HPALETTE hPalette,DWORD dwFirstEntry,DWORD dwNumOfEntries)
206 {
207     UNIMPLEMENTED;
208     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
209     return 0;
210 }
211 
212 /* EOF */
213