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)
1221 UINT dib_size, dib32_size;
1229 /* Create a DIB section with a color table */
1231 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1232 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1236 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1238 /* Choose width and height such that the row length (in bytes)
1239 is a multiple of 4 (makes things easier) */
1240 info->bmiHeader.biWidth = 32;
1241 info->bmiHeader.biHeight = 32;
1242 info->bmiHeader.biPlanes = 1;
1243 info->bmiHeader.biBitCount = bpp;
1244 info->bmiHeader.biCompression = BI_RGB;
1246 for (i=0; i < (1u << bpp); i++)
1248 BYTE c = i * (1 << (8 - bpp));
1249 info->bmiColors[i].rgbRed = c;
1250 info->bmiColors[i].rgbGreen = c;
1251 info->bmiColors[i].rgbBlue = c;
1252 info->bmiColors[i].rgbReserved = 0;
1255 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1257 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1258 dib32_size = 32 * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1260 /* Set the bits of the DIB section */
1261 for (i=0; i < dib_size; i++)
1263 ((BYTE *)bits)[i] = i % 256;
1266 /* Select the DIB into a DC */
1267 dib_dc = CreateCompatibleDC(NULL);
1268 old_bmp = SelectObject(dib_dc, dib);
1269 dc = CreateCompatibleDC(NULL);
1270 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib32_size);
1273 /* Copy the DIB attributes but not the color table */
1274 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1276 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1277 ok(res, "GetDIBits failed\n");
1279 /* Compare the color table and the bits */
1280 equalContents = TRUE;
1281 for (i=0; i < (1u << bpp); i++)
1283 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1284 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1285 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1286 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1288 equalContents = FALSE;
1292 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1294 equalContents = TRUE;
1295 for (i=0; i < dib_size / sizeof(DWORD); i++)
1297 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1299 equalContents = FALSE;
1303 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1305 /* Map into a 32bit-DIB */
1306 info2->bmiHeader.biBitCount = 32;
1307 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1308 ok(res, "GetDIBits failed\n");
1310 /* Check if last pixel was set */
1311 pixel = ((DWORD *)bits2)[info->bmiHeader.biWidth * info->bmiHeader.biHeight - 1];
1312 ok(pixel != 0, "Pixel: 0x%08x\n", pixel);
1314 HeapFree(GetProcessHeap(), 0, bits2);
1317 SelectObject(dib_dc, old_bmp);
1321 HeapFree(GetProcessHeap(), 0, info2);
1322 HeapFree(GetProcessHeap(), 0, info);
1325 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1340 width = height = 16;
1342 /* Create a DDB (device-dependent bitmap) */
1346 ddb = CreateBitmap(width, height, 1, 1, NULL);
1350 HDC screen_dc = GetDC(NULL);
1351 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1352 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1353 ReleaseDC(NULL, screen_dc);
1356 /* Set the pixels */
1357 ddb_dc = CreateCompatibleDC(NULL);
1358 old_bmp = SelectObject(ddb_dc, ddb);
1359 for (i = 0; i < width; i++)
1361 for (j=0; j < height; j++)
1363 BYTE c = (i * width + j) % 256;
1364 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1367 SelectObject(ddb_dc, old_bmp);
1369 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1370 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1374 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1375 info->bmiHeader.biWidth = width;
1376 info->bmiHeader.biHeight = height;
1377 info->bmiHeader.biPlanes = 1;
1378 info->bmiHeader.biBitCount = bpp;
1379 info->bmiHeader.biCompression = BI_RGB;
1381 dc = CreateCompatibleDC(NULL);
1383 /* Fill in biSizeImage */
1384 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1385 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1387 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1388 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1393 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1394 ok(res, "GetDIBits failed\n");
1396 /* Copy the DIB attributes but not the color table */
1397 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1399 /* Select the DDB into another DC */
1400 old_bmp = SelectObject(ddb_dc, ddb);
1403 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1404 ok(res, "GetDIBits failed\n");
1406 /* Compare the color table and the bits */
1409 equalContents = TRUE;
1410 for (i=0; i < (1u << bpp); i++)
1412 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1413 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1414 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1415 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1417 equalContents = FALSE;
1421 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1424 equalContents = TRUE;
1425 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1427 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1429 equalContents = FALSE;
1432 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1434 /* Test the palette */
1435 equalContents = TRUE;
1436 if (info2->bmiHeader.biBitCount <= 8)
1438 WORD *colors = (WORD*)info2->bmiColors;
1440 /* Get the palette indices */
1441 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1442 if (res == 0 && GetLastError() == ERROR_INVALID_PARAMETER) /* Win9x */
1443 res = GetDIBits(dc, ddb, 0, height, NULL, info2, DIB_PAL_COLORS);
1444 ok(res, "GetDIBits failed\n");
1446 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1450 equalContents = FALSE;
1456 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1458 HeapFree(GetProcessHeap(), 0, bits2);
1459 HeapFree(GetProcessHeap(), 0, bits);
1462 SelectObject(ddb_dc, old_bmp);
1466 HeapFree(GetProcessHeap(), 0, info2);
1467 HeapFree(GetProcessHeap(), 0, info);
1470 static void test_GetDIBits(void)
1472 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1473 static const BYTE bmp_bits_1[16 * 2] =
1475 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1476 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1477 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1478 0xff,0xff, 0,0, 0xff,0xff, 0,0
1480 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1481 static const BYTE dib_bits_1[16 * 4] =
1483 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1484 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1485 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1486 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1488 static const BYTE dib_bits_1_9x[16 * 4] =
1490 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1491 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1492 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1493 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1495 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1496 static const BYTE bmp_bits_24[16 * 16*3] =
1498 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1519 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1520 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1522 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1523 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1524 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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1526 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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1528 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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1531 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1532 static const BYTE dib_bits_24[16 * 16*3] =
1534 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
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 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1555 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1556 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1557 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1558 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1559 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1560 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1561 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1562 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1563 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1564 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1565 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1570 int i, bytes, lines;
1572 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1573 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1577 /* 1-bit source bitmap data */
1578 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1579 ok(hbmp != 0, "CreateBitmap failed\n");
1581 memset(&bm, 0xAA, sizeof(bm));
1582 bytes = GetObject(hbmp, sizeof(bm), &bm);
1583 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1584 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1585 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1586 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1587 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1588 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1589 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1590 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1592 bytes = GetBitmapBits(hbmp, 0, NULL);
1593 ok(bytes == sizeof(bmp_bits_1) || broken(bytes == 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes);
1594 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1595 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1596 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1598 /* retrieve 1-bit DIB data */
1599 memset(bi, 0, sizeof(*bi));
1600 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1601 bi->bmiHeader.biWidth = bm.bmWidth;
1602 bi->bmiHeader.biHeight = bm.bmHeight;
1603 bi->bmiHeader.biPlanes = 1;
1604 bi->bmiHeader.biBitCount = 1;
1605 bi->bmiHeader.biCompression = BI_RGB;
1606 bi->bmiHeader.biSizeImage = 0;
1607 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1608 SetLastError(0xdeadbeef);
1609 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1610 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1611 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1612 broken(GetLastError() == 0xdeadbeef), /* winnt */
1613 "wrong error %u\n", GetLastError());
1614 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1616 memset(buf, 0xAA, sizeof(buf));
1617 SetLastError(0xdeadbeef);
1618 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1619 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1620 lines, bm.bmHeight, GetLastError());
1621 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1622 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1623 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1625 /* the color table consists of black and white */
1626 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1627 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1628 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1629 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1630 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1631 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1632 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1633 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1634 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1635 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1636 for (i = 2; i < 256; i++)
1638 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1639 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1640 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1641 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1642 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1645 /* returned bits are DWORD aligned and upside down */
1646 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1647 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1648 "DIB bits don't match\n");
1650 /* Test the palette indices */
1651 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1652 SetLastError(0xdeadbeef);
1653 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1654 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1655 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1658 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1659 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1661 for (i = 2; i < 256; i++)
1662 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1664 /* retrieve 24-bit DIB data */
1665 memset(bi, 0, sizeof(*bi));
1666 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1667 bi->bmiHeader.biWidth = bm.bmWidth;
1668 bi->bmiHeader.biHeight = bm.bmHeight;
1669 bi->bmiHeader.biPlanes = 1;
1670 bi->bmiHeader.biBitCount = 24;
1671 bi->bmiHeader.biCompression = BI_RGB;
1672 bi->bmiHeader.biSizeImage = 0;
1673 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1674 memset(buf, 0xAA, sizeof(buf));
1675 SetLastError(0xdeadbeef);
1676 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1677 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1678 lines, bm.bmHeight, GetLastError());
1679 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1680 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1681 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1683 /* the color table doesn't exist for 24-bit images */
1684 for (i = 0; i < 256; i++)
1686 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1687 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1688 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1689 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1690 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1693 /* returned bits are DWORD aligned and upside down */
1694 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1697 /* 24-bit source bitmap data */
1698 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1699 ok(hbmp != 0, "CreateBitmap failed\n");
1700 SetLastError(0xdeadbeef);
1701 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1702 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1703 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1704 lines, bm.bmHeight, GetLastError());
1706 memset(&bm, 0xAA, sizeof(bm));
1707 bytes = GetObject(hbmp, sizeof(bm), &bm);
1708 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1709 ok(bm.bmType == 0 ||
1710 broken(bm.bmType == 21072), /* win9x */
1711 "wrong bmType %d\n", bm.bmType);
1712 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1713 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1714 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1715 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1716 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1717 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1719 bytes = GetBitmapBits(hbmp, 0, NULL);
1720 ok(bytes == bm.bmWidthBytes * bm.bmHeight ||
1721 broken(bytes == 0), /* win9x */
1722 "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
1723 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1724 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1725 bm.bmWidthBytes * bm.bmHeight, bytes);
1727 /* retrieve 1-bit DIB data */
1728 memset(bi, 0, sizeof(*bi));
1729 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1730 bi->bmiHeader.biWidth = bm.bmWidth;
1731 bi->bmiHeader.biHeight = bm.bmHeight;
1732 bi->bmiHeader.biPlanes = 1;
1733 bi->bmiHeader.biBitCount = 1;
1734 bi->bmiHeader.biCompression = BI_RGB;
1735 bi->bmiHeader.biSizeImage = 0;
1736 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1737 memset(buf, 0xAA, sizeof(buf));
1738 SetLastError(0xdeadbeef);
1739 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1740 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1741 lines, bm.bmHeight, GetLastError());
1742 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1) ||
1743 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1744 "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1746 /* the color table consists of black and white */
1747 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1748 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1749 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1750 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1751 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1752 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1753 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1754 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1755 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1756 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1757 for (i = 2; i < 256; i++)
1759 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1760 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1761 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1762 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1763 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1766 /* returned bits are DWORD aligned and upside down */
1768 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)) ||
1769 broken(!memcmp(buf, dib_bits_1_9x, sizeof(dib_bits_1_9x))), /* Win9x, WinME */
1770 "DIB bits don't match\n");
1772 /* Test the palette indices */
1773 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1774 SetLastError(0xdeadbeef);
1775 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1776 if (lines == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1777 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1780 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1781 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1783 for (i = 2; i < 256; i++)
1784 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1786 /* retrieve 24-bit DIB data */
1787 memset(bi, 0, sizeof(*bi));
1788 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1789 bi->bmiHeader.biWidth = bm.bmWidth;
1790 bi->bmiHeader.biHeight = bm.bmHeight;
1791 bi->bmiHeader.biPlanes = 1;
1792 bi->bmiHeader.biBitCount = 24;
1793 bi->bmiHeader.biCompression = BI_RGB;
1794 bi->bmiHeader.biSizeImage = 0;
1795 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1796 memset(buf, 0xAA, sizeof(buf));
1797 SetLastError(0xdeadbeef);
1798 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1799 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1800 lines, bm.bmHeight, GetLastError());
1801 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24) ||
1802 broken(bi->bmiHeader.biSizeImage == 0), /* win9x */
1803 "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1805 /* the color table doesn't exist for 24-bit images */
1806 for (i = 0; i < 256; i++)
1808 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1809 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1810 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1811 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1812 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1815 /* returned bits are DWORD aligned and upside down */
1816 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1822 static void test_GetDIBits_BI_BITFIELDS(void)
1824 /* Try a screen resolution detection technique
1825 * from the September 1999 issue of Windows Developer's Journal
1826 * which seems to be in widespread use.
1827 * http://www.lesher.ws/highcolor.html
1828 * http://www.lesher.ws/vidfmt.c
1829 * It hinges on being able to retrieve the bitmaps
1830 * for the three primary colors in non-paletted 16 bit mode.
1832 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1834 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1835 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1841 memset(dibinfo, 0, sizeof(dibinfo_buf));
1842 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1845 ok(hdc != NULL, "GetDC failed?\n");
1846 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1847 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1849 /* Call GetDIBits to fill in bmiHeader. */
1850 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1851 ok(ret == 1, "GetDIBits failed\n");
1852 if (dibinfo->bmiHeader.biBitCount > 8)
1854 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1855 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1857 ok( !bitmasks[0], "red mask is set\n" );
1858 ok( !bitmasks[1], "green mask is set\n" );
1859 ok( !bitmasks[2], "blue mask is set\n" );
1861 /* test with NULL bits pointer and correct bpp */
1862 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1863 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1864 ok(ret == 1, "GetDIBits failed\n");
1866 ok( bitmasks[0] != 0, "red mask is not set\n" );
1867 ok( bitmasks[1] != 0, "green mask is not set\n" );
1868 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1869 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1871 /* test with valid bits pointer */
1872 memset(dibinfo, 0, sizeof(dibinfo_buf));
1873 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1874 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1875 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1876 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1877 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1878 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1880 ok( bitmasks[0] != 0, "red mask is not set\n" );
1881 ok( bitmasks[1] != 0, "green mask is not set\n" );
1882 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1883 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
1884 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
1885 "size image not set\n" );
1887 /* now with bits and 0 lines */
1888 memset(dibinfo, 0, sizeof(dibinfo_buf));
1889 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1890 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1891 SetLastError(0xdeadbeef);
1892 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1893 if (ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1894 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1897 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1899 ok( !bitmasks[0], "red mask is set\n" );
1900 ok( !bitmasks[1], "green mask is set\n" );
1901 ok( !bitmasks[2], "blue mask is set\n" );
1902 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1904 memset(bitmasks, 0, 3*sizeof(DWORD));
1905 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1906 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1907 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1909 ok( bitmasks[0] != 0, "red mask is not set\n" );
1910 ok( bitmasks[1] != 0, "green mask is not set\n" );
1911 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1912 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1915 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1919 /* same thing now with a 32-bpp DIB section */
1921 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1922 dibinfo->bmiHeader.biWidth = 1;
1923 dibinfo->bmiHeader.biHeight = 1;
1924 dibinfo->bmiHeader.biPlanes = 1;
1925 dibinfo->bmiHeader.biBitCount = 32;
1926 dibinfo->bmiHeader.biCompression = BI_RGB;
1927 dibinfo->bmiHeader.biSizeImage = 0;
1928 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1929 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1930 dibinfo->bmiHeader.biClrUsed = 0;
1931 dibinfo->bmiHeader.biClrImportant = 0;
1932 bitmasks[0] = 0x0000ff;
1933 bitmasks[1] = 0x00ff00;
1934 bitmasks[2] = 0xff0000;
1935 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1936 ok( hbm != 0, "failed to create bitmap\n" );
1938 memset(dibinfo, 0, sizeof(dibinfo_buf));
1939 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1940 ret = GetDIBits(hdc, hbm, 0, 0, NULL, 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 );
1944 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1945 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1946 ok( !bitmasks[0], "red mask is set\n" );
1947 ok( !bitmasks[1], "green mask is set\n" );
1948 ok( !bitmasks[2], "blue mask is set\n" );
1950 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1951 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1952 ok(ret == 1, "GetDIBits failed\n");
1953 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1954 ok( bitmasks[0] == 0xff0000, "wrong red mask %08x\n", bitmasks[0] );
1955 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1956 ok( bitmasks[2] == 0x0000ff, "wrong blue mask %08x\n", bitmasks[2] );
1957 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
1958 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
1959 "size image not set\n" );
1963 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1964 dibinfo->bmiHeader.biWidth = 1;
1965 dibinfo->bmiHeader.biHeight = 1;
1966 dibinfo->bmiHeader.biPlanes = 1;
1967 dibinfo->bmiHeader.biBitCount = 32;
1968 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
1969 dibinfo->bmiHeader.biSizeImage = 0;
1970 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1971 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1972 dibinfo->bmiHeader.biClrUsed = 0;
1973 dibinfo->bmiHeader.biClrImportant = 0;
1974 bitmasks[0] = 0x0000ff;
1975 bitmasks[1] = 0x00ff00;
1976 bitmasks[2] = 0xff0000;
1977 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1978 ok( hbm != 0 || broken(!hbm), /* win9x */ "failed to create bitmap\n" );
1982 memset(dibinfo, 0, sizeof(dibinfo_buf));
1983 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1984 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1985 ok(ret == 1, "GetDIBits failed\n");
1987 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1988 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1989 ok( !bitmasks[0], "red mask is set\n" );
1990 ok( !bitmasks[1], "green mask is set\n" );
1991 ok( !bitmasks[2], "blue mask is set\n" );
1993 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1994 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1995 ok(ret == 1, "GetDIBits failed\n");
1996 ok( bitmasks[0] == 0x0000ff, "wrong red mask %08x\n", bitmasks[0] );
1997 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1998 ok( bitmasks[2] == 0xff0000, "wrong blue mask %08x\n", bitmasks[2] );
1999 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2004 /* 24-bpp DIB sections don't have bitfields */
2006 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2007 dibinfo->bmiHeader.biWidth = 1;
2008 dibinfo->bmiHeader.biHeight = 1;
2009 dibinfo->bmiHeader.biPlanes = 1;
2010 dibinfo->bmiHeader.biBitCount = 24;
2011 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
2012 dibinfo->bmiHeader.biSizeImage = 0;
2013 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2014 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2015 dibinfo->bmiHeader.biClrUsed = 0;
2016 dibinfo->bmiHeader.biClrImportant = 0;
2017 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2018 ok( hbm == 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
2019 dibinfo->bmiHeader.biCompression = BI_RGB;
2020 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2021 ok( hbm != 0, "failed to create bitmap\n" );
2023 memset(dibinfo, 0, sizeof(dibinfo_buf));
2024 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2025 ret = GetDIBits(hdc, hbm, 0, 0, NULL, 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 );
2029 ok( dibinfo->bmiHeader.biCompression == BI_RGB,
2030 "compression is %u\n", dibinfo->bmiHeader.biCompression );
2031 ok( !bitmasks[0], "red mask is set\n" );
2032 ok( !bitmasks[1], "green mask is set\n" );
2033 ok( !bitmasks[2], "blue mask is set\n" );
2035 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2036 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2037 ok(ret == 1, "GetDIBits failed\n");
2038 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2039 ok( !bitmasks[0], "red mask is set\n" );
2040 ok( !bitmasks[1], "green mask is set\n" );
2041 ok( !bitmasks[2], "blue mask is set\n" );
2042 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef ||
2043 broken(dibinfo->bmiHeader.biSizeImage == 0xdeadbeef), /* win9x */
2044 "size image not set\n" );
2047 ReleaseDC(NULL, hdc);
2050 static void test_select_object(void)
2053 HBITMAP hbm, hbm_old;
2055 DWORD depths[] = {8, 15, 16, 24, 32};
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 should fail\n");
2070 hdc = CreateCompatibleDC(0);
2071 ok(hdc != 0, "GetDC(0) failed\n");
2072 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2073 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2075 hbm_old = SelectObject(hdc, hbm);
2076 ok(hbm_old != 0, "SelectObject failed\n");
2077 hbm_old = SelectObject(hdc, hbm_old);
2078 ok(hbm_old == hbm, "SelectObject failed\n");
2082 /* test an 1-bpp bitmap */
2083 planes = GetDeviceCaps(hdc, PLANES);
2086 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
2087 ok(hbm != 0, "CreateBitmap failed\n");
2089 hbm_old = SelectObject(hdc, hbm);
2090 ok(hbm_old != 0, "SelectObject failed\n");
2091 hbm_old = SelectObject(hdc, hbm_old);
2092 ok(hbm_old == hbm, "SelectObject failed\n");
2096 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
2097 /* test a color bitmap to dc bpp matching */
2098 planes = GetDeviceCaps(hdc, PLANES);
2099 bpp = GetDeviceCaps(hdc, BITSPIXEL);
2101 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
2102 ok(hbm != 0, "CreateBitmap failed\n");
2104 hbm_old = SelectObject(hdc, hbm);
2105 if(depths[i] == bpp ||
2106 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
2108 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
2109 SelectObject(hdc, hbm_old);
2111 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
2114 memset(&bm, 0xAA, sizeof(bm));
2115 bytes = GetObject(hbm, sizeof(bm), &bm);
2116 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2117 ok(bm.bmType == 0 ||
2118 broken(bm.bmType == 21072), /* win9x */
2119 "wrong bmType %d\n", bm.bmType);
2120 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2121 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2122 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2123 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2124 if(depths[i] == 15) {
2125 ok(bm.bmBitsPixel == 16 ||
2126 broken(bm.bmBitsPixel == 15), /* Win9x/WinME */
2127 "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2129 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2131 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2139 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
2144 ret = GetObjectType(hbmp);
2145 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
2147 ret = GetObject(hbmp, 0, 0);
2148 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
2149 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
2151 memset(&bm, 0xDA, sizeof(bm));
2152 SetLastError(0xdeadbeef);
2153 ret = GetObject(hbmp, sizeof(bm), &bm);
2154 if (!ret) /* XP, only for curObj2 */ return;
2155 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
2156 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
2157 "GetObject returned %d, error %u\n", ret, GetLastError());
2158 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
2159 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
2160 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
2161 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
2162 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
2163 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
2164 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2167 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2169 static void test_CreateBitmap(void)
2172 HDC screenDC = GetDC(0);
2173 HDC hdc = CreateCompatibleDC(screenDC);
2176 /* all of these are the stock monochrome bitmap */
2177 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
2178 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2179 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2180 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2181 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
2182 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2184 /* these 2 are not the stock monochrome bitmap */
2185 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2186 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2188 HBITMAP old1 = SelectObject(hdc, bm2);
2189 HBITMAP old2 = SelectObject(screenDC, bm3);
2190 SelectObject(hdc, old1);
2191 SelectObject(screenDC, old2);
2193 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2194 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2195 bm, bm1, bm4, bm5, curObj1, old1);
2196 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2198 ok(bm != curObj2 || /* WinXP */
2199 broken(bm == curObj2) /* Win9x */,
2200 "0: %p, curObj2 %p\n", bm, curObj2);
2201 ok(old2 == 0, "old2 %p\n", old2);
2203 test_mono_1x1_bmp(bm);
2204 test_mono_1x1_bmp(bm1);
2205 test_mono_1x1_bmp(bm2);
2206 test_mono_1x1_bmp(bm3);
2207 test_mono_1x1_bmp(bm4);
2208 test_mono_1x1_bmp(bm5);
2209 test_mono_1x1_bmp(old1);
2210 test_mono_1x1_bmp(curObj1);
2220 ReleaseDC(0, screenDC);
2222 /* show that Windows ignores the provided bm.bmWidthBytes */
2226 bmp.bmWidthBytes = 28;
2228 bmp.bmBitsPixel = 1;
2230 bm = CreateBitmapIndirect(&bmp);
2231 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2232 test_mono_1x1_bmp(bm);
2235 /* Test how the bmBitsPixel field is treated */
2236 for(i = 1; i <= 33; i++) {
2240 bmp.bmWidthBytes = 28;
2242 bmp.bmBitsPixel = i;
2244 SetLastError(0xdeadbeef);
2245 bm = CreateBitmapIndirect(&bmp);
2247 DWORD error = GetLastError();
2249 broken(bm != 0), /* Win9x and WinMe */
2250 "CreateBitmapIndirect for %d bpp succeeded\n", i);
2251 ok(error == ERROR_INVALID_PARAMETER ||
2252 broken(error == 0xdeadbeef), /* Win9x and WinME */
2253 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2257 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2258 GetObject(bm, sizeof(bmp), &bmp);
2265 } else if(i <= 16) {
2267 } else if(i <= 24) {
2269 } else if(i <= 32) {
2272 ok(bmp.bmBitsPixel == expect ||
2273 broken(bmp.bmBitsPixel == i), /* Win9x and WinMe */
2274 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2275 i, bmp.bmBitsPixel, expect);
2280 static void test_bitmapinfoheadersize(void)
2287 memset(&bmi, 0, sizeof(BITMAPINFO));
2288 bmi.bmiHeader.biHeight = 100;
2289 bmi.bmiHeader.biWidth = 512;
2290 bmi.bmiHeader.biBitCount = 24;
2291 bmi.bmiHeader.biPlanes = 1;
2293 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2295 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2296 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2298 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2300 SetLastError(0xdeadbeef);
2301 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2302 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2305 bmi.bmiHeader.biSize++;
2307 SetLastError(0xdeadbeef);
2308 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2310 broken(!hdib), /* Win98, WinMe */
2311 "CreateDIBSection error %d\n", GetLastError());
2314 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2316 SetLastError(0xdeadbeef);
2317 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2319 broken(!hdib), /* Win98, WinMe */
2320 "CreateDIBSection error %d\n", GetLastError());
2323 bmi.bmiHeader.biSize++;
2325 SetLastError(0xdeadbeef);
2326 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2328 broken(!hdib), /* Win98, WinMe */
2329 "CreateDIBSection error %d\n", GetLastError());
2332 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2334 SetLastError(0xdeadbeef);
2335 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2336 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2339 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2341 SetLastError(0xdeadbeef);
2342 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2344 broken(!hdib), /* Win95 */
2345 "CreateDIBSection error %d\n", GetLastError());
2348 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2349 bci.bmciHeader.bcHeight = 100;
2350 bci.bmciHeader.bcWidth = 512;
2351 bci.bmciHeader.bcBitCount = 24;
2352 bci.bmciHeader.bcPlanes = 1;
2354 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2356 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2357 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2359 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2361 SetLastError(0xdeadbeef);
2362 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2363 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2366 bci.bmciHeader.bcSize++;
2368 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2369 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2371 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2373 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2374 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2379 static void test_get16dibits(void)
2381 BYTE bits[4 * (16 / sizeof(BYTE))];
2383 HDC screen_dc = GetDC(NULL);
2386 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2388 int overwritten_bytes = 0;
2390 memset(bits, 0, sizeof(bits));
2391 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2392 ok(hbmp != NULL, "CreateBitmap failed\n");
2394 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2397 memset(info, '!', info_len);
2398 memset(info, 0, sizeof(info->bmiHeader));
2400 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2401 info->bmiHeader.biWidth = 2;
2402 info->bmiHeader.biHeight = 2;
2403 info->bmiHeader.biPlanes = 1;
2404 info->bmiHeader.biCompression = BI_RGB;
2406 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2408 broken(ret == 0), /* win9x */
2409 "GetDIBits failed got %d\n", ret);
2411 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2413 overwritten_bytes++;
2414 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2416 HeapFree(GetProcessHeap(), 0, info);
2418 ReleaseDC(NULL, screen_dc);
2421 static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2424 for(i = 0; i < length; i++)
2425 if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2430 static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2431 DWORD dwRop, UINT32 expected, int line)
2433 *srcBuffer = 0xFEDCBA98;
2434 *dstBuffer = 0x89ABCDEF;
2435 Rectangle(hdcSrc, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2436 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
2437 ok(expected == *dstBuffer,
2438 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2439 dwRop, expected, *dstBuffer, line);
2442 static void test_BitBlt(void)
2444 HBITMAP bmpDst, bmpSrc;
2445 HBITMAP oldDst, oldSrc;
2446 HDC hdcScreen, hdcDst, hdcSrc;
2447 UINT32 *dstBuffer, *srcBuffer;
2448 HBRUSH hBrush, hOldBrush;
2449 BITMAPINFO bitmapInfo;
2451 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2452 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2453 bitmapInfo.bmiHeader.biWidth = 1;
2454 bitmapInfo.bmiHeader.biHeight = 1;
2455 bitmapInfo.bmiHeader.biPlanes = 1;
2456 bitmapInfo.bmiHeader.biBitCount = 32;
2457 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2458 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2460 hdcScreen = CreateCompatibleDC(0);
2461 hdcDst = CreateCompatibleDC(hdcScreen);
2462 hdcSrc = CreateCompatibleDC(hdcDst);
2464 /* Setup the destination dib section */
2465 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
2467 oldDst = SelectObject(hdcDst, bmpDst);
2469 hBrush = CreateSolidBrush(0x012345678);
2470 hOldBrush = SelectObject(hdcDst, hBrush);
2472 /* Setup the source dib section */
2473 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
2475 oldSrc = SelectObject(hdcSrc, bmpSrc);
2477 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2478 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2479 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2480 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2481 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2482 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2483 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2484 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2485 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2486 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2487 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2488 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2489 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2490 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2491 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2494 SelectObject(hdcSrc, oldSrc);
2495 DeleteObject(bmpSrc);
2498 SelectObject(hdcDst, hOldBrush);
2499 DeleteObject(hBrush);
2500 SelectObject(hdcDst, oldDst);
2501 DeleteObject(bmpDst);
2505 DeleteDC(hdcScreen);
2508 static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2509 DWORD dwRop, UINT32 expected, int line)
2511 *srcBuffer = 0xFEDCBA98;
2512 *dstBuffer = 0x89ABCDEF;
2513 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
2514 ok(expected == *dstBuffer,
2515 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2516 dwRop, expected, *dstBuffer, line);
2519 static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2520 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2521 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2522 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2524 memset(dstBuffer, 0, 16);
2525 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2526 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2527 ok(memcmp(dstBuffer, expected, 16) == 0 ||
2528 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
2529 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2530 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2531 expected[0], expected[1], expected[2], expected[3],
2532 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2533 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2534 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2537 static void test_StretchBlt(void)
2539 HBITMAP bmpDst, bmpSrc;
2540 HBITMAP oldDst, oldSrc;
2541 HDC hdcScreen, hdcDst, hdcSrc;
2542 UINT32 *dstBuffer, *srcBuffer;
2543 HBRUSH hBrush, hOldBrush;
2544 BITMAPINFO biDst, biSrc;
2545 UINT32 expected[4], legacy_expected[4];
2547 memset(&biDst, 0, sizeof(BITMAPINFO));
2548 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2549 biDst.bmiHeader.biWidth = 2;
2550 biDst.bmiHeader.biHeight = -2;
2551 biDst.bmiHeader.biPlanes = 1;
2552 biDst.bmiHeader.biBitCount = 32;
2553 biDst.bmiHeader.biCompression = BI_RGB;
2554 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
2556 hdcScreen = CreateCompatibleDC(0);
2557 hdcDst = CreateCompatibleDC(hdcScreen);
2558 hdcSrc = CreateCompatibleDC(hdcDst);
2561 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2563 oldDst = SelectObject(hdcDst, bmpDst);
2565 bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
2567 oldSrc = SelectObject(hdcSrc, bmpSrc);
2569 hBrush = CreateSolidBrush(0x012345678);
2570 hOldBrush = SelectObject(hdcDst, hBrush);
2572 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2573 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2574 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2575 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2576 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2577 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2578 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2579 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2580 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2581 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2582 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2583 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2584 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2585 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2586 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2588 SelectObject(hdcDst, hOldBrush);
2589 DeleteObject(hBrush);
2591 /* Top-down to top-down tests */
2592 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2593 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2595 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2596 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2597 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2598 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2600 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2601 expected[2] = 0x00000000, expected[3] = 0x00000000;
2602 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2603 0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
2605 expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2606 expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2607 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2608 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2610 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2611 expected[2] = 0x00000000, expected[3] = 0x00000000;
2612 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2613 0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2615 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2616 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2617 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2618 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2620 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2621 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2622 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2623 1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2625 /* This result seems broken. One might expect the following result:
2626 * 0xCAFED00D 0xFEEDFACE
2627 * 0xFEDCBA98 0x76543210
2629 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2630 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2631 legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2632 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2633 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2634 1, 1, -2, -2, 1, 1, -2, -2, expected,
2635 legacy_expected, __LINE__);
2637 expected[0] = 0x00000000, expected[1] = 0x00000000;
2638 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2639 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2640 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2642 SelectObject(hdcDst, oldDst);
2643 DeleteObject(bmpDst);
2645 /* Top-down to bottom-up tests */
2646 biDst.bmiHeader.biHeight = 2;
2647 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2649 oldDst = SelectObject(hdcDst, bmpDst);
2651 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2652 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2653 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2654 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2656 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2657 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2658 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2659 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2661 SelectObject(hdcSrc, oldSrc);
2662 DeleteObject(bmpSrc);
2664 /* Bottom-up to bottom-up tests */
2665 biSrc.bmiHeader.biHeight = 2;
2666 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2668 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2669 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2670 oldSrc = SelectObject(hdcSrc, bmpSrc);
2672 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2673 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2674 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2675 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2677 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2678 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2679 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2680 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2682 SelectObject(hdcDst, oldDst);
2683 DeleteObject(bmpDst);
2685 /* Bottom-up to top-down tests */
2686 biDst.bmiHeader.biHeight = -2;
2687 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2689 oldDst = SelectObject(hdcDst, bmpDst);
2691 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2692 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2693 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2694 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2696 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2697 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2698 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2699 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2702 SelectObject(hdcSrc, oldSrc);
2703 DeleteObject(bmpSrc);
2706 SelectObject(hdcDst, oldDst);
2707 DeleteObject(bmpDst);
2710 DeleteDC(hdcScreen);
2713 static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2714 DWORD dwRop, UINT32 expected, int line)
2716 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
2717 BITMAPINFO bitmapInfo;
2719 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2720 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2721 bitmapInfo.bmiHeader.biWidth = 2;
2722 bitmapInfo.bmiHeader.biHeight = 1;
2723 bitmapInfo.bmiHeader.biPlanes = 1;
2724 bitmapInfo.bmiHeader.biBitCount = 32;
2725 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2726 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
2728 *dstBuffer = 0x89ABCDEF;
2730 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
2731 ok(expected == *dstBuffer,
2732 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2733 dwRop, expected, *dstBuffer, line);
2736 static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2737 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2738 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2739 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2741 BITMAPINFO bitmapInfo;
2743 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2744 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2745 bitmapInfo.bmiHeader.biWidth = 2;
2746 bitmapInfo.bmiHeader.biHeight = -2;
2747 bitmapInfo.bmiHeader.biPlanes = 1;
2748 bitmapInfo.bmiHeader.biBitCount = 32;
2749 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2751 memset(dstBuffer, 0, 16);
2752 StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2753 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2754 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
2755 ok(memcmp(dstBuffer, expected, 16) == 0 || /* Win2k/XP */
2756 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)) || /* Win9X/ME */
2757 broken(nWidthSrc < 0 || nHeightSrc < 0), /* Win9X/ME */
2758 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2759 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2760 expected[0], expected[1], expected[2], expected[3],
2761 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2762 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2763 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2766 static void test_StretchDIBits(void)
2770 HDC hdcScreen, hdcDst;
2771 UINT32 *dstBuffer, srcBuffer[4];
2772 HBRUSH hBrush, hOldBrush;
2774 UINT32 expected[4], legacy_expected[4];
2776 memset(&biDst, 0, sizeof(BITMAPINFO));
2777 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2778 biDst.bmiHeader.biWidth = 2;
2779 biDst.bmiHeader.biHeight = -2;
2780 biDst.bmiHeader.biPlanes = 1;
2781 biDst.bmiHeader.biBitCount = 32;
2782 biDst.bmiHeader.biCompression = BI_RGB;
2784 hdcScreen = CreateCompatibleDC(0);
2785 hdcDst = CreateCompatibleDC(hdcScreen);
2788 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2790 oldDst = SelectObject(hdcDst, bmpDst);
2792 hBrush = CreateSolidBrush(0x012345678);
2793 hOldBrush = SelectObject(hdcDst, hBrush);
2795 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2796 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2797 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2798 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2799 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2800 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2801 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2802 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2803 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2804 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2805 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2806 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2807 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2808 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2809 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2811 SelectObject(hdcDst, hOldBrush);
2812 DeleteObject(hBrush);
2814 /* Top-down destination tests */
2815 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2816 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2818 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2819 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2820 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2821 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2823 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2824 expected[2] = 0x00000000, expected[3] = 0x00000000;
2825 legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
2826 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2827 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2828 0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
2830 expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
2831 expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
2832 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2833 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2835 expected[0] = 0x42441000, expected[1] = 0x00000000;
2836 expected[2] = 0x00000000, expected[3] = 0x00000000;
2837 legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
2838 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2839 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2840 0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
2842 expected[0] = 0x00000000, expected[1] = 0x00000000;
2843 expected[2] = 0x00000000, expected[3] = 0x00000000;
2844 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2845 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2847 expected[0] = 0x00000000, expected[1] = 0x00000000;
2848 expected[2] = 0x00000000, expected[3] = 0x00000000;
2849 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2850 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2852 expected[0] = 0x00000000, expected[1] = 0x00000000;
2853 expected[2] = 0x00000000, expected[3] = 0x00000000;
2854 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2855 1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
2857 expected[0] = 0x00000000, expected[1] = 0x00000000;
2858 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2859 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2860 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2862 SelectObject(hdcDst, oldDst);
2863 DeleteObject(bmpDst);
2865 /* Bottom up destination tests */
2866 biDst.bmiHeader.biHeight = 2;
2867 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2869 oldDst = SelectObject(hdcDst, bmpDst);
2871 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2872 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2873 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2874 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2877 SelectObject(hdcDst, oldDst);
2878 DeleteObject(bmpDst);
2881 DeleteDC(hdcScreen);
2884 static void test_GdiAlphaBlend(void)
2886 /* test out-of-bound parameters for GdiAlphaBlend */
2899 BLENDFUNCTION blend;
2901 if (!pGdiAlphaBlend)
2903 win_skip("GdiAlphaBlend() is not implemented\n");
2907 hdcNull = GetDC(NULL);
2908 hdcDst = CreateCompatibleDC(hdcNull);
2909 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2910 hdcSrc = CreateCompatibleDC(hdcNull);
2912 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2913 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2914 bmi.bmiHeader.biHeight = 20;
2915 bmi.bmiHeader.biWidth = 20;
2916 bmi.bmiHeader.biBitCount = 32;
2917 bmi.bmiHeader.biPlanes = 1;
2918 bmi.bmiHeader.biCompression = BI_RGB;
2919 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2920 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2922 oldDst = SelectObject(hdcDst, bmpDst);
2923 oldSrc = SelectObject(hdcSrc, bmpSrc);
2925 blend.BlendOp = AC_SRC_OVER;
2926 blend.BlendFlags = 0;
2927 blend.SourceConstantAlpha = 128;
2928 blend.AlphaFormat = 0;
2930 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2931 SetLastError(0xdeadbeef);
2932 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2933 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2934 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2935 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2936 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2937 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2939 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2940 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2941 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2942 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2943 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2944 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2945 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2947 SetLastError(0xdeadbeef);
2948 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
2949 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2951 SelectObject(hdcDst, oldDst);
2952 SelectObject(hdcSrc, oldSrc);
2953 DeleteObject(bmpSrc);
2954 DeleteObject(bmpDst);
2958 ReleaseDC(NULL, hdcNull);
2962 static void test_clipping(void)
2970 HDC hdcDst = CreateCompatibleDC( NULL );
2971 HDC hdcSrc = CreateCompatibleDC( NULL );
2973 BITMAPINFO bmpinfo={{0}};
2974 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2975 bmpinfo.bmiHeader.biWidth = 100;
2976 bmpinfo.bmiHeader.biHeight = 100;
2977 bmpinfo.bmiHeader.biPlanes = 1;
2978 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2979 bmpinfo.bmiHeader.biCompression = BI_RGB;
2981 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2982 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2983 SelectObject( hdcDst, bmpDst );
2985 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2986 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2987 SelectObject( hdcSrc, bmpSrc );
2989 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2990 ok(result, "BitBlt failed\n");
2992 hRgn = CreateRectRgn( 0,0,0,0 );
2993 SelectClipRgn( hdcDst, hRgn );
2995 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2996 ok(result, "BitBlt failed\n");
2998 DeleteObject( bmpDst );
2999 DeleteObject( bmpSrc );
3000 DeleteObject( hRgn );
3005 static void test_32bit_bitmap_blt(void)
3008 HBITMAP bmpSrc, bmpDst;
3009 HBITMAP oldSrc, oldDst;
3010 HDC hdcSrc, hdcDst, hdcScreen;
3012 DWORD colorSrc = 0x11223344;
3014 memset(&biDst, 0, sizeof(BITMAPINFO));
3015 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3016 biDst.bmiHeader.biWidth = 2;
3017 biDst.bmiHeader.biHeight = -2;
3018 biDst.bmiHeader.biPlanes = 1;
3019 biDst.bmiHeader.biBitCount = 32;
3020 biDst.bmiHeader.biCompression = BI_RGB;
3022 hdcScreen = CreateCompatibleDC(0);
3023 if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
3025 DeleteDC(hdcScreen);
3026 trace("Skipping 32-bit DDB test\n");
3030 hdcSrc = CreateCompatibleDC(hdcScreen);
3031 bmpSrc = CreateBitmap(1, 1, 1, 32, &colorSrc);
3032 oldSrc = SelectObject(hdcSrc, bmpSrc);
3034 hdcDst = CreateCompatibleDC(hdcScreen);
3035 bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
3036 oldDst = SelectObject(hdcDst, bmpDst);
3038 StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
3039 ok(dstBuffer[0] == colorSrc, "Expected color=%x, received color=%x\n", colorSrc, dstBuffer[0]);
3042 SelectObject(hdcDst, oldDst);
3043 DeleteObject(bmpDst);
3046 SelectObject(hdcSrc, oldSrc);
3047 DeleteObject(bmpSrc);
3050 DeleteDC(hdcScreen);
3056 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
3058 hdll = GetModuleHandle("gdi32.dll");
3059 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
3061 test_createdibitmap();
3063 test_mono_dibsection();
3066 test_GetDIBits_selected_DIB(1);
3067 test_GetDIBits_selected_DIB(4);
3068 test_GetDIBits_selected_DIB(8);
3069 test_GetDIBits_selected_DDB(TRUE);
3070 test_GetDIBits_selected_DDB(FALSE);
3072 test_GetDIBits_BI_BITFIELDS();
3073 test_select_object();
3074 test_CreateBitmap();
3077 test_StretchDIBits();
3078 test_GdiAlphaBlend();
3079 test_32bit_bitmap_blt();
3080 test_bitmapinfoheadersize();