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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/test.h"
35 static INT
BITMAP_GetWidthBytes( INT bmWidth
, INT bpp
)
40 return 2 * ((bmWidth
+15) >> 4);
43 bmWidth
*= 3; /* fall through */
45 return bmWidth
+ (bmWidth
& 1);
55 return 2 * ((bmWidth
+3) >> 2);
58 trace("Unknown depth %d, please report.\n", bpp
);
64 static void test_bitmap_info(HBITMAP hbm
, INT expected_depth
, const BITMAPINFOHEADER
*bmih
)
68 char buf
[512], buf_cmp
[512];
70 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
71 ok(ret
== sizeof(bm
), "GetObject returned %d instead of %d\n", ret
, sizeof(bm
));
73 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
74 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
75 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
76 width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
77 ok(bm
.bmWidthBytes
== width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, width_bytes
);
78 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
79 ok(bm
.bmBitsPixel
== expected_depth
, "wrong bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, expected_depth
);
80 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
82 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
83 assert(sizeof(buf
) == sizeof(buf_cmp
));
85 ret
= GetBitmapBits(hbm
, 0, NULL
);
86 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
88 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
89 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
91 memset(buf
, 0xAA, sizeof(buf
));
92 ret
= GetBitmapBits(hbm
, sizeof(buf
), buf
);
93 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
94 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
96 /* test various buffer sizes for GetObject */
97 ret
= GetObject(hbm
, 0, NULL
);
98 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
100 ret
= GetObject(hbm
, sizeof(bm
) * 2, &bm
);
101 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
103 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
104 ok(ret
== 0, "%d != 0\n", ret
);
106 ret
= GetObject(hbm
, 0, &bm
);
107 ok(ret
== 0, "%d != 0\n", ret
);
109 ret
= GetObject(hbm
, 1, &bm
);
110 ok(ret
== 0, "%d != 0\n", ret
);
113 static void test_createdibitmap(void)
116 BITMAPINFOHEADER bmih
;
117 HBITMAP hbm
, hbm_colour
, hbm_old
;
121 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
);
122 memset(&bmih
, 0, sizeof(bmih
));
123 bmih
.biSize
= sizeof(bmih
);
127 bmih
.biBitCount
= 32;
128 bmih
.biCompression
= BI_RGB
;
130 /* First create an un-initialised bitmap. The depth of the bitmap
131 should match that of the hdc and not that supplied in bmih.
134 /* First try 32 bits */
135 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
136 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
137 test_bitmap_info(hbm
, screen_depth
, &bmih
);
141 bmih
.biBitCount
= 16;
142 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
143 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
144 test_bitmap_info(hbm
, screen_depth
, &bmih
);
149 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
150 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
151 test_bitmap_info(hbm
, screen_depth
, &bmih
);
154 /* Now with a monochrome dc we expect a monochrome bitmap */
155 hdcmem
= CreateCompatibleDC(hdc
);
157 /* First try 32 bits */
158 bmih
.biBitCount
= 32;
159 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
160 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
161 test_bitmap_info(hbm
, 1, &bmih
);
165 bmih
.biBitCount
= 16;
166 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
167 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
168 test_bitmap_info(hbm
, 1, &bmih
);
173 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
174 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
175 test_bitmap_info(hbm
, 1, &bmih
);
178 /* Now select a polychrome bitmap into the dc and we expect
179 screen_depth bitmaps again */
180 hbm_colour
= CreateCompatibleBitmap(hdc
, 1, 1);
181 hbm_old
= SelectObject(hdcmem
, hbm_colour
);
183 /* First try 32 bits */
184 bmih
.biBitCount
= 32;
185 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
186 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
187 test_bitmap_info(hbm
, screen_depth
, &bmih
);
191 bmih
.biBitCount
= 16;
192 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
193 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
194 test_bitmap_info(hbm
, screen_depth
, &bmih
);
199 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
200 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
201 test_bitmap_info(hbm
, screen_depth
, &bmih
);
204 SelectObject(hdcmem
, hbm_old
);
205 DeleteObject(hbm_colour
);
208 /* If hdc == 0 then we get a 1 bpp bitmap */
210 bmih
.biBitCount
= 32;
211 hbm
= CreateDIBitmap(0, &bmih
, 0, NULL
, NULL
, 0);
212 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
213 test_bitmap_info(hbm
, 1, &bmih
);
220 static INT
DIB_GetWidthBytes( int width
, int bpp
)
226 case 1: words
= (width
+ 31) / 32; break;
227 case 4: words
= (width
+ 7) / 8; break;
228 case 8: words
= (width
+ 3) / 4; break;
230 case 16: words
= (width
+ 1) / 2; break;
231 case 24: words
= (width
* 3 + 3)/4; break;
232 case 32: words
= width
; break;
236 trace("Unknown depth %d, please report.\n", bpp
);
243 static void test_dib_info(HBITMAP hbm
, const void *bits
, const BITMAPINFOHEADER
*bmih
)
247 INT ret
, width_bytes
;
250 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
251 ok(ret
== sizeof(bm
), "GetObject returned %d instead of %d\n", ret
, sizeof(bm
));
253 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
254 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
255 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
256 width_bytes
= DIB_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
257 ok(bm
.bmWidthBytes
== width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, width_bytes
);
258 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
259 ok(bm
.bmBitsPixel
== bmih
->biBitCount
, "bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, bmih
->biBitCount
);
260 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
262 buf
= HeapAlloc(GetProcessHeap(), 0, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
264 width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
266 /* GetBitmapBits returns not 32-bit aligned data */
267 ret
= GetBitmapBits(hbm
, 0, NULL
);
268 ok(ret
== width_bytes
* bm
.bmHeight
, "%d != %d\n", ret
, width_bytes
* bm
.bmHeight
);
270 memset(buf
, 0xAA, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
271 ret
= GetBitmapBits(hbm
, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096, buf
);
272 ok(ret
== width_bytes
* bm
.bmHeight
, "%d != %d\n", ret
, width_bytes
* bm
.bmHeight
);
274 HeapFree(GetProcessHeap(), 0, buf
);
276 /* test various buffer sizes for GetObject */
277 memset(&ds
, 0xAA, sizeof(ds
));
278 ret
= GetObject(hbm
, sizeof(bm
) * 2, &bm
);
279 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
280 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
281 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
282 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
284 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
285 ok(ret
== 0, "%d != 0\n", ret
);
287 ret
= GetObject(hbm
, 0, &bm
);
288 ok(ret
== 0, "%d != 0\n", ret
);
290 ret
= GetObject(hbm
, 1, &bm
);
291 ok(ret
== 0, "%d != 0\n", ret
);
293 /* test various buffer sizes for GetObject */
294 ret
= GetObject(hbm
, 0, NULL
);
295 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
297 memset(&ds
, 0xAA, sizeof(ds
));
298 ret
= GetObject(hbm
, sizeof(ds
) * 2, &ds
);
299 ok(ret
== sizeof(ds
), "%d != %d\n", ret
, sizeof(ds
));
301 ok(ds
.dsBm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", ds
.dsBm
.bmBits
, bits
);
302 ok(ds
.dsBmih
.biSizeImage
== ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
, "%lu != %u\n",
303 ds
.dsBmih
.biSizeImage
, ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
);
304 ok(bmih
->biSizeImage
== 0, "%lu != 0\n", bmih
->biSizeImage
);
305 ds
.dsBmih
.biSizeImage
= 0;
307 ok(ds
.dsBmih
.biSize
== bmih
->biSize
, "%lu != %lu\n", ds
.dsBmih
.biSize
, bmih
->biSize
);
308 ok(ds
.dsBmih
.biWidth
== bmih
->biWidth
, "%lu != %lu\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
309 ok(ds
.dsBmih
.biHeight
== bmih
->biHeight
, "%lu != %lu\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
310 ok(ds
.dsBmih
.biPlanes
== bmih
->biPlanes
, "%u != %u\n", ds
.dsBmih
.biPlanes
, bmih
->biPlanes
);
311 ok(ds
.dsBmih
.biBitCount
== bmih
->biBitCount
, "%u != %u\n", ds
.dsBmih
.biBitCount
, bmih
->biBitCount
);
312 ok(ds
.dsBmih
.biCompression
== bmih
->biCompression
, "%lu != %lu\n", ds
.dsBmih
.biCompression
, bmih
->biCompression
);
313 ok(ds
.dsBmih
.biSizeImage
== bmih
->biSizeImage
, "%lu != %lu\n", ds
.dsBmih
.biSizeImage
, bmih
->biSizeImage
);
314 ok(ds
.dsBmih
.biXPelsPerMeter
== bmih
->biXPelsPerMeter
, "%lu != %lu\n", ds
.dsBmih
.biXPelsPerMeter
, bmih
->biXPelsPerMeter
);
315 ok(ds
.dsBmih
.biYPelsPerMeter
== bmih
->biYPelsPerMeter
, "%lu != %lu\n", ds
.dsBmih
.biYPelsPerMeter
, bmih
->biYPelsPerMeter
);
317 memset(&ds
, 0xAA, sizeof(ds
));
318 ret
= GetObject(hbm
, sizeof(ds
) - 4, &ds
);
319 ok(ret
== sizeof(ds
.dsBm
), "%d != %d\n", ret
, sizeof(ds
.dsBm
));
320 ok(ds
.dsBm
.bmWidth
== bmih
->biWidth
, "%lu != %lu\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
321 ok(ds
.dsBm
.bmHeight
== bmih
->biHeight
, "%lu != %lu\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
322 ok(ds
.dsBm
.bmBits
== bits
, "%p != %p\n", ds
.dsBm
.bmBits
, bits
);
324 ret
= GetObject(hbm
, 0, &ds
);
325 ok(ret
== 0, "%d != 0\n", ret
);
327 ret
= GetObject(hbm
, 1, &ds
);
328 ok(ret
== 0, "%d != 0\n", ret
);
331 #define test_color_todo(got, exp, txt, todo) \
332 if (!todo && got != exp && screen_depth < 24) { \
333 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
334 screen_depth, (UINT)got, (UINT)exp); \
336 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
337 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
339 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
342 c = SetPixel(hdc, 0, 0, color); \
343 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
344 c = GetPixel(hdc, 0, 0); \
345 test_color_todo(c, exp, GetPixel, todo_getp); \
348 static void test_dibsections(void)
350 HDC hdc
, hdcmem
, hdcmem2
;
351 HBITMAP hdib
, oldbm
, hdib2
, oldbm2
;
352 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
353 char bcibuf
[sizeof(BITMAPCOREINFO
) + 256 * sizeof(RGBTRIPLE
)];
354 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
355 BITMAPCOREINFO
*pbci
= (BITMAPCOREINFO
*)bcibuf
;
361 char logpalbuf
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
362 LOGPALETTE
*plogpal
= (LOGPALETTE
*)logpalbuf
;
365 HPALETTE hpal
, oldpal
;
370 MEMORY_BASIC_INFORMATION info
;
373 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
375 memset(pbmi
, 0, sizeof(bmibuf
));
376 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
377 pbmi
->bmiHeader
.biHeight
= 100;
378 pbmi
->bmiHeader
.biWidth
= 512;
379 pbmi
->bmiHeader
.biBitCount
= 24;
380 pbmi
->bmiHeader
.biPlanes
= 1;
381 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
383 SetLastError(0xdeadbeef);
384 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
385 ok(hdib
!= NULL
, "CreateDIBSection error %ld\n", GetLastError());
386 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
387 ok(dibsec
.dsBm
.bmBits
== bits
, "dibsec.dsBits %p != bits %p\n", dibsec
.dsBm
.bmBits
, bits
);
389 /* test the DIB memory */
390 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
391 "VirtualQuery failed\n");
392 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
393 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
394 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%lx != PAGE_READWRITE\n", info
.AllocationProtect
);
395 ok(info
.RegionSize
== 0x26000, "0x%lx != 0x26000\n", info
.RegionSize
);
396 ok(info
.State
== MEM_COMMIT
, "%lx != MEM_COMMIT\n", info
.State
);
397 ok(info
.Protect
== PAGE_READWRITE
, "%lx != PAGE_READWRITE\n", info
.Protect
);
398 ok(info
.Type
== MEM_PRIVATE
, "%lx != MEM_PRIVATE\n", info
.Type
);
400 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
403 pbmi
->bmiHeader
.biBitCount
= 8;
404 pbmi
->bmiHeader
.biCompression
= BI_RLE8
;
405 SetLastError(0xdeadbeef);
406 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
407 ok(hdib
== NULL
, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
408 ok(GetLastError() == 0xdeadbeef, "wrong error %ld\n", GetLastError());
410 pbmi
->bmiHeader
.biBitCount
= 16;
411 pbmi
->bmiHeader
.biCompression
= BI_BITFIELDS
;
412 ((PDWORD
)pbmi
->bmiColors
)[0] = 0xf800;
413 ((PDWORD
)pbmi
->bmiColors
)[1] = 0x07e0;
414 ((PDWORD
)pbmi
->bmiColors
)[2] = 0x001f;
415 SetLastError(0xdeadbeef);
416 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
417 ok(hdib
!= NULL
, "CreateDIBSection error %ld\n", GetLastError());
419 /* test the DIB memory */
420 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
421 "VirtualQuery failed\n");
422 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
423 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
424 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%lx != PAGE_READWRITE\n", info
.AllocationProtect
);
425 ok(info
.RegionSize
== 0x19000, "0x%lx != 0x19000\n", info
.RegionSize
);
426 ok(info
.State
== MEM_COMMIT
, "%lx != MEM_COMMIT\n", info
.State
);
427 ok(info
.Protect
== PAGE_READWRITE
, "%lx != PAGE_READWRITE\n", info
.Protect
);
428 ok(info
.Type
== MEM_PRIVATE
, "%lx != MEM_PRIVATE\n", info
.Type
);
430 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
433 memset(pbmi
, 0, sizeof(bmibuf
));
434 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
435 pbmi
->bmiHeader
.biHeight
= 16;
436 pbmi
->bmiHeader
.biWidth
= 16;
437 pbmi
->bmiHeader
.biBitCount
= 1;
438 pbmi
->bmiHeader
.biPlanes
= 1;
439 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
440 pbmi
->bmiColors
[0].rgbRed
= 0xff;
441 pbmi
->bmiColors
[0].rgbGreen
= 0;
442 pbmi
->bmiColors
[0].rgbBlue
= 0;
443 pbmi
->bmiColors
[1].rgbRed
= 0;
444 pbmi
->bmiColors
[1].rgbGreen
= 0;
445 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
447 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
448 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
449 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
450 ok(dibsec
.dsBmih
.biClrUsed
== 2,
451 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
453 /* Test if the old BITMAPCOREINFO structure is supported */
455 pbci
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
456 pbci
->bmciHeader
.bcBitCount
= 0;
459 ret
= GetDIBits(hdc
, hdib
, 0, 16, NULL
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
460 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
461 ok((pbci
->bmciHeader
.bcWidth
== 16) && (pbci
->bmciHeader
.bcHeight
== 16)
462 && (pbci
->bmciHeader
.bcBitCount
== 1) && (pbci
->bmciHeader
.bcPlanes
== 1),
463 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
465 ret
= GetDIBits(hdc
, hdib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
466 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
467 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
468 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
469 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
470 "The color table has not been translated to the old BITMAPCOREINFO format\n");
472 hcoredib
= CreateDIBSection(hdc
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
473 ok(hcoredib
!= NULL
, "CreateDIBSection failed with a BITMAPCOREINFO\n");
475 ZeroMemory(pbci
->bmciColors
, 256 * sizeof(RGBTRIPLE
));
476 ret
= GetDIBits(hdc
, hcoredib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
477 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
478 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
479 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
480 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
481 "The color table has not been translated to the old BITMAPCOREINFO format\n");
483 DeleteObject(hcoredib
);
486 hdcmem
= CreateCompatibleDC(hdc
);
487 oldbm
= SelectObject(hdcmem
, hdib
);
489 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
490 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
491 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
492 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
493 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
494 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
496 c0
= RGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
, pbmi
->bmiColors
[0].rgbBlue
);
497 c1
= RGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
, pbmi
->bmiColors
[1].rgbBlue
);
499 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
500 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
501 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
502 test_color(hdcmem
, PALETTEINDEX(0), c0
, 1, 1);
503 test_color(hdcmem
, PALETTEINDEX(1), c0
, 1, 1);
504 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
505 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
,
506 pbmi
->bmiColors
[0].rgbBlue
), c0
, 1, 1);
507 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
,
508 pbmi
->bmiColors
[1].rgbBlue
), c1
, 1, 1);
509 test_color(hdcmem
, PALETTERGB(0, 0, 0), c0
, 1, 1);
510 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
511 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c1
, 1, 1);
513 SelectObject(hdcmem
, oldbm
);
516 pbmi
->bmiColors
[0].rgbRed
= 0xff;
517 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
518 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
519 pbmi
->bmiColors
[1].rgbRed
= 0;
520 pbmi
->bmiColors
[1].rgbGreen
= 0;
521 pbmi
->bmiColors
[1].rgbBlue
= 0;
523 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
524 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
526 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
528 oldbm
= SelectObject(hdcmem
, hdib
);
530 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
531 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
532 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
533 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
534 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
535 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
537 SelectObject(hdcmem
, oldbm
);
538 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
541 pbmi
->bmiHeader
.biBitCount
= 4;
542 for (i
= 0; i
< 16; i
++) {
543 pbmi
->bmiColors
[i
].rgbRed
= i
;
544 pbmi
->bmiColors
[i
].rgbGreen
= 16-i
;
545 pbmi
->bmiColors
[i
].rgbBlue
= 0;
547 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
548 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
549 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
550 ok(dibsec
.dsBmih
.biClrUsed
== 16,
551 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 16);
552 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
555 pbmi
->bmiHeader
.biBitCount
= 8;
557 for (i
= 0; i
< 128; i
++) {
558 pbmi
->bmiColors
[i
].rgbRed
= 255 - i
* 2;
559 pbmi
->bmiColors
[i
].rgbGreen
= i
* 2;
560 pbmi
->bmiColors
[i
].rgbBlue
= 0;
561 pbmi
->bmiColors
[255 - i
].rgbRed
= 0;
562 pbmi
->bmiColors
[255 - i
].rgbGreen
= i
* 2;
563 pbmi
->bmiColors
[255 - i
].rgbBlue
= 255 - i
* 2;
565 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
566 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
567 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
568 ok(dibsec
.dsBmih
.biClrUsed
== 256,
569 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
571 oldbm
= SelectObject(hdcmem
, hdib
);
573 for (i
= 0; i
< 256; i
++) {
574 test_color(hdcmem
, DIBINDEX(i
),
575 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
576 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
),
577 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
580 SelectObject(hdcmem
, oldbm
);
581 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
584 pbmi
->bmiHeader
.biBitCount
= 1;
586 /* Now create a palette and a palette indexed dib section */
587 memset(plogpal
, 0, sizeof(logpalbuf
));
588 plogpal
->palVersion
= 0x300;
589 plogpal
->palNumEntries
= 2;
590 plogpal
->palPalEntry
[0].peRed
= 0xff;
591 plogpal
->palPalEntry
[0].peBlue
= 0xff;
592 plogpal
->palPalEntry
[1].peGreen
= 0xff;
594 index
= (WORD
*)pbmi
->bmiColors
;
597 hpal
= CreatePalette(plogpal
);
598 ok(hpal
!= NULL
, "CreatePalette failed\n");
599 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
600 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
601 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
602 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
603 ok(dibsec
.dsBmih
.biClrUsed
== 2,
604 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
606 /* The colour table has already been grabbed from the dc, so we select back the
609 SelectPalette(hdc
, oldpal
, TRUE
);
610 oldbm
= SelectObject(hdcmem
, hdib
);
611 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
613 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
614 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
615 ok(rgb
[0].rgbRed
== 0xff && rgb
[0].rgbBlue
== 0xff && rgb
[0].rgbGreen
== 0 &&
616 rgb
[1].rgbRed
== 0 && rgb
[1].rgbBlue
== 0 && rgb
[1].rgbGreen
== 0xff,
617 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
618 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
619 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
621 c0
= RGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
, plogpal
->palPalEntry
[0].peBlue
);
622 c1
= RGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
, plogpal
->palPalEntry
[1].peBlue
);
624 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
625 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
626 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
627 test_color(hdcmem
, PALETTEINDEX(0), c0
, 0, 1);
628 test_color(hdcmem
, PALETTEINDEX(1), c1
, 0, 1);
629 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
630 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
,
631 plogpal
->palPalEntry
[0].peBlue
), c0
, 1, 1);
632 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
,
633 plogpal
->palPalEntry
[1].peBlue
), c1
, 1, 1);
634 test_color(hdcmem
, PALETTERGB(0, 0, 0), c1
, 1, 1);
635 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
636 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c0
, 1, 1);
637 test_color(hdcmem
, PALETTERGB(0, 1, 0), c1
, 1, 1);
638 test_color(hdcmem
, PALETTERGB(0x3f, 0, 0x3f), c1
, 1, 1);
639 test_color(hdcmem
, PALETTERGB(0x40, 0, 0x40), c0
, 1, 1);
641 /* Bottom and 2nd row from top green, everything else magenta */
642 bits
[0] = bits
[1] = 0xff;
643 bits
[13 * 4] = bits
[13*4 + 1] = 0xff;
645 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
647 pbmi
->bmiHeader
.biBitCount
= 32;
649 hdib2
= CreateDIBSection(NULL
, pbmi
, DIB_RGB_COLORS
, (void **)&bits32
, NULL
, 0);
650 ok(hdib2
!= NULL
, "CreateDIBSection failed\n");
651 hdcmem2
= CreateCompatibleDC(hdc
);
652 oldbm2
= SelectObject(hdcmem2
, hdib2
);
654 BitBlt(hdcmem2
, 0, 0, 16,16, hdcmem
, 0, 0, SRCCOPY
);
656 ok(bits32
[0] == 0xff00, "lower left pixel is %08lx\n", bits32
[0]);
657 ok(bits32
[17] == 0xff00ff, "bottom but one, left pixel is %08lx\n", bits32
[17]);
659 SelectObject(hdcmem2
, oldbm2
);
660 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
663 SelectObject(hdcmem
, oldbm
);
664 SelectObject(hdcmem
, oldpal
);
669 pbmi
->bmiHeader
.biBitCount
= 8;
671 memset(plogpal
, 0, sizeof(logpalbuf
));
672 plogpal
->palVersion
= 0x300;
673 plogpal
->palNumEntries
= 256;
675 for (i
= 0; i
< 128; i
++) {
676 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
677 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
678 plogpal
->palPalEntry
[i
].peGreen
= 0;
679 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
680 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
681 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
684 index
= (WORD
*)pbmi
->bmiColors
;
685 for (i
= 0; i
< 256; i
++) {
689 hpal
= CreatePalette(plogpal
);
690 ok(hpal
!= NULL
, "CreatePalette failed\n");
691 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
692 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
693 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
694 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
695 ok(dibsec
.dsBmih
.biClrUsed
== 256,
696 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
698 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
700 SelectPalette(hdc
, oldpal
, TRUE
);
701 oldbm
= SelectObject(hdcmem
, hdib
);
702 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
704 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
705 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
706 for (i
= 0; i
< 256; i
++) {
707 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
708 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
709 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
710 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
711 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
714 for (i
= 0; i
< 256; i
++) {
715 test_color(hdcmem
, DIBINDEX(i
),
716 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
717 test_color(hdcmem
, PALETTEINDEX(i
),
718 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
719 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
720 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
723 SelectPalette(hdcmem
, oldpal
, TRUE
);
724 SelectObject(hdcmem
, oldbm
);
733 void test_mono_dibsection(void)
736 HBITMAP old_bm
, mono_ds
;
737 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
738 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
745 memdc
= CreateCompatibleDC(hdc
);
747 memset(pbmi
, 0, sizeof(bmibuf
));
748 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
749 pbmi
->bmiHeader
.biHeight
= 10;
750 pbmi
->bmiHeader
.biWidth
= 10;
751 pbmi
->bmiHeader
.biBitCount
= 1;
752 pbmi
->bmiHeader
.biPlanes
= 1;
753 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
754 pbmi
->bmiColors
[0].rgbRed
= 0xff;
755 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
756 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
757 pbmi
->bmiColors
[1].rgbRed
= 0x0;
758 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
759 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
762 * First dib section is 'inverted' ie color[0] is white, color[1] is black
765 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
766 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
767 old_bm
= SelectObject(memdc
, mono_ds
);
769 /* black border, white interior */
770 Rectangle(memdc
, 0, 0, 10, 10);
771 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
772 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
774 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
776 memset(bits
, 0, sizeof(bits
));
779 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
780 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
782 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
784 pbmi
->bmiColors
[0].rgbRed
= 0x0;
785 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
786 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
787 pbmi
->bmiColors
[1].rgbRed
= 0xff;
788 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
789 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
791 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
792 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
794 SelectObject(memdc
, old_bm
);
795 DeleteObject(mono_ds
);
798 * Next dib section is 'normal' ie color[0] is black, color[1] is white
801 pbmi
->bmiColors
[0].rgbRed
= 0x0;
802 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
803 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
804 pbmi
->bmiColors
[1].rgbRed
= 0xff;
805 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
806 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
808 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
809 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
810 old_bm
= SelectObject(memdc
, mono_ds
);
812 /* black border, white interior */
813 Rectangle(memdc
, 0, 0, 10, 10);
814 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
815 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
817 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
819 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
820 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
822 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
824 pbmi
->bmiColors
[0].rgbRed
= 0xff;
825 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
826 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
827 pbmi
->bmiColors
[1].rgbRed
= 0x0;
828 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
829 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
831 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
832 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
835 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
838 pbmi
->bmiColors
[0].rgbRed
= 0xff;
839 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
840 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
841 pbmi
->bmiColors
[1].rgbRed
= 0x0;
842 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
843 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
844 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
845 ok(num
== 2, "num = %d\n", num
);
847 /* black border, white interior */
848 Rectangle(memdc
, 0, 0, 10, 10);
850 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
851 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
853 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
855 memset(bits
, 0, sizeof(bits
));
858 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
859 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
861 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
863 pbmi
->bmiColors
[0].rgbRed
= 0x0;
864 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
865 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
866 pbmi
->bmiColors
[1].rgbRed
= 0xff;
867 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
868 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
870 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
871 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
873 SelectObject(memdc
, old_bm
);
874 DeleteObject(mono_ds
);
877 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
880 pbmi
->bmiColors
[0].rgbRed
= 0xff;
881 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
882 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
883 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
884 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
885 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
887 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
888 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
889 old_bm
= SelectObject(memdc
, mono_ds
);
891 /* black border, white interior */
892 Rectangle(memdc
, 0, 0, 10, 10);
893 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
894 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
896 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
898 pbmi
->bmiColors
[0].rgbRed
= 0x0;
899 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
900 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
901 pbmi
->bmiColors
[1].rgbRed
= 0xff;
902 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
903 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
905 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
906 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
908 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
910 pbmi
->bmiColors
[0].rgbRed
= 0xff;
911 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
912 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
913 pbmi
->bmiColors
[1].rgbRed
= 0x0;
914 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
915 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
917 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
918 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
920 SelectObject(memdc
, old_bm
);
921 DeleteObject(mono_ds
);
927 static void test_bitmap(void)
929 char buf
[256], buf_cmp
[256];
930 HBITMAP hbmp
, hbmp_old
;
935 hdc
= CreateCompatibleDC(0);
938 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
939 assert(hbmp
!= NULL
);
941 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
942 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
944 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
945 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
946 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
947 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
948 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
949 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
950 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
952 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
953 assert(sizeof(buf
) == sizeof(buf_cmp
));
955 ret
= GetBitmapBits(hbmp
, 0, NULL
);
956 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
958 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
959 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
961 memset(buf
, 0xAA, sizeof(buf
));
962 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
963 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
964 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
966 hbmp_old
= SelectObject(hdc
, hbmp
);
968 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
969 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
971 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
972 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
973 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
974 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
975 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
976 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
977 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
979 memset(buf
, 0xAA, sizeof(buf
));
980 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
981 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
982 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
984 hbmp_old
= SelectObject(hdc
, hbmp_old
);
985 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
987 /* test various buffer sizes for GetObject */
988 ret
= GetObject(hbmp
, sizeof(bm
) * 2, &bm
);
989 ok(ret
== sizeof(bm
), "%d != %d\n", ret
, sizeof(bm
));
991 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
992 ok(ret
== 0, "%d != 0\n", ret
);
994 ret
= GetObject(hbmp
, 0, &bm
);
995 ok(ret
== 0, "%d != 0\n", ret
);
997 ret
= GetObject(hbmp
, 1, &bm
);
998 ok(ret
== 0, "%d != 0\n", ret
);
1006 is_win9x
= GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
) == 0;
1008 test_createdibitmap();
1010 test_mono_dibsection();