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);
36 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
38 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
40 static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
45 return 2 * ((bmWidth+15) >> 4);
48 bmWidth *= 3; /* fall through */
50 return bmWidth + (bmWidth & 1);
60 return 2 * ((bmWidth+3) >> 2);
63 trace("Unknown depth %d, please report.\n", bpp );
69 static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
74 BYTE buf[512], buf_cmp[512];
76 ret = GetObject(hbm, sizeof(bm), &bm);
77 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
79 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
80 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
81 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
82 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
83 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
84 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
85 ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
86 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
88 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
89 assert(sizeof(buf) == sizeof(buf_cmp));
91 SetLastError(0xdeadbeef);
92 ret = GetBitmapBits(hbm, 0, NULL);
93 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
95 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
96 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
98 memset(buf, 0xAA, sizeof(buf));
99 ret = GetBitmapBits(hbm, sizeof(buf), buf);
100 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
101 ok(!memcmp(buf, buf_cmp, sizeof(buf)),
102 "buffers do not match, depth %d\n", bmih->biBitCount);
104 /* test various buffer sizes for GetObject */
105 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
106 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
108 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
109 ok(ret == 0, "%d != 0\n", ret);
111 ret = GetObject(hbm, 0, &bm);
112 ok(ret == 0, "%d != 0\n", ret);
114 ret = GetObject(hbm, 1, &bm);
115 ok(ret == 0, "%d != 0\n", ret);
117 ret = GetObject(hbm, 0, NULL);
118 ok(ret == sizeof(bm), "wrong size %d\n", ret);
121 static void test_createdibitmap(void)
124 BITMAPINFOHEADER bmih;
126 HBITMAP hbm, hbm_colour, hbm_old;
131 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
132 memset(&bmih, 0, sizeof(bmih));
133 bmih.biSize = sizeof(bmih);
137 bmih.biBitCount = 32;
138 bmih.biCompression = BI_RGB;
140 hbm = CreateDIBitmap(hdc, NULL, CBM_INIT, NULL, NULL, 0);
141 ok(hbm == NULL, "CreateDIBitmap should fail\n");
142 hbm = CreateDIBitmap(hdc, NULL, 0, NULL, NULL, 0);
143 ok(hbm == NULL, "CreateDIBitmap should fail\n");
145 /* First create an un-initialised bitmap. The depth of the bitmap
146 should match that of the hdc and not that supplied in bmih.
149 /* First try 32 bits */
150 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
151 ok(hbm != NULL, "CreateDIBitmap failed\n");
152 test_bitmap_info(hbm, screen_depth, &bmih);
156 bmih.biBitCount = 16;
157 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
158 ok(hbm != NULL, "CreateDIBitmap failed\n");
159 test_bitmap_info(hbm, screen_depth, &bmih);
164 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
165 ok(hbm != NULL, "CreateDIBitmap failed\n");
166 test_bitmap_info(hbm, screen_depth, &bmih);
169 /* Now with a monochrome dc we expect a monochrome bitmap */
170 hdcmem = CreateCompatibleDC(hdc);
172 /* First try 32 bits */
173 bmih.biBitCount = 32;
174 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
175 ok(hbm != NULL, "CreateDIBitmap failed\n");
176 test_bitmap_info(hbm, 1, &bmih);
180 bmih.biBitCount = 16;
181 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
182 ok(hbm != NULL, "CreateDIBitmap failed\n");
183 test_bitmap_info(hbm, 1, &bmih);
188 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
189 ok(hbm != NULL, "CreateDIBitmap failed\n");
190 test_bitmap_info(hbm, 1, &bmih);
193 /* Now select a polychrome bitmap into the dc and we expect
194 screen_depth bitmaps again */
195 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
196 test_bitmap_info(hbm_colour, screen_depth, &bmih);
197 hbm_old = SelectObject(hdcmem, hbm_colour);
199 /* First try 32 bits */
200 bmih.biBitCount = 32;
201 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
202 ok(hbm != NULL, "CreateDIBitmap failed\n");
203 test_bitmap_info(hbm, screen_depth, &bmih);
207 bmih.biBitCount = 16;
208 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
209 ok(hbm != NULL, "CreateDIBitmap failed\n");
210 test_bitmap_info(hbm, screen_depth, &bmih);
215 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
216 ok(hbm != NULL, "CreateDIBitmap failed\n");
217 test_bitmap_info(hbm, screen_depth, &bmih);
220 SelectObject(hdcmem, hbm_old);
221 DeleteObject(hbm_colour);
224 bmih.biBitCount = 32;
225 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
226 ok(hbm != NULL, "CreateDIBitmap failed\n");
227 test_bitmap_info(hbm, 1, &bmih);
230 /* Test how formats are converted */
236 memset(&bm, 0, sizeof(bm));
237 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
238 bm.bmiHeader.biWidth = 1;
239 bm.bmiHeader.biHeight = 1;
240 bm.bmiHeader.biPlanes = 1;
241 bm.bmiHeader.biBitCount= 24;
242 bm.bmiHeader.biCompression= BI_RGB;
243 bm.bmiHeader.biSizeImage = 0;
244 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
245 ok(hbm != NULL, "CreateDIBitmap failed\n");
248 bm.bmiHeader.biBitCount= 32;
249 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
250 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel);
256 static INT DIB_GetWidthBytes( int width, int bpp )
262 case 1: words = (width + 31) / 32; break;
263 case 4: words = (width + 7) / 8; break;
264 case 8: words = (width + 3) / 4; break;
266 case 16: words = (width + 1) / 2; break;
267 case 24: words = (width * 3 + 3)/4; break;
268 case 32: words = width; break;
272 trace("Unknown depth %d, please report.\n", bpp );
279 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
285 INT ret, bm_width_bytes, dib_width_bytes;
288 ret = GetObject(hbm, sizeof(bm), &bm);
289 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
291 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
292 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
293 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
294 dib_width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
295 bm_width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
296 if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
297 ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
299 ok(bm.bmWidthBytes == dib_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, dib_width_bytes);
300 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
301 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
302 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
304 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
306 /* GetBitmapBits returns not 32-bit aligned data */
307 SetLastError(0xdeadbeef);
308 ret = GetBitmapBits(hbm, 0, NULL);
309 ok(ret == bm_width_bytes * bm.bmHeight,
310 "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
312 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
313 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
314 ok(ret == bm_width_bytes * bm.bmHeight, "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
316 HeapFree(GetProcessHeap(), 0, buf);
318 /* test various buffer sizes for GetObject */
319 memset(&ds, 0xAA, sizeof(ds));
320 ret = GetObject(hbm, sizeof(*bma) * 2, bma);
321 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
322 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
323 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
324 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
326 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
327 ok(ret == 0, "%d != 0\n", ret);
329 ret = GetObject(hbm, 0, &bm);
330 ok(ret == 0, "%d != 0\n", ret);
332 ret = GetObject(hbm, 1, &bm);
333 ok(ret == 0, "%d != 0\n", ret);
335 /* test various buffer sizes for GetObject */
336 ret = GetObject(hbm, 0, NULL);
337 ok(ret == sizeof(bm), "wrong size %d\n", ret);
339 ret = GetObject(hbm, sizeof(*dsa) * 2, dsa);
340 ok(ret == sizeof(*dsa), "wrong size %d\n", ret);
342 memset(&ds, 0xAA, sizeof(ds));
343 ret = GetObject(hbm, sizeof(ds), &ds);
344 ok(ret == sizeof(ds), "wrong size %d\n", ret);
346 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
347 if (ds.dsBm.bmWidthBytes != bm_width_bytes) /* Win2k bug */
348 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
349 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
350 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
351 ds.dsBmih.biSizeImage = 0;
353 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
354 ok(ds.dsBmih.biWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
355 ok(ds.dsBmih.biHeight == abs(bmih->biHeight), "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
356 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
357 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
358 ok(ds.dsBmih.biCompression == bmih->biCompression ||
359 ((bmih->biBitCount == 32) && broken(ds.dsBmih.biCompression == BI_BITFIELDS)), /* nt4 sp1 and 2 */
360 "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
361 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
362 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%d != %d\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
363 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%d != %d\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
365 memset(&ds, 0xAA, sizeof(ds));
366 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
367 ok(ret == sizeof(ds.dsBm), "wrong size %d\n", ret);
368 ok(ds.dsBm.bmWidth == bmih->biWidth, "%d != %d\n", ds.dsBmih.biWidth, bmih->biWidth);
369 ok(ds.dsBm.bmHeight == abs(bmih->biHeight), "%d != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
370 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
372 ret = GetObject(hbm, 0, &ds);
373 ok(ret == 0, "%d != 0\n", ret);
375 ret = GetObject(hbm, 1, &ds);
376 ok(ret == 0, "%d != 0\n", ret);
379 #define test_color_todo(got, exp, txt, todo) \
380 if (!todo && got != exp && screen_depth < 24) { \
381 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
382 screen_depth, (UINT)got, (UINT)exp); \
384 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
385 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
387 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
390 c = SetPixel(hdc, 0, 0, color); \
391 test_color_todo(c, exp, SetPixel, todo_setp); \
392 c = GetPixel(hdc, 0, 0); \
393 test_color_todo(c, exp, GetPixel, todo_getp); \
396 static void test_dib_bits_access( HBITMAP hdib, void *bits )
398 MEMORY_BASIC_INFORMATION info;
399 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
401 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
403 char filename[MAX_PATH];
408 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
409 "VirtualQuery failed\n");
410 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
411 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
412 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
413 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
414 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
415 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
417 memset( pbmi, 0, sizeof(bmibuf) );
418 memset( data, 0xcc, sizeof(data) );
419 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
420 pbmi->bmiHeader.biHeight = 16;
421 pbmi->bmiHeader.biWidth = 16;
422 pbmi->bmiHeader.biBitCount = 32;
423 pbmi->bmiHeader.biPlanes = 1;
424 pbmi->bmiHeader.biCompression = BI_RGB;
428 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
429 ok(ret == 16, "SetDIBits failed: expected 16 got %d\n", ret);
433 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
434 "VirtualQuery failed\n");
435 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
436 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
437 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
438 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
439 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
440 /* it has been protected now */
441 todo_wine ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
443 /* try writing protected bits to a file */
445 GetTempFileNameA( ".", "dib", 0, filename );
446 file = CreateFileA( filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
447 CREATE_ALWAYS, 0, 0 );
448 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %u\n", filename, GetLastError() );
449 ret = WriteFile( file, bits, 8192, &written, NULL );
450 ok( ret, "WriteFile failed error %u\n", GetLastError() );
451 if (ret) ok( written == 8192, "only wrote %u bytes\n", written );
453 DeleteFileA( filename );
456 static void test_dibsections(void)
458 HDC hdc, hdcmem, hdcmem2;
459 HBITMAP hdib, oldbm, hdib2, oldbm2;
460 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
461 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
462 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
463 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
469 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
470 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
473 HPALETTE hpal, oldpal;
478 MEMORY_BASIC_INFORMATION info;
481 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
483 memset(pbmi, 0, sizeof(bmibuf));
484 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
485 pbmi->bmiHeader.biHeight = 100;
486 pbmi->bmiHeader.biWidth = 512;
487 pbmi->bmiHeader.biBitCount = 24;
488 pbmi->bmiHeader.biPlanes = 1;
489 pbmi->bmiHeader.biCompression = BI_RGB;
491 SetLastError(0xdeadbeef);
493 /* invalid pointer for BITMAPINFO
494 (*bits should be NULL on error) */
495 bits = (BYTE*)0xdeadbeef;
496 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
497 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
499 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
500 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
501 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
502 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
504 /* test the DIB memory */
505 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
506 "VirtualQuery failed\n");
507 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
508 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
509 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
510 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
511 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
512 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
513 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
515 test_dib_bits_access( hdib, bits );
517 test_dib_info(hdib, bits, &pbmi->bmiHeader);
520 /* Test a top-down DIB. */
521 pbmi->bmiHeader.biHeight = -100;
522 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
523 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
524 test_dib_info(hdib, bits, &pbmi->bmiHeader);
527 pbmi->bmiHeader.biHeight = 100;
528 pbmi->bmiHeader.biBitCount = 8;
529 pbmi->bmiHeader.biCompression = BI_RLE8;
530 SetLastError(0xdeadbeef);
531 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
532 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
533 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
535 for (i = 0; i < 128; i++)
537 pbmi->bmiHeader.biBitCount = i;
538 pbmi->bmiHeader.biCompression = BI_RGB;
539 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
540 if (i == 1 || i == 4 || i == 8 || i == 16 || i == 24 || i == 32)
541 ok(hdib != NULL, "CreateDIBSection bpp %u\n", i);
543 ok(hdib == NULL, "CreateDIBSection bpp %u succeeded\n", i);
544 if (hdib) DeleteObject( hdib );
547 pbmi->bmiHeader.biBitCount = 16;
548 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
549 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
550 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
551 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
552 SetLastError(0xdeadbeef);
553 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
554 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
556 /* test the DIB memory */
557 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
558 "VirtualQuery failed\n");
559 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
560 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
561 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
562 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
563 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
564 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
565 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
567 test_dib_info(hdib, bits, &pbmi->bmiHeader);
570 memset(pbmi, 0, sizeof(bmibuf));
571 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
572 pbmi->bmiHeader.biHeight = 16;
573 pbmi->bmiHeader.biWidth = 16;
574 pbmi->bmiHeader.biBitCount = 1;
575 pbmi->bmiHeader.biPlanes = 1;
576 pbmi->bmiHeader.biCompression = BI_RGB;
577 pbmi->bmiColors[0].rgbRed = 0xff;
578 pbmi->bmiColors[0].rgbGreen = 0;
579 pbmi->bmiColors[0].rgbBlue = 0;
580 pbmi->bmiColors[1].rgbRed = 0;
581 pbmi->bmiColors[1].rgbGreen = 0;
582 pbmi->bmiColors[1].rgbBlue = 0xff;
584 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
585 ok(hdib != NULL, "CreateDIBSection failed\n");
586 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
587 ok(dibsec.dsBmih.biClrUsed == 2,
588 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
590 /* Test if the old BITMAPCOREINFO structure is supported */
592 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
593 pbci->bmciHeader.bcBitCount = 0;
595 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
596 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
597 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
598 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
599 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
601 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
602 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
603 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
604 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
605 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
606 "The color table has not been translated to the old BITMAPCOREINFO format\n");
608 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
609 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
611 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
612 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
613 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
614 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
615 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
616 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
617 "The color table has not been translated to the old BITMAPCOREINFO format\n");
619 DeleteObject(hcoredib);
621 hdcmem = CreateCompatibleDC(hdc);
622 oldbm = SelectObject(hdcmem, hdib);
624 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
625 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
626 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
627 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
628 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
629 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
631 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
632 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
634 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
635 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
636 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
637 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
638 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
639 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
640 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
641 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
642 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
643 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
644 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
645 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
646 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
648 SelectObject(hdcmem, oldbm);
651 pbmi->bmiColors[0].rgbRed = 0xff;
652 pbmi->bmiColors[0].rgbGreen = 0xff;
653 pbmi->bmiColors[0].rgbBlue = 0xff;
654 pbmi->bmiColors[1].rgbRed = 0;
655 pbmi->bmiColors[1].rgbGreen = 0;
656 pbmi->bmiColors[1].rgbBlue = 0;
658 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
659 ok(hdib != NULL, "CreateDIBSection failed\n");
661 test_dib_info(hdib, bits, &pbmi->bmiHeader);
663 oldbm = SelectObject(hdcmem, hdib);
665 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
666 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
667 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
668 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
669 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
670 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
672 SelectObject(hdcmem, oldbm);
673 test_dib_info(hdib, bits, &pbmi->bmiHeader);
676 pbmi->bmiHeader.biBitCount = 4;
677 for (i = 0; i < 16; i++) {
678 pbmi->bmiColors[i].rgbRed = i;
679 pbmi->bmiColors[i].rgbGreen = 16-i;
680 pbmi->bmiColors[i].rgbBlue = 0;
682 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
683 ok(hdib != NULL, "CreateDIBSection failed\n");
684 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
685 ok(dibsec.dsBmih.biClrUsed == 16,
686 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
687 test_dib_info(hdib, bits, &pbmi->bmiHeader);
690 pbmi->bmiHeader.biBitCount = 8;
692 for (i = 0; i < 128; i++) {
693 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
694 pbmi->bmiColors[i].rgbGreen = i * 2;
695 pbmi->bmiColors[i].rgbBlue = 0;
696 pbmi->bmiColors[255 - i].rgbRed = 0;
697 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
698 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
700 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
701 ok(hdib != NULL, "CreateDIBSection failed\n");
702 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
703 ok(dibsec.dsBmih.biClrUsed == 256,
704 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
706 oldbm = SelectObject(hdcmem, hdib);
708 for (i = 0; i < 256; i++) {
709 test_color(hdcmem, DIBINDEX(i),
710 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
711 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
712 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
715 SelectObject(hdcmem, oldbm);
716 test_dib_info(hdib, bits, &pbmi->bmiHeader);
719 pbmi->bmiHeader.biBitCount = 1;
721 /* Now create a palette and a palette indexed dib section */
722 memset(plogpal, 0, sizeof(logpalbuf));
723 plogpal->palVersion = 0x300;
724 plogpal->palNumEntries = 2;
725 plogpal->palPalEntry[0].peRed = 0xff;
726 plogpal->palPalEntry[0].peBlue = 0xff;
727 plogpal->palPalEntry[1].peGreen = 0xff;
729 index = (WORD*)pbmi->bmiColors;
732 hpal = CreatePalette(plogpal);
733 ok(hpal != NULL, "CreatePalette failed\n");
734 oldpal = SelectPalette(hdc, hpal, TRUE);
735 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
736 ok(hdib != NULL, "CreateDIBSection failed\n");
737 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
738 ok(dibsec.dsBmih.biClrUsed == 2, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
740 /* The colour table has already been grabbed from the dc, so we select back the
743 SelectPalette(hdc, oldpal, TRUE);
744 oldbm = SelectObject(hdcmem, hdib);
745 oldpal = SelectPalette(hdcmem, hpal, TRUE);
747 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
748 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
749 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
750 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
751 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
752 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
753 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
755 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
756 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
758 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
759 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
760 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
761 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
762 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
763 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
764 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
765 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
766 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
767 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
768 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
769 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
770 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
771 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
772 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
773 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
775 /* Bottom and 2nd row from top green, everything else magenta */
776 bits[0] = bits[1] = 0xff;
777 bits[13 * 4] = bits[13*4 + 1] = 0xff;
779 test_dib_info(hdib, bits, &pbmi->bmiHeader);
781 pbmi->bmiHeader.biBitCount = 32;
783 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
784 ok(hdib2 != NULL, "CreateDIBSection failed\n");
785 hdcmem2 = CreateCompatibleDC(hdc);
786 oldbm2 = SelectObject(hdcmem2, hdib2);
788 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
790 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
791 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32[17]);
793 SelectObject(hdcmem2, oldbm2);
794 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
797 SelectObject(hdcmem, oldbm);
798 SelectPalette(hdcmem, oldpal, TRUE);
803 pbmi->bmiHeader.biBitCount = 8;
805 memset(plogpal, 0, sizeof(logpalbuf));
806 plogpal->palVersion = 0x300;
807 plogpal->palNumEntries = 256;
809 for (i = 0; i < 128; i++) {
810 plogpal->palPalEntry[i].peRed = 255 - i * 2;
811 plogpal->palPalEntry[i].peBlue = i * 2;
812 plogpal->palPalEntry[i].peGreen = 0;
813 plogpal->palPalEntry[255 - i].peRed = 0;
814 plogpal->palPalEntry[255 - i].peGreen = i * 2;
815 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
818 index = (WORD*)pbmi->bmiColors;
819 for (i = 0; i < 256; i++) {
823 hpal = CreatePalette(plogpal);
824 ok(hpal != NULL, "CreatePalette failed\n");
825 oldpal = SelectPalette(hdc, hpal, TRUE);
826 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
827 ok(hdib != NULL, "CreateDIBSection failed\n");
828 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
829 ok(dibsec.dsBmih.biClrUsed == 256, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
831 test_dib_info(hdib, bits, &pbmi->bmiHeader);
833 SelectPalette(hdc, oldpal, TRUE);
834 oldbm = SelectObject(hdcmem, hdib);
835 oldpal = SelectPalette(hdcmem, hpal, TRUE);
837 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
838 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
839 for (i = 0; i < 256; i++) {
840 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
841 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
842 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
843 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
844 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
847 for (i = 0; i < 256; i++) {
848 test_color(hdcmem, DIBINDEX(i),
849 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
850 test_color(hdcmem, PALETTEINDEX(i),
851 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
852 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
853 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
856 SelectPalette(hdcmem, oldpal, TRUE);
857 SelectObject(hdcmem, oldbm);
866 static void test_mono_dibsection(void)
869 HBITMAP old_bm, mono_ds;
870 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
871 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
878 memdc = CreateCompatibleDC(hdc);
880 memset(pbmi, 0, sizeof(bmibuf));
881 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
882 pbmi->bmiHeader.biHeight = 10;
883 pbmi->bmiHeader.biWidth = 10;
884 pbmi->bmiHeader.biBitCount = 1;
885 pbmi->bmiHeader.biPlanes = 1;
886 pbmi->bmiHeader.biCompression = BI_RGB;
887 pbmi->bmiColors[0].rgbRed = 0xff;
888 pbmi->bmiColors[0].rgbGreen = 0xff;
889 pbmi->bmiColors[0].rgbBlue = 0xff;
890 pbmi->bmiColors[1].rgbRed = 0x0;
891 pbmi->bmiColors[1].rgbGreen = 0x0;
892 pbmi->bmiColors[1].rgbBlue = 0x0;
895 * First dib section is 'inverted' ie color[0] is white, color[1] is black
898 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
899 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
900 old_bm = SelectObject(memdc, mono_ds);
902 /* black border, white interior */
903 Rectangle(memdc, 0, 0, 10, 10);
904 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
905 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
907 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
909 memset(bits, 0, sizeof(bits));
912 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
913 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
915 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
917 pbmi->bmiColors[0].rgbRed = 0x0;
918 pbmi->bmiColors[0].rgbGreen = 0x0;
919 pbmi->bmiColors[0].rgbBlue = 0x0;
920 pbmi->bmiColors[1].rgbRed = 0xff;
921 pbmi->bmiColors[1].rgbGreen = 0xff;
922 pbmi->bmiColors[1].rgbBlue = 0xff;
924 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
925 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
927 SelectObject(memdc, old_bm);
928 DeleteObject(mono_ds);
931 * Next dib section is 'normal' ie color[0] is black, color[1] is white
934 pbmi->bmiColors[0].rgbRed = 0x0;
935 pbmi->bmiColors[0].rgbGreen = 0x0;
936 pbmi->bmiColors[0].rgbBlue = 0x0;
937 pbmi->bmiColors[1].rgbRed = 0xff;
938 pbmi->bmiColors[1].rgbGreen = 0xff;
939 pbmi->bmiColors[1].rgbBlue = 0xff;
941 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
942 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
943 old_bm = SelectObject(memdc, mono_ds);
945 /* black border, white interior */
946 Rectangle(memdc, 0, 0, 10, 10);
947 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
948 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
950 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
952 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
953 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
955 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
957 pbmi->bmiColors[0].rgbRed = 0xff;
958 pbmi->bmiColors[0].rgbGreen = 0xff;
959 pbmi->bmiColors[0].rgbBlue = 0xff;
960 pbmi->bmiColors[1].rgbRed = 0x0;
961 pbmi->bmiColors[1].rgbGreen = 0x0;
962 pbmi->bmiColors[1].rgbBlue = 0x0;
964 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
965 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
968 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
971 pbmi->bmiColors[0].rgbRed = 0xff;
972 pbmi->bmiColors[0].rgbGreen = 0xff;
973 pbmi->bmiColors[0].rgbBlue = 0xff;
974 pbmi->bmiColors[1].rgbRed = 0x0;
975 pbmi->bmiColors[1].rgbGreen = 0x0;
976 pbmi->bmiColors[1].rgbBlue = 0x0;
977 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
978 ok(num == 2, "num = %d\n", num);
980 /* black border, white interior */
981 Rectangle(memdc, 0, 0, 10, 10);
982 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
983 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
985 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
987 memset(bits, 0, sizeof(bits));
990 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
991 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
993 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
995 pbmi->bmiColors[0].rgbRed = 0x0;
996 pbmi->bmiColors[0].rgbGreen = 0x0;
997 pbmi->bmiColors[0].rgbBlue = 0x0;
998 pbmi->bmiColors[1].rgbRed = 0xff;
999 pbmi->bmiColors[1].rgbGreen = 0xff;
1000 pbmi->bmiColors[1].rgbBlue = 0xff;
1002 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1003 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1005 SelectObject(memdc, old_bm);
1006 DeleteObject(mono_ds);
1009 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1012 pbmi->bmiColors[0].rgbRed = 0xff;
1013 pbmi->bmiColors[0].rgbGreen = 0x0;
1014 pbmi->bmiColors[0].rgbBlue = 0x0;
1015 pbmi->bmiColors[1].rgbRed = 0xfe;
1016 pbmi->bmiColors[1].rgbGreen = 0x0;
1017 pbmi->bmiColors[1].rgbBlue = 0x0;
1019 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1020 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1021 old_bm = SelectObject(memdc, mono_ds);
1023 /* black border, white interior */
1024 Rectangle(memdc, 0, 0, 10, 10);
1025 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1026 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1028 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1030 pbmi->bmiColors[0].rgbRed = 0x0;
1031 pbmi->bmiColors[0].rgbGreen = 0x0;
1032 pbmi->bmiColors[0].rgbBlue = 0x0;
1033 pbmi->bmiColors[1].rgbRed = 0xff;
1034 pbmi->bmiColors[1].rgbGreen = 0xff;
1035 pbmi->bmiColors[1].rgbBlue = 0xff;
1037 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1038 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1040 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1042 pbmi->bmiColors[0].rgbRed = 0xff;
1043 pbmi->bmiColors[0].rgbGreen = 0xff;
1044 pbmi->bmiColors[0].rgbBlue = 0xff;
1045 pbmi->bmiColors[1].rgbRed = 0x0;
1046 pbmi->bmiColors[1].rgbGreen = 0x0;
1047 pbmi->bmiColors[1].rgbBlue = 0x0;
1049 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1050 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1052 SelectObject(memdc, old_bm);
1053 DeleteObject(mono_ds);
1059 static void test_bitmap(void)
1061 char buf[256], buf_cmp[256];
1062 HBITMAP hbmp, hbmp_old;
1068 hdc = CreateCompatibleDC(0);
1071 SetLastError(0xdeadbeef);
1072 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1075 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1076 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1077 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1082 SetLastError(0xdeadbeef);
1083 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1086 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1087 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1088 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1093 SetLastError(0xdeadbeef);
1094 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1095 ok(!hbmp, "CreateBitmap should fail\n");
1097 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1098 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1102 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1103 assert(hbmp != NULL);
1105 ret = GetObject(hbmp, sizeof(bm), &bm);
1106 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1108 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1109 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1110 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1111 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1112 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1113 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1114 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1116 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1117 assert(sizeof(buf) == sizeof(buf_cmp));
1119 ret = GetBitmapBits(hbmp, 0, NULL);
1120 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1122 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1123 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1125 memset(buf, 0xAA, sizeof(buf));
1126 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1127 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1128 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1130 hbmp_old = SelectObject(hdc, hbmp);
1132 ret = GetObject(hbmp, sizeof(bm), &bm);
1133 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1135 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1136 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1137 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1138 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1139 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1140 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1141 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1143 memset(buf, 0xAA, sizeof(buf));
1144 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1145 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1146 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1148 hbmp_old = SelectObject(hdc, hbmp_old);
1149 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1151 /* test various buffer sizes for GetObject */
1152 ret = GetObject(hbmp, sizeof(*bma) * 2, bma);
1153 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
1155 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1156 ok(ret == 0, "%d != 0\n", ret);
1158 ret = GetObject(hbmp, 0, &bm);
1159 ok(ret == 0, "%d != 0\n", ret);
1161 ret = GetObject(hbmp, 1, &bm);
1162 ok(ret == 0, "%d != 0\n", ret);
1168 static void test_bmBits(void)
1174 memset(bits, 0, sizeof(bits));
1175 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1176 ok(hbmp != NULL, "CreateBitmap failed\n");
1178 memset(&bmp, 0xFF, sizeof(bmp));
1179 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1180 "GetObject failed or returned a wrong structure size\n");
1181 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1186 static void test_GetDIBits_selected_DIB(UINT bpp)
1193 UINT dib_size, dib32_size;
1201 /* Create a DIB section with a color table */
1203 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1204 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1208 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1210 /* Choose width and height such that the row length (in bytes)
1211 is a multiple of 4 (makes things easier) */
1212 info->bmiHeader.biWidth = 32;
1213 info->bmiHeader.biHeight = 32;
1214 info->bmiHeader.biPlanes = 1;
1215 info->bmiHeader.biBitCount = bpp;
1216 info->bmiHeader.biCompression = BI_RGB;
1218 for (i=0; i < (1u << bpp); i++)
1220 BYTE c = i * (1 << (8 - bpp));
1221 info->bmiColors[i].rgbRed = c;
1222 info->bmiColors[i].rgbGreen = c;
1223 info->bmiColors[i].rgbBlue = c;
1224 info->bmiColors[i].rgbReserved = 0;
1227 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1229 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1230 dib32_size = 32 * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1232 /* Set the bits of the DIB section */
1233 for (i=0; i < dib_size; i++)
1235 ((BYTE *)bits)[i] = i % 256;
1238 /* Select the DIB into a DC */
1239 dib_dc = CreateCompatibleDC(NULL);
1240 old_bmp = SelectObject(dib_dc, dib);
1241 dc = CreateCompatibleDC(NULL);
1242 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib32_size);
1245 /* Copy the DIB attributes but not the color table */
1246 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1248 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1249 ok(res, "GetDIBits failed\n");
1251 /* Compare the color table and the bits */
1252 equalContents = TRUE;
1253 for (i=0; i < (1u << bpp); i++)
1255 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1256 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1257 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1258 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1260 equalContents = FALSE;
1264 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1266 equalContents = TRUE;
1267 for (i=0; i < dib_size / sizeof(DWORD); i++)
1269 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1271 equalContents = FALSE;
1275 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1277 /* Map into a 32bit-DIB */
1278 info2->bmiHeader.biBitCount = 32;
1279 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1280 ok(res, "GetDIBits failed\n");
1282 /* Check if last pixel was set */
1283 pixel = ((DWORD *)bits2)[info->bmiHeader.biWidth * info->bmiHeader.biHeight - 1];
1284 ok(pixel != 0, "Pixel: 0x%08x\n", pixel);
1286 HeapFree(GetProcessHeap(), 0, bits2);
1289 SelectObject(dib_dc, old_bmp);
1293 HeapFree(GetProcessHeap(), 0, info2);
1294 HeapFree(GetProcessHeap(), 0, info);
1297 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1312 width = height = 16;
1314 /* Create a DDB (device-dependent bitmap) */
1318 ddb = CreateBitmap(width, height, 1, 1, NULL);
1322 HDC screen_dc = GetDC(NULL);
1323 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1324 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1325 ReleaseDC(NULL, screen_dc);
1328 /* Set the pixels */
1329 ddb_dc = CreateCompatibleDC(NULL);
1330 old_bmp = SelectObject(ddb_dc, ddb);
1331 for (i = 0; i < width; i++)
1333 for (j=0; j < height; j++)
1335 BYTE c = (i * width + j) % 256;
1336 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1339 SelectObject(ddb_dc, old_bmp);
1341 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1342 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1346 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1347 info->bmiHeader.biWidth = width;
1348 info->bmiHeader.biHeight = height;
1349 info->bmiHeader.biPlanes = 1;
1350 info->bmiHeader.biBitCount = bpp;
1351 info->bmiHeader.biCompression = BI_RGB;
1353 dc = CreateCompatibleDC(NULL);
1355 /* Fill in biSizeImage */
1356 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1357 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1359 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1360 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1365 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1366 ok(res, "GetDIBits failed\n");
1368 /* Copy the DIB attributes but not the color table */
1369 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1371 /* Select the DDB into another DC */
1372 old_bmp = SelectObject(ddb_dc, ddb);
1375 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1376 ok(res, "GetDIBits failed\n");
1378 /* Compare the color table and the bits */
1381 equalContents = TRUE;
1382 for (i=0; i < (1u << bpp); i++)
1384 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1385 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1386 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1387 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1389 equalContents = FALSE;
1393 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1396 equalContents = TRUE;
1397 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1399 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1401 equalContents = FALSE;
1404 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1406 /* Test the palette */
1407 equalContents = TRUE;
1408 if (info2->bmiHeader.biBitCount <= 8)
1410 WORD *colors = (WORD*)info2->bmiColors;
1412 /* Get the palette indices */
1413 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
1414 ok(res, "GetDIBits failed\n");
1416 for (i=0;i < 1 << info->bmiHeader.biSizeImage; i++)
1420 equalContents = FALSE;
1426 ok(equalContents, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1428 HeapFree(GetProcessHeap(), 0, bits2);
1429 HeapFree(GetProcessHeap(), 0, bits);
1432 SelectObject(ddb_dc, old_bmp);
1436 HeapFree(GetProcessHeap(), 0, info2);
1437 HeapFree(GetProcessHeap(), 0, info);
1440 static void test_GetDIBits(void)
1442 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1443 static const BYTE bmp_bits_1[16 * 2] =
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,
1448 0xff,0xff, 0,0, 0xff,0xff, 0,0
1450 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1451 static const BYTE dib_bits_1[16 * 4] =
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,
1456 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1458 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1459 static const BYTE bmp_bits_24[16 * 16*3] =
1461 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1462 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1463 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1464 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1465 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1466 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1467 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1468 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1469 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1470 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1471 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1472 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1473 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1474 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1475 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1476 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1477 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1478 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1479 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1480 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1481 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1482 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1483 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1484 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1485 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1486 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1487 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1488 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1489 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1490 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1491 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1492 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1494 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1495 static const BYTE dib_bits_24[16 * 16*3] =
1497 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1498 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1499 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1500 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1501 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1502 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1503 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1504 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1505 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1506 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1507 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1508 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1509 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1510 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1511 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1512 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1513 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1514 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1515 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1516 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1517 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1518 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1519 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1520 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1522 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1523 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1524 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1525 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1526 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1527 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1528 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1533 int i, bytes, lines;
1535 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1536 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1537 PALETTEENTRY pal_ents[20];
1541 /* 1-bit source bitmap data */
1542 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1543 ok(hbmp != 0, "CreateBitmap failed\n");
1545 memset(&bm, 0xAA, sizeof(bm));
1546 bytes = GetObject(hbmp, sizeof(bm), &bm);
1547 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1548 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1549 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1550 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1551 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1552 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1553 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1554 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1556 bytes = GetBitmapBits(hbmp, 0, NULL);
1557 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1558 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1559 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1560 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1562 /* retrieve 1-bit DIB data */
1563 memset(bi, 0, sizeof(*bi));
1564 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1565 bi->bmiHeader.biWidth = bm.bmWidth;
1566 bi->bmiHeader.biHeight = bm.bmHeight;
1567 bi->bmiHeader.biPlanes = 1;
1568 bi->bmiHeader.biBitCount = 1;
1569 bi->bmiHeader.biCompression = BI_RGB;
1570 bi->bmiHeader.biSizeImage = 0;
1571 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1572 SetLastError(0xdeadbeef);
1573 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1574 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1575 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
1576 broken(GetLastError() == 0xdeadbeef), /* winnt */
1577 "wrong error %u\n", GetLastError());
1578 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1580 memset(buf, 0xAA, sizeof(buf));
1581 SetLastError(0xdeadbeef);
1582 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1583 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1584 lines, bm.bmHeight, GetLastError());
1585 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1587 /* the color table consists of black and white */
1588 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1589 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1590 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1591 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1592 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1593 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1594 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1595 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1596 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1597 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1598 for (i = 2; i < 256; i++)
1600 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1601 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1602 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1603 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1604 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1607 /* returned bits are DWORD aligned and upside down */
1608 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1610 /* Test the palette indices */
1611 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1612 SetLastError(0xdeadbeef);
1613 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1614 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1615 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1616 for (i = 2; i < 256; i++)
1617 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[1]);
1619 /* retrieve 24-bit DIB data */
1620 memset(bi, 0, sizeof(*bi));
1621 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1622 bi->bmiHeader.biWidth = bm.bmWidth;
1623 bi->bmiHeader.biHeight = bm.bmHeight;
1624 bi->bmiHeader.biPlanes = 1;
1625 bi->bmiHeader.biBitCount = 24;
1626 bi->bmiHeader.biCompression = BI_RGB;
1627 bi->bmiHeader.biSizeImage = 0;
1628 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1629 memset(buf, 0xAA, sizeof(buf));
1630 SetLastError(0xdeadbeef);
1631 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1632 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1633 lines, bm.bmHeight, GetLastError());
1634 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1636 /* the color table doesn't exist for 24-bit images */
1637 for (i = 0; i < 256; i++)
1639 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1640 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1641 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1642 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1643 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1646 /* returned bits are DWORD aligned and upside down */
1647 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1650 /* 24-bit source bitmap data */
1651 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1652 ok(hbmp != 0, "CreateBitmap failed\n");
1653 SetLastError(0xdeadbeef);
1654 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1655 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1656 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1657 lines, bm.bmHeight, GetLastError());
1659 memset(&bm, 0xAA, sizeof(bm));
1660 bytes = GetObject(hbmp, sizeof(bm), &bm);
1661 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1662 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1663 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1664 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1665 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1666 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1667 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1668 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1670 bytes = GetBitmapBits(hbmp, 0, NULL);
1671 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
1672 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1673 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1674 bm.bmWidthBytes * bm.bmHeight, bytes);
1676 /* retrieve 1-bit DIB data */
1677 memset(bi, 0, sizeof(*bi));
1678 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1679 bi->bmiHeader.biWidth = bm.bmWidth;
1680 bi->bmiHeader.biHeight = bm.bmHeight;
1681 bi->bmiHeader.biPlanes = 1;
1682 bi->bmiHeader.biBitCount = 1;
1683 bi->bmiHeader.biCompression = BI_RGB;
1684 bi->bmiHeader.biSizeImage = 0;
1685 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1686 memset(buf, 0xAA, sizeof(buf));
1687 SetLastError(0xdeadbeef);
1688 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1689 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1690 lines, bm.bmHeight, GetLastError());
1691 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1693 /* the color table consists of black and white */
1694 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1695 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1696 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1697 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1698 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1699 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1700 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1701 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1702 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1703 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1704 for (i = 2; i < 256; i++)
1706 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1707 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1708 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1709 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1710 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1713 /* returned bits are DWORD aligned and upside down */
1715 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1717 /* Test the palette indices */
1718 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1719 SetLastError(0xdeadbeef);
1720 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
1721 ok(((WORD*)bi->bmiColors)[0] == 0, "Color 0 is %d\n", ((WORD*)bi->bmiColors)[0]);
1722 ok(((WORD*)bi->bmiColors)[1] == 1, "Color 1 is %d\n", ((WORD*)bi->bmiColors)[1]);
1723 for (i = 2; i < 256; i++)
1724 ok(((WORD*)bi->bmiColors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)bi->bmiColors)[i]);
1726 /* retrieve 4-bit DIB data */
1727 memset(bi, 0, sizeof(*bi));
1728 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1729 bi->bmiHeader.biWidth = bm.bmWidth;
1730 bi->bmiHeader.biHeight = bm.bmHeight;
1731 bi->bmiHeader.biPlanes = 1;
1732 bi->bmiHeader.biBitCount = 4;
1733 bi->bmiHeader.biCompression = BI_RGB;
1734 bi->bmiHeader.biSizeImage = 0;
1735 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1736 memset(buf, 0xAA, sizeof(buf));
1737 SetLastError(0xdeadbeef);
1738 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1739 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1740 lines, bm.bmHeight, GetLastError());
1742 GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, pal_ents );
1744 for (i = 0; i < 16; i++)
1747 int entry = i < 8 ? i : i + 4;
1749 if(entry == 7) entry = 12;
1750 else if(entry == 12) entry = 7;
1752 expect.rgbRed = pal_ents[entry].peRed;
1753 expect.rgbGreen = pal_ents[entry].peGreen;
1754 expect.rgbBlue = pal_ents[entry].peBlue;
1755 expect.rgbReserved = 0;
1757 ok(!memcmp(bi->bmiColors + i, &expect, sizeof(expect)),
1758 "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
1759 expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
1760 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1761 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1764 /* retrieve 8-bit DIB data */
1765 memset(bi, 0, sizeof(*bi));
1766 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1767 bi->bmiHeader.biWidth = bm.bmWidth;
1768 bi->bmiHeader.biHeight = bm.bmHeight;
1769 bi->bmiHeader.biPlanes = 1;
1770 bi->bmiHeader.biBitCount = 8;
1771 bi->bmiHeader.biCompression = BI_RGB;
1772 bi->bmiHeader.biSizeImage = 0;
1773 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1774 memset(buf, 0xAA, sizeof(buf));
1775 SetLastError(0xdeadbeef);
1776 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1777 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1778 lines, bm.bmHeight, GetLastError());
1780 GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, pal_ents );
1782 for (i = 0; i < 256; i++)
1786 if (i < 10 || i >= 246)
1788 int entry = i < 10 ? i : i - 236;
1789 expect.rgbRed = pal_ents[entry].peRed;
1790 expect.rgbGreen = pal_ents[entry].peGreen;
1791 expect.rgbBlue = pal_ents[entry].peBlue;
1795 expect.rgbRed = (i & 0x07) << 5;
1796 expect.rgbGreen = (i & 0x38) << 2;
1797 expect.rgbBlue = i & 0xc0;
1799 expect.rgbReserved = 0;
1801 ok(!memcmp(bi->bmiColors + i, &expect, sizeof(expect)),
1802 "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
1803 expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
1804 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1805 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1808 /* retrieve 24-bit DIB data */
1809 memset(bi, 0, sizeof(*bi));
1810 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1811 bi->bmiHeader.biWidth = bm.bmWidth;
1812 bi->bmiHeader.biHeight = bm.bmHeight;
1813 bi->bmiHeader.biPlanes = 1;
1814 bi->bmiHeader.biBitCount = 24;
1815 bi->bmiHeader.biCompression = BI_RGB;
1816 bi->bmiHeader.biSizeImage = 0;
1817 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1818 memset(buf, 0xAA, sizeof(buf));
1819 SetLastError(0xdeadbeef);
1820 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1821 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1822 lines, bm.bmHeight, GetLastError());
1823 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1825 /* the color table doesn't exist for 24-bit images */
1826 for (i = 0; i < 256; i++)
1828 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1829 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1830 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1831 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1832 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1835 /* returned bits are DWORD aligned and upside down */
1836 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1842 static void test_GetDIBits_BI_BITFIELDS(void)
1844 /* Try a screen resolution detection technique
1845 * from the September 1999 issue of Windows Developer's Journal
1846 * which seems to be in widespread use.
1847 * http://www.lesher.ws/highcolor.html
1848 * http://www.lesher.ws/vidfmt.c
1849 * It hinges on being able to retrieve the bitmaps
1850 * for the three primary colors in non-paletted 16 bit mode.
1852 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
1854 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
1855 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
1861 memset(dibinfo, 0, sizeof(dibinfo_buf));
1862 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1865 ok(hdc != NULL, "GetDC failed?\n");
1866 hbm = CreateCompatibleBitmap(hdc, 1, 1);
1867 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
1869 /* Call GetDIBits to fill in bmiHeader. */
1870 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1871 ok(ret == 1, "GetDIBits failed\n");
1872 if (dibinfo->bmiHeader.biBitCount > 8)
1874 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
1875 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
1876 "compression is %u (%d bpp)\n", dibinfo->bmiHeader.biCompression, dibinfo->bmiHeader.biBitCount );
1878 if (dibinfo->bmiHeader.biCompression == BI_BITFIELDS)
1880 ok( !bitmasks[0], "red mask is set\n" );
1881 ok( !bitmasks[1], "green mask is set\n" );
1882 ok( !bitmasks[2], "blue mask is set\n" );
1884 /* test with NULL bits pointer and correct bpp */
1885 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1886 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1887 ok(ret == 1, "GetDIBits failed\n");
1889 ok( bitmasks[0] != 0, "red mask is not set\n" );
1890 ok( bitmasks[1] != 0, "green mask is not set\n" );
1891 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1892 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1894 /* test with valid bits pointer */
1895 memset(dibinfo, 0, sizeof(dibinfo_buf));
1896 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1897 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
1898 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1899 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1900 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1901 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1903 ok( bitmasks[0] != 0, "red mask is not set\n" );
1904 ok( bitmasks[1] != 0, "green mask is not set\n" );
1905 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1906 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1908 /* now with bits and 0 lines */
1909 memset(dibinfo, 0, sizeof(dibinfo_buf));
1910 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1911 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1912 SetLastError(0xdeadbeef);
1913 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1914 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
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" );
1919 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1921 memset(bitmasks, 0, 3*sizeof(DWORD));
1922 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1923 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
1924 ok(ret == 1, "GetDIBits failed ret %u err %u\n",ret,GetLastError());
1926 ok( bitmasks[0] != 0, "red mask is not set\n" );
1927 ok( bitmasks[1] != 0, "green mask is not set\n" );
1928 ok( bitmasks[2] != 0, "blue mask is not set\n" );
1929 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1932 else skip("bitmap in colortable mode, skipping BI_BITFIELDS tests\n");
1936 /* same thing now with a 32-bpp DIB section */
1938 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1939 dibinfo->bmiHeader.biWidth = 1;
1940 dibinfo->bmiHeader.biHeight = 1;
1941 dibinfo->bmiHeader.biPlanes = 1;
1942 dibinfo->bmiHeader.biBitCount = 32;
1943 dibinfo->bmiHeader.biCompression = BI_RGB;
1944 dibinfo->bmiHeader.biSizeImage = 0;
1945 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1946 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1947 dibinfo->bmiHeader.biClrUsed = 0;
1948 dibinfo->bmiHeader.biClrImportant = 0;
1949 bitmasks[0] = 0x0000ff;
1950 bitmasks[1] = 0x00ff00;
1951 bitmasks[2] = 0xff0000;
1952 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
1953 ok( hbm != 0, "failed to create bitmap\n" );
1955 memset(dibinfo, 0, sizeof(dibinfo_buf));
1956 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1957 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
1958 ok(ret == 1, "GetDIBits failed\n");
1959 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1961 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
1962 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
1963 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1964 ok( !bitmasks[0], "red mask is set\n" );
1965 ok( !bitmasks[1], "green mask is set\n" );
1966 ok( !bitmasks[2], "blue mask is set\n" );
1968 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
1969 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
1970 ok(ret == 1, "GetDIBits failed\n");
1971 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
1972 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
1973 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
1974 "compression is %u\n", dibinfo->bmiHeader.biCompression );
1975 if (dibinfo->bmiHeader.biCompression == BI_BITFIELDS)
1977 ok( bitmasks[0] == 0xff0000, "wrong red mask %08x\n", bitmasks[0] );
1978 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
1979 ok( bitmasks[2] == 0x0000ff, "wrong blue mask %08x\n", bitmasks[2] );
1981 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
1985 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1986 dibinfo->bmiHeader.biWidth = 1;
1987 dibinfo->bmiHeader.biHeight = 1;
1988 dibinfo->bmiHeader.biPlanes = 1;
1989 dibinfo->bmiHeader.biBitCount = 32;
1990 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
1991 dibinfo->bmiHeader.biSizeImage = 0;
1992 dibinfo->bmiHeader.biXPelsPerMeter = 0;
1993 dibinfo->bmiHeader.biYPelsPerMeter = 0;
1994 dibinfo->bmiHeader.biClrUsed = 0;
1995 dibinfo->bmiHeader.biClrImportant = 0;
1996 bitmasks[0] = 0x0000ff;
1997 bitmasks[1] = 0x00ff00;
1998 bitmasks[2] = 0xff0000;
1999 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2000 ok( hbm != 0, "failed to create bitmap\n" );
2004 memset(dibinfo, 0, sizeof(dibinfo_buf));
2005 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2006 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2007 ok(ret == 1, "GetDIBits failed\n");
2009 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS,
2010 "compression is %u\n", dibinfo->bmiHeader.biCompression );
2011 ok( !bitmasks[0], "red mask is set\n" );
2012 ok( !bitmasks[1], "green mask is set\n" );
2013 ok( !bitmasks[2], "blue mask is set\n" );
2015 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2016 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2017 ok(ret == 1, "GetDIBits failed\n");
2018 ok( bitmasks[0] == 0x0000ff, "wrong red mask %08x\n", bitmasks[0] );
2019 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks[1] );
2020 ok( bitmasks[2] == 0xff0000, "wrong blue mask %08x\n", bitmasks[2] );
2021 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2026 /* 24-bpp DIB sections don't have bitfields */
2028 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2029 dibinfo->bmiHeader.biWidth = 1;
2030 dibinfo->bmiHeader.biHeight = 1;
2031 dibinfo->bmiHeader.biPlanes = 1;
2032 dibinfo->bmiHeader.biBitCount = 24;
2033 dibinfo->bmiHeader.biCompression = BI_BITFIELDS;
2034 dibinfo->bmiHeader.biSizeImage = 0;
2035 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2036 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2037 dibinfo->bmiHeader.biClrUsed = 0;
2038 dibinfo->bmiHeader.biClrImportant = 0;
2039 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2040 ok( hbm == 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
2041 dibinfo->bmiHeader.biCompression = BI_RGB;
2042 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2043 ok( hbm != 0, "failed to create bitmap\n" );
2045 memset(dibinfo, 0, sizeof(dibinfo_buf));
2046 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2047 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2048 ok(ret == 1, "GetDIBits failed\n");
2049 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2051 ok( dibinfo->bmiHeader.biCompression == BI_RGB,
2052 "compression is %u\n", dibinfo->bmiHeader.biCompression );
2053 ok( !bitmasks[0], "red mask is set\n" );
2054 ok( !bitmasks[1], "green mask is set\n" );
2055 ok( !bitmasks[2], "blue mask is set\n" );
2057 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2058 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2059 ok(ret == 1, "GetDIBits failed\n");
2060 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2061 ok( !bitmasks[0], "red mask is set\n" );
2062 ok( !bitmasks[1], "green mask is set\n" );
2063 ok( !bitmasks[2], "blue mask is set\n" );
2064 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2067 ReleaseDC(NULL, hdc);
2070 static void test_select_object(void)
2073 HBITMAP hbm, hbm_old;
2075 DWORD depths[] = {8, 15, 16, 24, 32};
2080 ok(hdc != 0, "GetDC(0) failed\n");
2081 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2082 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2084 hbm_old = SelectObject(hdc, hbm);
2085 ok(hbm_old == 0, "SelectObject should fail\n");
2090 hdc = CreateCompatibleDC(0);
2091 ok(hdc != 0, "GetDC(0) failed\n");
2092 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2093 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2095 hbm_old = SelectObject(hdc, hbm);
2096 ok(hbm_old != 0, "SelectObject failed\n");
2097 hbm_old = SelectObject(hdc, hbm_old);
2098 ok(hbm_old == hbm, "SelectObject failed\n");
2102 /* test an 1-bpp bitmap */
2103 planes = GetDeviceCaps(hdc, PLANES);
2106 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
2107 ok(hbm != 0, "CreateBitmap failed\n");
2109 hbm_old = SelectObject(hdc, hbm);
2110 ok(hbm_old != 0, "SelectObject failed\n");
2111 hbm_old = SelectObject(hdc, hbm_old);
2112 ok(hbm_old == hbm, "SelectObject failed\n");
2116 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
2117 /* test a color bitmap to dc bpp matching */
2118 planes = GetDeviceCaps(hdc, PLANES);
2119 bpp = GetDeviceCaps(hdc, BITSPIXEL);
2121 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
2122 ok(hbm != 0, "CreateBitmap failed\n");
2124 hbm_old = SelectObject(hdc, hbm);
2125 if(depths[i] == bpp ||
2126 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
2128 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
2129 SelectObject(hdc, hbm_old);
2131 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
2134 memset(&bm, 0xAA, sizeof(bm));
2135 bytes = GetObject(hbm, sizeof(bm), &bm);
2136 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2137 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2138 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2139 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2140 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2141 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2142 if(depths[i] == 15) {
2143 ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2145 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2147 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2155 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
2160 ret = GetObjectType(hbmp);
2161 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
2163 ret = GetObject(hbmp, 0, 0);
2164 ok_(__FILE__, line)(ret == sizeof(BITMAP), "object size %d\n", ret);
2166 memset(&bm, 0xDA, sizeof(bm));
2167 SetLastError(0xdeadbeef);
2168 ret = GetObject(hbmp, sizeof(bm), &bm);
2169 if (!ret) /* XP, only for curObj2 */ return;
2170 ok_(__FILE__, line)(ret == sizeof(BITMAP), "GetObject returned %d, error %u\n", ret, GetLastError());
2171 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
2172 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
2173 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
2174 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
2175 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
2176 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
2177 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2180 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2182 static void test_CreateBitmap(void)
2185 HDC screenDC = GetDC(0);
2186 HDC hdc = CreateCompatibleDC(screenDC);
2189 /* all of these are the stock monochrome bitmap */
2190 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
2191 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2192 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2193 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2194 HBITMAP curObj1 = GetCurrentObject(hdc, OBJ_BITMAP);
2195 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2197 /* these 2 are not the stock monochrome bitmap */
2198 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2199 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2201 HBITMAP old1 = SelectObject(hdc, bm2);
2202 HBITMAP old2 = SelectObject(screenDC, bm3);
2203 SelectObject(hdc, old1);
2204 SelectObject(screenDC, old2);
2206 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2207 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2208 bm, bm1, bm4, bm5, curObj1, old1);
2209 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2211 ok(bm != curObj2, "0: %p, curObj2 %p\n", bm, curObj2);
2212 ok(old2 == 0, "old2 %p\n", old2);
2214 test_mono_1x1_bmp(bm);
2215 test_mono_1x1_bmp(bm1);
2216 test_mono_1x1_bmp(bm2);
2217 test_mono_1x1_bmp(bm3);
2218 test_mono_1x1_bmp(bm4);
2219 test_mono_1x1_bmp(bm5);
2220 test_mono_1x1_bmp(old1);
2221 test_mono_1x1_bmp(curObj1);
2231 ReleaseDC(0, screenDC);
2233 /* show that Windows ignores the provided bm.bmWidthBytes */
2237 bmp.bmWidthBytes = 28;
2239 bmp.bmBitsPixel = 1;
2241 bm = CreateBitmapIndirect(&bmp);
2242 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2243 test_mono_1x1_bmp(bm);
2246 /* Test how the bmBitsPixel field is treated */
2247 for(i = 1; i <= 33; i++) {
2251 bmp.bmWidthBytes = 28;
2253 bmp.bmBitsPixel = i;
2255 SetLastError(0xdeadbeef);
2256 bm = CreateBitmapIndirect(&bmp);
2258 DWORD error = GetLastError();
2259 ok(bm == 0, "CreateBitmapIndirect for %d bpp succeeded\n", i);
2260 ok(error == ERROR_INVALID_PARAMETER, "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
2264 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
2265 GetObject(bm, sizeof(bmp), &bmp);
2272 } else if(i <= 16) {
2274 } else if(i <= 24) {
2276 } else if(i <= 32) {
2279 ok(bmp.bmBitsPixel == expect, "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2280 i, bmp.bmBitsPixel, expect);
2285 static void test_bitmapinfoheadersize(void)
2292 memset(&bmi, 0, sizeof(BITMAPINFO));
2293 bmi.bmiHeader.biHeight = 100;
2294 bmi.bmiHeader.biWidth = 512;
2295 bmi.bmiHeader.biBitCount = 24;
2296 bmi.bmiHeader.biPlanes = 1;
2298 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2300 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2301 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2303 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2305 SetLastError(0xdeadbeef);
2306 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2307 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2310 bmi.bmiHeader.biSize++;
2312 SetLastError(0xdeadbeef);
2313 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2315 broken(!hdib), /* Win98, WinMe */
2316 "CreateDIBSection error %d\n", GetLastError());
2319 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2321 SetLastError(0xdeadbeef);
2322 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2324 broken(!hdib), /* Win98, WinMe */
2325 "CreateDIBSection error %d\n", GetLastError());
2328 bmi.bmiHeader.biSize++;
2330 SetLastError(0xdeadbeef);
2331 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2333 broken(!hdib), /* Win98, WinMe */
2334 "CreateDIBSection error %d\n", GetLastError());
2337 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2339 SetLastError(0xdeadbeef);
2340 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2341 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2344 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2346 SetLastError(0xdeadbeef);
2347 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2349 broken(!hdib), /* Win95 */
2350 "CreateDIBSection error %d\n", GetLastError());
2353 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2354 bci.bmciHeader.bcHeight = 100;
2355 bci.bmciHeader.bcWidth = 512;
2356 bci.bmciHeader.bcBitCount = 24;
2357 bci.bmciHeader.bcPlanes = 1;
2359 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2361 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2362 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2364 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2366 SetLastError(0xdeadbeef);
2367 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2368 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
2371 bci.bmciHeader.bcSize++;
2373 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2374 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2376 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2378 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2379 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2384 static void test_get16dibits(void)
2386 BYTE bits[4 * (16 / sizeof(BYTE))];
2388 HDC screen_dc = GetDC(NULL);
2391 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2393 int overwritten_bytes = 0;
2395 memset(bits, 0, sizeof(bits));
2396 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2397 ok(hbmp != NULL, "CreateBitmap failed\n");
2399 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
2402 memset(info, '!', info_len);
2403 memset(info, 0, sizeof(info->bmiHeader));
2405 info->bmiHeader.biSize = sizeof(info->bmiHeader);
2406 info->bmiHeader.biWidth = 2;
2407 info->bmiHeader.biHeight = 2;
2408 info->bmiHeader.biPlanes = 1;
2409 info->bmiHeader.biCompression = BI_RGB;
2411 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
2412 ok(ret != 0, "GetDIBits failed got %d\n", ret);
2414 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
2416 overwritten_bytes++;
2417 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
2419 HeapFree(GetProcessHeap(), 0, info);
2421 ReleaseDC(NULL, screen_dc);
2424 static BOOL compare_buffers_no_alpha(UINT32 *a, UINT32 *b, int length)
2427 for(i = 0; i < length; i++)
2428 if((a[i] & 0x00FFFFFF) != (b[i] & 0x00FFFFFF))
2433 static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2434 DWORD dwRop, UINT32 expected, int line)
2436 *srcBuffer = 0xFEDCBA98;
2437 *dstBuffer = 0x89ABCDEF;
2438 Rectangle(hdcSrc, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2439 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
2440 ok(expected == *dstBuffer,
2441 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2442 dwRop, expected, *dstBuffer, line);
2445 static void test_BitBlt(void)
2447 HBITMAP bmpDst, bmpSrc;
2448 HBITMAP oldDst, oldSrc;
2449 HDC hdcScreen, hdcDst, hdcSrc;
2450 UINT32 *dstBuffer, *srcBuffer;
2451 HBRUSH hBrush, hOldBrush;
2452 BITMAPINFO bitmapInfo;
2454 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2455 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2456 bitmapInfo.bmiHeader.biWidth = 1;
2457 bitmapInfo.bmiHeader.biHeight = 1;
2458 bitmapInfo.bmiHeader.biPlanes = 1;
2459 bitmapInfo.bmiHeader.biBitCount = 32;
2460 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2461 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
2463 hdcScreen = CreateCompatibleDC(0);
2464 hdcDst = CreateCompatibleDC(hdcScreen);
2465 hdcSrc = CreateCompatibleDC(hdcDst);
2467 /* Setup the destination dib section */
2468 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
2470 oldDst = SelectObject(hdcDst, bmpDst);
2472 hBrush = CreateSolidBrush(0x012345678);
2473 hOldBrush = SelectObject(hdcDst, hBrush);
2475 /* Setup the source dib section */
2476 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
2478 oldSrc = SelectObject(hdcSrc, bmpSrc);
2480 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2481 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2482 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2483 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2484 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2485 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2486 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2487 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2488 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2489 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2490 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2491 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2492 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2493 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2494 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2497 SelectObject(hdcSrc, oldSrc);
2498 DeleteObject(bmpSrc);
2501 SelectObject(hdcDst, hOldBrush);
2502 DeleteObject(hBrush);
2503 SelectObject(hdcDst, oldDst);
2504 DeleteObject(bmpDst);
2508 DeleteDC(hdcScreen);
2511 static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2512 DWORD dwRop, UINT32 expected, int line)
2514 *srcBuffer = 0xFEDCBA98;
2515 *dstBuffer = 0x89ABCDEF;
2516 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
2517 ok(expected == *dstBuffer,
2518 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2519 dwRop, expected, *dstBuffer, line);
2522 static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
2523 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2524 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2525 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2527 memset(dstBuffer, 0, 16);
2528 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2529 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
2530 ok(memcmp(dstBuffer, expected, 16) == 0 ||
2531 broken(compare_buffers_no_alpha(dstBuffer, legacy_expected, 4)),
2532 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2533 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2534 expected[0], expected[1], expected[2], expected[3],
2535 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2536 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2537 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2540 static void test_StretchBlt(void)
2542 HBITMAP bmpDst, bmpSrc;
2543 HBITMAP oldDst, oldSrc;
2544 HDC hdcScreen, hdcDst, hdcSrc;
2545 UINT32 *dstBuffer, *srcBuffer;
2546 HBRUSH hBrush, hOldBrush;
2547 BITMAPINFO biDst, biSrc;
2548 UINT32 expected[4], legacy_expected[4];
2550 memset(&biDst, 0, sizeof(BITMAPINFO));
2551 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2552 biDst.bmiHeader.biWidth = 2;
2553 biDst.bmiHeader.biHeight = -2;
2554 biDst.bmiHeader.biPlanes = 1;
2555 biDst.bmiHeader.biBitCount = 32;
2556 biDst.bmiHeader.biCompression = BI_RGB;
2557 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
2559 hdcScreen = CreateCompatibleDC(0);
2560 hdcDst = CreateCompatibleDC(hdcScreen);
2561 hdcSrc = CreateCompatibleDC(hdcDst);
2564 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2566 oldDst = SelectObject(hdcDst, bmpDst);
2568 bmpSrc = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&srcBuffer,
2570 oldSrc = SelectObject(hdcSrc, bmpSrc);
2572 hBrush = CreateSolidBrush(0x012345678);
2573 hOldBrush = SelectObject(hdcDst, hBrush);
2575 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2576 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2577 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2578 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2579 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2580 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2581 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2582 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2583 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2584 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2585 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2586 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2587 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2588 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2589 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2591 SelectObject(hdcDst, hOldBrush);
2592 DeleteObject(hBrush);
2594 /* Top-down to top-down tests */
2595 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2596 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2598 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2599 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2600 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2601 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2603 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2604 expected[2] = 0x00000000, expected[3] = 0x00000000;
2605 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2606 0, 0, 1, 1, 0, 0, 1, 1, expected, expected, __LINE__);
2608 expected[0] = 0xCAFED00D, expected[1] = 0xCAFED00D;
2609 expected[2] = 0xCAFED00D, expected[3] = 0xCAFED00D;
2610 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2611 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2613 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2614 expected[2] = 0x00000000, expected[3] = 0x00000000;
2615 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2616 0, 0, 1, 1, 0, 0, 2, 2, expected, expected, __LINE__);
2618 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2619 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2620 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2621 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2623 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2624 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2625 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2626 1, 1, -2, -2, 0, 0, 2, 2, expected, expected, __LINE__);
2628 /* This result seems broken. One might expect the following result:
2629 * 0xCAFED00D 0xFEEDFACE
2630 * 0xFEDCBA98 0x76543210
2632 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2633 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2634 legacy_expected[0] = 0xCAFED00D, legacy_expected[1] = 0x00000000;
2635 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2636 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2637 1, 1, -2, -2, 1, 1, -2, -2, expected,
2638 legacy_expected, __LINE__);
2640 expected[0] = 0x00000000, expected[1] = 0x00000000;
2641 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2642 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2643 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2645 SelectObject(hdcDst, oldDst);
2646 DeleteObject(bmpDst);
2648 /* Top-down to bottom-up tests */
2649 biDst.bmiHeader.biHeight = 2;
2650 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2652 oldDst = SelectObject(hdcDst, bmpDst);
2654 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2655 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2656 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2657 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2659 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2660 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2661 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2662 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2664 SelectObject(hdcSrc, oldSrc);
2665 DeleteObject(bmpSrc);
2667 /* Bottom-up to bottom-up tests */
2668 biSrc.bmiHeader.biHeight = 2;
2669 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
2671 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2672 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2673 oldSrc = SelectObject(hdcSrc, bmpSrc);
2675 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2676 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2677 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2678 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2680 expected[0] = 0x76543210, expected[1] = 0xFEDCBA98;
2681 expected[2] = 0xFEEDFACE, expected[3] = 0xCAFED00D;
2682 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2683 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2685 SelectObject(hdcDst, oldDst);
2686 DeleteObject(bmpDst);
2688 /* Bottom-up to top-down tests */
2689 biDst.bmiHeader.biHeight = -2;
2690 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2692 oldDst = SelectObject(hdcDst, bmpDst);
2694 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2695 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2696 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2697 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2699 expected[0] = 0xFEEDFACE, expected[1] = 0xCAFED00D;
2700 expected[2] = 0x76543210, expected[3] = 0xFEDCBA98;
2701 check_StretchBlt_stretch(hdcDst, hdcSrc, dstBuffer, srcBuffer,
2702 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2705 SelectObject(hdcSrc, oldSrc);
2706 DeleteObject(bmpSrc);
2709 SelectObject(hdcDst, oldDst);
2710 DeleteObject(bmpDst);
2713 DeleteDC(hdcScreen);
2716 static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2717 DWORD dwRop, UINT32 expected, int line)
2719 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
2720 BITMAPINFO bitmapInfo;
2722 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2723 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2724 bitmapInfo.bmiHeader.biWidth = 2;
2725 bitmapInfo.bmiHeader.biHeight = 1;
2726 bitmapInfo.bmiHeader.biPlanes = 1;
2727 bitmapInfo.bmiHeader.biBitCount = 32;
2728 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2729 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
2731 *dstBuffer = 0x89ABCDEF;
2733 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
2734 ok(expected == *dstBuffer,
2735 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2736 dwRop, expected, *dstBuffer, line);
2739 static void check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
2740 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
2741 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
2742 UINT32 expected[4], UINT32 legacy_expected[4], int line)
2744 BITMAPINFO bitmapInfo;
2746 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
2747 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2748 bitmapInfo.bmiHeader.biWidth = 2;
2749 bitmapInfo.bmiHeader.biHeight = -2;
2750 bitmapInfo.bmiHeader.biPlanes = 1;
2751 bitmapInfo.bmiHeader.biBitCount = 32;
2752 bitmapInfo.bmiHeader.biCompression = BI_RGB;
2754 memset(dstBuffer, 0, 16);
2755 StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
2756 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2757 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
2758 ok(memcmp(dstBuffer, expected, 16) == 0,
2759 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2760 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2761 expected[0], expected[1], expected[2], expected[3],
2762 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
2763 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
2764 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
2767 static void test_StretchDIBits(void)
2771 HDC hdcScreen, hdcDst;
2772 UINT32 *dstBuffer, srcBuffer[4];
2773 HBRUSH hBrush, hOldBrush;
2775 UINT32 expected[4], legacy_expected[4];
2777 memset(&biDst, 0, sizeof(BITMAPINFO));
2778 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2779 biDst.bmiHeader.biWidth = 2;
2780 biDst.bmiHeader.biHeight = -2;
2781 biDst.bmiHeader.biPlanes = 1;
2782 biDst.bmiHeader.biBitCount = 32;
2783 biDst.bmiHeader.biCompression = BI_RGB;
2785 hdcScreen = CreateCompatibleDC(0);
2786 hdcDst = CreateCompatibleDC(hdcScreen);
2789 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2791 oldDst = SelectObject(hdcDst, bmpDst);
2793 hBrush = CreateSolidBrush(0x012345678);
2794 hOldBrush = SelectObject(hdcDst, hBrush);
2796 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
2797 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
2798 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
2799 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
2800 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
2801 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
2802 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
2803 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
2804 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
2805 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
2806 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
2807 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
2808 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
2809 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
2810 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
2812 SelectObject(hdcDst, hOldBrush);
2813 DeleteObject(hBrush);
2815 /* Top-down destination tests */
2816 srcBuffer[0] = 0xCAFED00D, srcBuffer[1] = 0xFEEDFACE;
2817 srcBuffer[2] = 0xFEDCBA98, srcBuffer[3] = 0x76543210;
2819 expected[0] = 0xCAFED00D, expected[1] = 0xFEEDFACE;
2820 expected[2] = 0xFEDCBA98, expected[3] = 0x76543210;
2821 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2822 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2824 expected[0] = 0xCAFED00D, expected[1] = 0x00000000;
2825 expected[2] = 0x00000000, expected[3] = 0x00000000;
2826 legacy_expected[0] = 0xFEDCBA98, legacy_expected[1] = 0x00000000;
2827 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2828 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2829 0, 0, 1, 1, 0, 0, 1, 1, expected, legacy_expected, __LINE__);
2831 expected[0] = 0xFEDCBA98, expected[1] = 0xFEDCBA98;
2832 expected[2] = 0xFEDCBA98, expected[3] = 0xFEDCBA98;
2833 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2834 0, 0, 2, 2, 0, 0, 1, 1, expected, expected, __LINE__);
2836 expected[0] = 0x42441000, expected[1] = 0x00000000;
2837 expected[2] = 0x00000000, expected[3] = 0x00000000;
2838 legacy_expected[0] = 0x00543210, legacy_expected[1] = 0x00000000;
2839 legacy_expected[2] = 0x00000000, legacy_expected[3] = 0x00000000;
2840 todo_wine check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2841 0, 0, 1, 1, 0, 0, 2, 2, expected, legacy_expected, __LINE__);
2843 expected[0] = 0x00000000, expected[1] = 0x00000000;
2844 expected[2] = 0x00000000, expected[3] = 0x00000000;
2845 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2846 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2848 expected[0] = 0x00000000, expected[1] = 0x00000000;
2849 expected[2] = 0x00000000, expected[3] = 0x00000000;
2850 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2851 0, 0, 2, 2, 1, 1, -2, -2, expected, expected, __LINE__);
2853 expected[0] = 0x00000000, expected[1] = 0x00000000;
2854 expected[2] = 0x00000000, expected[3] = 0x00000000;
2855 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2856 1, 1, -2, -2, 1, 1, -2, -2, expected, expected, __LINE__);
2858 expected[0] = 0x00000000, expected[1] = 0x00000000;
2859 expected[2] = 0x00000000, expected[3] = 0xCAFED00D;
2860 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2861 1, 1, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2863 SelectObject(hdcDst, oldDst);
2864 DeleteObject(bmpDst);
2866 /* Bottom up destination tests */
2867 biDst.bmiHeader.biHeight = 2;
2868 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
2870 oldDst = SelectObject(hdcDst, bmpDst);
2872 expected[0] = 0xFEDCBA98, expected[1] = 0x76543210;
2873 expected[2] = 0xCAFED00D, expected[3] = 0xFEEDFACE;
2874 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
2875 0, 0, 2, 2, 0, 0, 2, 2, expected, expected, __LINE__);
2878 SelectObject(hdcDst, oldDst);
2879 DeleteObject(bmpDst);
2882 DeleteDC(hdcScreen);
2885 static void test_GdiAlphaBlend(void)
2887 /* test out-of-bound parameters for GdiAlphaBlend */
2900 BLENDFUNCTION blend;
2902 if (!pGdiAlphaBlend)
2904 win_skip("GdiAlphaBlend() is not implemented\n");
2908 hdcNull = GetDC(NULL);
2909 hdcDst = CreateCompatibleDC(hdcNull);
2910 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
2911 hdcSrc = CreateCompatibleDC(hdcNull);
2913 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2914 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
2915 bmi.bmiHeader.biHeight = 20;
2916 bmi.bmiHeader.biWidth = 20;
2917 bmi.bmiHeader.biBitCount = 32;
2918 bmi.bmiHeader.biPlanes = 1;
2919 bmi.bmiHeader.biCompression = BI_RGB;
2920 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
2921 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2923 oldDst = SelectObject(hdcDst, bmpDst);
2924 oldSrc = SelectObject(hdcSrc, bmpSrc);
2926 blend.BlendOp = AC_SRC_OVER;
2927 blend.BlendFlags = 0;
2928 blend.SourceConstantAlpha = 128;
2929 blend.AlphaFormat = 0;
2931 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
2932 SetLastError(0xdeadbeef);
2933 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
2934 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
2935 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
2936 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
2937 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2938 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
2940 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
2941 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
2942 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
2943 SetMapMode(hdcSrc, MM_ANISOTROPIC);
2944 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
2945 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
2946 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
2948 SetLastError(0xdeadbeef);
2949 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend), FALSE, BOOL, "%d");
2950 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2952 SelectObject(hdcDst, oldDst);
2953 SelectObject(hdcSrc, oldSrc);
2954 DeleteObject(bmpSrc);
2955 DeleteObject(bmpDst);
2959 ReleaseDC(NULL, hdcNull);
2963 static void test_clipping(void)
2971 HDC hdcDst = CreateCompatibleDC( NULL );
2972 HDC hdcSrc = CreateCompatibleDC( NULL );
2974 BITMAPINFO bmpinfo={{0}};
2975 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2976 bmpinfo.bmiHeader.biWidth = 100;
2977 bmpinfo.bmiHeader.biHeight = 100;
2978 bmpinfo.bmiHeader.biPlanes = 1;
2979 bmpinfo.bmiHeader.biBitCount = GetDeviceCaps( hdcDst, BITSPIXEL );
2980 bmpinfo.bmiHeader.biCompression = BI_RGB;
2982 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2983 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
2984 SelectObject( hdcDst, bmpDst );
2986 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
2987 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
2988 SelectObject( hdcSrc, bmpSrc );
2990 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
2991 ok(result, "BitBlt failed\n");
2993 hRgn = CreateRectRgn( 0,0,0,0 );
2994 SelectClipRgn( hdcDst, hRgn );
2996 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
2997 ok(result, "BitBlt failed\n");
2999 DeleteObject( bmpDst );
3000 DeleteObject( bmpSrc );
3001 DeleteObject( hRgn );
3006 static void test_32bit_bitmap_blt(void)
3009 HBITMAP bmpSrc, bmpDst;
3010 HBITMAP oldSrc, oldDst;
3011 HDC hdcSrc, hdcDst, hdcScreen;
3013 DWORD colorSrc = 0x11223344;
3015 memset(&biDst, 0, sizeof(BITMAPINFO));
3016 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3017 biDst.bmiHeader.biWidth = 2;
3018 biDst.bmiHeader.biHeight = -2;
3019 biDst.bmiHeader.biPlanes = 1;
3020 biDst.bmiHeader.biBitCount = 32;
3021 biDst.bmiHeader.biCompression = BI_RGB;
3023 hdcScreen = CreateCompatibleDC(0);
3024 if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
3026 DeleteDC(hdcScreen);
3027 trace("Skipping 32-bit DDB test\n");
3031 hdcSrc = CreateCompatibleDC(hdcScreen);
3032 bmpSrc = CreateBitmap(1, 1, 1, 32, &colorSrc);
3033 oldSrc = SelectObject(hdcSrc, bmpSrc);
3035 hdcDst = CreateCompatibleDC(hdcScreen);
3036 bmpDst = CreateDIBSection(hdcDst, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
3037 oldDst = SelectObject(hdcDst, bmpDst);
3039 StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
3040 ok(dstBuffer[0] == colorSrc, "Expected color=%x, received color=%x\n", colorSrc, dstBuffer[0]);
3043 SelectObject(hdcDst, oldDst);
3044 DeleteObject(bmpDst);
3047 SelectObject(hdcSrc, oldSrc);
3048 DeleteObject(bmpSrc);
3051 DeleteDC(hdcScreen);
3055 * Used by test_GetDIBits_top_down to create the bitmap to test against.
3057 static void setup_picture(char *picture, int bpp)
3065 /*Set the first byte in each pixel to the index of that pixel.*/
3066 for (i = 0; i < 4; i++)
3067 picture[i * (bpp / 8)] = i;
3072 /*Each scanline in a bitmap must be a multiple of 4 bytes long.*/
3079 static void test_GetDIBits_top_down(int bpp)
3082 HBITMAP bmptb, bmpbt;
3088 bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
3089 bi.bmiHeader.biWidth=2;
3090 bi.bmiHeader.biHeight=2;
3091 bi.bmiHeader.biPlanes=1;
3092 bi.bmiHeader.biBitCount=bpp;
3093 bi.bmiHeader.biCompression=BI_RGB;
3095 /*Get the device context for the screen.*/
3097 ok(hdc != NULL, "Could not get a handle to a device context.\n");
3099 /*Create the bottom to top image (image's bottom scan line is at the top in memory).*/
3100 bmpbt = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
3101 ok(bmpbt != NULL, "Could not create a DIB section.\n");
3102 /*Now that we have a pointer to the pixels, we write to them.*/
3103 setup_picture((char*)picture, bpp);
3104 /*Create the top to bottom image (images' bottom scan line is at the bottom in memory).*/
3105 bi.bmiHeader.biHeight=-2; /*We specify that we want a top to bottom image by specifying a negative height.*/
3106 bmptb = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
3107 ok(bmptb != NULL, "Could not create a DIB section.\n");
3108 /*Write to this top to bottom bitmap.*/
3109 setup_picture((char*)picture, bpp);
3111 bi.bmiHeader.biWidth = 1;
3113 bi.bmiHeader.biHeight = 2;
3114 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3115 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3116 /*Check the first byte of the pixel.*/
3117 ok((char)pictureOut[0] == 0, "Bottom-up -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3118 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3119 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3120 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3121 /*Check second scanline.*/
3122 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3123 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3124 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3125 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3126 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3127 ok((char)pictureOut[0] == 2, "Bottom-up -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3128 /*Check both scanlines.*/
3129 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3130 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3131 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3132 ok((char)pictureOut[1] == 0, "Top-down -> bottom-up: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3133 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3134 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3135 ok((char)pictureOut[0] == 0, "Bottom up -> bottom-up: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3136 ok((char)pictureOut[1] == 2, "Bottom up -> bottom-up: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3138 /*Make destination bitmap top-down.*/
3139 bi.bmiHeader.biHeight = -2;
3140 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3141 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3142 ok((char)pictureOut[0] == 0, "Bottom-up -> top-down: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3143 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
3144 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3145 ok((char)pictureOut[0] == 2, "Top-down -> top-down: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3146 /*Check second scanline.*/
3147 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3148 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3149 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
3150 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
3151 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3152 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
3153 /*Check both scanlines.*/
3154 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3155 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3156 ok((char)pictureOut[0] == 0, "Top-down -> top-down: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3157 ok((char)pictureOut[1] == 2, "Top-down -> top-down: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3158 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
3159 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
3160 ok((char)pictureOut[0] == 2, "Bottom up -> top-down: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
3161 ok((char)pictureOut[1] == 0, "Bottom up -> top-down: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
3163 DeleteObject(bmpbt);
3164 DeleteObject(bmptb);
3167 static void test_GetSetDIBits_rtl(void)
3170 HBITMAP bitmap, orig_bitmap;
3173 DWORD bits_1[8 * 8], bits_2[8 * 8];
3177 win_skip("Don't have SetLayout\n");
3181 hdc = GetDC( NULL );
3182 hdc_mem = CreateCompatibleDC( hdc );
3183 pSetLayout( hdc_mem, LAYOUT_LTR );
3185 bitmap = CreateCompatibleBitmap( hdc, 8, 8 );
3186 orig_bitmap = SelectObject( hdc_mem, bitmap );
3187 SetPixel( hdc_mem, 0, 0, RGB(0xff, 0, 0) );
3188 SelectObject( hdc_mem, orig_bitmap );
3190 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3191 info.bmiHeader.biWidth = 8;
3192 info.bmiHeader.biHeight = 8;
3193 info.bmiHeader.biPlanes = 1;
3194 info.bmiHeader.biBitCount = 32;
3195 info.bmiHeader.biCompression = BI_RGB;
3197 /* First show that GetDIBits ignores the layout mode. */
3199 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
3200 ok(ret == 8, "got %d\n", ret);
3201 ok(bits_1[56] == 0xff0000, "got %08x\n", bits_1[56]); /* check we have a red pixel */
3203 pSetLayout( hdc_mem, LAYOUT_RTL );
3205 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
3206 ok(ret == 8, "got %d\n", ret);
3208 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
3210 /* Now to show that SetDIBits also ignores the mode, we perform a SetDIBits
3211 followed by a GetDIBits and show that the bits remain unchanged. */
3213 pSetLayout( hdc_mem, LAYOUT_LTR );
3215 ret = SetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
3216 ok(ret == 8, "got %d\n", ret);
3217 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
3218 ok(ret == 8, "got %d\n", ret);
3219 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
3221 pSetLayout( hdc_mem, LAYOUT_RTL );
3223 ret = SetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
3224 ok(ret == 8, "got %d\n", ret);
3225 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
3226 ok(ret == 8, "got %d\n", ret);
3227 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
3229 DeleteObject( bitmap );
3230 DeleteDC( hdc_mem );
3231 ReleaseDC( NULL, hdc );
3238 hdll = GetModuleHandle("gdi32.dll");
3239 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
3240 pSetLayout = (void*)GetProcAddress(hdll, "SetLayout");
3242 test_createdibitmap();
3244 test_mono_dibsection();
3247 test_GetDIBits_selected_DIB(1);
3248 test_GetDIBits_selected_DIB(4);
3249 test_GetDIBits_selected_DIB(8);
3250 test_GetDIBits_selected_DDB(TRUE);
3251 test_GetDIBits_selected_DDB(FALSE);
3253 test_GetDIBits_BI_BITFIELDS();
3254 test_select_object();
3255 test_CreateBitmap();
3258 test_StretchDIBits();
3259 test_GdiAlphaBlend();
3260 test_32bit_bitmap_blt();
3261 test_bitmapinfoheadersize();
3264 test_GetDIBits_top_down(16);
3265 test_GetDIBits_top_down(24);
3266 test_GetDIBits_top_down(32);
3267 test_GetSetDIBits_rtl();