Merge from amd64-branch:
[reactos.git] / rostests / winetests / gdi32 / bitmap.c
1 /*
2 * Unit test suite for bitmaps
3 *
4 * Copyright 2004 Huw Davies
5 * Copyright 2006 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <stdarg.h>
23 #include <assert.h>
24 #include <string.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "mmsystem.h"
32
33 #include "wine/test.h"
34
35 static BOOL (WINAPI *pGdiAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
36
37 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
38
39 static BOOL is_win9x;
40
41 static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
42 {
43 switch(bpp)
44 {
45 case 1:
46 return 2 * ((bmWidth+15) >> 4);
47
48 case 24:
49 bmWidth *= 3; /* fall through */
50 case 8:
51 return bmWidth + (bmWidth & 1);
52
53 case 32:
54 return bmWidth * 4;
55
56 case 16:
57 case 15:
58 return bmWidth * 2;
59
60 case 4:
61 return 2 * ((bmWidth+3) >> 2);
62
63 default:
64 trace("Unknown depth %d, please report.\n", bpp );
65 assert(0);
66 }
67 return -1;
68 }
69
70 static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
71 {
72 BITMAP bm;
73 BITMAP bma[2];
74 INT ret, width_bytes;
75 BYTE buf[512], buf_cmp[512];
76 DWORD gle;
77
78 ret = GetObject(hbm, sizeof(bm), &bm);
79 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
80
81 ok(bm.bmType == 0 || broken(bm.bmType == 21072 /* Win9x */), "wrong bm.bmType %d\n", bm.bmType);
82 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
83 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
84 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
85 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
86 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
87 ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
88 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
89
90 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
91 assert(sizeof(buf) == sizeof(buf_cmp));
92
93 SetLastError(0xdeadbeef);
94 ret = GetBitmapBits(hbm, 0, NULL);
95 gle=GetLastError();
96 ok(ret == bm.bmWidthBytes * bm.bmHeight || (ret == 0 && gle == ERROR_INVALID_PARAMETER /* Win9x */), "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
97
98 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
99 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
100
101 memset(buf, 0xAA, sizeof(buf));
102 ret = GetBitmapBits(hbm, sizeof(buf), buf);
103 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
104 ok(!memcmp(buf, buf_cmp, sizeof(buf)) ||
105 broken(memcmp(buf, buf_cmp, sizeof(buf))), /* win9x doesn't init the bitmap bits */
106 "buffers do not match, depth %d\n", bmih->biBitCount);
107
108 /* test various buffer sizes for GetObject */
109 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
110 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
111
112 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
113 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
114
115 ret = GetObject(hbm, 0, &bm);
116 ok(ret == 0, "%d != 0\n", ret);
117
118 ret = GetObject(hbm, 1, &bm);
119 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
120
121 /* Don't trust Win9x not to try to write to NULL */
122 if (ret == 0)
123 {
124 ret = GetObject(hbm, 0, NULL);
125 ok(ret == sizeof(bm), "wrong size %d\n", ret);
126 }
127 }
128
129 static void test_createdibitmap(void)
130 {
131 HDC hdc, hdcmem;
132 BITMAPINFOHEADER bmih;
133 BITMAPINFO bm;
134 HBITMAP hbm, hbm_colour, hbm_old;
135 INT screen_depth;
136 DWORD pixel;
137
138 hdc = GetDC(0);
139 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
140 memset(&bmih, 0, sizeof(bmih));
141 bmih.biSize = sizeof(bmih);
142 bmih.biWidth = 10;
143 bmih.biHeight = 10;
144 bmih.biPlanes = 1;
145 bmih.biBitCount = 32;
146 bmih.biCompression = BI_RGB;
147
148 hbm = CreateDIBitmap(hdc, NULL, CBM_INIT, NULL, NULL, 0);
149 ok(hbm == NULL, "CreateDIBitmap should fail\n");
150 hbm = CreateDIBitmap(hdc, NULL, 0, NULL, NULL, 0);
151 ok(hbm == NULL, "CreateDIBitmap should fail\n");
152
153 /* First create an un-initialised bitmap. The depth of the bitmap
154 should match that of the hdc and not that supplied in bmih.
155 */
156
157 /* First try 32 bits */
158 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
159 ok(hbm != NULL, "CreateDIBitmap failed\n");
160 test_bitmap_info(hbm, screen_depth, &bmih);
161 DeleteObject(hbm);
162
163 /* Then 16 */
164 bmih.biBitCount = 16;
165 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
166 ok(hbm != NULL, "CreateDIBitmap failed\n");
167 test_bitmap_info(hbm, screen_depth, &bmih);
168 DeleteObject(hbm);
169
170 /* Then 1 */
171 bmih.biBitCount = 1;
172 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
173 ok(hbm != NULL, "CreateDIBitmap failed\n");
174 test_bitmap_info(hbm, screen_depth, &bmih);
175 DeleteObject(hbm);
176
177 /* Now with a monochrome dc we expect a monochrome bitmap */
178 hdcmem = CreateCompatibleDC(hdc);
179
180 /* First try 32 bits */
181 bmih.biBitCount = 32;
182 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
183 ok(hbm != NULL, "CreateDIBitmap failed\n");
184 test_bitmap_info(hbm, 1, &bmih);
185 DeleteObject(hbm);
186
187 /* Then 16 */
188 bmih.biBitCount = 16;
189 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
190 ok(hbm != NULL, "CreateDIBitmap failed\n");
191 test_bitmap_info(hbm, 1, &bmih);
192 DeleteObject(hbm);
193
194 /* Then 1 */
195 bmih.biBitCount = 1;
196 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
197 ok(hbm != NULL, "CreateDIBitmap failed\n");
198 test_bitmap_info(hbm, 1, &bmih);
199 DeleteObject(hbm);
200
201 /* Now select a polychrome bitmap into the dc and we expect
202 screen_depth bitmaps again */
203 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
204 test_bitmap_info(hbm_colour, screen_depth, &bmih);
205 hbm_old = SelectObject(hdcmem, hbm_colour);
206
207 /* First try 32 bits */
208 bmih.biBitCount = 32;
209 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
210 ok(hbm != NULL, "CreateDIBitmap failed\n");
211 test_bitmap_info(hbm, screen_depth, &bmih);
212 DeleteObject(hbm);
213
214 /* Then 16 */
215 bmih.biBitCount = 16;
216 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
217 ok(hbm != NULL, "CreateDIBitmap failed\n");
218 test_bitmap_info(hbm, screen_depth, &bmih);
219 DeleteObject(hbm);
220
221 /* Then 1 */
222 bmih.biBitCount = 1;
223 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
224 ok(hbm != NULL, "CreateDIBitmap failed\n");
225 test_bitmap_info(hbm, screen_depth, &bmih);
226 DeleteObject(hbm);
227
228 SelectObject(hdcmem, hbm_old);
229 DeleteObject(hbm_colour);
230 DeleteDC(hdcmem);
231
232 /* If hdc == 0 then we get a 1 bpp bitmap */
233 if (!is_win9x) {
234 bmih.biBitCount = 32;
235 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
236 ok(hbm != NULL, "CreateDIBitmap failed\n");
237 test_bitmap_info(hbm, 1, &bmih);
238 DeleteObject(hbm);
239 }
240
241 /* Test how formats are converted */
242 pixel = 0xffffffff;
243 bmih.biBitCount = 1;
244 bmih.biWidth = 1;
245 bmih.biHeight = 1;
246
247 memset(&bm, 0, sizeof(bm));
248 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
249 bm.bmiHeader.biWidth = 1;
250 bm.bmiHeader.biHeight = 1;
251 bm.bmiHeader.biPlanes = 1;
252 bm.bmiHeader.biBitCount= 24;
253 bm.bmiHeader.biCompression= BI_RGB;
254 bm.bmiHeader.biSizeImage = 0;
255 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
256 ok(hbm != NULL, "CreateDIBitmap failed\n");
257
258 pixel = 0xdeadbeef;
259 bm.bmiHeader.biBitCount= 32;
260 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
261 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel);
262 DeleteObject(hbm);
263
264 ReleaseDC(0, hdc);
265 }
266
267 static INT DIB_GetWidthBytes( int width, int bpp )
268 {
269 int words;
270
271 switch (bpp)
272 {
273 case 1: words = (width + 31) / 32; break;
274 case 4: words = (width + 7) / 8; break;
275 case 8: words = (width + 3) / 4; break;
276 case 15:
277 case 16: words = (width + 1) / 2; break;
278 case 24: words = (width * 3 + 3)/4; break;
279 case 32: words = width; break;
280
281 default:
282 words=0;
283 trace("Unknown depth %d, please report.\n", bpp );
284 assert(0);
285 break;
286 }
287 return 4 * words;
288 }
289
290 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
291 {
292 BITMAP bm;
293 BITMAP bma[2];
294 DIBSECTION ds;
295 DIBSECTION dsa[2];
296 INT ret, bm_width_bytes, dib_width_bytes;
297 BYTE *buf;
298
299 ret = GetObject(hbm, sizeof(bm), &bm);
300 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
301
302 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
303 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
304 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
305 dib_width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
306 bm_width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
307 if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
308 ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
309 else
310 ok(bm.bmWidthBytes == dib_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, dib_width_bytes);
311 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
312 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
313 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
314
315 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
316
317 /* GetBitmapBits returns not 32-bit aligned data */
318 SetLastError(0xdeadbeef);
319 ret = GetBitmapBits(hbm, 0, NULL);
320 ok(ret == bm_width_bytes * bm.bmHeight ||
321 broken(ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */
322 "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
323
324 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
325 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
326 ok(ret == bm_width_bytes * bm.bmHeight, "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
327
328 HeapFree(GetProcessHeap(), 0, buf);
329
330 /* test various buffer sizes for GetObject */
331 memset(&ds, 0xAA, sizeof(ds));
332 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
333 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
334 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
335 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
336 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
337
338 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
339 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
340
341 ret = GetObject(hbm, 0, &bm);
342 ok(ret == 0, "%d != 0\n", ret);
343
344 ret = GetObject(hbm, 1, &bm);
345 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
346
347 /* test various buffer sizes for GetObject */
348 ret = GetObject(hbm, 0, NULL);
349 ok(ret == sizeof(bm) || broken(ret == sizeof(DIBSECTION) /* Win9x */), "wrong size %d\n", ret);
350
351 ret = GetObject(hbm, sizeof(*dsa) * 2, dsa);
352 ok(ret == sizeof(*dsa) || broken(ret == sizeof(*dsa) * 2 /* Win9x */), "wrong size %d\n", ret);
353
354 memset(&ds, 0xAA, sizeof(ds));
355 ret = GetObject(hbm, sizeof(ds), &ds);
356 ok(ret == sizeof(ds), "wrong size %d\n", ret);
357
358 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
359 if (ds.dsBm.bmWidthBytes != bm_width_bytes) /* Win2k bug */
360 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
361 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
362 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
363 ds.dsBmih.biSizeImage = 0;
364
365 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
366 ok(ds.dsBmih.biWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
367 ok(ds.dsBmih.biHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
368 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
369 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
370 ok(ds.dsBmih.biCompression == bmih->biCompression, "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
371 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
372 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%u != %u\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
373 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%u != %u\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
374
375 memset(&ds, 0xAA, sizeof(ds));
376 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
377 ok(ret == sizeof(ds.dsBm) || broken(ret == (sizeof(ds) - 4) /* Win9x */), "wrong size %d\n", ret);
378 ok(ds.dsBm.bmWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
379 ok(ds.dsBm.bmHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
380 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
381
382 ret = GetObject(hbm, 0, &ds);
383 ok(ret == 0, "%d != 0\n", ret);
384
385 ret = GetObject(hbm, 1, &ds);
386 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
387 }
388
389 #define test_color_todo(got, exp, txt, todo) \
390 if (!todo && got != exp && screen_depth < 24) { \
391 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
392 screen_depth, (UINT)got, (UINT)exp); \
393 return; \
394 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
395 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
396
397 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
398 { \
399 COLORREF c; \
400 c = SetPixel(hdc, 0, 0, color); \
401 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
402 c = GetPixel(hdc, 0, 0); \
403 test_color_todo(c, exp, GetPixel, todo_getp); \
404 }
405
406 static void test_dib_bits_access( HBITMAP hdib, void *bits )
407 {
408 MEMORY_BASIC_INFORMATION info;
409 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
410 DWORD data[256];
411 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
412 HDC hdc = GetDC(0);
413 char filename[MAX_PATH];
414 HANDLE file;
415 DWORD written;
416 INT ret;
417
418 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
419 "VirtualQuery failed\n");
420 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
421 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
422 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
423 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
424 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
425 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
426
427 memset( pbmi, 0, sizeof(bmibuf) );
428 memset( data, 0xcc, sizeof(data) );
429 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
430 pbmi->bmiHeader.biHeight = 16;
431 pbmi->bmiHeader.biWidth = 16;
432 pbmi->bmiHeader.biBitCount = 32;
433 pbmi->bmiHeader.biPlanes = 1;
434 pbmi->bmiHeader.biCompression = BI_RGB;
435
436 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
437 ok(ret == 16 ||
438 broken(ret == 0), /* win9x */
439 "SetDIBits failed: expected 16 got %d\n", ret);
440
441 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
442 "VirtualQuery failed\n");
443 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
444 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
445 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
446 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
447 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
448 /* it has been protected now */
449 todo_wine ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
450
451 /* try writing protected bits to a file */
452
453 GetTempFileNameA( ".", "dib", 0, filename );
454 file = CreateFileA( filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
455 CREATE_ALWAYS, 0, 0 );
456 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %u\n", filename, GetLastError() );
457 ret = WriteFile( file, bits, 8192, &written, NULL );
458 ok( ret, "WriteFile failed error %u\n", GetLastError() );
459 if (ret) ok( written == 8192, "only wrote %u bytes\n", written );
460 CloseHandle( file );
461 DeleteFileA( filename );
462 }
463
464 static void test_dibsections(void)
465 {
466 HDC hdc, hdcmem, hdcmem2;
467 HBITMAP hdib, oldbm, hdib2, oldbm2;
468 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
469 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
470 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
471 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
472 HBITMAP hcoredib;
473 char coreBits[256];
474 BYTE *bits;
475 RGBQUAD rgb[256];
476 int ret;
477 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
478 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
479 WORD *index;
480 DWORD *bits32;
481 HPALETTE hpal, oldpal;
482 DIBSECTION dibsec;
483 COLORREF c0, c1;
484 int i;
485 int screen_depth;
486 MEMORY_BASIC_INFORMATION info;
487
488 hdc = GetDC(0);
489 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
490
491 memset(pbmi, 0, sizeof(bmibuf));
492 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
493 pbmi->bmiHeader.biHeight = 100;
494 pbmi->bmiHeader.biWidth = 512;
495 pbmi->bmiHeader.biBitCount = 24;
496 pbmi->bmiHeader.biPlanes = 1;
497 pbmi->bmiHeader.biCompression = BI_RGB;
498
499 SetLastError(0xdeadbeef);
500
501 /* invalid pointer for BITMAPINFO
502 (*bits should be NULL on error) */
503 bits = (BYTE*)0xdeadbeef;
504 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
505 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
506
507 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
508 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
509 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
510 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
511
512 /* test the DIB memory */
513 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
514 "VirtualQuery failed\n");
515 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
516 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
517 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
518 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
519 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
520 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
521 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
522
523 test_dib_bits_access( hdib, bits );
524
525 test_dib_info(hdib, bits, &pbmi->bmiHeader);
526 DeleteObject(hdib);
527
528 pbmi->bmiHeader.biBitCount = 8;
529 pbmi->bmiHeader.biCompression = BI_RLE8;
530 SetLastError(0xdeadbeef);
531 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
532 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
533 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
534
535 pbmi->bmiHeader.biBitCount = 16;
536 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
537 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
538 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
539 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
540 SetLastError(0xdeadbeef);
541 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
542 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
543
544 /* test the DIB memory */
545 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
546 "VirtualQuery failed\n");
547 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
548 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
549 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
550 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
551 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
552 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
553 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
554
555 test_dib_info(hdib, bits, &pbmi->bmiHeader);
556 DeleteObject(hdib);
557
558 memset(pbmi, 0, sizeof(bmibuf));
559 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
560 pbmi->bmiHeader.biHeight = 16;
561 pbmi->bmiHeader.biWidth = 16;
562 pbmi->bmiHeader.biBitCount = 1;
563 pbmi->bmiHeader.biPlanes = 1;
564 pbmi->bmiHeader.biCompression = BI_RGB;
565 pbmi->bmiColors[0].rgbRed = 0xff;
566 pbmi->bmiColors[0].rgbGreen = 0;
567 pbmi->bmiColors[0].rgbBlue = 0;
568 pbmi->bmiColors[1].rgbRed = 0;
569 pbmi->bmiColors[1].rgbGreen = 0;
570 pbmi->bmiColors[1].rgbBlue = 0xff;
571
572 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
573 ok(hdib != NULL, "CreateDIBSection failed\n");
574 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
575 ok(dibsec.dsBmih.biClrUsed == 2,
576 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
577
578 /* Test if the old BITMAPCOREINFO structure is supported */
579
580 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
581 pbci->bmciHeader.bcBitCount = 0;
582
583 if (!is_win9x) {
584 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
585 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
586 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
587 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
588 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
589
590 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
591 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
592 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
593 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
594 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
595 "The color table has not been translated to the old BITMAPCOREINFO format\n");
596
597 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
598 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
599
600 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
601 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
602 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
603 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
604 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
605 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
606 "The color table has not been translated to the old BITMAPCOREINFO format\n");
607
608 DeleteObject(hcoredib);
609 }
610
611 hdcmem = CreateCompatibleDC(hdc);
612 oldbm = SelectObject(hdcmem, hdib);
613
614 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
615 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
616 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
617 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
618 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
619 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
620
621 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
622 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
623
624 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
625 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
626 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
627 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
628 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
629 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
630 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
631 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
632 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
633 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
634 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
635 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
636 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
637
638 SelectObject(hdcmem, oldbm);
639 DeleteObject(hdib);
640
641 pbmi->bmiColors[0].rgbRed = 0xff;
642 pbmi->bmiColors[0].rgbGreen = 0xff;
643 pbmi->bmiColors[0].rgbBlue = 0xff;
644 pbmi->bmiColors[1].rgbRed = 0;
645 pbmi->bmiColors[1].rgbGreen = 0;
646 pbmi->bmiColors[1].rgbBlue = 0;
647
648 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
649 ok(hdib != NULL, "CreateDIBSection failed\n");
650
651 test_dib_info(hdib, bits, &pbmi->bmiHeader);
652
653 oldbm = SelectObject(hdcmem, hdib);
654
655 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
656 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
657 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
658 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
659 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
660 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
661
662 SelectObject(hdcmem, oldbm);
663 test_dib_info(hdib, bits, &pbmi->bmiHeader);
664 DeleteObject(hdib);
665
666 pbmi->bmiHeader.biBitCount = 4;
667 for (i = 0; i < 16; i++) {
668 pbmi->bmiColors[i].rgbRed = i;
669 pbmi->bmiColors[i].rgbGreen = 16-i;
670 pbmi->bmiColors[i].rgbBlue = 0;
671 }
672 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
673 ok(hdib != NULL, "CreateDIBSection failed\n");
674 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
675 ok(dibsec.dsBmih.biClrUsed == 16,
676 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
677 test_dib_info(hdib, bits, &pbmi->bmiHeader);
678 DeleteObject(hdib);
679
680 pbmi->bmiHeader.biBitCount = 8;
681
682 for (i = 0; i < 128; i++) {
683 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
684 pbmi->bmiColors[i].rgbGreen = i * 2;
685 pbmi->bmiColors[i].rgbBlue = 0;
686 pbmi->bmiColors[255 - i].rgbRed = 0;
687 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
688 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
689 }
690 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
691 ok(hdib != NULL, "CreateDIBSection failed\n");
692 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
693 ok(dibsec.dsBmih.biClrUsed == 256,
694 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
695
696 oldbm = SelectObject(hdcmem, hdib);
697
698 for (i = 0; i < 256; i++) {
699 test_color(hdcmem, DIBINDEX(i),
700 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
701 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
702 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
703 }
704
705 SelectObject(hdcmem, oldbm);
706 test_dib_info(hdib, bits, &pbmi->bmiHeader);
707 DeleteObject(hdib);
708
709 pbmi->bmiHeader.biBitCount = 1;
710
711 /* Now create a palette and a palette indexed dib section */
712 memset(plogpal, 0, sizeof(logpalbuf));
713 plogpal->palVersion = 0x300;
714 plogpal->palNumEntries = 2;
715 plogpal->palPalEntry[0].peRed = 0xff;
716 plogpal->palPalEntry[0].peBlue = 0xff;
717 plogpal->palPalEntry[1].peGreen = 0xff;
718
719 index = (WORD*)pbmi->bmiColors;
720 *index++ = 0;
721 *index = 1;
722 hpal = CreatePalette(plogpal);
723 ok(hpal != NULL, "CreatePalette failed\n");
724 oldpal = SelectPalette(hdc, hpal, TRUE);
725 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
726 ok(hdib != NULL, "CreateDIBSection failed\n");
727 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
728 ok(dibsec.dsBmih.biClrUsed == 2 ||
729 broken(dibsec.dsBmih.biClrUsed == 0), /* win9x */
730 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
731
732 /* The colour table has already been grabbed from the dc, so we select back the
733 old palette */
734
735 SelectPalette(hdc, oldpal, TRUE);
736 oldbm = SelectObject(hdcmem, hdib);
737 oldpal = SelectPalette(hdcmem, hpal, TRUE);
738
739 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
740 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
741 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
742 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
743 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
744 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
745 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
746
747 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
748 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
749
750 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
751 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
752 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
753 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
754 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
755 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
756 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
757 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
758 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
759 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
760 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
761 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
762 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
763 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
764 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
765 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
766
767 /* Bottom and 2nd row from top green, everything else magenta */
768 bits[0] = bits[1] = 0xff;
769 bits[13 * 4] = bits[13*4 + 1] = 0xff;
770
771 test_dib_info(hdib, bits, &pbmi->bmiHeader);
772
773 pbmi->bmiHeader.biBitCount = 32;
774
775 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
776 ok(hdib2 != NULL, "CreateDIBSection failed\n");
777 hdcmem2 = CreateCompatibleDC(hdc);
778 oldbm2 = SelectObject(hdcmem2, hdib2);
779
780 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
781
782 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
783 ok(bits32[17] == 0xff00ff ||
784 broken(bits32[17] == 0x00ff00), /* Intermittent on Win9x/ME */
785 "bottom but one, left pixel is %08x\n", bits32[17]);
786
787 SelectObject(hdcmem2, oldbm2);
788 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
789 DeleteObject(hdib2);
790
791 SelectObject(hdcmem, oldbm);
792 SelectObject(hdcmem, oldpal);
793 DeleteObject(hdib);
794 DeleteObject(hpal);
795
796
797 pbmi->bmiHeader.biBitCount = 8;
798
799 memset(plogpal, 0, sizeof(logpalbuf));
800 plogpal->palVersion = 0x300;
801 plogpal->palNumEntries = 256;
802
803 for (i = 0; i < 128; i++) {
804 plogpal->palPalEntry[i].peRed = 255 - i * 2;
805 plogpal->palPalEntry[i].peBlue = i * 2;
806 plogpal->palPalEntry[i].peGreen = 0;
807 plogpal->palPalEntry[255 - i].peRed = 0;
808 plogpal->palPalEntry[255 - i].peGreen = i * 2;
809 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
810 }
811
812 index = (WORD*)pbmi->bmiColors;
813 for (i = 0; i < 256; i++) {
814 *index++ = i;
815 }
816
817 hpal = CreatePalette(plogpal);
818 ok(hpal != NULL, "CreatePalette failed\n");
819 oldpal = SelectPalette(hdc, hpal, TRUE);
820 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
821 ok(hdib != NULL, "CreateDIBSection failed\n");
822 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
823 ok(dibsec.dsBmih.biClrUsed == 256 ||
824 broken(dibsec.dsBmih.biClrUsed == 0), /* win9x */
825 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
826
827 test_dib_info(hdib, bits, &pbmi->bmiHeader);
828
829 SelectPalette(hdc, oldpal, TRUE);
830 oldbm = SelectObject(hdcmem, hdib);
831 oldpal = SelectPalette(hdcmem, hpal, TRUE);
832
833 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
834 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
835 for (i = 0; i < 256; i++) {
836 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
837 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
838 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
839 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
840 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
841 }
842
843 for (i = 0; i < 256; i++) {
844 test_color(hdcmem, DIBINDEX(i),
845 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
846 test_color(hdcmem, PALETTEINDEX(i),
847 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
848 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
849 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
850 }
851
852 SelectPalette(hdcmem, oldpal, TRUE);
853 SelectObject(hdcmem, oldbm);
854 DeleteObject(hdib);
855 DeleteObject(hpal);
856
857
858 DeleteDC(hdcmem);
859 ReleaseDC(0, hdc);
860 }
861
862 static void test_mono_dibsection(void)
863 {
864 HDC hdc, memdc;
865 HBITMAP old_bm, mono_ds;
866 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
867 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
868 BYTE bits[10 * 4];
869 BYTE *ds_bits;
870 int num;
871
872 hdc = GetDC(0);
873
874 memdc = CreateCompatibleDC(hdc);
875
876 memset(pbmi, 0, sizeof(bmibuf));
877 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
878 pbmi->bmiHeader.biHeight = 10;
879 pbmi->bmiHeader.biWidth = 10;
880 pbmi->bmiHeader.biBitCount = 1;
881 pbmi->bmiHeader.biPlanes = 1;
882 pbmi->bmiHeader.biCompression = BI_RGB;
883 pbmi->bmiColors[0].rgbRed = 0xff;
884 pbmi->bmiColors[0].rgbGreen = 0xff;
885 pbmi->bmiColors[0].rgbBlue = 0xff;
886 pbmi->bmiColors[1].rgbRed = 0x0;
887 pbmi->bmiColors[1].rgbGreen = 0x0;
888 pbmi->bmiColors[1].rgbBlue = 0x0;
889
890 /*
891 * First dib section is 'inverted' ie color[0] is white, color[1] is black
892 */
893
894 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
895 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
896 old_bm = SelectObject(memdc, mono_ds);
897
898 /* black border, white interior */
899 Rectangle(memdc, 0, 0, 10, 10);
900 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
901 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
902
903 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
904
905 memset(bits, 0, sizeof(bits));
906 bits[0] = 0xaa;
907
908 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
909 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
910
911 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
912
913 pbmi->bmiColors[0].rgbRed = 0x0;
914 pbmi->bmiColors[0].rgbGreen = 0x0;
915 pbmi->bmiColors[0].rgbBlue = 0x0;
916 pbmi->bmiColors[1].rgbRed = 0xff;
917 pbmi->bmiColors[1].rgbGreen = 0xff;
918 pbmi->bmiColors[1].rgbBlue = 0xff;
919
920 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
921 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
922
923 SelectObject(memdc, old_bm);
924 DeleteObject(mono_ds);
925
926 /*
927 * Next dib section is 'normal' ie color[0] is black, color[1] is white
928 */
929
930 pbmi->bmiColors[0].rgbRed = 0x0;
931 pbmi->bmiColors[0].rgbGreen = 0x0;
932 pbmi->bmiColors[0].rgbBlue = 0x0;
933 pbmi->bmiColors[1].rgbRed = 0xff;
934 pbmi->bmiColors[1].rgbGreen = 0xff;
935 pbmi->bmiColors[1].rgbBlue = 0xff;
936
937 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
938 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
939 old_bm = SelectObject(memdc, mono_ds);
940
941 /* black border, white interior */
942 Rectangle(memdc, 0, 0, 10, 10);
943 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
944 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
945
946 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
947
948 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
949 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
950
951 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
952
953 pbmi->bmiColors[0].rgbRed = 0xff;
954 pbmi->bmiColors[0].rgbGreen = 0xff;
955 pbmi->bmiColors[0].rgbBlue = 0xff;
956 pbmi->bmiColors[1].rgbRed = 0x0;
957 pbmi->bmiColors[1].rgbGreen = 0x0;
958 pbmi->bmiColors[1].rgbBlue = 0x0;
959
960 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
961 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
962
963 /*
964 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
965 */
966
967 pbmi->bmiColors[0].rgbRed = 0xff;
968 pbmi->bmiColors[0].rgbGreen = 0xff;
969 pbmi->bmiColors[0].rgbBlue = 0xff;
970 pbmi->bmiColors[1].rgbRed = 0x0;
971 pbmi->bmiColors[1].rgbGreen = 0x0;
972 pbmi->bmiColors[1].rgbBlue = 0x0;
973 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
974 ok(num == 2, "num = %d\n", num);
975
976 /* black border, white interior */
977 Rectangle(memdc, 0, 0, 10, 10);
978 todo_wine {
979 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
980 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
981 }
982 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
983
984 memset(bits, 0, sizeof(bits));
985 bits[0] = 0xaa;
986
987 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
988 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
989
990 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
991
992 pbmi->bmiColors[0].rgbRed = 0x0;
993 pbmi->bmiColors[0].rgbGreen = 0x0;
994 pbmi->bmiColors[0].rgbBlue = 0x0;
995 pbmi->bmiColors[1].rgbRed = 0xff;
996 pbmi->bmiColors[1].rgbGreen = 0xff;
997 pbmi->bmiColors[1].rgbBlue = 0xff;
998
999 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1000 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1001
1002 SelectObject(memdc, old_bm);
1003 DeleteObject(mono_ds);
1004
1005 /*
1006 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1007 */
1008
1009 pbmi->bmiColors[0].rgbRed = 0xff;
1010 pbmi->bmiColors[0].rgbGreen = 0x0;
1011 pbmi->bmiColors[0].rgbBlue = 0x0;
1012 pbmi->bmiColors[1].rgbRed = 0xfe;
1013 pbmi->bmiColors[1].rgbGreen = 0x0;
1014 pbmi->bmiColors[1].rgbBlue = 0x0;
1015
1016 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1017 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1018 old_bm = SelectObject(memdc, mono_ds);
1019
1020 /* black border, white interior */
1021 Rectangle(memdc, 0, 0, 10, 10);
1022 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1023 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1024
1025 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1026
1027 pbmi->bmiColors[0].rgbRed = 0x0;
1028 pbmi->bmiColors[0].rgbGreen = 0x0;
1029 pbmi->bmiColors[0].rgbBlue = 0x0;
1030 pbmi->bmiColors[1].rgbRed = 0xff;
1031 pbmi->bmiColors[1].rgbGreen = 0xff;
1032 pbmi->bmiColors[1].rgbBlue = 0xff;
1033
1034 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1035 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1036
1037 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1038
1039 pbmi->bmiColors[0].rgbRed = 0xff;
1040 pbmi->bmiColors[0].rgbGreen = 0xff;
1041 pbmi->bmiColors[0].rgbBlue = 0xff;
1042 pbmi->bmiColors[1].rgbRed = 0x0;
1043 pbmi->bmiColors[1].rgbGreen = 0x0;
1044 pbmi->bmiColors[1].rgbBlue = 0x0;
1045
1046 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1047 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1048
1049 SelectObject(memdc, old_bm);
1050 DeleteObject(mono_ds);
1051
1052 DeleteDC(memdc);
1053 ReleaseDC(0, hdc);
1054 }
1055
1056 static void test_bitmap(void)
1057 {
1058 char buf[256], buf_cmp[256];
1059 HBITMAP hbmp, hbmp_old;
1060 HDC hdc;
1061 BITMAP bm;
1062 BITMAP bma[2];
1063 INT ret;
1064
1065 hdc = CreateCompatibleDC(0);
1066 assert(hdc != 0);
1067
1068 SetLastError(0xdeadbeef);
1069 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1070 if (!hbmp)
1071 {
1072 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1073 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1074 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1075 }
1076 else
1077 DeleteObject(hbmp);
1078
1079 SetLastError(0xdeadbeef);
1080 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1081 if (!hbmp)
1082 {
1083 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1084 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1085 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1086 }
1087 else
1088 DeleteObject(hbmp);
1089
1090 SetLastError(0xdeadbeef);
1091 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1092 ok(!hbmp || broken(hbmp != NULL /* Win9x */), "CreateBitmap should fail\n");
1093 if (!hbmp)
1094 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1095 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1096 else
1097 DeleteObject(hbmp);
1098
1099 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1100 assert(hbmp != NULL);
1101
1102 ret = GetObject(hbmp, sizeof(bm), &bm);
1103 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1104
1105 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1106 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1107 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1108 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1109 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1110 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1111 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1112
1113 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1114 assert(sizeof(buf) == sizeof(buf_cmp));
1115
1116 ret = GetBitmapBits(hbmp, 0, NULL);
1117 ok(ret == bm.bmWidthBytes * bm.bmHeight || broken(ret == 0 /* Win9x */),
1118 "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1119
1120 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1121 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1122
1123 memset(buf, 0xAA, sizeof(buf));
1124 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1125 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1126 ok(!memcmp(buf, buf_cmp, sizeof(buf)) ||
1127 broken(memcmp(buf, buf_cmp, sizeof(buf))), /* win9x doesn't init the bitmap bits */
1128 "buffers do not match\n");
1129
1130 hbmp_old = SelectObject(hdc, hbmp);
1131
1132 ret = GetObject(hbmp, sizeof(bm), &bm);
1133 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1134
1135 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1136 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1137 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1138 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1139 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1140 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1141 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1142
1143 memset(buf, 0xAA, sizeof(buf));
1144 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1145 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1146 ok(!memcmp(buf, buf_cmp, sizeof(buf)) ||
1147 broken(memcmp(buf, buf_cmp, sizeof(buf))), /* win9x doesn't init the bitmap bits */
1148 "buffers do not match\n");
1149
1150 hbmp_old = SelectObject(hdc, hbmp_old);
1151 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1152
1153 /* test various buffer sizes for GetObject */
1154 ret = GetObject(hbmp, sizeof(*bma) * 2, bma);
1155 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
1156
1157 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1158 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
1159
1160 ret = GetObject(hbmp, 0, &bm);
1161 ok(ret == 0, "%d != 0\n", ret);
1162
1163 ret = GetObject(hbmp, 1, &bm);
1164 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
1165
1166 DeleteObject(hbmp);
1167 DeleteDC(hdc);
1168 }
1169
1170 static void test_bmBits(void)
1171 {
1172 BYTE bits[4];
1173 HBITMAP hbmp;
1174 BITMAP bmp;
1175
1176 memset(bits, 0, sizeof(bits));
1177 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1178 ok(hbmp != NULL, "CreateBitmap failed\n");
1179
1180 memset(&bmp, 0xFF, sizeof(bmp));
1181 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1182 "GetObject failed or returned a wrong structure size\n");
1183 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1184
1185 DeleteObject(hbmp);
1186 }
1187
1188 static void test_GetDIBits_selected_DIB(UINT bpp)
1189 {
1190 HBITMAP dib;
1191 BITMAPINFO * info;
1192 BITMAPINFO * info2;
1193 void * bits;
1194 void * bits2;
1195 UINT dib_size;
1196 HDC dib_dc, dc;
1197 HBITMAP old_bmp;
1198 BOOL equalContents;
1199 UINT i;
1200 int res;
1201
1202 /* Create a DIB section with a color table */
1203
1204 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1205 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1206 assert(info);
1207 assert(info2);
1208
1209 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1210
1211 /* Choose width and height such that the row length (in bytes)
1212 is a multiple of 4 (makes things easier) */
1213 info->bmiHeader.biWidth = 32;
1214 info->bmiHeader.biHeight = 32;
1215 info->bmiHeader.biPlanes = 1;
1216 info->bmiHeader.biBitCount = bpp;
1217 info->bmiHeader.biCompression = BI_RGB;
1218
1219 for (i=0; i < (1u << bpp); i++)
1220 {
1221 BYTE c = i * (1 << (8 - bpp));
1222 info->bmiColors[i].rgbRed = c;
1223 info->bmiColors[i].rgbGreen = c;
1224 info->bmiColors[i].rgbBlue = c;
1225 info->bmiColors[i].rgbReserved = 0;
1226 }
1227
1228 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1229 assert(dib);
1230 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1231
1232 /* Set the bits of the DIB section */
1233 for (i=0; i < dib_size; i++)
1234 {
1235 ((BYTE *)bits)[i] = i % 256;
1236 }
1237
1238 /* Select the DIB into a DC */
1239 dib_dc = CreateCompatibleDC(NULL);
1240 old_bmp = SelectObject(dib_dc, dib);
1241 dc = CreateCompatibleDC(NULL);
1242 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib_size);
1243 assert(bits2);
1244
1245 /* Copy the DIB attributes but not the color table */
1246 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1247
1248 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1249 ok(res, "GetDIBits failed\n");
1250
1251 /* Compare the color table and the bits */
1252 equalContents = TRUE;
1253 for (i=0; i < (1u << bpp); i++)
1254 {
1255 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1256 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1257 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1258 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1259 {
1260 equalContents = FALSE;
1261 break;
1262 }
1263 }
1264 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1265
1266 equalContents = TRUE;
1267 for (i=0; i < dib_size / sizeof(DWORD); i++)
1268 {
1269 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1270 {
1271 equalContents = FALSE;
1272 break;
1273 }
1274 }
1275 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1276
1277 HeapFree(GetProcessHeap(), 0, bits2);
1278 DeleteDC(dc);
1279
1280 SelectObject(dib_dc, old_bmp);
1281 DeleteDC(dib_dc);
1282 DeleteObject(dib);
1283
1284 HeapFree(GetProcessHeap(), 0, info2);
1285 HeapFree(GetProcessHeap(), 0, info);
1286 }
1287
1288 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1289 {
1290 HBITMAP ddb;
1291 BITMAPINFO * info;
1292 BITMAPINFO * info2;
1293 void * bits;
1294 void * bits2;
1295 HDC ddb_dc, dc;
1296 HBITMAP old_bmp;
1297 BOOL equalContents;
1298 UINT width, height;
1299 UINT bpp;
1300 UINT i, j;
1301 int res;
1302
1303 width = height = 16;
1304
1305 /* Create a DDB (device-dependent bitmap) */
1306 if (monochrome)
1307 {
1308 bpp = 1;
1309 ddb = CreateBitmap(width, height, 1, 1, NULL);
1310 }
1311 else
1312 {
1313 HDC screen_dc = GetDC(NULL);
1314 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1315 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1316 ReleaseDC(NULL, screen_dc);
1317 }
1318
1319 /* Set the pixels */
1320 ddb_dc = CreateCompatibleDC(NULL);
1321 old_bmp = SelectObject(ddb_dc, ddb);
1322 for (i = 0; i < width; i++)
1323 {
1324 for (j=0; j < height; j++)
1325 {
1326 BYTE c = (i * width + j) % 256;
1327 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1328 }
1329 }
1330 SelectObject(ddb_dc, old_bmp);
1331
1332 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1333 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1334 assert(info);
1335 assert(info2);
1336
1337 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1338 info->bmiHeader.biWidth = width;
1339 info->bmiHeader.biHeight = height;
1340 info->bmiHeader.biPlanes = 1;
1341 info->bmiHeader.biBitCount = bpp;
1342 info->bmiHeader.biCompression = BI_RGB;
1343
1344 dc = CreateCompatibleDC(NULL);
1345
1346 /* Fill in biSizeImage */
1347 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1348 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1349
1350 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1351 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1352 assert(bits);
1353 assert(bits2);
1354
1355 /* Get the bits */
1356 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1357 ok(res, "GetDIBits failed\n");
1358
1359 /* Copy the DIB attributes but not the color table */
1360 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1361
1362 /* Select the DDB into another DC */
1363 old_bmp = SelectObject(ddb_dc, ddb);
1364
1365 /* Get the bits */
1366 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1367 ok(res, "GetDIBits failed\n");
1368
1369 /* Compare the color table and the bits */
1370 if (bpp <= 8)
1371 {
1372 equalContents = TRUE;
1373 for (i=0; i < (1u << bpp); i++)
1374 {
1375 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1376 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1377 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1378 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1379 {
1380 equalContents = FALSE;
1381 break;
1382 }
1383 }
1384 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1385 }
1386
1387 equalContents = TRUE;
1388 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1389 {
1390 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1391 {
1392 equalContents = FALSE;
1393 }
1394 }
1395 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1396
1397 /* Test the palette */
1398 equalContents = TRUE;
1399 if (info2->bmiHeader.biBitCount <= 8)
1400 {
1401 WORD *colors = (WORD*)info2->bmiColors;
1402
1403 /* Get the palette indices */
1404 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1405 if (res == 0 && GetLastError() == ERROR_INVALID_PARAMETER) /* Win9x */
1406 res = GetDIBits(dc, ddb, 0, height, NULL, info2, DIB_PAL_COLORS);
1407 ok(res, "GetDIBits failed\n");
1408
1409 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1410 {
1411 if (colors[i] != i)
1412 {
1413 equalContents = FALSE;
1414 break;
1415 }
1416 }
1417 }
1418
1419 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1420
1421 HeapFree(GetProcessHeap(), 0, bits2);
1422 HeapFree(GetProcessHeap(), 0, bits);
1423 DeleteDC(dc);
1424
1425 SelectObject(ddb_dc, old_bmp);
1426 DeleteDC(ddb_dc);
1427 DeleteObject(ddb);
1428
1429 HeapFree(GetProcessHeap(), 0, info2);
1430 HeapFree(GetProcessHeap(), 0, info);
1431 }
1432
1433 static void test_GetDIBits(void)
1434 {
1435 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1436 static const BYTE bmp_bits_1[16 * 2] =
1437 {
1438 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1439 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1440 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1441 0xff,0xff, 0,0, 0xff,0xff, 0,0
1442 };
1443 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1444 static const BYTE dib_bits_1[16 * 4] =
1445 {
1446 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1447 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1448 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1449 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1450 };
1451 static const BYTE dib_bits_1_9x[16 * 4] =
1452 {
1453 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1454 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1455 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1456 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1457 };
1458 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1459 static const BYTE bmp_bits_24[16 * 16*3] =
1460 {
1461 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1462 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1463 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1464 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1465 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1466 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1467 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1468 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1469 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1470 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1471 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1472 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1473 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1474 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1475 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1476 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1477 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1478 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1479 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1480 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1481 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1482 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1483 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1484 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1485 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1486 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1487 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1488 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1489 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1490 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1491 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1492 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1493 };
1494 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1495 static const BYTE dib_bits_24[16 * 16*3] =
1496 {
1497 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1498 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1499 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1500 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1501 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1502 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1503 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1504 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1505 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1506 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1507 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1508 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1509 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1510 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1511 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1512 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1513 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1514 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1515 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1516 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1517 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1518 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1519 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1520 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1522 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1523 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1524 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1525 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1526 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1527 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1528 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1529 };
1530 HBITMAP hbmp;
1531 BITMAP bm;
1532 HDC hdc;
1533 int i, bytes, lines;
1534 BYTE buf[1024];
1535 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1536 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1537
1538 hdc = GetDC(0);
1539
1540 /* 1-bit source bitmap data */
1541 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1542 ok(hbmp != 0, "CreateBitmap failed\n");
1543
1544 memset(&bm, 0xAA, sizeof(bm));
1545 bytes = GetObject(hbmp, sizeof(bm), &bm);
1546 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1547 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1548 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1549 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1550 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1551 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1552 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1553 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1554
1555 bytes = GetBitmapBits(hbmp, 0, NULL);
1556 ok(bytes == sizeof(bmp_bits_1) || broken(bytes == 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes);
1557 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1558 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1559 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1560
1561 /* retrieve 1-bit DIB data */
1562 memset(bi, 0, sizeof(*bi));
1563 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1564 bi->bmiHeader.biWidth = bm.bmWidth;
1565 bi->bmiHeader.biHeight = bm.bmHeight;
1566 bi->bmiHeader.biPlanes = 1;
1567 bi->bmiHeader.biBitCount = 1;
1568 bi->bmiHeader.biCompression = BI_RGB;
1569 bi->bmiHeader.biSizeImage = 0;
1570 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1571 SetLastError(0xdeadbeef);
1572 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1573 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1574 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1575 broken(GetLastError() == 0xdeadbeef), /* winnt */
1576 "wrong error %u\n", GetLastError());
1577 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1578
1579 memset(buf, 0xAA, sizeof(buf));
1580 SetLastError(0xdeadbeef);
1581 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1582 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1583 lines, bm.bmHeight, GetLastError());
1584 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1585 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1586 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1587
1588 /* the color table consists of black and white */
1589 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1590 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1591 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1592 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1593 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1594 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1595 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1596 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1597 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1598 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1599 for (i = 2; i < 256; i++)
1600 {
1601 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1602 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1603 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1604 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1605 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1606 }
1607
1608 /* returned bits are DWORD aligned and upside down */
1609 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1610 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1611 "DIB bits don't match\n");
1612
1613 /* Test the palette indices */
1614 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1615 SetLastError(0xdeadbeef);
1616 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1617 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1618 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1619 else
1620 {
1621 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1622 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1623 }
1624 for (i = 2; i < 256; i++)
1625 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1626
1627 /* retrieve 24-bit DIB data */
1628 memset(bi, 0, sizeof(*bi));
1629 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1630 bi->bmiHeader.biWidth = bm.bmWidth;
1631 bi->bmiHeader.biHeight = bm.bmHeight;
1632 bi->bmiHeader.biPlanes = 1;
1633 bi->bmiHeader.biBitCount = 24;
1634 bi->bmiHeader.biCompression = BI_RGB;
1635 bi->bmiHeader.biSizeImage = 0;
1636 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1637 memset(buf, 0xAA, sizeof(buf));
1638 SetLastError(0xdeadbeef);
1639 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1640 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1641 lines, bm.bmHeight, GetLastError());
1642 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1643 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1644 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1645
1646 /* the color table doesn't exist for 24-bit images */
1647 for (i = 0; i < 256; i++)
1648 {
1649 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1650 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1651 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1652 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1653 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1654 }
1655
1656 /* returned bits are DWORD aligned and upside down */
1657 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1658 DeleteObject(hbmp);
1659
1660 /* 24-bit source bitmap data */
1661 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1662 ok(hbmp != 0, "CreateBitmap failed\n");
1663 SetLastError(0xdeadbeef);
1664 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1665 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1666 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1667 lines, bm.bmHeight, GetLastError());
1668
1669 memset(&bm, 0xAA, sizeof(bm));
1670 bytes = GetObject(hbmp, sizeof(bm), &bm);
1671 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1672 ok(bm.bmType == 0 ||
1673 broken(bm.bmType == 21072), /* win9x */
1674 "wrong bmType %d\n", bm.bmType);
1675 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1676 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1677 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1678 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1679 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1680 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1681
1682 bytes = GetBitmapBits(hbmp, 0, NULL);
1683 ok(bytes == bm.bmWidthBytes * bm.bmHeight ||
1684 broken(bytes == 0), /* win9x */
1685 "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
1686 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1687 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1688 bm.bmWidthBytes * bm.bmHeight, bytes);
1689
1690 /* retrieve 1-bit DIB data */
1691 memset(bi, 0, sizeof(*bi));
1692 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1693 bi->bmiHeader.biWidth = bm.bmWidth;
1694 bi->bmiHeader.biHeight = bm.bmHeight;
1695 bi->bmiHeader.biPlanes = 1;
1696 bi->bmiHeader.biBitCount = 1;
1697 bi->bmiHeader.biCompression = BI_RGB;
1698 bi->bmiHeader.biSizeImage = 0;
1699 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1700 memset(buf, 0xAA, sizeof(buf));
1701 SetLastError(0xdeadbeef);
1702 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1703 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1704 lines, bm.bmHeight, GetLastError());
1705 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1706 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1707 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1708
1709 /* the color table consists of black and white */
1710 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1711 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1712 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1713 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1714 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1715 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1716 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1717 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1718 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1719 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1720 for (i = 2; i < 256; i++)
1721 {
1722 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1723 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1724 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1725 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1726 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1727 }
1728
1729 /* returned bits are DWORD aligned and upside down */
1730 todo_wine
1731 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1732 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1733 "DIB bits don't match\n");
1734
1735 /* Test the palette indices */
1736 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1737 SetLastError(0xdeadbeef);
1738 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1739 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1740 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1741 else
1742 {
1743 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1744 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1745 }
1746 for (i = 2; i < 256; i++)
1747 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1748
1749 /* retrieve 24-bit DIB data */
1750 memset(bi, 0, sizeof(*bi));
1751 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1752 bi->bmiHeader.biWidth = bm.bmWidth;
1753 bi->bmiHeader.biHeight = bm.bmHeight;
1754 bi->bmiHeader.biPlanes = 1;
1755 bi->bmiHeader.biBitCount = 24;
1756 bi->bmiHeader.biCompression = BI_RGB;
1757 bi->bmiHeader.biSizeImage = 0;
1758 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1759 memset(buf, 0xAA, sizeof(buf));
1760 SetLastError(0xdeadbeef);
1761 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1762 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1763 lines, bm.bmHeight, GetLastError());
1764 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1765 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1766 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1767
1768 /* the color table doesn't exist for 24-bit images */
1769 for (i = 0; i < 256; i++)
1770 {
1771 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1772 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1773 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1774 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1775 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1776 }
1777
1778 /* returned bits are DWORD aligned and upside down */
1779 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1780 DeleteObject(hbmp);
1781
1782 ReleaseDC(0, hdc);
1783 }
1784
1785 static void test_GetDIBits_BI_BITFIELDS(void)
1786 {
1787 /* Try a screen resolution detection technique
1788 * from the September 1999 issue of Windows Developer's Journal
1789 * which seems to be in widespread use.
1790 * http://www.lesher.ws/highcolor.html
1791 * http://www.lesher.ws/vidfmt.c
1792 * It hinges on being able to retrieve the bitmaps
1793 * for the three primary colors in non-paletted 16 bit mode.
1794 */
1795 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1796 DWORD bits[32];
1797 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1798 HDC hdc;
1799 HBITMAP hbm;
1800 int ret;
1801
1802 memset(dibinfo, 0, sizeof(dibinfo_buf));
1803 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1804
1805 hdc = GetDC(NULL);
1806 ok(hdc != NULL, "GetDC failed?\n");
1807 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1808 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1809
1810 /* Call GetDIBits to fill in bmiHeader. */
1811 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1812 ok(ret == 1, "GetDIBits failed\n");
1813 if (dibinfo->bmiHeader.biBitCount > 8)
1814 {
1815 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1816
1817 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1818 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1819
1820 ok( !bitmasks[0], "red mask is set\n" );
1821 ok( !bitmasks[1], "green mask is set\n" );
1822 ok( !bitmasks[2], "blue mask is set\n" );
1823
1824 /* test with NULL bits pointer and correct bpp */
1825 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1826 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1827 ok(ret == 1, "GetDIBits failed\n");
1828
1829 ok( bitmasks[0] != 0, "red mask is not set\n" );
1830 ok( bitmasks[1] != 0, "green mask is not set\n" );
1831 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1832 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1833
1834 /* test with valid bits pointer */
1835 memset(dibinfo, 0, sizeof(dibinfo_buf));
1836 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1837 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1838 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1839 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1840 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1841 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1842
1843 ok( bitmasks[0] != 0, "red mask is not set\n" );
1844 ok( bitmasks[1] != 0, "green mask is not set\n" );
1845 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1846 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
1847 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
1848 "size image not set\n" );
1849
1850 /* now with bits and 0 lines */
1851 memset(dibinfo, 0, sizeof(dibinfo_buf));
1852 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1853 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1854 SetLastError(0xdeadbeef);
1855 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1856 if (ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1857 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1858 else
1859 {
1860 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1861
1862 ok( !bitmasks[0], "red mask is set\n" );
1863 ok( !bitmasks[1], "green mask is set\n" );
1864 ok( !bitmasks[2], "blue mask is set\n" );
1865 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1866
1867 memset(bitmasks, 0, 3*sizeof(DWORD));
1868 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1869 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1870 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1871
1872 ok( bitmasks[0] != 0, "red mask is not set\n" );
1873 ok( bitmasks[1] != 0, "green mask is not set\n" );
1874 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1875 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1876 }
1877 }
1878 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1879
1880 DeleteObject(hbm);
1881 ReleaseDC(NULL, hdc);
1882 }
1883
1884 static void test_select_object(void)
1885 {
1886 HDC hdc;
1887 HBITMAP hbm, hbm_old;
1888 INT planes, bpp, i;
1889 DWORD depths[] = {8, 15, 16, 24, 32};
1890 BITMAP bm;
1891 DWORD bytes;
1892
1893 hdc = GetDC(0);
1894 ok(hdc != 0, "GetDC(0) failed\n");
1895 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1896 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1897
1898 hbm_old = SelectObject(hdc, hbm);
1899 ok(hbm_old == 0, "SelectObject should fail\n");
1900
1901 DeleteObject(hbm);
1902 ReleaseDC(0, hdc);
1903
1904 hdc = CreateCompatibleDC(0);
1905 ok(hdc != 0, "GetDC(0) failed\n");
1906 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1907 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1908
1909 hbm_old = SelectObject(hdc, hbm);
1910 ok(hbm_old != 0, "SelectObject failed\n");
1911 hbm_old = SelectObject(hdc, hbm_old);
1912 ok(hbm_old == hbm, "SelectObject failed\n");
1913
1914 DeleteObject(hbm);
1915
1916 /* test an 1-bpp bitmap */
1917 planes = GetDeviceCaps(hdc, PLANES);
1918 bpp = 1;
1919
1920 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
1921 ok(hbm != 0, "CreateBitmap failed\n");
1922
1923 hbm_old = SelectObject(hdc, hbm);
1924 ok(hbm_old != 0, "SelectObject failed\n");
1925 hbm_old = SelectObject(hdc, hbm_old);
1926 ok(hbm_old == hbm, "SelectObject failed\n");
1927
1928 DeleteObject(hbm);
1929
1930 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
1931 /* test a color bitmap to dc bpp matching */
1932 planes = GetDeviceCaps(hdc, PLANES);
1933 bpp = GetDeviceCaps(hdc, BITSPIXEL);
1934
1935 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
1936 ok(hbm != 0, "CreateBitmap failed\n");
1937
1938 hbm_old = SelectObject(hdc, hbm);
1939 if(depths[i] == bpp ||
1940 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
1941 ) {
1942 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
1943 SelectObject(hdc, hbm_old);
1944 } else {
1945 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
1946 }
1947
1948 memset(&bm, 0xAA, sizeof(bm));
1949 bytes = GetObject(hbm, sizeof(bm), &bm);
1950 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1951 ok(bm.bmType == 0 ||
1952 broken(bm.bmType == 21072), /* win9x */
1953 "wrong bmType %d\n", bm.bmType);
1954 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
1955 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
1956 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1957 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
1958 if(depths[i] == 15) {
1959 ok(bm.bmBitsPixel == 16 ||
1960 broken(bm.bmBitsPixel == 15), /* Win9x/WinME */
1961 "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
1962 } else {
1963 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1964 }
1965 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1966
1967 DeleteObject(hbm);
1968 }
1969
1970 DeleteDC(hdc);
1971 }
1972
1973 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
1974 {
1975 INT ret;
1976 BITMAP bm;
1977
1978 ret = GetObjectType(hbmp);
1979 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
1980
1981 ret = GetObject(hbmp, 0, 0);
1982 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
1983 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
1984
1985 memset(&bm, 0xDA, sizeof(bm));
1986 SetLastError(0xdeadbeef);
1987 ret = GetObject(hbmp, sizeof(bm), &bm);
1988 if (!ret) /* XP, only for curObj2 */ return;
1989 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
1990 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
1991 "GetObject returned %d, error %u\n", ret, GetLastError());
1992 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
1993 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
1994 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
1995 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
1996 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
1997 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
1998 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1999 }
2000
2001 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2002
2003 static void test_CreateBitmap(void)
2004 {
2005 BITMAP bmp;
2006 HDC screenDC = GetDC(0);
2007 HDC hdc = CreateCompatibleDC(screenDC);
2008 UINT i, expect = 0;
2009
2010 /* all of these are the stock monochrome bitmap */
2011 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
2012 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2013 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2014 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2015 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
2016 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2017
2018 /* these 2 are not the stock monochrome bitmap */
2019 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2020 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2021
2022 HBITMAP old1 = SelectObject(hdc, bm2);
2023 HBITMAP old2 = SelectObject(screenDC, bm3);
2024 SelectObject(hdc, old1);
2025 SelectObject(screenDC, old2);
2026
2027 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2028 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2029 bm, bm1, bm4, bm5, curObj1, old1);
2030 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2031 todo_wine
2032 ok(bm != curObj2 || /* WinXP */
2033 broken(bm == curObj2) /* Win9x */,
2034 "0: %p, curObj2 %p\n", bm, curObj2);
2035 ok(old2 == 0, "old2 %p\n", old2);
2036
2037 test_mono_1x1_bmp(bm);
2038 test_mono_1x1_bmp(bm1);
2039 test_mono_1x1_bmp(bm2);
2040 test_mono_1x1_bmp(bm3);
2041 test_mono_1x1_bmp(bm4);
2042 test_mono_1x1_bmp(bm5);
2043 test_mono_1x1_bmp(old1);
2044 test_mono_1x1_bmp(curObj1);
2045
2046 DeleteObject(bm);
2047 DeleteObject(bm1);
2048 DeleteObject(bm2);
2049 DeleteObject(bm3);
2050 DeleteObject(bm4);
2051 DeleteObject(bm5);
2052
2053 DeleteDC(hdc);
2054 ReleaseDC(0, screenDC);
2055
2056 /* show that Windows ignores the provided bm.bmWidthBytes */
2057 bmp.bmType = 0;
2058 bmp.bmWidth = 1;
2059 bmp.bmHeight = 1;
2060 bmp.bmWidthBytes = 28;
2061 bmp.bmPlanes = 1;
2062 bmp.bmBitsPixel = 1;
2063 bmp.bmBits = NULL;
2064 bm = CreateBitmapIndirect(&bmp);
2065 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2066 test_mono_1x1_bmp(bm);
2067 DeleteObject(bm);
2068
2069 /* Test how the bmBitsPixel field is treated */
2070 for(i = 1; i <= 33; i++) {
2071 bmp.bmType = 0;
2072 bmp.bmWidth = 1;
2073 bmp.bmHeight = 1;
2074 bmp.bmWidthBytes = 28;
2075 bmp.bmPlanes = 1;
2076 bmp.bmBitsPixel = i;
2077 bmp.bmBits = NULL;
2078 SetLastError(0xdeadbeef);
2079 bm = CreateBitmapIndirect(&bmp);
2080 if(i > 32) {
2081 DWORD error = GetLastError();
2082 ok(bm == 0 ||
2083 broken(bm != 0), /* Win9x and WinMe */
2084 "CreateBitmapIndirect for %d bpp succeeded\n", i);
2085 ok(error == ERROR_INVALID_PARAMETER ||
2086 broken(error == 0xdeadbeef), /* Win9x and WinME */
2087 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2088 DeleteObject(bm);
2089 continue;
2090 }
2091 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2092 GetObject(bm, sizeof(bmp), &bmp);
2093 if(i == 1) {
2094 expect = 1;
2095 } else if(i <= 4) {
2096 expect = 4;
2097 } else if(i <= 8) {
2098 expect = 8;
2099 } else if(i <= 16) {
2100 expect = 16;
2101 } else if(i <= 24) {
2102 expect = 24;
2103 } else if(i <= 32) {
2104 expect = 32;
2105 }
2106 ok(bmp.bmBitsPixel == expect ||
2107 broken(bmp.bmBitsPixel == i), /* Win9x and WinMe */
2108 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2109 i, bmp.bmBitsPixel, expect);
2110 DeleteObject(bm);
2111 }
2112 }
2113
2114 static void test_bitmapinfoheadersize(void)
2115 {
2116 HBITMAP hdib;
2117 BITMAPINFO bmi;
2118 BITMAPCOREINFO bci;
2119 HDC hdc = GetDC(0);
2120
2121 memset(&bmi, 0, sizeof(BITMAPINFO));
2122 bmi.bmiHeader.biHeight = 100;
2123 bmi.bmiHeader.biWidth = 512;
2124 bmi.bmiHeader.biBitCount = 24;
2125 bmi.bmiHeader.biPlanes = 1;
2126
2127 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2128
2129 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2130 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2131
2132 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2133
2134 SetLastError(0xdeadbeef);
2135 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2136 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2137 DeleteObject(hdib);
2138
2139 bmi.bmiHeader.biSize++;
2140
2141 SetLastError(0xdeadbeef);
2142 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2143 ok(hdib != NULL ||
2144 broken(!hdib), /* Win98, WinMe */
2145 "CreateDIBSection error %d\n", GetLastError());
2146 DeleteObject(hdib);
2147
2148 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2149
2150 SetLastError(0xdeadbeef);
2151 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2152 ok(hdib != NULL ||
2153 broken(!hdib), /* Win98, WinMe */
2154 "CreateDIBSection error %d\n", GetLastError());
2155 DeleteObject(hdib);
2156
2157 bmi.bmiHeader.biSize++;
2158
2159 SetLastError(0xdeadbeef);
2160 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2161 ok(hdib != NULL ||
2162 broken(!hdib), /* Win98, WinMe */
2163 "CreateDIBSection error %d\n", GetLastError());
2164 DeleteObject(hdib);
2165
2166 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2167
2168 SetLastError(0xdeadbeef);
2169 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2170 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2171 DeleteObject(hdib);
2172
2173 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2174
2175 SetLastError(0xdeadbeef);
2176 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2177 ok(hdib != NULL ||
2178 broken(!hdib), /* Win95 */
2179 "CreateDIBSection error %d\n", GetLastError());
2180 DeleteObject(hdib);
2181
2182 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2183 bci.bmciHeader.bcHeight = 100;
2184 bci.bmciHeader.bcWidth = 512;
2185 bci.bmciHeader.bcBitCount = 24;
2186 bci.bmciHeader.bcPlanes = 1;
2187
2188 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2189
2190 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2191 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2192
2193 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2194
2195 SetLastError(0xdeadbeef);
2196 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2197 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2198 DeleteObject(hdib);
2199
2200 bci.bmciHeader.bcSize++;
2201
2202 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2203 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2204
2205 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2206
2207 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2208 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2209
2210 ReleaseDC(0, hdc);
2211 }
2212
2213 static void test_get16dibits(void)
2214 {
2215 BYTE bits[4 * (16 / sizeof(BYTE))];
2216 HBITMAP hbmp;
2217 HDC screen_dc = GetDC(NULL);
2218 int ret;
2219 BITMAPINFO * info;
2220 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2221 BYTE *p;
2222 int overwritten_bytes = 0;
2223
2224 memset(bits, 0, sizeof(bits));
2225 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2226 ok(hbmp != NULL, "CreateBitmap failed\n");
2227
2228 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2229 assert(info);
2230
2231 memset(info, '!', info_len);
2232 memset(info, 0, sizeof(info->bmiHeader));
2233
2234 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2235 info->bmiHeader.biWidth = 2;
2236 info->bmiHeader.biHeight = 2;
2237 info->bmiHeader.biPlanes = 1;
2238 info->bmiHeader.biCompression = BI_RGB;
2239
2240 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2241 ok(ret != 0 ||
2242 broken(ret == 0), /* win9x */
2243 "GetDIBits failed got %d\n", ret);
2244
2245 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2246 if (*p != '!')
2247 overwritten_bytes++;
2248 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2249
2250 HeapFree(GetProcessHeap(), 0, info);
2251 DeleteObject(hbmp);
2252 ReleaseDC(NULL, screen_dc);
2253 }
2254
2255 static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2256 {
2257 int i;
2258 for(i = 0; i < length; i++)
2259 if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2260 return FALSE;
2261 return TRUE;
2262 }
2263
2264 static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2265 DWORD dwRop, UINT32 expected, int line)
2266 {
2267 *srcBuffer = 0xFEDCBA98;
2268 *dstBuffer = 0x89ABCDEF;
2269 Rectangle(hdcSrc, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2270 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
2271 ok(expected == *dstBuffer,
2272 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2273 dwRop, expected, *dstBuffer, line);
2274 }
2275
2276 static void test_BitBlt(void)
2277 {
2278 HBITMAP bmpDst, bmpSrc;
2279 HBITMAP oldDst, oldSrc;
2280 HDC hdcScreen, hdcDst, hdcSrc;
2281 UINT32 *dstBuffer, *srcBuffer;
2282 HBRUSH hBrush, hOldBrush;
2283 BITMAPINFO bitmapInfo;
2284
2285 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2286 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2287 bitmapInfo.bmiHeader.biWidth = 1;
2288 bitmapInfo.bmiHeader.biHeight = 1;
2289 bitmapInfo.bmiHeader.biPlanes = 1;
2290 bitmapInfo.bmiHeader.biBitCount = 32;
2291 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2292 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2293
2294 hdcScreen = CreateCompatibleDC(0);
2295 hdcDst = CreateCompatibleDC(hdcScreen);
2296 hdcSrc = CreateCompatibleDC(hdcDst);
2297
2298 /* Setup the destination dib section */
2299 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
2300 NULL, 0);
2301 oldDst = SelectObject(hdcDst, bmpDst);
2302
2303 hBrush = CreateSolidBrush(0x012345678);
2304 hOldBrush = SelectObject(hdcDst, hBrush);
2305
2306 /* Setup the source dib section */
2307 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
2308 NULL, 0);
2309 oldSrc = SelectObject(hdcSrc, bmpSrc);
2310
2311 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2312 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2313 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2314 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2315 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2316 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2317 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2318 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2319 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2320 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2321 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2322 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2323 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2324 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2325 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2326
2327 /* Tidy up */
2328 SelectObject(hdcSrc, oldSrc);
2329 DeleteObject(bmpSrc);
2330 DeleteDC(hdcSrc);
2331
2332 SelectObject(hdcDst, hOldBrush);
2333 DeleteObject(hBrush);
2334 SelectObject(hdcDst, oldDst);
2335 DeleteObject(bmpDst);
2336 DeleteDC(hdcDst);
2337
2338
2339 DeleteDC(hdcScreen);
2340 }
2341
2342 static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2343 DWORD dwRop, UINT32 expected, int line)
2344 {
2345 *srcBuffer = 0xFEDCBA98;
2346 *dstBuffer = 0x89ABCDEF;
2347 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
2348 ok(expected == *dstBuffer,
2349 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2350 dwRop, expected, *dstBuffer, line);
2351 }
2352
2353 static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2354 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2355 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2356 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2357 {
2358 memset(dstBuffer, 0, 16);
2359 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2360 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2361 ok(memcmp(dstBuffer, expected, 16) == 0 ||
2362 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
2363 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2364 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2365 expected[0], expected[1], expected[2], expected[3],
2366 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2367 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2368 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2369 }
2370
2371 static void test_StretchBlt(void)
2372 {
2373 HBITMAP bmpDst, bmpSrc;
2374 HBITMAP oldDst, oldSrc;
2375 HDC hdcScreen, hdcDst, hdcSrc;
2376 UINT32 *dstBuffer, *srcBuffer;
2377 HBRUSH hBrush, hOldBrush;
2378 BITMAPINFO biDst, biSrc;
2379 UINT32 expected[4], legacy_expected[4];
2380
2381 memset(&biDst, 0, sizeof(BITMAPINFO));
2382 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2383 biDst.bmiHeader.biWidth = 2;
2384 biDst.bmiHeader.biHeight = -2;
2385 biDst.bmiHeader.biPlanes = 1;
2386 biDst.bmiHeader.biBitCount = 32;
2387 biDst.bmiHeader.biCompression = BI_RGB;
2388 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
2389
2390 hdcScreen = CreateCompatibleDC(0);
2391 hdcDst = CreateCompatibleDC(hdcScreen);
2392 hdcSrc = CreateCompatibleDC(hdcDst);
2393
2394 /* Pixel Tests */
2395 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2396 NULL, 0);
2397 oldDst = SelectObject(hdcDst, bmpDst);
2398
2399 bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
2400 NULL, 0);
2401 oldSrc = SelectObject(hdcSrc, bmpSrc);
2402
2403 hBrush = CreateSolidBrush(0x012345678);
2404 hOldBrush = SelectObject(hdcDst, hBrush);
2405
2406 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2407 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2408 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2409 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2410 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2411 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2412 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2413 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2414 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2415 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2416 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2417 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2418 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2419 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2420 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2421
2422 SelectObject(hdcDst, hOldBrush);
2423 DeleteObject(hBrush);
2424
2425 /* Top-down to top-down tests */
2426 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2427 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2428
2429 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2430 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2431 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2432 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2433
2434 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2435 expected[2] = 0x00000000, expected[3] = 0x00000000;
2436 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2437 0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
2438
2439 expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2440 expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2441 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2442 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2443
2444 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2445 expected[2] = 0x00000000, expected[3] = 0x00000000;
2446 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2447 0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2448
2449 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2450 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2451 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2452 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2453
2454 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2455 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2456 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2457 1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2458
2459 /* This result seems broken. One might expect the following result:
2460 * 0xCAFED00D 0xFEEDFACE
2461 * 0xFEDCBA98 0x76543210
2462 */
2463 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2464 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2465 legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2466 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2467 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2468 1, 1, -2, -2, 1, 1, -2, -2, expected,
2469 legacy_expected, __LINE__);
2470
2471 expected[0] = 0x00000000, expected[1] = 0x00000000;
2472 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2473 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2474 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2475
2476 SelectObject(hdcDst, oldDst);
2477 DeleteObject(bmpDst);
2478
2479 /* Top-down to bottom-up tests */
2480 biDst.bmiHeader.biHeight = 2;
2481 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2482 NULL, 0);
2483 oldDst = SelectObject(hdcDst, bmpDst);
2484
2485 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2486 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2487 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2488 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2489
2490 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2491 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2492 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2493 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2494
2495 SelectObject(hdcSrc, oldSrc);
2496 DeleteObject(bmpSrc);
2497
2498 /* Bottom-up to bottom-up tests */
2499 biSrc.bmiHeader.biHeight = 2;
2500 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2501 NULL, 0);
2502 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2503 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2504 oldSrc = SelectObject(hdcSrc, bmpSrc);
2505
2506 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2507 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2508 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2509 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2510
2511 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2512 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2513 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2514 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2515
2516 SelectObject(hdcDst, oldDst);
2517 DeleteObject(bmpDst);
2518
2519 /* Bottom-up to top-down tests */
2520 biDst.bmiHeader.biHeight = -2;
2521 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2522 NULL, 0);
2523 oldDst = SelectObject(hdcDst, bmpDst);
2524
2525 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2526 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2527 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2528 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2529
2530 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2531 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2532 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2533 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2534
2535 /* Tidy up */
2536 SelectObject(hdcSrc, oldSrc);
2537 DeleteObject(bmpSrc);
2538 DeleteDC(hdcSrc);
2539
2540 SelectObject(hdcDst, oldDst);
2541 DeleteObject(bmpDst);
2542 DeleteDC(hdcDst);
2543
2544 DeleteDC(hdcScreen);
2545 }
2546
2547 static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2548 DWORD dwRop, UINT32 expected, int line)
2549 {
2550 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
2551 BITMAPINFO bitmapInfo;
2552
2553 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2554 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2555 bitmapInfo.bmiHeader.biWidth = 2;
2556 bitmapInfo.bmiHeader.biHeight = 1;
2557 bitmapInfo.bmiHeader.biPlanes = 1;
2558 bitmapInfo.bmiHeader.biBitCount = 32;
2559 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2560 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
2561
2562 *dstBuffer = 0x89ABCDEF;
2563
2564 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
2565 ok(expected == *dstBuffer,
2566 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2567 dwRop, expected, *dstBuffer, line);
2568 }
2569
2570 static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2571 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2572 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2573 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2574 {
2575 BITMAPINFO bitmapInfo;
2576
2577 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2578 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2579 bitmapInfo.bmiHeader.biWidth = 2;
2580 bitmapInfo.bmiHeader.biHeight = -2;
2581 bitmapInfo.bmiHeader.biPlanes = 1;
2582 bitmapInfo.bmiHeader.biBitCount = 32;
2583 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2584
2585 memset(dstBuffer, 0, 16);
2586 StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2587 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2588 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
2589 ok(memcmp(dstBuffer, expected, 16) == 0 || /* Win2k/XP */
2590 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)) || /* Win9X/ME */
2591 broken(nWidthSrc < 0 || nHeightSrc < 0), /* Win9X/ME */
2592 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2593 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2594 expected[0], expected[1], expected[2], expected[3],
2595 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2596 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2597 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2598 }
2599
2600 static void test_StretchDIBits(void)
2601 {
2602 HBITMAP bmpDst;
2603 HBITMAP oldDst;
2604 HDC hdcScreen, hdcDst;
2605 UINT32 *dstBuffer, srcBuffer[4];
2606 HBRUSH hBrush, hOldBrush;
2607 BITMAPINFO biDst;
2608 UINT32 expected[4], legacy_expected[4];
2609
2610 memset(&biDst, 0, sizeof(BITMAPINFO));
2611 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2612 biDst.bmiHeader.biWidth = 2;
2613 biDst.bmiHeader.biHeight = -2;
2614 biDst.bmiHeader.biPlanes = 1;
2615 biDst.bmiHeader.biBitCount = 32;
2616 biDst.bmiHeader.biCompression = BI_RGB;
2617
2618 hdcScreen = CreateCompatibleDC(0);
2619 hdcDst = CreateCompatibleDC(hdcScreen);
2620
2621 /* Pixel Tests */
2622 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2623 NULL, 0);
2624 oldDst = SelectObject(hdcDst, bmpDst);
2625
2626 hBrush = CreateSolidBrush(0x012345678);
2627 hOldBrush = SelectObject(hdcDst, hBrush);
2628
2629 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2630 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2631 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2632 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2633 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2634 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2635 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2636 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2637 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2638 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2639 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2640 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2641 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2642 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2643 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2644
2645 SelectObject(hdcDst, hOldBrush);
2646 DeleteObject(hBrush);
2647
2648 /* Top-down destination tests */
2649 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2650 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2651
2652 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2653 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2654 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2655 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2656
2657 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2658 expected[2] = 0x00000000, expected[3] = 0x00000000;
2659 legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
2660 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2661 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2662 0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
2663
2664 expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
2665 expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
2666 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2667 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2668
2669 expected[0] = 0x42441000, expected[1] = 0x00000000;
2670 expected[2] = 0x00000000, expected[3] = 0x00000000;
2671 legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
2672 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2673 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2674 0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
2675
2676 expected[0] = 0x00000000, expected[1] = 0x00000000;
2677 expected[2] = 0x00000000, expected[3] = 0x00000000;
2678 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2679 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2680
2681 expected[0] = 0x00000000, expected[1] = 0x00000000;
2682 expected[2] = 0x00000000, expected[3] = 0x00000000;
2683 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2684 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2685
2686 expected[0] = 0x00000000, expected[1] = 0x00000000;
2687 expected[2] = 0x00000000, expected[3] = 0x00000000;
2688 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2689 1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
2690
2691 expected[0] = 0x00000000, expected[1] = 0x00000000;
2692 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2693 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2694 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2695
2696 SelectObject(hdcDst, oldDst);
2697 DeleteObject(bmpDst);
2698
2699 /* Bottom up destination tests */
2700 biDst.bmiHeader.biHeight = 2;
2701 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2702 NULL, 0);
2703 oldDst = SelectObject(hdcDst, bmpDst);
2704
2705 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2706 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2707 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2708 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2709
2710 /* Tidy up */
2711 SelectObject(hdcDst, oldDst);
2712 DeleteObject(bmpDst);
2713 DeleteDC(hdcDst);
2714
2715 DeleteDC(hdcScreen);
2716 }
2717
2718 static void test_GdiAlphaBlend(void)
2719 {
2720 /* test out-of-bound parameters for GdiAlphaBlend */
2721 HDC hdcNull;
2722
2723 HDC hdcDst;
2724 HBITMAP bmpDst;
2725 HBITMAP oldDst;
2726
2727 BITMAPINFO bmi;
2728 HDC hdcSrc;
2729 HBITMAP bmpSrc;
2730 HBITMAP oldSrc;
2731 LPVOID bits;
2732
2733 BLENDFUNCTION blend;
2734
2735 if (!pGdiAlphaBlend)
2736 {
2737 win_skip("GdiAlphaBlend() is not implemented\n");
2738 return;
2739 }
2740
2741 hdcNull = GetDC(NULL);
2742 hdcDst = CreateCompatibleDC(hdcNull);
2743 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2744 hdcSrc = CreateCompatibleDC(hdcNull);
2745
2746 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2747 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2748 bmi.bmiHeader.biHeight = 20;
2749 bmi.bmiHeader.biWidth = 20;
2750 bmi.bmiHeader.biBitCount = 32;
2751 bmi.bmiHeader.biPlanes = 1;
2752 bmi.bmiHeader.biCompression = BI_RGB;
2753 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2754 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2755
2756 oldDst = SelectObject(hdcDst, bmpDst);
2757 oldSrc = SelectObject(hdcSrc, bmpSrc);
2758
2759 blend.BlendOp = AC_SRC_OVER;
2760 blend.BlendFlags = 0;
2761 blend.SourceConstantAlpha = 128;
2762 blend.AlphaFormat = 0;
2763
2764 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2765 SetLastError(0xdeadbeef);
2766 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2767 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2768 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2769 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2770 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2771 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2772
2773 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2774 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2775 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2776 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2777 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2778 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2779 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2780
2781 SetLastError(0xdeadbeef);
2782 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
2783 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2784
2785 SelectObject(hdcDst, oldDst);
2786 SelectObject(hdcSrc, oldSrc);
2787 DeleteObject(bmpSrc);
2788 DeleteObject(bmpDst);
2789 DeleteDC(hdcDst);
2790 DeleteDC(hdcSrc);
2791
2792 ReleaseDC(NULL, hdcNull);
2793
2794 }
2795
2796 static void test_clipping(void)
2797 {
2798 HBITMAP bmpDst;
2799 HBITMAP oldDst;
2800 HBITMAP bmpSrc;
2801 HBITMAP oldSrc;
2802 HRGN hRgn;
2803 LPVOID bits;
2804 BOOL result;
2805
2806 HDC hdcDst = CreateCompatibleDC( NULL );
2807 HDC hdcSrc = CreateCompatibleDC( NULL );
2808
2809 BITMAPINFO bmpinfo={{0}};
2810 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2811 bmpinfo.bmiHeader.biWidth = 100;
2812 bmpinfo.bmiHeader.biHeight = 100;
2813 bmpinfo.bmiHeader.biPlanes = 1;
2814 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2815 bmpinfo.bmiHeader.biCompression = BI_RGB;
2816
2817 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2818 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2819 oldDst = SelectObject( hdcDst, bmpDst );
2820
2821 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2822 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2823 oldSrc = SelectObject( hdcSrc, bmpSrc );
2824
2825 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2826 ok(result, "BitBlt failed\n");
2827
2828 hRgn = CreateRectRgn( 0,0,0,0 );
2829 SelectClipRgn( hdcDst, hRgn );
2830
2831 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2832 ok(result, "BitBlt failed\n");
2833
2834 DeleteObject( bmpDst );
2835 DeleteObject( bmpSrc );
2836 DeleteObject( hRgn );
2837 DeleteDC( hdcDst );
2838 DeleteDC( hdcSrc );
2839 }
2840
2841 START_TEST(bitmap)
2842 {
2843 HMODULE hdll;
2844 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
2845
2846 hdll = GetModuleHandle("gdi32.dll");
2847 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
2848
2849 test_createdibitmap();
2850 test_dibsections();
2851 test_mono_dibsection();
2852 test_bitmap();
2853 test_bmBits();
2854 test_GetDIBits_selected_DIB(1);
2855 test_GetDIBits_selected_DIB(4);
2856 test_GetDIBits_selected_DIB(8);
2857 test_GetDIBits_selected_DDB(TRUE);
2858 test_GetDIBits_selected_DDB(FALSE);
2859 test_GetDIBits();
2860 test_GetDIBits_BI_BITFIELDS();
2861 test_select_object();
2862 test_CreateBitmap();
2863 test_BitBlt();
2864 test_StretchBlt();
2865 test_StretchDIBits();
2866 test_GdiAlphaBlend();
2867 test_bitmapinfoheadersize();
2868 test_get16dibits();
2869 test_clipping();
2870 }