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 if(bm.bmType == 21072)
105 win_skip("win9x does not initialize the bitmap\n");
107 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match, depth %d\n", bmih->biBitCount);
109 /* test various buffer sizes for GetObject */
110 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
111 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
113 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
114 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
116 ret = GetObject(hbm, 0, &bm);
117 ok(ret == 0, "%d != 0\n", ret);
119 ret = GetObject(hbm, 1, &bm);
120 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
122 /* Don't trust Win9x not to try to write to NULL */
125 ret = GetObject(hbm, 0, NULL);
126 ok(ret == sizeof(bm), "wrong size %d\n", ret);
130 static void test_createdibitmap(void)
133 BITMAPINFOHEADER bmih;
135 HBITMAP hbm, hbm_colour, hbm_old;
140 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
141 memset(&bmih, 0, sizeof(bmih));
142 bmih.biSize = sizeof(bmih);
146 bmih.biBitCount = 32;
147 bmih.biCompression = BI_RGB;
149 /* First create an un-initialised bitmap. The depth of the bitmap
150 should match that of the hdc and not that supplied in bmih.
153 /* First try 32 bits */
154 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
155 ok(hbm != NULL, "CreateDIBitmap failed\n");
156 test_bitmap_info(hbm, screen_depth, &bmih);
160 bmih.biBitCount = 16;
161 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
162 ok(hbm != NULL, "CreateDIBitmap failed\n");
163 test_bitmap_info(hbm, screen_depth, &bmih);
168 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
169 ok(hbm != NULL, "CreateDIBitmap failed\n");
170 test_bitmap_info(hbm, screen_depth, &bmih);
173 /* Now with a monochrome dc we expect a monochrome bitmap */
174 hdcmem = CreateCompatibleDC(hdc);
176 /* First try 32 bits */
177 bmih.biBitCount = 32;
178 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
179 ok(hbm != NULL, "CreateDIBitmap failed\n");
180 test_bitmap_info(hbm, 1, &bmih);
184 bmih.biBitCount = 16;
185 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
186 ok(hbm != NULL, "CreateDIBitmap failed\n");
187 test_bitmap_info(hbm, 1, &bmih);
192 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
193 ok(hbm != NULL, "CreateDIBitmap failed\n");
194 test_bitmap_info(hbm, 1, &bmih);
197 /* Now select a polychrome bitmap into the dc and we expect
198 screen_depth bitmaps again */
199 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
200 test_bitmap_info(hbm_colour, screen_depth, &bmih);
201 hbm_old = SelectObject(hdcmem, hbm_colour);
203 /* First try 32 bits */
204 bmih.biBitCount = 32;
205 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
206 ok(hbm != NULL, "CreateDIBitmap failed\n");
207 test_bitmap_info(hbm, screen_depth, &bmih);
211 bmih.biBitCount = 16;
212 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
213 ok(hbm != NULL, "CreateDIBitmap failed\n");
214 test_bitmap_info(hbm, screen_depth, &bmih);
219 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
220 ok(hbm != NULL, "CreateDIBitmap failed\n");
221 test_bitmap_info(hbm, screen_depth, &bmih);
224 SelectObject(hdcmem, hbm_old);
225 DeleteObject(hbm_colour);
228 /* If hdc == 0 then we get a 1 bpp bitmap */
230 bmih.biBitCount = 32;
231 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
232 ok(hbm != NULL, "CreateDIBitmap failed\n");
233 test_bitmap_info(hbm, 1, &bmih);
237 /* Test how formats are converted */
243 memset(&bm, 0, sizeof(bm));
244 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
245 bm.bmiHeader.biWidth = 1;
246 bm.bmiHeader.biHeight = 1;
247 bm.bmiHeader.biPlanes = 1;
248 bm.bmiHeader.biBitCount= 24;
249 bm.bmiHeader.biCompression= BI_RGB;
250 bm.bmiHeader.biSizeImage = 0;
251 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
252 ok(hbm != NULL, "CreateDIBitmap failed\n");
255 bm.bmiHeader.biBitCount= 32;
256 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
257 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel);
263 static INT DIB_GetWidthBytes( int width, int bpp )
269 case 1: words = (width + 31) / 32; break;
270 case 4: words = (width + 7) / 8; break;
271 case 8: words = (width + 3) / 4; break;
273 case 16: words = (width + 1) / 2; break;
274 case 24: words = (width * 3 + 3)/4; break;
275 case 32: words = width; break;
279 trace("Unknown depth %d, please report.\n", bpp );
286 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
292 INT ret, bm_width_bytes, dib_width_bytes;
295 ret = GetObject(hbm, sizeof(bm), &bm);
296 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
298 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
299 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
300 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
301 dib_width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
302 bm_width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
303 if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
304 ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
306 ok(bm.bmWidthBytes == dib_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, dib_width_bytes);
307 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
308 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
309 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
311 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
313 /* GetBitmapBits returns not 32-bit aligned data */
314 SetLastError(0xdeadbeef);
315 ret = GetBitmapBits(hbm, 0, NULL);
316 ok(ret == bm_width_bytes * bm.bmHeight ||
317 broken(ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */
318 "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
320 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
321 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
322 ok(ret == bm_width_bytes * bm.bmHeight, "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
324 HeapFree(GetProcessHeap(), 0, buf);
326 /* test various buffer sizes for GetObject */
327 memset(&ds, 0xAA, sizeof(ds));
328 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
329 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
330 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
331 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
332 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
334 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
335 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
337 ret = GetObject(hbm, 0, &bm);
338 ok(ret == 0, "%d != 0\n", ret);
340 ret = GetObject(hbm, 1, &bm);
341 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
343 /* test various buffer sizes for GetObject */
344 ret = GetObject(hbm, 0, NULL);
345 ok(ret == sizeof(bm) || broken(ret == sizeof(DIBSECTION) /* Win9x */), "wrong size %d\n", ret);
347 ret = GetObject(hbm, sizeof(*dsa) * 2, dsa);
348 ok(ret == sizeof(*dsa) || broken(ret == sizeof(*dsa) * 2 /* Win9x */), "wrong size %d\n", ret);
350 memset(&ds, 0xAA, sizeof(ds));
351 ret = GetObject(hbm, sizeof(ds), &ds);
352 ok(ret == sizeof(ds), "wrong size %d\n", ret);
354 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
355 if (ds.dsBm.bmWidthBytes != bm_width_bytes) /* Win2k bug */
356 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
357 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
358 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
359 ds.dsBmih.biSizeImage = 0;
361 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
362 ok(ds.dsBmih.biWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
363 ok(ds.dsBmih.biHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
364 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
365 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
366 ok(ds.dsBmih.biCompression == bmih->biCompression, "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
367 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
368 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%u != %u\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
369 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%u != %u\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
371 memset(&ds, 0xAA, sizeof(ds));
372 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
373 ok(ret == sizeof(ds.dsBm) || broken(ret == (sizeof(ds) - 4) /* Win9x */), "wrong size %d\n", ret);
374 ok(ds.dsBm.bmWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
375 ok(ds.dsBm.bmHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
376 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
378 ret = GetObject(hbm, 0, &ds);
379 ok(ret == 0, "%d != 0\n", ret);
381 ret = GetObject(hbm, 1, &ds);
382 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
385 #define test_color_todo(got, exp, txt, todo) \
386 if (!todo && got != exp && screen_depth < 24) { \
387 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
388 screen_depth, (UINT)got, (UINT)exp); \
390 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
391 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
393 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
396 c = SetPixel(hdc, 0, 0, color); \
397 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
398 c = GetPixel(hdc, 0, 0); \
399 test_color_todo(c, exp, GetPixel, todo_getp); \
402 static void test_dib_bits_access( HBITMAP hdib, void *bits )
404 MEMORY_BASIC_INFORMATION info;
405 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
407 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
409 char filename[MAX_PATH];
414 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
415 "VirtualQuery failed\n");
416 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
417 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
418 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
419 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
420 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
421 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
423 memset( pbmi, 0, sizeof(bmibuf) );
424 memset( data, 0xcc, sizeof(data) );
425 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
426 pbmi->bmiHeader.biHeight = 16;
427 pbmi->bmiHeader.biWidth = 16;
428 pbmi->bmiHeader.biBitCount = 32;
429 pbmi->bmiHeader.biPlanes = 1;
430 pbmi->bmiHeader.biCompression = BI_RGB;
432 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
433 ok(ret == 16, "SetDIBits failed: expected 16 got %d\n", ret);
435 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
436 "VirtualQuery failed\n");
437 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
438 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
439 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
440 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
441 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
442 /* it has been protected now */
443 todo_wine ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
445 /* try writing protected bits to a file */
447 GetTempFileNameA( ".", "dib", 0, filename );
448 file = CreateFileA( filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
449 CREATE_ALWAYS, 0, 0 );
450 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %u\n", filename, GetLastError() );
451 ret = WriteFile( file, bits, 8192, &written, NULL );
452 ok( ret, "WriteFile failed error %u\n", GetLastError() );
453 if (ret) ok( written == 8192, "only wrote %u bytes\n", written );
455 DeleteFileA( filename );
458 static void test_dibsections(void)
460 HDC hdc, hdcmem, hdcmem2;
461 HBITMAP hdib, oldbm, hdib2, oldbm2;
462 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
463 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
464 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
465 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
471 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
472 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
475 HPALETTE hpal, oldpal;
480 MEMORY_BASIC_INFORMATION info;
483 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
485 memset(pbmi, 0, sizeof(bmibuf));
486 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
487 pbmi->bmiHeader.biHeight = 100;
488 pbmi->bmiHeader.biWidth = 512;
489 pbmi->bmiHeader.biBitCount = 24;
490 pbmi->bmiHeader.biPlanes = 1;
491 pbmi->bmiHeader.biCompression = BI_RGB;
493 SetLastError(0xdeadbeef);
495 /* invalid pointer for BITMAPINFO
496 (*bits should be NULL on error) */
497 bits = (BYTE*)0xdeadbeef;
498 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
499 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
501 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
502 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
503 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
504 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
506 /* test the DIB memory */
507 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
508 "VirtualQuery failed\n");
509 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
510 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
511 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
512 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
513 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
514 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
515 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
517 test_dib_bits_access( hdib, bits );
519 test_dib_info(hdib, bits, &pbmi->bmiHeader);
522 pbmi->bmiHeader.biBitCount = 8;
523 pbmi->bmiHeader.biCompression = BI_RLE8;
524 SetLastError(0xdeadbeef);
525 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
526 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
527 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
529 pbmi->bmiHeader.biBitCount = 16;
530 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
531 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
532 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
533 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
534 SetLastError(0xdeadbeef);
535 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
536 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
538 /* test the DIB memory */
539 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
540 "VirtualQuery failed\n");
541 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
542 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
543 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
544 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
545 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
546 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
547 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
549 test_dib_info(hdib, bits, &pbmi->bmiHeader);
552 memset(pbmi, 0, sizeof(bmibuf));
553 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
554 pbmi->bmiHeader.biHeight = 16;
555 pbmi->bmiHeader.biWidth = 16;
556 pbmi->bmiHeader.biBitCount = 1;
557 pbmi->bmiHeader.biPlanes = 1;
558 pbmi->bmiHeader.biCompression = BI_RGB;
559 pbmi->bmiColors[0].rgbRed = 0xff;
560 pbmi->bmiColors[0].rgbGreen = 0;
561 pbmi->bmiColors[0].rgbBlue = 0;
562 pbmi->bmiColors[1].rgbRed = 0;
563 pbmi->bmiColors[1].rgbGreen = 0;
564 pbmi->bmiColors[1].rgbBlue = 0xff;
566 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
567 ok(hdib != NULL, "CreateDIBSection failed\n");
568 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
569 ok(dibsec.dsBmih.biClrUsed == 2,
570 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
572 /* Test if the old BITMAPCOREINFO structure is supported */
574 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
575 pbci->bmciHeader.bcBitCount = 0;
578 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
579 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
580 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
581 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
582 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
584 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
585 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
586 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
587 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
588 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
589 "The color table has not been translated to the old BITMAPCOREINFO format\n");
591 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
592 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
594 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
595 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
596 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
597 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
598 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
599 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
600 "The color table has not been translated to the old BITMAPCOREINFO format\n");
602 DeleteObject(hcoredib);
605 hdcmem = CreateCompatibleDC(hdc);
606 oldbm = SelectObject(hdcmem, hdib);
608 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
609 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
610 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
611 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
612 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
613 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
615 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
616 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
618 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
619 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
620 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
621 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
622 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
623 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
624 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
625 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
626 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
627 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
628 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
629 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
630 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
632 SelectObject(hdcmem, oldbm);
635 pbmi->bmiColors[0].rgbRed = 0xff;
636 pbmi->bmiColors[0].rgbGreen = 0xff;
637 pbmi->bmiColors[0].rgbBlue = 0xff;
638 pbmi->bmiColors[1].rgbRed = 0;
639 pbmi->bmiColors[1].rgbGreen = 0;
640 pbmi->bmiColors[1].rgbBlue = 0;
642 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
643 ok(hdib != NULL, "CreateDIBSection failed\n");
645 test_dib_info(hdib, bits, &pbmi->bmiHeader);
647 oldbm = SelectObject(hdcmem, hdib);
649 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
650 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
651 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
652 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
653 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
654 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
656 SelectObject(hdcmem, oldbm);
657 test_dib_info(hdib, bits, &pbmi->bmiHeader);
660 pbmi->bmiHeader.biBitCount = 4;
661 for (i = 0; i < 16; i++) {
662 pbmi->bmiColors[i].rgbRed = i;
663 pbmi->bmiColors[i].rgbGreen = 16-i;
664 pbmi->bmiColors[i].rgbBlue = 0;
666 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
667 ok(hdib != NULL, "CreateDIBSection failed\n");
668 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
669 ok(dibsec.dsBmih.biClrUsed == 16,
670 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
671 test_dib_info(hdib, bits, &pbmi->bmiHeader);
674 pbmi->bmiHeader.biBitCount = 8;
676 for (i = 0; i < 128; i++) {
677 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
678 pbmi->bmiColors[i].rgbGreen = i * 2;
679 pbmi->bmiColors[i].rgbBlue = 0;
680 pbmi->bmiColors[255 - i].rgbRed = 0;
681 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
682 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
684 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
685 ok(hdib != NULL, "CreateDIBSection failed\n");
686 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
687 ok(dibsec.dsBmih.biClrUsed == 256,
688 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
690 oldbm = SelectObject(hdcmem, hdib);
692 for (i = 0; i < 256; i++) {
693 test_color(hdcmem, DIBINDEX(i),
694 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
695 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
696 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
699 SelectObject(hdcmem, oldbm);
700 test_dib_info(hdib, bits, &pbmi->bmiHeader);
703 pbmi->bmiHeader.biBitCount = 1;
705 /* Now create a palette and a palette indexed dib section */
706 memset(plogpal, 0, sizeof(logpalbuf));
707 plogpal->palVersion = 0x300;
708 plogpal->palNumEntries = 2;
709 plogpal->palPalEntry[0].peRed = 0xff;
710 plogpal->palPalEntry[0].peBlue = 0xff;
711 plogpal->palPalEntry[1].peGreen = 0xff;
713 index = (WORD*)pbmi->bmiColors;
716 hpal = CreatePalette(plogpal);
717 ok(hpal != NULL, "CreatePalette failed\n");
718 oldpal = SelectPalette(hdc, hpal, TRUE);
719 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
720 ok(hdib != NULL, "CreateDIBSection failed\n");
721 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
722 ok(dibsec.dsBmih.biClrUsed == 2,
723 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
725 /* The colour table has already been grabbed from the dc, so we select back the
728 SelectPalette(hdc, oldpal, TRUE);
729 oldbm = SelectObject(hdcmem, hdib);
730 oldpal = SelectPalette(hdcmem, hpal, TRUE);
732 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
733 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
734 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
735 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
736 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
737 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
738 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
740 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
741 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
743 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
744 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
745 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
746 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
747 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
748 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
749 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
750 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
751 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
752 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
753 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
754 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
755 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
756 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
757 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
758 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
760 /* Bottom and 2nd row from top green, everything else magenta */
761 bits[0] = bits[1] = 0xff;
762 bits[13 * 4] = bits[13*4 + 1] = 0xff;
764 test_dib_info(hdib, bits, &pbmi->bmiHeader);
766 pbmi->bmiHeader.biBitCount = 32;
768 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
769 ok(hdib2 != NULL, "CreateDIBSection failed\n");
770 hdcmem2 = CreateCompatibleDC(hdc);
771 oldbm2 = SelectObject(hdcmem2, hdib2);
773 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
775 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
776 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32[17]);
778 SelectObject(hdcmem2, oldbm2);
779 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
782 SelectObject(hdcmem, oldbm);
783 SelectObject(hdcmem, oldpal);
788 pbmi->bmiHeader.biBitCount = 8;
790 memset(plogpal, 0, sizeof(logpalbuf));
791 plogpal->palVersion = 0x300;
792 plogpal->palNumEntries = 256;
794 for (i = 0; i < 128; i++) {
795 plogpal->palPalEntry[i].peRed = 255 - i * 2;
796 plogpal->palPalEntry[i].peBlue = i * 2;
797 plogpal->palPalEntry[i].peGreen = 0;
798 plogpal->palPalEntry[255 - i].peRed = 0;
799 plogpal->palPalEntry[255 - i].peGreen = i * 2;
800 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
803 index = (WORD*)pbmi->bmiColors;
804 for (i = 0; i < 256; i++) {
808 hpal = CreatePalette(plogpal);
809 ok(hpal != NULL, "CreatePalette failed\n");
810 oldpal = SelectPalette(hdc, hpal, TRUE);
811 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
812 ok(hdib != NULL, "CreateDIBSection failed\n");
813 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
814 ok(dibsec.dsBmih.biClrUsed == 256,
815 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
817 test_dib_info(hdib, bits, &pbmi->bmiHeader);
819 SelectPalette(hdc, oldpal, TRUE);
820 oldbm = SelectObject(hdcmem, hdib);
821 oldpal = SelectPalette(hdcmem, hpal, TRUE);
823 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
824 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
825 for (i = 0; i < 256; i++) {
826 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
827 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
828 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
829 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
830 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
833 for (i = 0; i < 256; i++) {
834 test_color(hdcmem, DIBINDEX(i),
835 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
836 test_color(hdcmem, PALETTEINDEX(i),
837 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
838 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
839 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
842 SelectPalette(hdcmem, oldpal, TRUE);
843 SelectObject(hdcmem, oldbm);
852 static void test_mono_dibsection(void)
855 HBITMAP old_bm, mono_ds;
856 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
857 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
864 memdc = CreateCompatibleDC(hdc);
866 memset(pbmi, 0, sizeof(bmibuf));
867 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
868 pbmi->bmiHeader.biHeight = 10;
869 pbmi->bmiHeader.biWidth = 10;
870 pbmi->bmiHeader.biBitCount = 1;
871 pbmi->bmiHeader.biPlanes = 1;
872 pbmi->bmiHeader.biCompression = BI_RGB;
873 pbmi->bmiColors[0].rgbRed = 0xff;
874 pbmi->bmiColors[0].rgbGreen = 0xff;
875 pbmi->bmiColors[0].rgbBlue = 0xff;
876 pbmi->bmiColors[1].rgbRed = 0x0;
877 pbmi->bmiColors[1].rgbGreen = 0x0;
878 pbmi->bmiColors[1].rgbBlue = 0x0;
881 * First dib section is 'inverted' ie color[0] is white, color[1] is black
884 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
885 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
886 old_bm = SelectObject(memdc, mono_ds);
888 /* black border, white interior */
889 Rectangle(memdc, 0, 0, 10, 10);
890 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
891 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
893 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
895 memset(bits, 0, sizeof(bits));
898 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
899 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
901 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
903 pbmi->bmiColors[0].rgbRed = 0x0;
904 pbmi->bmiColors[0].rgbGreen = 0x0;
905 pbmi->bmiColors[0].rgbBlue = 0x0;
906 pbmi->bmiColors[1].rgbRed = 0xff;
907 pbmi->bmiColors[1].rgbGreen = 0xff;
908 pbmi->bmiColors[1].rgbBlue = 0xff;
910 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
911 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
913 SelectObject(memdc, old_bm);
914 DeleteObject(mono_ds);
917 * Next dib section is 'normal' ie color[0] is black, color[1] is white
920 pbmi->bmiColors[0].rgbRed = 0x0;
921 pbmi->bmiColors[0].rgbGreen = 0x0;
922 pbmi->bmiColors[0].rgbBlue = 0x0;
923 pbmi->bmiColors[1].rgbRed = 0xff;
924 pbmi->bmiColors[1].rgbGreen = 0xff;
925 pbmi->bmiColors[1].rgbBlue = 0xff;
927 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
928 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
929 old_bm = SelectObject(memdc, mono_ds);
931 /* black border, white interior */
932 Rectangle(memdc, 0, 0, 10, 10);
933 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
934 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
936 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
938 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
939 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
941 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
943 pbmi->bmiColors[0].rgbRed = 0xff;
944 pbmi->bmiColors[0].rgbGreen = 0xff;
945 pbmi->bmiColors[0].rgbBlue = 0xff;
946 pbmi->bmiColors[1].rgbRed = 0x0;
947 pbmi->bmiColors[1].rgbGreen = 0x0;
948 pbmi->bmiColors[1].rgbBlue = 0x0;
950 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
951 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
954 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
957 pbmi->bmiColors[0].rgbRed = 0xff;
958 pbmi->bmiColors[0].rgbGreen = 0xff;
959 pbmi->bmiColors[0].rgbBlue = 0xff;
960 pbmi->bmiColors[1].rgbRed = 0x0;
961 pbmi->bmiColors[1].rgbGreen = 0x0;
962 pbmi->bmiColors[1].rgbBlue = 0x0;
963 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
964 ok(num == 2, "num = %d\n", num);
966 /* black border, white interior */
967 Rectangle(memdc, 0, 0, 10, 10);
969 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
970 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
972 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
974 memset(bits, 0, sizeof(bits));
977 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
978 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
980 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
982 pbmi->bmiColors[0].rgbRed = 0x0;
983 pbmi->bmiColors[0].rgbGreen = 0x0;
984 pbmi->bmiColors[0].rgbBlue = 0x0;
985 pbmi->bmiColors[1].rgbRed = 0xff;
986 pbmi->bmiColors[1].rgbGreen = 0xff;
987 pbmi->bmiColors[1].rgbBlue = 0xff;
989 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
990 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
992 SelectObject(memdc, old_bm);
993 DeleteObject(mono_ds);
996 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
999 pbmi->bmiColors[0].rgbRed = 0xff;
1000 pbmi->bmiColors[0].rgbGreen = 0x0;
1001 pbmi->bmiColors[0].rgbBlue = 0x0;
1002 pbmi->bmiColors[1].rgbRed = 0xfe;
1003 pbmi->bmiColors[1].rgbGreen = 0x0;
1004 pbmi->bmiColors[1].rgbBlue = 0x0;
1006 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1007 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1008 old_bm = SelectObject(memdc, mono_ds);
1010 /* black border, white interior */
1011 Rectangle(memdc, 0, 0, 10, 10);
1012 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1013 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1015 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1017 pbmi->bmiColors[0].rgbRed = 0x0;
1018 pbmi->bmiColors[0].rgbGreen = 0x0;
1019 pbmi->bmiColors[0].rgbBlue = 0x0;
1020 pbmi->bmiColors[1].rgbRed = 0xff;
1021 pbmi->bmiColors[1].rgbGreen = 0xff;
1022 pbmi->bmiColors[1].rgbBlue = 0xff;
1024 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1025 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1027 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1029 pbmi->bmiColors[0].rgbRed = 0xff;
1030 pbmi->bmiColors[0].rgbGreen = 0xff;
1031 pbmi->bmiColors[0].rgbBlue = 0xff;
1032 pbmi->bmiColors[1].rgbRed = 0x0;
1033 pbmi->bmiColors[1].rgbGreen = 0x0;
1034 pbmi->bmiColors[1].rgbBlue = 0x0;
1036 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1037 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1039 SelectObject(memdc, old_bm);
1040 DeleteObject(mono_ds);
1046 static void test_bitmap(void)
1048 char buf[256], buf_cmp[256];
1049 HBITMAP hbmp, hbmp_old;
1055 hdc = CreateCompatibleDC(0);
1058 SetLastError(0xdeadbeef);
1059 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1062 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1063 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1064 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1069 SetLastError(0xdeadbeef);
1070 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1073 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1074 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1075 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1080 SetLastError(0xdeadbeef);
1081 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1082 ok(!hbmp || broken(hbmp != NULL /* Win9x */), "CreateBitmap should fail\n");
1084 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1085 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1089 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1090 assert(hbmp != NULL);
1092 ret = GetObject(hbmp, sizeof(bm), &bm);
1093 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1095 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1096 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1097 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1098 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1099 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1100 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1101 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1103 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1104 assert(sizeof(buf) == sizeof(buf_cmp));
1106 ret = GetBitmapBits(hbmp, 0, NULL);
1107 ok(ret == bm.bmWidthBytes * bm.bmHeight || broken(ret == 0 /* Win9x */),
1108 "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1110 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1111 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1113 memset(buf, 0xAA, sizeof(buf));
1114 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1115 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1116 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1118 hbmp_old = SelectObject(hdc, hbmp);
1120 ret = GetObject(hbmp, sizeof(bm), &bm);
1121 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1123 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1124 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1125 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1126 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1127 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1128 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1129 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1131 memset(buf, 0xAA, sizeof(buf));
1132 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1133 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1134 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1136 hbmp_old = SelectObject(hdc, hbmp_old);
1137 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1139 /* test various buffer sizes for GetObject */
1140 ret = GetObject(hbmp, sizeof(*bma) * 2, bma);
1141 ok(ret == sizeof(*bma) || broken(ret == sizeof(*bma) * 2 /* Win9x */), "wrong size %d\n", ret);
1143 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1144 ok(ret == 0 || broken(ret == sizeof(bm) / 2 /* Win9x */), "%d != 0\n", ret);
1146 ret = GetObject(hbmp, 0, &bm);
1147 ok(ret == 0, "%d != 0\n", ret);
1149 ret = GetObject(hbmp, 1, &bm);
1150 ok(ret == 0 || broken(ret == 1 /* Win9x */), "%d != 0\n", ret);
1156 static void test_bmBits(void)
1162 memset(bits, 0, sizeof(bits));
1163 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1164 ok(hbmp != NULL, "CreateBitmap failed\n");
1166 memset(&bmp, 0xFF, sizeof(bmp));
1167 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1168 "GetObject failed or returned a wrong structure size\n");
1169 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1174 static void test_GetDIBits_selected_DIB(UINT bpp)
1188 /* Create a DIB section with a color table */
1190 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1191 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1195 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1197 /* Choose width and height such that the row length (in bytes)
1198 is a multiple of 4 (makes things easier) */
1199 info->bmiHeader.biWidth = 32;
1200 info->bmiHeader.biHeight = 32;
1201 info->bmiHeader.biPlanes = 1;
1202 info->bmiHeader.biBitCount = bpp;
1203 info->bmiHeader.biCompression = BI_RGB;
1205 for (i=0; i < (1u << bpp); i++)
1207 BYTE c = i * (1 << (8 - bpp));
1208 info->bmiColors[i].rgbRed = c;
1209 info->bmiColors[i].rgbGreen = c;
1210 info->bmiColors[i].rgbBlue = c;
1211 info->bmiColors[i].rgbReserved = 0;
1214 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1216 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1218 /* Set the bits of the DIB section */
1219 for (i=0; i < dib_size; i++)
1221 ((BYTE *)bits)[i] = i % 256;
1224 /* Select the DIB into a DC */
1225 dib_dc = CreateCompatibleDC(NULL);
1226 old_bmp = SelectObject(dib_dc, dib);
1227 dc = CreateCompatibleDC(NULL);
1228 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib_size);
1231 /* Copy the DIB attributes but not the color table */
1232 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1234 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1235 ok(res, "GetDIBits failed\n");
1237 /* Compare the color table and the bits */
1238 equalContents = TRUE;
1239 for (i=0; i < (1u << bpp); i++)
1241 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1242 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1243 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1244 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1246 equalContents = FALSE;
1250 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1252 equalContents = TRUE;
1253 for (i=0; i < dib_size / sizeof(DWORD); i++)
1255 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1257 equalContents = FALSE;
1261 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1263 HeapFree(GetProcessHeap(), 0, bits2);
1266 SelectObject(dib_dc, old_bmp);
1270 HeapFree(GetProcessHeap(), 0, info2);
1271 HeapFree(GetProcessHeap(), 0, info);
1274 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1289 width = height = 16;
1291 /* Create a DDB (device-dependent bitmap) */
1295 ddb = CreateBitmap(width, height, 1, 1, NULL);
1299 HDC screen_dc = GetDC(NULL);
1300 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1301 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1302 ReleaseDC(NULL, screen_dc);
1305 /* Set the pixels */
1306 ddb_dc = CreateCompatibleDC(NULL);
1307 old_bmp = SelectObject(ddb_dc, ddb);
1308 for (i = 0; i < width; i++)
1310 for (j=0; j < height; j++)
1312 BYTE c = (i * width + j) % 256;
1313 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1316 SelectObject(ddb_dc, old_bmp);
1318 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1319 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1323 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1324 info->bmiHeader.biWidth = width;
1325 info->bmiHeader.biHeight = height;
1326 info->bmiHeader.biPlanes = 1;
1327 info->bmiHeader.biBitCount = bpp;
1328 info->bmiHeader.biCompression = BI_RGB;
1330 dc = CreateCompatibleDC(NULL);
1332 /* Fill in biSizeImage */
1333 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1334 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1336 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1337 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1342 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1343 ok(res, "GetDIBits failed\n");
1345 /* Copy the DIB attributes but not the color table */
1346 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1348 /* Select the DDB into another DC */
1349 old_bmp = SelectObject(ddb_dc, ddb);
1352 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1353 ok(res, "GetDIBits failed\n");
1355 /* Compare the color table and the bits */
1358 equalContents = TRUE;
1359 for (i=0; i < (1u << bpp); i++)
1361 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1362 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1363 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1364 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1366 equalContents = FALSE;
1370 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1373 equalContents = TRUE;
1374 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1376 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1378 equalContents = FALSE;
1381 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1383 /* Test the palette */
1384 equalContents = TRUE;
1385 if (info2->bmiHeader.biBitCount <= 8)
1387 WORD *colors = (WORD*)info2->bmiColors;
1389 /* Get the palette indices */
1390 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1391 if (res == 0 && GetLastError() == ERROR_INVALID_PARAMETER) /* Win9x */
1392 res = GetDIBits(dc, ddb, 0, height, NULL, info2, DIB_PAL_COLORS);
1393 ok(res, "GetDIBits failed\n");
1395 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1399 equalContents = FALSE;
1405 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1407 HeapFree(GetProcessHeap(), 0, bits2);
1408 HeapFree(GetProcessHeap(), 0, bits);
1411 SelectObject(ddb_dc, old_bmp);
1415 HeapFree(GetProcessHeap(), 0, info2);
1416 HeapFree(GetProcessHeap(), 0, info);
1419 static void test_GetDIBits(void)
1421 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1422 static const BYTE bmp_bits_1[16 * 2] =
1424 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1425 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1426 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1427 0xff,0xff, 0,0, 0xff,0xff, 0,0
1429 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1430 static const BYTE dib_bits_1[16 * 4] =
1432 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1433 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1434 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1435 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1437 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1438 static const BYTE bmp_bits_24[16 * 16*3] =
1440 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1441 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1442 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1443 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1444 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1445 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1446 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1447 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1448 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1449 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1450 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1451 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1452 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1453 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1454 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1455 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1456 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1457 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1458 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1459 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1460 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1461 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1462 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1463 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1464 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1465 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1466 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1467 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1468 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1469 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1470 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1471 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1473 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1474 static const BYTE dib_bits_24[16 * 16*3] =
1476 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1477 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1478 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1479 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1480 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1481 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1482 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1483 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1484 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1485 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1486 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1487 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1488 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1489 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1490 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1491 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1492 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1493 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1494 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1495 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1496 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1497 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1498 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
1512 int i, bytes, lines;
1514 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1515 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1519 /* 1-bit source bitmap data */
1520 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1521 ok(hbmp != 0, "CreateBitmap failed\n");
1523 memset(&bm, 0xAA, sizeof(bm));
1524 bytes = GetObject(hbmp, sizeof(bm), &bm);
1525 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1526 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1527 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1528 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1529 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1530 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1531 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1532 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1534 bytes = GetBitmapBits(hbmp, 0, NULL);
1535 ok(bytes == sizeof(bmp_bits_1) || broken(bytes == 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes);
1536 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1537 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1538 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1540 /* retrieve 1-bit DIB data */
1541 memset(bi, 0, sizeof(*bi));
1542 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1543 bi->bmiHeader.biWidth = bm.bmWidth;
1544 bi->bmiHeader.biHeight = bm.bmHeight;
1545 bi->bmiHeader.biPlanes = 1;
1546 bi->bmiHeader.biBitCount = 1;
1547 bi->bmiHeader.biCompression = BI_RGB;
1548 bi->bmiHeader.biSizeImage = 0;
1549 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1550 SetLastError(0xdeadbeef);
1551 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1552 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1553 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1554 broken(GetLastError() == 0xdeadbeef), /* winnt */
1555 "wrong error %u\n", GetLastError());
1556 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1558 memset(buf, 0xAA, sizeof(buf));
1559 SetLastError(0xdeadbeef);
1560 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1561 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1562 lines, bm.bmHeight, GetLastError());
1563 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1565 /* the color table consists of black and white */
1566 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1567 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1568 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1569 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1570 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1571 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1572 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1573 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1574 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1575 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1576 for (i = 2; i < 256; i++)
1578 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1579 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1580 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1581 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1582 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1585 /* returned bits are DWORD aligned and upside down */
1586 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1588 /* Test the palette indices */
1589 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1590 SetLastError(0xdeadbeef);
1591 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1593 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1594 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1595 for (i = 2; i < 256; i++)
1596 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1598 /* retrieve 24-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 = 24;
1605 bi->bmiHeader.biCompression = BI_RGB;
1606 bi->bmiHeader.biSizeImage = 0;
1607 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1608 memset(buf, 0xAA, sizeof(buf));
1609 SetLastError(0xdeadbeef);
1610 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1611 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1612 lines, bm.bmHeight, GetLastError());
1613 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1615 /* the color table doesn't exist for 24-bit images */
1616 for (i = 0; i < 256; i++)
1618 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1619 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1620 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1621 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1622 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1625 /* returned bits are DWORD aligned and upside down */
1626 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1629 /* 24-bit source bitmap data */
1630 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1631 ok(hbmp != 0, "CreateBitmap failed\n");
1632 SetLastError(0xdeadbeef);
1633 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1634 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1635 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1636 lines, bm.bmHeight, GetLastError());
1638 memset(&bm, 0xAA, sizeof(bm));
1639 bytes = GetObject(hbmp, sizeof(bm), &bm);
1640 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1641 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1642 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1643 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1644 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1645 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1646 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1647 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1649 bytes = GetBitmapBits(hbmp, 0, NULL);
1650 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1651 bm.bmWidthBytes * bm.bmHeight, bytes);
1652 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1653 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1654 bm.bmWidthBytes * bm.bmHeight, bytes);
1656 /* retrieve 1-bit DIB data */
1657 memset(bi, 0, sizeof(*bi));
1658 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1659 bi->bmiHeader.biWidth = bm.bmWidth;
1660 bi->bmiHeader.biHeight = bm.bmHeight;
1661 bi->bmiHeader.biPlanes = 1;
1662 bi->bmiHeader.biBitCount = 1;
1663 bi->bmiHeader.biCompression = BI_RGB;
1664 bi->bmiHeader.biSizeImage = 0;
1665 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1666 memset(buf, 0xAA, sizeof(buf));
1667 SetLastError(0xdeadbeef);
1668 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1669 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1670 lines, bm.bmHeight, GetLastError());
1671 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1673 /* the color table consists of black and white */
1674 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1675 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1676 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1677 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1678 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1679 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1680 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1681 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1682 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1683 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1684 for (i = 2; 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 */
1695 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1697 /* Test the palette indices */
1698 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1699 SetLastError(0xdeadbeef);
1700 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1702 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1703 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1704 for (i = 2; i < 256; i++)
1705 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1707 /* retrieve 24-bit DIB data */
1708 memset(bi, 0, sizeof(*bi));
1709 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1710 bi->bmiHeader.biWidth = bm.bmWidth;
1711 bi->bmiHeader.biHeight = bm.bmHeight;
1712 bi->bmiHeader.biPlanes = 1;
1713 bi->bmiHeader.biBitCount = 24;
1714 bi->bmiHeader.biCompression = BI_RGB;
1715 bi->bmiHeader.biSizeImage = 0;
1716 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1717 memset(buf, 0xAA, sizeof(buf));
1718 SetLastError(0xdeadbeef);
1719 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1720 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1721 lines, bm.bmHeight, GetLastError());
1722 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1724 /* the color table doesn't exist for 24-bit images */
1725 for (i = 0; i < 256; i++)
1727 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1728 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1729 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1730 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1731 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1734 /* returned bits are DWORD aligned and upside down */
1735 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1741 static void test_GetDIBits_BI_BITFIELDS(void)
1743 /* Try a screen resolution detection technique
1744 * from the September 1999 issue of Windows Developer's Journal
1745 * which seems to be in widespread use.
1746 * http://www.lesher.ws/highcolor.html
1747 * http://www.lesher.ws/vidfmt.c
1748 * It hinges on being able to retrieve the bitmaps
1749 * for the three primary colors in non-paletted 16 bit mode.
1751 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1753 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1758 memset(dibinfo, 0, sizeof(dibinfo_buf));
1759 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1762 ok(hdc != NULL, "GetDC failed?\n");
1763 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1764 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1766 /* Call GetDIBits to fill in bmiHeader. */
1767 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1768 ok(ret == 1, "GetDIBits failed\n");
1769 if (dibinfo->bmiHeader.biBitCount > 8)
1771 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1773 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1774 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1776 ok( !bitmasks[0], "red mask is set\n" );
1777 ok( !bitmasks[1], "green mask is set\n" );
1778 ok( !bitmasks[2], "blue mask is set\n" );
1780 /* test with NULL bits pointer and correct bpp */
1781 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1782 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1783 ok(ret == 1, "GetDIBits failed\n");
1785 ok( bitmasks[0] != 0, "red mask is not set\n" );
1786 ok( bitmasks[1] != 0, "green mask is not set\n" );
1787 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1788 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1790 /* test with valid bits pointer */
1791 memset(dibinfo, 0, sizeof(dibinfo_buf));
1792 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1793 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1794 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1795 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1796 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1797 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1799 ok( bitmasks[0] != 0, "red mask is not set\n" );
1800 ok( bitmasks[1] != 0, "green mask is not set\n" );
1801 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1802 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1804 /* now with bits and 0 lines */
1805 memset(dibinfo, 0, sizeof(dibinfo_buf));
1806 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1807 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1808 SetLastError(0xdeadbeef);
1809 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1810 if (ret == 0 && GetLastError() == ERROR_INVALID_PARAMETER)
1811 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1814 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1816 ok( !bitmasks[0], "red mask is set\n" );
1817 ok( !bitmasks[1], "green mask is set\n" );
1818 ok( !bitmasks[2], "blue mask is set\n" );
1819 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1821 memset(bitmasks, 0, 3*sizeof(DWORD));
1822 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1823 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1824 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1826 ok( bitmasks[0] != 0, "red mask is not set\n" );
1827 ok( bitmasks[1] != 0, "green mask is not set\n" );
1828 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1829 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1832 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1835 ReleaseDC(NULL, hdc);
1838 static void test_select_object(void)
1841 HBITMAP hbm, hbm_old;
1843 DWORD depths[] = {8, 15, 16, 24, 32};
1848 ok(hdc != 0, "GetDC(0) failed\n");
1849 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1850 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1852 hbm_old = SelectObject(hdc, hbm);
1853 ok(hbm_old == 0, "SelectObject should fail\n");
1858 hdc = CreateCompatibleDC(0);
1859 ok(hdc != 0, "GetDC(0) failed\n");
1860 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1861 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1863 hbm_old = SelectObject(hdc, hbm);
1864 ok(hbm_old != 0, "SelectObject failed\n");
1865 hbm_old = SelectObject(hdc, hbm_old);
1866 ok(hbm_old == hbm, "SelectObject failed\n");
1870 /* test an 1-bpp bitmap */
1871 planes = GetDeviceCaps(hdc, PLANES);
1874 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
1875 ok(hbm != 0, "CreateBitmap failed\n");
1877 hbm_old = SelectObject(hdc, hbm);
1878 ok(hbm_old != 0, "SelectObject failed\n");
1879 hbm_old = SelectObject(hdc, hbm_old);
1880 ok(hbm_old == hbm, "SelectObject failed\n");
1884 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
1885 /* test a color bitmap to dc bpp matching */
1886 planes = GetDeviceCaps(hdc, PLANES);
1887 bpp = GetDeviceCaps(hdc, BITSPIXEL);
1889 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
1890 ok(hbm != 0, "CreateBitmap failed\n");
1892 hbm_old = SelectObject(hdc, hbm);
1893 if(depths[i] == bpp ||
1894 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
1896 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
1897 SelectObject(hdc, hbm_old);
1899 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
1902 memset(&bm, 0xAA, sizeof(bm));
1903 bytes = GetObject(hbm, sizeof(bm), &bm);
1904 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1905 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1906 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
1907 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
1908 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1909 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
1910 if(depths[i] == 15) {
1911 ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
1913 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1915 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1923 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
1928 ret = GetObjectType(hbmp);
1929 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
1931 ret = GetObject(hbmp, 0, 0);
1932 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
1933 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
1935 memset(&bm, 0xDA, sizeof(bm));
1936 SetLastError(0xdeadbeef);
1937 ret = GetObject(hbmp, sizeof(bm), &bm);
1938 if (!ret) /* XP, only for curObj2 */ return;
1939 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
1940 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
1941 "GetObject returned %d, error %u\n", ret, GetLastError());
1942 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
1943 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
1944 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
1945 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
1946 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
1947 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
1948 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1951 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
1953 static void test_CreateBitmap(void)
1956 HDC screenDC = GetDC(0);
1957 HDC hdc = CreateCompatibleDC(screenDC);
1960 /* all of these are the stock monochrome bitmap */
1961 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
1962 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
1963 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
1964 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
1965 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
1966 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
1968 /* these 2 are not the stock monochrome bitmap */
1969 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
1970 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
1972 HBITMAP old1 = SelectObject(hdc, bm2);
1973 HBITMAP old2 = SelectObject(screenDC, bm3);
1974 SelectObject(hdc, old1);
1975 SelectObject(screenDC, old2);
1977 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
1978 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
1979 bm, bm1, bm4, bm5, curObj1, old1);
1980 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
1982 ok(bm != curObj2 || /* WinXP */
1983 broken(bm == curObj2) /* Win9x */,
1984 "0: %p, curObj2 %p\n", bm, curObj2);
1985 ok(old2 == 0, "old2 %p\n", old2);
1987 test_mono_1x1_bmp(bm);
1988 test_mono_1x1_bmp(bm1);
1989 test_mono_1x1_bmp(bm2);
1990 test_mono_1x1_bmp(bm3);
1991 test_mono_1x1_bmp(bm4);
1992 test_mono_1x1_bmp(bm5);
1993 test_mono_1x1_bmp(old1);
1994 test_mono_1x1_bmp(curObj1);
2004 ReleaseDC(0, screenDC);
2006 /* show that Windows ignores the provided bm.bmWidthBytes */
2010 bmp.bmWidthBytes = 28;
2012 bmp.bmBitsPixel = 1;
2014 bm = CreateBitmapIndirect(&bmp);
2015 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2016 test_mono_1x1_bmp(bm);
2019 /* Test how the bmBitsPixel field is treated */
2020 for(i = 1; i <= 33; i++) {
2024 bmp.bmWidthBytes = 28;
2026 bmp.bmBitsPixel = i;
2028 SetLastError(0xdeadbeef);
2029 bm = CreateBitmapIndirect(&bmp);
2031 DWORD error = GetLastError();
2033 broken(bm != 0), /* Win9x and WinMe */
2034 "CreateBitmapIndirect for %d bpp succeeded\n", i);
2035 ok(error == ERROR_INVALID_PARAMETER ||
2036 broken(error == 0xdeadbeef), /* Win9x and WinME */
2037 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2041 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2042 GetObject(bm, sizeof(bmp), &bmp);
2049 } else if(i <= 16) {
2051 } else if(i <= 24) {
2053 } else if(i <= 32) {
2056 ok(bmp.bmBitsPixel == expect ||
2057 broken(bmp.bmBitsPixel == i), /* Win9x and WinMe */
2058 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2059 i, bmp.bmBitsPixel, expect);
2064 static void test_bitmapinfoheadersize(void)
2071 memset(&bmi, 0, sizeof(BITMAPINFO));
2072 bmi.bmiHeader.biHeight = 100;
2073 bmi.bmiHeader.biWidth = 512;
2074 bmi.bmiHeader.biBitCount = 24;
2075 bmi.bmiHeader.biPlanes = 1;
2077 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2079 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2080 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2082 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2084 SetLastError(0xdeadbeef);
2085 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2086 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2089 bmi.bmiHeader.biSize++;
2091 SetLastError(0xdeadbeef);
2092 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2094 broken(!hdib), /* Win98, WinMe */
2095 "CreateDIBSection error %d\n", GetLastError());
2098 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2100 SetLastError(0xdeadbeef);
2101 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2103 broken(!hdib), /* Win98, WinMe */
2104 "CreateDIBSection error %d\n", GetLastError());
2107 bmi.bmiHeader.biSize++;
2109 SetLastError(0xdeadbeef);
2110 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2112 broken(!hdib), /* Win98, WinMe */
2113 "CreateDIBSection error %d\n", GetLastError());
2116 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2118 SetLastError(0xdeadbeef);
2119 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2120 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2123 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2125 SetLastError(0xdeadbeef);
2126 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2128 broken(!hdib), /* Win95 */
2129 "CreateDIBSection error %d\n", GetLastError());
2132 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2133 bci.bmciHeader.bcHeight = 100;
2134 bci.bmciHeader.bcWidth = 512;
2135 bci.bmciHeader.bcBitCount = 24;
2136 bci.bmciHeader.bcPlanes = 1;
2138 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2140 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2141 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2143 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2145 SetLastError(0xdeadbeef);
2146 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2147 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2150 bci.bmciHeader.bcSize++;
2152 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2153 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2155 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2157 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2158 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2163 static void test_get16dibits(void)
2165 BYTE bits[4 * (16 / sizeof(BYTE))];
2167 HDC screen_dc = GetDC(NULL);
2170 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2172 int overwritten_bytes = 0;
2174 memset(bits, 0, sizeof(bits));
2175 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2176 ok(hbmp != NULL, "CreateBitmap failed\n");
2178 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2181 memset(info, '!', info_len);
2182 memset(info, 0, sizeof(info->bmiHeader));
2184 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2185 info->bmiHeader.biWidth = 2;
2186 info->bmiHeader.biHeight = 2;
2187 info->bmiHeader.biPlanes = 1;
2188 info->bmiHeader.biCompression = BI_RGB;
2190 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2191 ok(ret != 0, "GetDIBits failed got %d\n", ret);
2193 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2195 overwritten_bytes++;
2196 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2198 HeapFree(GetProcessHeap(), 0, info);
2200 ReleaseDC(NULL, screen_dc);
2203 static void test_GdiAlphaBlend(void)
2205 /* test out-of-bound parameters for GdiAlphaBlend */
2218 BLENDFUNCTION blend;
2220 if (!pGdiAlphaBlend)
2222 win_skip("GdiAlphaBlend() is not implemented\n");
2226 hdcNull = GetDC(NULL);
2227 hdcDst = CreateCompatibleDC(hdcNull);
2228 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2229 hdcSrc = CreateCompatibleDC(hdcNull);
2231 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2232 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2233 bmi.bmiHeader.biHeight = 20;
2234 bmi.bmiHeader.biWidth = 20;
2235 bmi.bmiHeader.biBitCount = 32;
2236 bmi.bmiHeader.biPlanes = 1;
2237 bmi.bmiHeader.biCompression = BI_RGB;
2238 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2239 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2241 oldDst = SelectObject(hdcDst, bmpDst);
2242 oldSrc = SelectObject(hdcSrc, bmpSrc);
2244 blend.BlendOp = AC_SRC_OVER;
2245 blend.BlendFlags = 0;
2246 blend.SourceConstantAlpha = 128;
2247 blend.AlphaFormat = 0;
2249 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2250 SetLastError(0xdeadbeef);
2251 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2252 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2253 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2254 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2255 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2256 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2258 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2259 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2260 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2261 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2262 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2263 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2264 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2266 SelectObject(hdcDst, oldDst);
2267 SelectObject(hdcSrc, oldSrc);
2268 DeleteObject(bmpSrc);
2269 DeleteObject(bmpDst);
2273 ReleaseDC(NULL, hdcNull);
2277 static void test_clipping(void)
2287 HDC hdcDst = CreateCompatibleDC( NULL );
2288 HDC hdcSrc = CreateCompatibleDC( NULL );
2290 BITMAPINFO bmpinfo={{0}};
2291 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2292 bmpinfo.bmiHeader.biWidth = 100;
2293 bmpinfo.bmiHeader.biHeight = 100;
2294 bmpinfo.bmiHeader.biPlanes = 1;
2295 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2296 bmpinfo.bmiHeader.biCompression = BI_RGB;
2298 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2299 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2300 oldDst = SelectObject( hdcDst, bmpDst );
2302 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2303 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2304 oldSrc = SelectObject( hdcSrc, bmpSrc );
2306 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2307 ok(result, "BitBlt failed\n");
2309 hRgn = CreateRectRgn( 0,0,0,0 );
2310 SelectClipRgn( hdcDst, hRgn );
2312 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2313 ok(result, "BitBlt failed\n");
2315 DeleteObject( bmpDst );
2316 DeleteObject( bmpSrc );
2317 DeleteObject( hRgn );
2325 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
2327 hdll = GetModuleHandle("gdi32.dll");
2328 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
2330 test_createdibitmap();
2332 test_mono_dibsection();
2335 test_GetDIBits_selected_DIB(1);
2336 test_GetDIBits_selected_DIB(4);
2337 test_GetDIBits_selected_DIB(8);
2338 test_GetDIBits_selected_DDB(TRUE);
2339 test_GetDIBits_selected_DDB(FALSE);
2341 test_GetDIBits_BI_BITFIELDS();
2342 test_select_object();
2343 test_CreateBitmap();
2344 test_GdiAlphaBlend();
2345 test_bitmapinfoheadersize();