9c539dd2f9e969dbfb11e1539c88b4b4e806fd57
[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
12 void Test_GetDIBits()
13 {
14 HDC hdcScreen, hdcMem;
15 HBITMAP hbmp;
16 PBITMAPINFO pbi;
17 INT ret, ScreenBpp;
18 DWORD ajBits[10] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
19
20 pbi = malloc(sizeof(BITMAPV5HEADER) + 256 * sizeof(DWORD));
21
22 hdcScreen = GetDC(NULL);
23 ok(hdcScreen != 0, "GetDC failed, skipping tests\n");
24 if (hdcScreen == NULL) return;
25
26 hdcMem = CreateCompatibleDC(0);
27 ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n");
28 if (hdcMem == NULL) return;
29
30 hbmp = CreateCompatibleBitmap(hdcScreen, 16, 16);
31 ok(hbmp != NULL, "CreateCompatibleBitmap failed\n");
32
33 /* misc */
34 SetLastError(ERROR_SUCCESS);
35 ok(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
36 ok_err(ERROR_INVALID_PARAMETER);
37
38 SetLastError(ERROR_SUCCESS);
39 ok(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
40 ok_err(ERROR_INVALID_PARAMETER);
41
42 SetLastError(ERROR_SUCCESS);
43 ok(GetDIBits((HDC)2345, hbmp, 0, 0, NULL, NULL, 0) == 0, "\n");
44 ok_err(ERROR_INVALID_PARAMETER);
45
46 SetLastError(ERROR_SUCCESS);
47 ok(GetDIBits((HDC)2345, hbmp, 0, 15, NULL, pbi, 0) == 0, "\n");
48 ok_err(ERROR_INVALID_PARAMETER);
49
50
51
52 /* null hdc */
53 SetLastError(ERROR_SUCCESS);
54 ZeroMemory(pbi, sizeof(BITMAPINFO));
55 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
56 ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
57 ok_err(ERROR_INVALID_PARAMETER);
58
59 /* null bitmap */
60 SetLastError(ERROR_SUCCESS);
61 ZeroMemory(pbi, sizeof(BITMAPINFO));
62 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
63 ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
64 ok_err(ERROR_SUCCESS);
65
66 /* 0 scan lines */
67 SetLastError(ERROR_SUCCESS);
68 ZeroMemory(pbi, sizeof(BITMAPINFO));
69 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
70 ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
71 ok_err(ERROR_SUCCESS);
72
73 /* null bitmap info - crashes XP*/
74 //SetLastError(ERROR_SUCCESS);
75 //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
76 //ok(GetLastError() == ERROR_INVALID_PARAMETER);
77
78 /* bad bmi colours (uUsage) */
79 SetLastError(ERROR_SUCCESS);
80 ZeroMemory(pbi, sizeof(BITMAPINFO));
81 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
82 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n");
83 ok_err(ERROR_SUCCESS);
84 ok(pbi->bmiHeader.biWidth == 0, "\n");
85 ok(pbi->bmiHeader.biHeight == 0, "\n");
86 ok(pbi->bmiHeader.biBitCount == 0, "\n");
87 ok(pbi->bmiHeader.biSizeImage == 0, "\n");
88
89 /* basic call */
90 SetLastError(ERROR_SUCCESS);
91 ZeroMemory(pbi, sizeof(BITMAPINFO));
92 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
93 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
94 ok_err(ERROR_SUCCESS);
95 ScreenBpp = GetDeviceCaps(hdcScreen, BITSPIXEL);
96 ok(pbi->bmiHeader.biWidth == 16, "\n");
97 ok(pbi->bmiHeader.biHeight == 16, "\n");
98 ok(pbi->bmiHeader.biBitCount == ScreenBpp, "\n");
99 ok(pbi->bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8), "\n");
100
101 /* Test if COREHEADER is supported */
102 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER);
103 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
104 ok(pbi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER), "\n");
105
106 /* Test different header sizes */
107 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER) + 4;
108 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n");
109 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 4;
110 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n");
111 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER);
112 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n");
113 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER) + 4;
114 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n");
115
116
117 DeleteObject(hbmp);
118
119 /* Test a mono bitmap */
120 hbmp = CreateBitmap(13, 7, 1, 1, ajBits);
121 ok(hbmp != 0, "failed to create bitmap\n");
122 ZeroMemory(pbi, sizeof(BITMAPINFO));
123 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
124 ret = GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS);
125 ok(ret == 1, "%d\n", ret);
126 ok(pbi->bmiHeader.biWidth == 13, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth);
127 ok(pbi->bmiHeader.biHeight == 7, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight);
128 ok(pbi->bmiHeader.biBitCount == 1, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount);
129 ok(pbi->bmiHeader.biSizeImage == 28, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage);
130
131 /* Test a mono bitmap with values set */
132 ZeroMemory(pbi, sizeof(BITMAPINFO));
133 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
134 pbi->bmiHeader.biWidth = 12;
135 pbi->bmiHeader.biHeight = 9;
136 pbi->bmiHeader.biPlanes = 1;
137 pbi->bmiHeader.biBitCount = 32;
138 pbi->bmiHeader.biCompression = BI_RGB;
139 pbi->bmiHeader.biSizeImage = 123;
140 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
141 ok(ret == 1, "%d\n", ret);
142 ok(pbi->bmiHeader.biWidth == 12, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth);
143 ok(pbi->bmiHeader.biHeight == 9, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight);
144 ok(pbi->bmiHeader.biBitCount == 32, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount);
145 ok(pbi->bmiHeader.biSizeImage == 432, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage);
146
147 /* Set individual values */
148 ZeroMemory(pbi, sizeof(BITMAPINFO));
149 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
150 pbi->bmiHeader.biWidth = 12;
151 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
152 ok(ret == 1, "%d\n", ret);
153 pbi->bmiHeader.biWidth = 0;
154 pbi->bmiHeader.biSizeImage = 123;
155 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
156 ok(ret == 0, "%d\n", ret);
157 pbi->bmiHeader.biSizeImage = 0;
158 pbi->bmiHeader.biCompression = BI_RGB;
159 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
160 ok(ret == 0, "%d\n", ret);
161
162 DeleteObject(hbmp);
163 DeleteDC(hdcMem);
164 ReleaseDC(NULL, hdcScreen);
165 }
166
167 START_TEST(GetDIBits)
168 {
169 Test_GetDIBits();
170 }
171