2 * Unit test suite for bitmaps
4 * Copyright 2004 Huw Davies
5 * Copyright 2006 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 static BOOL (WINAPI
*pGdiAlphaBlend
)(HDC
,int,int,int,int,HDC
,int,int,int,int,BLENDFUNCTION
);
37 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
41 static INT
BITMAP_GetWidthBytes( INT bmWidth
, INT bpp
)
46 return 2 * ((bmWidth
+15) >> 4);
49 bmWidth
*= 3; /* fall through */
51 return bmWidth
+ (bmWidth
& 1);
61 return 2 * ((bmWidth
+3) >> 2);
64 trace("Unknown depth %d, please report.\n", bpp
);
70 static void test_bitmap_info(HBITMAP hbm
, INT expected_depth
, const BITMAPINFOHEADER
*bmih
)
75 char buf
[512], buf_cmp
[512];
78 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
79 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
81 ok(bm
.bmType
== 0 || broken(bm
.bmType
== 21072 /* Win9x */), "wrong bm.bmType %d\n", bm
.bmType
);
82 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
83 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
84 width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
85 ok(bm
.bmWidthBytes
== width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, width_bytes
);
86 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
87 ok(bm
.bmBitsPixel
== expected_depth
, "wrong bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, expected_depth
);
88 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
90 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
91 assert(sizeof(buf
) == sizeof(buf_cmp
));
93 SetLastError(0xdeadbeef);
94 ret
= GetBitmapBits(hbm
, 0, NULL
);
96 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
|| (ret
== 0 && gle
== ERROR_INVALID_PARAMETER
/* Win9x */), "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
98 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
99 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
101 memset(buf
, 0xAA, sizeof(buf
));
102 ret
= GetBitmapBits(hbm
, sizeof(buf
), buf
);
103 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
104 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
106 /* test various buffer sizes for GetObject */
107 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
108 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
110 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
111 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
113 ret
= GetObject(hbm
, 0, &bm
);
114 ok(ret
== 0, "%d != 0\n", ret
);
116 ret
= GetObject(hbm
, 1, &bm
);
117 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
119 /* Don't trust Win9x not to try to write to NULL */
122 ret
= GetObject(hbm
, 0, NULL
);
123 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
127 static void test_createdibitmap(void)
130 BITMAPINFOHEADER bmih
;
132 HBITMAP hbm
, hbm_colour
, hbm_old
;
137 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
);
138 memset(&bmih
, 0, sizeof(bmih
));
139 bmih
.biSize
= sizeof(bmih
);
143 bmih
.biBitCount
= 32;
144 bmih
.biCompression
= BI_RGB
;
146 /* First create an un-initialised bitmap. The depth of the bitmap
147 should match that of the hdc and not that supplied in bmih.
150 /* First try 32 bits */
151 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
152 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
153 test_bitmap_info(hbm
, screen_depth
, &bmih
);
157 bmih
.biBitCount
= 16;
158 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
159 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
160 test_bitmap_info(hbm
, screen_depth
, &bmih
);
165 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
166 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
167 test_bitmap_info(hbm
, screen_depth
, &bmih
);
170 /* Now with a monochrome dc we expect a monochrome bitmap */
171 hdcmem
= CreateCompatibleDC(hdc
);
173 /* First try 32 bits */
174 bmih
.biBitCount
= 32;
175 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
176 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
177 test_bitmap_info(hbm
, 1, &bmih
);
181 bmih
.biBitCount
= 16;
182 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
183 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
184 test_bitmap_info(hbm
, 1, &bmih
);
189 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
190 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
191 test_bitmap_info(hbm
, 1, &bmih
);
194 /* Now select a polychrome bitmap into the dc and we expect
195 screen_depth bitmaps again */
196 hbm_colour
= CreateCompatibleBitmap(hdc
, bmih
.biWidth
, bmih
.biHeight
);
197 test_bitmap_info(hbm_colour
, screen_depth
, &bmih
);
198 hbm_old
= SelectObject(hdcmem
, hbm_colour
);
200 /* First try 32 bits */
201 bmih
.biBitCount
= 32;
202 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
203 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
204 test_bitmap_info(hbm
, screen_depth
, &bmih
);
208 bmih
.biBitCount
= 16;
209 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
210 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
211 test_bitmap_info(hbm
, screen_depth
, &bmih
);
216 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
217 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
218 test_bitmap_info(hbm
, screen_depth
, &bmih
);
221 SelectObject(hdcmem
, hbm_old
);
222 DeleteObject(hbm_colour
);
225 /* If hdc == 0 then we get a 1 bpp bitmap */
227 bmih
.biBitCount
= 32;
228 hbm
= CreateDIBitmap(0, &bmih
, 0, NULL
, NULL
, 0);
229 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
230 test_bitmap_info(hbm
, 1, &bmih
);
234 /* Test how formats are converted */
240 memset(&bm
, 0, sizeof(bm
));
241 bm
.bmiHeader
.biSize
= sizeof(bm
.bmiHeader
);
242 bm
.bmiHeader
.biWidth
= 1;
243 bm
.bmiHeader
.biHeight
= 1;
244 bm
.bmiHeader
.biPlanes
= 1;
245 bm
.bmiHeader
.biBitCount
= 24;
246 bm
.bmiHeader
.biCompression
= BI_RGB
;
247 bm
.bmiHeader
.biSizeImage
= 0;
248 hbm
= CreateDIBitmap(hdc
, &bmih
, CBM_INIT
, &pixel
, &bm
, DIB_RGB_COLORS
);
249 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
252 bm
.bmiHeader
.biBitCount
= 32;
253 GetDIBits(hdc
, hbm
, 0, 1, &pixel
, &bm
, DIB_RGB_COLORS
);
254 ok(pixel
== 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel
);
260 static INT
DIB_GetWidthBytes( int width
, int bpp
)
266 case 1: words
= (width
+ 31) / 32; break;
267 case 4: words
= (width
+ 7) / 8; break;
268 case 8: words
= (width
+ 3) / 4; break;
270 case 16: words
= (width
+ 1) / 2; break;
271 case 24: words
= (width
* 3 + 3)/4; break;
272 case 32: words
= width
; break;
276 trace("Unknown depth %d, please report.\n", bpp
);
283 static void test_dib_info(HBITMAP hbm
, const void *bits
, const BITMAPINFOHEADER
*bmih
)
289 INT ret
, bm_width_bytes
, dib_width_bytes
;
292 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
293 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
295 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
296 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
297 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
298 dib_width_bytes
= DIB_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
299 bm_width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
300 if (bm
.bmWidthBytes
!= dib_width_bytes
) /* Win2k bug */
301 ok(bm
.bmWidthBytes
== bm_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, bm_width_bytes
);
303 ok(bm
.bmWidthBytes
== dib_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, dib_width_bytes
);
304 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
305 ok(bm
.bmBitsPixel
== bmih
->biBitCount
, "bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, bmih
->biBitCount
);
306 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
308 buf
= HeapAlloc(GetProcessHeap(), 0, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
310 /* GetBitmapBits returns not 32-bit aligned data */
311 SetLastError(0xdeadbeef);
312 ret
= GetBitmapBits(hbm
, 0, NULL
);
313 ok(ret
== bm_width_bytes
* bm
.bmHeight
||
314 broken(ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
), /* Win9x */
315 "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
317 memset(buf
, 0xAA, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
318 ret
= GetBitmapBits(hbm
, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096, buf
);
319 ok(ret
== bm_width_bytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
321 HeapFree(GetProcessHeap(), 0, buf
);
323 /* test various buffer sizes for GetObject */
324 memset(&ds
, 0xAA, sizeof(ds
));
325 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
326 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
327 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
328 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
329 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
331 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
332 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
334 ret
= GetObject(hbm
, 0, &bm
);
335 ok(ret
== 0, "%d != 0\n", ret
);
337 ret
= GetObject(hbm
, 1, &bm
);
338 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
340 /* test various buffer sizes for GetObject */
341 ret
= GetObject(hbm
, 0, NULL
);
342 ok(ret
== sizeof(bm
) || broken(ret
== sizeof(DIBSECTION
) /* Win9x */), "wrong size %d\n", ret
);
344 ret
= GetObject(hbm
, sizeof(*dsa
) * 2, dsa
);
345 ok(ret
== sizeof(*dsa
) || broken(ret
== sizeof(*dsa
) * 2 /* Win9x */), "wrong size %d\n", ret
);
347 memset(&ds
, 0xAA, sizeof(ds
));
348 ret
= GetObject(hbm
, sizeof(ds
), &ds
);
349 ok(ret
== sizeof(ds
), "wrong size %d\n", ret
);
351 ok(ds
.dsBm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", ds
.dsBm
.bmBits
, bits
);
352 if (ds
.dsBm
.bmWidthBytes
!= bm_width_bytes
) /* Win2k bug */
353 ok(ds
.dsBmih
.biSizeImage
== ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
, "%u != %u\n",
354 ds
.dsBmih
.biSizeImage
, ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
);
355 ok(bmih
->biSizeImage
== 0, "%u != 0\n", bmih
->biSizeImage
);
356 ds
.dsBmih
.biSizeImage
= 0;
358 ok(ds
.dsBmih
.biSize
== bmih
->biSize
, "%u != %u\n", ds
.dsBmih
.biSize
, bmih
->biSize
);
359 ok(ds
.dsBmih
.biWidth
== bmih
->biWidth
, "%u != %u\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
360 ok(ds
.dsBmih
.biHeight
== bmih
->biHeight
, "%u != %u\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
361 ok(ds
.dsBmih
.biPlanes
== bmih
->biPlanes
, "%u != %u\n", ds
.dsBmih
.biPlanes
, bmih
->biPlanes
);
362 ok(ds
.dsBmih
.biBitCount
== bmih
->biBitCount
, "%u != %u\n", ds
.dsBmih
.biBitCount
, bmih
->biBitCount
);
363 ok(ds
.dsBmih
.biCompression
== bmih
->biCompression
, "%u != %u\n", ds
.dsBmih
.biCompression
, bmih
->biCompression
);
364 ok(ds
.dsBmih
.biSizeImage
== bmih
->biSizeImage
, "%u != %u\n", ds
.dsBmih
.biSizeImage
, bmih
->biSizeImage
);
365 ok(ds
.dsBmih
.biXPelsPerMeter
== bmih
->biXPelsPerMeter
, "%u != %u\n", ds
.dsBmih
.biXPelsPerMeter
, bmih
->biXPelsPerMeter
);
366 ok(ds
.dsBmih
.biYPelsPerMeter
== bmih
->biYPelsPerMeter
, "%u != %u\n", ds
.dsBmih
.biYPelsPerMeter
, bmih
->biYPelsPerMeter
);
368 memset(&ds
, 0xAA, sizeof(ds
));
369 ret
= GetObject(hbm
, sizeof(ds
) - 4, &ds
);
370 ok(ret
== sizeof(ds
.dsBm
) || broken(ret
== (sizeof(ds
) - 4) /* Win9x */), "wrong size %d\n", ret
);
371 ok(ds
.dsBm
.bmWidth
== bmih
->biWidth
, "%u != %u\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
372 ok(ds
.dsBm
.bmHeight
== bmih
->biHeight
, "%u != %u\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
373 ok(ds
.dsBm
.bmBits
== bits
, "%p != %p\n", ds
.dsBm
.bmBits
, bits
);
375 ret
= GetObject(hbm
, 0, &ds
);
376 ok(ret
== 0, "%d != 0\n", ret
);
378 ret
= GetObject(hbm
, 1, &ds
);
379 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
382 #define test_color_todo(got, exp, txt, todo) \
383 if (!todo && got != exp && screen_depth < 24) { \
384 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
385 screen_depth, (UINT)got, (UINT)exp); \
387 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
388 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
390 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
393 c = SetPixel(hdc, 0, 0, color); \
394 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
395 c = GetPixel(hdc, 0, 0); \
396 test_color_todo(c, exp, GetPixel, todo_getp); \
399 static void test_dib_bits_access( HBITMAP hdib
, void *bits
)
401 MEMORY_BASIC_INFORMATION info
;
402 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
404 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
406 char filename
[MAX_PATH
];
411 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
412 "VirtualQuery failed\n");
413 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
414 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
415 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
416 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
417 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
418 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
420 memset( pbmi
, 0, sizeof(bmibuf
) );
421 memset( data
, 0xcc, sizeof(data
) );
422 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
423 pbmi
->bmiHeader
.biHeight
= 16;
424 pbmi
->bmiHeader
.biWidth
= 16;
425 pbmi
->bmiHeader
.biBitCount
= 32;
426 pbmi
->bmiHeader
.biPlanes
= 1;
427 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
429 ret
= SetDIBits( hdc
, hdib
, 0, 16, data
, pbmi
, DIB_RGB_COLORS
);
430 ok( ret
== 16, "SetDIBits failed\n" );
432 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
433 "VirtualQuery failed\n");
434 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
435 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
436 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
437 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
438 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
439 /* it has been protected now */
440 todo_wine
ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
442 /* try writing protected bits to a file */
444 GetTempFileNameA( ".", "dib", 0, filename
);
445 file
= CreateFileA( filename
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
446 CREATE_ALWAYS
, 0, 0 );
447 ok( file
!= INVALID_HANDLE_VALUE
, "failed to open %s error %u\n", filename
, GetLastError() );
448 ret
= WriteFile( file
, bits
, 8192, &written
, NULL
);
449 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
450 if (ret
) ok( written
== 8192, "only wrote %u bytes\n", written
);
452 DeleteFileA( filename
);
455 static void test_dibsections(void)
457 HDC hdc
, hdcmem
, hdcmem2
;
458 HBITMAP hdib
, oldbm
, hdib2
, oldbm2
;
459 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
460 char bcibuf
[sizeof(BITMAPCOREINFO
) + 256 * sizeof(RGBTRIPLE
)];
461 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
462 BITMAPCOREINFO
*pbci
= (BITMAPCOREINFO
*)bcibuf
;
468 char logpalbuf
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
469 LOGPALETTE
*plogpal
= (LOGPALETTE
*)logpalbuf
;
472 HPALETTE hpal
, oldpal
;
477 MEMORY_BASIC_INFORMATION info
;
480 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
482 memset(pbmi
, 0, sizeof(bmibuf
));
483 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
484 pbmi
->bmiHeader
.biHeight
= 100;
485 pbmi
->bmiHeader
.biWidth
= 512;
486 pbmi
->bmiHeader
.biBitCount
= 24;
487 pbmi
->bmiHeader
.biPlanes
= 1;
488 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
490 SetLastError(0xdeadbeef);
492 /* invalid pointer for BITMAPINFO
493 (*bits should be NULL on error) */
494 bits
= (BYTE
*)0xdeadbeef;
495 hdib
= CreateDIBSection(hdc
, NULL
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
496 ok(hdib
== NULL
&& bits
== NULL
, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
498 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
499 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
500 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
501 ok(dibsec
.dsBm
.bmBits
== bits
, "dibsec.dsBits %p != bits %p\n", dibsec
.dsBm
.bmBits
, bits
);
503 /* test the DIB memory */
504 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
505 "VirtualQuery failed\n");
506 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
507 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
508 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
509 ok(info
.RegionSize
== 0x26000, "0x%lx != 0x26000\n", info
.RegionSize
);
510 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
511 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
512 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
514 test_dib_bits_access( hdib
, bits
);
516 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
519 pbmi
->bmiHeader
.biBitCount
= 8;
520 pbmi
->bmiHeader
.biCompression
= BI_RLE8
;
521 SetLastError(0xdeadbeef);
522 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
523 ok(hdib
== NULL
, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
524 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
526 pbmi
->bmiHeader
.biBitCount
= 16;
527 pbmi
->bmiHeader
.biCompression
= BI_BITFIELDS
;
528 ((PDWORD
)pbmi
->bmiColors
)[0] = 0xf800;
529 ((PDWORD
)pbmi
->bmiColors
)[1] = 0x07e0;
530 ((PDWORD
)pbmi
->bmiColors
)[2] = 0x001f;
531 SetLastError(0xdeadbeef);
532 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
533 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
535 /* test the DIB memory */
536 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
537 "VirtualQuery failed\n");
538 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
539 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
540 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
541 ok(info
.RegionSize
== 0x19000, "0x%lx != 0x19000\n", info
.RegionSize
);
542 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
543 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
544 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
546 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
549 memset(pbmi
, 0, sizeof(bmibuf
));
550 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
551 pbmi
->bmiHeader
.biHeight
= 16;
552 pbmi
->bmiHeader
.biWidth
= 16;
553 pbmi
->bmiHeader
.biBitCount
= 1;
554 pbmi
->bmiHeader
.biPlanes
= 1;
555 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
556 pbmi
->bmiColors
[0].rgbRed
= 0xff;
557 pbmi
->bmiColors
[0].rgbGreen
= 0;
558 pbmi
->bmiColors
[0].rgbBlue
= 0;
559 pbmi
->bmiColors
[1].rgbRed
= 0;
560 pbmi
->bmiColors
[1].rgbGreen
= 0;
561 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
563 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
564 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
565 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
566 ok(dibsec
.dsBmih
.biClrUsed
== 2,
567 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
569 /* Test if the old BITMAPCOREINFO structure is supported */
571 pbci
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
572 pbci
->bmciHeader
.bcBitCount
= 0;
575 ret
= GetDIBits(hdc
, hdib
, 0, 16, NULL
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
576 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
577 ok((pbci
->bmciHeader
.bcWidth
== 16) && (pbci
->bmciHeader
.bcHeight
== 16)
578 && (pbci
->bmciHeader
.bcBitCount
== 1) && (pbci
->bmciHeader
.bcPlanes
== 1),
579 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
581 ret
= GetDIBits(hdc
, hdib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
582 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
583 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
584 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
585 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
586 "The color table has not been translated to the old BITMAPCOREINFO format\n");
588 hcoredib
= CreateDIBSection(hdc
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
589 ok(hcoredib
!= NULL
, "CreateDIBSection failed with a BITMAPCOREINFO\n");
591 ZeroMemory(pbci
->bmciColors
, 256 * sizeof(RGBTRIPLE
));
592 ret
= GetDIBits(hdc
, hcoredib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
593 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
594 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
595 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
596 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
597 "The color table has not been translated to the old BITMAPCOREINFO format\n");
599 DeleteObject(hcoredib
);
602 hdcmem
= CreateCompatibleDC(hdc
);
603 oldbm
= SelectObject(hdcmem
, hdib
);
605 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
606 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
607 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
608 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
609 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
610 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
612 c0
= RGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
, pbmi
->bmiColors
[0].rgbBlue
);
613 c1
= RGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
, pbmi
->bmiColors
[1].rgbBlue
);
615 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
616 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
617 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
618 test_color(hdcmem
, PALETTEINDEX(0), c0
, 1, 1);
619 test_color(hdcmem
, PALETTEINDEX(1), c0
, 1, 1);
620 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
621 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
,
622 pbmi
->bmiColors
[0].rgbBlue
), c0
, 1, 1);
623 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
,
624 pbmi
->bmiColors
[1].rgbBlue
), c1
, 1, 1);
625 test_color(hdcmem
, PALETTERGB(0, 0, 0), c0
, 1, 1);
626 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
627 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c1
, 1, 1);
629 SelectObject(hdcmem
, oldbm
);
632 pbmi
->bmiColors
[0].rgbRed
= 0xff;
633 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
634 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
635 pbmi
->bmiColors
[1].rgbRed
= 0;
636 pbmi
->bmiColors
[1].rgbGreen
= 0;
637 pbmi
->bmiColors
[1].rgbBlue
= 0;
639 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
640 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
642 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
644 oldbm
= SelectObject(hdcmem
, hdib
);
646 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
647 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
648 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
649 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
650 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
651 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
653 SelectObject(hdcmem
, oldbm
);
654 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
657 pbmi
->bmiHeader
.biBitCount
= 4;
658 for (i
= 0; i
< 16; i
++) {
659 pbmi
->bmiColors
[i
].rgbRed
= i
;
660 pbmi
->bmiColors
[i
].rgbGreen
= 16-i
;
661 pbmi
->bmiColors
[i
].rgbBlue
= 0;
663 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
664 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
665 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
666 ok(dibsec
.dsBmih
.biClrUsed
== 16,
667 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 16);
668 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
671 pbmi
->bmiHeader
.biBitCount
= 8;
673 for (i
= 0; i
< 128; i
++) {
674 pbmi
->bmiColors
[i
].rgbRed
= 255 - i
* 2;
675 pbmi
->bmiColors
[i
].rgbGreen
= i
* 2;
676 pbmi
->bmiColors
[i
].rgbBlue
= 0;
677 pbmi
->bmiColors
[255 - i
].rgbRed
= 0;
678 pbmi
->bmiColors
[255 - i
].rgbGreen
= i
* 2;
679 pbmi
->bmiColors
[255 - i
].rgbBlue
= 255 - i
* 2;
681 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
682 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
683 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
684 ok(dibsec
.dsBmih
.biClrUsed
== 256,
685 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
687 oldbm
= SelectObject(hdcmem
, hdib
);
689 for (i
= 0; i
< 256; i
++) {
690 test_color(hdcmem
, DIBINDEX(i
),
691 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
692 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
),
693 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
696 SelectObject(hdcmem
, oldbm
);
697 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
700 pbmi
->bmiHeader
.biBitCount
= 1;
702 /* Now create a palette and a palette indexed dib section */
703 memset(plogpal
, 0, sizeof(logpalbuf
));
704 plogpal
->palVersion
= 0x300;
705 plogpal
->palNumEntries
= 2;
706 plogpal
->palPalEntry
[0].peRed
= 0xff;
707 plogpal
->palPalEntry
[0].peBlue
= 0xff;
708 plogpal
->palPalEntry
[1].peGreen
= 0xff;
710 index
= (WORD
*)pbmi
->bmiColors
;
713 hpal
= CreatePalette(plogpal
);
714 ok(hpal
!= NULL
, "CreatePalette failed\n");
715 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
716 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
717 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
718 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
719 ok(dibsec
.dsBmih
.biClrUsed
== 2,
720 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
722 /* The colour table has already been grabbed from the dc, so we select back the
725 SelectPalette(hdc
, oldpal
, TRUE
);
726 oldbm
= SelectObject(hdcmem
, hdib
);
727 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
729 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
730 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
731 ok(rgb
[0].rgbRed
== 0xff && rgb
[0].rgbBlue
== 0xff && rgb
[0].rgbGreen
== 0 &&
732 rgb
[1].rgbRed
== 0 && rgb
[1].rgbBlue
== 0 && rgb
[1].rgbGreen
== 0xff,
733 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
734 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
735 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
737 c0
= RGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
, plogpal
->palPalEntry
[0].peBlue
);
738 c1
= RGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
, plogpal
->palPalEntry
[1].peBlue
);
740 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
741 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
742 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
743 test_color(hdcmem
, PALETTEINDEX(0), c0
, 0, 1);
744 test_color(hdcmem
, PALETTEINDEX(1), c1
, 0, 1);
745 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
746 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
,
747 plogpal
->palPalEntry
[0].peBlue
), c0
, 1, 1);
748 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
,
749 plogpal
->palPalEntry
[1].peBlue
), c1
, 1, 1);
750 test_color(hdcmem
, PALETTERGB(0, 0, 0), c1
, 1, 1);
751 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
752 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c0
, 1, 1);
753 test_color(hdcmem
, PALETTERGB(0, 1, 0), c1
, 1, 1);
754 test_color(hdcmem
, PALETTERGB(0x3f, 0, 0x3f), c1
, 1, 1);
755 test_color(hdcmem
, PALETTERGB(0x40, 0, 0x40), c0
, 1, 1);
757 /* Bottom and 2nd row from top green, everything else magenta */
758 bits
[0] = bits
[1] = 0xff;
759 bits
[13 * 4] = bits
[13*4 + 1] = 0xff;
761 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
763 pbmi
->bmiHeader
.biBitCount
= 32;
765 hdib2
= CreateDIBSection(NULL
, pbmi
, DIB_RGB_COLORS
, (void **)&bits32
, NULL
, 0);
766 ok(hdib2
!= NULL
, "CreateDIBSection failed\n");
767 hdcmem2
= CreateCompatibleDC(hdc
);
768 oldbm2
= SelectObject(hdcmem2
, hdib2
);
770 BitBlt(hdcmem2
, 0, 0, 16,16, hdcmem
, 0, 0, SRCCOPY
);
772 ok(bits32
[0] == 0xff00, "lower left pixel is %08x\n", bits32
[0]);
773 ok(bits32
[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32
[17]);
775 SelectObject(hdcmem2
, oldbm2
);
776 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
779 SelectObject(hdcmem
, oldbm
);
780 SelectObject(hdcmem
, oldpal
);
785 pbmi
->bmiHeader
.biBitCount
= 8;
787 memset(plogpal
, 0, sizeof(logpalbuf
));
788 plogpal
->palVersion
= 0x300;
789 plogpal
->palNumEntries
= 256;
791 for (i
= 0; i
< 128; i
++) {
792 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
793 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
794 plogpal
->palPalEntry
[i
].peGreen
= 0;
795 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
796 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
797 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
800 index
= (WORD
*)pbmi
->bmiColors
;
801 for (i
= 0; i
< 256; i
++) {
805 hpal
= CreatePalette(plogpal
);
806 ok(hpal
!= NULL
, "CreatePalette failed\n");
807 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
808 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
809 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
810 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
811 ok(dibsec
.dsBmih
.biClrUsed
== 256,
812 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
814 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
816 SelectPalette(hdc
, oldpal
, TRUE
);
817 oldbm
= SelectObject(hdcmem
, hdib
);
818 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
820 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
821 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
822 for (i
= 0; i
< 256; i
++) {
823 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
824 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
825 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
826 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
827 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
830 for (i
= 0; i
< 256; i
++) {
831 test_color(hdcmem
, DIBINDEX(i
),
832 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
833 test_color(hdcmem
, PALETTEINDEX(i
),
834 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
835 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
836 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
839 SelectPalette(hdcmem
, oldpal
, TRUE
);
840 SelectObject(hdcmem
, oldbm
);
849 static void test_mono_dibsection(void)
852 HBITMAP old_bm
, mono_ds
;
853 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
854 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
861 memdc
= CreateCompatibleDC(hdc
);
863 memset(pbmi
, 0, sizeof(bmibuf
));
864 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
865 pbmi
->bmiHeader
.biHeight
= 10;
866 pbmi
->bmiHeader
.biWidth
= 10;
867 pbmi
->bmiHeader
.biBitCount
= 1;
868 pbmi
->bmiHeader
.biPlanes
= 1;
869 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
870 pbmi
->bmiColors
[0].rgbRed
= 0xff;
871 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
872 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
873 pbmi
->bmiColors
[1].rgbRed
= 0x0;
874 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
875 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
878 * First dib section is 'inverted' ie color[0] is white, color[1] is black
881 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
882 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
883 old_bm
= SelectObject(memdc
, mono_ds
);
885 /* black border, white interior */
886 Rectangle(memdc
, 0, 0, 10, 10);
887 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
888 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
890 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
892 memset(bits
, 0, sizeof(bits
));
895 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
896 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
898 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
900 pbmi
->bmiColors
[0].rgbRed
= 0x0;
901 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
902 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
903 pbmi
->bmiColors
[1].rgbRed
= 0xff;
904 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
905 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
907 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
908 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
910 SelectObject(memdc
, old_bm
);
911 DeleteObject(mono_ds
);
914 * Next dib section is 'normal' ie color[0] is black, color[1] is white
917 pbmi
->bmiColors
[0].rgbRed
= 0x0;
918 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
919 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
920 pbmi
->bmiColors
[1].rgbRed
= 0xff;
921 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
922 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
924 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
925 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
926 old_bm
= SelectObject(memdc
, mono_ds
);
928 /* black border, white interior */
929 Rectangle(memdc
, 0, 0, 10, 10);
930 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
931 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
933 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
935 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
936 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
938 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
940 pbmi
->bmiColors
[0].rgbRed
= 0xff;
941 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
942 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
943 pbmi
->bmiColors
[1].rgbRed
= 0x0;
944 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
945 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
947 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
948 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
951 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
954 pbmi
->bmiColors
[0].rgbRed
= 0xff;
955 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
956 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
957 pbmi
->bmiColors
[1].rgbRed
= 0x0;
958 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
959 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
960 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
961 ok(num
== 2, "num = %d\n", num
);
963 /* black border, white interior */
964 Rectangle(memdc
, 0, 0, 10, 10);
966 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
967 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
969 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
971 memset(bits
, 0, sizeof(bits
));
974 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
975 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
977 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
979 pbmi
->bmiColors
[0].rgbRed
= 0x0;
980 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
981 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
982 pbmi
->bmiColors
[1].rgbRed
= 0xff;
983 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
984 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
986 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
987 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
989 SelectObject(memdc
, old_bm
);
990 DeleteObject(mono_ds
);
993 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
996 pbmi
->bmiColors
[0].rgbRed
= 0xff;
997 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
998 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
999 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
1000 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1001 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1003 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
1004 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
1005 old_bm
= SelectObject(memdc
, mono_ds
);
1007 /* black border, white interior */
1008 Rectangle(memdc
, 0, 0, 10, 10);
1009 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
1010 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
1012 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1014 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1015 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1016 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1017 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1018 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1019 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1021 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1022 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1024 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1026 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1027 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
1028 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
1029 pbmi
->bmiColors
[1].rgbRed
= 0x0;
1030 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1031 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1033 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1034 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1036 SelectObject(memdc
, old_bm
);
1037 DeleteObject(mono_ds
);
1043 static void test_bitmap(void)
1045 char buf
[256], buf_cmp
[256];
1046 HBITMAP hbmp
, hbmp_old
;
1052 hdc
= CreateCompatibleDC(0);
1055 SetLastError(0xdeadbeef);
1056 hbmp
= CreateBitmap(0x7ffffff, 1, 1, 1, NULL
);
1059 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1060 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1061 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1066 SetLastError(0xdeadbeef);
1067 hbmp
= CreateBitmap(0x7ffffff, 9, 1, 1, NULL
);
1070 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1071 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1072 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1077 SetLastError(0xdeadbeef);
1078 hbmp
= CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL
);
1079 ok(!hbmp
|| broken(hbmp
!= NULL
/* Win9x */), "CreateBitmap should fail\n");
1081 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1082 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1086 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
1087 assert(hbmp
!= NULL
);
1089 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1090 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1092 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1093 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1094 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1095 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1096 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1097 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1098 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1100 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
1101 assert(sizeof(buf
) == sizeof(buf_cmp
));
1103 ret
= GetBitmapBits(hbmp
, 0, NULL
);
1104 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
|| broken(ret
== 0 /* Win9x */),
1105 "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1107 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
1108 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
1110 memset(buf
, 0xAA, sizeof(buf
));
1111 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1112 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1113 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
1115 hbmp_old
= SelectObject(hdc
, hbmp
);
1117 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1118 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1120 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1121 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1122 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1123 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1124 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1125 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1126 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1128 memset(buf
, 0xAA, sizeof(buf
));
1129 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1130 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1131 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
1133 hbmp_old
= SelectObject(hdc
, hbmp_old
);
1134 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
1136 /* test various buffer sizes for GetObject */
1137 ret
= GetObject(hbmp
, sizeof(*bma
) * 2, bma
);
1138 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
1140 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
1141 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
1143 ret
= GetObject(hbmp
, 0, &bm
);
1144 ok(ret
== 0, "%d != 0\n", ret
);
1146 ret
= GetObject(hbmp
, 1, &bm
);
1147 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
1153 static void test_bmBits(void)
1159 memset(bits
, 0, sizeof(bits
));
1160 hbmp
= CreateBitmap(2, 2, 1, 4, bits
);
1161 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
1163 memset(&bmp
, 0xFF, sizeof(bmp
));
1164 ok(GetObject(hbmp
, sizeof(bmp
), &bmp
) == sizeof(bmp
),
1165 "GetObject failed or returned a wrong structure size\n");
1166 ok(!bmp
.bmBits
, "bmBits must be NULL for device-dependent bitmaps\n");
1171 static void test_GetDIBits_selected_DIB(UINT bpp
)
1185 /* Create a DIB section with a color table */
1187 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1188 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1192 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1194 /* Choose width and height such that the row length (in bytes)
1195 is a multiple of 4 (makes things easier) */
1196 info
->bmiHeader
.biWidth
= 32;
1197 info
->bmiHeader
.biHeight
= 32;
1198 info
->bmiHeader
.biPlanes
= 1;
1199 info
->bmiHeader
.biBitCount
= bpp
;
1200 info
->bmiHeader
.biCompression
= BI_RGB
;
1202 for (i
=0; i
< (1u << bpp
); i
++)
1204 BYTE c
= i
* (1 << (8 - bpp
));
1205 info
->bmiColors
[i
].rgbRed
= c
;
1206 info
->bmiColors
[i
].rgbGreen
= c
;
1207 info
->bmiColors
[i
].rgbBlue
= c
;
1208 info
->bmiColors
[i
].rgbReserved
= 0;
1211 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1213 dib_size
= bpp
* (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1215 /* Set the bits of the DIB section */
1216 for (i
=0; i
< dib_size
; i
++)
1218 ((BYTE
*)bits
)[i
] = i
% 256;
1221 /* Select the DIB into a DC */
1222 dib_dc
= CreateCompatibleDC(NULL
);
1223 old_bmp
= SelectObject(dib_dc
, dib
);
1224 dc
= CreateCompatibleDC(NULL
);
1225 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dib_size
);
1228 /* Copy the DIB attributes but not the color table */
1229 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1231 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1232 ok(res
, "GetDIBits failed\n");
1234 /* Compare the color table and the bits */
1235 equalContents
= TRUE
;
1236 for (i
=0; i
< (1u << bpp
); i
++)
1238 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1239 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1240 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1241 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1243 equalContents
= FALSE
;
1247 ok(equalContents
, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1249 equalContents
= TRUE
;
1250 for (i
=0; i
< dib_size
/ sizeof(DWORD
); i
++)
1252 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1254 equalContents
= FALSE
;
1258 ok(equalContents
, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp
);
1260 HeapFree(GetProcessHeap(), 0, bits2
);
1263 SelectObject(dib_dc
, old_bmp
);
1267 HeapFree(GetProcessHeap(), 0, info2
);
1268 HeapFree(GetProcessHeap(), 0, info
);
1271 static void test_GetDIBits_selected_DDB(BOOL monochrome
)
1286 width
= height
= 16;
1288 /* Create a DDB (device-dependent bitmap) */
1292 ddb
= CreateBitmap(width
, height
, 1, 1, NULL
);
1296 HDC screen_dc
= GetDC(NULL
);
1297 bpp
= GetDeviceCaps(screen_dc
, BITSPIXEL
) * GetDeviceCaps(screen_dc
, PLANES
);
1298 ddb
= CreateCompatibleBitmap(screen_dc
, width
, height
);
1299 ReleaseDC(NULL
, screen_dc
);
1302 /* Set the pixels */
1303 ddb_dc
= CreateCompatibleDC(NULL
);
1304 old_bmp
= SelectObject(ddb_dc
, ddb
);
1305 for (i
= 0; i
< width
; i
++)
1307 for (j
=0; j
< height
; j
++)
1309 BYTE c
= (i
* width
+ j
) % 256;
1310 SetPixelV(ddb_dc
, i
, j
, RGB(c
, c
, c
));
1313 SelectObject(ddb_dc
, old_bmp
);
1315 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1316 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1320 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1321 info
->bmiHeader
.biWidth
= width
;
1322 info
->bmiHeader
.biHeight
= height
;
1323 info
->bmiHeader
.biPlanes
= 1;
1324 info
->bmiHeader
.biBitCount
= bpp
;
1325 info
->bmiHeader
.biCompression
= BI_RGB
;
1327 dc
= CreateCompatibleDC(NULL
);
1329 /* Fill in biSizeImage */
1330 GetDIBits(dc
, ddb
, 0, height
, NULL
, info
, DIB_RGB_COLORS
);
1331 ok(info
->bmiHeader
.biSizeImage
!= 0, "GetDIBits failed to get the DIB attributes\n");
1333 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1334 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1339 res
= GetDIBits(dc
, ddb
, 0, height
, bits
, info
, DIB_RGB_COLORS
);
1340 ok(res
, "GetDIBits failed\n");
1342 /* Copy the DIB attributes but not the color table */
1343 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1345 /* Select the DDB into another DC */
1346 old_bmp
= SelectObject(ddb_dc
, ddb
);
1349 res
= GetDIBits(dc
, ddb
, 0, height
, bits2
, info2
, DIB_RGB_COLORS
);
1350 ok(res
, "GetDIBits failed\n");
1352 /* Compare the color table and the bits */
1355 equalContents
= TRUE
;
1356 for (i
=0; i
< (1u << bpp
); i
++)
1358 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1359 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1360 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1361 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1363 equalContents
= FALSE
;
1367 ok(equalContents
, "GetDIBits with DDB selected in DC: Got a different color table\n");
1370 equalContents
= TRUE
;
1371 for (i
=0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++)
1373 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1375 equalContents
= FALSE
;
1378 ok(equalContents
, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1380 /* Test the palette */
1381 equalContents
= TRUE
;
1382 if (info2
->bmiHeader
.biBitCount
<= 8)
1384 WORD
*colors
= (WORD
*)info2
->bmiColors
;
1386 /* Get the palette indices */
1387 res
= GetDIBits(dc
, ddb
, 0, 0, NULL
, info2
, DIB_PAL_COLORS
);
1388 if (res
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
) /* Win9x */
1389 res
= GetDIBits(dc
, ddb
, 0, height
, NULL
, info2
, DIB_PAL_COLORS
);
1390 ok(res
, "GetDIBits failed\n");
1392 for (i
=0;i
< 1 << info
->bmiHeader
.biSizeImage
; i
++)
1396 equalContents
= FALSE
;
1402 ok(equalContents
, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1404 HeapFree(GetProcessHeap(), 0, bits2
);
1405 HeapFree(GetProcessHeap(), 0, bits
);
1408 SelectObject(ddb_dc
, old_bmp
);
1412 HeapFree(GetProcessHeap(), 0, info2
);
1413 HeapFree(GetProcessHeap(), 0, info
);
1416 static void test_GetDIBits(void)
1418 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1419 static const BYTE bmp_bits_1
[16 * 2] =
1421 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1422 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1423 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1424 0xff,0xff, 0,0, 0xff,0xff, 0,0
1426 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1427 static const BYTE dib_bits_1
[16 * 4] =
1429 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1430 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1431 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1432 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1434 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1435 static const BYTE bmp_bits_24
[16 * 16*3] =
1437 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1438 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1439 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1440 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1441 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1442 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1443 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1444 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1445 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1446 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1447 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1448 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1449 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1450 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1451 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1452 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1453 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1454 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1455 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1456 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1457 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1458 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1459 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1460 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1461 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1462 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1463 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1464 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1465 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1466 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1467 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1468 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1470 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1471 static const BYTE dib_bits_24
[16 * 16*3] =
1473 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1474 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1475 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1476 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1477 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1478 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1479 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1480 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1481 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1482 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1483 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1484 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1485 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1486 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1487 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1488 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1489 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1490 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1491 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1492 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1493 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1494 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1495 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1496 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1497 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1498 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1499 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1500 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1501 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1502 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1503 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1504 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1509 int i
, bytes
, lines
;
1511 char bi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1512 BITMAPINFO
*bi
= (BITMAPINFO
*)bi_buf
;
1516 /* 1-bit source bitmap data */
1517 hbmp
= CreateBitmap(16, 16, 1, 1, bmp_bits_1
);
1518 ok(hbmp
!= 0, "CreateBitmap failed\n");
1520 memset(&bm
, 0xAA, sizeof(bm
));
1521 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1522 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1523 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1524 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1525 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1526 ok(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1527 ok(bm
.bmPlanes
== 1, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1528 ok(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1529 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1531 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1532 ok(bytes
== sizeof(bmp_bits_1
) || broken(bytes
== 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes
);
1533 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1534 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1535 ok(!memcmp(buf
, bmp_bits_1
, sizeof(bmp_bits_1
)), "bitmap bits don't match\n");
1537 /* retrieve 1-bit DIB data */
1538 memset(bi
, 0, sizeof(*bi
));
1539 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1540 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1541 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1542 bi
->bmiHeader
.biPlanes
= 1;
1543 bi
->bmiHeader
.biBitCount
= 1;
1544 bi
->bmiHeader
.biCompression
= BI_RGB
;
1545 bi
->bmiHeader
.biSizeImage
= 0;
1546 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1547 SetLastError(0xdeadbeef);
1548 lines
= GetDIBits(0, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1549 ok(lines
== 0, "GetDIBits copied %d lines with hdc = 0\n", lines
);
1550 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
1551 broken(GetLastError() == 0xdeadbeef), /* winnt */
1552 "wrong error %u\n", GetLastError());
1553 ok(bi
->bmiHeader
.biSizeImage
== 0, "expected 0, got %u\n", bi
->bmiHeader
.biSizeImage
);
1555 memset(buf
, 0xAA, sizeof(buf
));
1556 SetLastError(0xdeadbeef);
1557 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1558 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1559 lines
, bm
.bmHeight
, GetLastError());
1560 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
), "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1562 /* the color table consists of black and white */
1563 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1564 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1565 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1566 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1567 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1568 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1569 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1570 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1571 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1572 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1573 for (i
= 2; i
< 256; i
++)
1575 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1576 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1577 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1578 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1579 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1582 /* returned bits are DWORD aligned and upside down */
1583 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)), "DIB bits don't match\n");
1585 /* Test the palette indices */
1586 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1587 SetLastError(0xdeadbeef);
1588 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1590 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1591 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1592 for (i
= 2; i
< 256; i
++)
1593 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[1]);
1595 /* retrieve 24-bit DIB data */
1596 memset(bi
, 0, sizeof(*bi
));
1597 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1598 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1599 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1600 bi
->bmiHeader
.biPlanes
= 1;
1601 bi
->bmiHeader
.biBitCount
= 24;
1602 bi
->bmiHeader
.biCompression
= BI_RGB
;
1603 bi
->bmiHeader
.biSizeImage
= 0;
1604 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1605 memset(buf
, 0xAA, sizeof(buf
));
1606 SetLastError(0xdeadbeef);
1607 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1608 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1609 lines
, bm
.bmHeight
, GetLastError());
1610 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
), "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1612 /* the color table doesn't exist for 24-bit images */
1613 for (i
= 0; i
< 256; i
++)
1615 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1616 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1617 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1618 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1619 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1622 /* returned bits are DWORD aligned and upside down */
1623 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1626 /* 24-bit source bitmap data */
1627 hbmp
= CreateCompatibleBitmap(hdc
, 16, 16);
1628 ok(hbmp
!= 0, "CreateBitmap failed\n");
1629 SetLastError(0xdeadbeef);
1630 bi
->bmiHeader
.biHeight
= -bm
.bmHeight
; /* indicate bottom-up data */
1631 lines
= SetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, bmp_bits_24
, bi
, DIB_RGB_COLORS
);
1632 ok(lines
== bm
.bmHeight
, "SetDIBits copied %d lines of %d, error %u\n",
1633 lines
, bm
.bmHeight
, GetLastError());
1635 memset(&bm
, 0xAA, sizeof(bm
));
1636 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1637 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1638 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1639 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1640 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1641 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1642 ok(bm
.bmPlanes
== GetDeviceCaps(hdc
, PLANES
), "wrong bmPlanes %u\n", bm
.bmPlanes
);
1643 ok(bm
.bmBitsPixel
== GetDeviceCaps(hdc
, BITSPIXEL
), "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1644 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1646 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1647 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1648 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1649 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1650 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1651 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1653 /* retrieve 1-bit DIB data */
1654 memset(bi
, 0, sizeof(*bi
));
1655 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1656 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1657 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1658 bi
->bmiHeader
.biPlanes
= 1;
1659 bi
->bmiHeader
.biBitCount
= 1;
1660 bi
->bmiHeader
.biCompression
= BI_RGB
;
1661 bi
->bmiHeader
.biSizeImage
= 0;
1662 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1663 memset(buf
, 0xAA, sizeof(buf
));
1664 SetLastError(0xdeadbeef);
1665 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1666 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1667 lines
, bm
.bmHeight
, GetLastError());
1668 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
), "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1670 /* the color table consists of black and white */
1671 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1672 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1673 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1674 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1675 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1676 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1677 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1678 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1679 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1680 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1681 for (i
= 2; i
< 256; i
++)
1683 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1684 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1685 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1686 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1687 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1690 /* returned bits are DWORD aligned and upside down */
1692 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)), "DIB bits don't match\n");
1694 /* Test the palette indices */
1695 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1696 SetLastError(0xdeadbeef);
1697 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1699 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1700 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1701 for (i
= 2; i
< 256; i
++)
1702 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[i
]);
1704 /* retrieve 24-bit DIB data */
1705 memset(bi
, 0, sizeof(*bi
));
1706 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1707 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1708 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1709 bi
->bmiHeader
.biPlanes
= 1;
1710 bi
->bmiHeader
.biBitCount
= 24;
1711 bi
->bmiHeader
.biCompression
= BI_RGB
;
1712 bi
->bmiHeader
.biSizeImage
= 0;
1713 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1714 memset(buf
, 0xAA, sizeof(buf
));
1715 SetLastError(0xdeadbeef);
1716 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1717 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1718 lines
, bm
.bmHeight
, GetLastError());
1719 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
), "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1721 /* the color table doesn't exist for 24-bit images */
1722 for (i
= 0; i
< 256; i
++)
1724 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1725 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1726 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1727 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1728 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1731 /* returned bits are DWORD aligned and upside down */
1732 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1738 static void test_GetDIBits_BI_BITFIELDS(void)
1740 /* Try a screen resolution detection technique
1741 * from the September 1999 issue of Windows Developer's Journal
1742 * which seems to be in widespread use.
1743 * http://www.lesher.ws/highcolor.html
1744 * http://www.lesher.ws/vidfmt.c
1745 * It hinges on being able to retrieve the bitmaps
1746 * for the three primary colors in non-paletted 16 bit mode.
1748 char dibinfo_buf
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
1750 LPBITMAPINFO dibinfo
= (LPBITMAPINFO
) dibinfo_buf
;
1755 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1756 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1759 ok(hdc
!= NULL
, "GetDC failed?\n");
1760 hbm
= CreateCompatibleBitmap(hdc
, 1, 1);
1761 ok(hbm
!= NULL
, "CreateCompatibleBitmap failed?\n");
1763 /* Call GetDIBits to fill in bmiHeader. */
1764 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1765 ok(ret
== 1, "GetDIBits failed\n");
1766 if (dibinfo
->bmiHeader
.biBitCount
> 8)
1768 DWORD
*bitmasks
= (DWORD
*)dibinfo
->bmiColors
;
1770 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1771 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1773 ok( !bitmasks
[0], "red mask is set\n" );
1774 ok( !bitmasks
[1], "green mask is set\n" );
1775 ok( !bitmasks
[2], "blue mask is set\n" );
1777 /* test with NULL bits pointer and correct bpp */
1778 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1779 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1780 ok(ret
== 1, "GetDIBits failed\n");
1782 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1783 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1784 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1785 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1787 /* test with valid bits pointer */
1788 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1789 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1790 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1791 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1792 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1793 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1794 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1796 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1797 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1798 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1799 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1801 /* now with bits and 0 lines */
1802 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1803 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1804 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1805 SetLastError(0xdeadbeef);
1806 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1807 if (ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1808 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1811 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1813 ok( !bitmasks
[0], "red mask is set\n" );
1814 ok( !bitmasks
[1], "green mask is set\n" );
1815 ok( !bitmasks
[2], "blue mask is set\n" );
1816 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1818 memset(bitmasks
, 0, 3*sizeof(DWORD
));
1819 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1820 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1821 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1823 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1824 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1825 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1826 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1829 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1832 ReleaseDC(NULL
, hdc
);
1835 static void test_select_object(void)
1838 HBITMAP hbm
, hbm_old
;
1840 DWORD depths
[] = {8, 15, 16, 24, 32};
1845 ok(hdc
!= 0, "GetDC(0) failed\n");
1846 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1847 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1849 hbm_old
= SelectObject(hdc
, hbm
);
1850 ok(hbm_old
== 0, "SelectObject should fail\n");
1855 hdc
= CreateCompatibleDC(0);
1856 ok(hdc
!= 0, "GetDC(0) failed\n");
1857 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1858 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1860 hbm_old
= SelectObject(hdc
, hbm
);
1861 ok(hbm_old
!= 0, "SelectObject failed\n");
1862 hbm_old
= SelectObject(hdc
, hbm_old
);
1863 ok(hbm_old
== hbm
, "SelectObject failed\n");
1867 /* test an 1-bpp bitmap */
1868 planes
= GetDeviceCaps(hdc
, PLANES
);
1871 hbm
= CreateBitmap(10, 10, planes
, bpp
, NULL
);
1872 ok(hbm
!= 0, "CreateBitmap failed\n");
1874 hbm_old
= SelectObject(hdc
, hbm
);
1875 ok(hbm_old
!= 0, "SelectObject failed\n");
1876 hbm_old
= SelectObject(hdc
, hbm_old
);
1877 ok(hbm_old
== hbm
, "SelectObject failed\n");
1881 for(i
= 0; i
< sizeof(depths
)/sizeof(depths
[0]); i
++) {
1882 /* test a color bitmap to dc bpp matching */
1883 planes
= GetDeviceCaps(hdc
, PLANES
);
1884 bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
1886 hbm
= CreateBitmap(10, 10, planes
, depths
[i
], NULL
);
1887 ok(hbm
!= 0, "CreateBitmap failed\n");
1889 hbm_old
= SelectObject(hdc
, hbm
);
1890 if(depths
[i
] == bpp
||
1891 (bpp
== 16 && depths
[i
] == 15) /* 16 and 15 bpp are compatible */
1893 ok(hbm_old
!= 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp
, depths
[i
]);
1894 SelectObject(hdc
, hbm_old
);
1896 ok(hbm_old
== 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp
, depths
[i
]);
1899 memset(&bm
, 0xAA, sizeof(bm
));
1900 bytes
= GetObject(hbm
, sizeof(bm
), &bm
);
1901 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1902 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1903 ok(bm
.bmWidth
== 10, "wrong bmWidth %d\n", bm
.bmWidth
);
1904 ok(bm
.bmHeight
== 10, "wrong bmHeight %d\n", bm
.bmHeight
);
1905 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1906 ok(bm
.bmPlanes
== planes
, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1907 if(depths
[i
] == 15) {
1908 ok(bm
.bmBitsPixel
== 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm
.bmBitsPixel
);
1910 ok(bm
.bmBitsPixel
== depths
[i
], "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1912 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1920 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp
, int line
)
1925 ret
= GetObjectType(hbmp
);
1926 ok_(__FILE__
, line
)(ret
== OBJ_BITMAP
, "the object %p is not bitmap\n", hbmp
);
1928 ret
= GetObject(hbmp
, 0, 0);
1929 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) /* XP */ ||
1930 ret
== sizeof(DIBSECTION
) /* Win9x */, "object size %d\n", ret
);
1932 memset(&bm
, 0xDA, sizeof(bm
));
1933 SetLastError(0xdeadbeef);
1934 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1935 if (!ret
) /* XP, only for curObj2 */ return;
1936 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) ||
1937 ret
== sizeof(DIBSECTION
) /* Win9x, only for curObj2 */,
1938 "GetObject returned %d, error %u\n", ret
, GetLastError());
1939 ok_(__FILE__
, line
)(bm
.bmType
== 0, "wrong bmType, expected 0 got %d\n", bm
.bmType
);
1940 ok_(__FILE__
, line
)(bm
.bmWidth
== 1, "wrong bmWidth, expected 1 got %d\n", bm
.bmWidth
);
1941 ok_(__FILE__
, line
)(bm
.bmHeight
== 1, "wrong bmHeight, expected 1 got %d\n", bm
.bmHeight
);
1942 ok_(__FILE__
, line
)(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes, expected 2 got %d\n", bm
.bmWidthBytes
);
1943 ok_(__FILE__
, line
)(bm
.bmPlanes
== 1, "wrong bmPlanes, expected 1 got %u\n", bm
.bmPlanes
);
1944 ok_(__FILE__
, line
)(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel, expected 1 got %d\n", bm
.bmBitsPixel
);
1945 ok_(__FILE__
, line
)(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1948 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
1950 static void test_CreateBitmap(void)
1953 HDC screenDC
= GetDC(0);
1954 HDC hdc
= CreateCompatibleDC(screenDC
);
1957 /* all of these are the stock monochrome bitmap */
1958 HBITMAP bm
= CreateCompatibleBitmap(hdc
, 0, 0);
1959 HBITMAP bm1
= CreateCompatibleBitmap(screenDC
, 0, 0);
1960 HBITMAP bm4
= CreateBitmap(0, 1, 0, 0, 0);
1961 HBITMAP bm5
= CreateDiscardableBitmap(hdc
, 0, 0);
1962 HBITMAP curObj1
= GetCurrentObject(hdc
, OBJ_BITMAP
);
1963 HBITMAP curObj2
= GetCurrentObject(screenDC
, OBJ_BITMAP
);
1965 /* these 2 are not the stock monochrome bitmap */
1966 HBITMAP bm2
= CreateCompatibleBitmap(hdc
, 1, 1);
1967 HBITMAP bm3
= CreateBitmap(1, 1, 1, 1, 0);
1969 HBITMAP old1
= SelectObject(hdc
, bm2
);
1970 HBITMAP old2
= SelectObject(screenDC
, bm3
);
1971 SelectObject(hdc
, old1
);
1972 SelectObject(screenDC
, old2
);
1974 ok(bm
== bm1
&& bm
== bm4
&& bm
== bm5
&& bm
== curObj1
&& bm
== old1
,
1975 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
1976 bm
, bm1
, bm4
, bm5
, curObj1
, old1
);
1977 ok(bm
!= bm2
&& bm
!= bm3
, "0: %p, 2: %p, 3: %p\n", bm
, bm2
, bm3
);
1979 ok(bm
!= curObj2
|| /* WinXP */
1980 broken(bm
== curObj2
) /* Win9x */,
1981 "0: %p, curObj2 %p\n", bm
, curObj2
);
1982 ok(old2
== 0, "old2 %p\n", old2
);
1984 test_mono_1x1_bmp(bm
);
1985 test_mono_1x1_bmp(bm1
);
1986 test_mono_1x1_bmp(bm2
);
1987 test_mono_1x1_bmp(bm3
);
1988 test_mono_1x1_bmp(bm4
);
1989 test_mono_1x1_bmp(bm5
);
1990 test_mono_1x1_bmp(old1
);
1991 test_mono_1x1_bmp(curObj1
);
2001 ReleaseDC(0, screenDC
);
2003 /* show that Windows ignores the provided bm.bmWidthBytes */
2007 bmp
.bmWidthBytes
= 28;
2009 bmp
.bmBitsPixel
= 1;
2011 bm
= CreateBitmapIndirect(&bmp
);
2012 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2013 test_mono_1x1_bmp(bm
);
2016 /* Test how the bmBitsPixel field is treated */
2017 for(i
= 1; i
<= 33; i
++) {
2021 bmp
.bmWidthBytes
= 28;
2023 bmp
.bmBitsPixel
= i
;
2025 SetLastError(0xdeadbeef);
2026 bm
= CreateBitmapIndirect(&bmp
);
2028 DWORD error
= GetLastError();
2030 broken(bm
!= 0), /* Win9x and WinMe */
2031 "CreateBitmapIndirect for %d bpp succeeded\n", i
);
2032 ok(error
== ERROR_INVALID_PARAMETER
||
2033 broken(error
== 0xdeadbeef), /* Win9x and WinME */
2034 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error
);
2038 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2039 GetObject(bm
, sizeof(bmp
), &bmp
);
2046 } else if(i
<= 16) {
2048 } else if(i
<= 24) {
2050 } else if(i
<= 32) {
2053 ok(bmp
.bmBitsPixel
== expect
||
2054 broken(bmp
.bmBitsPixel
== i
), /* Win9x and WinMe */
2055 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2056 i
, bmp
.bmBitsPixel
, expect
);
2061 static void test_bitmapinfoheadersize(void)
2068 memset(&bmi
, 0, sizeof(BITMAPINFO
));
2069 bmi
.bmiHeader
.biHeight
= 100;
2070 bmi
.bmiHeader
.biWidth
= 512;
2071 bmi
.bmiHeader
.biBitCount
= 24;
2072 bmi
.bmiHeader
.biPlanes
= 1;
2074 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) - 1;
2076 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2077 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2079 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2081 SetLastError(0xdeadbeef);
2082 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2083 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2086 bmi
.bmiHeader
.biSize
++;
2088 SetLastError(0xdeadbeef);
2089 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2091 broken(!hdib
), /* Win98, WinMe */
2092 "CreateDIBSection error %d\n", GetLastError());
2095 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFO
);
2097 SetLastError(0xdeadbeef);
2098 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2100 broken(!hdib
), /* Win98, WinMe */
2101 "CreateDIBSection error %d\n", GetLastError());
2104 bmi
.bmiHeader
.biSize
++;
2106 SetLastError(0xdeadbeef);
2107 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2109 broken(!hdib
), /* Win98, WinMe */
2110 "CreateDIBSection error %d\n", GetLastError());
2113 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
2115 SetLastError(0xdeadbeef);
2116 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2117 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2120 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
2122 SetLastError(0xdeadbeef);
2123 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2125 broken(!hdib
), /* Win95 */
2126 "CreateDIBSection error %d\n", GetLastError());
2129 memset(&bci
, 0, sizeof(BITMAPCOREINFO
));
2130 bci
.bmciHeader
.bcHeight
= 100;
2131 bci
.bmciHeader
.bcWidth
= 512;
2132 bci
.bmciHeader
.bcBitCount
= 24;
2133 bci
.bmciHeader
.bcPlanes
= 1;
2135 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
) - 1;
2137 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2138 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2140 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2142 SetLastError(0xdeadbeef);
2143 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2144 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2147 bci
.bmciHeader
.bcSize
++;
2149 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2150 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2152 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREINFO
);
2154 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2155 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2160 static void test_get16dibits(void)
2162 BYTE bits
[4 * (16 / sizeof(BYTE
))];
2164 HDC screen_dc
= GetDC(NULL
);
2167 int info_len
= sizeof(BITMAPINFOHEADER
) + 1024;
2169 int overwritten_bytes
= 0;
2171 memset(bits
, 0, sizeof(bits
));
2172 hbmp
= CreateBitmap(2, 2, 1, 16, bits
);
2173 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
2175 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info_len
);
2178 memset(info
, '!', info_len
);
2179 memset(info
, 0, sizeof(info
->bmiHeader
));
2181 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
2182 info
->bmiHeader
.biWidth
= 2;
2183 info
->bmiHeader
.biHeight
= 2;
2184 info
->bmiHeader
.biPlanes
= 1;
2185 info
->bmiHeader
.biCompression
= BI_RGB
;
2187 ret
= GetDIBits(screen_dc
, hbmp
, 0, 0, NULL
, info
, 0);
2188 ok(ret
!= 0, "GetDIBits failed\n");
2190 for (p
= ((BYTE
*) info
) + sizeof(info
->bmiHeader
); (p
- ((BYTE
*) info
)) < info_len
; p
++)
2192 overwritten_bytes
++;
2193 ok(overwritten_bytes
== 0, "GetDIBits wrote past the buffer given\n");
2195 HeapFree(GetProcessHeap(), 0, info
);
2197 ReleaseDC(NULL
, screen_dc
);
2200 static void test_GdiAlphaBlend(void)
2202 /* test out-of-bound parameters for GdiAlphaBlend */
2215 BLENDFUNCTION blend
;
2217 if (!pGdiAlphaBlend
)
2219 win_skip("GdiAlphaBlend() is not implemented\n");
2223 hdcNull
= GetDC(NULL
);
2224 hdcDst
= CreateCompatibleDC(hdcNull
);
2225 bmpDst
= CreateCompatibleBitmap(hdcNull
, 100, 100);
2226 hdcSrc
= CreateCompatibleDC(hdcNull
);
2228 memset(&bmi
, 0, sizeof(bmi
)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2229 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
2230 bmi
.bmiHeader
.biHeight
= 20;
2231 bmi
.bmiHeader
.biWidth
= 20;
2232 bmi
.bmiHeader
.biBitCount
= 32;
2233 bmi
.bmiHeader
.biPlanes
= 1;
2234 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2235 bmpSrc
= CreateDIBSection(hdcDst
, &bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2236 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2238 oldDst
= SelectObject(hdcDst
, bmpDst
);
2239 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2241 blend
.BlendOp
= AC_SRC_OVER
;
2242 blend
.BlendFlags
= 0;
2243 blend
.SourceConstantAlpha
= 128;
2244 blend
.AlphaFormat
= 0;
2246 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, 0, 20, 20, blend
), TRUE
, BOOL
, "%d");
2247 SetLastError(0xdeadbeef);
2248 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2249 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER
, int, "%d");
2250 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), FALSE
, BOOL
, "%d");
2251 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 15, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2252 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2253 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2255 SetWindowOrgEx(hdcSrc
, -10, -10, NULL
);
2256 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), TRUE
, BOOL
, "%d");
2257 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), TRUE
, BOOL
, "%d");
2258 SetMapMode(hdcSrc
, MM_ANISOTROPIC
);
2259 ScaleWindowExtEx(hdcSrc
, 10, 1, 10, 1, NULL
);
2260 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 30, 30, blend
), TRUE
, BOOL
, "%d");
2261 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 30, 30, blend
), TRUE
, BOOL
, "%d");
2263 SelectObject(hdcDst
, oldDst
);
2264 SelectObject(hdcSrc
, oldSrc
);
2265 DeleteObject(bmpSrc
);
2266 DeleteObject(bmpDst
);
2270 ReleaseDC(NULL
, hdcNull
);
2274 static void test_clipping(void)
2284 HDC hdcDst
= CreateCompatibleDC( NULL
);
2285 HDC hdcSrc
= CreateCompatibleDC( NULL
);
2287 BITMAPINFO bmpinfo
={{0}};
2288 bmpinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2289 bmpinfo
.bmiHeader
.biWidth
= 100;
2290 bmpinfo
.bmiHeader
.biHeight
= 100;
2291 bmpinfo
.bmiHeader
.biPlanes
= 1;
2292 bmpinfo
.bmiHeader
.biBitCount
= GetDeviceCaps( hdcDst
, BITSPIXEL
);
2293 bmpinfo
.bmiHeader
.biCompression
= BI_RGB
;
2295 bmpDst
= CreateDIBSection( hdcDst
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2296 ok(bmpDst
!= NULL
, "Couldn't create destination bitmap\n");
2297 oldDst
= SelectObject( hdcDst
, bmpDst
);
2299 bmpSrc
= CreateDIBSection( hdcSrc
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2300 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2301 oldSrc
= SelectObject( hdcSrc
, bmpSrc
);
2303 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 100, 100, SRCCOPY
);
2304 ok(result
, "BitBlt failed\n");
2306 hRgn
= CreateRectRgn( 0,0,0,0 );
2307 SelectClipRgn( hdcDst
, hRgn
);
2309 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 0, 0, SRCCOPY
);
2310 ok(result
, "BitBlt failed\n");
2312 DeleteObject( bmpDst
);
2313 DeleteObject( bmpSrc
);
2314 DeleteObject( hRgn
);
2322 is_win9x
= GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
) == 0;
2324 hdll
= GetModuleHandle("gdi32.dll");
2325 pGdiAlphaBlend
= (void*)GetProcAddress(hdll
, "GdiAlphaBlend");
2327 test_createdibitmap();
2329 test_mono_dibsection();
2332 test_GetDIBits_selected_DIB(1);
2333 test_GetDIBits_selected_DIB(4);
2334 test_GetDIBits_selected_DIB(8);
2335 test_GetDIBits_selected_DDB(TRUE
);
2336 test_GetDIBits_selected_DDB(FALSE
);
2338 test_GetDIBits_BI_BITFIELDS();
2339 test_select_object();
2340 test_CreateBitmap();
2341 test_GdiAlphaBlend();
2342 test_bitmapinfoheadersize();