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;
122 HBITMAP hbm, hbm_colour, hbm_old;
126 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
127 memset(&bmih, 0, sizeof(bmih));
128 bmih.biSize = sizeof(bmih);
132 bmih.biBitCount = 32;
133 bmih.biCompression = BI_RGB;
135 /* First create an un-initialised bitmap. The depth of the bitmap
136 should match that of the hdc and not that supplied in bmih.
139 /* First try 32 bits */
140 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
141 ok(hbm != NULL, "CreateDIBitmap failed\n");
142 test_bitmap_info(hbm, screen_depth, &bmih);
146 bmih.biBitCount = 16;
147 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
148 ok(hbm != NULL, "CreateDIBitmap failed\n");
149 test_bitmap_info(hbm, screen_depth, &bmih);
154 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
155 ok(hbm != NULL, "CreateDIBitmap failed\n");
156 test_bitmap_info(hbm, screen_depth, &bmih);
159 /* Now with a monochrome dc we expect a monochrome bitmap */
160 hdcmem = CreateCompatibleDC(hdc);
162 /* First try 32 bits */
163 bmih.biBitCount = 32;
164 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
165 ok(hbm != NULL, "CreateDIBitmap failed\n");
166 test_bitmap_info(hbm, 1, &bmih);
170 bmih.biBitCount = 16;
171 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
172 ok(hbm != NULL, "CreateDIBitmap failed\n");
173 test_bitmap_info(hbm, 1, &bmih);
178 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
179 ok(hbm != NULL, "CreateDIBitmap failed\n");
180 test_bitmap_info(hbm, 1, &bmih);
183 /* Now select a polychrome bitmap into the dc and we expect
184 screen_depth bitmaps again */
185 hbm_colour = CreateCompatibleBitmap(hdc, 1, 1);
186 hbm_old = SelectObject(hdcmem, hbm_colour);
188 /* First try 32 bits */
189 bmih.biBitCount = 32;
190 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
191 ok(hbm != NULL, "CreateDIBitmap failed\n");
192 test_bitmap_info(hbm, screen_depth, &bmih);
196 bmih.biBitCount = 16;
197 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
198 ok(hbm != NULL, "CreateDIBitmap failed\n");
199 test_bitmap_info(hbm, screen_depth, &bmih);
204 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
205 ok(hbm != NULL, "CreateDIBitmap failed\n");
206 test_bitmap_info(hbm, screen_depth, &bmih);
209 SelectObject(hdcmem, hbm_old);
210 DeleteObject(hbm_colour);
213 /* If hdc == 0 then we get a 1 bpp bitmap */
215 bmih.biBitCount = 32;
216 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
217 ok(hbm != NULL, "CreateDIBitmap failed\n");
218 test_bitmap_info(hbm, 1, &bmih);
225 static INT DIB_GetWidthBytes( int width, int bpp )
231 case 1: words = (width + 31) / 32; break;
232 case 4: words = (width + 7) / 8; break;
233 case 8: words = (width + 3) / 4; break;
235 case 16: words = (width + 1) / 2; break;
236 case 24: words = (width * 3 + 3)/4; break;
237 case 32: words = width; break;
241 trace("Unknown depth %d, please report.\n", bpp );
248 static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
252 INT ret, width_bytes;
255 ret = GetObject(hbm, sizeof(bm), &bm);
256 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
258 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
259 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
260 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
261 width_bytes = DIB_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
262 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
263 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
264 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
265 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
267 buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight + 4096);
269 width_bytes = BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel);
271 /* GetBitmapBits returns not 32-bit aligned data */
272 ret = GetBitmapBits(hbm, 0, NULL);
273 ok(ret == width_bytes * bm.bmHeight, "%d != %d\n", ret, width_bytes * bm.bmHeight);
275 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
276 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
277 ok(ret == width_bytes * bm.bmHeight, "%d != %d\n", ret, width_bytes * bm.bmHeight);
279 HeapFree(GetProcessHeap(), 0, buf);
281 /* test various buffer sizes for GetObject */
282 memset(&ds, 0xAA, sizeof(ds));
283 ret = GetObject(hbm, sizeof(bm) * 2, &bm);
284 ok(ret == sizeof(bm), "wrong size %d\n", ret);
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 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
289 ret = GetObject(hbm, sizeof(bm) / 2, &bm);
290 ok(ret == 0, "%d != 0\n", ret);
292 ret = GetObject(hbm, 0, &bm);
293 ok(ret == 0, "%d != 0\n", ret);
295 ret = GetObject(hbm, 1, &bm);
296 ok(ret == 0, "%d != 0\n", ret);
298 /* test various buffer sizes for GetObject */
299 ret = GetObject(hbm, 0, NULL);
300 ok(ret == sizeof(bm), "wrong size %d\n", ret);
302 memset(&ds, 0xAA, sizeof(ds));
303 ret = GetObject(hbm, sizeof(ds) * 2, &ds);
304 ok(ret == sizeof(ds), "wrong size %d\n", ret);
306 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
307 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%u != %u\n",
308 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
309 ok(bmih->biSizeImage == 0, "%u != 0\n", bmih->biSizeImage);
310 ds.dsBmih.biSizeImage = 0;
312 ok(ds.dsBmih.biSize == bmih->biSize, "%u != %u\n", ds.dsBmih.biSize, bmih->biSize);
313 ok(ds.dsBmih.biWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
314 ok(ds.dsBmih.biHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
315 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
316 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
317 ok(ds.dsBmih.biCompression == bmih->biCompression, "%u != %u\n", ds.dsBmih.biCompression, bmih->biCompression);
318 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%u != %u\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
319 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%u != %u\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
320 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%u != %u\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
322 memset(&ds, 0xAA, sizeof(ds));
323 ret = GetObject(hbm, sizeof(ds) - 4, &ds);
324 ok(ret == sizeof(ds.dsBm), "wrong size %d\n", ret);
325 ok(ds.dsBm.bmWidth == bmih->biWidth, "%u != %u\n", ds.dsBmih.biWidth, bmih->biWidth);
326 ok(ds.dsBm.bmHeight == bmih->biHeight, "%u != %u\n", ds.dsBmih.biHeight, bmih->biHeight);
327 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
329 ret = GetObject(hbm, 0, &ds);
330 ok(ret == 0, "%d != 0\n", ret);
332 ret = GetObject(hbm, 1, &ds);
333 ok(ret == 0, "%d != 0\n", ret);
336 #define test_color_todo(got, exp, txt, todo) \
337 if (!todo && got != exp && screen_depth < 24) { \
338 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
339 screen_depth, (UINT)got, (UINT)exp); \
341 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
342 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
344 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
347 c = SetPixel(hdc, 0, 0, color); \
348 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
349 c = GetPixel(hdc, 0, 0); \
350 test_color_todo(c, exp, GetPixel, todo_getp); \
353 static void test_dibsections(void)
355 HDC hdc, hdcmem, hdcmem2;
356 HBITMAP hdib, oldbm, hdib2, oldbm2;
357 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
358 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
359 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
360 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
366 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
367 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
370 HPALETTE hpal, oldpal;
375 MEMORY_BASIC_INFORMATION info;
378 screen_depth = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
380 memset(pbmi, 0, sizeof(bmibuf));
381 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
382 pbmi->bmiHeader.biHeight = 100;
383 pbmi->bmiHeader.biWidth = 512;
384 pbmi->bmiHeader.biBitCount = 24;
385 pbmi->bmiHeader.biPlanes = 1;
386 pbmi->bmiHeader.biCompression = BI_RGB;
388 SetLastError(0xdeadbeef);
389 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
390 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
391 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
392 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
394 /* test the DIB memory */
395 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
396 "VirtualQuery failed\n");
397 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
398 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
399 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
400 ok(info.RegionSize == 0x26000, "0x%lx != 0x26000\n", info.RegionSize);
401 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
402 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
403 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
405 test_dib_info(hdib, bits, &pbmi->bmiHeader);
408 pbmi->bmiHeader.biBitCount = 8;
409 pbmi->bmiHeader.biCompression = BI_RLE8;
410 SetLastError(0xdeadbeef);
411 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
412 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
413 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
415 pbmi->bmiHeader.biBitCount = 16;
416 pbmi->bmiHeader.biCompression = BI_BITFIELDS;
417 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
418 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
419 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
420 SetLastError(0xdeadbeef);
421 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
422 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
424 /* test the DIB memory */
425 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
426 "VirtualQuery failed\n");
427 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
428 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
429 ok(info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect);
430 ok(info.RegionSize == 0x19000, "0x%lx != 0x19000\n", info.RegionSize);
431 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
432 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
433 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
435 test_dib_info(hdib, bits, &pbmi->bmiHeader);
438 memset(pbmi, 0, sizeof(bmibuf));
439 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
440 pbmi->bmiHeader.biHeight = 16;
441 pbmi->bmiHeader.biWidth = 16;
442 pbmi->bmiHeader.biBitCount = 1;
443 pbmi->bmiHeader.biPlanes = 1;
444 pbmi->bmiHeader.biCompression = BI_RGB;
445 pbmi->bmiColors[0].rgbRed = 0xff;
446 pbmi->bmiColors[0].rgbGreen = 0;
447 pbmi->bmiColors[0].rgbBlue = 0;
448 pbmi->bmiColors[1].rgbRed = 0;
449 pbmi->bmiColors[1].rgbGreen = 0;
450 pbmi->bmiColors[1].rgbBlue = 0xff;
452 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
453 ok(hdib != NULL, "CreateDIBSection failed\n");
454 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
455 ok(dibsec.dsBmih.biClrUsed == 2,
456 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
458 /* Test if the old BITMAPCOREINFO structure is supported */
460 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
461 pbci->bmciHeader.bcBitCount = 0;
464 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
465 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
466 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
467 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
468 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
470 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
471 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
472 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
473 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
474 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
475 "The color table has not been translated to the old BITMAPCOREINFO format\n");
477 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
478 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
480 ZeroMemory(pbci->bmciColors, 256 * sizeof(RGBTRIPLE));
481 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
482 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
483 ok((pbci->bmciColors[0].rgbtRed == 0xff) && (pbci->bmciColors[0].rgbtGreen == 0) &&
484 (pbci->bmciColors[0].rgbtBlue == 0) && (pbci->bmciColors[1].rgbtRed == 0) &&
485 (pbci->bmciColors[1].rgbtGreen == 0) && (pbci->bmciColors[1].rgbtBlue == 0xff),
486 "The color table has not been translated to the old BITMAPCOREINFO format\n");
488 DeleteObject(hcoredib);
491 hdcmem = CreateCompatibleDC(hdc);
492 oldbm = SelectObject(hdcmem, hdib);
494 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
495 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
496 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
497 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
498 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
499 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
501 c0 = RGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen, pbmi->bmiColors[0].rgbBlue);
502 c1 = RGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen, pbmi->bmiColors[1].rgbBlue);
504 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
505 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
506 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
507 test_color(hdcmem, PALETTEINDEX(0), c0, 1, 1);
508 test_color(hdcmem, PALETTEINDEX(1), c0, 1, 1);
509 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
510 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[0].rgbRed, pbmi->bmiColors[0].rgbGreen,
511 pbmi->bmiColors[0].rgbBlue), c0, 1, 1);
512 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[1].rgbRed, pbmi->bmiColors[1].rgbGreen,
513 pbmi->bmiColors[1].rgbBlue), c1, 1, 1);
514 test_color(hdcmem, PALETTERGB(0, 0, 0), c0, 1, 1);
515 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
516 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1, 1, 1);
518 SelectObject(hdcmem, oldbm);
521 pbmi->bmiColors[0].rgbRed = 0xff;
522 pbmi->bmiColors[0].rgbGreen = 0xff;
523 pbmi->bmiColors[0].rgbBlue = 0xff;
524 pbmi->bmiColors[1].rgbRed = 0;
525 pbmi->bmiColors[1].rgbGreen = 0;
526 pbmi->bmiColors[1].rgbBlue = 0;
528 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
529 ok(hdib != NULL, "CreateDIBSection failed\n");
531 test_dib_info(hdib, bits, &pbmi->bmiHeader);
533 oldbm = SelectObject(hdcmem, hdib);
535 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
536 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
537 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
538 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
539 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
540 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
542 SelectObject(hdcmem, oldbm);
543 test_dib_info(hdib, bits, &pbmi->bmiHeader);
546 pbmi->bmiHeader.biBitCount = 4;
547 for (i = 0; i < 16; i++) {
548 pbmi->bmiColors[i].rgbRed = i;
549 pbmi->bmiColors[i].rgbGreen = 16-i;
550 pbmi->bmiColors[i].rgbBlue = 0;
552 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
553 ok(hdib != NULL, "CreateDIBSection failed\n");
554 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
555 ok(dibsec.dsBmih.biClrUsed == 16,
556 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
557 test_dib_info(hdib, bits, &pbmi->bmiHeader);
560 pbmi->bmiHeader.biBitCount = 8;
562 for (i = 0; i < 128; i++) {
563 pbmi->bmiColors[i].rgbRed = 255 - i * 2;
564 pbmi->bmiColors[i].rgbGreen = i * 2;
565 pbmi->bmiColors[i].rgbBlue = 0;
566 pbmi->bmiColors[255 - i].rgbRed = 0;
567 pbmi->bmiColors[255 - i].rgbGreen = i * 2;
568 pbmi->bmiColors[255 - i].rgbBlue = 255 - i * 2;
570 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
571 ok(hdib != NULL, "CreateDIBSection failed\n");
572 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
573 ok(dibsec.dsBmih.biClrUsed == 256,
574 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
576 oldbm = SelectObject(hdcmem, hdib);
578 for (i = 0; i < 256; i++) {
579 test_color(hdcmem, DIBINDEX(i),
580 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
581 test_color(hdcmem, PALETTERGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue),
582 RGB(pbmi->bmiColors[i].rgbRed, pbmi->bmiColors[i].rgbGreen, pbmi->bmiColors[i].rgbBlue), 0, 0);
585 SelectObject(hdcmem, oldbm);
586 test_dib_info(hdib, bits, &pbmi->bmiHeader);
589 pbmi->bmiHeader.biBitCount = 1;
591 /* Now create a palette and a palette indexed dib section */
592 memset(plogpal, 0, sizeof(logpalbuf));
593 plogpal->palVersion = 0x300;
594 plogpal->palNumEntries = 2;
595 plogpal->palPalEntry[0].peRed = 0xff;
596 plogpal->palPalEntry[0].peBlue = 0xff;
597 plogpal->palPalEntry[1].peGreen = 0xff;
599 index = (WORD*)pbmi->bmiColors;
602 hpal = CreatePalette(plogpal);
603 ok(hpal != NULL, "CreatePalette failed\n");
604 oldpal = SelectPalette(hdc, hpal, TRUE);
605 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
606 ok(hdib != NULL, "CreateDIBSection failed\n");
607 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
608 ok(dibsec.dsBmih.biClrUsed == 2,
609 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
611 /* The colour table has already been grabbed from the dc, so we select back the
614 SelectPalette(hdc, oldpal, TRUE);
615 oldbm = SelectObject(hdcmem, hdib);
616 oldpal = SelectPalette(hdcmem, hpal, TRUE);
618 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
619 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
620 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
621 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
622 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
623 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
624 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
626 c0 = RGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen, plogpal->palPalEntry[0].peBlue);
627 c1 = RGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen, plogpal->palPalEntry[1].peBlue);
629 test_color(hdcmem, DIBINDEX(0), c0, 0, 1);
630 test_color(hdcmem, DIBINDEX(1), c1, 0, 1);
631 test_color(hdcmem, DIBINDEX(2), c0, 1, 1);
632 test_color(hdcmem, PALETTEINDEX(0), c0, 0, 1);
633 test_color(hdcmem, PALETTEINDEX(1), c1, 0, 1);
634 test_color(hdcmem, PALETTEINDEX(2), c0, 1, 1);
635 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[0].peRed, plogpal->palPalEntry[0].peGreen,
636 plogpal->palPalEntry[0].peBlue), c0, 1, 1);
637 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[1].peRed, plogpal->palPalEntry[1].peGreen,
638 plogpal->palPalEntry[1].peBlue), c1, 1, 1);
639 test_color(hdcmem, PALETTERGB(0, 0, 0), c1, 1, 1);
640 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0, 1, 1);
641 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0, 1, 1);
642 test_color(hdcmem, PALETTERGB(0, 1, 0), c1, 1, 1);
643 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1, 1, 1);
644 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0, 1, 1);
646 /* Bottom and 2nd row from top green, everything else magenta */
647 bits[0] = bits[1] = 0xff;
648 bits[13 * 4] = bits[13*4 + 1] = 0xff;
650 test_dib_info(hdib, bits, &pbmi->bmiHeader);
652 pbmi->bmiHeader.biBitCount = 32;
654 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
655 ok(hdib2 != NULL, "CreateDIBSection failed\n");
656 hdcmem2 = CreateCompatibleDC(hdc);
657 oldbm2 = SelectObject(hdcmem2, hdib2);
659 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
661 ok(bits32[0] == 0xff00, "lower left pixel is %08x\n", bits32[0]);
662 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32[17]);
664 SelectObject(hdcmem2, oldbm2);
665 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
668 SelectObject(hdcmem, oldbm);
669 SelectObject(hdcmem, oldpal);
674 pbmi->bmiHeader.biBitCount = 8;
676 memset(plogpal, 0, sizeof(logpalbuf));
677 plogpal->palVersion = 0x300;
678 plogpal->palNumEntries = 256;
680 for (i = 0; i < 128; i++) {
681 plogpal->palPalEntry[i].peRed = 255 - i * 2;
682 plogpal->palPalEntry[i].peBlue = i * 2;
683 plogpal->palPalEntry[i].peGreen = 0;
684 plogpal->palPalEntry[255 - i].peRed = 0;
685 plogpal->palPalEntry[255 - i].peGreen = i * 2;
686 plogpal->palPalEntry[255 - i].peBlue = 255 - i * 2;
689 index = (WORD*)pbmi->bmiColors;
690 for (i = 0; i < 256; i++) {
694 hpal = CreatePalette(plogpal);
695 ok(hpal != NULL, "CreatePalette failed\n");
696 oldpal = SelectPalette(hdc, hpal, TRUE);
697 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
698 ok(hdib != NULL, "CreateDIBSection failed\n");
699 ok(GetObject(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
700 ok(dibsec.dsBmih.biClrUsed == 256,
701 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
703 test_dib_info(hdib, bits, &pbmi->bmiHeader);
705 SelectPalette(hdc, oldpal, TRUE);
706 oldbm = SelectObject(hdcmem, hdib);
707 oldpal = SelectPalette(hdcmem, hpal, TRUE);
709 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
710 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
711 for (i = 0; i < 256; i++) {
712 ok(rgb[i].rgbRed == plogpal->palPalEntry[i].peRed &&
713 rgb[i].rgbBlue == plogpal->palPalEntry[i].peBlue &&
714 rgb[i].rgbGreen == plogpal->palPalEntry[i].peGreen,
715 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
716 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
719 for (i = 0; i < 256; i++) {
720 test_color(hdcmem, DIBINDEX(i),
721 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
722 test_color(hdcmem, PALETTEINDEX(i),
723 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
724 test_color(hdcmem, PALETTERGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue),
725 RGB(plogpal->palPalEntry[i].peRed, plogpal->palPalEntry[i].peGreen, plogpal->palPalEntry[i].peBlue), 0, 0);
728 SelectPalette(hdcmem, oldpal, TRUE);
729 SelectObject(hdcmem, oldbm);
738 static void test_mono_dibsection(void)
741 HBITMAP old_bm, mono_ds;
742 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
743 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
750 memdc = CreateCompatibleDC(hdc);
752 memset(pbmi, 0, sizeof(bmibuf));
753 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
754 pbmi->bmiHeader.biHeight = 10;
755 pbmi->bmiHeader.biWidth = 10;
756 pbmi->bmiHeader.biBitCount = 1;
757 pbmi->bmiHeader.biPlanes = 1;
758 pbmi->bmiHeader.biCompression = BI_RGB;
759 pbmi->bmiColors[0].rgbRed = 0xff;
760 pbmi->bmiColors[0].rgbGreen = 0xff;
761 pbmi->bmiColors[0].rgbBlue = 0xff;
762 pbmi->bmiColors[1].rgbRed = 0x0;
763 pbmi->bmiColors[1].rgbGreen = 0x0;
764 pbmi->bmiColors[1].rgbBlue = 0x0;
767 * First dib section is 'inverted' ie color[0] is white, color[1] is black
770 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
771 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
772 old_bm = SelectObject(memdc, mono_ds);
774 /* black border, white interior */
775 Rectangle(memdc, 0, 0, 10, 10);
776 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
777 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
779 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
781 memset(bits, 0, sizeof(bits));
784 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
785 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
787 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
789 pbmi->bmiColors[0].rgbRed = 0x0;
790 pbmi->bmiColors[0].rgbGreen = 0x0;
791 pbmi->bmiColors[0].rgbBlue = 0x0;
792 pbmi->bmiColors[1].rgbRed = 0xff;
793 pbmi->bmiColors[1].rgbGreen = 0xff;
794 pbmi->bmiColors[1].rgbBlue = 0xff;
796 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
797 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
799 SelectObject(memdc, old_bm);
800 DeleteObject(mono_ds);
803 * Next dib section is 'normal' ie color[0] is black, color[1] is white
806 pbmi->bmiColors[0].rgbRed = 0x0;
807 pbmi->bmiColors[0].rgbGreen = 0x0;
808 pbmi->bmiColors[0].rgbBlue = 0x0;
809 pbmi->bmiColors[1].rgbRed = 0xff;
810 pbmi->bmiColors[1].rgbGreen = 0xff;
811 pbmi->bmiColors[1].rgbBlue = 0xff;
813 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
814 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
815 old_bm = SelectObject(memdc, mono_ds);
817 /* black border, white interior */
818 Rectangle(memdc, 0, 0, 10, 10);
819 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
820 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
822 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
824 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
825 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
827 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
829 pbmi->bmiColors[0].rgbRed = 0xff;
830 pbmi->bmiColors[0].rgbGreen = 0xff;
831 pbmi->bmiColors[0].rgbBlue = 0xff;
832 pbmi->bmiColors[1].rgbRed = 0x0;
833 pbmi->bmiColors[1].rgbGreen = 0x0;
834 pbmi->bmiColors[1].rgbBlue = 0x0;
836 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
837 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
840 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
843 pbmi->bmiColors[0].rgbRed = 0xff;
844 pbmi->bmiColors[0].rgbGreen = 0xff;
845 pbmi->bmiColors[0].rgbBlue = 0xff;
846 pbmi->bmiColors[1].rgbRed = 0x0;
847 pbmi->bmiColors[1].rgbGreen = 0x0;
848 pbmi->bmiColors[1].rgbBlue = 0x0;
849 num = SetDIBColorTable(memdc, 0, 2, pbmi->bmiColors);
850 ok(num == 2, "num = %d\n", num);
852 /* black border, white interior */
853 Rectangle(memdc, 0, 0, 10, 10);
855 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
856 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
858 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
860 memset(bits, 0, sizeof(bits));
863 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
864 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
866 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
868 pbmi->bmiColors[0].rgbRed = 0x0;
869 pbmi->bmiColors[0].rgbGreen = 0x0;
870 pbmi->bmiColors[0].rgbBlue = 0x0;
871 pbmi->bmiColors[1].rgbRed = 0xff;
872 pbmi->bmiColors[1].rgbGreen = 0xff;
873 pbmi->bmiColors[1].rgbBlue = 0xff;
875 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
876 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
878 SelectObject(memdc, old_bm);
879 DeleteObject(mono_ds);
882 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
885 pbmi->bmiColors[0].rgbRed = 0xff;
886 pbmi->bmiColors[0].rgbGreen = 0x0;
887 pbmi->bmiColors[0].rgbBlue = 0x0;
888 pbmi->bmiColors[1].rgbRed = 0xfe;
889 pbmi->bmiColors[1].rgbGreen = 0x0;
890 pbmi->bmiColors[1].rgbBlue = 0x0;
892 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
893 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
894 old_bm = SelectObject(memdc, mono_ds);
896 /* black border, white interior */
897 Rectangle(memdc, 0, 0, 10, 10);
898 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
899 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
901 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
903 pbmi->bmiColors[0].rgbRed = 0x0;
904 pbmi->bmiColors[0].rgbGreen = 0x0;
905 pbmi->bmiColors[0].rgbBlue = 0x0;
906 pbmi->bmiColors[1].rgbRed = 0xff;
907 pbmi->bmiColors[1].rgbGreen = 0xff;
908 pbmi->bmiColors[1].rgbBlue = 0xff;
910 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
911 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
913 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
915 pbmi->bmiColors[0].rgbRed = 0xff;
916 pbmi->bmiColors[0].rgbGreen = 0xff;
917 pbmi->bmiColors[0].rgbBlue = 0xff;
918 pbmi->bmiColors[1].rgbRed = 0x0;
919 pbmi->bmiColors[1].rgbGreen = 0x0;
920 pbmi->bmiColors[1].rgbBlue = 0x0;
922 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
923 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
925 SelectObject(memdc, old_bm);
926 DeleteObject(mono_ds);
932 static void test_bitmap(void)
934 char buf[256], buf_cmp[256];
935 HBITMAP hbmp, hbmp_old;
940 hdc = CreateCompatibleDC(0);
943 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
944 assert(hbmp != NULL);
946 ret = GetObject(hbmp, sizeof(bm), &bm);
947 ok(ret == sizeof(bm), "wrong size %d\n", ret);
949 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
950 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
951 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
952 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
953 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
954 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
955 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
957 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
958 assert(sizeof(buf) == sizeof(buf_cmp));
960 ret = GetBitmapBits(hbmp, 0, NULL);
961 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
963 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
964 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
966 memset(buf, 0xAA, sizeof(buf));
967 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
968 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
969 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
971 hbmp_old = SelectObject(hdc, hbmp);
973 ret = GetObject(hbmp, sizeof(bm), &bm);
974 ok(ret == sizeof(bm), "wrong size %d\n", ret);
976 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
977 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
978 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
979 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
980 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
981 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
982 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
984 memset(buf, 0xAA, sizeof(buf));
985 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
986 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
987 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
989 hbmp_old = SelectObject(hdc, hbmp_old);
990 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
992 /* test various buffer sizes for GetObject */
993 ret = GetObject(hbmp, sizeof(bm) * 2, &bm);
994 ok(ret == sizeof(bm), "wrong size %d\n", ret);
996 ret = GetObject(hbmp, sizeof(bm) / 2, &bm);
997 ok(ret == 0, "%d != 0\n", ret);
999 ret = GetObject(hbmp, 0, &bm);
1000 ok(ret == 0, "%d != 0\n", ret);
1002 ret = GetObject(hbmp, 1, &bm);
1003 ok(ret == 0, "%d != 0\n", ret);
1009 static void test_bmBits(void)
1015 memset(bits, 0, sizeof(bits));
1016 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1017 ok(hbmp != NULL, "CreateBitmap failed\n");
1019 memset(&bmp, 0xFF, sizeof(bmp));
1020 ok(GetObject(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1021 "GetObject failed or returned a wrong structure size\n");
1022 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1027 static void test_GetDIBits_selected_DIB(UINT bpp)
1041 /* Create a DIB section with a color table */
1043 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1044 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + (1 << bpp) * sizeof(RGBQUAD));
1048 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1050 /* Choose width and height such that the row length (in bytes)
1051 is a multiple of 4 (makes things easier) */
1052 info->bmiHeader.biWidth = 32;
1053 info->bmiHeader.biHeight = 32;
1054 info->bmiHeader.biPlanes = 1;
1055 info->bmiHeader.biBitCount = bpp;
1056 info->bmiHeader.biCompression = BI_RGB;
1058 for (i=0; i < (1u << bpp); i++)
1060 BYTE c = i * (1 << (8 - bpp));
1061 info->bmiColors[i].rgbRed = c;
1062 info->bmiColors[i].rgbGreen = c;
1063 info->bmiColors[i].rgbBlue = c;
1064 info->bmiColors[i].rgbReserved = 0;
1067 dib = CreateDIBSection(NULL, info, DIB_RGB_COLORS, &bits, NULL, 0);
1069 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1071 /* Set the bits of the DIB section */
1072 for (i=0; i < dib_size; i++)
1074 ((BYTE *)bits)[i] = i % 256;
1077 /* Select the DIB into a DC */
1078 dib_dc = CreateCompatibleDC(NULL);
1079 old_bmp = (HBITMAP) SelectObject(dib_dc, dib);
1080 dc = CreateCompatibleDC(NULL);
1081 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dib_size);
1084 /* Copy the DIB attributes but not the color table */
1085 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1087 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1088 ok(res, "GetDIBits failed\n");
1090 /* Compare the color table and the bits */
1091 equalContents = TRUE;
1092 for (i=0; i < (1u << bpp); i++)
1094 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1095 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1096 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1097 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1099 equalContents = FALSE;
1103 ok(equalContents, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1105 equalContents = TRUE;
1106 for (i=0; i < dib_size / sizeof(DWORD); i++)
1108 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1110 equalContents = FALSE;
1115 ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1117 todo_wine ok(equalContents, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp);
1119 HeapFree(GetProcessHeap(), 0, bits2);
1122 SelectObject(dib_dc, old_bmp);
1126 HeapFree(GetProcessHeap(), 0, info2);
1127 HeapFree(GetProcessHeap(), 0, info);
1130 static void test_GetDIBits_selected_DDB(BOOL monochrome)
1145 width = height = 16;
1147 /* Create a DDB (device-dependent bitmap) */
1151 ddb = CreateBitmap(width, height, 1, 1, NULL);
1155 HDC screen_dc = GetDC(NULL);
1156 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1157 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1158 ReleaseDC(NULL, screen_dc);
1161 /* Set the pixels */
1162 ddb_dc = CreateCompatibleDC(NULL);
1163 old_bmp = (HBITMAP) SelectObject(ddb_dc, ddb);
1164 for (i = 0; i < width; i++)
1166 for (j=0; j < height; j++)
1168 BYTE c = (i * width + j) % 256;
1169 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1172 SelectObject(ddb_dc, old_bmp);
1174 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1175 info2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1179 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1180 info->bmiHeader.biWidth = width;
1181 info->bmiHeader.biHeight = height;
1182 info->bmiHeader.biPlanes = 1;
1183 info->bmiHeader.biBitCount = bpp;
1184 info->bmiHeader.biCompression = BI_RGB;
1186 dc = CreateCompatibleDC(NULL);
1188 /* Fill in biSizeImage */
1189 GetDIBits(dc, ddb, 0, height, NULL, info, DIB_RGB_COLORS);
1190 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1192 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1193 bits2 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info->bmiHeader.biSizeImage);
1198 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1199 ok(res, "GetDIBits failed\n");
1201 /* Copy the DIB attributes but not the color table */
1202 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1204 /* Select the DDB into another DC */
1205 old_bmp = (HBITMAP) SelectObject(ddb_dc, ddb);
1208 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1209 ok(res, "GetDIBits failed\n");
1211 /* Compare the color table and the bits */
1214 equalContents = TRUE;
1215 for (i=0; i < (1u << bpp); i++)
1217 if ((info->bmiColors[i].rgbRed != info2->bmiColors[i].rgbRed)
1218 || (info->bmiColors[i].rgbGreen != info2->bmiColors[i].rgbGreen)
1219 || (info->bmiColors[i].rgbBlue != info2->bmiColors[i].rgbBlue)
1220 || (info->bmiColors[i].rgbReserved != info2->bmiColors[i].rgbReserved))
1222 equalContents = FALSE;
1226 ok(equalContents, "GetDIBits with DDB selected in DC: Got a different color table\n");
1229 equalContents = TRUE;
1230 for (i=0; i < info->bmiHeader.biSizeImage / sizeof(DWORD); i++)
1232 if (((DWORD *)bits)[i] != ((DWORD *)bits2)[i])
1234 equalContents = FALSE;
1237 ok(equalContents, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1239 HeapFree(GetProcessHeap(), 0, bits2);
1240 HeapFree(GetProcessHeap(), 0, bits);
1243 SelectObject(ddb_dc, old_bmp);
1247 HeapFree(GetProcessHeap(), 0, info2);
1248 HeapFree(GetProcessHeap(), 0, info);
1251 static void test_GetDIBits(void)
1253 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1254 static const BYTE bmp_bits_1[16 * 2] =
1256 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1257 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1258 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1259 0xff,0xff, 0,0, 0xff,0xff, 0,0
1261 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1262 static const BYTE dib_bits_1[16 * 4] =
1264 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1265 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1266 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1267 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1269 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1270 static const BYTE bmp_bits_24[16 * 16*3] =
1272 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1273 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1274 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1275 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1276 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1277 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1278 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1279 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1280 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1281 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1282 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1283 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1284 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1285 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1286 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1287 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1288 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1289 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1290 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1291 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1292 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1293 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1294 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1295 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1296 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1297 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1298 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1299 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1300 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1301 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1302 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1303 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 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1306 static const BYTE dib_bits_24[16 * 16*3] =
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,
1330 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1331 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1332 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1333 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1334 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1335 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1336 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1337 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1338 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1339 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1344 int i, bytes, lines;
1346 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
1347 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
1351 /* 1-bit source bitmap data */
1352 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
1353 ok(hbmp != 0, "CreateBitmap failed\n");
1355 memset(&bm, 0xAA, sizeof(bm));
1356 bytes = GetObject(hbmp, sizeof(bm), &bm);
1357 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1358 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1359 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1360 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1361 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1362 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1363 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1364 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1366 bytes = GetBitmapBits(hbmp, 0, NULL);
1367 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1368 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1369 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
1370 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
1372 /* retrieve 1-bit DIB data */
1373 memset(bi, 0, sizeof(*bi));
1374 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1375 bi->bmiHeader.biWidth = bm.bmWidth;
1376 bi->bmiHeader.biHeight = bm.bmHeight;
1377 bi->bmiHeader.biPlanes = 1;
1378 bi->bmiHeader.biBitCount = 1;
1379 bi->bmiHeader.biCompression = BI_RGB;
1380 bi->bmiHeader.biSizeImage = 0;
1381 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1382 SetLastError(0xdeadbeef);
1383 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1384 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
1385 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
1386 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %u\n", bi->bmiHeader.biSizeImage);
1388 memset(buf, 0xAA, sizeof(buf));
1389 SetLastError(0xdeadbeef);
1390 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1391 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1392 lines, bm.bmHeight, GetLastError());
1393 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1395 /* the color table consists of black and white */
1396 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1397 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1398 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1399 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1400 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1402 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1403 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1404 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1405 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1406 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1407 for (i = 2; i < 256; i++)
1409 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1410 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1411 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1412 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1413 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1416 /* returned bits are DWORD aligned and upside down */
1418 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1420 /* retrieve 24-bit DIB data */
1421 memset(bi, 0, sizeof(*bi));
1422 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1423 bi->bmiHeader.biWidth = bm.bmWidth;
1424 bi->bmiHeader.biHeight = bm.bmHeight;
1425 bi->bmiHeader.biPlanes = 1;
1426 bi->bmiHeader.biBitCount = 24;
1427 bi->bmiHeader.biCompression = BI_RGB;
1428 bi->bmiHeader.biSizeImage = 0;
1429 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1430 memset(buf, 0xAA, sizeof(buf));
1431 SetLastError(0xdeadbeef);
1432 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1433 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1434 lines, bm.bmHeight, GetLastError());
1435 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1437 /* the color table doesn't exist for 24-bit images */
1438 for (i = 0; i < 256; i++)
1440 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1441 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1442 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1443 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1444 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1447 /* returned bits are DWORD aligned and upside down */
1449 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1452 /* 24-bit source bitmap data */
1453 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
1454 ok(hbmp != 0, "CreateBitmap failed\n");
1455 SetLastError(0xdeadbeef);
1456 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
1457 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
1458 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %u\n",
1459 lines, bm.bmHeight, GetLastError());
1461 memset(&bm, 0xAA, sizeof(bm));
1462 bytes = GetObject(hbmp, sizeof(bm), &bm);
1463 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
1464 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1465 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
1466 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
1467 ok(bm.bmWidthBytes == BITMAP_GetWidthBytes(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1468 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
1469 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1470 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1472 bytes = GetBitmapBits(hbmp, 0, NULL);
1473 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1474 bm.bmWidthBytes * bm.bmHeight, bytes);
1475 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
1476 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
1477 bm.bmWidthBytes * bm.bmHeight, bytes);
1479 /* retrieve 1-bit DIB data */
1480 memset(bi, 0, sizeof(*bi));
1481 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1482 bi->bmiHeader.biWidth = bm.bmWidth;
1483 bi->bmiHeader.biHeight = bm.bmHeight;
1484 bi->bmiHeader.biPlanes = 1;
1485 bi->bmiHeader.biBitCount = 1;
1486 bi->bmiHeader.biCompression = BI_RGB;
1487 bi->bmiHeader.biSizeImage = 0;
1488 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1489 memset(buf, 0xAA, sizeof(buf));
1490 SetLastError(0xdeadbeef);
1491 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1492 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1493 lines, bm.bmHeight, GetLastError());
1494 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %u\n", bi->bmiHeader.biSizeImage);
1496 /* the color table consists of black and white */
1497 ok(bi->bmiColors[0].rgbRed == 0 && bi->bmiColors[0].rgbGreen == 0 &&
1498 bi->bmiColors[0].rgbBlue == 0 && bi->bmiColors[0].rgbReserved == 0,
1499 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1500 bi->bmiColors[0].rgbRed, bi->bmiColors[0].rgbGreen,
1501 bi->bmiColors[0].rgbBlue, bi->bmiColors[0].rgbReserved);
1502 ok(bi->bmiColors[1].rgbRed == 0xff && bi->bmiColors[1].rgbGreen == 0xff &&
1503 bi->bmiColors[1].rgbBlue == 0xff && bi->bmiColors[1].rgbReserved == 0,
1504 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1505 bi->bmiColors[1].rgbRed, bi->bmiColors[1].rgbGreen,
1506 bi->bmiColors[1].rgbBlue, bi->bmiColors[1].rgbReserved);
1507 for (i = 2; i < 256; i++)
1509 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1510 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1511 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1512 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1513 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1516 /* returned bits are DWORD aligned and upside down */
1518 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
1520 /* retrieve 24-bit DIB data */
1521 memset(bi, 0, sizeof(*bi));
1522 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1523 bi->bmiHeader.biWidth = bm.bmWidth;
1524 bi->bmiHeader.biHeight = bm.bmHeight;
1525 bi->bmiHeader.biPlanes = 1;
1526 bi->bmiHeader.biBitCount = 24;
1527 bi->bmiHeader.biCompression = BI_RGB;
1528 bi->bmiHeader.biSizeImage = 0;
1529 memset(bi->bmiColors, 0xAA, sizeof(RGBQUAD) * 256);
1530 memset(buf, 0xAA, sizeof(buf));
1531 SetLastError(0xdeadbeef);
1532 lines = GetDIBits(hdc, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
1533 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %u\n",
1534 lines, bm.bmHeight, GetLastError());
1535 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %u\n", bi->bmiHeader.biSizeImage);
1537 /* the color table doesn't exist for 24-bit images */
1538 for (i = 0; i < 256; i++)
1540 ok(bi->bmiColors[i].rgbRed == 0xAA && bi->bmiColors[i].rgbGreen == 0xAA &&
1541 bi->bmiColors[i].rgbBlue == 0xAA && bi->bmiColors[i].rgbReserved == 0xAA,
1542 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
1543 bi->bmiColors[i].rgbRed, bi->bmiColors[i].rgbGreen,
1544 bi->bmiColors[i].rgbBlue, bi->bmiColors[i].rgbReserved);
1547 /* returned bits are DWORD aligned and upside down */
1548 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
1554 static void test_select_object(void)
1557 HBITMAP hbm, hbm_old;
1561 ok(hdc != 0, "GetDC(0) failed\n");
1562 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1563 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1565 hbm_old = SelectObject(hdc, hbm);
1566 ok(hbm_old == 0, "SelectObject should fail\n");
1571 hdc = CreateCompatibleDC(0);
1572 ok(hdc != 0, "GetDC(0) failed\n");
1573 hbm = CreateCompatibleBitmap(hdc, 10, 10);
1574 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
1576 hbm_old = SelectObject(hdc, hbm);
1577 ok(hbm_old != 0, "SelectObject failed\n");
1578 hbm_old = SelectObject(hdc, hbm_old);
1579 ok(hbm_old == hbm, "SelectObject failed\n");
1583 /* test an 1-bpp bitmap */
1584 planes = GetDeviceCaps(hdc, PLANES);
1587 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
1588 ok(hbm != 0, "CreateBitmap failed\n");
1590 hbm_old = SelectObject(hdc, hbm);
1591 ok(hbm_old != 0, "SelectObject failed\n");
1592 hbm_old = SelectObject(hdc, hbm_old);
1593 ok(hbm_old == hbm, "SelectObject failed\n");
1597 /* test a color bitmap that doesn't match the dc's bpp */
1598 planes = GetDeviceCaps(hdc, PLANES);
1599 bpp = GetDeviceCaps(hdc, BITSPIXEL) == 24 ? 8 : 24;
1601 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
1602 ok(hbm != 0, "CreateBitmap failed\n");
1604 hbm_old = SelectObject(hdc, hbm);
1605 ok(hbm_old == 0, "SelectObject should fail\n");
1612 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
1617 ret = GetObjectType(hbmp);
1618 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
1620 ret = GetObject(hbmp, 0, 0);
1621 ok_(__FILE__, line)(ret == sizeof(BITMAP) /* XP */ ||
1622 ret == sizeof(DIBSECTION) /* Win9x */, "object size %d\n", ret);
1624 memset(&bm, 0xDA, sizeof(bm));
1625 SetLastError(0xdeadbeef);
1626 ret = GetObject(hbmp, sizeof(bm), &bm);
1627 if (!ret) /* XP, only for curObj2 */ return;
1628 ok_(__FILE__, line)(ret == sizeof(BITMAP) ||
1629 ret == sizeof(DIBSECTION) /* Win9x, only for curObj2 */,
1630 "GetObject returned %d, error %u\n", ret, GetLastError());
1631 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
1632 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth %d\n", bm.bmWidth);
1633 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight %d\n", bm.bmHeight);
1634 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
1635 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
1636 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
1637 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
1640 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
1642 static void test_CreateBitmap(void)
1645 HDC screenDC = GetDC(0);
1646 HDC hdc = CreateCompatibleDC(screenDC);
1648 /* all of these are the stock monochrome bitmap */
1649 HBITMAP bm = CreateCompatibleBitmap(hdc, 0, 0);
1650 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
1651 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
1652 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
1653 HBITMAP curObj1 = (HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP);
1654 HBITMAP curObj2 = (HBITMAP)GetCurrentObject(screenDC, OBJ_BITMAP);
1656 /* these 2 are not the stock monochrome bitmap */
1657 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
1658 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
1660 HBITMAP old1 = (HBITMAP)SelectObject(hdc, bm2);
1661 HBITMAP old2 = (HBITMAP)SelectObject(screenDC, bm3);
1662 SelectObject(hdc, old1);
1663 SelectObject(screenDC, old2);
1665 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
1666 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
1667 bm, bm1, bm4, bm5, curObj1, old1);
1668 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
1669 ok(bm != curObj2 /* XP */ || bm == curObj2 /* Win9x */,
1670 "0: %p, curObj2 %p\n", bm, curObj2);
1671 ok(old2 == 0, "old2 %p\n", old2);
1673 test_mono_1x1_bmp(bm);
1674 test_mono_1x1_bmp(bm1);
1675 test_mono_1x1_bmp(bm2);
1676 test_mono_1x1_bmp(bm3);
1677 test_mono_1x1_bmp(bm4);
1678 test_mono_1x1_bmp(bm5);
1679 test_mono_1x1_bmp(old1);
1680 test_mono_1x1_bmp(curObj1);
1681 test_mono_1x1_bmp(curObj2);
1691 ReleaseDC(0, screenDC);
1693 /* show that Windows ignores the provided bm.bmWidthBytes */
1697 bmp.bmWidthBytes = 28;
1699 bmp.bmBitsPixel = 1;
1701 bm = CreateBitmapIndirect(&bmp);
1702 ok(bm != 0, "CreateBitmapIndirect error %u\n", GetLastError());
1703 test_mono_1x1_bmp(bm);
1707 static void test_bitmapinfoheadersize(void)
1714 memset(&bmi, 0, sizeof(BITMAPINFO));
1715 bmi.bmiHeader.biHeight = 100;
1716 bmi.bmiHeader.biWidth = 512;
1717 bmi.bmiHeader.biBitCount = 24;
1718 bmi.bmiHeader.biPlanes = 1;
1720 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
1722 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1723 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1725 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1727 SetLastError(0xdeadbeef);
1728 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1729 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1732 bmi.bmiHeader.biSize++;
1734 SetLastError(0xdeadbeef);
1735 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1736 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1739 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
1741 SetLastError(0xdeadbeef);
1742 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1743 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1746 bmi.bmiHeader.biSize++;
1748 SetLastError(0xdeadbeef);
1749 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1750 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1753 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
1755 SetLastError(0xdeadbeef);
1756 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1757 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1760 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
1762 SetLastError(0xdeadbeef);
1763 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
1764 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1767 memset(&bci, 0, sizeof(BITMAPCOREINFO));
1768 bci.bmciHeader.bcHeight = 100;
1769 bci.bmciHeader.bcWidth = 512;
1770 bci.bmciHeader.bcBitCount = 24;
1771 bci.bmciHeader.bcPlanes = 1;
1773 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
1775 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1776 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1778 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
1780 SetLastError(0xdeadbeef);
1781 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1782 ok(hdib != NULL, "CreateDIBSection error %d\n", GetLastError());
1785 bci.bmciHeader.bcSize++;
1787 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1788 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1790 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
1792 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
1793 ok(hdib == NULL, "CreateDIBSection succeeded\n");
1798 static void test_get16dibits(void)
1800 BYTE bits[4 * (16 / sizeof(BYTE))];
1802 HDC screen_dc = GetDC(NULL);
1805 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
1807 int overwritten_bytes = 0;
1809 memset(bits, 0, sizeof(bits));
1810 hbmp = CreateBitmap(2, 2, 1, 16, bits);
1811 ok(hbmp != NULL, "CreateBitmap failed\n");
1813 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, info_len);
1816 memset(info, '!', info_len);
1817 memset(info, 0, sizeof(info->bmiHeader));
1819 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1820 info->bmiHeader.biWidth = 2;
1821 info->bmiHeader.biHeight = 2;
1822 info->bmiHeader.biPlanes = 1;
1823 info->bmiHeader.biCompression = BI_RGB;
1825 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
1826 ok(ret != 0, "GetDIBits failed\n");
1828 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
1830 overwritten_bytes++;
1831 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
1833 HeapFree(GetProcessHeap(), 0, info);
1835 ReleaseDC(NULL, screen_dc);
1838 void test_GdiAlphaBlend()
1840 /* test out-of-bound parameters for GdiAlphaBlend */
1853 BLENDFUNCTION blend;
1855 if (!pGdiAlphaBlend)
1857 skip("GdiAlphaBlend() is not implemented\n");
1861 hdcNull = GetDC(NULL);
1862 hdcDst = CreateCompatibleDC(hdcNull);
1863 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
1864 hdcSrc = CreateCompatibleDC(hdcNull);
1866 memset(&bmi, 0, sizeof(bmi)); /* as of Wine 0.9.44 we require the src to be a DIB section */
1867 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
1868 bmi.bmiHeader.biHeight = 20;
1869 bmi.bmiHeader.biWidth = 20;
1870 bmi.bmiHeader.biBitCount = 32;
1871 bmi.bmiHeader.biPlanes = 1;
1872 bmi.bmiHeader.biCompression = BI_RGB;
1873 bmpSrc = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, &bits, NULL, 0);
1874 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
1876 oldDst = (HBITMAP)SelectObject(hdcDst, bmpDst);
1877 oldSrc = (HBITMAP)SelectObject(hdcSrc, bmpSrc);
1879 blend.BlendOp = AC_SRC_OVER;
1880 blend.BlendFlags = 0;
1881 blend.SourceConstantAlpha = 128;
1882 blend.AlphaFormat = 0;
1884 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend), TRUE, BOOL, "%d");
1885 SetLastError(0xdeadbeef);
1886 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), FALSE, BOOL, "%d");
1887 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER, int, "%d");
1888 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), FALSE, BOOL, "%d");
1889 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend), FALSE, BOOL, "%d");
1890 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
1891 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend), FALSE, BOOL, "%d");
1893 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
1894 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend), TRUE, BOOL, "%d");
1895 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend), TRUE, BOOL, "%d");
1896 SetMapMode(hdcSrc, MM_ANISOTROPIC);
1897 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
1898 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend), TRUE, BOOL, "%d");
1899 expect_eq(pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend), TRUE, BOOL, "%d");
1901 SelectObject(hdcDst, oldDst);
1902 SelectObject(hdcSrc, oldSrc);
1903 DeleteObject(bmpSrc);
1904 DeleteObject(bmpDst);
1908 ReleaseDC(NULL, hdcNull);
1915 is_win9x = GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC) == 0;
1917 hdll = GetModuleHandle("gdi32.dll");
1918 pGdiAlphaBlend = (void*)GetProcAddress(hdll, "GdiAlphaBlend");
1920 test_createdibitmap();
1922 test_mono_dibsection();
1925 test_GetDIBits_selected_DIB(1);
1926 test_GetDIBits_selected_DIB(4);
1927 test_GetDIBits_selected_DIB(8);
1928 test_GetDIBits_selected_DDB(TRUE);
1929 test_GetDIBits_selected_DDB(FALSE);
1931 test_select_object();
1932 test_CreateBitmap();
1933 test_GdiAlphaBlend();
1934 test_bitmapinfoheadersize();