[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / GetDIBits.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetDIBits
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11 #include "init.h"
12
13 void
14 Test_GetDIBits_xBpp(
15 ULONG cBitsPixel)
16 {
17 UCHAR ajBuffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
18 PBITMAPINFO pbmi = (PBITMAPINFO)ajBuffer;
19 HBITMAP hbmp;
20 ULONG cjSizeImage, cColors;
21 HDC hdc;
22
23 hdc = GetDC(0);
24 hbmp = CreateBitmap(3, 3, 1, cBitsPixel, NULL);
25
26 /* Fill in the size field */
27 ZeroMemory(pbmi, sizeof(ajBuffer));
28 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
29
30 /* Get info */
31 ok_int(GetDIBits(hdc, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
32 cjSizeImage = (((pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount) + 31) & ~31) * pbmi->bmiHeader.biHeight / 8;
33 cColors = cBitsPixel <= 8 ? 1 << pbmi->bmiHeader.biBitCount : 0;
34
35 ok_int(pbmi->bmiHeader.biSize, sizeof(BITMAPINFOHEADER));
36 ok_int(pbmi->bmiHeader.biWidth, 3);
37 ok_int(pbmi->bmiHeader.biHeight, 3);
38 ok_int(pbmi->bmiHeader.biPlanes, 1);
39 ok_int(pbmi->bmiHeader.biBitCount, cBitsPixel);
40 ok_int(pbmi->bmiHeader.biCompression, (cBitsPixel == 16) || (cBitsPixel == 32) ? BI_BITFIELDS : BI_RGB);
41 ok_int(pbmi->bmiHeader.biSizeImage, cjSizeImage);
42 ok_int(pbmi->bmiHeader.biXPelsPerMeter, 0);
43 ok_int(pbmi->bmiHeader.biYPelsPerMeter, 0);
44 ok_int(pbmi->bmiHeader.biClrUsed, cColors);
45 ok_int(pbmi->bmiHeader.biClrImportant, cColors);
46
47 // pbmi->bmiHeader.biSizeImage = 0;
48 //ok_int(GetDIBits(NULL, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
49
50 /* Test a bitmap with values partly set */
51 ZeroMemory(pbmi, sizeof(BITMAPINFO));
52 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
53 pbmi->bmiHeader.biWidth = 12;
54 pbmi->bmiHeader.biHeight = 14;
55 pbmi->bmiHeader.biPlanes = 2;
56 pbmi->bmiHeader.biBitCount = 0; // keep biBitCount == 0!
57 pbmi->bmiHeader.biCompression = 7;
58 pbmi->bmiHeader.biSizeImage = 123;
59 ok_int(GetDIBits(hdc, hbmp, 0, 5, NULL, pbmi, DIB_RGB_COLORS), 1);
60 ok_int(pbmi->bmiHeader.biWidth, 3);
61 ok_int(pbmi->bmiHeader.biHeight, 3);
62 ok_int(pbmi->bmiHeader.biPlanes, 1);
63 ok_int(pbmi->bmiHeader.biBitCount, cBitsPixel);
64 ok_int(pbmi->bmiHeader.biSizeImage, cjSizeImage);
65 ok_int(pbmi->bmiHeader.biXPelsPerMeter, 0);
66 ok_int(pbmi->bmiHeader.biYPelsPerMeter, 0);
67 ok_int(pbmi->bmiHeader.biClrUsed, cColors);
68 ok_int(pbmi->bmiHeader.biClrImportant, cColors);
69
70
71 #if 0
72 /* Get info including the color table */
73 ZeroMemory(pbmi, sizeof(ajBuffer));
74 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
75 pbmi->bmiHeader.biBitCount = 1;
76 ok_int(GetDIBits(NULL, hbmp, 0, 0, NULL, pbmi, DIB_PAL_COLORS), 1);
77
78 /* Check a different bit depth */
79 pbmi->bmiHeader.biBitCount, cBitsPixel = (cBitsPixel == 1) ? 8 : 1;
80 ok_int(GetDIBits(hdc, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
81 ok_int(pbmi->bmiHeader.biBitCount, (cBitsPixel == 1) ? 8 : 1);
82
83 /* Get the bits */
84 SetLastError(0);
85 ok_int(GetDIBits(hdc, hbmp, 0, 4, pvBits, pbmi, DIB_PAL_COLORS), 3);
86 ok_int(GetDIBits(hdc, hbmp, 3, 7, pvBits, pbmi, DIB_RGB_COLORS), 1);
87 ok_err(0);
88
89 pbmi->bmiHeader.biPlanes = 2;
90 pbmi->bmiHeader.biClrUsed = 0;
91 ok_int(GetDIBits(hdc, hbmp, 0, 4, pvBits, pbmi, DIB_RGB_COLORS), 3);
92 #endif
93
94 DeleteObject(hbmp);
95 ReleaseDC(NULL, hdc);
96 }
97
98 void Test_GetDIBits()
99 {
100 HDC hdcScreen, hdcMem;
101 HBITMAP hbmp;
102 PBITMAPINFO pbi;
103 PBITMAPCOREHEADER pbch;
104 PBITMAPV5HEADER pbV5Header;
105 INT ScreenBpp;
106 DWORD ajBits[100] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
107 PVOID pvBits;
108 ULONG cjSizeImage;
109
110 pbi = malloc(sizeof(BITMAPV5HEADER) + 256 * sizeof(DWORD));
111 pbch = (PVOID)pbi;
112 pbV5Header = (PVOID)pbi;
113
114 hdcScreen = GetDC(NULL);
115 ok(hdcScreen != 0, "GetDC failed, skipping tests\n");
116 if (hdcScreen == NULL) return;
117
118 hdcMem = CreateCompatibleDC(0);
119 ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n");
120 if (hdcMem == NULL) return;
121
122 hbmp = CreateCompatibleBitmap(hdcScreen, 16, 16);
123 ok(hbmp != NULL, "CreateCompatibleBitmap failed\n");
124
125 /* misc */
126 SetLastError(ERROR_SUCCESS);
127 ok(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
128 ok_err(ERROR_INVALID_PARAMETER);
129
130 SetLastError(ERROR_SUCCESS);
131 ok(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
132 ok_err(ERROR_INVALID_PARAMETER);
133
134 SetLastError(ERROR_SUCCESS);
135 ok(GetDIBits((HDC)2345, hbmp, 0, 0, NULL, NULL, 0) == 0, "\n");
136 ok_err(ERROR_INVALID_PARAMETER);
137
138 SetLastError(ERROR_SUCCESS);
139 ok(GetDIBits((HDC)2345, hbmp, 0, 15, NULL, pbi, 0) == 0, "\n");
140 ok_err(ERROR_INVALID_PARAMETER);
141
142
143
144 /* null hdc */
145 SetLastError(ERROR_SUCCESS);
146 ZeroMemory(pbi, sizeof(BITMAPINFO));
147 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
148 ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
149 ok_err(ERROR_INVALID_PARAMETER);
150
151 /* null bitmap */
152 SetLastError(ERROR_SUCCESS);
153 ZeroMemory(pbi, sizeof(BITMAPINFO));
154 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
155 ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
156 ok_err(ERROR_SUCCESS);
157
158 /* 0 scan lines */
159 SetLastError(ERROR_SUCCESS);
160 ZeroMemory(pbi, sizeof(BITMAPINFO));
161 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
162 ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
163 ok_err(ERROR_SUCCESS);
164
165 /* null bitmap info - crashes XP*/
166 //SetLastError(ERROR_SUCCESS);
167 //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
168 //ok(GetLastError() == ERROR_INVALID_PARAMETER);
169
170 /* bad bmi colours (uUsage) */
171 SetLastError(0);
172 ZeroMemory(pbi, sizeof(BITMAPINFO));
173 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
174 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n");
175 ok_err(ERROR_SUCCESS);
176 ok(pbi->bmiHeader.biWidth == 0, "\n");
177 ok(pbi->bmiHeader.biHeight == 0, "\n");
178 ok(pbi->bmiHeader.biBitCount == 0, "\n");
179 ok(pbi->bmiHeader.biSizeImage == 0, "\n");
180
181 /* basic call */
182 SetLastError(ERROR_SUCCESS);
183 ZeroMemory(pbi, sizeof(BITMAPINFO));
184 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
185 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
186 ok_err(ERROR_SUCCESS);
187 ScreenBpp = GetDeviceCaps(hdcScreen, BITSPIXEL);
188 ok(pbi->bmiHeader.biWidth == 16, "\n");
189 ok(pbi->bmiHeader.biHeight == 16, "\n");
190 ok(pbi->bmiHeader.biBitCount == ScreenBpp, "\n");
191 ok(pbi->bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8), "\n");
192
193 /* Test if COREHEADER is supported */
194 ZeroMemory(pbi, sizeof(BITMAPINFO));
195 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER);
196 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
197 ok_int(pbi->bmiHeader.biSize, sizeof(BITMAPCOREHEADER));
198 ok_int(pbch->bcWidth, 16);
199 ok_int(pbch->bcHeight, 16);
200 ok_int(pbch->bcPlanes, 1);
201 //ok_int(pbch->bcBitCount, ScreenBpp > 16 ? 24 : ScreenBpp); // fails on XP with screenbpp == 16
202
203 /* Test different header sizes */
204 ZeroMemory(pbi, sizeof(BITMAPINFO));
205 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER) + 4;
206 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 0);
207
208 ZeroMemory(pbi, sizeof(BITMAPINFO));
209 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 4;
210 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
211
212 ZeroMemory(pbi, sizeof(BITMAPINFO));
213 pbi->bmiHeader.biSize = sizeof(BITMAPV4HEADER);
214 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
215
216 ZeroMemory(pbi, sizeof(BITMAPINFO));
217 pbi->bmiHeader.biSize = sizeof(BITMAPV4HEADER) + 4;
218 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
219
220 ZeroMemory(pbi, sizeof(BITMAPINFO));
221 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER);
222 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
223
224 ZeroMemory(pbi, sizeof(BITMAPINFO));
225 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER) + 4;
226 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
227 ok_int(pbV5Header->bV5RedMask, 0);
228 ok_int(pbV5Header->bV5GreenMask, 0);
229 ok_int(pbV5Header->bV5BlueMask, 0);
230 ok_int(pbV5Header->bV5AlphaMask, 0);
231 ok_int(pbV5Header->bV5CSType, 0);
232 // CIEXYZTRIPLE bV5Endpoints;
233 ok_int(pbV5Header->bV5GammaRed, 0);
234 ok_int(pbV5Header->bV5GammaGreen, 0);
235 ok_int(pbV5Header->bV5GammaBlue, 0);
236 ok_int(pbV5Header->bV5Intent, 0);
237 ok_int(pbV5Header->bV5ProfileData, 0);
238 ok_int(pbV5Header->bV5ProfileSize, 0);
239 ok_int(pbV5Header->bV5Reserved, 0);
240
241 ZeroMemory(pbi, sizeof(BITMAPINFO));
242 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
243 ok_int(GetDIBits(hdcScreen, hbmp, 234, 43, NULL, pbi, DIB_RGB_COLORS), 1);
244
245 DeleteObject(hbmp);
246
247 /* Test a mono bitmap */
248 hbmp = CreateBitmap(13, 7, 1, 1, ajBits);
249 ok(hbmp != 0, "failed to create bitmap\n");
250 ZeroMemory(pbi, sizeof(BITMAPINFO));
251 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
252 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
253 ok_int(pbi->bmiHeader.biWidth, 13);
254 ok_int(pbi->bmiHeader.biHeight, 7);
255 ok_int(pbi->bmiHeader.biBitCount, 1);
256 ok_int(pbi->bmiHeader.biSizeImage, 28);
257
258 /* Test with values set, except biSizeImage */
259 pbi->bmiHeader.biSizeImage = 0;
260 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
261 ok_int(pbi->bmiHeader.biSizeImage, 28);
262
263 /* Test with different biWidth set */
264 pbi->bmiHeader.biWidth = 17;
265 pbi->bmiHeader.biHeight = 3;
266 pbi->bmiHeader.biSizeImage = 0;
267 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
268 ok_int(pbi->bmiHeader.biSizeImage, 12);
269 ok_int(pbi->bmiHeader.biWidth, 17);
270 ok_int(pbi->bmiHeader.biHeight, 3);
271
272 /* Test with different biBitCount set */
273 pbi->bmiHeader.biBitCount = 4;
274 pbi->bmiHeader.biSizeImage = 0;
275 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
276 ok_int(pbi->bmiHeader.biSizeImage, 36);
277 ok_int(pbi->bmiHeader.biBitCount, 4);
278
279 /* Set bitmap dimensions */
280 ok_int(SetBitmapDimensionEx(hbmp, 110, 220, NULL), 1);
281 ZeroMemory(pbi, sizeof(BITMAPINFO));
282 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
283 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
284 ok_int(pbi->bmiHeader.biXPelsPerMeter, 0);
285 ok_int(pbi->bmiHeader.biYPelsPerMeter, 0);
286
287 /* Set individual values */
288 ZeroMemory(pbi, sizeof(BITMAPINFO));
289 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
290 pbi->bmiHeader.biWidth = 12;
291 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
292 ok_int(pbi->bmiHeader.biWidth, 13);
293 ok_int(pbi->bmiHeader.biSizeImage, 28);
294
295 ZeroMemory(pbi, sizeof(BITMAPINFO));
296 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
297 pbi->bmiHeader.biSizeImage = 123;
298 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
299
300 ZeroMemory(pbi, sizeof(BITMAPINFO));
301 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
302 pbi->bmiHeader.biCompression = BI_RGB;
303 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
304
305 /* Set only biBitCount */
306 ZeroMemory(pbi, sizeof(BITMAPINFO));
307 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
308 pbi->bmiHeader.biBitCount = 5;
309 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
310 pbi->bmiHeader.biBitCount = 1;
311 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
312 pbi->bmiHeader.biBitCount = 8;
313 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
314 pbi->bmiHeader.biBitCount = 32;
315 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
316 ok_int(pbi->bmiHeader.biWidth, 0);
317 ok_int(pbi->bmiHeader.biHeight, 0);
318 ok_int(pbi->bmiHeader.biPlanes, 0);
319 ok_int(pbi->bmiHeader.biBitCount, 32);
320 ok_int(pbi->bmiHeader.biCompression, 0);
321 ok_int(pbi->bmiHeader.biSizeImage, 0);
322
323 /* Get the bitmap bits */
324 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
325 pbi->bmiHeader.biWidth = 4;
326 pbi->bmiHeader.biHeight = 4;
327 pbi->bmiHeader.biPlanes = 1;
328 pbi->bmiHeader.biBitCount = 32;
329 pbi->bmiHeader.biCompression = BI_RGB;
330 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
331 pbi->bmiHeader.biWidth = 0;
332 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
333 pbi->bmiHeader.biWidth = -3;
334 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
335 pbi->bmiHeader.biWidth = 4;
336 pbi->bmiHeader.biHeight = 0;
337 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
338 pbi->bmiHeader.biHeight = -4;
339 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
340 pbi->bmiHeader.biBitCount = 31;
341 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
342 pbi->bmiHeader.biBitCount = 16;
343 pbi->bmiHeader.biPlanes = 23;
344 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
345 ok_int(pbi->bmiHeader.biPlanes, 1);
346 pbi->bmiHeader.biCompression = BI_JPEG;
347 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
348 pbi->bmiHeader.biCompression = BI_PNG;
349 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
350
351
352 /* Get the bitmap bits */
353 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
354 pbi->bmiHeader.biWidth = 4;
355 pbi->bmiHeader.biHeight = 4;
356 pbi->bmiHeader.biPlanes = 1;
357 pbi->bmiHeader.biBitCount = 32;
358 pbi->bmiHeader.biCompression = BI_RGB;
359 pbi->bmiHeader.biSizeImage = 0;
360 pbi->bmiHeader.biXPelsPerMeter = 0;
361 pbi->bmiHeader.biYPelsPerMeter = 0;
362 pbi->bmiHeader.biClrUsed = 0;
363 pbi->bmiHeader.biClrImportant = 0;
364 cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
365 pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 512);
366 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
367
368 /* Set biBitCount to 0 */
369 pbi->bmiHeader.biBitCount = 0;
370 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
371 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 1);
372 ok_int(GetDIBits(NULL, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 0);
373
374 /* Try different biBitCount and biWidth */
375 pbi->bmiHeader.biBitCount = 24;
376 pbi->bmiHeader.biWidth = 3;
377 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
378
379 /* Try different biBitCount and biWidth */
380 pbi->bmiHeader.biBitCount = 24;
381 pbi->bmiHeader.biWidth = 3;
382 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
383
384 /* Set only biBitCount and pjInit */
385 ZeroMemory(pbi, sizeof(BITMAPINFO));
386 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
387 pbi->bmiHeader.biBitCount = 5;
388 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
389
390 DeleteObject(hbmp);
391 HeapFree(GetProcessHeap(), 0, pvBits);
392
393 /* Test a 4 bpp bitmap */
394 hbmp = CreateBitmap(3, 5, 1, 4, NULL);
395 ok(hbmp != 0, "failed to create bitmap\n");
396 ZeroMemory(pbi, sizeof(BITMAPINFO));
397 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
398 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
399 ok_int(pbi->bmiHeader.biWidth, 3);
400 ok_int(pbi->bmiHeader.biHeight, 5);
401 ok_int(pbi->bmiHeader.biBitCount, 4);
402 ok_int(pbi->bmiHeader.biSizeImage, 20);
403
404 /* This does NOT work with incompatible bitmaps */
405 pbi->bmiHeader.biSizeImage = 0;
406 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0);
407
408 cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
409 pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cjSizeImage);
410
411 ok(SelectObject(hdcMem, ghbmpDIB4) != 0, "\n");;
412 ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
413 ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 3);
414
415
416 DeleteDC(hdcMem);
417 ReleaseDC(NULL, hdcScreen);
418 }
419
420 void Test_GetDIBits_BI_BITFIELDS()
421 {
422 }
423
424 START_TEST(GetDIBits)
425 {
426 //getchar();
427 InitStuff();
428 Test_GetDIBits_xBpp(1);
429 Test_GetDIBits_xBpp(4);
430 Test_GetDIBits_xBpp(8);
431 Test_GetDIBits_xBpp(16);
432 Test_GetDIBits_xBpp(24);
433 Test_GetDIBits_xBpp(32);
434 Test_GetDIBits();
435 }
436