ReactOS  0.4.10-dev-238-gc84f398
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 "init.h"
11 
12 void
14  ULONG cBitsPixel)
15 {
16  UCHAR ajBuffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
17  PBITMAPINFO pbmi = (PBITMAPINFO)ajBuffer;
18  HBITMAP hbmp;
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));
27  pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
28 
29  /* Get info */
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;
33 
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);
43  ok_int(pbmi->bmiHeader.biClrUsed, cColors);
44  ok_int(pbmi->bmiHeader.biClrImportant, 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));
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);
66  ok_int(pbmi->bmiHeader.biClrUsed, cColors);
67  ok_int(pbmi->bmiHeader.biClrImportant, cColors);
68 
69 
70 #if 0
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);
76 
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);
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 
88  pbmi->bmiHeader.biPlanes = 2;
89  pbmi->bmiHeader.biClrUsed = 0;
90  ok_int(GetDIBits(hdc, hbmp, 0, 4, pvBits, pbmi, DIB_RGB_COLORS), 3);
91 #endif
92 
93  DeleteObject(hbmp);
94  ReleaseDC(NULL, hdc);
95 }
96 
98 {
99  HDC hdcScreen, hdcMem;
100  HBITMAP hbmp;
102  DWORD bisize;
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  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 
140 
141  /* null hdc */
143  ZeroMemory(pbi, bisize);
144  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
145  ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
147 
148  /* null bitmap */
150  ZeroMemory(pbi, bisize);
151  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
152  ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
154 
155  /* 0 scan lines */
157  ZeroMemory(pbi, bisize);
158  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
159  ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
161 
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);
166 
167  /* bad bmi colours (uUsage) */
168  SetLastError(0);
169  ZeroMemory(pbi, bisize);
170  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
171  ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n");
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");
177 
178  /* basic call */
180  ZeroMemory(pbi, bisize);
181  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
182  ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
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");
189 
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
199 
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);
204 
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);
208 
209  ZeroMemory(pbi, bisize);
210  pbi->bmiHeader.biSize = sizeof(BITMAPV4HEADER);
211  ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
212 
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);
216 
217  ZeroMemory(pbi, bisize);
218  pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER);
219  ok_int(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS), 1);
220 
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);
237 
238  ZeroMemory(pbi, bisize);
239  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
240  ok_int(GetDIBits(hdcScreen, hbmp, 234, 43, NULL, pbi, DIB_RGB_COLORS), 1);
241 
242  DeleteObject(hbmp);
243 
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);
254 
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);
259 
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);
268 
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);
275 
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);
282 
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);
289 
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);
297 
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);
305 
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);
310 
311  ZeroMemory(pbi, bisize);
312  pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
314  ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 1);
315 
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);
333 
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;
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);
364  ok_err(0x57);
365  SetLastError(0xdeadbabe);
366  ok_int(GetDIBits(hdcScreen, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
367  ok_err(0xdeadbabe);
368  SetLastError(0xdeadbabe);
369  ok_int(GetDIBits((HDC)0xff00ff00, (HBITMAP)0xff00ff00, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
370  ok_err(0x57);
371  SetLastError(0xdeadbabe);
372  ok_int(GetDIBits(NULL, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
373  ok_err(0x57);
374 
376  ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
378  ok_int(GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS), 0);
379 
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;
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);
401  ok_int(pbi->bmiHeader.biSizeImage, 64);
404  ok_int(pbi->bmiHeader.biClrUsed, 0);
406 
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);
413 
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);
418 
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);
423 
424  /* Try invalid biBitCount */
425  pbi->bmiHeader.biBitCount = 17;
426  ok_int(GetDIBits(hdcScreen, hbmp, 0, 4, pvBits, pbi, DIB_RGB_COLORS), 0);
427 
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);
433 
434  DeleteObject(hbmp);
435  HeapFree(GetProcessHeap(), 0, pvBits);
436 
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);
447 
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);
451 
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);
456 
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);
463 
464  HeapFree(GetProcessHeap(), 0, pvBits);
465  DeleteDC(hdcMem);
466  ReleaseDC(NULL, hdcScreen);
467 }
468 
470 {
471 }
472 
474 {
475  //getchar();
476  InitStuff();
483  Test_GetDIBits();
484 }
485 
DWORD *typedef PVOID
Definition: winlogon.h:52
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define HDC
Definition: msvc.h:22
#define BITSPIXEL
Definition: wingdi.h:718
#define HBITMAP
Definition: msvc.h:28
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1453
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD biClrImportant
Definition: amvideo.idl:40
#define DIB_PAL_COLORS
Definition: wingdi.h:364
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define ok_int(x, y)
Definition: sprintf.c:21
#define BI_JPEG
Definition: wingdi.h:38
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
void Test_GetDIBits_BI_BITFIELDS()
Definition: GetDIBits.c:469
#define ok_err(error)
Definition: FindFiles.c:39
START_TEST(GetDIBits)
Definition: GetDIBits.c:473
LONG biYPelsPerMeter
Definition: amvideo.idl:38
int32_t INT
Definition: typedefs.h:56
#define BI_BITFIELDS
Definition: mmreg.h:507
DWORD DWORD
Definition: winlogon.h:75
void Test_GetDIBits()
Definition: GetDIBits.c:97
HBITMAP ghbmpDIB4
Definition: init.c:7
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
DWORD biCompression
Definition: amvideo.idl:35
HDC hdc
Definition: msvc.h:53
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917
#define ok(value,...)
Definition: CComObject.cpp:34
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
DWORD biSizeImage
Definition: amvideo.idl:36
#define SetLastError(x)
Definition: compat.h:409
BOOL InitStuff(void)
Definition: init.c:95
unsigned char UCHAR
Definition: xmlstorage.h:181
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
BOOL WINAPI DeleteDC(_In_ HDC)
#define BI_PNG
Definition: wingdi.h:39
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
void Test_GetDIBits_xBpp(ULONG cBitsPixel)
Definition: GetDIBits.c:13
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
BOOL WINAPI SetBitmapDimensionEx(_In_ HBITMAP, _In_ int, _In_ int, _Out_opt_ LPSIZE)
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)
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
struct tagBITMAPINFO * PBITMAPINFO
#define DIB_RGB_COLORS
Definition: wingdi.h:365
HBITMAP hbmp
Definition: msvc.h:60
#define BI_RGB
Definition: precomp.h:35
#define HeapFree(x, y, z)
Definition: compat.h:394
HDC hdcMem
Definition: welcome.c:104
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)