[GDI32]: Don't destroy the heap when calling GetSystemPaletteEntries. Note to whoever...
[reactos.git] / reactos / dll / win32 / gdi32 / objects / palette.c
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(HDC hDC) /* [in] Handle of device context */
139 {
140 #if 0
141 // Handle something other than a normal dc object.
142 if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)
143 {
144 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
145 return MFDRV_(hDC);
146 else
147 {
148 HPALETTE Pal = GetDCObject(hDC, GDI_OBJECT_TYPE_PALETTE);
149 PLDC pLDC = GdiGetLDC((HDC) Pal);
150 if ( !pLDC ) return FALSE;
151 if (pLDC->iType == LDC_EMFLDC) return EMFDRV_(Pal);
152 return FALSE;
153 }
154 }
155 #endif
156 return UserRealizePalette(hDC);
157 }
158
159 /*
160 * @implemented
161 */
162 BOOL
163 WINAPI
164 ResizePalette(
165 HPALETTE hPalette,
166 UINT nEntries
167 )
168 {
169 return NtGdiResizePalette(hPalette, nEntries);
170 }
171
172 /*
173 * @implemented
174 */
175 UINT
176 WINAPI
177 SetDIBColorTable(HDC hDC,
178 UINT iStartIndex,
179 UINT cEntries,
180 const RGBQUAD *pColors)
181 {
182 UINT retValue=0;
183
184 if (cEntries)
185 {
186 retValue = NtGdiDoPalette(hDC, iStartIndex, cEntries, (RGBQUAD*)pColors, GdiPalSetColorTable, TRUE);
187 }
188
189 return retValue;
190 }
191
192 /*
193 * @implemented
194 */
195 BOOL
196 WINAPI
197 UpdateColors(
198 HDC hdc
199 )
200 {
201 ((PW32CLIENTINFO)NtCurrentTeb()->Win32ClientInfo)->cSpins = 0;
202 return NtGdiUpdateColors(hdc);
203 }
204
205 /* EOF */