2 * Unit test suite for bitmaps
4 * Copyright 2004 Huw Davies
5 * Copyright 2006 Dmitry Timoshkov
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.
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.
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
33 #include "wine/test.h"
35 static BOOL (WINAPI *pGdiAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
37 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
41 static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
46 return 2 * ((bmWidth+15) >> 4);
49 bmWidth *= 3; /* fall through */
51 return bmWidth + (bmWidth & 1);
61 return 2 * ((bmWidth+3) >> 2);
64 trace("Unknown depth %d, please report.\n", bpp );
70 static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
75 BYTE buf[512], buf_cmp[512];
78 ret = GetObject(hbm, sizeof(bm), &bm);
79 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
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);
90 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
91 assert(sizeof(buf) == sizeof(buf_cmp));
93 SetLastError(0xdeadbeef);
94 ret = GetBitmapBits(hbm, 0, NULL);
96 ok(ret == bm.bmWidthBytes * bm.bmHeight || (ret == 0 && gle == ERROR_INVALID_PARAMETER /* Win9x */), "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
98 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
99 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
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);
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);
112 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
113 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
115 ret = GetObject(hbm, 0, &bm);
116 ok(ret == 0, "%d != 0\n", ret);
118 ret = GetObject(hbm, 1, &bm);
119 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
121 /* Don't trust Win9x not to try to write to NULL */
124 ret = GetObject(hbm, 0, NULL);
125 ok(ret == sizeof(bm), "wrong size %d\n", ret);
129 static void test_createdibitmap(void)
132 BITMAPINFOHEADER bmih;
134 HBITMAP hbm, hbm_colour, hbm_old;
139 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
140 memset(&bmih, 0, sizeof(bmih));
141 bmih.biSize = sizeof(bmih);
145 bmih.biBitCount = 32;
146 bmih.biCompression = BI_RGB;
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");
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.
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);
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);
172 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
173 ok(hbm != NULL, "CreateDIBitmap failed\n");
174 test_bitmap_info(hbm, screen_depth, &bmih);
177 /* Now with a monochrome dc we expect a monochrome bitmap */
178 hdcmem = CreateCompatibleDC(hdc);
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);
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);
196 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
197 ok(hbm != NULL, "CreateDIBitmap failed\n");
198 test_bitmap_info(hbm, 1, &bmih);
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);
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);
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);
223 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
224 ok(hbm != NULL, "CreateDIBitmap failed\n");
225 test_bitmap_info(hbm, screen_depth, &bmih);
228 SelectObject(hdcmem, hbm_old);
229 DeleteObject(hbm_colour);
232 /* If hdc == 0 then we get a 1 bpp bitmap */
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);
241 /* Test how formats are converted */
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");
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);
267 static INT DIB_GetWidthBytes( int width, int bpp )
273 case 1: words = (width + 31) / 32; break;
274 case 4: words = (width + 7) / 8; break;
275 case 8: words = (width + 3) / 4; break;
277 case 16: words = (width + 1) / 2; break;
278 case 24: words = (width * 3 + 3)/4; break;
279 case 32: words = width; break;
283 trace("Unknown depth %d, please report.\n", bpp );
290 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
296 INT ret, bm_width_bytes, dib_width_bytes;
299 ret = GetObject(hbm, sizeof(bm), &bm);
300 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
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 == abs(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);
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);
315 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
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);
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);
328 HeapFree(GetProcessHeap(), 0, buf);
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 == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
336 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
338 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
339 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
341 ret = GetObject(hbm, 0, &bm);
342 ok(ret == 0, "%d != 0\n", ret);
344 ret = GetObject(hbm, 1, &bm);
345 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
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);
351 ret = GetObject(hbm, sizeof(*dsa) * 2, dsa);
352 ok(ret == sizeof(*dsa) || broken(ret == sizeof(*dsa) * 2 /* Win9x */), "wrong size %d\n", ret);
354 memset(&ds, 0xAA, sizeof(ds));
355 ret = GetObject(hbm, sizeof(ds), &ds);
356 ok(ret == sizeof(ds), "wrong size %d\n", ret);
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;
365 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
366 ok(ds.dsBmih.biWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
367 ok(ds.dsBmih.biHeight == abs(bmih->biHeight) ||
368 broken(ds.dsBmih.biHeight == bmih->biHeight), /* Win9x/WinMe */
369 "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
370 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
371 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
372 ok(ds.dsBmih.biCompression == bmih->biCompression, "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
373 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
374 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%d != %d\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
375 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%d != %d\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
377 memset(&ds, 0xAA, sizeof(ds));
378 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
379 ok(ret == sizeof(ds.dsBm) || broken(ret == (sizeof(ds) - 4) /* Win9x */), "wrong size %d\n", ret);
380 ok(ds.dsBm.bmWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
381 ok(ds.dsBm.bmHeight == abs(bmih->biHeight), "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
382 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
384 ret = GetObject(hbm, 0, &ds);
385 ok(ret == 0, "%d != 0\n", ret);
387 ret = GetObject(hbm, 1, &ds);
388 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
391 #define test_color_todo(got, exp, txt, todo) \
392 if (!todo && got != exp && screen_depth < 24) { \
393 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
394 screen_depth, (UINT)got, (UINT)exp); \
396 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
397 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
399 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
402 c = SetPixel(hdc, 0, 0, color); \
403 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
404 c = GetPixel(hdc, 0, 0); \
405 test_color_todo(c, exp, GetPixel, todo_getp); \
408 static void test_dib_bits_access( HBITMAP hdib, void *bits )
410 MEMORY_BASIC_INFORMATION info;
411 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
413 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
415 char filename[MAX_PATH];
420 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
421 "VirtualQuery failed\n");
422 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
423 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
424 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
425 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
426 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
427 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
429 memset( pbmi, 0, sizeof(bmibuf) );
430 memset( data, 0xcc, sizeof(data) );
431 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
432 pbmi->bmiHeader.biHeight = 16;
433 pbmi->bmiHeader.biWidth = 16;
434 pbmi->bmiHeader.biBitCount = 32;
435 pbmi->bmiHeader.biPlanes = 1;
436 pbmi->bmiHeader.biCompression = BI_RGB;
440 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
442 broken(ret == 0), /* win9x */
443 "SetDIBits failed: expected 16 got %d\n", ret);
447 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
448 "VirtualQuery failed\n");
449 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
450 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
451 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
452 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
453 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
454 /* it has been protected now */
455 todo_wine ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
457 /* try writing protected bits to a file */
459 GetTempFileNameA( ".", "dib", 0, filename );
460 file = CreateFileA( filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
461 CREATE_ALWAYS, 0, 0 );
462 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %u\n", filename, GetLastError() );
463 ret = WriteFile( file, bits, 8192, &written, NULL );
464 ok( ret, "WriteFile failed error %u\n", GetLastError() );
465 if (ret) ok( written == 8192, "only wrote %u bytes\n", written );
467 DeleteFileA( filename );
470 static void test_dibsections(void)
472 HDC hdc, hdcmem, hdcmem2;
473 HBITMAP hdib, oldbm, hdib2, oldbm2;
474 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
475 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
476 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
477 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
483 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
484 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
487 HPALETTE hpal, oldpal;
492 MEMORY_BASIC_INFORMATION info;
495 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
497 memset(pbmi, 0, sizeof(bmibuf));
498 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
499 pbmi->bmiHeader.biHeight = 100;
500 pbmi->bmiHeader.biWidth = 512;
501 pbmi->bmiHeader.biBitCount = 24;
502 pbmi->bmiHeader.biPlanes = 1;
503 pbmi->bmiHeader.biCompression = BI_RGB;
505 SetLastError(0xdeadbeef);
507 /* invalid pointer for BITMAPINFO
508 (*bits should be NULL on error) */
509 bits = (BYTE*)0xdeadbeef;
510 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
511 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
513 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
514 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
515 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
516 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
518 /* test the DIB memory */
519 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
520 "VirtualQuery failed\n");
521 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
522 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
523 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
524 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
525 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
526 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
527 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
529 test_dib_bits_access( hdib, bits );
531 test_dib_info(hdib, bits, &pbmi->bmiHeader);
534 /* Test a top-down DIB. */
535 pbmi->bmiHeader.biHeight = -100;
536 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
537 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
538 test_dib_info(hdib, bits, &pbmi->bmiHeader);
541 pbmi->bmiHeader.biHeight = 100;
542 pbmi->bmiHeader.biBitCount = 8;
543 pbmi->bmiHeader.biCompression = BI_RLE8;
544 SetLastError(0xdeadbeef);
545 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
546 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
547 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
549 for (i = 0; i < 128; i++)
551 pbmi->bmiHeader.biBitCount = i;
552 pbmi->bmiHeader.biCompression = BI_RGB;
553 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
554 if (i == 1 || i == 4 || i == 8 || i == 16 || i == 24 || i == 32)
555 ok(hdib != NULL, "CreateDIBSection bpp %u\n", i);
557 ok(hdib == NULL, "CreateDIBSection bpp %u succeeded\n", i);
558 if (hdib) DeleteObject( hdib );
561 pbmi->bmiHeader.biBitCount = 16;
562 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
563 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
564 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
565 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
566 SetLastError(0xdeadbeef);
567 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
568 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
570 /* test the DIB memory */
571 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
572 "VirtualQuery failed\n");
573 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
574 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
575 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
576 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
577 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
578 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
579 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
581 test_dib_info(hdib, bits, &pbmi->bmiHeader);
584 memset(pbmi, 0, sizeof(bmibuf));
585 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
586 pbmi->bmiHeader.biHeight = 16;
587 pbmi->bmiHeader.biWidth = 16;
588 pbmi->bmiHeader.biBitCount = 1;
589 pbmi->bmiHeader.biPlanes = 1;
590 pbmi->bmiHeader.biCompression = BI_RGB;
591 pbmi->bmiColors[0].rgbRed = 0xff;
592 pbmi->bmiColors[0].rgbGreen = 0;
593 pbmi->bmiColors[0].rgbBlue = 0;
594 pbmi->bmiColors[1].rgbRed = 0;
595 pbmi->bmiColors[1].rgbGreen = 0;
596 pbmi->bmiColors[1].rgbBlue = 0xff;
598 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
599 ok(hdib != NULL, "CreateDIBSection failed\n");
600 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
601 ok(dibsec.dsBmih.biClrUsed == 2,
602 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
604 /* Test if the old BITMAPCOREINFO structure is supported */
606 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
607 pbci->bmciHeader.bcBitCount = 0;
610 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
611 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
612 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
613 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
614 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
616 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
617 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
618 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
619 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
620 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
621 "The color table has not been translated to the old BITMAPCOREINFO format\n");
623 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
624 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
626 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
627 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
628 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
629 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
630 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
631 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
632 "The color table has not been translated to the old BITMAPCOREINFO format\n");
634 DeleteObject(hcoredib);
637 hdcmem = CreateCompatibleDC(hdc);
638 oldbm = SelectObject(hdcmem, hdib);
640 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
641 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
642 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
643 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
644 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
645 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
647 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
648 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
650 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
651 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
652 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
653 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
654 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
655 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
656 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
657 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
658 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
659 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
660 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
661 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
662 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
664 SelectObject(hdcmem, oldbm);
667 pbmi->bmiColors[0].rgbRed = 0xff;
668 pbmi->bmiColors[0].rgbGreen = 0xff;
669 pbmi->bmiColors[0].rgbBlue = 0xff;
670 pbmi->bmiColors[1].rgbRed = 0;
671 pbmi->bmiColors[1].rgbGreen = 0;
672 pbmi->bmiColors[1].rgbBlue = 0;
674 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
675 ok(hdib != NULL, "CreateDIBSection failed\n");
677 test_dib_info(hdib, bits, &pbmi->bmiHeader);
679 oldbm = SelectObject(hdcmem, hdib);
681 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
682 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
683 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
684 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
685 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
686 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
688 SelectObject(hdcmem, oldbm);
689 test_dib_info(hdib, bits, &pbmi->bmiHeader);
692 pbmi->bmiHeader.biBitCount = 4;
693 for (i = 0; i < 16; i++) {
694 pbmi->bmiColors[i].rgbRed = i;
695 pbmi->bmiColors[i].rgbGreen = 16-i;
696 pbmi->bmiColors[i].rgbBlue = 0;
698 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
699 ok(hdib != NULL, "CreateDIBSection failed\n");
700 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
701 ok(dibsec.dsBmih.biClrUsed == 16,
702 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
703 test_dib_info(hdib, bits, &pbmi->bmiHeader);
706 pbmi->bmiHeader.biBitCount = 8;
708 for (i = 0; i < 128; i++) {
709 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
710 pbmi->bmiColors[i].rgbGreen = i * 2;
711 pbmi->bmiColors[i].rgbBlue = 0;
712 pbmi->bmiColors[255 - i].rgbRed = 0;
713 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
714 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
716 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
717 ok(hdib != NULL, "CreateDIBSection failed\n");
718 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
719 ok(dibsec.dsBmih.biClrUsed == 256,
720 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
722 oldbm = SelectObject(hdcmem, hdib);
724 for (i = 0; i < 256; i++) {
725 test_color(hdcmem, DIBINDEX(i),
726 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
727 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
728 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
731 SelectObject(hdcmem, oldbm);
732 test_dib_info(hdib, bits, &pbmi->bmiHeader);
735 pbmi->bmiHeader.biBitCount = 1;
737 /* Now create a palette and a palette indexed dib section */
738 memset(plogpal, 0, sizeof(logpalbuf));
739 plogpal->palVersion = 0x300;
740 plogpal->palNumEntries = 2;
741 plogpal->palPalEntry[0].peRed = 0xff;
742 plogpal->palPalEntry[0].peBlue = 0xff;
743 plogpal->palPalEntry[1].peGreen = 0xff;
745 index = (WORD*)pbmi->bmiColors;
748 hpal = CreatePalette(plogpal);
749 ok(hpal != NULL, "CreatePalette failed\n");
750 oldpal = SelectPalette(hdc, hpal, TRUE);
751 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
752 ok(hdib != NULL, "CreateDIBSection failed\n");
753 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
754 ok(dibsec.dsBmih.biClrUsed == 2 ||
755 broken(dibsec.dsBmih.biClrUsed == 0), /* win9x */
756 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
758 /* The colour table has already been grabbed from the dc, so we select back the
761 SelectPalette(hdc, oldpal, TRUE);
762 oldbm = SelectObject(hdcmem, hdib);
763 oldpal = SelectPalette(hdcmem, hpal, TRUE);
765 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
766 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
767 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
768 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
769 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
770 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
771 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
773 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
774 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
776 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
777 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
778 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
779 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
780 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
781 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
782 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
783 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
784 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
785 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
786 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
787 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
788 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
789 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
790 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
791 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
793 /* Bottom and 2nd row from top green, everything else magenta */
794 bits[0] = bits[1] = 0xff;
795 bits[13 * 4] = bits[13*4 + 1] = 0xff;
797 test_dib_info(hdib, bits, &pbmi->bmiHeader);
799 pbmi->bmiHeader.biBitCount = 32;
801 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
802 ok(hdib2 != NULL, "CreateDIBSection failed\n");
803 hdcmem2 = CreateCompatibleDC(hdc);
804 oldbm2 = SelectObject(hdcmem2, hdib2);
806 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
808 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
809 ok(bits32[17] == 0xff00ff ||
810 broken(bits32[17] == 0x00ff00), /* Intermittent on Win9x/ME */
811 "bottom but one, left pixel is %08x\n", bits32[17]);
813 SelectObject(hdcmem2, oldbm2);
814 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
817 SelectObject(hdcmem, oldbm);
818 SelectObject(hdcmem, oldpal);
823 pbmi->bmiHeader.biBitCount = 8;
825 memset(plogpal, 0, sizeof(logpalbuf));
826 plogpal->palVersion = 0x300;
827 plogpal->palNumEntries = 256;
829 for (i = 0; i < 128; i++) {
830 plogpal->palPalEntry[i].peRed = 255 - i * 2;
831 plogpal->palPalEntry[i].peBlue = i * 2;
832 plogpal->palPalEntry[i].peGreen = 0;
833 plogpal->palPalEntry[255 - i].peRed = 0;
834 plogpal->palPalEntry[255 - i].peGreen = i * 2;
835 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
838 index = (WORD*)pbmi->bmiColors;
839 for (i = 0; i < 256; i++) {
843 hpal = CreatePalette(plogpal);
844 ok(hpal != NULL, "CreatePalette failed\n");
845 oldpal = SelectPalette(hdc, hpal, TRUE);
846 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
847 ok(hdib != NULL, "CreateDIBSection failed\n");
848 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
849 ok(dibsec.dsBmih.biClrUsed == 256 ||
850 broken(dibsec.dsBmih.biClrUsed == 0), /* win9x */
851 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
853 test_dib_info(hdib, bits, &pbmi->bmiHeader);
855 SelectPalette(hdc, oldpal, TRUE);
856 oldbm = SelectObject(hdcmem, hdib);
857 oldpal = SelectPalette(hdcmem, hpal, TRUE);
859 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
860 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
861 for (i = 0; i < 256; i++) {
862 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
863 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
864 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
865 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
866 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
869 for (i = 0; i < 256; i++) {
870 test_color(hdcmem, DIBINDEX(i),
871 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
872 test_color(hdcmem, PALETTEINDEX(i),
873 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
874 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
875 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
878 SelectPalette(hdcmem, oldpal, TRUE);
879 SelectObject(hdcmem, oldbm);
888 static void test_mono_dibsection(void)
891 HBITMAP old_bm, mono_ds;
892 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
893 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
900 memdc = CreateCompatibleDC(hdc);
902 memset(pbmi, 0, sizeof(bmibuf));
903 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
904 pbmi->bmiHeader.biHeight = 10;
905 pbmi->bmiHeader.biWidth = 10;
906 pbmi->bmiHeader.biBitCount = 1;
907 pbmi->bmiHeader.biPlanes = 1;
908 pbmi->bmiHeader.biCompression = BI_RGB;
909 pbmi->bmiColors[0].rgbRed = 0xff;
910 pbmi->bmiColors[0].rgbGreen = 0xff;
911 pbmi->bmiColors[0].rgbBlue = 0xff;
912 pbmi->bmiColors[1].rgbRed = 0x0;
913 pbmi->bmiColors[1].rgbGreen = 0x0;
914 pbmi->bmiColors[1].rgbBlue = 0x0;
917 * First dib section is 'inverted' ie color[0] is white, color[1] is black
920 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
921 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
922 old_bm = SelectObject(memdc, mono_ds);
924 /* black border, white interior */
925 Rectangle(memdc, 0, 0, 10, 10);
926 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
927 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
929 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
931 memset(bits, 0, sizeof(bits));
934 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
935 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
937 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
939 pbmi->bmiColors[0].rgbRed = 0x0;
940 pbmi->bmiColors[0].rgbGreen = 0x0;
941 pbmi->bmiColors[0].rgbBlue = 0x0;
942 pbmi->bmiColors[1].rgbRed = 0xff;
943 pbmi->bmiColors[1].rgbGreen = 0xff;
944 pbmi->bmiColors[1].rgbBlue = 0xff;
946 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
947 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
949 SelectObject(memdc, old_bm);
950 DeleteObject(mono_ds);
953 * Next dib section is 'normal' ie color[0] is black, color[1] is white
956 pbmi->bmiColors[0].rgbRed = 0x0;
957 pbmi->bmiColors[0].rgbGreen = 0x0;
958 pbmi->bmiColors[0].rgbBlue = 0x0;
959 pbmi->bmiColors[1].rgbRed = 0xff;
960 pbmi->bmiColors[1].rgbGreen = 0xff;
961 pbmi->bmiColors[1].rgbBlue = 0xff;
963 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
964 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
965 old_bm = SelectObject(memdc, mono_ds);
967 /* black border, white interior */
968 Rectangle(memdc, 0, 0, 10, 10);
969 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
970 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
972 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
974 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
975 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
977 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
979 pbmi->bmiColors[0].rgbRed = 0xff;
980 pbmi->bmiColors[0].rgbGreen = 0xff;
981 pbmi->bmiColors[0].rgbBlue = 0xff;
982 pbmi->bmiColors[1].rgbRed = 0x0;
983 pbmi->bmiColors[1].rgbGreen = 0x0;
984 pbmi->bmiColors[1].rgbBlue = 0x0;
986 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
987 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
990 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
993 pbmi->bmiColors[0].rgbRed = 0xff;
994 pbmi->bmiColors[0].rgbGreen = 0xff;
995 pbmi->bmiColors[0].rgbBlue = 0xff;
996 pbmi->bmiColors[1].rgbRed = 0x0;
997 pbmi->bmiColors[1].rgbGreen = 0x0;
998 pbmi->bmiColors[1].rgbBlue = 0x0;
999 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
1000 ok(num == 2, "num = %d\n", num);
1002 /* black border, white interior */
1003 Rectangle(memdc, 0, 0, 10, 10);
1005 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1006 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1008 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
1010 memset(bits, 0, sizeof(bits));
1013 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1014 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1016 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1018 pbmi->bmiColors[0].rgbRed = 0x0;
1019 pbmi->bmiColors[0].rgbGreen = 0x0;
1020 pbmi->bmiColors[0].rgbBlue = 0x0;
1021 pbmi->bmiColors[1].rgbRed = 0xff;
1022 pbmi->bmiColors[1].rgbGreen = 0xff;
1023 pbmi->bmiColors[1].rgbBlue = 0xff;
1025 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1026 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1028 SelectObject(memdc, old_bm);
1029 DeleteObject(mono_ds);
1032 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1035 pbmi->bmiColors[0].rgbRed = 0xff;
1036 pbmi->bmiColors[0].rgbGreen = 0x0;
1037 pbmi->bmiColors[0].rgbBlue = 0x0;
1038 pbmi->bmiColors[1].rgbRed = 0xfe;
1039 pbmi->bmiColors[1].rgbGreen = 0x0;
1040 pbmi->bmiColors[1].rgbBlue = 0x0;
1042 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1043 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1044 old_bm = SelectObject(memdc, mono_ds);
1046 /* black border, white interior */
1047 Rectangle(memdc, 0, 0, 10, 10);
1048 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1049 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1051 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1053 pbmi->bmiColors[0].rgbRed = 0x0;
1054 pbmi->bmiColors[0].rgbGreen = 0x0;
1055 pbmi->bmiColors[0].rgbBlue = 0x0;
1056 pbmi->bmiColors[1].rgbRed = 0xff;
1057 pbmi->bmiColors[1].rgbGreen = 0xff;
1058 pbmi->bmiColors[1].rgbBlue = 0xff;
1060 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1061 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1063 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1065 pbmi->bmiColors[0].rgbRed = 0xff;
1066 pbmi->bmiColors[0].rgbGreen = 0xff;
1067 pbmi->bmiColors[0].rgbBlue = 0xff;
1068 pbmi->bmiColors[1].rgbRed = 0x0;
1069 pbmi->bmiColors[1].rgbGreen = 0x0;
1070 pbmi->bmiColors[1].rgbBlue = 0x0;
1072 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1073 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1075 SelectObject(memdc, old_bm);
1076 DeleteObject(mono_ds);
1082 static void test_bitmap(void)
1084 char buf[256], buf_cmp[256];
1085 HBITMAP hbmp, hbmp_old;
1091 hdc = CreateCompatibleDC(0);
1094 SetLastError(0xdeadbeef);
1095 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1098 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1099 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1100 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1105 SetLastError(0xdeadbeef);
1106 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1109 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1110 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1111 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1116 SetLastError(0xdeadbeef);
1117 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1118 ok(!hbmp || broken(hbmp != NULL /* Win9x */), "CreateBitmap should fail\n");
1120 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1121 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1125 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1126 assert(hbmp != NULL);
1128 ret = GetObject(hbmp, sizeof(bm), &bm);
1129 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1131 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1132 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1133 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1134 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1135 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1136 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1137 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1139 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1140 assert(sizeof(buf) == sizeof(buf_cmp));
1142 ret = GetBitmapBits(hbmp, 0, NULL);
1143 ok(ret == bm.bmWidthBytes * bm.bmHeight || broken(ret == 0 /* Win9x */),
1144 "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1146 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1147 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1149 memset(buf, 0xAA, sizeof(buf));
1150 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1151 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1152 ok(!memcmp(buf, buf_cmp, sizeof(buf)) ||
1153 broken(memcmp(buf, buf_cmp, sizeof(buf))), /* win9x doesn't init the bitmap bits */
1154 "buffers do not match\n");
1156 hbmp_old = SelectObject(hdc, hbmp);
1158 ret = GetObject(hbmp, sizeof(bm), &bm);
1159 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1161 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1162 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1163 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1164 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1165 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1166 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1167 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1169 memset(buf, 0xAA, sizeof(buf));
1170 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1171 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1172 ok(!memcmp(buf, buf_cmp, sizeof(buf)) ||
1173 broken(memcmp(buf, buf_cmp, sizeof(buf))), /* win9x doesn't init the bitmap bits */
1174 "buffers do not match\n");
1176 hbmp_old = SelectObject(hdc, hbmp_old);
1177 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1179 /* test various buffer sizes for GetObject */
1180 ret = GetObject(hbmp, sizeof(*bma) * 2, bma);
1181 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
1183 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1184 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
1186 ret = GetObject(hbmp, 0, &bm);
1187 ok(ret == 0, "%d != 0\n", ret);
1189 ret = GetObject(hbmp, 1, &bm);
1190 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
1196 static void test_bmBits(void)
1202 memset(bits, 0, sizeof(bits));
1203 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1204 ok(hbmp != NULL, "CreateBitmap failed\n");
1206 memset(&bmp, 0xFF, sizeof(bmp));
1207 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1208 "GetObject failed or returned a wrong structure size\n");
1209 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1214 static void test_GetDIBits_selected_DIB(UINT bpp)
1228 /* Create a DIB section with a color table */
1230 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1231 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1235 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1237 /* Choose width and height such that the row length (in bytes)
1238 is a multiple of 4 (makes things easier) */
1239 info->bmiHeader.biWidth = 32;
1240 info->bmiHeader.biHeight = 32;
1241 info->bmiHeader.biPlanes = 1;
1242 info->bmiHeader.biBitCount = bpp;
1243 info->bmiHeader.biCompression = BI_RGB;
1245 for (i=0; i < (1u << bpp); i++)
1247 BYTE c = i * (1 << (8 - bpp));
1248 info->bmiColors[i].rgbRed = c;
1249 info->bmiColors[i].rgbGreen = c;
1250 info->bmiColors[i].rgbBlue = c;
1251 info->bmiColors[i].rgbReserved = 0;
1254 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1256 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1258 /* Set the bits of the DIB section */
1259 for (i=0; i < dib_size; i++)
1261 ((BYTE *)bits)[i] = i % 256;
1264 /* Select the DIB into a DC */
1265 dib_dc = CreateCompatibleDC(NULL);
1266 old_bmp = SelectObject(dib_dc, dib);
1267 dc = CreateCompatibleDC(NULL);
1268 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib_size);
1271 /* Copy the DIB attributes but not the color table */
1272 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1274 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1275 ok(res, "GetDIBits failed\n");
1277 /* Compare the color table and the bits */
1278 equalContents = TRUE;
1279 for (i=0; i < (1u << bpp); i++)
1281 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1282 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1283 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1284 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1286 equalContents = FALSE;
1290 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1292 equalContents = TRUE;
1293 for (i=0; i < dib_size / sizeof(DWORD); i++)
1295 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1297 equalContents = FALSE;
1301 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1303 HeapFree(GetProcessHeap(), 0, bits2);
1306 SelectObject(dib_dc, old_bmp);
1310 HeapFree(GetProcessHeap(), 0, info2);
1311 HeapFree(GetProcessHeap(), 0, info);
1314 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1329 width = height = 16;
1331 /* Create a DDB (device-dependent bitmap) */
1335 ddb = CreateBitmap(width, height, 1, 1, NULL);
1339 HDC screen_dc = GetDC(NULL);
1340 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1341 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1342 ReleaseDC(NULL, screen_dc);
1345 /* Set the pixels */
1346 ddb_dc = CreateCompatibleDC(NULL);
1347 old_bmp = SelectObject(ddb_dc, ddb);
1348 for (i = 0; i < width; i++)
1350 for (j=0; j < height; j++)
1352 BYTE c = (i * width + j) % 256;
1353 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1356 SelectObject(ddb_dc, old_bmp);
1358 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1359 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1363 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1364 info->bmiHeader.biWidth = width;
1365 info->bmiHeader.biHeight = height;
1366 info->bmiHeader.biPlanes = 1;
1367 info->bmiHeader.biBitCount = bpp;
1368 info->bmiHeader.biCompression = BI_RGB;
1370 dc = CreateCompatibleDC(NULL);
1372 /* Fill in biSizeImage */
1373 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1374 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1376 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1377 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1382 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1383 ok(res, "GetDIBits failed\n");
1385 /* Copy the DIB attributes but not the color table */
1386 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1388 /* Select the DDB into another DC */
1389 old_bmp = SelectObject(ddb_dc, ddb);
1392 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1393 ok(res, "GetDIBits failed\n");
1395 /* Compare the color table and the bits */
1398 equalContents = TRUE;
1399 for (i=0; i < (1u << bpp); i++)
1401 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1402 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1403 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1404 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1406 equalContents = FALSE;
1410 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1413 equalContents = TRUE;
1414 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1416 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1418 equalContents = FALSE;
1421 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1423 /* Test the palette */
1424 equalContents = TRUE;
1425 if (info2->bmiHeader.biBitCount <= 8)
1427 WORD *colors = (WORD*)info2->bmiColors;
1429 /* Get the palette indices */
1430 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1431 if (res == 0 && GetLastError() == ERROR_INVALID_PARAMETER) /* Win9x */
1432 res = GetDIBits(dc, ddb, 0, height, NULL, info2, DIB_PAL_COLORS);
1433 ok(res, "GetDIBits failed\n");
1435 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1439 equalContents = FALSE;
1445 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1447 HeapFree(GetProcessHeap(), 0, bits2);
1448 HeapFree(GetProcessHeap(), 0, bits);
1451 SelectObject(ddb_dc, old_bmp);
1455 HeapFree(GetProcessHeap(), 0, info2);
1456 HeapFree(GetProcessHeap(), 0, info);
1459 static void test_GetDIBits(void)
1461 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1462 static const BYTE bmp_bits_1[16 * 2] =
1464 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1465 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1466 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1467 0xff,0xff, 0,0, 0xff,0xff, 0,0
1469 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1470 static const BYTE dib_bits_1[16 * 4] =
1472 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1473 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1474 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1475 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1477 static const BYTE dib_bits_1_9x[16 * 4] =
1479 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1480 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1481 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1482 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1484 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1485 static const BYTE bmp_bits_24[16 * 16*3] =
1487 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1488 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1489 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1490 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1491 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1492 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1493 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1494 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1495 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1496 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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
1520 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1521 static const BYTE dib_bits_24[16 * 16*3] =
1523 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1524 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1525 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1526 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1527 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1528 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1529 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1530 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1531 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1532 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1533 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1534 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1535 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1536 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1537 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1538 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1539 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1540 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1541 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1542 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1543 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1544 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1545 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1546 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1547 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1548 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1549 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1550 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1551 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1552 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1553 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1554 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1559 int i, bytes, lines;
1561 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1562 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1566 /* 1-bit source bitmap data */
1567 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1568 ok(hbmp != 0, "CreateBitmap failed\n");
1570 memset(&bm, 0xAA, sizeof(bm));
1571 bytes = GetObject(hbmp, sizeof(bm), &bm);
1572 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1573 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1574 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1575 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1576 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1577 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1578 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1579 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1581 bytes = GetBitmapBits(hbmp, 0, NULL);
1582 ok(bytes == sizeof(bmp_bits_1) || broken(bytes == 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes);
1583 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1584 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1585 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1587 /* retrieve 1-bit DIB data */
1588 memset(bi, 0, sizeof(*bi));
1589 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1590 bi->bmiHeader.biWidth = bm.bmWidth;
1591 bi->bmiHeader.biHeight = bm.bmHeight;
1592 bi->bmiHeader.biPlanes = 1;
1593 bi->bmiHeader.biBitCount = 1;
1594 bi->bmiHeader.biCompression = BI_RGB;
1595 bi->bmiHeader.biSizeImage = 0;
1596 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1597 SetLastError(0xdeadbeef);
1598 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1599 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1600 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1601 broken(GetLastError() == 0xdeadbeef), /* winnt */
1602 "wrong error %u\n", GetLastError());
1603 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1605 memset(buf, 0xAA, sizeof(buf));
1606 SetLastError(0xdeadbeef);
1607 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1608 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1609 lines, bm.bmHeight, GetLastError());
1610 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1611 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1612 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1614 /* the color table consists of black and white */
1615 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1616 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1617 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1618 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1619 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1620 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1621 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1622 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1623 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1624 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1625 for (i = 2; i < 256; i++)
1627 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1628 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1629 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1630 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1631 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1634 /* returned bits are DWORD aligned and upside down */
1635 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1636 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1637 "DIB bits don't match\n");
1639 /* Test the palette indices */
1640 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1641 SetLastError(0xdeadbeef);
1642 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1643 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1644 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1647 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1648 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1650 for (i = 2; i < 256; i++)
1651 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1653 /* retrieve 24-bit DIB data */
1654 memset(bi, 0, sizeof(*bi));
1655 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1656 bi->bmiHeader.biWidth = bm.bmWidth;
1657 bi->bmiHeader.biHeight = bm.bmHeight;
1658 bi->bmiHeader.biPlanes = 1;
1659 bi->bmiHeader.biBitCount = 24;
1660 bi->bmiHeader.biCompression = BI_RGB;
1661 bi->bmiHeader.biSizeImage = 0;
1662 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1663 memset(buf, 0xAA, sizeof(buf));
1664 SetLastError(0xdeadbeef);
1665 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1666 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1667 lines, bm.bmHeight, GetLastError());
1668 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1669 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1670 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1672 /* the color table doesn't exist for 24-bit images */
1673 for (i = 0; i < 256; i++)
1675 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1676 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1677 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1678 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1679 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1682 /* returned bits are DWORD aligned and upside down */
1683 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1686 /* 24-bit source bitmap data */
1687 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1688 ok(hbmp != 0, "CreateBitmap failed\n");
1689 SetLastError(0xdeadbeef);
1690 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1691 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1692 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1693 lines, bm.bmHeight, GetLastError());
1695 memset(&bm, 0xAA, sizeof(bm));
1696 bytes = GetObject(hbmp, sizeof(bm), &bm);
1697 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1698 ok(bm.bmType == 0 ||
1699 broken(bm.bmType == 21072), /* win9x */
1700 "wrong bmType %d\n", bm.bmType);
1701 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1702 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1703 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1704 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1705 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1706 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1708 bytes = GetBitmapBits(hbmp, 0, NULL);
1709 ok(bytes == bm.bmWidthBytes * bm.bmHeight ||
1710 broken(bytes == 0), /* win9x */
1711 "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
1712 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1713 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1714 bm.bmWidthBytes * bm.bmHeight, bytes);
1716 /* retrieve 1-bit DIB data */
1717 memset(bi, 0, sizeof(*bi));
1718 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1719 bi->bmiHeader.biWidth = bm.bmWidth;
1720 bi->bmiHeader.biHeight = bm.bmHeight;
1721 bi->bmiHeader.biPlanes = 1;
1722 bi->bmiHeader.biBitCount = 1;
1723 bi->bmiHeader.biCompression = BI_RGB;
1724 bi->bmiHeader.biSizeImage = 0;
1725 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1726 memset(buf, 0xAA, sizeof(buf));
1727 SetLastError(0xdeadbeef);
1728 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1729 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1730 lines, bm.bmHeight, GetLastError());
1731 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1732 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1733 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1735 /* the color table consists of black and white */
1736 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1737 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1738 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1739 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1740 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1741 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1742 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1743 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1744 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1745 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1746 for (i = 2; i < 256; i++)
1748 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1749 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1750 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1751 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1752 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1755 /* returned bits are DWORD aligned and upside down */
1757 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1758 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1759 "DIB bits don't match\n");
1761 /* Test the palette indices */
1762 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1763 SetLastError(0xdeadbeef);
1764 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1765 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1766 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1769 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1770 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1772 for (i = 2; i < 256; i++)
1773 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1775 /* retrieve 24-bit DIB data */
1776 memset(bi, 0, sizeof(*bi));
1777 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1778 bi->bmiHeader.biWidth = bm.bmWidth;
1779 bi->bmiHeader.biHeight = bm.bmHeight;
1780 bi->bmiHeader.biPlanes = 1;
1781 bi->bmiHeader.biBitCount = 24;
1782 bi->bmiHeader.biCompression = BI_RGB;
1783 bi->bmiHeader.biSizeImage = 0;
1784 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1785 memset(buf, 0xAA, sizeof(buf));
1786 SetLastError(0xdeadbeef);
1787 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1788 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1789 lines, bm.bmHeight, GetLastError());
1790 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1791 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1792 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1794 /* the color table doesn't exist for 24-bit images */
1795 for (i = 0; i < 256; i++)
1797 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1798 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1799 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1800 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1801 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1804 /* returned bits are DWORD aligned and upside down */
1805 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1811 static void test_GetDIBits_BI_BITFIELDS(void)
1813 /* Try a screen resolution detection technique
1814 * from the September 1999 issue of Windows Developer's Journal
1815 * which seems to be in widespread use.
1816 * http://www.lesher.ws/highcolor.html
1817 * http://www.lesher.ws/vidfmt.c
1818 * It hinges on being able to retrieve the bitmaps
1819 * for the three primary colors in non-paletted 16 bit mode.
1821 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1823 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1824 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1830 memset(dibinfo, 0, sizeof(dibinfo_buf));
1831 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1834 ok(hdc != NULL, "GetDC failed?\n");
1835 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1836 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1838 /* Call GetDIBits to fill in bmiHeader. */
1839 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1840 ok(ret == 1, "GetDIBits failed\n");
1841 if (dibinfo->bmiHeader.biBitCount > 8)
1843 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1844 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1846 ok( !bitmasks[0], "red mask is set\n" );
1847 ok( !bitmasks[1], "green mask is set\n" );
1848 ok( !bitmasks[2], "blue mask is set\n" );
1850 /* test with NULL bits pointer and correct bpp */
1851 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1852 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1853 ok(ret == 1, "GetDIBits failed\n");
1855 ok( bitmasks[0] != 0, "red mask is not set\n" );
1856 ok( bitmasks[1] != 0, "green mask is not set\n" );
1857 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1858 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1860 /* test with valid bits pointer */
1861 memset(dibinfo, 0, sizeof(dibinfo_buf));
1862 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1863 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1864 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1865 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1866 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1867 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1869 ok( bitmasks[0] != 0, "red mask is not set\n" );
1870 ok( bitmasks[1] != 0, "green mask is not set\n" );
1871 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1872 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
1873 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
1874 "size image not set\n" );
1876 /* now with bits and 0 lines */
1877 memset(dibinfo, 0, sizeof(dibinfo_buf));
1878 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1879 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1880 SetLastError(0xdeadbeef);
1881 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1882 if (ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1883 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1886 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1888 ok( !bitmasks[0], "red mask is set\n" );
1889 ok( !bitmasks[1], "green mask is set\n" );
1890 ok( !bitmasks[2], "blue mask is set\n" );
1891 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1893 memset(bitmasks, 0, 3*sizeof(DWORD));
1894 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1895 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1896 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1898 ok( bitmasks[0] != 0, "red mask is not set\n" );
1899 ok( bitmasks[1] != 0, "green mask is not set\n" );
1900 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1901 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1904 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1908 /* same thing now with a 32-bpp DIB section */
1910 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1911 dibinfo->bmiHeader.biWidth = 1;
1912 dibinfo->bmiHeader.biHeight = 1;
1913 dibinfo->bmiHeader.biPlanes = 1;
1914 dibinfo->bmiHeader.biBitCount = 32;
1915 dibinfo->bmiHeader.biCompression = BI_RGB;
1916 dibinfo->bmiHeader.biSizeImage = 0;
1917 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1918 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1919 dibinfo->bmiHeader.biClrUsed = 0;
1920 dibinfo->bmiHeader.biClrImportant = 0;
1921 bitmasks[0] = 0x0000ff;
1922 bitmasks[1] = 0x00ff00;
1923 bitmasks[2] = 0xff0000;
1924 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1925 ok( hbm != 0, "failed to create bitmap\n" );
1927 memset(dibinfo, 0, sizeof(dibinfo_buf));
1928 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1929 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1930 ok(ret == 1, "GetDIBits failed\n");
1931 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1933 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1934 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1935 ok( !bitmasks[0], "red mask is set\n" );
1936 ok( !bitmasks[1], "green mask is set\n" );
1937 ok( !bitmasks[2], "blue mask is set\n" );
1939 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1940 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1941 ok(ret == 1, "GetDIBits failed\n");
1942 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1943 ok( bitmasks[0] == 0xff0000, "wrong red mask %08x\n", bitmasks[0] );
1944 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1945 ok( bitmasks[2] == 0x0000ff, "wrong blue mask %08x\n", bitmasks[2] );
1946 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
1947 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
1948 "size image not set\n" );
1952 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1953 dibinfo->bmiHeader.biWidth = 1;
1954 dibinfo->bmiHeader.biHeight = 1;
1955 dibinfo->bmiHeader.biPlanes = 1;
1956 dibinfo->bmiHeader.biBitCount = 32;
1957 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
1958 dibinfo->bmiHeader.biSizeImage = 0;
1959 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1960 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1961 dibinfo->bmiHeader.biClrUsed = 0;
1962 dibinfo->bmiHeader.biClrImportant = 0;
1963 bitmasks[0] = 0x0000ff;
1964 bitmasks[1] = 0x00ff00;
1965 bitmasks[2] = 0xff0000;
1966 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1967 ok( hbm != 0 || broken(!hbm), /* win9x */ "failed to create bitmap\n" );
1971 memset(dibinfo, 0, sizeof(dibinfo_buf));
1972 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1973 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1974 ok(ret == 1, "GetDIBits failed\n");
1976 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1977 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1978 ok( !bitmasks[0], "red mask is set\n" );
1979 ok( !bitmasks[1], "green mask is set\n" );
1980 ok( !bitmasks[2], "blue mask is set\n" );
1982 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1983 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1984 ok(ret == 1, "GetDIBits failed\n");
1985 ok( bitmasks[0] == 0x0000ff, "wrong red mask %08x\n", bitmasks[0] );
1986 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1987 ok( bitmasks[2] == 0xff0000, "wrong blue mask %08x\n", bitmasks[2] );
1988 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1993 /* 24-bpp DIB sections don't have bitfields */
1995 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1996 dibinfo->bmiHeader.biWidth = 1;
1997 dibinfo->bmiHeader.biHeight = 1;
1998 dibinfo->bmiHeader.biPlanes = 1;
1999 dibinfo->bmiHeader.biBitCount = 24;
2000 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
2001 dibinfo->bmiHeader.biSizeImage = 0;
2002 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2003 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2004 dibinfo->bmiHeader.biClrUsed = 0;
2005 dibinfo->bmiHeader.biClrImportant = 0;
2006 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2007 ok( hbm == 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
2008 dibinfo->bmiHeader.biCompression = BI_RGB;
2009 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2010 ok( hbm != 0, "failed to create bitmap\n" );
2012 memset(dibinfo, 0, sizeof(dibinfo_buf));
2013 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2014 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2015 ok(ret == 1, "GetDIBits failed\n");
2016 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2018 ok( dibinfo->bmiHeader.biCompression == BI_RGB,
2019 "compression is %u\n", dibinfo->bmiHeader.biCompression );
2020 ok( !bitmasks[0], "red mask is set\n" );
2021 ok( !bitmasks[1], "green mask is set\n" );
2022 ok( !bitmasks[2], "blue mask is set\n" );
2024 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2025 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2026 ok(ret == 1, "GetDIBits failed\n");
2027 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2028 ok( !bitmasks[0], "red mask is set\n" );
2029 ok( !bitmasks[1], "green mask is set\n" );
2030 ok( !bitmasks[2], "blue mask is set\n" );
2031 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
2032 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
2033 "size image not set\n" );
2036 ReleaseDC(NULL, hdc);
2039 static void test_select_object(void)
2042 HBITMAP hbm, hbm_old;
2044 DWORD depths[] = {8, 15, 16, 24, 32};
2049 ok(hdc != 0, "GetDC(0) failed\n");
2050 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2051 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2053 hbm_old = SelectObject(hdc, hbm);
2054 ok(hbm_old == 0, "SelectObject should fail\n");
2059 hdc = CreateCompatibleDC(0);
2060 ok(hdc != 0, "GetDC(0) failed\n");
2061 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2062 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2064 hbm_old = SelectObject(hdc, hbm);
2065 ok(hbm_old != 0, "SelectObject failed\n");
2066 hbm_old = SelectObject(hdc, hbm_old);
2067 ok(hbm_old == hbm, "SelectObject failed\n");
2071 /* test an 1-bpp bitmap */
2072 planes = GetDeviceCaps(hdc, PLANES);
2075 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
2076 ok(hbm != 0, "CreateBitmap failed\n");
2078 hbm_old = SelectObject(hdc, hbm);
2079 ok(hbm_old != 0, "SelectObject failed\n");
2080 hbm_old = SelectObject(hdc, hbm_old);
2081 ok(hbm_old == hbm, "SelectObject failed\n");
2085 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
2086 /* test a color bitmap to dc bpp matching */
2087 planes = GetDeviceCaps(hdc, PLANES);
2088 bpp = GetDeviceCaps(hdc, BITSPIXEL);
2090 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
2091 ok(hbm != 0, "CreateBitmap failed\n");
2093 hbm_old = SelectObject(hdc, hbm);
2094 if(depths[i] == bpp ||
2095 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
2097 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
2098 SelectObject(hdc, hbm_old);
2100 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
2103 memset(&bm, 0xAA, sizeof(bm));
2104 bytes = GetObject(hbm, sizeof(bm), &bm);
2105 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2106 ok(bm.bmType == 0 ||
2107 broken(bm.bmType == 21072), /* win9x */
2108 "wrong bmType %d\n", bm.bmType);
2109 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2110 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2111 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2112 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2113 if(depths[i] == 15) {
2114 ok(bm.bmBitsPixel == 16 ||
2115 broken(bm.bmBitsPixel == 15), /* Win9x/WinME */
2116 "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2118 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2120 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2128 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
2133 ret = GetObjectType(hbmp);
2134 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
2136 ret = GetObject(hbmp, 0, 0);
2137 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
2138 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
2140 memset(&bm, 0xDA, sizeof(bm));
2141 SetLastError(0xdeadbeef);
2142 ret = GetObject(hbmp, sizeof(bm), &bm);
2143 if (!ret) /* XP, only for curObj2 */ return;
2144 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
2145 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
2146 "GetObject returned %d, error %u\n", ret, GetLastError());
2147 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
2148 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
2149 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
2150 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
2151 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
2152 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
2153 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2156 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2158 static void test_CreateBitmap(void)
2161 HDC screenDC = GetDC(0);
2162 HDC hdc = CreateCompatibleDC(screenDC);
2165 /* all of these are the stock monochrome bitmap */
2166 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
2167 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2168 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2169 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2170 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
2171 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2173 /* these 2 are not the stock monochrome bitmap */
2174 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2175 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2177 HBITMAP old1 = SelectObject(hdc, bm2);
2178 HBITMAP old2 = SelectObject(screenDC, bm3);
2179 SelectObject(hdc, old1);
2180 SelectObject(screenDC, old2);
2182 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2183 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2184 bm, bm1, bm4, bm5, curObj1, old1);
2185 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2187 ok(bm != curObj2 || /* WinXP */
2188 broken(bm == curObj2) /* Win9x */,
2189 "0: %p, curObj2 %p\n", bm, curObj2);
2190 ok(old2 == 0, "old2 %p\n", old2);
2192 test_mono_1x1_bmp(bm);
2193 test_mono_1x1_bmp(bm1);
2194 test_mono_1x1_bmp(bm2);
2195 test_mono_1x1_bmp(bm3);
2196 test_mono_1x1_bmp(bm4);
2197 test_mono_1x1_bmp(bm5);
2198 test_mono_1x1_bmp(old1);
2199 test_mono_1x1_bmp(curObj1);
2209 ReleaseDC(0, screenDC);
2211 /* show that Windows ignores the provided bm.bmWidthBytes */
2215 bmp.bmWidthBytes = 28;
2217 bmp.bmBitsPixel = 1;
2219 bm = CreateBitmapIndirect(&bmp);
2220 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2221 test_mono_1x1_bmp(bm);
2224 /* Test how the bmBitsPixel field is treated */
2225 for(i = 1; i <= 33; i++) {
2229 bmp.bmWidthBytes = 28;
2231 bmp.bmBitsPixel = i;
2233 SetLastError(0xdeadbeef);
2234 bm = CreateBitmapIndirect(&bmp);
2236 DWORD error = GetLastError();
2238 broken(bm != 0), /* Win9x and WinMe */
2239 "CreateBitmapIndirect for %d bpp succeeded\n", i);
2240 ok(error == ERROR_INVALID_PARAMETER ||
2241 broken(error == 0xdeadbeef), /* Win9x and WinME */
2242 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2246 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2247 GetObject(bm, sizeof(bmp), &bmp);
2254 } else if(i <= 16) {
2256 } else if(i <= 24) {
2258 } else if(i <= 32) {
2261 ok(bmp.bmBitsPixel == expect ||
2262 broken(bmp.bmBitsPixel == i), /* Win9x and WinMe */
2263 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2264 i, bmp.bmBitsPixel, expect);
2269 static void test_bitmapinfoheadersize(void)
2276 memset(&bmi, 0, sizeof(BITMAPINFO));
2277 bmi.bmiHeader.biHeight = 100;
2278 bmi.bmiHeader.biWidth = 512;
2279 bmi.bmiHeader.biBitCount = 24;
2280 bmi.bmiHeader.biPlanes = 1;
2282 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2284 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2285 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2287 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2289 SetLastError(0xdeadbeef);
2290 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2291 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2294 bmi.bmiHeader.biSize++;
2296 SetLastError(0xdeadbeef);
2297 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2299 broken(!hdib), /* Win98, WinMe */
2300 "CreateDIBSection error %d\n", GetLastError());
2303 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2305 SetLastError(0xdeadbeef);
2306 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2308 broken(!hdib), /* Win98, WinMe */
2309 "CreateDIBSection error %d\n", GetLastError());
2312 bmi.bmiHeader.biSize++;
2314 SetLastError(0xdeadbeef);
2315 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2317 broken(!hdib), /* Win98, WinMe */
2318 "CreateDIBSection error %d\n", GetLastError());
2321 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2323 SetLastError(0xdeadbeef);
2324 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2325 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2328 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2330 SetLastError(0xdeadbeef);
2331 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2333 broken(!hdib), /* Win95 */
2334 "CreateDIBSection error %d\n", GetLastError());
2337 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2338 bci.bmciHeader.bcHeight = 100;
2339 bci.bmciHeader.bcWidth = 512;
2340 bci.bmciHeader.bcBitCount = 24;
2341 bci.bmciHeader.bcPlanes = 1;
2343 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2345 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2346 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2348 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2350 SetLastError(0xdeadbeef);
2351 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2352 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2355 bci.bmciHeader.bcSize++;
2357 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2358 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2360 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2362 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2363 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2368 static void test_get16dibits(void)
2370 BYTE bits[4 * (16 / sizeof(BYTE))];
2372 HDC screen_dc = GetDC(NULL);
2375 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2377 int overwritten_bytes = 0;
2379 memset(bits, 0, sizeof(bits));
2380 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2381 ok(hbmp != NULL, "CreateBitmap failed\n");
2383 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2386 memset(info, '!', info_len);
2387 memset(info, 0, sizeof(info->bmiHeader));
2389 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2390 info->bmiHeader.biWidth = 2;
2391 info->bmiHeader.biHeight = 2;
2392 info->bmiHeader.biPlanes = 1;
2393 info->bmiHeader.biCompression = BI_RGB;
2395 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2397 broken(ret == 0), /* win9x */
2398 "GetDIBits failed got %d\n", ret);
2400 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2402 overwritten_bytes++;
2403 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2405 HeapFree(GetProcessHeap(), 0, info);
2407 ReleaseDC(NULL, screen_dc);
2410 static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2413 for(i = 0; i < length; i++)
2414 if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2419 static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2420 DWORD dwRop, UINT32 expected, int line)
2422 *srcBuffer = 0xFEDCBA98;
2423 *dstBuffer = 0x89ABCDEF;
2424 Rectangle(hdcSrc, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2425 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
2426 ok(expected == *dstBuffer,
2427 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2428 dwRop, expected, *dstBuffer, line);
2431 static void test_BitBlt(void)
2433 HBITMAP bmpDst, bmpSrc;
2434 HBITMAP oldDst, oldSrc;
2435 HDC hdcScreen, hdcDst, hdcSrc;
2436 UINT32 *dstBuffer, *srcBuffer;
2437 HBRUSH hBrush, hOldBrush;
2438 BITMAPINFO bitmapInfo;
2440 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2441 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2442 bitmapInfo.bmiHeader.biWidth = 1;
2443 bitmapInfo.bmiHeader.biHeight = 1;
2444 bitmapInfo.bmiHeader.biPlanes = 1;
2445 bitmapInfo.bmiHeader.biBitCount = 32;
2446 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2447 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2449 hdcScreen = CreateCompatibleDC(0);
2450 hdcDst = CreateCompatibleDC(hdcScreen);
2451 hdcSrc = CreateCompatibleDC(hdcDst);
2453 /* Setup the destination dib section */
2454 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
2456 oldDst = SelectObject(hdcDst, bmpDst);
2458 hBrush = CreateSolidBrush(0x012345678);
2459 hOldBrush = SelectObject(hdcDst, hBrush);
2461 /* Setup the source dib section */
2462 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
2464 oldSrc = SelectObject(hdcSrc, bmpSrc);
2466 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2467 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2468 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2469 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2470 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2471 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2472 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2473 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2474 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2475 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2476 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2477 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2478 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2479 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2480 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2483 SelectObject(hdcSrc, oldSrc);
2484 DeleteObject(bmpSrc);
2487 SelectObject(hdcDst, hOldBrush);
2488 DeleteObject(hBrush);
2489 SelectObject(hdcDst, oldDst);
2490 DeleteObject(bmpDst);
2494 DeleteDC(hdcScreen);
2497 static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2498 DWORD dwRop, UINT32 expected, int line)
2500 *srcBuffer = 0xFEDCBA98;
2501 *dstBuffer = 0x89ABCDEF;
2502 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
2503 ok(expected == *dstBuffer,
2504 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2505 dwRop, expected, *dstBuffer, line);
2508 static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2509 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2510 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2511 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2513 memset(dstBuffer, 0, 16);
2514 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2515 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2516 ok(memcmp(dstBuffer, expected, 16) == 0 ||
2517 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
2518 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2519 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2520 expected[0], expected[1], expected[2], expected[3],
2521 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2522 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2523 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2526 static void test_StretchBlt(void)
2528 HBITMAP bmpDst, bmpSrc;
2529 HBITMAP oldDst, oldSrc;
2530 HDC hdcScreen, hdcDst, hdcSrc;
2531 UINT32 *dstBuffer, *srcBuffer;
2532 HBRUSH hBrush, hOldBrush;
2533 BITMAPINFO biDst, biSrc;
2534 UINT32 expected[4], legacy_expected[4];
2536 memset(&biDst, 0, sizeof(BITMAPINFO));
2537 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2538 biDst.bmiHeader.biWidth = 2;
2539 biDst.bmiHeader.biHeight = -2;
2540 biDst.bmiHeader.biPlanes = 1;
2541 biDst.bmiHeader.biBitCount = 32;
2542 biDst.bmiHeader.biCompression = BI_RGB;
2543 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
2545 hdcScreen = CreateCompatibleDC(0);
2546 hdcDst = CreateCompatibleDC(hdcScreen);
2547 hdcSrc = CreateCompatibleDC(hdcDst);
2550 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2552 oldDst = SelectObject(hdcDst, bmpDst);
2554 bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
2556 oldSrc = SelectObject(hdcSrc, bmpSrc);
2558 hBrush = CreateSolidBrush(0x012345678);
2559 hOldBrush = SelectObject(hdcDst, hBrush);
2561 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2562 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2563 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2564 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2565 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2566 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2567 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2568 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2569 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2570 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2571 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2572 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2573 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2574 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2575 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2577 SelectObject(hdcDst, hOldBrush);
2578 DeleteObject(hBrush);
2580 /* Top-down to top-down tests */
2581 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2582 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2584 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2585 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2586 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2587 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2589 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2590 expected[2] = 0x00000000, expected[3] = 0x00000000;
2591 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2592 0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
2594 expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2595 expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2596 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2597 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2599 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2600 expected[2] = 0x00000000, expected[3] = 0x00000000;
2601 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2602 0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2604 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2605 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2606 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2607 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2609 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2610 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2611 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2612 1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2614 /* This result seems broken. One might expect the following result:
2615 * 0xCAFED00D 0xFEEDFACE
2616 * 0xFEDCBA98 0x76543210
2618 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2619 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2620 legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2621 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2622 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2623 1, 1, -2, -2, 1, 1, -2, -2, expected,
2624 legacy_expected, __LINE__);
2626 expected[0] = 0x00000000, expected[1] = 0x00000000;
2627 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2628 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2629 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2631 SelectObject(hdcDst, oldDst);
2632 DeleteObject(bmpDst);
2634 /* Top-down to bottom-up tests */
2635 biDst.bmiHeader.biHeight = 2;
2636 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2638 oldDst = SelectObject(hdcDst, bmpDst);
2640 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2641 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2642 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2643 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2645 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2646 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2647 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2648 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2650 SelectObject(hdcSrc, oldSrc);
2651 DeleteObject(bmpSrc);
2653 /* Bottom-up to bottom-up tests */
2654 biSrc.bmiHeader.biHeight = 2;
2655 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2657 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2658 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2659 oldSrc = SelectObject(hdcSrc, bmpSrc);
2661 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2662 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2663 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2664 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2666 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2667 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2668 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2669 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2671 SelectObject(hdcDst, oldDst);
2672 DeleteObject(bmpDst);
2674 /* Bottom-up to top-down tests */
2675 biDst.bmiHeader.biHeight = -2;
2676 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2678 oldDst = SelectObject(hdcDst, bmpDst);
2680 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2681 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2682 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2683 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2685 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2686 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2687 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2688 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2691 SelectObject(hdcSrc, oldSrc);
2692 DeleteObject(bmpSrc);
2695 SelectObject(hdcDst, oldDst);
2696 DeleteObject(bmpDst);
2699 DeleteDC(hdcScreen);
2702 static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2703 DWORD dwRop, UINT32 expected, int line)
2705 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
2706 BITMAPINFO bitmapInfo;
2708 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2709 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2710 bitmapInfo.bmiHeader.biWidth = 2;
2711 bitmapInfo.bmiHeader.biHeight = 1;
2712 bitmapInfo.bmiHeader.biPlanes = 1;
2713 bitmapInfo.bmiHeader.biBitCount = 32;
2714 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2715 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
2717 *dstBuffer = 0x89ABCDEF;
2719 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
2720 ok(expected == *dstBuffer,
2721 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2722 dwRop, expected, *dstBuffer, line);
2725 static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2726 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2727 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2728 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2730 BITMAPINFO bitmapInfo;
2732 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2733 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2734 bitmapInfo.bmiHeader.biWidth = 2;
2735 bitmapInfo.bmiHeader.biHeight = -2;
2736 bitmapInfo.bmiHeader.biPlanes = 1;
2737 bitmapInfo.bmiHeader.biBitCount = 32;
2738 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2740 memset(dstBuffer, 0, 16);
2741 StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2742 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2743 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
2744 ok(memcmp(dstBuffer, expected, 16) == 0 || /* Win2k/XP */
2745 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)) || /* Win9X/ME */
2746 broken(nWidthSrc < 0 || nHeightSrc < 0), /* Win9X/ME */
2747 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2748 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2749 expected[0], expected[1], expected[2], expected[3],
2750 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2751 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2752 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2755 static void test_StretchDIBits(void)
2759 HDC hdcScreen, hdcDst;
2760 UINT32 *dstBuffer, srcBuffer[4];
2761 HBRUSH hBrush, hOldBrush;
2763 UINT32 expected[4], legacy_expected[4];
2765 memset(&biDst, 0, sizeof(BITMAPINFO));
2766 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2767 biDst.bmiHeader.biWidth = 2;
2768 biDst.bmiHeader.biHeight = -2;
2769 biDst.bmiHeader.biPlanes = 1;
2770 biDst.bmiHeader.biBitCount = 32;
2771 biDst.bmiHeader.biCompression = BI_RGB;
2773 hdcScreen = CreateCompatibleDC(0);
2774 hdcDst = CreateCompatibleDC(hdcScreen);
2777 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2779 oldDst = SelectObject(hdcDst, bmpDst);
2781 hBrush = CreateSolidBrush(0x012345678);
2782 hOldBrush = SelectObject(hdcDst, hBrush);
2784 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2785 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2786 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2787 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2788 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2789 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2790 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2791 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2792 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2793 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2794 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2795 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2796 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2797 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2798 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2800 SelectObject(hdcDst, hOldBrush);
2801 DeleteObject(hBrush);
2803 /* Top-down destination tests */
2804 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2805 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2807 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2808 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2809 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2810 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2812 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2813 expected[2] = 0x00000000, expected[3] = 0x00000000;
2814 legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
2815 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2816 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2817 0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
2819 expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
2820 expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
2821 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2822 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2824 expected[0] = 0x42441000, expected[1] = 0x00000000;
2825 expected[2] = 0x00000000, expected[3] = 0x00000000;
2826 legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
2827 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2828 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2829 0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
2831 expected[0] = 0x00000000, expected[1] = 0x00000000;
2832 expected[2] = 0x00000000, expected[3] = 0x00000000;
2833 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2834 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2836 expected[0] = 0x00000000, expected[1] = 0x00000000;
2837 expected[2] = 0x00000000, expected[3] = 0x00000000;
2838 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2839 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2841 expected[0] = 0x00000000, expected[1] = 0x00000000;
2842 expected[2] = 0x00000000, expected[3] = 0x00000000;
2843 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2844 1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
2846 expected[0] = 0x00000000, expected[1] = 0x00000000;
2847 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2848 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2849 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2851 SelectObject(hdcDst, oldDst);
2852 DeleteObject(bmpDst);
2854 /* Bottom up destination tests */
2855 biDst.bmiHeader.biHeight = 2;
2856 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2858 oldDst = SelectObject(hdcDst, bmpDst);
2860 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2861 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2862 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2863 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2866 SelectObject(hdcDst, oldDst);
2867 DeleteObject(bmpDst);
2870 DeleteDC(hdcScreen);
2873 static void test_GdiAlphaBlend(void)
2875 /* test out-of-bound parameters for GdiAlphaBlend */
2888 BLENDFUNCTION blend;
2890 if (!pGdiAlphaBlend)
2892 win_skip("GdiAlphaBlend() is not implemented\n");
2896 hdcNull = GetDC(NULL);
2897 hdcDst = CreateCompatibleDC(hdcNull);
2898 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2899 hdcSrc = CreateCompatibleDC(hdcNull);
2901 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2902 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2903 bmi.bmiHeader.biHeight = 20;
2904 bmi.bmiHeader.biWidth = 20;
2905 bmi.bmiHeader.biBitCount = 32;
2906 bmi.bmiHeader.biPlanes = 1;
2907 bmi.bmiHeader.biCompression = BI_RGB;
2908 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2909 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2911 oldDst = SelectObject(hdcDst, bmpDst);
2912 oldSrc = SelectObject(hdcSrc, bmpSrc);
2914 blend.BlendOp = AC_SRC_OVER;
2915 blend.BlendFlags = 0;
2916 blend.SourceConstantAlpha = 128;
2917 blend.AlphaFormat = 0;
2919 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2920 SetLastError(0xdeadbeef);
2921 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2922 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2923 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2924 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2925 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2926 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2928 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2929 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2930 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2931 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2932 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2933 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2934 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2936 SetLastError(0xdeadbeef);
2937 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
2938 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2940 SelectObject(hdcDst, oldDst);
2941 SelectObject(hdcSrc, oldSrc);
2942 DeleteObject(bmpSrc);
2943 DeleteObject(bmpDst);
2947 ReleaseDC(NULL, hdcNull);
2951 static void test_clipping(void)
2959 HDC hdcDst = CreateCompatibleDC( NULL );
2960 HDC hdcSrc = CreateCompatibleDC( NULL );
2962 BITMAPINFO bmpinfo={{0}};
2963 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2964 bmpinfo.bmiHeader.biWidth = 100;
2965 bmpinfo.bmiHeader.biHeight = 100;
2966 bmpinfo.bmiHeader.biPlanes = 1;
2967 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2968 bmpinfo.bmiHeader.biCompression = BI_RGB;
2970 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2971 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2972 SelectObject( hdcDst, bmpDst );
2974 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2975 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2976 SelectObject( hdcSrc, bmpSrc );
2978 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2979 ok(result, "BitBlt failed\n");
2981 hRgn = CreateRectRgn( 0,0,0,0 );
2982 SelectClipRgn( hdcDst, hRgn );
2984 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2985 ok(result, "BitBlt failed\n");
2987 DeleteObject( bmpDst );
2988 DeleteObject( bmpSrc );
2989 DeleteObject( hRgn );
2994 static void test_32bit_bitmap_blt(void)
2997 HBITMAP bmpSrc, bmpDst;
2998 HBITMAP oldSrc, oldDst;
2999 HDC hdcSrc, hdcDst, hdcScreen;
3001 DWORD colorSrc = 0x11223344;
3003 memset(&biDst, 0, sizeof(BITMAPINFO));
3004 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3005 biDst.bmiHeader.biWidth = 2;
3006 biDst.bmiHeader.biHeight = -2;
3007 biDst.bmiHeader.biPlanes = 1;
3008 biDst.bmiHeader.biBitCount = 32;
3009 biDst.bmiHeader.biCompression = BI_RGB;
3011 hdcScreen = CreateCompatibleDC(0);
3012 if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
3014 DeleteDC(hdcScreen);
3015 trace("Skipping 32-bit DDB test\n");
3019 hdcSrc = CreateCompatibleDC(hdcScreen);
3020 bmpSrc = CreateBitmap(1, 1, 1, 32, &colorSrc);
3021 oldSrc = SelectObject(hdcSrc, bmpSrc);
3023 hdcDst = CreateCompatibleDC(hdcScreen);
3024 bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
3025 oldDst = SelectObject(hdcDst, bmpDst);
3027 StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
3028 ok(dstBuffer[0] == colorSrc, "Expected color=%x, received color=%x\n", colorSrc, dstBuffer[0]);
3031 SelectObject(hdcDst, oldDst);
3032 DeleteObject(bmpDst);
3035 SelectObject(hdcSrc, oldSrc);
3036 DeleteObject(bmpSrc);
3039 DeleteDC(hdcScreen);
3045 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
3047 hdll = GetModuleHandle("gdi32.dll");
3048 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
3050 test_createdibitmap();
3052 test_mono_dibsection();
3055 test_GetDIBits_selected_DIB(1);
3056 test_GetDIBits_selected_DIB(4);
3057 test_GetDIBits_selected_DIB(8);
3058 test_GetDIBits_selected_DDB(TRUE);
3059 test_GetDIBits_selected_DDB(FALSE);
3061 test_GetDIBits_BI_BITFIELDS();
3062 test_select_object();
3063 test_CreateBitmap();
3066 test_StretchDIBits();
3067 test_GdiAlphaBlend();
3068 test_32bit_bitmap_blt();
3069 test_bitmapinfoheadersize();