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
32 #include "wine/test.h"
34 static BOOL (WINAPI *pGdiAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
36 #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)
73 char buf[512], buf_cmp[512];
75 ret = GetObject(hbm, sizeof(bm), &bm);
76 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
78 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
79 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
80 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
81 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
82 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
83 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
84 ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
85 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
87 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
88 assert(sizeof(buf) == sizeof(buf_cmp));
90 ret = GetBitmapBits(hbm, 0, NULL);
91 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
93 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
94 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
96 memset(buf, 0xAA, sizeof(buf));
97 ret = GetBitmapBits(hbm, sizeof(buf), buf);
98 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
99 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
101 /* test various buffer sizes for GetObject */
102 ret = GetObject(hbm, 0, NULL);
103 ok(ret == sizeof(bm), "wrong size %d\n", ret);
105 ret = GetObject(hbm, sizeof(bm) * 2, &bm);
106 ok(ret == sizeof(bm), "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);
118 static void test_createdibitmap(void)
121 BITMAPINFOHEADER bmih;
123 HBITMAP hbm, hbm_colour, hbm_old;
128 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
129 memset(&bmih, 0, sizeof(bmih));
130 bmih.biSize = sizeof(bmih);
134 bmih.biBitCount = 32;
135 bmih.biCompression = BI_RGB;
137 /* First create an un-initialised bitmap. The depth of the bitmap
138 should match that of the hdc and not that supplied in bmih.
141 /* First try 32 bits */
142 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
143 ok(hbm != NULL, "CreateDIBitmap failed\n");
144 test_bitmap_info(hbm, screen_depth, &bmih);
148 bmih.biBitCount = 16;
149 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
150 ok(hbm != NULL, "CreateDIBitmap failed\n");
151 test_bitmap_info(hbm, screen_depth, &bmih);
156 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
157 ok(hbm != NULL, "CreateDIBitmap failed\n");
158 test_bitmap_info(hbm, screen_depth, &bmih);
161 /* Now with a monochrome dc we expect a monochrome bitmap */
162 hdcmem = CreateCompatibleDC(hdc);
164 /* First try 32 bits */
165 bmih.biBitCount = 32;
166 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
167 ok(hbm != NULL, "CreateDIBitmap failed\n");
168 test_bitmap_info(hbm, 1, &bmih);
172 bmih.biBitCount = 16;
173 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
174 ok(hbm != NULL, "CreateDIBitmap failed\n");
175 test_bitmap_info(hbm, 1, &bmih);
180 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
181 ok(hbm != NULL, "CreateDIBitmap failed\n");
182 test_bitmap_info(hbm, 1, &bmih);
185 /* Now select a polychrome bitmap into the dc and we expect
186 screen_depth bitmaps again */
187 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
188 test_bitmap_info(hbm_colour, screen_depth, &bmih);
189 hbm_old = SelectObject(hdcmem, hbm_colour);
191 /* First try 32 bits */
192 bmih.biBitCount = 32;
193 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
194 ok(hbm != NULL, "CreateDIBitmap failed\n");
195 test_bitmap_info(hbm, screen_depth, &bmih);
199 bmih.biBitCount = 16;
200 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
201 ok(hbm != NULL, "CreateDIBitmap failed\n");
202 test_bitmap_info(hbm, screen_depth, &bmih);
207 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
208 ok(hbm != NULL, "CreateDIBitmap failed\n");
209 test_bitmap_info(hbm, screen_depth, &bmih);
212 SelectObject(hdcmem, hbm_old);
213 DeleteObject(hbm_colour);
216 /* If hdc == 0 then we get a 1 bpp bitmap */
218 bmih.biBitCount = 32;
219 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
220 ok(hbm != NULL, "CreateDIBitmap failed\n");
221 test_bitmap_info(hbm, 1, &bmih);
225 /* Test how formats are converted */
231 memset(&bm, 0, sizeof(bm));
232 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
233 bm.bmiHeader.biWidth = 1;
234 bm.bmiHeader.biHeight = 1;
235 bm.bmiHeader.biPlanes = 1;
236 bm.bmiHeader.biBitCount= 24;
237 bm.bmiHeader.biCompression= BI_RGB;
238 bm.bmiHeader.biSizeImage = 0;
239 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
240 ok(hbm != NULL, "CreateDIBitmap failed\n");
243 bm.bmiHeader.biBitCount= 32;
244 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
245 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel);
251 static INT DIB_GetWidthBytes( int width, int bpp )
257 case 1: words = (width + 31) / 32; break;
258 case 4: words = (width + 7) / 8; break;
259 case 8: words = (width + 3) / 4; break;
261 case 16: words = (width + 1) / 2; break;
262 case 24: words = (width * 3 + 3)/4; break;
263 case 32: words = width; break;
267 trace("Unknown depth %d, please report.\n", bpp );
274 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
278 INT ret, width_bytes;
281 ret = GetObject(hbm, sizeof(bm), &bm);
282 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
284 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
285 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
286 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
287 width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
288 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
289 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
290 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
291 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
293 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
295 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
297 /* GetBitmapBits returns not 32-bit aligned data */
298 ret = GetBitmapBits(hbm, 0, NULL);
299 ok(ret == width_bytes * bm.bmHeight, "%d != %d\n", ret, width_bytes * bm.bmHeight);
301 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
302 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
303 ok(ret == width_bytes * bm.bmHeight, "%d != %d\n", ret, width_bytes * bm.bmHeight);
305 HeapFree(GetProcessHeap(), 0, buf);
307 /* test various buffer sizes for GetObject */
308 memset(&ds, 0xAA, sizeof(ds));
309 ret = GetObject(hbm, sizeof(bm) * 2, &bm);
310 ok(ret == sizeof(bm), "wrong size %d\n", ret);
311 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
312 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
313 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
315 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
316 ok(ret == 0, "%d != 0\n", ret);
318 ret = GetObject(hbm, 0, &bm);
319 ok(ret == 0, "%d != 0\n", ret);
321 ret = GetObject(hbm, 1, &bm);
322 ok(ret == 0, "%d != 0\n", ret);
324 /* test various buffer sizes for GetObject */
325 ret = GetObject(hbm, 0, NULL);
326 ok(ret == sizeof(bm), "wrong size %d\n", ret);
328 memset(&ds, 0xAA, sizeof(ds));
329 ret = GetObject(hbm, sizeof(ds) * 2, &ds);
330 ok(ret == sizeof(ds), "wrong size %d\n", ret);
332 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
333 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
334 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
335 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
336 ds.dsBmih.biSizeImage = 0;
338 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
339 ok(ds.dsBmih.biWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
340 ok(ds.dsBmih.biHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
341 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
342 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
343 ok(ds.dsBmih.biCompression == bmih->biCompression, "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
344 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
345 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%u != %u\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
346 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%u != %u\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
348 memset(&ds, 0xAA, sizeof(ds));
349 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
350 ok(ret == sizeof(ds.dsBm), "wrong size %d\n", ret);
351 ok(ds.dsBm.bmWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
352 ok(ds.dsBm.bmHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
353 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
355 ret = GetObject(hbm, 0, &ds);
356 ok(ret == 0, "%d != 0\n", ret);
358 ret = GetObject(hbm, 1, &ds);
359 ok(ret == 0, "%d != 0\n", ret);
362 #define test_color_todo(got, exp, txt, todo) \
363 if (!todo && got != exp && screen_depth < 24) { \
364 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
365 screen_depth, (UINT)got, (UINT)exp); \
367 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
368 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
370 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
373 c = SetPixel(hdc, 0, 0, color); \
374 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
375 c = GetPixel(hdc, 0, 0); \
376 test_color_todo(c, exp, GetPixel, todo_getp); \
379 static void test_dibsections(void)
381 HDC hdc, hdcmem, hdcmem2;
382 HBITMAP hdib, oldbm, hdib2, oldbm2;
383 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
384 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
385 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
386 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
392 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
393 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
396 HPALETTE hpal, oldpal;
401 MEMORY_BASIC_INFORMATION info;
404 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
406 memset(pbmi, 0, sizeof(bmibuf));
407 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
408 pbmi->bmiHeader.biHeight = 100;
409 pbmi->bmiHeader.biWidth = 512;
410 pbmi->bmiHeader.biBitCount = 24;
411 pbmi->bmiHeader.biPlanes = 1;
412 pbmi->bmiHeader.biCompression = BI_RGB;
414 SetLastError(0xdeadbeef);
415 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
416 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
417 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
418 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
420 /* test the DIB memory */
421 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
422 "VirtualQuery failed\n");
423 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
424 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
425 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
426 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
427 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
428 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
429 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
431 test_dib_info(hdib, bits, &pbmi->bmiHeader);
434 pbmi->bmiHeader.biBitCount = 8;
435 pbmi->bmiHeader.biCompression = BI_RLE8;
436 SetLastError(0xdeadbeef);
437 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
438 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
439 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
441 pbmi->bmiHeader.biBitCount = 16;
442 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
443 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
444 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
445 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
446 SetLastError(0xdeadbeef);
447 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
448 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
450 /* test the DIB memory */
451 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
452 "VirtualQuery failed\n");
453 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
454 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
455 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
456 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
457 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
458 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
459 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
461 test_dib_info(hdib, bits, &pbmi->bmiHeader);
464 memset(pbmi, 0, sizeof(bmibuf));
465 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
466 pbmi->bmiHeader.biHeight = 16;
467 pbmi->bmiHeader.biWidth = 16;
468 pbmi->bmiHeader.biBitCount = 1;
469 pbmi->bmiHeader.biPlanes = 1;
470 pbmi->bmiHeader.biCompression = BI_RGB;
471 pbmi->bmiColors[0].rgbRed = 0xff;
472 pbmi->bmiColors[0].rgbGreen = 0;
473 pbmi->bmiColors[0].rgbBlue = 0;
474 pbmi->bmiColors[1].rgbRed = 0;
475 pbmi->bmiColors[1].rgbGreen = 0;
476 pbmi->bmiColors[1].rgbBlue = 0xff;
478 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
479 ok(hdib != NULL, "CreateDIBSection failed\n");
480 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
481 ok(dibsec.dsBmih.biClrUsed == 2,
482 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
484 /* Test if the old BITMAPCOREINFO structure is supported */
486 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
487 pbci->bmciHeader.bcBitCount = 0;
490 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
491 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
492 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
493 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
494 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
496 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
497 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
498 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
499 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
500 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
501 "The color table has not been translated to the old BITMAPCOREINFO format\n");
503 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
504 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
506 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
507 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
508 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
509 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
510 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
511 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
512 "The color table has not been translated to the old BITMAPCOREINFO format\n");
514 DeleteObject(hcoredib);
517 hdcmem = CreateCompatibleDC(hdc);
518 oldbm = SelectObject(hdcmem, hdib);
520 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
521 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
522 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
523 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
524 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
525 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
527 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
528 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
530 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
531 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
532 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
533 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
534 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
535 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
536 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
537 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
538 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
539 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
540 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
541 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
542 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
544 SelectObject(hdcmem, oldbm);
547 pbmi->bmiColors[0].rgbRed = 0xff;
548 pbmi->bmiColors[0].rgbGreen = 0xff;
549 pbmi->bmiColors[0].rgbBlue = 0xff;
550 pbmi->bmiColors[1].rgbRed = 0;
551 pbmi->bmiColors[1].rgbGreen = 0;
552 pbmi->bmiColors[1].rgbBlue = 0;
554 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
555 ok(hdib != NULL, "CreateDIBSection failed\n");
557 test_dib_info(hdib, bits, &pbmi->bmiHeader);
559 oldbm = SelectObject(hdcmem, hdib);
561 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
562 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
563 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
564 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
565 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
566 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
568 SelectObject(hdcmem, oldbm);
569 test_dib_info(hdib, bits, &pbmi->bmiHeader);
572 pbmi->bmiHeader.biBitCount = 4;
573 for (i = 0; i < 16; i++) {
574 pbmi->bmiColors[i].rgbRed = i;
575 pbmi->bmiColors[i].rgbGreen = 16-i;
576 pbmi->bmiColors[i].rgbBlue = 0;
578 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
579 ok(hdib != NULL, "CreateDIBSection failed\n");
580 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
581 ok(dibsec.dsBmih.biClrUsed == 16,
582 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
583 test_dib_info(hdib, bits, &pbmi->bmiHeader);
586 pbmi->bmiHeader.biBitCount = 8;
588 for (i = 0; i < 128; i++) {
589 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
590 pbmi->bmiColors[i].rgbGreen = i * 2;
591 pbmi->bmiColors[i].rgbBlue = 0;
592 pbmi->bmiColors[255 - i].rgbRed = 0;
593 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
594 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
596 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
597 ok(hdib != NULL, "CreateDIBSection failed\n");
598 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
599 ok(dibsec.dsBmih.biClrUsed == 256,
600 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
602 oldbm = SelectObject(hdcmem, hdib);
604 for (i = 0; i < 256; i++) {
605 test_color(hdcmem, DIBINDEX(i),
606 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
607 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
608 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
611 SelectObject(hdcmem, oldbm);
612 test_dib_info(hdib, bits, &pbmi->bmiHeader);
615 pbmi->bmiHeader.biBitCount = 1;
617 /* Now create a palette and a palette indexed dib section */
618 memset(plogpal, 0, sizeof(logpalbuf));
619 plogpal->palVersion = 0x300;
620 plogpal->palNumEntries = 2;
621 plogpal->palPalEntry[0].peRed = 0xff;
622 plogpal->palPalEntry[0].peBlue = 0xff;
623 plogpal->palPalEntry[1].peGreen = 0xff;
625 index = (WORD*)pbmi->bmiColors;
628 hpal = CreatePalette(plogpal);
629 ok(hpal != NULL, "CreatePalette failed\n");
630 oldpal = SelectPalette(hdc, hpal, TRUE);
631 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
632 ok(hdib != NULL, "CreateDIBSection failed\n");
633 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
634 ok(dibsec.dsBmih.biClrUsed == 2,
635 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
637 /* The colour table has already been grabbed from the dc, so we select back the
640 SelectPalette(hdc, oldpal, TRUE);
641 oldbm = SelectObject(hdcmem, hdib);
642 oldpal = SelectPalette(hdcmem, hpal, TRUE);
644 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
645 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
646 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
647 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
648 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
649 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
650 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
652 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
653 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
655 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
656 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
657 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
658 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
659 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
660 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
661 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
662 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
663 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
664 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
665 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
666 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
667 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
668 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
669 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
670 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
672 /* Bottom and 2nd row from top green, everything else magenta */
673 bits[0] = bits[1] = 0xff;
674 bits[13 * 4] = bits[13*4 + 1] = 0xff;
676 test_dib_info(hdib, bits, &pbmi->bmiHeader);
678 pbmi->bmiHeader.biBitCount = 32;
680 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
681 ok(hdib2 != NULL, "CreateDIBSection failed\n");
682 hdcmem2 = CreateCompatibleDC(hdc);
683 oldbm2 = SelectObject(hdcmem2, hdib2);
685 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
687 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
688 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32[17]);
690 SelectObject(hdcmem2, oldbm2);
691 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
694 SelectObject(hdcmem, oldbm);
695 SelectObject(hdcmem, oldpal);
700 pbmi->bmiHeader.biBitCount = 8;
702 memset(plogpal, 0, sizeof(logpalbuf));
703 plogpal->palVersion = 0x300;
704 plogpal->palNumEntries = 256;
706 for (i = 0; i < 128; i++) {
707 plogpal->palPalEntry[i].peRed = 255 - i * 2;
708 plogpal->palPalEntry[i].peBlue = i * 2;
709 plogpal->palPalEntry[i].peGreen = 0;
710 plogpal->palPalEntry[255 - i].peRed = 0;
711 plogpal->palPalEntry[255 - i].peGreen = i * 2;
712 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
715 index = (WORD*)pbmi->bmiColors;
716 for (i = 0; i < 256; i++) {
720 hpal = CreatePalette(plogpal);
721 ok(hpal != NULL, "CreatePalette failed\n");
722 oldpal = SelectPalette(hdc, hpal, TRUE);
723 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
724 ok(hdib != NULL, "CreateDIBSection failed\n");
725 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
726 ok(dibsec.dsBmih.biClrUsed == 256,
727 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
729 test_dib_info(hdib, bits, &pbmi->bmiHeader);
731 SelectPalette(hdc, oldpal, TRUE);
732 oldbm = SelectObject(hdcmem, hdib);
733 oldpal = SelectPalette(hdcmem, hpal, TRUE);
735 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
736 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
737 for (i = 0; i < 256; i++) {
738 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
739 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
740 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
741 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
742 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
745 for (i = 0; i < 256; i++) {
746 test_color(hdcmem, DIBINDEX(i),
747 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
748 test_color(hdcmem, PALETTEINDEX(i),
749 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
750 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
751 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
754 SelectPalette(hdcmem, oldpal, TRUE);
755 SelectObject(hdcmem, oldbm);
764 static void test_mono_dibsection(void)
767 HBITMAP old_bm, mono_ds;
768 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
769 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
776 memdc = CreateCompatibleDC(hdc);
778 memset(pbmi, 0, sizeof(bmibuf));
779 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
780 pbmi->bmiHeader.biHeight = 10;
781 pbmi->bmiHeader.biWidth = 10;
782 pbmi->bmiHeader.biBitCount = 1;
783 pbmi->bmiHeader.biPlanes = 1;
784 pbmi->bmiHeader.biCompression = BI_RGB;
785 pbmi->bmiColors[0].rgbRed = 0xff;
786 pbmi->bmiColors[0].rgbGreen = 0xff;
787 pbmi->bmiColors[0].rgbBlue = 0xff;
788 pbmi->bmiColors[1].rgbRed = 0x0;
789 pbmi->bmiColors[1].rgbGreen = 0x0;
790 pbmi->bmiColors[1].rgbBlue = 0x0;
793 * First dib section is 'inverted' ie color[0] is white, color[1] is black
796 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
797 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
798 old_bm = SelectObject(memdc, mono_ds);
800 /* black border, white interior */
801 Rectangle(memdc, 0, 0, 10, 10);
802 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
803 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
805 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
807 memset(bits, 0, sizeof(bits));
810 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
811 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
813 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
815 pbmi->bmiColors[0].rgbRed = 0x0;
816 pbmi->bmiColors[0].rgbGreen = 0x0;
817 pbmi->bmiColors[0].rgbBlue = 0x0;
818 pbmi->bmiColors[1].rgbRed = 0xff;
819 pbmi->bmiColors[1].rgbGreen = 0xff;
820 pbmi->bmiColors[1].rgbBlue = 0xff;
822 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
823 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
825 SelectObject(memdc, old_bm);
826 DeleteObject(mono_ds);
829 * Next dib section is 'normal' ie color[0] is black, color[1] is white
832 pbmi->bmiColors[0].rgbRed = 0x0;
833 pbmi->bmiColors[0].rgbGreen = 0x0;
834 pbmi->bmiColors[0].rgbBlue = 0x0;
835 pbmi->bmiColors[1].rgbRed = 0xff;
836 pbmi->bmiColors[1].rgbGreen = 0xff;
837 pbmi->bmiColors[1].rgbBlue = 0xff;
839 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
840 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
841 old_bm = SelectObject(memdc, mono_ds);
843 /* black border, white interior */
844 Rectangle(memdc, 0, 0, 10, 10);
845 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
846 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
848 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
850 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
851 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
853 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
855 pbmi->bmiColors[0].rgbRed = 0xff;
856 pbmi->bmiColors[0].rgbGreen = 0xff;
857 pbmi->bmiColors[0].rgbBlue = 0xff;
858 pbmi->bmiColors[1].rgbRed = 0x0;
859 pbmi->bmiColors[1].rgbGreen = 0x0;
860 pbmi->bmiColors[1].rgbBlue = 0x0;
862 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
863 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
866 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
869 pbmi->bmiColors[0].rgbRed = 0xff;
870 pbmi->bmiColors[0].rgbGreen = 0xff;
871 pbmi->bmiColors[0].rgbBlue = 0xff;
872 pbmi->bmiColors[1].rgbRed = 0x0;
873 pbmi->bmiColors[1].rgbGreen = 0x0;
874 pbmi->bmiColors[1].rgbBlue = 0x0;
875 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
876 ok(num == 2, "num = %d\n", num);
878 /* black border, white interior */
879 Rectangle(memdc, 0, 0, 10, 10);
881 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
882 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
884 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
886 memset(bits, 0, sizeof(bits));
889 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
890 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
892 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
894 pbmi->bmiColors[0].rgbRed = 0x0;
895 pbmi->bmiColors[0].rgbGreen = 0x0;
896 pbmi->bmiColors[0].rgbBlue = 0x0;
897 pbmi->bmiColors[1].rgbRed = 0xff;
898 pbmi->bmiColors[1].rgbGreen = 0xff;
899 pbmi->bmiColors[1].rgbBlue = 0xff;
901 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
902 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
904 SelectObject(memdc, old_bm);
905 DeleteObject(mono_ds);
908 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
911 pbmi->bmiColors[0].rgbRed = 0xff;
912 pbmi->bmiColors[0].rgbGreen = 0x0;
913 pbmi->bmiColors[0].rgbBlue = 0x0;
914 pbmi->bmiColors[1].rgbRed = 0xfe;
915 pbmi->bmiColors[1].rgbGreen = 0x0;
916 pbmi->bmiColors[1].rgbBlue = 0x0;
918 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
919 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
920 old_bm = SelectObject(memdc, mono_ds);
922 /* black border, white interior */
923 Rectangle(memdc, 0, 0, 10, 10);
924 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
925 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
927 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
929 pbmi->bmiColors[0].rgbRed = 0x0;
930 pbmi->bmiColors[0].rgbGreen = 0x0;
931 pbmi->bmiColors[0].rgbBlue = 0x0;
932 pbmi->bmiColors[1].rgbRed = 0xff;
933 pbmi->bmiColors[1].rgbGreen = 0xff;
934 pbmi->bmiColors[1].rgbBlue = 0xff;
936 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
937 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
939 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
941 pbmi->bmiColors[0].rgbRed = 0xff;
942 pbmi->bmiColors[0].rgbGreen = 0xff;
943 pbmi->bmiColors[0].rgbBlue = 0xff;
944 pbmi->bmiColors[1].rgbRed = 0x0;
945 pbmi->bmiColors[1].rgbGreen = 0x0;
946 pbmi->bmiColors[1].rgbBlue = 0x0;
948 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
949 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
951 SelectObject(memdc, old_bm);
952 DeleteObject(mono_ds);
958 static void test_bitmap(void)
960 char buf[256], buf_cmp[256];
961 HBITMAP hbmp, hbmp_old;
966 hdc = CreateCompatibleDC(0);
969 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
970 assert(hbmp != NULL);
972 ret = GetObject(hbmp, sizeof(bm), &bm);
973 ok(ret == sizeof(bm), "wrong size %d\n", ret);
975 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
976 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
977 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
978 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
979 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
980 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
981 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
983 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
984 assert(sizeof(buf) == sizeof(buf_cmp));
986 ret = GetBitmapBits(hbmp, 0, NULL);
987 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
989 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
990 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
992 memset(buf, 0xAA, sizeof(buf));
993 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
994 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
995 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
997 hbmp_old = SelectObject(hdc, hbmp);
999 ret = GetObject(hbmp, sizeof(bm), &bm);
1000 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1002 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1003 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1004 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1005 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1006 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1007 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1008 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1010 memset(buf, 0xAA, sizeof(buf));
1011 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1012 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1013 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1015 hbmp_old = SelectObject(hdc, hbmp_old);
1016 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1018 /* test various buffer sizes for GetObject */
1019 ret = GetObject(hbmp, sizeof(bm) * 2, &bm);
1020 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1022 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
1023 ok(ret == 0, "%d != 0\n", ret);
1025 ret = GetObject(hbmp, 0, &bm);
1026 ok(ret == 0, "%d != 0\n", ret);
1028 ret = GetObject(hbmp, 1, &bm);
1029 ok(ret == 0, "%d != 0\n", ret);
1035 static void test_bmBits(void)
1041 memset(bits, 0, sizeof(bits));
1042 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1043 ok(hbmp != NULL, "CreateBitmap failed\n");
1045 memset(&bmp, 0xFF, sizeof(bmp));
1046 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1047 "GetObject failed or returned a wrong structure size\n");
1048 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1053 static void test_GetDIBits_selected_DIB(UINT bpp)
1067 /* Create a DIB section with a color table */
1069 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1070 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1074 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1076 /* Choose width and height such that the row length (in bytes)
1077 is a multiple of 4 (makes things easier) */
1078 info->bmiHeader.biWidth = 32;
1079 info->bmiHeader.biHeight = 32;
1080 info->bmiHeader.biPlanes = 1;
1081 info->bmiHeader.biBitCount = bpp;
1082 info->bmiHeader.biCompression = BI_RGB;
1084 for (i=0; i < (1u << bpp); i++)
1086 BYTE c = i * (1 << (8 - bpp));
1087 info->bmiColors[i].rgbRed = c;
1088 info->bmiColors[i].rgbGreen = c;
1089 info->bmiColors[i].rgbBlue = c;
1090 info->bmiColors[i].rgbReserved = 0;
1093 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1095 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1097 /* Set the bits of the DIB section */
1098 for (i=0; i < dib_size; i++)
1100 ((BYTE *)bits)[i] = i % 256;
1103 /* Select the DIB into a DC */
1104 dib_dc = CreateCompatibleDC(NULL);
1105 old_bmp = (HBITMAP) SelectObject(dib_dc, dib);
1106 dc = CreateCompatibleDC(NULL);
1107 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib_size);
1110 /* Copy the DIB attributes but not the color table */
1111 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1113 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1114 ok(res, "GetDIBits failed\n");
1116 /* Compare the color table and the bits */
1117 equalContents = TRUE;
1118 for (i=0; i < (1u << bpp); i++)
1120 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1121 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1122 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1123 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1125 equalContents = FALSE;
1129 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1131 equalContents = TRUE;
1132 for (i=0; i < dib_size / sizeof(DWORD); i++)
1134 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1136 equalContents = FALSE;
1141 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1143 todo_wine ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1145 HeapFree(GetProcessHeap(), 0, bits2);
1148 SelectObject(dib_dc, old_bmp);
1152 HeapFree(GetProcessHeap(), 0, info2);
1153 HeapFree(GetProcessHeap(), 0, info);
1156 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1171 width = height = 16;
1173 /* Create a DDB (device-dependent bitmap) */
1177 ddb = CreateBitmap(width, height, 1, 1, NULL);
1181 HDC screen_dc = GetDC(NULL);
1182 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1183 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1184 ReleaseDC(NULL, screen_dc);
1187 /* Set the pixels */
1188 ddb_dc = CreateCompatibleDC(NULL);
1189 old_bmp = (HBITMAP) SelectObject(ddb_dc, ddb);
1190 for (i = 0; i < width; i++)
1192 for (j=0; j < height; j++)
1194 BYTE c = (i * width + j) % 256;
1195 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1198 SelectObject(ddb_dc, old_bmp);
1200 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1201 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1205 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1206 info->bmiHeader.biWidth = width;
1207 info->bmiHeader.biHeight = height;
1208 info->bmiHeader.biPlanes = 1;
1209 info->bmiHeader.biBitCount = bpp;
1210 info->bmiHeader.biCompression = BI_RGB;
1212 dc = CreateCompatibleDC(NULL);
1214 /* Fill in biSizeImage */
1215 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1216 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1218 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1219 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1224 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1225 ok(res, "GetDIBits failed\n");
1227 /* Copy the DIB attributes but not the color table */
1228 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1230 /* Select the DDB into another DC */
1231 old_bmp = (HBITMAP) SelectObject(ddb_dc, ddb);
1234 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1235 ok(res, "GetDIBits failed\n");
1237 /* Compare the color table and the bits */
1240 equalContents = TRUE;
1241 for (i=0; i < (1u << bpp); i++)
1243 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1244 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1245 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1246 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1248 equalContents = FALSE;
1252 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1255 equalContents = TRUE;
1256 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1258 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1260 equalContents = FALSE;
1263 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1265 HeapFree(GetProcessHeap(), 0, bits2);
1266 HeapFree(GetProcessHeap(), 0, bits);
1269 SelectObject(ddb_dc, old_bmp);
1273 HeapFree(GetProcessHeap(), 0, info2);
1274 HeapFree(GetProcessHeap(), 0, info);
1277 static void test_GetDIBits(void)
1279 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1280 static const BYTE bmp_bits_1[16 * 2] =
1282 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1283 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1284 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1285 0xff,0xff, 0,0, 0xff,0xff, 0,0
1287 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1288 static const BYTE dib_bits_1[16 * 4] =
1290 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1291 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1292 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1293 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1295 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1296 static const BYTE bmp_bits_24[16 * 16*3] =
1298 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1299 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1300 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1301 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1302 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1303 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1304 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1305 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1306 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1307 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1308 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1309 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1310 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1311 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1312 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1313 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1314 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1315 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1316 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1317 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1318 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1319 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1320 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1321 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1322 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1323 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1324 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1325 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1326 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1327 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1328 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1329 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1331 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1332 static const BYTE dib_bits_24[16 * 16*3] =
1334 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1335 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1336 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1337 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1338 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1339 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1340 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1341 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1342 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1343 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1344 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1345 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1346 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1347 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1348 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1349 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1350 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1351 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1352 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1353 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1354 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1355 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1356 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1357 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1358 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1359 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1360 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1361 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1362 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1363 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1364 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1365 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1370 int i, bytes, lines;
1372 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1373 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1377 /* 1-bit source bitmap data */
1378 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1379 ok(hbmp != 0, "CreateBitmap failed\n");
1381 memset(&bm, 0xAA, sizeof(bm));
1382 bytes = GetObject(hbmp, sizeof(bm), &bm);
1383 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1384 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1385 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1386 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1387 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1388 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1389 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1390 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1392 bytes = GetBitmapBits(hbmp, 0, NULL);
1393 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1394 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1395 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1396 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1398 /* retrieve 1-bit DIB data */
1399 memset(bi, 0, sizeof(*bi));
1400 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1401 bi->bmiHeader.biWidth = bm.bmWidth;
1402 bi->bmiHeader.biHeight = bm.bmHeight;
1403 bi->bmiHeader.biPlanes = 1;
1404 bi->bmiHeader.biBitCount = 1;
1405 bi->bmiHeader.biCompression = BI_RGB;
1406 bi->bmiHeader.biSizeImage = 0;
1407 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1408 SetLastError(0xdeadbeef);
1409 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1410 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1411 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
1412 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1414 memset(buf, 0xAA, sizeof(buf));
1415 SetLastError(0xdeadbeef);
1416 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1417 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1418 lines, bm.bmHeight, GetLastError());
1419 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1421 /* the color table consists of black and white */
1422 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1423 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1424 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1425 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1426 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1428 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1429 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1430 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1431 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1432 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1433 for (i = 2; i < 256; i++)
1435 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1436 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1437 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1438 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1439 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1442 /* returned bits are DWORD aligned and upside down */
1444 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1446 /* retrieve 24-bit DIB data */
1447 memset(bi, 0, sizeof(*bi));
1448 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1449 bi->bmiHeader.biWidth = bm.bmWidth;
1450 bi->bmiHeader.biHeight = bm.bmHeight;
1451 bi->bmiHeader.biPlanes = 1;
1452 bi->bmiHeader.biBitCount = 24;
1453 bi->bmiHeader.biCompression = BI_RGB;
1454 bi->bmiHeader.biSizeImage = 0;
1455 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1456 memset(buf, 0xAA, sizeof(buf));
1457 SetLastError(0xdeadbeef);
1458 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1459 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1460 lines, bm.bmHeight, GetLastError());
1461 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1463 /* the color table doesn't exist for 24-bit images */
1464 for (i = 0; i < 256; i++)
1466 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1467 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1468 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1469 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1470 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1473 /* returned bits are DWORD aligned and upside down */
1475 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1478 /* 24-bit source bitmap data */
1479 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1480 ok(hbmp != 0, "CreateBitmap failed\n");
1481 SetLastError(0xdeadbeef);
1482 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1483 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1484 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1485 lines, bm.bmHeight, GetLastError());
1487 memset(&bm, 0xAA, sizeof(bm));
1488 bytes = GetObject(hbmp, sizeof(bm), &bm);
1489 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1490 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1491 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1492 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1493 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1494 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1495 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1496 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1498 bytes = GetBitmapBits(hbmp, 0, NULL);
1499 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1500 bm.bmWidthBytes * bm.bmHeight, bytes);
1501 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1502 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1503 bm.bmWidthBytes * bm.bmHeight, bytes);
1505 /* retrieve 1-bit DIB data */
1506 memset(bi, 0, sizeof(*bi));
1507 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1508 bi->bmiHeader.biWidth = bm.bmWidth;
1509 bi->bmiHeader.biHeight = bm.bmHeight;
1510 bi->bmiHeader.biPlanes = 1;
1511 bi->bmiHeader.biBitCount = 1;
1512 bi->bmiHeader.biCompression = BI_RGB;
1513 bi->bmiHeader.biSizeImage = 0;
1514 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1515 memset(buf, 0xAA, sizeof(buf));
1516 SetLastError(0xdeadbeef);
1517 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1518 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1519 lines, bm.bmHeight, GetLastError());
1520 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1522 /* the color table consists of black and white */
1523 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1524 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1525 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1526 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1527 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1528 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1529 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1530 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1531 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1532 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1533 for (i = 2; i < 256; i++)
1535 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1536 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1537 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1538 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1539 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1542 /* returned bits are DWORD aligned and upside down */
1544 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1546 /* retrieve 24-bit DIB data */
1547 memset(bi, 0, sizeof(*bi));
1548 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1549 bi->bmiHeader.biWidth = bm.bmWidth;
1550 bi->bmiHeader.biHeight = bm.bmHeight;
1551 bi->bmiHeader.biPlanes = 1;
1552 bi->bmiHeader.biBitCount = 24;
1553 bi->bmiHeader.biCompression = BI_RGB;
1554 bi->bmiHeader.biSizeImage = 0;
1555 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1556 memset(buf, 0xAA, sizeof(buf));
1557 SetLastError(0xdeadbeef);
1558 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1559 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1560 lines, bm.bmHeight, GetLastError());
1561 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1563 /* the color table doesn't exist for 24-bit images */
1564 for (i = 0; i < 256; i++)
1566 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1567 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1568 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1569 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1570 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1573 /* returned bits are DWORD aligned and upside down */
1574 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1580 static void test_select_object(void)
1583 HBITMAP hbm, hbm_old;
1585 DWORD depths[] = {8, 15, 16, 24, 32};
1590 ok(hdc != 0, "GetDC(0) failed\n");
1591 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1592 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1594 hbm_old = SelectObject(hdc, hbm);
1595 ok(hbm_old == 0, "SelectObject should fail\n");
1600 hdc = CreateCompatibleDC(0);
1601 ok(hdc != 0, "GetDC(0) failed\n");
1602 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1603 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1605 hbm_old = SelectObject(hdc, hbm);
1606 ok(hbm_old != 0, "SelectObject failed\n");
1607 hbm_old = SelectObject(hdc, hbm_old);
1608 ok(hbm_old == hbm, "SelectObject failed\n");
1612 /* test an 1-bpp bitmap */
1613 planes = GetDeviceCaps(hdc, PLANES);
1616 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
1617 ok(hbm != 0, "CreateBitmap failed\n");
1619 hbm_old = SelectObject(hdc, hbm);
1620 ok(hbm_old != 0, "SelectObject failed\n");
1621 hbm_old = SelectObject(hdc, hbm_old);
1622 ok(hbm_old == hbm, "SelectObject failed\n");
1626 for(i = 0; i < sizeof(depths)/sizeof(depths[0]); i++) {
1627 /* test a color bitmap to dc bpp matching */
1628 planes = GetDeviceCaps(hdc, PLANES);
1629 bpp = GetDeviceCaps(hdc, BITSPIXEL);
1631 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
1632 ok(hbm != 0, "CreateBitmap failed\n");
1634 hbm_old = SelectObject(hdc, hbm);
1635 if(depths[i] == bpp ||
1636 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
1638 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp, depths[i]);
1639 SelectObject(hdc, hbm_old);
1641 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp, depths[i]);
1644 memset(&bm, 0xAA, sizeof(bm));
1645 bytes = GetObject(hbm, sizeof(bm), &bm);
1646 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1647 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1648 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
1649 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
1650 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1651 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
1652 if(depths[i] == 15) {
1653 ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
1655 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1657 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1665 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
1670 ret = GetObjectType(hbmp);
1671 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
1673 ret = GetObject(hbmp, 0, 0);
1674 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
1675 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
1677 memset(&bm, 0xDA, sizeof(bm));
1678 SetLastError(0xdeadbeef);
1679 ret = GetObject(hbmp, sizeof(bm), &bm);
1680 if (!ret) /* XP, only for curObj2 */ return;
1681 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
1682 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
1683 "GetObject returned %d, error %u\n", ret, GetLastError());
1684 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1685 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth %d\n", bm.bmWidth);
1686 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight %d\n", bm.bmHeight);
1687 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1688 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1689 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1690 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1693 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
1695 static void test_CreateBitmap(void)
1698 HDC screenDC = GetDC(0);
1699 HDC hdc = CreateCompatibleDC(screenDC);
1702 /* all of these are the stock monochrome bitmap */
1703 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
1704 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
1705 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
1706 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
1707 HBITMAP curObj1 = (HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP);
1708 HBITMAP curObj2 = (HBITMAP)GetCurrentObject(screenDC, OBJ_BITMAP);
1710 /* these 2 are not the stock monochrome bitmap */
1711 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
1712 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
1714 HBITMAP old1 = (HBITMAP)SelectObject(hdc, bm2);
1715 HBITMAP old2 = (HBITMAP)SelectObject(screenDC, bm3);
1716 SelectObject(hdc, old1);
1717 SelectObject(screenDC, old2);
1719 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
1720 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
1721 bm, bm1, bm4, bm5, curObj1, old1);
1722 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
1723 ok(bm != curObj2 /* XP */ || bm == curObj2 /* Win9x */,
1724 "0: %p, curObj2 %p\n", bm, curObj2);
1725 ok(old2 == 0, "old2 %p\n", old2);
1727 test_mono_1x1_bmp(bm);
1728 test_mono_1x1_bmp(bm1);
1729 test_mono_1x1_bmp(bm2);
1730 test_mono_1x1_bmp(bm3);
1731 test_mono_1x1_bmp(bm4);
1732 test_mono_1x1_bmp(bm5);
1733 test_mono_1x1_bmp(old1);
1734 test_mono_1x1_bmp(curObj1);
1735 test_mono_1x1_bmp(curObj2);
1745 ReleaseDC(0, screenDC);
1747 /* show that Windows ignores the provided bm.bmWidthBytes */
1751 bmp.bmWidthBytes = 28;
1753 bmp.bmBitsPixel = 1;
1755 bm = CreateBitmapIndirect(&bmp);
1756 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
1757 test_mono_1x1_bmp(bm);
1760 /* Test how the bmBitsPixel field is treated */
1761 for(i = 1; i <= 33; i++) {
1765 bmp.bmWidthBytes = 28;
1767 bmp.bmBitsPixel = i;
1769 bm = CreateBitmapIndirect(&bmp);
1771 DWORD error = GetLastError();
1772 ok(bm == 0, "CreateBitmapIndirect for %d bpp succeeded\n", i);
1773 ok(error == ERROR_INVALID_PARAMETER, "Got error %d, expected ERROR_INVALID_PARAMETER\n", error);
1776 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
1777 GetObject(bm, sizeof(bmp), &bmp);
1784 } else if(i <= 16) {
1786 } else if(i <= 24) {
1788 } else if(i <= 32) {
1791 ok(bmp.bmBitsPixel == expect, "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
1792 i, bmp.bmBitsPixel, expect);
1797 static void test_bitmapinfoheadersize(void)
1804 memset(&bmi, 0, sizeof(BITMAPINFO));
1805 bmi.bmiHeader.biHeight = 100;
1806 bmi.bmiHeader.biWidth = 512;
1807 bmi.bmiHeader.biBitCount = 24;
1808 bmi.bmiHeader.biPlanes = 1;
1810 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
1812 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1813 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1815 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1817 SetLastError(0xdeadbeef);
1818 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1819 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1822 bmi.bmiHeader.biSize++;
1824 SetLastError(0xdeadbeef);
1825 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1826 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1829 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
1831 SetLastError(0xdeadbeef);
1832 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1833 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1836 bmi.bmiHeader.biSize++;
1838 SetLastError(0xdeadbeef);
1839 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1840 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1843 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
1845 SetLastError(0xdeadbeef);
1846 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1847 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1850 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
1852 SetLastError(0xdeadbeef);
1853 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1854 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1857 memset(&bci, 0, sizeof(BITMAPCOREINFO));
1858 bci.bmciHeader.bcHeight = 100;
1859 bci.bmciHeader.bcWidth = 512;
1860 bci.bmciHeader.bcBitCount = 24;
1861 bci.bmciHeader.bcPlanes = 1;
1863 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
1865 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1866 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1868 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
1870 SetLastError(0xdeadbeef);
1871 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1872 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1875 bci.bmciHeader.bcSize++;
1877 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1878 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1880 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
1882 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1883 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1888 static void test_get16dibits(void)
1890 BYTE bits[4 * (16 / sizeof(BYTE))];
1892 HDC screen_dc = GetDC(NULL);
1895 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
1897 int overwritten_bytes = 0;
1899 memset(bits, 0, sizeof(bits));
1900 hbmp = CreateBitmap(2, 2, 1, 16, bits);
1901 ok(hbmp != NULL, "CreateBitmap failed\n");
1903 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
1906 memset(info, '!', info_len);
1907 memset(info, 0, sizeof(info->bmiHeader));
1909 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1910 info->bmiHeader.biWidth = 2;
1911 info->bmiHeader.biHeight = 2;
1912 info->bmiHeader.biPlanes = 1;
1913 info->bmiHeader.biCompression = BI_RGB;
1915 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
1916 ok(ret != 0, "GetDIBits failed\n");
1918 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
1920 overwritten_bytes++;
1921 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
1923 HeapFree(GetProcessHeap(), 0, info);
1925 ReleaseDC(NULL, screen_dc);
1928 void test_GdiAlphaBlend()
1930 /* test out-of-bound parameters for GdiAlphaBlend */
1943 BLENDFUNCTION blend;
1945 if (!pGdiAlphaBlend)
1947 skip("GdiAlphaBlend() is not implemented\n");
1951 hdcNull = GetDC(NULL);
1952 hdcDst = CreateCompatibleDC(hdcNull);
1953 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
1954 hdcSrc = CreateCompatibleDC(hdcNull);
1956 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
1957 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1958 bmi.bmiHeader.biHeight = 20;
1959 bmi.bmiHeader.biWidth = 20;
1960 bmi.bmiHeader.biBitCount = 32;
1961 bmi.bmiHeader.biPlanes = 1;
1962 bmi.bmiHeader.biCompression = BI_RGB;
1963 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
1964 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
1966 oldDst = (HBITMAP)SelectObject(hdcDst, bmpDst);
1967 oldSrc = (HBITMAP)SelectObject(hdcSrc, bmpSrc);
1969 blend.BlendOp = AC_SRC_OVER;
1970 blend.BlendFlags = 0;
1971 blend.SourceConstantAlpha = 128;
1972 blend.AlphaFormat = 0;
1974 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
1975 SetLastError(0xdeadbeef);
1976 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
1977 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
1978 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
1979 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
1980 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
1981 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
1983 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
1984 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
1985 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
1986 SetMapMode(hdcSrc, MM_ANISOTROPIC);
1987 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
1988 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
1989 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
1991 SelectObject(hdcDst, oldDst);
1992 SelectObject(hdcSrc, oldSrc);
1993 DeleteObject(bmpSrc);
1994 DeleteObject(bmpDst);
1998 ReleaseDC(NULL, hdcNull);
2005 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
2007 hdll = GetModuleHandle("gdi32.dll");
2008 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
2010 test_createdibitmap();
2012 test_mono_dibsection();
2015 test_GetDIBits_selected_DIB(1);
2016 test_GetDIBits_selected_DIB(4);
2017 test_GetDIBits_selected_DIB(8);
2018 test_GetDIBits_selected_DDB(TRUE);
2019 test_GetDIBits_selected_DDB(FALSE);
2021 test_select_object();
2022 test_CreateBitmap();
2023 test_GdiAlphaBlend();
2024 test_bitmapinfoheadersize();