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); }
39 static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
44 return 2 * ((bmWidth+15) >> 4);
47 bmWidth *= 3; /* fall through */
49 return bmWidth + (bmWidth & 1);
59 return 2 * ((bmWidth+3) >> 2);
62 trace("Unknown depth %d, please report.\n", bpp );
68 static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
73 BYTE buf[512], buf_cmp[512];
75 ret = GetObject(hbm, sizeof(bm), &bm);
76 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
78 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
79 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
80 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
81 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
82 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
83 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
84 ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
85 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
87 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
88 assert(sizeof(buf) == sizeof(buf_cmp));
90 SetLastError(0xdeadbeef);
91 ret = GetBitmapBits(hbm, 0, NULL);
92 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
94 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
95 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
97 memset(buf, 0xAA, sizeof(buf));
98 ret = GetBitmapBits(hbm, sizeof(buf), buf);
99 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
100 ok(!memcmp(buf, buf_cmp, sizeof(buf)),
101 "buffers do not match, depth %d\n", bmih->biBitCount);
103 /* test various buffer sizes for GetObject */
104 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
105 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
107 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
108 ok(ret == 0, "%d != 0\n", ret);
110 ret = GetObject(hbm, 0, &bm);
111 ok(ret == 0, "%d != 0\n", ret);
113 ret = GetObject(hbm, 1, &bm);
114 ok(ret == 0, "%d != 0\n", ret);
116 ret = GetObject(hbm, 0, NULL);
117 ok(ret == sizeof(bm), "wrong size %d\n", ret);
120 static void test_createdibitmap(void)
123 BITMAPINFOHEADER bmih;
125 HBITMAP hbm, hbm_colour, hbm_old;
130 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
131 memset(&bmih, 0, sizeof(bmih));
132 bmih.biSize = sizeof(bmih);
136 bmih.biBitCount = 32;
137 bmih.biCompression = BI_RGB;
139 hbm = CreateDIBitmap(hdc, NULL, CBM_INIT, NULL, NULL, 0);
140 ok(hbm == NULL, "CreateDIBitmap should fail\n");
141 hbm = CreateDIBitmap(hdc, NULL, 0, NULL, NULL, 0);
142 ok(hbm == NULL, "CreateDIBitmap should fail\n");
144 /* First create an un-initialised bitmap. The depth of the bitmap
145 should match that of the hdc and not that supplied in bmih.
148 /* First try 32 bits */
149 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
150 ok(hbm != NULL, "CreateDIBitmap failed\n");
151 test_bitmap_info(hbm, screen_depth, &bmih);
155 bmih.biBitCount = 16;
156 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
157 ok(hbm != NULL, "CreateDIBitmap failed\n");
158 test_bitmap_info(hbm, screen_depth, &bmih);
163 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
164 ok(hbm != NULL, "CreateDIBitmap failed\n");
165 test_bitmap_info(hbm, screen_depth, &bmih);
168 /* Now with a monochrome dc we expect a monochrome bitmap */
169 hdcmem = CreateCompatibleDC(hdc);
171 /* First try 32 bits */
172 bmih.biBitCount = 32;
173 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
174 ok(hbm != NULL, "CreateDIBitmap failed\n");
175 test_bitmap_info(hbm, 1, &bmih);
179 bmih.biBitCount = 16;
180 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
181 ok(hbm != NULL, "CreateDIBitmap failed\n");
182 test_bitmap_info(hbm, 1, &bmih);
187 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
188 ok(hbm != NULL, "CreateDIBitmap failed\n");
189 test_bitmap_info(hbm, 1, &bmih);
192 /* Now select a polychrome bitmap into the dc and we expect
193 screen_depth bitmaps again */
194 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
195 test_bitmap_info(hbm_colour, screen_depth, &bmih);
196 hbm_old = SelectObject(hdcmem, hbm_colour);
198 /* First try 32 bits */
199 bmih.biBitCount = 32;
200 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
201 ok(hbm != NULL, "CreateDIBitmap failed\n");
202 test_bitmap_info(hbm, screen_depth, &bmih);
206 bmih.biBitCount = 16;
207 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
208 ok(hbm != NULL, "CreateDIBitmap failed\n");
209 test_bitmap_info(hbm, screen_depth, &bmih);
214 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
215 ok(hbm != NULL, "CreateDIBitmap failed\n");
216 test_bitmap_info(hbm, screen_depth, &bmih);
219 SelectObject(hdcmem, hbm_old);
220 DeleteObject(hbm_colour);
223 bmih.biBitCount = 32;
224 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
225 ok(hbm != NULL, "CreateDIBitmap failed\n");
226 test_bitmap_info(hbm, 1, &bmih);
229 /* Test how formats are converted */
235 memset(&bm, 0, sizeof(bm));
236 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
237 bm.bmiHeader.biWidth = 1;
238 bm.bmiHeader.biHeight = 1;
239 bm.bmiHeader.biPlanes = 1;
240 bm.bmiHeader.biBitCount= 24;
241 bm.bmiHeader.biCompression= BI_RGB;
242 bm.bmiHeader.biSizeImage = 0;
243 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
244 ok(hbm != NULL, "CreateDIBitmap failed\n");
247 bm.bmiHeader.biBitCount= 32;
248 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
249 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel);
255 static INT DIB_GetWidthBytes( int width, int bpp )
261 case 1: words = (width + 31) / 32; break;
262 case 4: words = (width + 7) / 8; break;
263 case 8: words = (width + 3) / 4; break;
265 case 16: words = (width + 1) / 2; break;
266 case 24: words = (width * 3 + 3)/4; break;
267 case 32: words = width; break;
271 trace("Unknown depth %d, please report.\n", bpp );
278 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
284 INT ret, bm_width_bytes, dib_width_bytes;
287 ret = GetObject(hbm, sizeof(bm), &bm);
288 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
290 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
291 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
292 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
293 dib_width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
294 bm_width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
295 if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
296 ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
298 ok(bm.bmWidthBytes == dib_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, dib_width_bytes);
299 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
300 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
301 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
303 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
305 /* GetBitmapBits returns not 32-bit aligned data */
306 SetLastError(0xdeadbeef);
307 ret = GetBitmapBits(hbm, 0, NULL);
308 ok(ret == bm_width_bytes * bm.bmHeight,
309 "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
311 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
312 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
313 ok(ret == bm_width_bytes * bm.bmHeight, "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
315 HeapFree(GetProcessHeap(), 0, buf);
317 /* test various buffer sizes for GetObject */
318 memset(&ds, 0xAA, sizeof(ds));
319 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
320 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
321 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
322 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
323 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
325 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
326 ok(ret == 0, "%d != 0\n", ret);
328 ret = GetObject(hbm, 0, &bm);
329 ok(ret == 0, "%d != 0\n", ret);
331 ret = GetObject(hbm, 1, &bm);
332 ok(ret == 0, "%d != 0\n", ret);
334 /* test various buffer sizes for GetObject */
335 ret = GetObject(hbm, 0, NULL);
336 ok(ret == sizeof(bm), "wrong size %d\n", ret);
338 ret = GetObject(hbm, sizeof(*dsa) * 2, dsa);
339 ok(ret == sizeof(*dsa), "wrong size %d\n", ret);
341 memset(&ds, 0xAA, sizeof(ds));
342 ret = GetObject(hbm, sizeof(ds), &ds);
343 ok(ret == sizeof(ds), "wrong size %d\n", ret);
345 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
346 if (ds.dsBm.bmWidthBytes != bm_width_bytes) /* Win2k bug */
347 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
348 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
349 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
350 ds.dsBmih.biSizeImage = 0;
352 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
353 ok(ds.dsBmih.biWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
354 ok(ds.dsBmih.biHeight == abs(bmih->biHeight), "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
355 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
356 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
357 ok(ds.dsBmih.biCompression == bmih->biCompression ||
358 ((bmih->biBitCount == 32) && broken(ds.dsBmih.biCompression == BI_BITFIELDS)), /* nt4 sp1 and 2 */
359 "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
360 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
361 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%d != %d\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
362 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%d != %d\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
364 memset(&ds, 0xAA, sizeof(ds));
365 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
366 ok(ret == sizeof(ds.dsBm), "wrong size %d\n", ret);
367 ok(ds.dsBm.bmWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
368 ok(ds.dsBm.bmHeight == abs(bmih->biHeight), "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
369 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
371 ret = GetObject(hbm, 0, &ds);
372 ok(ret == 0, "%d != 0\n", ret);
374 ret = GetObject(hbm, 1, &ds);
375 ok(ret == 0, "%d != 0\n", ret);
378 #define test_color_todo(got, exp, txt, todo) \
379 if (!todo && got != exp && screen_depth < 24) { \
380 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
381 screen_depth, (UINT)got, (UINT)exp); \
383 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
384 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
386 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
389 c = SetPixel(hdc, 0, 0, color); \
390 test_color_todo(c, exp, SetPixel, todo_setp); \
391 c = GetPixel(hdc, 0, 0); \
392 test_color_todo(c, exp, GetPixel, todo_getp); \
395 static void test_dib_bits_access( HBITMAP hdib, void *bits )
397 MEMORY_BASIC_INFORMATION info;
398 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
400 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
402 char filename[MAX_PATH];
407 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
408 "VirtualQuery failed\n");
409 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
410 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
411 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
412 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
413 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
414 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
416 memset( pbmi, 0, sizeof(bmibuf) );
417 memset( data, 0xcc, sizeof(data) );
418 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
419 pbmi->bmiHeader.biHeight = 16;
420 pbmi->bmiHeader.biWidth = 16;
421 pbmi->bmiHeader.biBitCount = 32;
422 pbmi->bmiHeader.biPlanes = 1;
423 pbmi->bmiHeader.biCompression = BI_RGB;
427 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
428 ok(ret == 16, "SetDIBits failed: expected 16 got %d\n", ret);
432 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
433 "VirtualQuery failed\n");
434 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
435 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
436 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
437 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
438 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
439 /* it has been protected now */
440 todo_wine ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
442 /* try writing protected bits to a file */
444 GetTempFileNameA( ".", "dib", 0, filename );
445 file = CreateFileA( filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
446 CREATE_ALWAYS, 0, 0 );
447 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %u\n", filename, GetLastError() );
448 ret = WriteFile( file, bits, 8192, &written, NULL );
449 ok( ret, "WriteFile failed error %u\n", GetLastError() );
450 if (ret) ok( written == 8192, "only wrote %u bytes\n", written );
452 DeleteFileA( filename );
455 static void test_dibsections(void)
457 HDC hdc, hdcmem, hdcmem2;
458 HBITMAP hdib, oldbm, hdib2, oldbm2;
459 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
460 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
461 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
462 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
468 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
469 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
472 HPALETTE hpal, oldpal;
477 MEMORY_BASIC_INFORMATION info;
480 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
482 memset(pbmi, 0, sizeof(bmibuf));
483 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
484 pbmi->bmiHeader.biHeight = 100;
485 pbmi->bmiHeader.biWidth = 512;
486 pbmi->bmiHeader.biBitCount = 24;
487 pbmi->bmiHeader.biPlanes = 1;
488 pbmi->bmiHeader.biCompression = BI_RGB;
490 SetLastError(0xdeadbeef);
492 /* invalid pointer for BITMAPINFO
493 (*bits should be NULL on error) */
494 bits = (BYTE*)0xdeadbeef;
495 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
496 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
498 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
499 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
500 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
501 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
503 /* test the DIB memory */
504 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
505 "VirtualQuery failed\n");
506 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
507 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
508 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
509 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
510 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
511 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
512 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
514 test_dib_bits_access( hdib, bits );
516 test_dib_info(hdib, bits, &pbmi->bmiHeader);
519 /* Test a top-down DIB. */
520 pbmi->bmiHeader.biHeight = -100;
521 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
522 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
523 test_dib_info(hdib, bits, &pbmi->bmiHeader);
526 pbmi->bmiHeader.biHeight = 100;
527 pbmi->bmiHeader.biBitCount = 8;
528 pbmi->bmiHeader.biCompression = BI_RLE8;
529 SetLastError(0xdeadbeef);
530 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
531 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
532 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
534 for (i = 0; i < 128; i++)
536 pbmi->bmiHeader.biBitCount = i;
537 pbmi->bmiHeader.biCompression = BI_RGB;
538 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
539 if (i == 1 || i == 4 || i == 8 || i == 16 || i == 24 || i == 32)
540 ok(hdib != NULL, "CreateDIBSection bpp %u\n", i);
542 ok(hdib == NULL, "CreateDIBSection bpp %u succeeded\n", i);
543 if (hdib) DeleteObject( hdib );
546 pbmi->bmiHeader.biBitCount = 16;
547 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
548 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
549 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
550 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
551 SetLastError(0xdeadbeef);
552 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
553 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
555 /* test the DIB memory */
556 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
557 "VirtualQuery failed\n");
558 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
559 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
560 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
561 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
562 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
563 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
564 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
566 test_dib_info(hdib, bits, &pbmi->bmiHeader);
569 memset(pbmi, 0, sizeof(bmibuf));
570 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
571 pbmi->bmiHeader.biHeight = 16;
572 pbmi->bmiHeader.biWidth = 16;
573 pbmi->bmiHeader.biBitCount = 1;
574 pbmi->bmiHeader.biPlanes = 1;
575 pbmi->bmiHeader.biCompression = BI_RGB;
576 pbmi->bmiColors[0].rgbRed = 0xff;
577 pbmi->bmiColors[0].rgbGreen = 0;
578 pbmi->bmiColors[0].rgbBlue = 0;
579 pbmi->bmiColors[1].rgbRed = 0;
580 pbmi->bmiColors[1].rgbGreen = 0;
581 pbmi->bmiColors[1].rgbBlue = 0xff;
583 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
584 ok(hdib != NULL, "CreateDIBSection failed\n");
585 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
586 ok(dibsec.dsBmih.biClrUsed == 2,
587 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
589 /* Test if the old BITMAPCOREINFO structure is supported */
591 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
592 pbci->bmciHeader.bcBitCount = 0;
594 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
595 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
596 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
597 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
598 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
600 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
601 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
602 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
603 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
604 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
605 "The color table has not been translated to the old BITMAPCOREINFO format\n");
607 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
608 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
610 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
611 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
612 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
613 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
614 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
615 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
616 "The color table has not been translated to the old BITMAPCOREINFO format\n");
618 DeleteObject(hcoredib);
620 hdcmem = CreateCompatibleDC(hdc);
621 oldbm = SelectObject(hdcmem, hdib);
623 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
624 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
625 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
626 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
627 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
628 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
630 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
631 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
633 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
634 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
635 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
636 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
637 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
638 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
639 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
640 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
641 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
642 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
643 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
644 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
645 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
647 SelectObject(hdcmem, oldbm);
650 pbmi->bmiColors[0].rgbRed = 0xff;
651 pbmi->bmiColors[0].rgbGreen = 0xff;
652 pbmi->bmiColors[0].rgbBlue = 0xff;
653 pbmi->bmiColors[1].rgbRed = 0;
654 pbmi->bmiColors[1].rgbGreen = 0;
655 pbmi->bmiColors[1].rgbBlue = 0;
657 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
658 ok(hdib != NULL, "CreateDIBSection failed\n");
660 test_dib_info(hdib, bits, &pbmi->bmiHeader);
662 oldbm = SelectObject(hdcmem, hdib);
664 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
665 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
666 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
667 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
668 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
669 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
671 SelectObject(hdcmem, oldbm);
672 test_dib_info(hdib, bits, &pbmi->bmiHeader);
675 pbmi->bmiHeader.biBitCount = 4;
676 for (i = 0; i < 16; i++) {
677 pbmi->bmiColors[i].rgbRed = i;
678 pbmi->bmiColors[i].rgbGreen = 16-i;
679 pbmi->bmiColors[i].rgbBlue = 0;
681 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
682 ok(hdib != NULL, "CreateDIBSection failed\n");
683 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
684 ok(dibsec.dsBmih.biClrUsed == 16,
685 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
686 test_dib_info(hdib, bits, &pbmi->bmiHeader);
689 pbmi->bmiHeader.biBitCount = 8;
691 for (i = 0; i < 128; i++) {
692 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
693 pbmi->bmiColors[i].rgbGreen = i * 2;
694 pbmi->bmiColors[i].rgbBlue = 0;
695 pbmi->bmiColors[255 - i].rgbRed = 0;
696 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
697 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
699 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
700 ok(hdib != NULL, "CreateDIBSection failed\n");
701 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
702 ok(dibsec.dsBmih.biClrUsed == 256,
703 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
705 oldbm = SelectObject(hdcmem, hdib);
707 for (i = 0; i < 256; i++) {
708 test_color(hdcmem, DIBINDEX(i),
709 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
710 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
711 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
714 SelectObject(hdcmem, oldbm);
715 test_dib_info(hdib, bits, &pbmi->bmiHeader);
718 pbmi->bmiHeader.biBitCount = 1;
720 /* Now create a palette and a palette indexed dib section */
721 memset(plogpal, 0, sizeof(logpalbuf));
722 plogpal->palVersion = 0x300;
723 plogpal->palNumEntries = 2;
724 plogpal->palPalEntry[0].peRed = 0xff;
725 plogpal->palPalEntry[0].peBlue = 0xff;
726 plogpal->palPalEntry[1].peGreen = 0xff;
728 index = (WORD*)pbmi->bmiColors;
731 hpal = CreatePalette(plogpal);
732 ok(hpal != NULL, "CreatePalette failed\n");
733 oldpal = SelectPalette(hdc, hpal, TRUE);
734 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
735 ok(hdib != NULL, "CreateDIBSection failed\n");
736 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
737 ok(dibsec.dsBmih.biClrUsed == 2, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
739 /* The colour table has already been grabbed from the dc, so we select back the
742 SelectPalette(hdc, oldpal, TRUE);
743 oldbm = SelectObject(hdcmem, hdib);
744 oldpal = SelectPalette(hdcmem, hpal, TRUE);
746 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
747 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
748 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
749 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
750 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
751 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
752 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
754 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
755 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
757 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
758 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
759 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
760 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
761 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
762 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
763 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
764 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
765 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
766 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
767 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
768 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
769 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
770 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
771 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
772 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
774 /* Bottom and 2nd row from top green, everything else magenta */
775 bits[0] = bits[1] = 0xff;
776 bits[13 * 4] = bits[13*4 + 1] = 0xff;
778 test_dib_info(hdib, bits, &pbmi->bmiHeader);
780 pbmi->bmiHeader.biBitCount = 32;
782 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
783 ok(hdib2 != NULL, "CreateDIBSection failed\n");
784 hdcmem2 = CreateCompatibleDC(hdc);
785 oldbm2 = SelectObject(hdcmem2, hdib2);
787 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
789 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
790 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32[17]);
792 SelectObject(hdcmem2, oldbm2);
793 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
796 SelectObject(hdcmem, oldbm);
797 SelectPalette(hdcmem, oldpal, TRUE);
802 pbmi->bmiHeader.biBitCount = 8;
804 memset(plogpal, 0, sizeof(logpalbuf));
805 plogpal->palVersion = 0x300;
806 plogpal->palNumEntries = 256;
808 for (i = 0; i < 128; i++) {
809 plogpal->palPalEntry[i].peRed = 255 - i * 2;
810 plogpal->palPalEntry[i].peBlue = i * 2;
811 plogpal->palPalEntry[i].peGreen = 0;
812 plogpal->palPalEntry[255 - i].peRed = 0;
813 plogpal->palPalEntry[255 - i].peGreen = i * 2;
814 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
817 index = (WORD*)pbmi->bmiColors;
818 for (i = 0; i < 256; i++) {
822 hpal = CreatePalette(plogpal);
823 ok(hpal != NULL, "CreatePalette failed\n");
824 oldpal = SelectPalette(hdc, hpal, TRUE);
825 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
826 ok(hdib != NULL, "CreateDIBSection failed\n");
827 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
828 ok(dibsec.dsBmih.biClrUsed == 256, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
830 test_dib_info(hdib, bits, &pbmi->bmiHeader);
832 SelectPalette(hdc, oldpal, TRUE);
833 oldbm = SelectObject(hdcmem, hdib);
834 oldpal = SelectPalette(hdcmem, hpal, TRUE);
836 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
837 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
838 for (i = 0; i < 256; i++) {
839 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
840 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
841 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
842 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
843 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
846 for (i = 0; i < 256; i++) {
847 test_color(hdcmem, DIBINDEX(i),
848 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
849 test_color(hdcmem, PALETTEINDEX(i),
850 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
851 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
852 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
855 SelectPalette(hdcmem, oldpal, TRUE);
856 SelectObject(hdcmem, oldbm);
865 static void test_mono_dibsection(void)
868 HBITMAP old_bm, mono_ds;
869 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
870 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
877 memdc = CreateCompatibleDC(hdc);
879 memset(pbmi, 0, sizeof(bmibuf));
880 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
881 pbmi->bmiHeader.biHeight = 10;
882 pbmi->bmiHeader.biWidth = 10;
883 pbmi->bmiHeader.biBitCount = 1;
884 pbmi->bmiHeader.biPlanes = 1;
885 pbmi->bmiHeader.biCompression = BI_RGB;
886 pbmi->bmiColors[0].rgbRed = 0xff;
887 pbmi->bmiColors[0].rgbGreen = 0xff;
888 pbmi->bmiColors[0].rgbBlue = 0xff;
889 pbmi->bmiColors[1].rgbRed = 0x0;
890 pbmi->bmiColors[1].rgbGreen = 0x0;
891 pbmi->bmiColors[1].rgbBlue = 0x0;
894 * First dib section is 'inverted' ie color[0] is white, color[1] is black
897 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
898 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
899 old_bm = SelectObject(memdc, mono_ds);
901 /* black border, white interior */
902 Rectangle(memdc, 0, 0, 10, 10);
903 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
904 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
906 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
908 memset(bits, 0, sizeof(bits));
911 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
912 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
914 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
916 pbmi->bmiColors[0].rgbRed = 0x0;
917 pbmi->bmiColors[0].rgbGreen = 0x0;
918 pbmi->bmiColors[0].rgbBlue = 0x0;
919 pbmi->bmiColors[1].rgbRed = 0xff;
920 pbmi->bmiColors[1].rgbGreen = 0xff;
921 pbmi->bmiColors[1].rgbBlue = 0xff;
923 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
924 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
926 SelectObject(memdc, old_bm);
927 DeleteObject(mono_ds);
930 * Next dib section is 'normal' ie color[0] is black, color[1] is white
933 pbmi->bmiColors[0].rgbRed = 0x0;
934 pbmi->bmiColors[0].rgbGreen = 0x0;
935 pbmi->bmiColors[0].rgbBlue = 0x0;
936 pbmi->bmiColors[1].rgbRed = 0xff;
937 pbmi->bmiColors[1].rgbGreen = 0xff;
938 pbmi->bmiColors[1].rgbBlue = 0xff;
940 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
941 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
942 old_bm = SelectObject(memdc, mono_ds);
944 /* black border, white interior */
945 Rectangle(memdc, 0, 0, 10, 10);
946 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
947 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
949 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
951 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
952 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
954 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
956 pbmi->bmiColors[0].rgbRed = 0xff;
957 pbmi->bmiColors[0].rgbGreen = 0xff;
958 pbmi->bmiColors[0].rgbBlue = 0xff;
959 pbmi->bmiColors[1].rgbRed = 0x0;
960 pbmi->bmiColors[1].rgbGreen = 0x0;
961 pbmi->bmiColors[1].rgbBlue = 0x0;
963 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
964 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
967 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
970 pbmi->bmiColors[0].rgbRed = 0xff;
971 pbmi->bmiColors[0].rgbGreen = 0xff;
972 pbmi->bmiColors[0].rgbBlue = 0xff;
973 pbmi->bmiColors[1].rgbRed = 0x0;
974 pbmi->bmiColors[1].rgbGreen = 0x0;
975 pbmi->bmiColors[1].rgbBlue = 0x0;
976 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
977 ok(num == 2, "num = %d\n", num);
979 /* black border, white interior */
980 Rectangle(memdc, 0, 0, 10, 10);
981 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
982 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
984 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
986 memset(bits, 0, sizeof(bits));
989 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
990 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
992 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
994 pbmi->bmiColors[0].rgbRed = 0x0;
995 pbmi->bmiColors[0].rgbGreen = 0x0;
996 pbmi->bmiColors[0].rgbBlue = 0x0;
997 pbmi->bmiColors[1].rgbRed = 0xff;
998 pbmi->bmiColors[1].rgbGreen = 0xff;
999 pbmi->bmiColors[1].rgbBlue = 0xff;
1001 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1002 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1004 SelectObject(memdc, old_bm);
1005 DeleteObject(mono_ds);
1008 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1011 pbmi->bmiColors[0].rgbRed = 0xff;
1012 pbmi->bmiColors[0].rgbGreen = 0x0;
1013 pbmi->bmiColors[0].rgbBlue = 0x0;
1014 pbmi->bmiColors[1].rgbRed = 0xfe;
1015 pbmi->bmiColors[1].rgbGreen = 0x0;
1016 pbmi->bmiColors[1].rgbBlue = 0x0;
1018 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1019 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1020 old_bm = SelectObject(memdc, mono_ds);
1022 /* black border, white interior */
1023 Rectangle(memdc, 0, 0, 10, 10);
1024 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1025 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1027 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1029 pbmi->bmiColors[0].rgbRed = 0x0;
1030 pbmi->bmiColors[0].rgbGreen = 0x0;
1031 pbmi->bmiColors[0].rgbBlue = 0x0;
1032 pbmi->bmiColors[1].rgbRed = 0xff;
1033 pbmi->bmiColors[1].rgbGreen = 0xff;
1034 pbmi->bmiColors[1].rgbBlue = 0xff;
1036 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1037 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1039 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1041 pbmi->bmiColors[0].rgbRed = 0xff;
1042 pbmi->bmiColors[0].rgbGreen = 0xff;
1043 pbmi->bmiColors[0].rgbBlue = 0xff;
1044 pbmi->bmiColors[1].rgbRed = 0x0;
1045 pbmi->bmiColors[1].rgbGreen = 0x0;
1046 pbmi->bmiColors[1].rgbBlue = 0x0;
1048 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1049 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1051 SelectObject(memdc, old_bm);
1052 DeleteObject(mono_ds);
1058 static void test_bitmap(void)
1060 char buf[256], buf_cmp[256];
1061 HBITMAP hbmp, hbmp_old;
1067 hdc = CreateCompatibleDC(0);
1070 SetLastError(0xdeadbeef);
1071 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1074 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1075 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1076 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1081 SetLastError(0xdeadbeef);
1082 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1085 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1086 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1087 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1092 SetLastError(0xdeadbeef);
1093 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1094 ok(!hbmp, "CreateBitmap should fail\n");
1096 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1097 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1101 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1102 assert(hbmp != NULL);
1104 ret = GetObject(hbmp, sizeof(bm), &bm);
1105 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1107 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1108 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1109 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1110 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1111 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1112 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1113 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1115 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1116 assert(sizeof(buf) == sizeof(buf_cmp));
1118 ret = GetBitmapBits(hbmp, 0, NULL);
1119 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1121 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1122 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1124 memset(buf, 0xAA, sizeof(buf));
1125 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1126 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1127 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1129 hbmp_old = SelectObject(hdc, hbmp);
1131 ret = GetObject(hbmp, sizeof(bm), &bm);
1132 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1134 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1135 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1136 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1137 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1138 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1139 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1140 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1142 memset(buf, 0xAA, sizeof(buf));
1143 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1144 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1145 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1147 hbmp_old = SelectObject(hdc, hbmp_old);
1148 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1150 /* test various buffer sizes for GetObject */
1151 ret = GetObject(hbmp, sizeof(*bma) * 2, bma);
1152 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
1154 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1155 ok(ret == 0, "%d != 0\n", ret);
1157 ret = GetObject(hbmp, 0, &bm);
1158 ok(ret == 0, "%d != 0\n", ret);
1160 ret = GetObject(hbmp, 1, &bm);
1161 ok(ret == 0, "%d != 0\n", ret);
1167 static void test_bmBits(void)
1173 memset(bits, 0, sizeof(bits));
1174 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1175 ok(hbmp != NULL, "CreateBitmap failed\n");
1177 memset(&bmp, 0xFF, sizeof(bmp));
1178 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1179 "GetObject failed or returned a wrong structure size\n");
1180 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1185 static void test_GetDIBits_selected_DIB(UINT bpp)
1192 UINT dib_size, dib32_size;
1200 /* Create a DIB section with a color table */
1202 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1203 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1207 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1209 /* Choose width and height such that the row length (in bytes)
1210 is a multiple of 4 (makes things easier) */
1211 info->bmiHeader.biWidth = 32;
1212 info->bmiHeader.biHeight = 32;
1213 info->bmiHeader.biPlanes = 1;
1214 info->bmiHeader.biBitCount = bpp;
1215 info->bmiHeader.biCompression = BI_RGB;
1217 for (i=0; i < (1u << bpp); i++)
1219 BYTE c = i * (1 << (8 - bpp));
1220 info->bmiColors[i].rgbRed = c;
1221 info->bmiColors[i].rgbGreen = c;
1222 info->bmiColors[i].rgbBlue = c;
1223 info->bmiColors[i].rgbReserved = 0;
1226 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1228 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1229 dib32_size = 32 * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1231 /* Set the bits of the DIB section */
1232 for (i=0; i < dib_size; i++)
1234 ((BYTE *)bits)[i] = i % 256;
1237 /* Select the DIB into a DC */
1238 dib_dc = CreateCompatibleDC(NULL);
1239 old_bmp = SelectObject(dib_dc, dib);
1240 dc = CreateCompatibleDC(NULL);
1241 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib32_size);
1244 /* Copy the DIB attributes but not the color table */
1245 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1247 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1248 ok(res, "GetDIBits failed\n");
1250 /* Compare the color table and the bits */
1251 equalContents = TRUE;
1252 for (i=0; i < (1u << bpp); i++)
1254 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1255 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1256 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1257 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1259 equalContents = FALSE;
1263 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1265 equalContents = TRUE;
1266 for (i=0; i < dib_size / sizeof(DWORD); i++)
1268 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1270 equalContents = FALSE;
1274 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1276 /* Map into a 32bit-DIB */
1277 info2->bmiHeader.biBitCount = 32;
1278 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1279 ok(res, "GetDIBits failed\n");
1281 /* Check if last pixel was set */
1282 pixel = ((DWORD *)bits2)[info->bmiHeader.biWidth * info->bmiHeader.biHeight - 1];
1283 ok(pixel != 0, "Pixel: 0x%08x\n", pixel);
1285 HeapFree(GetProcessHeap(), 0, bits2);
1288 SelectObject(dib_dc, old_bmp);
1292 HeapFree(GetProcessHeap(), 0, info2);
1293 HeapFree(GetProcessHeap(), 0, info);
1296 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1311 width = height = 16;
1313 /* Create a DDB (device-dependent bitmap) */
1317 ddb = CreateBitmap(width, height, 1, 1, NULL);
1321 HDC screen_dc = GetDC(NULL);
1322 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1323 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1324 ReleaseDC(NULL, screen_dc);
1327 /* Set the pixels */
1328 ddb_dc = CreateCompatibleDC(NULL);
1329 old_bmp = SelectObject(ddb_dc, ddb);
1330 for (i = 0; i < width; i++)
1332 for (j=0; j < height; j++)
1334 BYTE c = (i * width + j) % 256;
1335 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1338 SelectObject(ddb_dc, old_bmp);
1340 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1341 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1345 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1346 info->bmiHeader.biWidth = width;
1347 info->bmiHeader.biHeight = height;
1348 info->bmiHeader.biPlanes = 1;
1349 info->bmiHeader.biBitCount = bpp;
1350 info->bmiHeader.biCompression = BI_RGB;
1352 dc = CreateCompatibleDC(NULL);
1354 /* Fill in biSizeImage */
1355 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1356 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1358 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1359 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1364 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1365 ok(res, "GetDIBits failed\n");
1367 /* Copy the DIB attributes but not the color table */
1368 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1370 /* Select the DDB into another DC */
1371 old_bmp = SelectObject(ddb_dc, ddb);
1374 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1375 ok(res, "GetDIBits failed\n");
1377 /* Compare the color table and the bits */
1380 equalContents = TRUE;
1381 for (i=0; i < (1u << bpp); i++)
1383 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1384 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1385 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1386 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1388 equalContents = FALSE;
1392 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1395 equalContents = TRUE;
1396 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1398 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1400 equalContents = FALSE;
1403 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1405 /* Test the palette */
1406 equalContents = TRUE;
1407 if (info2->bmiHeader.biBitCount <= 8)
1409 WORD *colors = (WORD*)info2->bmiColors;
1411 /* Get the palette indices */
1412 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1413 ok(res, "GetDIBits failed\n");
1415 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1419 equalContents = FALSE;
1425 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1427 HeapFree(GetProcessHeap(), 0, bits2);
1428 HeapFree(GetProcessHeap(), 0, bits);
1431 SelectObject(ddb_dc, old_bmp);
1435 HeapFree(GetProcessHeap(), 0, info2);
1436 HeapFree(GetProcessHeap(), 0, info);
1439 static void test_GetDIBits(void)
1441 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1442 static const BYTE bmp_bits_1[16 * 2] =
1444 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1445 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1446 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1447 0xff,0xff, 0,0, 0xff,0xff, 0,0
1449 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1450 static const BYTE dib_bits_1[16 * 4] =
1452 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1453 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1454 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1455 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1457 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1458 static const BYTE bmp_bits_24[16 * 16*3] =
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,
1472 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1473 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1474 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1475 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1476 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1477 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1478 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1479 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1480 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1481 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1482 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1483 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1484 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1485 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1486 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1487 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1488 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1489 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1490 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1491 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 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1494 static const BYTE dib_bits_24[16 * 16*3] =
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,
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
1532 int i, bytes, lines;
1534 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1535 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1539 /* 1-bit source bitmap data */
1540 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1541 ok(hbmp != 0, "CreateBitmap failed\n");
1543 memset(&bm, 0xAA, sizeof(bm));
1544 bytes = GetObject(hbmp, sizeof(bm), &bm);
1545 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1546 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1547 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1548 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1549 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1550 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1551 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1552 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1554 bytes = GetBitmapBits(hbmp, 0, NULL);
1555 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1556 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1557 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1558 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1560 /* retrieve 1-bit DIB data */
1561 memset(bi, 0, sizeof(*bi));
1562 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1563 bi->bmiHeader.biWidth = bm.bmWidth;
1564 bi->bmiHeader.biHeight = bm.bmHeight;
1565 bi->bmiHeader.biPlanes = 1;
1566 bi->bmiHeader.biBitCount = 1;
1567 bi->bmiHeader.biCompression = BI_RGB;
1568 bi->bmiHeader.biSizeImage = 0;
1569 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1570 SetLastError(0xdeadbeef);
1571 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1572 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1573 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1574 broken(GetLastError() == 0xdeadbeef), /* winnt */
1575 "wrong error %u\n", GetLastError());
1576 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1578 memset(buf, 0xAA, sizeof(buf));
1579 SetLastError(0xdeadbeef);
1580 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1581 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1582 lines, bm.bmHeight, GetLastError());
1583 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1585 /* the color table consists of black and white */
1586 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1587 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1588 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1589 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1590 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1591 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1592 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1593 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1594 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1595 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1596 for (i = 2; i < 256; i++)
1598 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1599 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1600 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1601 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1602 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1605 /* returned bits are DWORD aligned and upside down */
1606 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1608 /* Test the palette indices */
1609 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1610 SetLastError(0xdeadbeef);
1611 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1612 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1613 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1614 for (i = 2; i < 256; i++)
1615 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1617 /* retrieve 24-bit DIB data */
1618 memset(bi, 0, sizeof(*bi));
1619 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1620 bi->bmiHeader.biWidth = bm.bmWidth;
1621 bi->bmiHeader.biHeight = bm.bmHeight;
1622 bi->bmiHeader.biPlanes = 1;
1623 bi->bmiHeader.biBitCount = 24;
1624 bi->bmiHeader.biCompression = BI_RGB;
1625 bi->bmiHeader.biSizeImage = 0;
1626 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1627 memset(buf, 0xAA, sizeof(buf));
1628 SetLastError(0xdeadbeef);
1629 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1630 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1631 lines, bm.bmHeight, GetLastError());
1632 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1634 /* the color table doesn't exist for 24-bit images */
1635 for (i = 0; i < 256; i++)
1637 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1638 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1639 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1640 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1641 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1644 /* returned bits are DWORD aligned and upside down */
1645 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1648 /* 24-bit source bitmap data */
1649 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1650 ok(hbmp != 0, "CreateBitmap failed\n");
1651 SetLastError(0xdeadbeef);
1652 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1653 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1654 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1655 lines, bm.bmHeight, GetLastError());
1657 memset(&bm, 0xAA, sizeof(bm));
1658 bytes = GetObject(hbmp, sizeof(bm), &bm);
1659 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1660 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1661 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1662 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1663 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1664 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1665 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1666 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1668 bytes = GetBitmapBits(hbmp, 0, NULL);
1669 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
1670 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1671 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1672 bm.bmWidthBytes * bm.bmHeight, bytes);
1674 /* retrieve 1-bit DIB data */
1675 memset(bi, 0, sizeof(*bi));
1676 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1677 bi->bmiHeader.biWidth = bm.bmWidth;
1678 bi->bmiHeader.biHeight = bm.bmHeight;
1679 bi->bmiHeader.biPlanes = 1;
1680 bi->bmiHeader.biBitCount = 1;
1681 bi->bmiHeader.biCompression = BI_RGB;
1682 bi->bmiHeader.biSizeImage = 0;
1683 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1684 memset(buf, 0xAA, sizeof(buf));
1685 SetLastError(0xdeadbeef);
1686 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1687 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1688 lines, bm.bmHeight, GetLastError());
1689 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1691 /* the color table consists of black and white */
1692 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1693 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1694 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1695 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1696 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1697 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1698 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1699 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1700 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1701 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1702 for (i = 2; i < 256; i++)
1704 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1705 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1706 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1707 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1708 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1711 /* returned bits are DWORD aligned and upside down */
1713 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1715 /* Test the palette indices */
1716 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1717 SetLastError(0xdeadbeef);
1718 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1719 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1720 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1721 for (i = 2; i < 256; i++)
1722 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1724 /* retrieve 24-bit DIB data */
1725 memset(bi, 0, sizeof(*bi));
1726 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1727 bi->bmiHeader.biWidth = bm.bmWidth;
1728 bi->bmiHeader.biHeight = bm.bmHeight;
1729 bi->bmiHeader.biPlanes = 1;
1730 bi->bmiHeader.biBitCount = 24;
1731 bi->bmiHeader.biCompression = BI_RGB;
1732 bi->bmiHeader.biSizeImage = 0;
1733 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1734 memset(buf, 0xAA, sizeof(buf));
1735 SetLastError(0xdeadbeef);
1736 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1737 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1738 lines, bm.bmHeight, GetLastError());
1739 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1741 /* the color table doesn't exist for 24-bit images */
1742 for (i = 0; i < 256; i++)
1744 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1745 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1746 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1747 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1748 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1751 /* returned bits are DWORD aligned and upside down */
1752 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1758 static void test_GetDIBits_BI_BITFIELDS(void)
1760 /* Try a screen resolution detection technique
1761 * from the September 1999 issue of Windows Developer's Journal
1762 * which seems to be in widespread use.
1763 * http://www.lesher.ws/highcolor.html
1764 * http://www.lesher.ws/vidfmt.c
1765 * It hinges on being able to retrieve the bitmaps
1766 * for the three primary colors in non-paletted 16 bit mode.
1768 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1770 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1771 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1777 memset(dibinfo, 0, sizeof(dibinfo_buf));
1778 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1781 ok(hdc != NULL, "GetDC failed?\n");
1782 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1783 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1785 /* Call GetDIBits to fill in bmiHeader. */
1786 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1787 ok(ret == 1, "GetDIBits failed\n");
1788 if (dibinfo->bmiHeader.biBitCount > 8)
1790 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1791 "compression is %u (%d bpp)\n", dibinfo->bmiHeader.biCompression, dibinfo->bmiHeader.biBitCount );
1793 ok( !bitmasks[0], "red mask is set\n" );
1794 ok( !bitmasks[1], "green mask is set\n" );
1795 ok( !bitmasks[2], "blue mask is set\n" );
1797 /* test with NULL bits pointer and correct bpp */
1798 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1799 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1800 ok(ret == 1, "GetDIBits failed\n");
1802 ok( bitmasks[0] != 0, "red mask is not set\n" );
1803 ok( bitmasks[1] != 0, "green mask is not set\n" );
1804 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1805 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1807 /* test with valid bits pointer */
1808 memset(dibinfo, 0, sizeof(dibinfo_buf));
1809 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1810 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1811 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1812 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1813 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1814 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1816 ok( bitmasks[0] != 0, "red mask is not set\n" );
1817 ok( bitmasks[1] != 0, "green mask is not set\n" );
1818 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1819 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1821 /* now with bits and 0 lines */
1822 memset(dibinfo, 0, sizeof(dibinfo_buf));
1823 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1824 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1825 SetLastError(0xdeadbeef);
1826 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1827 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1829 ok( !bitmasks[0], "red mask is set\n" );
1830 ok( !bitmasks[1], "green mask is set\n" );
1831 ok( !bitmasks[2], "blue mask is set\n" );
1832 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1834 memset(bitmasks, 0, 3*sizeof(DWORD));
1835 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1836 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1837 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1839 ok( bitmasks[0] != 0, "red mask is not set\n" );
1840 ok( bitmasks[1] != 0, "green mask is not set\n" );
1841 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1842 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1844 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1848 /* same thing now with a 32-bpp DIB section */
1850 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1851 dibinfo->bmiHeader.biWidth = 1;
1852 dibinfo->bmiHeader.biHeight = 1;
1853 dibinfo->bmiHeader.biPlanes = 1;
1854 dibinfo->bmiHeader.biBitCount = 32;
1855 dibinfo->bmiHeader.biCompression = BI_RGB;
1856 dibinfo->bmiHeader.biSizeImage = 0;
1857 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1858 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1859 dibinfo->bmiHeader.biClrUsed = 0;
1860 dibinfo->bmiHeader.biClrImportant = 0;
1861 bitmasks[0] = 0x0000ff;
1862 bitmasks[1] = 0x00ff00;
1863 bitmasks[2] = 0xff0000;
1864 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1865 ok( hbm != 0, "failed to create bitmap\n" );
1867 memset(dibinfo, 0, sizeof(dibinfo_buf));
1868 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1869 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1870 ok(ret == 1, "GetDIBits failed\n");
1871 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1873 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1874 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1875 ok( !bitmasks[0], "red mask is set\n" );
1876 ok( !bitmasks[1], "green mask is set\n" );
1877 ok( !bitmasks[2], "blue mask is set\n" );
1879 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1880 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1881 ok(ret == 1, "GetDIBits failed\n");
1882 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1883 ok( bitmasks[0] == 0xff0000, "wrong red mask %08x\n", bitmasks[0] );
1884 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1885 ok( bitmasks[2] == 0x0000ff, "wrong blue mask %08x\n", bitmasks[2] );
1886 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1890 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1891 dibinfo->bmiHeader.biWidth = 1;
1892 dibinfo->bmiHeader.biHeight = 1;
1893 dibinfo->bmiHeader.biPlanes = 1;
1894 dibinfo->bmiHeader.biBitCount = 32;
1895 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
1896 dibinfo->bmiHeader.biSizeImage = 0;
1897 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1898 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1899 dibinfo->bmiHeader.biClrUsed = 0;
1900 dibinfo->bmiHeader.biClrImportant = 0;
1901 bitmasks[0] = 0x0000ff;
1902 bitmasks[1] = 0x00ff00;
1903 bitmasks[2] = 0xff0000;
1904 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1905 ok( hbm != 0, "failed to create bitmap\n" );
1909 memset(dibinfo, 0, sizeof(dibinfo_buf));
1910 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1911 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1912 ok(ret == 1, "GetDIBits failed\n");
1914 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
1915 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1916 ok( !bitmasks[0], "red mask is set\n" );
1917 ok( !bitmasks[1], "green mask is set\n" );
1918 ok( !bitmasks[2], "blue mask is set\n" );
1920 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1921 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1922 ok(ret == 1, "GetDIBits failed\n");
1923 ok( bitmasks[0] == 0x0000ff, "wrong red mask %08x\n", bitmasks[0] );
1924 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1925 ok( bitmasks[2] == 0xff0000, "wrong blue mask %08x\n", bitmasks[2] );
1926 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1931 /* 24-bpp DIB sections don't have bitfields */
1933 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1934 dibinfo->bmiHeader.biWidth = 1;
1935 dibinfo->bmiHeader.biHeight = 1;
1936 dibinfo->bmiHeader.biPlanes = 1;
1937 dibinfo->bmiHeader.biBitCount = 24;
1938 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
1939 dibinfo->bmiHeader.biSizeImage = 0;
1940 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1941 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1942 dibinfo->bmiHeader.biClrUsed = 0;
1943 dibinfo->bmiHeader.biClrImportant = 0;
1944 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1945 ok( hbm == 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
1946 dibinfo->bmiHeader.biCompression = BI_RGB;
1947 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1948 ok( hbm != 0, "failed to create bitmap\n" );
1950 memset(dibinfo, 0, sizeof(dibinfo_buf));
1951 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1952 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1953 ok(ret == 1, "GetDIBits failed\n");
1954 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1956 ok( dibinfo->bmiHeader.biCompression == BI_RGB,
1957 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1958 ok( !bitmasks[0], "red mask is set\n" );
1959 ok( !bitmasks[1], "green mask is set\n" );
1960 ok( !bitmasks[2], "blue mask is set\n" );
1962 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1963 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1964 ok(ret == 1, "GetDIBits failed\n");
1965 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1966 ok( !bitmasks[0], "red mask is set\n" );
1967 ok( !bitmasks[1], "green mask is set\n" );
1968 ok( !bitmasks[2], "blue mask is set\n" );
1969 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1972 ReleaseDC(NULL, hdc);
1975 static void test_select_object(void)
1978 HBITMAP hbm, hbm_old;
1980 DWORD depths[] = {8, 15, 16, 24, 32};
1985 ok(hdc != 0, "GetDC(0) failed\n");
1986 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1987 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1989 hbm_old = SelectObject(hdc, hbm);
1990 ok(hbm_old == 0, "SelectObject should fail\n");
1995 hdc = CreateCompatibleDC(0);
1996 ok(hdc != 0, "GetDC(0) failed\n");
1997 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1998 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2000 hbm_old = SelectObject(hdc, hbm);
2001 ok(hbm_old != 0, "SelectObject failed\n");
2002 hbm_old = SelectObject(hdc, hbm_old);
2003 ok(hbm_old == hbm, "SelectObject failed\n");
2007 /* test an 1-bpp bitmap */
2008 planes = GetDeviceCaps(hdc, PLANES);
2011 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
2012 ok(hbm != 0, "CreateBitmap failed\n");
2014 hbm_old = SelectObject(hdc, hbm);
2015 ok(hbm_old != 0, "SelectObject failed\n");
2016 hbm_old = SelectObject(hdc, hbm_old);
2017 ok(hbm_old == hbm, "SelectObject failed\n");
2021 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
2022 /* test a color bitmap to dc bpp matching */
2023 planes = GetDeviceCaps(hdc, PLANES);
2024 bpp = GetDeviceCaps(hdc, BITSPIXEL);
2026 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
2027 ok(hbm != 0, "CreateBitmap failed\n");
2029 hbm_old = SelectObject(hdc, hbm);
2030 if(depths[i] == bpp ||
2031 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
2033 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
2034 SelectObject(hdc, hbm_old);
2036 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
2039 memset(&bm, 0xAA, sizeof(bm));
2040 bytes = GetObject(hbm, sizeof(bm), &bm);
2041 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2042 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2043 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2044 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2045 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2046 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2047 if(depths[i] == 15) {
2048 ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2050 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2052 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2060 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
2065 ret = GetObjectType(hbmp);
2066 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
2068 ret = GetObject(hbmp, 0, 0);
2069 ok_(__FILE__, line)(ret == sizeof(BITMAP), "object size %d\n", ret);
2071 memset(&bm, 0xDA, sizeof(bm));
2072 SetLastError(0xdeadbeef);
2073 ret = GetObject(hbmp, sizeof(bm), &bm);
2074 if (!ret) /* XP, only for curObj2 */ return;
2075 ok_(__FILE__, line)(ret == sizeof(BITMAP), "GetObject returned %d, error %u\n", ret, GetLastError());
2076 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
2077 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
2078 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
2079 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
2080 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
2081 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
2082 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2085 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2087 static void test_CreateBitmap(void)
2090 HDC screenDC = GetDC(0);
2091 HDC hdc = CreateCompatibleDC(screenDC);
2094 /* all of these are the stock monochrome bitmap */
2095 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
2096 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2097 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2098 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2099 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
2100 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2102 /* these 2 are not the stock monochrome bitmap */
2103 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2104 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2106 HBITMAP old1 = SelectObject(hdc, bm2);
2107 HBITMAP old2 = SelectObject(screenDC, bm3);
2108 SelectObject(hdc, old1);
2109 SelectObject(screenDC, old2);
2111 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2112 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2113 bm, bm1, bm4, bm5, curObj1, old1);
2114 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2116 ok(bm != curObj2, "0: %p, curObj2 %p\n", bm, curObj2);
2117 ok(old2 == 0, "old2 %p\n", old2);
2119 test_mono_1x1_bmp(bm);
2120 test_mono_1x1_bmp(bm1);
2121 test_mono_1x1_bmp(bm2);
2122 test_mono_1x1_bmp(bm3);
2123 test_mono_1x1_bmp(bm4);
2124 test_mono_1x1_bmp(bm5);
2125 test_mono_1x1_bmp(old1);
2126 test_mono_1x1_bmp(curObj1);
2136 ReleaseDC(0, screenDC);
2138 /* show that Windows ignores the provided bm.bmWidthBytes */
2142 bmp.bmWidthBytes = 28;
2144 bmp.bmBitsPixel = 1;
2146 bm = CreateBitmapIndirect(&bmp);
2147 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2148 test_mono_1x1_bmp(bm);
2151 /* Test how the bmBitsPixel field is treated */
2152 for(i = 1; i <= 33; i++) {
2156 bmp.bmWidthBytes = 28;
2158 bmp.bmBitsPixel = i;
2160 SetLastError(0xdeadbeef);
2161 bm = CreateBitmapIndirect(&bmp);
2163 DWORD error = GetLastError();
2164 ok(bm == 0, "CreateBitmapIndirect for %d bpp succeeded\n", i);
2165 ok(error == ERROR_INVALID_PARAMETER, "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2169 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2170 GetObject(bm, sizeof(bmp), &bmp);
2177 } else if(i <= 16) {
2179 } else if(i <= 24) {
2181 } else if(i <= 32) {
2184 ok(bmp.bmBitsPixel == expect, "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2185 i, bmp.bmBitsPixel, expect);
2190 static void test_bitmapinfoheadersize(void)
2197 memset(&bmi, 0, sizeof(BITMAPINFO));
2198 bmi.bmiHeader.biHeight = 100;
2199 bmi.bmiHeader.biWidth = 512;
2200 bmi.bmiHeader.biBitCount = 24;
2201 bmi.bmiHeader.biPlanes = 1;
2203 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2205 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2206 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2208 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2210 SetLastError(0xdeadbeef);
2211 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2212 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2215 bmi.bmiHeader.biSize++;
2217 SetLastError(0xdeadbeef);
2218 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2220 broken(!hdib), /* Win98, WinMe */
2221 "CreateDIBSection error %d\n", GetLastError());
2224 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2226 SetLastError(0xdeadbeef);
2227 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2229 broken(!hdib), /* Win98, WinMe */
2230 "CreateDIBSection error %d\n", GetLastError());
2233 bmi.bmiHeader.biSize++;
2235 SetLastError(0xdeadbeef);
2236 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2238 broken(!hdib), /* Win98, WinMe */
2239 "CreateDIBSection error %d\n", GetLastError());
2242 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2244 SetLastError(0xdeadbeef);
2245 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2246 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2249 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2251 SetLastError(0xdeadbeef);
2252 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2254 broken(!hdib), /* Win95 */
2255 "CreateDIBSection error %d\n", GetLastError());
2258 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2259 bci.bmciHeader.bcHeight = 100;
2260 bci.bmciHeader.bcWidth = 512;
2261 bci.bmciHeader.bcBitCount = 24;
2262 bci.bmciHeader.bcPlanes = 1;
2264 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2266 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2267 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2269 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2271 SetLastError(0xdeadbeef);
2272 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2273 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2276 bci.bmciHeader.bcSize++;
2278 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2279 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2281 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2283 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2284 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2289 static void test_get16dibits(void)
2291 BYTE bits[4 * (16 / sizeof(BYTE))];
2293 HDC screen_dc = GetDC(NULL);
2296 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2298 int overwritten_bytes = 0;
2300 memset(bits, 0, sizeof(bits));
2301 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2302 ok(hbmp != NULL, "CreateBitmap failed\n");
2304 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2307 memset(info, '!', info_len);
2308 memset(info, 0, sizeof(info->bmiHeader));
2310 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2311 info->bmiHeader.biWidth = 2;
2312 info->bmiHeader.biHeight = 2;
2313 info->bmiHeader.biPlanes = 1;
2314 info->bmiHeader.biCompression = BI_RGB;
2316 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2317 ok(ret != 0, "GetDIBits failed got %d\n", ret);
2319 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2321 overwritten_bytes++;
2322 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2324 HeapFree(GetProcessHeap(), 0, info);
2326 ReleaseDC(NULL, screen_dc);
2329 static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2332 for(i = 0; i < length; i++)
2333 if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2338 static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2339 DWORD dwRop, UINT32 expected, int line)
2341 *srcBuffer = 0xFEDCBA98;
2342 *dstBuffer = 0x89ABCDEF;
2343 Rectangle(hdcSrc, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2344 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
2345 ok(expected == *dstBuffer,
2346 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2347 dwRop, expected, *dstBuffer, line);
2350 static void test_BitBlt(void)
2352 HBITMAP bmpDst, bmpSrc;
2353 HBITMAP oldDst, oldSrc;
2354 HDC hdcScreen, hdcDst, hdcSrc;
2355 UINT32 *dstBuffer, *srcBuffer;
2356 HBRUSH hBrush, hOldBrush;
2357 BITMAPINFO bitmapInfo;
2359 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2360 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2361 bitmapInfo.bmiHeader.biWidth = 1;
2362 bitmapInfo.bmiHeader.biHeight = 1;
2363 bitmapInfo.bmiHeader.biPlanes = 1;
2364 bitmapInfo.bmiHeader.biBitCount = 32;
2365 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2366 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2368 hdcScreen = CreateCompatibleDC(0);
2369 hdcDst = CreateCompatibleDC(hdcScreen);
2370 hdcSrc = CreateCompatibleDC(hdcDst);
2372 /* Setup the destination dib section */
2373 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
2375 oldDst = SelectObject(hdcDst, bmpDst);
2377 hBrush = CreateSolidBrush(0x012345678);
2378 hOldBrush = SelectObject(hdcDst, hBrush);
2380 /* Setup the source dib section */
2381 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
2383 oldSrc = SelectObject(hdcSrc, bmpSrc);
2385 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2386 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2387 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2388 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2389 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2390 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2391 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2392 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2393 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2394 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2395 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2396 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2397 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2398 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2399 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2402 SelectObject(hdcSrc, oldSrc);
2403 DeleteObject(bmpSrc);
2406 SelectObject(hdcDst, hOldBrush);
2407 DeleteObject(hBrush);
2408 SelectObject(hdcDst, oldDst);
2409 DeleteObject(bmpDst);
2413 DeleteDC(hdcScreen);
2416 static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2417 DWORD dwRop, UINT32 expected, int line)
2419 *srcBuffer = 0xFEDCBA98;
2420 *dstBuffer = 0x89ABCDEF;
2421 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
2422 ok(expected == *dstBuffer,
2423 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2424 dwRop, expected, *dstBuffer, line);
2427 static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2428 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2429 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2430 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2432 memset(dstBuffer, 0, 16);
2433 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2434 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2435 ok(memcmp(dstBuffer, expected, 16) == 0 ||
2436 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
2437 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2438 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2439 expected[0], expected[1], expected[2], expected[3],
2440 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2441 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2442 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2445 static void test_StretchBlt(void)
2447 HBITMAP bmpDst, bmpSrc;
2448 HBITMAP oldDst, oldSrc;
2449 HDC hdcScreen, hdcDst, hdcSrc;
2450 UINT32 *dstBuffer, *srcBuffer;
2451 HBRUSH hBrush, hOldBrush;
2452 BITMAPINFO biDst, biSrc;
2453 UINT32 expected[4], legacy_expected[4];
2455 memset(&biDst, 0, sizeof(BITMAPINFO));
2456 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2457 biDst.bmiHeader.biWidth = 2;
2458 biDst.bmiHeader.biHeight = -2;
2459 biDst.bmiHeader.biPlanes = 1;
2460 biDst.bmiHeader.biBitCount = 32;
2461 biDst.bmiHeader.biCompression = BI_RGB;
2462 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
2464 hdcScreen = CreateCompatibleDC(0);
2465 hdcDst = CreateCompatibleDC(hdcScreen);
2466 hdcSrc = CreateCompatibleDC(hdcDst);
2469 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2471 oldDst = SelectObject(hdcDst, bmpDst);
2473 bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
2475 oldSrc = SelectObject(hdcSrc, bmpSrc);
2477 hBrush = CreateSolidBrush(0x012345678);
2478 hOldBrush = SelectObject(hdcDst, hBrush);
2480 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2481 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2482 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2483 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2484 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2485 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2486 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2487 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2488 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2489 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2490 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2491 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2492 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2493 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2494 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2496 SelectObject(hdcDst, hOldBrush);
2497 DeleteObject(hBrush);
2499 /* Top-down to top-down tests */
2500 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2501 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2503 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2504 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2505 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2506 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2508 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2509 expected[2] = 0x00000000, expected[3] = 0x00000000;
2510 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2511 0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
2513 expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2514 expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2515 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2516 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2518 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2519 expected[2] = 0x00000000, expected[3] = 0x00000000;
2520 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2521 0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2523 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2524 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2525 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2526 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2528 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2529 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2530 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2531 1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2533 /* This result seems broken. One might expect the following result:
2534 * 0xCAFED00D 0xFEEDFACE
2535 * 0xFEDCBA98 0x76543210
2537 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2538 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2539 legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2540 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2541 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2542 1, 1, -2, -2, 1, 1, -2, -2, expected,
2543 legacy_expected, __LINE__);
2545 expected[0] = 0x00000000, expected[1] = 0x00000000;
2546 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2547 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2548 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2550 SelectObject(hdcDst, oldDst);
2551 DeleteObject(bmpDst);
2553 /* Top-down to bottom-up tests */
2554 biDst.bmiHeader.biHeight = 2;
2555 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2557 oldDst = SelectObject(hdcDst, bmpDst);
2559 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2560 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2561 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2562 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2564 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2565 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2566 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2567 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2569 SelectObject(hdcSrc, oldSrc);
2570 DeleteObject(bmpSrc);
2572 /* Bottom-up to bottom-up tests */
2573 biSrc.bmiHeader.biHeight = 2;
2574 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2576 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2577 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2578 oldSrc = SelectObject(hdcSrc, bmpSrc);
2580 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2581 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2582 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2583 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2585 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2586 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2587 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2588 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2590 SelectObject(hdcDst, oldDst);
2591 DeleteObject(bmpDst);
2593 /* Bottom-up to top-down tests */
2594 biDst.bmiHeader.biHeight = -2;
2595 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2597 oldDst = SelectObject(hdcDst, bmpDst);
2599 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2600 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2601 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2602 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2604 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2605 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2606 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2607 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2610 SelectObject(hdcSrc, oldSrc);
2611 DeleteObject(bmpSrc);
2614 SelectObject(hdcDst, oldDst);
2615 DeleteObject(bmpDst);
2618 DeleteDC(hdcScreen);
2621 static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2622 DWORD dwRop, UINT32 expected, int line)
2624 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
2625 BITMAPINFO bitmapInfo;
2627 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2628 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2629 bitmapInfo.bmiHeader.biWidth = 2;
2630 bitmapInfo.bmiHeader.biHeight = 1;
2631 bitmapInfo.bmiHeader.biPlanes = 1;
2632 bitmapInfo.bmiHeader.biBitCount = 32;
2633 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2634 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
2636 *dstBuffer = 0x89ABCDEF;
2638 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
2639 ok(expected == *dstBuffer,
2640 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2641 dwRop, expected, *dstBuffer, line);
2644 static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2645 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2646 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2647 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2649 BITMAPINFO bitmapInfo;
2651 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2652 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2653 bitmapInfo.bmiHeader.biWidth = 2;
2654 bitmapInfo.bmiHeader.biHeight = -2;
2655 bitmapInfo.bmiHeader.biPlanes = 1;
2656 bitmapInfo.bmiHeader.biBitCount = 32;
2657 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2659 memset(dstBuffer, 0, 16);
2660 StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2661 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2662 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
2663 ok(memcmp(dstBuffer, expected, 16) == 0,
2664 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2665 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2666 expected[0], expected[1], expected[2], expected[3],
2667 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2668 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2669 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2672 static void test_StretchDIBits(void)
2676 HDC hdcScreen, hdcDst;
2677 UINT32 *dstBuffer, srcBuffer[4];
2678 HBRUSH hBrush, hOldBrush;
2680 UINT32 expected[4], legacy_expected[4];
2682 memset(&biDst, 0, sizeof(BITMAPINFO));
2683 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2684 biDst.bmiHeader.biWidth = 2;
2685 biDst.bmiHeader.biHeight = -2;
2686 biDst.bmiHeader.biPlanes = 1;
2687 biDst.bmiHeader.biBitCount = 32;
2688 biDst.bmiHeader.biCompression = BI_RGB;
2690 hdcScreen = CreateCompatibleDC(0);
2691 hdcDst = CreateCompatibleDC(hdcScreen);
2694 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2696 oldDst = SelectObject(hdcDst, bmpDst);
2698 hBrush = CreateSolidBrush(0x012345678);
2699 hOldBrush = SelectObject(hdcDst, hBrush);
2701 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2702 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2703 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2704 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2705 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2706 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2707 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2708 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2709 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2710 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2711 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2712 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2713 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2714 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2715 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2717 SelectObject(hdcDst, hOldBrush);
2718 DeleteObject(hBrush);
2720 /* Top-down destination tests */
2721 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2722 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2724 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2725 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2726 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2727 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2729 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2730 expected[2] = 0x00000000, expected[3] = 0x00000000;
2731 legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
2732 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2733 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2734 0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
2736 expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
2737 expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
2738 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2739 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2741 expected[0] = 0x42441000, expected[1] = 0x00000000;
2742 expected[2] = 0x00000000, expected[3] = 0x00000000;
2743 legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
2744 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2745 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2746 0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
2748 expected[0] = 0x00000000, expected[1] = 0x00000000;
2749 expected[2] = 0x00000000, expected[3] = 0x00000000;
2750 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2751 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2753 expected[0] = 0x00000000, expected[1] = 0x00000000;
2754 expected[2] = 0x00000000, expected[3] = 0x00000000;
2755 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2756 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2758 expected[0] = 0x00000000, expected[1] = 0x00000000;
2759 expected[2] = 0x00000000, expected[3] = 0x00000000;
2760 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2761 1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
2763 expected[0] = 0x00000000, expected[1] = 0x00000000;
2764 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2765 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2766 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2768 SelectObject(hdcDst, oldDst);
2769 DeleteObject(bmpDst);
2771 /* Bottom up destination tests */
2772 biDst.bmiHeader.biHeight = 2;
2773 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2775 oldDst = SelectObject(hdcDst, bmpDst);
2777 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2778 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2779 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2780 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2783 SelectObject(hdcDst, oldDst);
2784 DeleteObject(bmpDst);
2787 DeleteDC(hdcScreen);
2790 static void test_GdiAlphaBlend(void)
2792 /* test out-of-bound parameters for GdiAlphaBlend */
2805 BLENDFUNCTION blend;
2807 if (!pGdiAlphaBlend)
2809 win_skip("GdiAlphaBlend() is not implemented\n");
2813 hdcNull = GetDC(NULL);
2814 hdcDst = CreateCompatibleDC(hdcNull);
2815 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2816 hdcSrc = CreateCompatibleDC(hdcNull);
2818 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2819 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2820 bmi.bmiHeader.biHeight = 20;
2821 bmi.bmiHeader.biWidth = 20;
2822 bmi.bmiHeader.biBitCount = 32;
2823 bmi.bmiHeader.biPlanes = 1;
2824 bmi.bmiHeader.biCompression = BI_RGB;
2825 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2826 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2828 oldDst = SelectObject(hdcDst, bmpDst);
2829 oldSrc = SelectObject(hdcSrc, bmpSrc);
2831 blend.BlendOp = AC_SRC_OVER;
2832 blend.BlendFlags = 0;
2833 blend.SourceConstantAlpha = 128;
2834 blend.AlphaFormat = 0;
2836 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2837 SetLastError(0xdeadbeef);
2838 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2839 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2840 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2841 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2842 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2843 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2845 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2846 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2847 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2848 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2849 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2850 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2851 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2853 SetLastError(0xdeadbeef);
2854 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
2855 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2857 SelectObject(hdcDst, oldDst);
2858 SelectObject(hdcSrc, oldSrc);
2859 DeleteObject(bmpSrc);
2860 DeleteObject(bmpDst);
2864 ReleaseDC(NULL, hdcNull);
2868 static void test_clipping(void)
2876 HDC hdcDst = CreateCompatibleDC( NULL );
2877 HDC hdcSrc = CreateCompatibleDC( NULL );
2879 BITMAPINFO bmpinfo={{0}};
2880 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2881 bmpinfo.bmiHeader.biWidth = 100;
2882 bmpinfo.bmiHeader.biHeight = 100;
2883 bmpinfo.bmiHeader.biPlanes = 1;
2884 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2885 bmpinfo.bmiHeader.biCompression = BI_RGB;
2887 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2888 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2889 SelectObject( hdcDst, bmpDst );
2891 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2892 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2893 SelectObject( hdcSrc, bmpSrc );
2895 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2896 ok(result, "BitBlt failed\n");
2898 hRgn = CreateRectRgn( 0,0,0,0 );
2899 SelectClipRgn( hdcDst, hRgn );
2901 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2902 ok(result, "BitBlt failed\n");
2904 DeleteObject( bmpDst );
2905 DeleteObject( bmpSrc );
2906 DeleteObject( hRgn );
2911 static void test_32bit_bitmap_blt(void)
2914 HBITMAP bmpSrc, bmpDst;
2915 HBITMAP oldSrc, oldDst;
2916 HDC hdcSrc, hdcDst, hdcScreen;
2918 DWORD colorSrc = 0x11223344;
2920 memset(&biDst, 0, sizeof(BITMAPINFO));
2921 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2922 biDst.bmiHeader.biWidth = 2;
2923 biDst.bmiHeader.biHeight = -2;
2924 biDst.bmiHeader.biPlanes = 1;
2925 biDst.bmiHeader.biBitCount = 32;
2926 biDst.bmiHeader.biCompression = BI_RGB;
2928 hdcScreen = CreateCompatibleDC(0);
2929 if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
2931 DeleteDC(hdcScreen);
2932 trace("Skipping 32-bit DDB test\n");
2936 hdcSrc = CreateCompatibleDC(hdcScreen);
2937 bmpSrc = CreateBitmap(1, 1, 1, 32, &colorSrc);
2938 oldSrc = SelectObject(hdcSrc, bmpSrc);
2940 hdcDst = CreateCompatibleDC(hdcScreen);
2941 bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
2942 oldDst = SelectObject(hdcDst, bmpDst);
2944 StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
2945 ok(dstBuffer[0] == colorSrc, "Expected color=%x, received color=%x\n", colorSrc, dstBuffer[0]);
2948 SelectObject(hdcDst, oldDst);
2949 DeleteObject(bmpDst);
2952 SelectObject(hdcSrc, oldSrc);
2953 DeleteObject(bmpSrc);
2956 DeleteDC(hdcScreen);
2960 * Used by test_GetDIBits_top_down to create the bitmap to test against.
2962 static void setup_picture(char *picture, int bpp)
2970 /*Set the first byte in each pixel to the index of that pixel.*/
2971 for (i = 0; i < 4; i++)
2972 picture[i * (bpp / 8)] = i;
2977 /*Each scanline in a bitmap must be a multiple of 4 bytes long.*/
2984 static void test_GetDIBits_top_down(int bpp)
2987 HBITMAP bmptb, bmpbt;
2993 bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
2994 bi.bmiHeader.biWidth=2;
2995 bi.bmiHeader.biHeight=2;
2996 bi.bmiHeader.biPlanes=1;
2997 bi.bmiHeader.biBitCount=bpp;
2998 bi.bmiHeader.biCompression=BI_RGB;
3000 /*Get the device context for the screen.*/
3002 ok(hdc != NULL, "Could not get a handle to a device context.\n");
3004 /*Create the bottom to top image (image's bottom scan line is at the top in memory).*/
3005 bmpbt = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
3006 ok(bmpbt != NULL, "Could not create a DIB section.\n");
3007 /*Now that we have a pointer to the pixels, we write to them.*/
3008 setup_picture((char*)picture, bpp);
3009 /*Create the top to bottom image (images' bottom scan line is at the bottom in memory).*/
3010 bi.bmiHeader.biHeight=-2; /*We specify that we want a top to bottom image by specifying a negative height.*/
3011 bmptb = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
3012 ok(bmptb != NULL, "Could not create a DIB section.\n");
3013 /*Write to this top to bottom bitmap.*/
3014 setup_picture((char*)picture, bpp);
3016 bi.bmiHeader.biWidth = 1;
3018 bi.bmiHeader.biHeight = 2;
3019 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3020 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3021 /*Check the first byte of the pixel.*/
3022 ok((char)pictureOut[0] == 0, "Bottom-up -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3023 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3024 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3025 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3026 /*Check second scanline.*/
3027 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3028 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3029 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3030 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3031 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3032 ok((char)pictureOut[0] == 2, "Bottom-up -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3033 /*Check both scanlines.*/
3034 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3035 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3036 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3037 ok((char)pictureOut[1] == 0, "Top-down -> bottom-up: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3038 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3039 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3040 ok((char)pictureOut[0] == 0, "Bottom up -> bottom-up: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3041 ok((char)pictureOut[1] == 2, "Bottom up -> bottom-up: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3043 /*Make destination bitmap top-down.*/
3044 bi.bmiHeader.biHeight = -2;
3045 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3046 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3047 ok((char)pictureOut[0] == 0, "Bottom-up -> top-down: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3048 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3049 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3050 ok((char)pictureOut[0] == 2, "Top-down -> top-down: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3051 /*Check second scanline.*/
3052 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3053 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3054 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3055 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3056 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3057 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3058 /*Check both scanlines.*/
3059 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3060 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3061 ok((char)pictureOut[0] == 0, "Top-down -> top-down: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3062 ok((char)pictureOut[1] == 2, "Top-down -> top-down: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3063 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3064 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3065 ok((char)pictureOut[0] == 2, "Bottom up -> top-down: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3066 ok((char)pictureOut[1] == 0, "Bottom up -> top-down: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3068 DeleteObject(bmpbt);
3069 DeleteObject(bmptb);
3076 hdll = GetModuleHandle("gdi32.dll");
3077 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
3079 test_createdibitmap();
3081 test_mono_dibsection();
3084 test_GetDIBits_selected_DIB(1);
3085 test_GetDIBits_selected_DIB(4);
3086 test_GetDIBits_selected_DIB(8);
3087 test_GetDIBits_selected_DDB(TRUE);
3088 test_GetDIBits_selected_DDB(FALSE);
3090 test_GetDIBits_BI_BITFIELDS();
3091 test_select_object();
3092 test_CreateBitmap();
3095 test_StretchDIBits();
3096 test_GdiAlphaBlend();
3097 test_32bit_bitmap_blt();
3098 test_bitmapinfoheadersize();
3101 test_GetDIBits_top_down(16);
3102 test_GetDIBits_top_down(24);
3103 test_GetDIBits_top_down(32);