2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetDIBits
5 * PROGRAMMERS: Timo Kreuzer
19 UCHAR ajBuffer
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
20 PBITMAPINFO pbmi
= (PBITMAPINFO
)ajBuffer
;
22 ULONG cjSizeImage
, cColors
;
26 hbmp
= CreateBitmap(3, 3, 1, cBitsPixel
, NULL
);
28 /* Fill in the size field */
29 ZeroMemory(pbmi
, sizeof(ajBuffer
));
30 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
33 ok_int(GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
34 cjSizeImage
= (((pbmi
->bmiHeader
.biWidth
* pbmi
->bmiHeader
.biBitCount
) + 31) & ~31) * pbmi
->bmiHeader
.biHeight
/ 8;
35 cColors
= cBitsPixel
<= 8 ? 1 << pbmi
->bmiHeader
.biBitCount
: 0;
37 ok_int(pbmi
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
));
38 ok_int(pbmi
->bmiHeader
.biWidth
, 3);
39 ok_int(pbmi
->bmiHeader
.biHeight
, 3);
40 ok_int(pbmi
->bmiHeader
.biPlanes
, 1);
41 ok_int(pbmi
->bmiHeader
.biBitCount
, cBitsPixel
);
42 ok_int(pbmi
->bmiHeader
.biCompression
, (cBitsPixel
== 16) || (cBitsPixel
== 32) ? BI_BITFIELDS
: BI_RGB
);
43 ok_int(pbmi
->bmiHeader
.biSizeImage
, cjSizeImage
);
44 ok_int(pbmi
->bmiHeader
.biXPelsPerMeter
, 0);
45 ok_int(pbmi
->bmiHeader
.biYPelsPerMeter
, 0);
46 ok_int(pbmi
->bmiHeader
.biClrUsed
, cColors
);
47 ok_int(pbmi
->bmiHeader
.biClrImportant
, cColors
);
49 // pbmi->bmiHeader.biSizeImage = 0;
50 //ok_int(GetDIBits(NULL, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
52 /* Test a bitmap with values partly set */
53 ZeroMemory(pbmi
, sizeof(ajBuffer
));
54 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
55 pbmi
->bmiHeader
.biWidth
= 12;
56 pbmi
->bmiHeader
.biHeight
= 14;
57 pbmi
->bmiHeader
.biPlanes
= 2;
58 pbmi
->bmiHeader
.biBitCount
= 0; // keep biBitCount == 0!
59 pbmi
->bmiHeader
.biCompression
= 7;
60 pbmi
->bmiHeader
.biSizeImage
= 123;
61 ok_int(GetDIBits(hdc
, hbmp
, 0, 5, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
62 ok_int(pbmi
->bmiHeader
.biWidth
, 3);
63 ok_int(pbmi
->bmiHeader
.biHeight
, 3);
64 ok_int(pbmi
->bmiHeader
.biPlanes
, 1);
65 ok_int(pbmi
->bmiHeader
.biBitCount
, cBitsPixel
);
66 ok_int(pbmi
->bmiHeader
.biSizeImage
, cjSizeImage
);
67 ok_int(pbmi
->bmiHeader
.biXPelsPerMeter
, 0);
68 ok_int(pbmi
->bmiHeader
.biYPelsPerMeter
, 0);
69 ok_int(pbmi
->bmiHeader
.biClrUsed
, cColors
);
70 ok_int(pbmi
->bmiHeader
.biClrImportant
, cColors
);
74 /* Get info including the color table */
75 ZeroMemory(pbmi
, sizeof(ajBuffer
));
76 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
77 pbmi
->bmiHeader
.biBitCount
= 1;
78 ok_int(GetDIBits(NULL
, hbmp
, 0, 0, NULL
, pbmi
, DIB_PAL_COLORS
), 1);
80 /* Check a different bit depth */
81 pbmi
->bmiHeader
.biBitCount
, cBitsPixel
= (cBitsPixel
== 1) ? 8 : 1;
82 ok_int(GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
), 1);
83 ok_int(pbmi
->bmiHeader
.biBitCount
, (cBitsPixel
== 1) ? 8 : 1);
87 ok_int(GetDIBits(hdc
, hbmp
, 0, 4, pvBits
, pbmi
, DIB_PAL_COLORS
), 3);
88 ok_int(GetDIBits(hdc
, hbmp
, 3, 7, pvBits
, pbmi
, DIB_RGB_COLORS
), 1);
91 pbmi
->bmiHeader
.biPlanes
= 2;
92 pbmi
->bmiHeader
.biClrUsed
= 0;
93 ok_int(GetDIBits(hdc
, hbmp
, 0, 4, pvBits
, pbmi
, DIB_RGB_COLORS
), 3);
100 void Test_GetDIBits()
102 HDC hdcScreen
, hdcMem
;
106 PBITMAPCOREHEADER pbch
;
107 PBITMAPV5HEADER pbV5Header
;
109 DWORD ajBits
[100] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
113 bisize
= sizeof(BITMAPV5HEADER
) + 256 * sizeof(DWORD
);
114 pbi
= malloc(bisize
);
116 pbV5Header
= (PVOID
)pbi
;
118 hdcScreen
= GetDC(NULL
);
119 ok(hdcScreen
!= 0, "GetDC failed, skipping tests\n");
120 if (hdcScreen
== NULL
) return;
122 hbmp
= CreateCompatibleBitmap(hdcScreen
, 16, 16);
123 ok(hbmp
!= NULL
, "CreateCompatibleBitmap failed\n");
126 SetLastError(ERROR_SUCCESS
);
127 ok(GetDIBits(0, 0, 0, 0, NULL
, NULL
, 0) == 0, "\n");
128 ok_err(ERROR_INVALID_PARAMETER
);
130 SetLastError(ERROR_SUCCESS
);
131 ok(GetDIBits((HDC
)2345, 0, 0, 0, NULL
, NULL
, 0) == 0, "\n");
132 ok_err(ERROR_INVALID_PARAMETER
);
134 SetLastError(ERROR_SUCCESS
);
135 ok(GetDIBits((HDC
)2345, hbmp
, 0, 0, NULL
, NULL
, 0) == 0, "\n");
136 ok_err(ERROR_INVALID_PARAMETER
);
138 SetLastError(ERROR_SUCCESS
);
139 ok(GetDIBits((HDC
)2345, hbmp
, 0, 15, NULL
, pbi
, 0) == 0, "\n");
140 ok_err(ERROR_INVALID_PARAMETER
);
145 SetLastError(ERROR_SUCCESS
);
146 ZeroMemory(pbi
, bisize
);
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
);
152 SetLastError(ERROR_SUCCESS
);
153 ZeroMemory(pbi
, bisize
);
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
);
159 SetLastError(ERROR_SUCCESS
);
160 ZeroMemory(pbi
, bisize
);
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
);
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);
170 /* bad bmi colours (uUsage) */
172 ZeroMemory(pbi
, bisize
);
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");
182 SetLastError(ERROR_SUCCESS
);
183 ZeroMemory(pbi
, bisize
);
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");
193 /* Test if COREHEADER is supported */
194 ZeroMemory(pbi
, bisize
);
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
203 /* Test different header sizes */
204 ZeroMemory(pbi
, bisize
);
205 pbi
->bmiHeader
.biSize
= sizeof(BITMAPCOREHEADER
) + 4;
206 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 0);
208 ZeroMemory(pbi
, bisize
);
209 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) + 4;
210 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
212 ZeroMemory(pbi
, bisize
);
213 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
214 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
216 ZeroMemory(pbi
, bisize
);
217 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
) + 4;
218 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
220 ZeroMemory(pbi
, bisize
);
221 pbi
->bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
222 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 15, NULL
, pbi
, DIB_RGB_COLORS
), 1);
224 ZeroMemory(pbi
, bisize
);
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);
241 ZeroMemory(pbi
, bisize
);
242 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
243 ok_int(GetDIBits(hdcScreen
, hbmp
, 234, 43, NULL
, pbi
, DIB_RGB_COLORS
), 1);
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
, bisize
);
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);
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);
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);
272 /* Test with different biBitCount set */
273 pbi
->bmiHeader
.biBitCount
= 4;
274 pbi
->bmiHeader
.biSizeImage
= 1;
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);
279 /* Test with different biBitCount set */
280 pbi
->bmiHeader
.biBitCount
= 8;
281 pbi
->bmiHeader
.biSizeImage
= 1000;
282 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
283 ok_int(pbi
->bmiHeader
.biSizeImage
, 60);
284 ok_int(pbi
->bmiHeader
.biBitCount
, 8);
286 /* Test with invalid biBitCount set */
287 pbi
->bmiHeader
.biBitCount
= 123;
288 pbi
->bmiHeader
.biSizeImage
= -12;
289 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 0);
290 ok_int(pbi
->bmiHeader
.biSizeImage
, -12);
291 ok_int(pbi
->bmiHeader
.biBitCount
, 123);
293 /* Set bitmap dimensions */
294 ok_int(SetBitmapDimensionEx(hbmp
, 110, 220, NULL
), 1);
295 ZeroMemory(pbi
, bisize
);
296 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
297 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
298 ok_int(pbi
->bmiHeader
.biXPelsPerMeter
, 0);
299 ok_int(pbi
->bmiHeader
.biYPelsPerMeter
, 0);
301 /* Set individual values */
302 ZeroMemory(pbi
, bisize
);
303 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
304 pbi
->bmiHeader
.biWidth
= 12;
305 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
306 ok_int(pbi
->bmiHeader
.biWidth
, 13);
307 ok_int(pbi
->bmiHeader
.biSizeImage
, 28);
309 ZeroMemory(pbi
, bisize
);
310 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
311 pbi
->bmiHeader
.biSizeImage
= 123;
312 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
314 ZeroMemory(pbi
, bisize
);
315 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
316 pbi
->bmiHeader
.biCompression
= BI_RGB
;
317 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
319 /* Set only biBitCount */
320 ZeroMemory(pbi
, bisize
);
321 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
322 pbi
->bmiHeader
.biBitCount
= 5;
323 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
324 pbi
->bmiHeader
.biBitCount
= 1;
325 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
326 pbi
->bmiHeader
.biBitCount
= 8;
327 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
328 pbi
->bmiHeader
.biBitCount
= 32;
329 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
330 ok_int(pbi
->bmiHeader
.biWidth
, 0);
331 ok_int(pbi
->bmiHeader
.biHeight
, 0);
332 ok_int(pbi
->bmiHeader
.biPlanes
, 0);
333 ok_int(pbi
->bmiHeader
.biBitCount
, 32);
334 ok_int(pbi
->bmiHeader
.biCompression
, 0);
335 ok_int(pbi
->bmiHeader
.biSizeImage
, 0);
337 /* Get the bitmap info */
338 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
339 pbi
->bmiHeader
.biWidth
= 4;
340 pbi
->bmiHeader
.biHeight
= 4;
341 pbi
->bmiHeader
.biPlanes
= 3;
342 pbi
->bmiHeader
.biBitCount
= 32;
343 pbi
->bmiHeader
.biCompression
= BI_RGB
;
344 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
345 ok_int(pbi
->bmiHeader
.biSizeImage
, 64);
346 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
347 pbi
->bmiHeader
.biWidth
= 0;
348 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
349 pbi
->bmiHeader
.biWidth
= 2;
350 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
351 ok_int(pbi
->bmiHeader
.biSizeImage
, 32);
352 pbi
->bmiHeader
.biWidth
= -3;
353 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
354 pbi
->bmiHeader
.biWidth
= 4;
355 pbi
->bmiHeader
.biHeight
= 0;
356 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
357 pbi
->bmiHeader
.biHeight
= -4;
358 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
359 pbi
->bmiHeader
.biBitCount
= 31;
360 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
361 pbi
->bmiHeader
.biBitCount
= 16;
362 pbi
->bmiHeader
.biPlanes
= 23;
363 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 1);
364 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
365 SetLastError(0xdeadbabe);
366 ok_int(GetDIBits((HDC
)0xff00ff00, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
368 SetLastError(0xdeadbabe);
369 ok_int(GetDIBits(hdcScreen
, (HBITMAP
)0xff00ff00, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
371 SetLastError(0xdeadbabe);
372 ok_int(GetDIBits((HDC
)0xff00ff00, (HBITMAP
)0xff00ff00, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
374 SetLastError(0xdeadbabe);
375 ok_int(GetDIBits(NULL
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
378 pbi
->bmiHeader
.biCompression
= BI_JPEG
;
379 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
380 pbi
->bmiHeader
.biCompression
= BI_PNG
;
381 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 5, NULL
, pbi
, DIB_RGB_COLORS
), 0);
383 /* Get the bitmap bits */
384 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
385 pbi
->bmiHeader
.biWidth
= 4;
386 pbi
->bmiHeader
.biHeight
= 4;
387 pbi
->bmiHeader
.biPlanes
= 1;
388 pbi
->bmiHeader
.biBitCount
= 32;
389 pbi
->bmiHeader
.biCompression
= BI_RGB
;
390 pbi
->bmiHeader
.biSizeImage
= 0;
391 pbi
->bmiHeader
.biXPelsPerMeter
= 0;
392 pbi
->bmiHeader
.biYPelsPerMeter
= 0;
393 pbi
->bmiHeader
.biClrUsed
= 0;
394 pbi
->bmiHeader
.biClrImportant
= 0;
395 cjSizeImage
= ((pbi
->bmiHeader
.biWidth
* pbi
->bmiHeader
.biBitCount
+ 31) / 32) * 4 * pbi
->bmiHeader
.biHeight
;
396 pvBits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 512);
397 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
398 ok_int(pbi
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
));
399 ok_int(pbi
->bmiHeader
.biWidth
, 4);
400 ok_int(pbi
->bmiHeader
.biHeight
, 4);
401 ok_int(pbi
->bmiHeader
.biPlanes
, 1);
402 ok_int(pbi
->bmiHeader
.biBitCount
, 32);
403 ok_int(pbi
->bmiHeader
.biCompression
, BI_RGB
);
404 ok_int(pbi
->bmiHeader
.biSizeImage
, 64);
405 ok_int(pbi
->bmiHeader
.biXPelsPerMeter
, 0);
406 ok_int(pbi
->bmiHeader
.biYPelsPerMeter
, 0);
407 ok_int(pbi
->bmiHeader
.biClrUsed
, 0);
408 ok_int(pbi
->bmiHeader
.biClrImportant
, 0);
410 /* Set biBitCount to 0 */
411 pbi
->bmiHeader
.biBitCount
= 0;
412 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
413 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, (PVOID
)(LONG_PTR
)-1, pbi
, DIB_RGB_COLORS
), 0);
414 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, NULL
, pbi
, DIB_RGB_COLORS
), 1);
415 ok_int(GetDIBits(NULL
, hbmp
, 0, 4, NULL
, pbi
, DIB_RGB_COLORS
), 0);
417 /* Try different biBitCount and biWidth */
418 pbi
->bmiHeader
.biBitCount
= 24;
419 pbi
->bmiHeader
.biWidth
= 3;
420 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
422 /* Try different biBitCount and biWidth */
423 pbi
->bmiHeader
.biBitCount
= 24;
424 pbi
->bmiHeader
.biWidth
= 3;
425 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
427 /* Try invalid biBitCount */
428 pbi
->bmiHeader
.biBitCount
= 17;
429 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
431 /* Set only biBitCount and pjInit */
432 ZeroMemory(pbi
, bisize
);
433 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
434 pbi
->bmiHeader
.biBitCount
= 5;
435 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
438 HeapFree(GetProcessHeap(), 0, pvBits
);
440 /* Test a 4 bpp bitmap */
441 hbmp
= CreateBitmap(3, 5, 1, 4, NULL
);
442 ok(hbmp
!= 0, "failed to create bitmap\n");
443 ZeroMemory(pbi
, bisize
);
444 pbi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
445 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 1);
446 ok_int(pbi
->bmiHeader
.biWidth
, 3);
447 ok_int(pbi
->bmiHeader
.biHeight
, 5);
448 ok_int(pbi
->bmiHeader
.biBitCount
, 4);
449 ok_int(pbi
->bmiHeader
.biSizeImage
, 20);
451 /* This does NOT work with incompatible bitmaps */
452 pbi
->bmiHeader
.biSizeImage
= 0;
453 ok_int(GetDIBits(hdcScreen
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
), 0);
455 /* Calculate bitmap size and allocate a buffer */
456 cjSizeImage
= ((pbi
->bmiHeader
.biWidth
* pbi
->bmiHeader
.biBitCount
+ 31) / 32) * 4 * pbi
->bmiHeader
.biHeight
;
457 ok_int(cjSizeImage
, 20);
458 pvBits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cjSizeImage
);
460 /* Test using a compatible DC */
461 hdcMem
= CreateCompatibleDC(0);
462 ok(hdcMem
!= 0, "CreateCompatibleDC failed, skipping tests\n");
463 if (hdcMem
== NULL
) return;
464 ok_int(GetDIBits(hdcMem
, hbmp
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 0);
465 ok_int(GetDIBits(hdcMem
, ghbmpDIB4
, 0, 4, pvBits
, pbi
, DIB_RGB_COLORS
), 4);
467 HeapFree(GetProcessHeap(), 0, pvBits
);
469 ReleaseDC(NULL
, hdcScreen
);
472 void Test_GetDIBits_BI_BITFIELDS()
476 START_TEST(GetDIBits
)
480 Test_GetDIBits_xBpp(1);
481 Test_GetDIBits_xBpp(4);
482 Test_GetDIBits_xBpp(8);
483 Test_GetDIBits_xBpp(16);
484 Test_GetDIBits_xBpp(24);
485 Test_GetDIBits_xBpp(32);