2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetDIBits
5 * PROGRAMMERS: Timo Kreuzer
16 UCHAR ajBuffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
17 PBITMAPINFO pbmi
= (PBITMAPINFO
)ajBuffer
;
19 ULONG cjSizeImage
, cColors
;
23 hbmp
= CreateBitmap(3, 3, 1, cBitsPixel
, NULL
);
25 /* Fill in the size field */
26 ZeroMemory(pbmi
, sizeof(ajBuffer
));
27 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
30 ok_int(GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
31 cjSizeImage
= (((pbmi
->bmiHeader
.biWidth
* pbmi
->bmiHeader
.biBitCount
) + 31) & ~31) * pbmi
->bmiHeader
.biHeight
/ 8;
32 cColors
= cBitsPixel
<= 8 ? 1 << pbmi
->bmiHeader
.biBitCount
: 0;
34 ok_int(pbmi
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
));
35 ok_int(pbmi
->bmiHeader
.biWidth
, 3);
36 ok_int(pbmi
->bmiHeader
.biHeight
, 3);
37 ok_int(pbmi
->bmiHeader
.biPlanes
, 1);
38 ok_int(pbmi
->bmiHeader
.biBitCount
, cBitsPixel
);
39 ok_int(pbmi
->bmiHeader
.biCompression
, (cBitsPixel
== 16) || (cBitsPixel
== 32) ? BI_BITFIELDS
: BI_RGB
);
40 ok_int(pbmi
->bmiHeader
.biSizeImage
, cjSizeImage
);
41 ok_int(pbmi
->bmiHeader
.biXPelsPerMeter
, 0);
42 ok_int(pbmi
->bmiHeader
.biYPelsPerMeter
, 0);
43 ok_int(pbmi
->bmiHeader
.biClrUsed
, cColors
);
44 ok_int(pbmi
->bmiHeader
.biClrImportant
, cColors
);
46 // pbmi->bmiHeader.biSizeImage = 0;
47 //ok_int(GetDIBits(NULL, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
49 /* Test a bitmap with values partly set */
50 ZeroMemory(pbmi
, sizeof(ajBuffer
));
51 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
52 pbmi
->bmiHeader
.biWidth
= 12;
53 pbmi
->bmiHeader
.biHeight
= 14;
54 pbmi
->bmiHeader
.biPlanes
= 2;
55 pbmi
->bmiHeader
.biBitCount
= 0; // keep biBitCount == 0!
56 pbmi
->bmiHeader
.biCompression
= 7;
57 pbmi
->bmiHeader
.biSizeImage
= 123;
58 ok_int(GetDIBits(hdc
, hbmp
, 0, 5, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
59 ok_int(pbmi
->bmiHeader
.biWidth
, 3);
60 ok_int(pbmi
->bmiHeader
.biHeight
, 3);
61 ok_int(pbmi
->bmiHeader
.biPlanes
, 1);
62 ok_int(pbmi
->bmiHeader
.biBitCount
, cBitsPixel
);
63 ok_int(pbmi
->bmiHeader
.biSizeImage
, cjSizeImage
);
64 ok_int(pbmi
->bmiHeader
.biXPelsPerMeter
, 0);
65 ok_int(pbmi
->bmiHeader
.biYPelsPerMeter
, 0);
66 ok_int(pbmi
->bmiHeader
.biClrUsed
, cColors
);
67 ok_int(pbmi
->bmiHeader
.biClrImportant
, cColors
);
71 /* Get info including the color table */
72 ZeroMemory(pbmi
, sizeof(ajBuffer
));
73 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
74 pbmi
->bmiHeader
.biBitCount
= 1;
75 ok_int(GetDIBits(NULL
, hbmp
, 0, 0, NULL
, pbmi
, DIB_PAL_COLORS
), 1);
77 /* Check a different bit depth */
78 pbmi
->bmiHeader
.biBitCount
, cBitsPixel
= (cBitsPixel
== 1) ? 8 : 1;
79 ok_int(GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
80 ok_int(pbmi
->bmiHeader
.biBitCount
, (cBitsPixel
== 1) ? 8 : 1);
84 ok_int(GetDIBits(hdc
, hbmp
, 0, 4, pvBits
, pbmi
, DIB_PAL_COLORS
), 3);
85 ok_int(GetDIBits(hdc
, hbmp
, 3, 7, pvBits
, pbmi
, DIB_RGB_COLORS
), 1);
88 pbmi
->bmiHeader
.biPlanes
= 2;
89 pbmi
->bmiHeader
.biClrUsed
= 0;
90 ok_int(GetDIBits(hdc
, hbmp
, 0, 4, pvBits
, pbmi
, DIB_RGB_COLORS
), 3);
99 HDC hdcScreen
, hdcMem
;
103 PBITMAPCOREHEADER pbch
;
104 PBITMAPV5HEADER pbV5Header
;
106 DWORD ajBits
[100] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
110 bisize
= sizeof(BITMAPV5HEADER
) + 256 * sizeof(DWORD
);
111 pbi
= malloc(bisize
);
113 pbV5Header
= (PVOID
)pbi
;
115 hdcScreen
= GetDC(NULL
);
116 ok(hdcScreen
!= 0, "GetDC failed, skipping tests\n");
117 if (hdcScreen
== NULL
) return;
119 hbmp
= CreateCompatibleBitmap(hdcScreen
, 16, 16);
120 ok(hbmp
!= NULL
, "CreateCompatibleBitmap failed\n");
123 SetLastError(ERROR_SUCCESS
);
124 ok(GetDIBits(0, 0, 0, 0, NULL
, NULL
, 0) == 0, "\n");
125 ok_err(ERROR_INVALID_PARAMETER
);
127 SetLastError(ERROR_SUCCESS
);
128 ok(GetDIBits((HDC
)2345, 0, 0, 0, NULL
, NULL
, 0) == 0, "\n");
129 ok_err(ERROR_INVALID_PARAMETER
);
131 SetLastError(ERROR_SUCCESS
);
132 ok(GetDIBits((HDC
)2345, hbmp
, 0, 0, NULL
, NULL
, 0) == 0, "\n");
133 ok_err(ERROR_INVALID_PARAMETER
);
135 SetLastError(ERROR_SUCCESS
);
136 ok(GetDIBits((HDC
)2345, hbmp
, 0, 15, NULL
, pbi
, 0) == 0, "\n");
137 ok_err(ERROR_INVALID_PARAMETER
);
142 SetLastError(ERROR_SUCCESS
);
143 ZeroMemory(pbi
, bisize
);
144 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
145 ok(GetDIBits(NULL
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
) == 0, "\n");
146 ok_err(ERROR_INVALID_PARAMETER
);
149 SetLastError(ERROR_SUCCESS
);
150 ZeroMemory(pbi
, bisize
);
151 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
152 ok(GetDIBits(hdcScreen
, NULL
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
) == 0, "\n");
153 ok_err(ERROR_SUCCESS
);
156 SetLastError(ERROR_SUCCESS
);
157 ZeroMemory(pbi
, bisize
);
158 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
159 ok(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
) > 0, "\n");
160 ok_err(ERROR_SUCCESS
);
162 /* null bitmap info - crashes XP*/
163 //SetLastError(ERROR_SUCCESS);
164 //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
165 //ok(GetLastError() == ERROR_INVALID_PARAMETER);
167 /* bad bmi colours (uUsage) */
169 ZeroMemory(pbi
, bisize
);
170 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
171 ok(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, 100) == 0, "\n");
172 ok_err(ERROR_SUCCESS
);
173 ok(pbi
->bmiHeader
.biWidth
== 0, "\n");
174 ok(pbi
->bmiHeader
.biHeight
== 0, "\n");
175 ok(pbi
->bmiHeader
.biBitCount
== 0, "\n");
176 ok(pbi
->bmiHeader
.biSizeImage
== 0, "\n");
179 SetLastError(ERROR_SUCCESS
);
180 ZeroMemory(pbi
, bisize
);
181 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
182 ok(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
) > 0, "\n");
183 ok_err(ERROR_SUCCESS
);
184 ScreenBpp
= GetDeviceCaps(hdcScreen
, BITSPIXEL
);
185 ok(pbi
->bmiHeader
.biWidth
== 16, "\n");
186 ok(pbi
->bmiHeader
.biHeight
== 16, "\n");
187 ok(pbi
->bmiHeader
.biBitCount
== ScreenBpp
, "\n");
188 ok(pbi
->bmiHeader
.biSizeImage
== (16 * 16) * (ScreenBpp
/ 8), "\n");
190 /* Test if COREHEADER is supported */
191 ZeroMemory(pbi
, bisize
);
192 pbi
->bmiHeader
.biSize
= sizeof(BITMAPCOREHEADER
);
193 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
194 ok_int(pbi
->bmiHeader
.biSize
, sizeof(BITMAPCOREHEADER
));
195 ok_int(pbch
->bcWidth
, 16);
196 ok_int(pbch
->bcHeight
, 16);
197 ok_int(pbch
->bcPlanes
, 1);
198 //ok_int(pbch->bcBitCount, ScreenBpp > 16 ? 24 : ScreenBpp); // fails on XP with screenbpp == 16
200 /* Test different header sizes */
201 ZeroMemory(pbi
, bisize
);
202 pbi
->bmiHeader
.biSize
= sizeof(BITMAPCOREHEADER
) + 4;
203 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 0);
205 ZeroMemory(pbi
, bisize
);
206 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) + 4;
207 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
209 ZeroMemory(pbi
, bisize
);
210 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
211 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
213 ZeroMemory(pbi
, bisize
);
214 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
) + 4;
215 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
217 ZeroMemory(pbi
, bisize
);
218 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
219 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
221 ZeroMemory(pbi
, bisize
);
222 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
) + 4;
223 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
224 ok_int(pbV5Header
->bV5RedMask
, 0);
225 ok_int(pbV5Header
->bV5GreenMask
, 0);
226 ok_int(pbV5Header
->bV5BlueMask
, 0);
227 ok_int(pbV5Header
->bV5AlphaMask
, 0);
228 ok_int(pbV5Header
->bV5CSType
, 0);
229 // CIEXYZTRIPLE bV5Endpoints;
230 ok_int(pbV5Header
->bV5GammaRed
, 0);
231 ok_int(pbV5Header
->bV5GammaGreen
, 0);
232 ok_int(pbV5Header
->bV5GammaBlue
, 0);
233 ok_int(pbV5Header
->bV5Intent
, 0);
234 ok_int(pbV5Header
->bV5ProfileData
, 0);
235 ok_int(pbV5Header
->bV5ProfileSize
, 0);
236 ok_int(pbV5Header
->bV5Reserved
, 0);
238 ZeroMemory(pbi
, bisize
);
239 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
240 ok_int(GetDIBits(hdcScreen
, hbmp
, 234, 43, NULL
, pbi
, DIB_RGB_COLORS
), 1);
244 /* Test a mono bitmap */
245 hbmp
= CreateBitmap(13, 7, 1, 1, ajBits
);
246 ok(hbmp
!= 0, "failed to create bitmap\n");
247 ZeroMemory(pbi
, bisize
);
248 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
249 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
250 ok_int(pbi
->bmiHeader
.biWidth
, 13);
251 ok_int(pbi
->bmiHeader
.biHeight
, 7);
252 ok_int(pbi
->bmiHeader
.biBitCount
, 1);
253 ok_int(pbi
->bmiHeader
.biSizeImage
, 28);
255 /* Test with values set, except biSizeImage */
256 pbi
->bmiHeader
.biSizeImage
= 0;
257 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
258 ok_int(pbi
->bmiHeader
.biSizeImage
, 28);
260 /* Test with different biWidth set */
261 pbi
->bmiHeader
.biWidth
= 17;
262 pbi
->bmiHeader
.biHeight
= 3;
263 pbi
->bmiHeader
.biSizeImage
= 0;
264 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
265 ok_int(pbi
->bmiHeader
.biSizeImage
, 12);
266 ok_int(pbi
->bmiHeader
.biWidth
, 17);
267 ok_int(pbi
->bmiHeader
.biHeight
, 3);
269 /* Test with different biBitCount set */
270 pbi
->bmiHeader
.biBitCount
= 4;
271 pbi
->bmiHeader
.biSizeImage
= 1;
272 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
273 ok_int(pbi
->bmiHeader
.biSizeImage
, 36);
274 ok_int(pbi
->bmiHeader
.biBitCount
, 4);
276 /* Test with different biBitCount set */
277 pbi
->bmiHeader
.biBitCount
= 8;
278 pbi
->bmiHeader
.biSizeImage
= 1000;
279 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
280 ok_int(pbi
->bmiHeader
.biSizeImage
, 60);
281 ok_int(pbi
->bmiHeader
.biBitCount
, 8);
283 /* Test with invalid biBitCount set */
284 pbi
->bmiHeader
.biBitCount
= 123;
285 pbi
->bmiHeader
.biSizeImage
= -12;
286 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 0);
287 ok_int(pbi
->bmiHeader
.biSizeImage
, -12);
288 ok_int(pbi
->bmiHeader
.biBitCount
, 123);
290 /* Set bitmap dimensions */
291 ok_int(SetBitmapDimensionEx(hbmp
, 110, 220, NULL
), 1);
292 ZeroMemory(pbi
, bisize
);
293 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
294 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
295 ok_int(pbi
->bmiHeader
.biXPelsPerMeter
, 0);
296 ok_int(pbi
->bmiHeader
.biYPelsPerMeter
, 0);
298 /* Set individual values */
299 ZeroMemory(pbi
, bisize
);
300 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
301 pbi
->bmiHeader
.biWidth
= 12;
302 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
303 ok_int(pbi
->bmiHeader
.biWidth
, 13);
304 ok_int(pbi
->bmiHeader
.biSizeImage
, 28);
306 ZeroMemory(pbi
, bisize
);
307 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
308 pbi
->bmiHeader
.biSizeImage
= 123;
309 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
311 ZeroMemory(pbi
, bisize
);
312 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
313 pbi
->bmiHeader
.biCompression
= BI_RGB
;
314 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
316 /* Set only biBitCount */
317 ZeroMemory(pbi
, bisize
);
318 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
319 pbi
->bmiHeader
.biBitCount
= 5;
320 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
321 pbi
->bmiHeader
.biBitCount
= 1;
322 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
323 pbi
->bmiHeader
.biBitCount
= 8;
324 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
325 pbi
->bmiHeader
.biBitCount
= 32;
326 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
327 ok_int(pbi
->bmiHeader
.biWidth
, 0);
328 ok_int(pbi
->bmiHeader
.biHeight
, 0);
329 ok_int(pbi
->bmiHeader
.biPlanes
, 0);
330 ok_int(pbi
->bmiHeader
.biBitCount
, 32);
331 ok_int(pbi
->bmiHeader
.biCompression
, 0);
332 ok_int(pbi
->bmiHeader
.biSizeImage
, 0);
334 /* Get the bitmap info */
335 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
336 pbi
->bmiHeader
.biWidth
= 4;
337 pbi
->bmiHeader
.biHeight
= 4;
338 pbi
->bmiHeader
.biPlanes
= 3;
339 pbi
->bmiHeader
.biBitCount
= 32;
340 pbi
->bmiHeader
.biCompression
= BI_RGB
;
341 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
342 ok_int(pbi
->bmiHeader
.biSizeImage
, 64);
343 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
344 pbi
->bmiHeader
.biWidth
= 0;
345 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
346 pbi
->bmiHeader
.biWidth
= 2;
347 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
348 ok_int(pbi
->bmiHeader
.biSizeImage
, 32);
349 pbi
->bmiHeader
.biWidth
= -3;
350 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
351 pbi
->bmiHeader
.biWidth
= 4;
352 pbi
->bmiHeader
.biHeight
= 0;
353 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
354 pbi
->bmiHeader
.biHeight
= -4;
355 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
356 pbi
->bmiHeader
.biBitCount
= 31;
357 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
358 pbi
->bmiHeader
.biBitCount
= 16;
359 pbi
->bmiHeader
.biPlanes
= 23;
360 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
361 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
362 SetLastError(0xdeadbabe);
363 ok_int(GetDIBits((HDC
)0xff00ff00, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
365 SetLastError(0xdeadbabe);
366 ok_int(GetDIBits(hdcScreen
, (HBITMAP
)0xff00ff00, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
368 SetLastError(0xdeadbabe);
369 ok_int(GetDIBits((HDC
)0xff00ff00, (HBITMAP
)0xff00ff00, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
371 SetLastError(0xdeadbabe);
372 ok_int(GetDIBits(NULL
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
375 pbi
->bmiHeader
.biCompression
= BI_JPEG
;
376 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
377 pbi
->bmiHeader
.biCompression
= BI_PNG
;
378 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
380 /* Get the bitmap bits */
381 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
382 pbi
->bmiHeader
.biWidth
= 4;
383 pbi
->bmiHeader
.biHeight
= 4;
384 pbi
->bmiHeader
.biPlanes
= 1;
385 pbi
->bmiHeader
.biBitCount
= 32;
386 pbi
->bmiHeader
.biCompression
= BI_RGB
;
387 pbi
->bmiHeader
.biSizeImage
= 0;
388 pbi
->bmiHeader
.biXPelsPerMeter
= 0;
389 pbi
->bmiHeader
.biYPelsPerMeter
= 0;
390 pbi
->bmiHeader
.biClrUsed
= 0;
391 pbi
->bmiHeader
.biClrImportant
= 0;
392 cjSizeImage
= ((pbi
->bmiHeader
.biWidth
* pbi
->bmiHeader
.biBitCount
+ 31) / 32) * 4 * pbi
->bmiHeader
.biHeight
;
393 pvBits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 512);
394 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
395 ok_int(pbi
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
));
396 ok_int(pbi
->bmiHeader
.biWidth
, 4);
397 ok_int(pbi
->bmiHeader
.biHeight
, 4);
398 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
399 ok_int(pbi
->bmiHeader
.biBitCount
, 32);
400 ok_int(pbi
->bmiHeader
.biCompression
, BI_RGB
);
401 ok_int(pbi
->bmiHeader
.biSizeImage
, 64);
402 ok_int(pbi
->bmiHeader
.biXPelsPerMeter
, 0);
403 ok_int(pbi
->bmiHeader
.biYPelsPerMeter
, 0);
404 ok_int(pbi
->bmiHeader
.biClrUsed
, 0);
405 ok_int(pbi
->bmiHeader
.biClrImportant
, 0);
407 /* Set biBitCount to 0 */
408 pbi
->bmiHeader
.biBitCount
= 0;
409 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
410 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, (PVOID
)(LONG_PTR
)-1, pbi
, DIB_RGB_COLORS
), 0);
411 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, NULL
, pbi
, DIB_RGB_COLORS
), 1);
412 ok_int(GetDIBits(NULL
, hbmp
, 0, 4, NULL
, pbi
, DIB_RGB_COLORS
), 0);
414 /* Try different biBitCount and biWidth */
415 pbi
->bmiHeader
.biBitCount
= 24;
416 pbi
->bmiHeader
.biWidth
= 3;
417 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
419 /* Try different biBitCount and biWidth */
420 pbi
->bmiHeader
.biBitCount
= 24;
421 pbi
->bmiHeader
.biWidth
= 3;
422 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
424 /* Try invalid biBitCount */
425 pbi
->bmiHeader
.biBitCount
= 17;
426 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
428 /* Set only biBitCount and pjInit */
429 ZeroMemory(pbi
, bisize
);
430 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
431 pbi
->bmiHeader
.biBitCount
= 5;
432 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
435 HeapFree(GetProcessHeap(), 0, pvBits
);
437 /* Test a 4 bpp bitmap */
438 hbmp
= CreateBitmap(3, 5, 1, 4, NULL
);
439 ok(hbmp
!= 0, "failed to create bitmap\n");
440 ZeroMemory(pbi
, bisize
);
441 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
442 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
443 ok_int(pbi
->bmiHeader
.biWidth
, 3);
444 ok_int(pbi
->bmiHeader
.biHeight
, 5);
445 ok_int(pbi
->bmiHeader
.biBitCount
, 4);
446 ok_int(pbi
->bmiHeader
.biSizeImage
, 20);
448 /* This does NOT work with incompatible bitmaps */
449 pbi
->bmiHeader
.biSizeImage
= 0;
450 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 0);
452 /* Calculate bitmap size and allocate a buffer */
453 cjSizeImage
= ((pbi
->bmiHeader
.biWidth
* pbi
->bmiHeader
.biBitCount
+ 31) / 32) * 4 * pbi
->bmiHeader
.biHeight
;
454 ok_int(cjSizeImage
, 20);
455 pvBits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cjSizeImage
);
457 /* Test using a compatible DC */
458 hdcMem
= CreateCompatibleDC(0);
459 ok(hdcMem
!= 0, "CreateCompatibleDC failed, skipping tests\n");
460 if (hdcMem
== NULL
) return;
461 ok_int(GetDIBits(hdcMem
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
462 ok_int(GetDIBits(hdcMem
, ghbmpDIB4
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
464 HeapFree(GetProcessHeap(), 0, pvBits
);
466 ReleaseDC(NULL
, hdcScreen
);
469 void Test_GetDIBits_BI_BITFIELDS()
473 START_TEST(GetDIBits
)
477 Test_GetDIBits_xBpp(1);
478 Test_GetDIBits_xBpp(4);
479 Test_GetDIBits_xBpp(8);
480 Test_GetDIBits_xBpp(16);
481 Test_GetDIBits_xBpp(24);
482 Test_GetDIBits_xBpp(32);