1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS api tests
3c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4c2c66affSColin Finck * PURPOSE: Test for NtGdiCreateDIBSection
5c2c66affSColin Finck * PROGRAMMERS:
6c2c66affSColin Finck */
7c2c66affSColin Finck
8*a5c3bb5bSSerge Gautherie #include "../win32nt.h"
9c2c66affSColin Finck
10c2c66affSColin Finck /*
11c2c66affSColin Finck HBITMAP
12c2c66affSColin Finck APIENTRY
13c2c66affSColin Finck NtGdiCreateDIBSection(
14c2c66affSColin Finck IN HDC hDC,
15c2c66affSColin Finck IN OPTIONAL HANDLE hSection,
16c2c66affSColin Finck IN DWORD dwOffset,
17c2c66affSColin Finck IN LPBITMAPINFO pbmi,
18c2c66affSColin Finck IN DWORD iUsage,
19c2c66affSColin Finck IN UINT cjHeader,
20c2c66affSColin Finck IN FLONG fl,
21c2c66affSColin Finck IN ULONG_PTR dwColorSpace,
22c2c66affSColin Finck OUT PVOID *ppvBits)
23c2c66affSColin Finck */
24c2c66affSColin Finck
25c2c66affSColin Finck ULONG
GetBitmapSize(BITMAPINFOHEADER * pbih)26c2c66affSColin Finck GetBitmapSize(BITMAPINFOHEADER *pbih)
27c2c66affSColin Finck {
28c2c66affSColin Finck ULONG WidthBits, WidthBytes;
29c2c66affSColin Finck
30c2c66affSColin Finck WidthBits = pbih->biWidth * pbih->biBitCount * pbih->biPlanes;
31c2c66affSColin Finck WidthBytes = ((WidthBits + 31) & ~ 31) >> 3;
32c2c66affSColin Finck
33c2c66affSColin Finck return pbih->biHeight * WidthBytes;
34c2c66affSColin Finck }
35c2c66affSColin Finck
36c2c66affSColin Finck
START_TEST(NtGdiCreateDIBSection)37c2c66affSColin Finck START_TEST(NtGdiCreateDIBSection)
38c2c66affSColin Finck {
39c2c66affSColin Finck HBITMAP hbmp;
40c2c66affSColin Finck HDC hDC;
41c2c66affSColin Finck ULONG cjHeader;
42c2c66affSColin Finck PVOID pvBits = NULL;
43c2c66affSColin Finck ULONG cEntries;
44c2c66affSColin Finck DIBSECTION dibsection;
45c2c66affSColin Finck
46c2c66affSColin Finck struct
47c2c66affSColin Finck {
48c2c66affSColin Finck BITMAPINFOHEADER bmiHeader;
49c2c66affSColin Finck RGBQUAD bmiColors[100];
50c2c66affSColin Finck } bmi;
51c2c66affSColin Finck PBITMAPINFO pbmi = (PBITMAPINFO)&bmi;
52c2c66affSColin Finck PBITMAPINFOHEADER pbih = (PBITMAPINFOHEADER)&bmi.bmiHeader;
53c2c66affSColin Finck PBITMAPV4HEADER pbV4h = (PBITMAPV4HEADER)&bmi.bmiHeader;
54c2c66affSColin Finck PBITMAPV5HEADER pbV5h = (PBITMAPV5HEADER)&bmi.bmiHeader;
55c2c66affSColin Finck
56c2c66affSColin Finck HANDLE hSection;
57c2c66affSColin Finck NTSTATUS Status;
58c2c66affSColin Finck LARGE_INTEGER MaximumSize;
59c2c66affSColin Finck
60c2c66affSColin Finck hDC = GetDC(0);
61c2c66affSColin Finck pbih->biSize = sizeof(BITMAPINFOHEADER);
62c2c66affSColin Finck pbih->biWidth = 2;
63c2c66affSColin Finck pbih->biHeight = 2;
64c2c66affSColin Finck pbih->biPlanes = 1;
65c2c66affSColin Finck pbih->biBitCount = 1;
66c2c66affSColin Finck pbih->biCompression = BI_RGB;
67c2c66affSColin Finck pbih->biSizeImage = 0;
68c2c66affSColin Finck pbih->biXPelsPerMeter = 100;
69c2c66affSColin Finck pbih->biYPelsPerMeter = 100;
70c2c66affSColin Finck pbih->biClrUsed = 2;
71c2c66affSColin Finck pbih->biClrImportant = 2;
72c2c66affSColin Finck
73c2c66affSColin Finck cEntries = 0;
74c2c66affSColin Finck
75c2c66affSColin Finck /** iUsage = 0 (DIB_RGB_COLORS) ***********************************************/
76c2c66affSColin Finck
77c2c66affSColin Finck cjHeader = bmi.bmiHeader.biSize + cEntries * 4 + 8;
78c2c66affSColin Finck
79c2c66affSColin Finck /* Test something simple */
80c2c66affSColin Finck SetLastError(0);
81c2c66affSColin Finck pvBits = 0;
82c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
83c2c66affSColin Finck TEST(pvBits != NULL);
84c2c66affSColin Finck TEST(hbmp != 0);
85c2c66affSColin Finck // TEST(GetLastError() == 0);
86c2c66affSColin Finck TEST(GetObject(hbmp, sizeof(DIBSECTION), &dibsection) == sizeof(DIBSECTION));
87c2c66affSColin Finck TEST(dibsection.dsBitfields[0] == 0);
88c2c66affSColin Finck TEST(dibsection.dsBitfields[1] == 0);
89c2c66affSColin Finck TEST(dibsection.dsBitfields[2] == 0);
90c2c66affSColin Finck TEST(dibsection.dshSection == 0);
91c2c66affSColin Finck TEST(dibsection.dsOffset == 0);
92c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
93c2c66affSColin Finck
94c2c66affSColin Finck
95c2c66affSColin Finck /* Test a 0 HDC */
966cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
97c2c66affSColin Finck pvBits = 0;
98c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(0, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
99c2c66affSColin Finck TEST(pvBits != NULL);
100c2c66affSColin Finck TEST(hbmp != 0);
1016cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
102c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
103c2c66affSColin Finck
104c2c66affSColin Finck /* Test a wrong HDC */
1056cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
106c2c66affSColin Finck pvBits = 0;
10742d2d5ecSTimo Kreuzer hbmp = NtGdiCreateDIBSection((HDC)(LONG_PTR)0xdeadbeef, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
108c2c66affSColin Finck TEST(pvBits != 0);
109c2c66affSColin Finck TEST(hbmp != 0);
1106cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
111c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
112c2c66affSColin Finck
113c2c66affSColin Finck /* Test pbmi = NULL */
114c2c66affSColin Finck SetLastError(0);
115c2c66affSColin Finck pvBits = (PVOID)-1;
116c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, NULL, 0, cjHeader, 0, 0, &pvBits);
117c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
118c2c66affSColin Finck TEST(hbmp == 0);
119c2c66affSColin Finck TEST(GetLastError() == 0);
120c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
121c2c66affSColin Finck
122c2c66affSColin Finck /* Test invalid pbmi */
123c2c66affSColin Finck SetLastError(0);
124c2c66affSColin Finck pvBits = (PVOID)-1;
12542d2d5ecSTimo Kreuzer hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, (PVOID)(LONG_PTR)0x80001234, 0, cjHeader, 0, 0, &pvBits);
126c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
127c2c66affSColin Finck TEST(hbmp == 0);
128c2c66affSColin Finck TEST(GetLastError() == ERROR_INVALID_PARAMETER);
129c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
130c2c66affSColin Finck
131c2c66affSColin Finck /* Test invalid pbmi */
132c2c66affSColin Finck SetLastError(0);
133c2c66affSColin Finck pvBits = (PVOID)-1;
13442d2d5ecSTimo Kreuzer hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, (PVOID)(LONG_PTR)1, 0, cjHeader, 0, 0, &pvBits);
135c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
136c2c66affSColin Finck TEST(hbmp == 0);
137c2c66affSColin Finck TEST(GetLastError() == ERROR_INVALID_PARAMETER);
138c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
139c2c66affSColin Finck
140c2c66affSColin Finck /* Test ppvBits = NULL */
141c2c66affSColin Finck SetLastError(0);
142c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(0, NULL, 0, pbmi, 0, cjHeader, 0, 0, NULL);
143c2c66affSColin Finck TEST(hbmp == 0);
144c2c66affSColin Finck TEST(GetLastError() == ERROR_INVALID_PARAMETER);
145c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
146c2c66affSColin Finck
147c2c66affSColin Finck /* Test ppvBits = NULL and pbmi == 0*/
148c2c66affSColin Finck SetLastError(0);
149c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(0, NULL, 0, NULL, 0, cjHeader, 0, 0, NULL);
150c2c66affSColin Finck TEST(hbmp == 0);
151c2c66affSColin Finck TEST(GetLastError() == 0);
152c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
153c2c66affSColin Finck
154c2c66affSColin Finck /* Test ppvBits = NULL and wrong cjHeader */
155c2c66affSColin Finck SetLastError(0);
156c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(0, NULL, 0, pbmi, 0, cjHeader+4, 0, 0, NULL);
157c2c66affSColin Finck TEST(hbmp == 0);
158c2c66affSColin Finck TEST(GetLastError() == 0);
159c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
160c2c66affSColin Finck
161c2c66affSColin Finck /* Test ppvBits = NULL and cjHeader = 0 */
162c2c66affSColin Finck SetLastError(0);
163c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(0, NULL, 0, pbmi, 0, 0, 0, 0, NULL);
164c2c66affSColin Finck TEST(hbmp == 0);
165c2c66affSColin Finck TEST(GetLastError() == 0);
166c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
167c2c66affSColin Finck
168c2c66affSColin Finck /* Test wrong cjHeader */
169c2c66affSColin Finck SetLastError(0);
170c2c66affSColin Finck pvBits = (PVOID)-1;
171c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader+4, 0, 0, &pvBits);
172c2c66affSColin Finck pvBits = (PVOID)-1;
173c2c66affSColin Finck TEST(hbmp == 0);
174c2c66affSColin Finck TEST(GetLastError() == 0);
175c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
176c2c66affSColin Finck
177c2c66affSColin Finck /* Test different bitcount */
178c2c66affSColin Finck pbih->biBitCount = 4;
179c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
180c2c66affSColin Finck TEST(hbmp != 0);
181c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
182c2c66affSColin Finck
183c2c66affSColin Finck pbih->biBitCount = 8;
184c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
185c2c66affSColin Finck TEST(hbmp != 0);
186c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
187c2c66affSColin Finck
188c2c66affSColin Finck cjHeader = pbih->biSize;
189c2c66affSColin Finck pbih->biBitCount = 16;
190c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
191c2c66affSColin Finck TEST(hbmp != 0);
192c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
193c2c66affSColin Finck
194c2c66affSColin Finck pbih->biBitCount = 24;
195c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
196c2c66affSColin Finck TEST(hbmp != 0);
197c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
198c2c66affSColin Finck
199c2c66affSColin Finck pbih->biBitCount = 32;
200c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
201c2c66affSColin Finck TEST(hbmp != 0);
202c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
203c2c66affSColin Finck
204c2c66affSColin Finck /* Test BI_BITFIELDS */
205c2c66affSColin Finck cEntries = 3;
206c2c66affSColin Finck cjHeader = pbih->biSize + cEntries * sizeof(DWORD);
207c2c66affSColin Finck pbih->biBitCount = 16;
208c2c66affSColin Finck pbih->biCompression = BI_BITFIELDS;
209c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[0] = 0x0007;
210c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[1] = 0x0038;
211c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[2] = 0x01C0;
212c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
213c2c66affSColin Finck TEST(hbmp != 0);
214c2c66affSColin Finck TEST(GetObject(hbmp, sizeof(DIBSECTION), &dibsection) == sizeof(DIBSECTION));
215c2c66affSColin Finck TEST(dibsection.dsBm.bmType == 0);
216c2c66affSColin Finck TEST(dibsection.dsBm.bmWidth == 2);
217c2c66affSColin Finck TEST(dibsection.dsBm.bmHeight == 2);
218c2c66affSColin Finck TEST(dibsection.dsBm.bmWidthBytes == 4);
219c2c66affSColin Finck TEST(dibsection.dsBm.bmPlanes == 1);
220c2c66affSColin Finck TEST(dibsection.dsBm.bmBitsPixel == 16);
221c2c66affSColin Finck TEST(dibsection.dsBm.bmBits == pvBits);
222c2c66affSColin Finck TEST(dibsection.dsBmih.biSize == sizeof(BITMAPINFOHEADER));
223c2c66affSColin Finck TEST(dibsection.dsBmih.biWidth == 2);
224c2c66affSColin Finck TEST(dibsection.dsBmih.biHeight == 2);
225c2c66affSColin Finck TEST(dibsection.dsBmih.biPlanes == 1);
226c2c66affSColin Finck TEST(dibsection.dsBmih.biBitCount == 16);
227c2c66affSColin Finck TEST(dibsection.dsBmih.biCompression == BI_BITFIELDS);
228c2c66affSColin Finck TEST(dibsection.dsBmih.biSizeImage == 8);
229c2c66affSColin Finck TEST(dibsection.dsBmih.biXPelsPerMeter == 0);
230c2c66affSColin Finck TEST(dibsection.dsBmih.biYPelsPerMeter == 0);
231c2c66affSColin Finck TEST(dibsection.dsBmih.biClrUsed == 0);
232c2c66affSColin Finck TEST(dibsection.dsBmih.biClrImportant == 0);
233c2c66affSColin Finck TEST(dibsection.dsBitfields[0] == 0x0007);
234c2c66affSColin Finck TEST(dibsection.dsBitfields[1] == 0x0038);
235c2c66affSColin Finck TEST(dibsection.dsBitfields[2] == 0x01C0);
236c2c66affSColin Finck TEST(dibsection.dshSection == 0);
237c2c66affSColin Finck TEST(dibsection.dsOffset == 0);
238c2c66affSColin Finck
239c2c66affSColin Finck printf("dib with bitfileds: %p\n", hbmp);
240c2c66affSColin Finck //system("PAUSE");
241c2c66affSColin Finck
242c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
243c2c66affSColin Finck
244c2c66affSColin Finck
245c2c66affSColin Finck /* Test BI_BITFIELDS */
246c2c66affSColin Finck SetLastError(0);
247c2c66affSColin Finck pvBits = 0;
248c2c66affSColin Finck
249c2c66affSColin Finck pbih->biSize = sizeof(BITMAPINFOHEADER);
250c2c66affSColin Finck pbih->biWidth = 2;
251c2c66affSColin Finck pbih->biHeight = 2;
252c2c66affSColin Finck pbih->biPlanes = 1;
253c2c66affSColin Finck pbih->biBitCount = 4;
254c2c66affSColin Finck pbih->biCompression = BI_RGB;
255c2c66affSColin Finck pbih->biSizeImage = 0;
256c2c66affSColin Finck pbih->biXPelsPerMeter = 100;
257c2c66affSColin Finck pbih->biYPelsPerMeter = 100;
258c2c66affSColin Finck pbih->biClrUsed = 0;
259c2c66affSColin Finck pbih->biClrImportant = 0;
260c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[0] = 0xF800;
261c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[1] = 0x00ff00;
262c2c66affSColin Finck ((DWORD*)pbmi->bmiColors)[2] = 0x0000ff;
263c2c66affSColin Finck cEntries = 0;
264c2c66affSColin Finck cjHeader = bmi.bmiHeader.biSize + cEntries * 4 + 20;
265c2c66affSColin Finck
266c2c66affSColin Finck
267c2c66affSColin Finck /** iUsage = 1 (DIB_PAL_COLORS) ***********************************************/
268c2c66affSColin Finck
269c2c66affSColin Finck pbmi->bmiHeader.biClrUsed = 2;
270c2c66affSColin Finck pbmi->bmiHeader.biClrImportant = 2;
271c2c66affSColin Finck
272c2c66affSColin Finck cEntries = 2;
273c2c66affSColin Finck cjHeader = bmi.bmiHeader.biSize + cEntries * 4 + 8;
274c2c66affSColin Finck
275c2c66affSColin Finck /* Test iUsage = 1 */
276c2c66affSColin Finck SetLastError(0);
277c2c66affSColin Finck pvBits = (PVOID)-1;
278c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 1, cjHeader, 0, 0, &pvBits);
279c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
280c2c66affSColin Finck TEST(hbmp == 0);
281c2c66affSColin Finck TEST(GetLastError() == 0);
282c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
283c2c66affSColin Finck
284c2c66affSColin Finck
285c2c66affSColin Finck
286c2c66affSColin Finck /** iUsage = 2 (???) **********************************************************/
287c2c66affSColin Finck
288c2c66affSColin Finck /* Test iUsage = 2 */
289c2c66affSColin Finck SetLastError(0);
290c2c66affSColin Finck pvBits = (PVOID)-1;
291c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 2, cjHeader, 0, 0, &pvBits);
292c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
293c2c66affSColin Finck TEST(hbmp == 0);
294c2c66affSColin Finck TEST(GetLastError() == 0);
295c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
296c2c66affSColin Finck
297c2c66affSColin Finck
298c2c66affSColin Finck /** wrong iUsage **************************************************************/
299c2c66affSColin Finck
300c2c66affSColin Finck cEntries = 0;
301c2c66affSColin Finck cjHeader = bmi.bmiHeader.biSize + cEntries * 4 + 8;
302c2c66affSColin Finck
303c2c66affSColin Finck /* Test iUsage = 3 */
304c2c66affSColin Finck SetLastError(0);
305c2c66affSColin Finck pvBits = (PVOID)-1;
306c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 3, cjHeader, 0, 0, &pvBits);
307c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
308c2c66affSColin Finck TEST(hbmp == 0);
309c2c66affSColin Finck TEST(GetLastError() == ERROR_INVALID_PARAMETER);
310c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
311c2c66affSColin Finck
312c2c66affSColin Finck /* Test iUsage = 3 */
313c2c66affSColin Finck SetLastError(0);
314c2c66affSColin Finck pvBits = (PVOID)-1;
315c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 3, cjHeader+4, 0, 0, &pvBits);
316c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
317c2c66affSColin Finck TEST(hbmp == 0);
318c2c66affSColin Finck TEST(GetLastError() == 0);
319c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
320c2c66affSColin Finck
321c2c66affSColin Finck /* Test wrong iUsage */
322c2c66affSColin Finck SetLastError(0);
323c2c66affSColin Finck pvBits = (PVOID)-1;
324c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, -55, cjHeader, 0, 0, &pvBits);
325c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
326c2c66affSColin Finck TEST(hbmp == 0);
327c2c66affSColin Finck TEST(GetLastError() == ERROR_INVALID_PARAMETER);
328c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
329c2c66affSColin Finck
330c2c66affSColin Finck /* Test wrong iUsage and wrong cjHeader */
331c2c66affSColin Finck SetLastError(0);
332c2c66affSColin Finck pvBits = (PVOID)-1;
333c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, -55, cjHeader+4, 0, 0, &pvBits);
334c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
335c2c66affSColin Finck TEST(hbmp == 0);
336c2c66affSColin Finck TEST(GetLastError() == 0);
337c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
338c2c66affSColin Finck
339c2c66affSColin Finck /* increased header size */
340c2c66affSColin Finck pbih->biSize = sizeof(BITMAPINFOHEADER) + 4;
341c2c66affSColin Finck cjHeader = pbih->biSize + cEntries * 4 + 8;
3426cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
343c2c66affSColin Finck pvBits = 0;
344c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
345c2c66affSColin Finck TEST(pvBits != NULL);
346c2c66affSColin Finck TEST(hbmp != 0);
3476cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
348c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
349c2c66affSColin Finck
350c2c66affSColin Finck /* increased header size */
351c2c66affSColin Finck pbih->biSize = sizeof(BITMAPINFOHEADER) + 2;
352c2c66affSColin Finck cjHeader = pbih->biSize + cEntries * 4 + 8;
353c2c66affSColin Finck SetLastError(0);
354c2c66affSColin Finck pvBits = (PVOID)-1;
355c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
356c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
357c2c66affSColin Finck TEST(hbmp == 0);
358c2c66affSColin Finck TEST(GetLastError() == 0);
359c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
360c2c66affSColin Finck
361c2c66affSColin Finck /* decreased header size */
362c2c66affSColin Finck pbih->biSize = sizeof(BITMAPINFOHEADER) - 4;
363c2c66affSColin Finck cjHeader = pbih->biSize + cEntries * 4 + 8;
364c2c66affSColin Finck SetLastError(0);
365c2c66affSColin Finck pvBits = (PVOID)-1;
366c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
367c2c66affSColin Finck TEST(pvBits == (PVOID)-1);
368c2c66affSColin Finck TEST(hbmp == 0);
369c2c66affSColin Finck TEST(GetLastError() == 0);
370c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
371c2c66affSColin Finck
372c2c66affSColin Finck
373c2c66affSColin Finck /** BITMAPV4HEADER ************************************************************/
374c2c66affSColin Finck
375c2c66affSColin Finck pbV4h->bV4Size = sizeof(BITMAPV4HEADER);
376c2c66affSColin Finck pbV4h->bV4Width = 2;
377c2c66affSColin Finck pbV4h->bV4Height = 3;
378c2c66affSColin Finck pbV4h->bV4Planes = 1;
379c2c66affSColin Finck pbV4h->bV4BitCount = 1;
380c2c66affSColin Finck pbV4h->bV4V4Compression = BI_RGB;
381c2c66affSColin Finck pbV4h->bV4SizeImage = 0;
382c2c66affSColin Finck pbV4h->bV4XPelsPerMeter = 100;
383c2c66affSColin Finck pbV4h->bV4YPelsPerMeter = 100;
384c2c66affSColin Finck pbV4h->bV4ClrUsed = 0;
385c2c66affSColin Finck pbV4h->bV4ClrImportant = 0;
386c2c66affSColin Finck pbV4h->bV4RedMask = 0;
387c2c66affSColin Finck pbV4h->bV4GreenMask = 0;
388c2c66affSColin Finck pbV4h->bV4BlueMask = 0;
389c2c66affSColin Finck pbV4h->bV4AlphaMask = 0;
390c2c66affSColin Finck pbV4h->bV4CSType = 0;
391c2c66affSColin Finck memset(&pbV4h->bV4Endpoints, 0, sizeof(CIEXYZTRIPLE));
392c2c66affSColin Finck pbV4h->bV4GammaRed = 0;
393c2c66affSColin Finck pbV4h->bV4GammaGreen = 0;
394c2c66affSColin Finck pbV4h->bV4GammaBlue = 0;
395c2c66affSColin Finck
396c2c66affSColin Finck cEntries = 0;
397c2c66affSColin Finck cjHeader = bmi.bmiHeader.biSize + cEntries * 4 + 8;
398c2c66affSColin Finck
399c2c66affSColin Finck /* Test something simple */
4006cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
401c2c66affSColin Finck pvBits = 0;
402c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
403c2c66affSColin Finck TEST(pvBits != NULL);
404c2c66affSColin Finck TEST(hbmp != 0);
4056cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
406c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
407c2c66affSColin Finck
408c2c66affSColin Finck
409c2c66affSColin Finck /** BITMAPV5HEADER ************************************************************/
410c2c66affSColin Finck
411c2c66affSColin Finck pbV5h->bV5Size = sizeof(BITMAPV5HEADER);
412c2c66affSColin Finck pbV5h->bV5Width = 2;
413c2c66affSColin Finck pbV5h->bV5Height = 3;
414c2c66affSColin Finck pbV5h->bV5Planes = 1;
415c2c66affSColin Finck pbV5h->bV5BitCount = 1;
416c2c66affSColin Finck pbV5h->bV5Compression = BI_RGB;
417c2c66affSColin Finck pbV5h->bV5SizeImage = 0;
418c2c66affSColin Finck pbV5h->bV5XPelsPerMeter = 100;
419c2c66affSColin Finck pbV5h->bV5YPelsPerMeter = 100;
420c2c66affSColin Finck pbV5h->bV5ClrUsed = 2;
421c2c66affSColin Finck pbV5h->bV5ClrImportant = 2;
422c2c66affSColin Finck pbV5h->bV5RedMask = 0;
423c2c66affSColin Finck pbV5h->bV5GreenMask = 0;
424c2c66affSColin Finck pbV5h->bV5BlueMask = 0;
425c2c66affSColin Finck pbV5h->bV5AlphaMask = 0;
426c2c66affSColin Finck pbV5h->bV5CSType = 0;
427c2c66affSColin Finck memset(&pbV5h->bV5Endpoints, 0, sizeof(CIEXYZTRIPLE));
428c2c66affSColin Finck pbV5h->bV5GammaRed = 0;
429c2c66affSColin Finck pbV5h->bV5GammaGreen = 0;
430c2c66affSColin Finck pbV5h->bV5GammaBlue = 0;
431c2c66affSColin Finck pbV5h->bV5Intent = 0;
432c2c66affSColin Finck pbV5h->bV5ProfileData = 0;
433c2c66affSColin Finck pbV5h->bV5ProfileSize = 0;
434c2c66affSColin Finck pbV5h->bV5Reserved = 0;
435c2c66affSColin Finck
436c2c66affSColin Finck cEntries = 0;
437c2c66affSColin Finck cjHeader = pbV5h->bV5Size + cEntries * 4 + 8;
438c2c66affSColin Finck
439c2c66affSColin Finck /* Test something simple */
4406cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
441c2c66affSColin Finck pvBits = 0;
442c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
443c2c66affSColin Finck TEST(pvBits != NULL);
444c2c66affSColin Finck TEST(hbmp != 0);
4456cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
446c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
447c2c66affSColin Finck
448c2c66affSColin Finck /* increased header size */
449c2c66affSColin Finck pbV5h->bV5Size = sizeof(BITMAPV5HEADER) + 64;
450c2c66affSColin Finck cjHeader = pbV5h->bV5Size + cEntries * 4 + 8;
4516cad84a7STimo Kreuzer SetLastError(0xdeadbeef);
452c2c66affSColin Finck pvBits = 0;
453c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, NULL, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
454c2c66affSColin Finck TEST(pvBits != NULL);
455c2c66affSColin Finck TEST(hbmp != 0);
4566cad84a7STimo Kreuzer ok_hex(GetLastError(), 0xdeadbeef);
457c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
458c2c66affSColin Finck
459c2c66affSColin Finck /* Test section */
460c2c66affSColin Finck MaximumSize.QuadPart = 4096;
461c2c66affSColin Finck Status = NtCreateSection(&hSection,
462c2c66affSColin Finck SECTION_ALL_ACCESS,
463c2c66affSColin Finck NULL,
464c2c66affSColin Finck &MaximumSize,
465c2c66affSColin Finck PAGE_READWRITE,
466c2c66affSColin Finck SEC_COMMIT,
467c2c66affSColin Finck NULL);
468c2c66affSColin Finck ASSERT(NT_SUCCESS(Status));
469c2c66affSColin Finck
470c2c66affSColin Finck SetLastError(0);
471c2c66affSColin Finck pvBits = 0;
472c2c66affSColin Finck hbmp = NtGdiCreateDIBSection(hDC, hSection, 0, pbmi, 0, cjHeader, 0, 0, &pvBits);
473c2c66affSColin Finck TEST(pvBits != NULL);
474c2c66affSColin Finck TEST(hbmp != 0);
475c2c66affSColin Finck // TEST(GetLastError() == 0);
476c2c66affSColin Finck printf("hbmp = %p, pvBits = %p, hSection = %p\n", hbmp, pvBits, hSection);
477c2c66affSColin Finck //system("PAUSE");
478c2c66affSColin Finck if (hbmp) DeleteObject(hbmp);
479c2c66affSColin Finck }
480