ReactOS 0.4.17-dev-1196-gb6224c3
GetDIBits.c
Go to the documentation of this file.
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 "precomp.h"
9
10#include <gditools.h>
11
12void
14 ULONG cBitsPixel)
15{
16 UCHAR ajBuffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
17 PBITMAPINFO pbmi = (PBITMAPINFO)ajBuffer;
19 ULONG cjSizeImage, cColors;
20 HDC hdc;
21
22 hdc = GetDC(0);
23 hbmp = CreateBitmap(3, 3, 1, cBitsPixel, NULL);
24
25 /* Fill in the size field */
26 ZeroMemory(pbmi, sizeof(ajBuffer));
28
29 /* Get info */
31 cjSizeImage = (((pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount) + 31) & ~31) * pbmi->bmiHeader.biHeight / 8;
32 cColors = cBitsPixel <= 8 ? 1 << pbmi->bmiHeader.biBitCount : 0;
33
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);
43 ok_int(pbmi->bmiHeader.biClrUsed, cColors);
45
46// pbmi->bmiHeader.biSizeImage = 0;
47 //ok_int(GetDIBits(NULL, hbmp, 0, 0, NULL, pbmi, DIB_RGB_COLORS), 1);
48
49 /* Test a bitmap with values partly set */
50 ZeroMemory(pbmi, sizeof(ajBuffer));
55 pbmi->bmiHeader.biBitCount = 0; // keep biBitCount == 0!
62 ok_int(pbmi->bmiHeader.biBitCount, cBitsPixel);
63 ok_int(pbmi->bmiHeader.biSizeImage, cjSizeImage);
66 ok_int(pbmi->bmiHeader.biClrUsed, cColors);
68
69
70#if 0
71 /* Get info including the color table */
72 ZeroMemory(pbmi, sizeof(ajBuffer));
76
77 /* Check a different bit depth */
78 pbmi->bmiHeader.biBitCount, cBitsPixel = (cBitsPixel == 1) ? 8 : 1;
80 ok_int(pbmi->bmiHeader.biBitCount, (cBitsPixel == 1) ? 8 : 1);
81
82 /* Get the bits */
83 SetLastError(0);
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);
86 ok_err(0);
87
90 ok_int(GetDIBits(hdc, hbmp, 0, 4, pvBits, pbmi, DIB_RGB_COLORS), 3);
91#endif
92
95}
96
98{
99 HDC hdcScreen, hdcMem;
102 DWORD bisize;
104 PBITMAPV5HEADER pbV5Header;
105 INT ScreenBpp;
106 DWORD ajBits[100] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
107 PVOID pvBits;
108 ULONG cjSizeImage;
109
110 bisize = sizeof(BITMAPV5HEADER) + 256 * sizeof(DWORD);
111 pbi = malloc(bisize);
112 pbch = (PVOID)pbi;
113 pbV5Header = (PVOID)pbi;
114
115 hdcScreen = GetDC(NULL);
116 ok(hdcScreen != 0, "GetDC failed, skipping tests\n");
117 if (hdcScreen == NULL) return;
118
119 hbmp = CreateCompatibleBitmap(hdcScreen, 16, 16);
120 ok(hbmp != NULL, "CreateCompatibleBitmap failed\n");
121
122 /* misc */
124 ok(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
126
128 ok(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
130
132 ok(GetDIBits((HDC)2345, hbmp, 0, 0, NULL, NULL, 0) == 0, "\n");
134
136 ok(GetDIBits((HDC)2345, hbmp, 0, 15, NULL, pbi, 0) == 0, "\n");
138
139 /* Test partly "uninitialized" BITMAPINFO (from wine's gdiplus!GdipCreateBitmapFromHBITMAP) */
140 memset(pbi, 0xCC, bisize);
141 HBITMAP hbm = CreateBitmap(16, 16, 1, 32, NULL);
142 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
143 pbi->bmiHeader.biBitCount = 0;
144 ok_eq_int(GetDIBits(hdcScreen, hbm, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
145 ok_eq_int(pbi->bmiHeader.biWidth, 16);
146 ok_eq_int(pbi->bmiHeader.biHeight, 16);
147 ok_eq_int(pbi->bmiHeader.biPlanes, 1);
148 ok_eq_int(pbi->bmiHeader.biBitCount, 32);
149 ok_eq_int(pbi->bmiHeader.biCompression, BI_BITFIELDS);
150 ok_eq_int(pbi->bmiHeader.biSizeImage, 0x400);
151 ok_eq_int(pbi->bmiHeader.biXPelsPerMeter, 0);
152 ok_eq_int(pbi->bmiHeader.biYPelsPerMeter, 0);
153 ok_eq_int(pbi->bmiHeader.biClrUsed, 0);
154 ok_eq_int(pbi->bmiHeader.biClrImportant, 0);
155 ok_eq_int(*(PULONG)&pbi->bmiColors[0], 0x00FF0000);
156 ok_eq_int(*(PULONG)&pbi->bmiColors[1], 0x0000FF00);
157 ok_eq_int(*(PULONG)&pbi->bmiColors[2], 0x000000FF);
158 ok_eq_int(*(PULONG)&pbi->bmiColors[3], 0xCCCCCCCC);
159 ok_eq_int(*(PULONG)&pbi->bmiColors[255], 0xCCCCCCCC);
161
162 /* null hdc */
164 ZeroMemory(pbi, bisize);
165 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
166 ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
168
169 /* null bitmap */
171 ZeroMemory(pbi, bisize);
172 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
173 ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
175
176 /* 0 scan lines */
178 ZeroMemory(pbi, bisize);
179 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
180 ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
182
183 /* null bitmap info - crashes XP*/
184 //SetLastError(ERROR_SUCCESS);
185 //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
186 //ok(GetLastError() == ERROR_INVALID_PARAMETER);
187
188 /* bad bmi colours (uUsage) */
189 SetLastError(0);
190 ZeroMemory(pbi, bisize);
191 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
192 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n");
194 ok(pbi->bmiHeader.biWidth == 0, "\n");
195 ok(pbi->bmiHeader.biHeight == 0, "\n");
196 ok(pbi->bmiHeader.biBitCount == 0, "\n");
197 ok(pbi->bmiHeader.biSizeImage == 0, "\n");
198
199 /* basic call */
201 ZeroMemory(pbi, bisize);
202 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
203 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
205 ScreenBpp = GetDeviceCaps(hdcScreen, BITSPIXEL);
206 ok(pbi->bmiHeader.biWidth == 16, "\n");
207 ok(pbi->bmiHeader.biHeight == 16, "\n");
208 ok(pbi->bmiHeader.biBitCount == ScreenBpp, "\n");
209 ok(pbi->bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8), "\n");
210
211 /* Test if COREHEADER is supported */
212 ZeroMemory(pbi, bisize);
213 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER);
214 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
215 ok_int(pbi->bmiHeader.biSize, sizeof(BITMAPCOREHEADER));
216 ok_int(pbch->bcWidth, 16);
217 ok_int(pbch->bcHeight, 16);
218 ok_int(pbch->bcPlanes, 1);
219 //ok_int(pbch->bcBitCount, ScreenBpp > 16 ? 24 : ScreenBpp); // fails on XP with screenbpp == 16
220
221 /* Test different header sizes */
222 ZeroMemory(pbi, bisize);
223 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER) + 4;
224 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 0);
225
226 ZeroMemory(pbi, bisize);
227 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 4;
228 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
229
230 ZeroMemory(pbi, bisize);
231 pbi->bmiHeader.biSize = sizeof(BITMAPV4HEADER);
232 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
233
234 ZeroMemory(pbi, bisize);
235 pbi->bmiHeader.biSize = sizeof(BITMAPV4HEADER) + 4;
236 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
237
238 ZeroMemory(pbi, bisize);
239 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER);
240 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
241
242 ZeroMemory(pbi, bisize);
243 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER) + 4;
244 ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
245 ok_int(pbV5Header->bV5RedMask, 0);
246 ok_int(pbV5Header->bV5GreenMask, 0);
247 ok_int(pbV5Header->bV5BlueMask, 0);
248 ok_int(pbV5Header->bV5AlphaMask, 0);
249 ok_int(pbV5Header->bV5CSType, 0);
250 // CIEXYZTRIPLE bV5Endpoints;
251 ok_int(pbV5Header->bV5GammaRed, 0);
252 ok_int(pbV5Header->bV5GammaGreen, 0);
253 ok_int(pbV5Header->bV5GammaBlue, 0);
254 ok_int(pbV5Header->bV5Intent, 0);
255 ok_int(pbV5Header->bV5ProfileData, 0);
256 ok_int(pbV5Header->bV5ProfileSize, 0);
257 ok_int(pbV5Header->bV5Reserved, 0);
258
259 ZeroMemory(pbi, bisize);
260 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
261 ok_int(GetDIBits(hdcScreen, hbmp, 234, 43, NULL, pbi, DIB_RGB_COLORS), 1);
262
264
265 /* Test a mono bitmap */
266 hbmp = CreateBitmap(13, 7, 1, 1, ajBits);
267 ok(hbmp != 0, "failed to create bitmap\n");
268 ZeroMemory(pbi, bisize);
269 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
270 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
271 ok_int(pbi->bmiHeader.biWidth, 13);
272 ok_int(pbi->bmiHeader.biHeight, 7);
273 ok_int(pbi->bmiHeader.biBitCount, 1);
274 ok_int(pbi->bmiHeader.biSizeImage, 28);
275
276 /* Test with values set, except biSizeImage */
277 pbi->bmiHeader.biSizeImage = 0;
278 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
279 ok_int(pbi->bmiHeader.biSizeImage, 28);
280
281 /* Test with different biWidth set */
282 pbi->bmiHeader.biWidth = 17;
283 pbi->bmiHeader.biHeight = 3;
284 pbi->bmiHeader.biSizeImage = 0;
285 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
286 ok_int(pbi->bmiHeader.biSizeImage, 12);
287 ok_int(pbi->bmiHeader.biWidth, 17);
288 ok_int(pbi->bmiHeader.biHeight, 3);
289
290 /* Test with different biBitCount set */
291 pbi->bmiHeader.biBitCount = 4;
292 pbi->bmiHeader.biSizeImage = 1;
293 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
294 ok_int(pbi->bmiHeader.biSizeImage, 36);
295 ok_int(pbi->bmiHeader.biBitCount, 4);
296
297 /* Test with different biBitCount set */
298 pbi->bmiHeader.biBitCount = 8;
299 pbi->bmiHeader.biSizeImage = 1000;
300 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
301 ok_int(pbi->bmiHeader.biSizeImage, 60);
302 ok_int(pbi->bmiHeader.biBitCount, 8);
303
304 /* Test with invalid biBitCount set */
305 pbi->bmiHeader.biBitCount = 123;
306 pbi->bmiHeader.biSizeImage = -12;
307 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0);
308 ok_int(pbi->bmiHeader.biSizeImage, -12);
309 ok_int(pbi->bmiHeader.biBitCount, 123);
310
311 /* Set bitmap dimensions */
312 ok_int(SetBitmapDimensionEx(hbmp, 110, 220, NULL), 1);
313 ZeroMemory(pbi, bisize);
314 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
315 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
316 ok_int(pbi->bmiHeader.biXPelsPerMeter, 0);
317 ok_int(pbi->bmiHeader.biYPelsPerMeter, 0);
318
319 /* Set individual values */
320 ZeroMemory(pbi, bisize);
321 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
322 pbi->bmiHeader.biWidth = 12;
323 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
324 ok_int(pbi->bmiHeader.biWidth, 13);
325 ok_int(pbi->bmiHeader.biSizeImage, 28);
326
327 ZeroMemory(pbi, bisize);
328 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
329 pbi->bmiHeader.biSizeImage = 123;
330 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
331
332 ZeroMemory(pbi, bisize);
333 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
334 pbi->bmiHeader.biCompression = BI_RGB;
335 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
336
337 /* Set only biBitCount */
338 ZeroMemory(pbi, bisize);
339 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
340 pbi->bmiHeader.biBitCount = 5;
341 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
342 pbi->bmiHeader.biBitCount = 1;
343 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
344 pbi->bmiHeader.biBitCount = 8;
345 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
346 pbi->bmiHeader.biBitCount = 32;
347 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
348 ok_int(pbi->bmiHeader.biWidth, 0);
349 ok_int(pbi->bmiHeader.biHeight, 0);
350 ok_int(pbi->bmiHeader.biPlanes, 0);
351 ok_int(pbi->bmiHeader.biBitCount, 32);
352 ok_int(pbi->bmiHeader.biCompression, 0);
353 ok_int(pbi->bmiHeader.biSizeImage, 0);
354
355 /* Get the bitmap info */
356 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
357 pbi->bmiHeader.biWidth = 4;
358 pbi->bmiHeader.biHeight = 4;
359 pbi->bmiHeader.biPlanes = 3;
360 pbi->bmiHeader.biBitCount = 32;
361 pbi->bmiHeader.biCompression = BI_RGB;
362 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
363 ok_int(pbi->bmiHeader.biSizeImage, 64);
364 ok_int(pbi->bmiHeader.biPlanes, 1);
365 pbi->bmiHeader.biWidth = 0;
366 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
367 pbi->bmiHeader.biWidth = 2;
368 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
369 ok_int(pbi->bmiHeader.biSizeImage, 32);
370 pbi->bmiHeader.biWidth = -3;
371 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
372 pbi->bmiHeader.biWidth = 4;
373 pbi->bmiHeader.biHeight = 0;
374 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
375 pbi->bmiHeader.biHeight = -4;
376 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
377 pbi->bmiHeader.biBitCount = 31;
378 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
379 pbi->bmiHeader.biBitCount = 16;
380 pbi->bmiHeader.biPlanes = 23;
381 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
382 ok_int(pbi->bmiHeader.biPlanes, 1);
383 SetLastError(0xdeadbabe);
384 ok_int(GetDIBits((HDC)UlongToHandle(0xff00ff00), hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
385 ok_err(0x57);
386 SetLastError(0xdeadbabe);
387 ok_int(GetDIBits(hdcScreen, (HBITMAP)UlongToHandle(0xff00ff00), 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
388 ok_err(0xdeadbabe);
389 SetLastError(0xdeadbabe);
390 ok_int(GetDIBits((HDC)UlongToHandle(0xff00ff00), (HBITMAP)UlongToHandle(0xff00ff00), 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
391 ok_err(0x57);
392 SetLastError(0xdeadbabe);
394 ok_err(0x57);
395
396 pbi->bmiHeader.biCompression = BI_JPEG;
397 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
398 pbi->bmiHeader.biCompression = BI_PNG;
399 ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
400
401 /* Get the bitmap bits */
402 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
403 pbi->bmiHeader.biWidth = 4;
404 pbi->bmiHeader.biHeight = 4;
405 pbi->bmiHeader.biPlanes = 1;
406 pbi->bmiHeader.biBitCount = 32;
407 pbi->bmiHeader.biCompression = BI_RGB;
408 pbi->bmiHeader.biSizeImage = 0;
409 pbi->bmiHeader.biXPelsPerMeter = 0;
410 pbi->bmiHeader.biYPelsPerMeter = 0;
411 pbi->bmiHeader.biClrUsed = 0;
412 pbi->bmiHeader.biClrImportant = 0;
413 cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
414 pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 512);
415 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
416 ok_int(pbi->bmiHeader.biSize, sizeof(BITMAPINFOHEADER));
417 ok_int(pbi->bmiHeader.biWidth, 4);
418 ok_int(pbi->bmiHeader.biHeight, 4);
419 ok_int(pbi->bmiHeader.biPlanes, 1);
420 ok_int(pbi->bmiHeader.biBitCount, 32);
421 ok_int(pbi->bmiHeader.biCompression, BI_RGB);
422 ok_int(pbi->bmiHeader.biSizeImage, 64);
423 ok_int(pbi->bmiHeader.biXPelsPerMeter, 0);
424 ok_int(pbi->bmiHeader.biYPelsPerMeter, 0);
425 ok_int(pbi->bmiHeader.biClrUsed, 0);
426 ok_int(pbi->bmiHeader.biClrImportant, 0);
427
428 /* Set biBitCount to 0 */
429 pbi->bmiHeader.biBitCount = 0;
430 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
431 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, (PVOID)(LONG_PTR)-1, pbi, DIB_RGB_COLORS), 0);
432 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, NULL, pbi, DIB_RGB_COLORS), 1);
434
435 /* Try different biBitCount and biWidth */
436 pbi->bmiHeader.biBitCount = 24;
437 pbi->bmiHeader.biWidth = 3;
438 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
439
440 /* Try different biBitCount and biWidth */
441 pbi->bmiHeader.biBitCount = 24;
442 pbi->bmiHeader.biWidth = 3;
443 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
444
445 /* Try invalid biBitCount */
446 pbi->bmiHeader.biBitCount = 17;
447 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
448
449 /* Set only biBitCount and pjInit */
450 ZeroMemory(pbi, bisize);
451 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
452 pbi->bmiHeader.biBitCount = 5;
453 ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
454
456 HeapFree(GetProcessHeap(), 0, pvBits);
457
458 /* Test a 4 bpp bitmap */
459 hbmp = CreateBitmap(3, 5, 1, 4, NULL);
460 ok(hbmp != 0, "failed to create bitmap\n");
461 ZeroMemory(pbi, bisize);
462 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
463 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 1);
464 ok_int(pbi->bmiHeader.biWidth, 3);
465 ok_int(pbi->bmiHeader.biHeight, 5);
466 ok_int(pbi->bmiHeader.biBitCount, 4);
467 ok_int(pbi->bmiHeader.biSizeImage, 20);
468
469 /* This does NOT work with incompatible bitmaps */
470 pbi->bmiHeader.biSizeImage = 0;
471 ok_int(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS), 0);
472
473 /* Calculate bitmap size and allocate a buffer */
474 cjSizeImage = ((pbi->bmiHeader.biWidth * pbi->bmiHeader.biBitCount + 31) / 32) * 4 * pbi->bmiHeader.biHeight;
475 ok_int(cjSizeImage, 20);
476 pvBits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cjSizeImage);
477
478 /* Test using a compatible DC */
480 ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n");
481 if (hdcMem == NULL) return;
482 ok_int(GetDIBits(hdcMem, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
483 ok_int(GetDIBits(hdcMem, ghbmpDIB4, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 4);
484
485 HeapFree(GetProcessHeap(), 0, pvBits);
487 ReleaseDC(NULL, hdcScreen);
488}
489
491{
492}
493
495{
496 ok(GdiToolsInit(), "GdiToolsInit failed\n");
497
505}
void Test_GetDIBits_BI_BITFIELDS()
Definition: GetDIBits.c:490
void Test_GetDIBits_xBpp(ULONG cBitsPixel)
Definition: GetDIBits.c:13
void Test_GetDIBits()
Definition: GetDIBits.c:97
#define ok_eq_int(value, expected)
Definition: apitest.h:119
#define ok(value,...)
Definition: atltest.h:57
#define ok_err(error)
Definition: atltest.h:124
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define UlongToHandle(ul)
Definition: basetsd.h:91
HBITMAP hbmp
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
ULONG RGBQUAD
Definition: precomp.h:49
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
BOOL GdiToolsInit(void)
Definition: gditools.c:251
HBITMAP ghbmpDIB4
Definition: gditools.c:23
#define ZeroMemory
Definition: minwinbase.h:31
#define BI_BITFIELDS
Definition: mmreg.h:507
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
_In_ HBITMAP hbm
Definition: ntgdi.h:2804
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2808
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
#define memset(x, y, z)
Definition: compat.h:39
ULONG biClrImportant
Definition: precomp.h:42
USHORT biBitCount
Definition: precomp.h:36
LONG biYPelsPerMeter
Definition: precomp.h:40
ULONG biCompression
Definition: precomp.h:37
LONG biXPelsPerMeter
Definition: precomp.h:39
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
void * PVOID
Definition: typedefs.h:50
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define BI_RGB
Definition: uefivid.c:46
HDC hdcMem
Definition: welcome.c:104
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define BI_JPEG
Definition: wingdi.h:38
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define BITSPIXEL
Definition: wingdi.h:720
struct tagBITMAPINFO * PBITMAPINFO
#define BI_PNG
Definition: wingdi.h:39
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI SetBitmapDimensionEx(_In_ HBITMAP, _In_ int, _In_ int, _Out_opt_ LPSIZE)