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 BYTE 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
)) ||
105 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
106 "buffers do not match, depth %d\n", bmih
->biBitCount
);
108 /* test various buffer sizes for GetObject */
109 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
110 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
112 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
113 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
115 ret
= GetObject(hbm
, 0, &bm
);
116 ok(ret
== 0, "%d != 0\n", ret
);
118 ret
= GetObject(hbm
, 1, &bm
);
119 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
121 /* Don't trust Win9x not to try to write to NULL */
124 ret
= GetObject(hbm
, 0, NULL
);
125 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
129 static void test_createdibitmap(void)
132 BITMAPINFOHEADER bmih
;
134 HBITMAP hbm
, hbm_colour
, hbm_old
;
139 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
);
140 memset(&bmih
, 0, sizeof(bmih
));
141 bmih
.biSize
= sizeof(bmih
);
145 bmih
.biBitCount
= 32;
146 bmih
.biCompression
= BI_RGB
;
148 hbm
= CreateDIBitmap(hdc
, NULL
, CBM_INIT
, NULL
, NULL
, 0);
149 ok(hbm
== NULL
, "CreateDIBitmap should fail\n");
150 hbm
= CreateDIBitmap(hdc
, NULL
, 0, NULL
, NULL
, 0);
151 ok(hbm
== NULL
, "CreateDIBitmap should fail\n");
153 /* First create an un-initialised bitmap. The depth of the bitmap
154 should match that of the hdc and not that supplied in bmih.
157 /* First try 32 bits */
158 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
159 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
160 test_bitmap_info(hbm
, screen_depth
, &bmih
);
164 bmih
.biBitCount
= 16;
165 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
166 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
167 test_bitmap_info(hbm
, screen_depth
, &bmih
);
172 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
173 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
174 test_bitmap_info(hbm
, screen_depth
, &bmih
);
177 /* Now with a monochrome dc we expect a monochrome bitmap */
178 hdcmem
= CreateCompatibleDC(hdc
);
180 /* First try 32 bits */
181 bmih
.biBitCount
= 32;
182 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
183 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
184 test_bitmap_info(hbm
, 1, &bmih
);
188 bmih
.biBitCount
= 16;
189 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
190 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
191 test_bitmap_info(hbm
, 1, &bmih
);
196 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
197 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
198 test_bitmap_info(hbm
, 1, &bmih
);
201 /* Now select a polychrome bitmap into the dc and we expect
202 screen_depth bitmaps again */
203 hbm_colour
= CreateCompatibleBitmap(hdc
, bmih
.biWidth
, bmih
.biHeight
);
204 test_bitmap_info(hbm_colour
, screen_depth
, &bmih
);
205 hbm_old
= SelectObject(hdcmem
, hbm_colour
);
207 /* First try 32 bits */
208 bmih
.biBitCount
= 32;
209 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
210 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
211 test_bitmap_info(hbm
, screen_depth
, &bmih
);
215 bmih
.biBitCount
= 16;
216 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
217 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
218 test_bitmap_info(hbm
, screen_depth
, &bmih
);
223 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
224 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
225 test_bitmap_info(hbm
, screen_depth
, &bmih
);
228 SelectObject(hdcmem
, hbm_old
);
229 DeleteObject(hbm_colour
);
232 /* If hdc == 0 then we get a 1 bpp bitmap */
234 bmih
.biBitCount
= 32;
235 hbm
= CreateDIBitmap(0, &bmih
, 0, NULL
, NULL
, 0);
236 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
237 test_bitmap_info(hbm
, 1, &bmih
);
241 /* Test how formats are converted */
247 memset(&bm
, 0, sizeof(bm
));
248 bm
.bmiHeader
.biSize
= sizeof(bm
.bmiHeader
);
249 bm
.bmiHeader
.biWidth
= 1;
250 bm
.bmiHeader
.biHeight
= 1;
251 bm
.bmiHeader
.biPlanes
= 1;
252 bm
.bmiHeader
.biBitCount
= 24;
253 bm
.bmiHeader
.biCompression
= BI_RGB
;
254 bm
.bmiHeader
.biSizeImage
= 0;
255 hbm
= CreateDIBitmap(hdc
, &bmih
, CBM_INIT
, &pixel
, &bm
, DIB_RGB_COLORS
);
256 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
259 bm
.bmiHeader
.biBitCount
= 32;
260 GetDIBits(hdc
, hbm
, 0, 1, &pixel
, &bm
, DIB_RGB_COLORS
);
261 ok(pixel
== 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel
);
267 static INT
DIB_GetWidthBytes( int width
, int bpp
)
273 case 1: words
= (width
+ 31) / 32; break;
274 case 4: words
= (width
+ 7) / 8; break;
275 case 8: words
= (width
+ 3) / 4; break;
277 case 16: words
= (width
+ 1) / 2; break;
278 case 24: words
= (width
* 3 + 3)/4; break;
279 case 32: words
= width
; break;
283 trace("Unknown depth %d, please report.\n", bpp
);
290 static void test_dib_info(HBITMAP hbm
, const void *bits
, const BITMAPINFOHEADER
*bmih
)
296 INT ret
, bm_width_bytes
, dib_width_bytes
;
299 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
300 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
302 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
303 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
304 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
305 dib_width_bytes
= DIB_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
306 bm_width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
307 if (bm
.bmWidthBytes
!= dib_width_bytes
) /* Win2k bug */
308 ok(bm
.bmWidthBytes
== bm_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, bm_width_bytes
);
310 ok(bm
.bmWidthBytes
== dib_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, dib_width_bytes
);
311 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
312 ok(bm
.bmBitsPixel
== bmih
->biBitCount
, "bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, bmih
->biBitCount
);
313 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
315 buf
= HeapAlloc(GetProcessHeap(), 0, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
317 /* GetBitmapBits returns not 32-bit aligned data */
318 SetLastError(0xdeadbeef);
319 ret
= GetBitmapBits(hbm
, 0, NULL
);
320 ok(ret
== bm_width_bytes
* bm
.bmHeight
||
321 broken(ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
), /* Win9x */
322 "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
324 memset(buf
, 0xAA, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
325 ret
= GetBitmapBits(hbm
, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096, buf
);
326 ok(ret
== bm_width_bytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
328 HeapFree(GetProcessHeap(), 0, buf
);
330 /* test various buffer sizes for GetObject */
331 memset(&ds
, 0xAA, sizeof(ds
));
332 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
333 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
334 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
335 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
336 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
338 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
339 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
341 ret
= GetObject(hbm
, 0, &bm
);
342 ok(ret
== 0, "%d != 0\n", ret
);
344 ret
= GetObject(hbm
, 1, &bm
);
345 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
347 /* test various buffer sizes for GetObject */
348 ret
= GetObject(hbm
, 0, NULL
);
349 ok(ret
== sizeof(bm
) || broken(ret
== sizeof(DIBSECTION
) /* Win9x */), "wrong size %d\n", ret
);
351 ret
= GetObject(hbm
, sizeof(*dsa
) * 2, dsa
);
352 ok(ret
== sizeof(*dsa
) || broken(ret
== sizeof(*dsa
) * 2 /* Win9x */), "wrong size %d\n", ret
);
354 memset(&ds
, 0xAA, sizeof(ds
));
355 ret
= GetObject(hbm
, sizeof(ds
), &ds
);
356 ok(ret
== sizeof(ds
), "wrong size %d\n", ret
);
358 ok(ds
.dsBm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", ds
.dsBm
.bmBits
, bits
);
359 if (ds
.dsBm
.bmWidthBytes
!= bm_width_bytes
) /* Win2k bug */
360 ok(ds
.dsBmih
.biSizeImage
== ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
, "%u != %u\n",
361 ds
.dsBmih
.biSizeImage
, ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
);
362 ok(bmih
->biSizeImage
== 0, "%u != 0\n", bmih
->biSizeImage
);
363 ds
.dsBmih
.biSizeImage
= 0;
365 ok(ds
.dsBmih
.biSize
== bmih
->biSize
, "%u != %u\n", ds
.dsBmih
.biSize
, bmih
->biSize
);
366 ok(ds
.dsBmih
.biWidth
== bmih
->biWidth
, "%u != %u\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
367 ok(ds
.dsBmih
.biHeight
== bmih
->biHeight
, "%u != %u\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
368 ok(ds
.dsBmih
.biPlanes
== bmih
->biPlanes
, "%u != %u\n", ds
.dsBmih
.biPlanes
, bmih
->biPlanes
);
369 ok(ds
.dsBmih
.biBitCount
== bmih
->biBitCount
, "%u != %u\n", ds
.dsBmih
.biBitCount
, bmih
->biBitCount
);
370 ok(ds
.dsBmih
.biCompression
== bmih
->biCompression
, "%u != %u\n", ds
.dsBmih
.biCompression
, bmih
->biCompression
);
371 ok(ds
.dsBmih
.biSizeImage
== bmih
->biSizeImage
, "%u != %u\n", ds
.dsBmih
.biSizeImage
, bmih
->biSizeImage
);
372 ok(ds
.dsBmih
.biXPelsPerMeter
== bmih
->biXPelsPerMeter
, "%u != %u\n", ds
.dsBmih
.biXPelsPerMeter
, bmih
->biXPelsPerMeter
);
373 ok(ds
.dsBmih
.biYPelsPerMeter
== bmih
->biYPelsPerMeter
, "%u != %u\n", ds
.dsBmih
.biYPelsPerMeter
, bmih
->biYPelsPerMeter
);
375 memset(&ds
, 0xAA, sizeof(ds
));
376 ret
= GetObject(hbm
, sizeof(ds
) - 4, &ds
);
377 ok(ret
== sizeof(ds
.dsBm
) || broken(ret
== (sizeof(ds
) - 4) /* Win9x */), "wrong size %d\n", ret
);
378 ok(ds
.dsBm
.bmWidth
== bmih
->biWidth
, "%u != %u\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
379 ok(ds
.dsBm
.bmHeight
== bmih
->biHeight
, "%u != %u\n", ds
.dsBmih
.biHeight
, bmih
->biHeight
);
380 ok(ds
.dsBm
.bmBits
== bits
, "%p != %p\n", ds
.dsBm
.bmBits
, bits
);
382 ret
= GetObject(hbm
, 0, &ds
);
383 ok(ret
== 0, "%d != 0\n", ret
);
385 ret
= GetObject(hbm
, 1, &ds
);
386 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
389 #define test_color_todo(got, exp, txt, todo) \
390 if (!todo && got != exp && screen_depth < 24) { \
391 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
392 screen_depth, (UINT)got, (UINT)exp); \
394 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
395 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
397 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
400 c = SetPixel(hdc, 0, 0, color); \
401 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
402 c = GetPixel(hdc, 0, 0); \
403 test_color_todo(c, exp, GetPixel, todo_getp); \
406 static void test_dib_bits_access( HBITMAP hdib
, void *bits
)
408 MEMORY_BASIC_INFORMATION info
;
409 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
411 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
413 char filename
[MAX_PATH
];
418 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
419 "VirtualQuery failed\n");
420 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
421 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
422 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
423 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
424 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
425 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
427 memset( pbmi
, 0, sizeof(bmibuf
) );
428 memset( data
, 0xcc, sizeof(data
) );
429 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
430 pbmi
->bmiHeader
.biHeight
= 16;
431 pbmi
->bmiHeader
.biWidth
= 16;
432 pbmi
->bmiHeader
.biBitCount
= 32;
433 pbmi
->bmiHeader
.biPlanes
= 1;
434 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
436 ret
= SetDIBits( hdc
, hdib
, 0, 16, data
, pbmi
, DIB_RGB_COLORS
);
438 broken(ret
== 0), /* win9x */
439 "SetDIBits failed: expected 16 got %d\n", ret
);
441 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
442 "VirtualQuery failed\n");
443 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
444 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
445 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
446 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
447 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
448 /* it has been protected now */
449 todo_wine
ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
451 /* try writing protected bits to a file */
453 GetTempFileNameA( ".", "dib", 0, filename
);
454 file
= CreateFileA( filename
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
455 CREATE_ALWAYS
, 0, 0 );
456 ok( file
!= INVALID_HANDLE_VALUE
, "failed to open %s error %u\n", filename
, GetLastError() );
457 ret
= WriteFile( file
, bits
, 8192, &written
, NULL
);
458 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
459 if (ret
) ok( written
== 8192, "only wrote %u bytes\n", written
);
461 DeleteFileA( filename
);
464 static void test_dibsections(void)
466 HDC hdc
, hdcmem
, hdcmem2
;
467 HBITMAP hdib
, oldbm
, hdib2
, oldbm2
;
468 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
469 char bcibuf
[sizeof(BITMAPCOREINFO
) + 256 * sizeof(RGBTRIPLE
)];
470 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
471 BITMAPCOREINFO
*pbci
= (BITMAPCOREINFO
*)bcibuf
;
477 char logpalbuf
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
478 LOGPALETTE
*plogpal
= (LOGPALETTE
*)logpalbuf
;
481 HPALETTE hpal
, oldpal
;
486 MEMORY_BASIC_INFORMATION info
;
489 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
491 memset(pbmi
, 0, sizeof(bmibuf
));
492 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
493 pbmi
->bmiHeader
.biHeight
= 100;
494 pbmi
->bmiHeader
.biWidth
= 512;
495 pbmi
->bmiHeader
.biBitCount
= 24;
496 pbmi
->bmiHeader
.biPlanes
= 1;
497 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
499 SetLastError(0xdeadbeef);
501 /* invalid pointer for BITMAPINFO
502 (*bits should be NULL on error) */
503 bits
= (BYTE
*)0xdeadbeef;
504 hdib
= CreateDIBSection(hdc
, NULL
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
505 ok(hdib
== NULL
&& bits
== NULL
, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
507 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
508 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
509 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
510 ok(dibsec
.dsBm
.bmBits
== bits
, "dibsec.dsBits %p != bits %p\n", dibsec
.dsBm
.bmBits
, bits
);
512 /* test the DIB memory */
513 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
514 "VirtualQuery failed\n");
515 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
516 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
517 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
518 ok(info
.RegionSize
== 0x26000, "0x%lx != 0x26000\n", info
.RegionSize
);
519 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
520 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
521 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
523 test_dib_bits_access( hdib
, bits
);
525 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
528 pbmi
->bmiHeader
.biBitCount
= 8;
529 pbmi
->bmiHeader
.biCompression
= BI_RLE8
;
530 SetLastError(0xdeadbeef);
531 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
532 ok(hdib
== NULL
, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
533 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
535 pbmi
->bmiHeader
.biBitCount
= 16;
536 pbmi
->bmiHeader
.biCompression
= BI_BITFIELDS
;
537 ((PDWORD
)pbmi
->bmiColors
)[0] = 0xf800;
538 ((PDWORD
)pbmi
->bmiColors
)[1] = 0x07e0;
539 ((PDWORD
)pbmi
->bmiColors
)[2] = 0x001f;
540 SetLastError(0xdeadbeef);
541 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
542 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
544 /* test the DIB memory */
545 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
546 "VirtualQuery failed\n");
547 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
548 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
549 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
550 ok(info
.RegionSize
== 0x19000, "0x%lx != 0x19000\n", info
.RegionSize
);
551 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
552 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
553 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
555 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
558 memset(pbmi
, 0, sizeof(bmibuf
));
559 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
560 pbmi
->bmiHeader
.biHeight
= 16;
561 pbmi
->bmiHeader
.biWidth
= 16;
562 pbmi
->bmiHeader
.biBitCount
= 1;
563 pbmi
->bmiHeader
.biPlanes
= 1;
564 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
565 pbmi
->bmiColors
[0].rgbRed
= 0xff;
566 pbmi
->bmiColors
[0].rgbGreen
= 0;
567 pbmi
->bmiColors
[0].rgbBlue
= 0;
568 pbmi
->bmiColors
[1].rgbRed
= 0;
569 pbmi
->bmiColors
[1].rgbGreen
= 0;
570 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
572 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
573 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
574 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
575 ok(dibsec
.dsBmih
.biClrUsed
== 2,
576 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
578 /* Test if the old BITMAPCOREINFO structure is supported */
580 pbci
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
581 pbci
->bmciHeader
.bcBitCount
= 0;
584 ret
= GetDIBits(hdc
, hdib
, 0, 16, NULL
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
585 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
586 ok((pbci
->bmciHeader
.bcWidth
== 16) && (pbci
->bmciHeader
.bcHeight
== 16)
587 && (pbci
->bmciHeader
.bcBitCount
== 1) && (pbci
->bmciHeader
.bcPlanes
== 1),
588 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
590 ret
= GetDIBits(hdc
, hdib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
591 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
592 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
593 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
594 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
595 "The color table has not been translated to the old BITMAPCOREINFO format\n");
597 hcoredib
= CreateDIBSection(hdc
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
598 ok(hcoredib
!= NULL
, "CreateDIBSection failed with a BITMAPCOREINFO\n");
600 ZeroMemory(pbci
->bmciColors
, 256 * sizeof(RGBTRIPLE
));
601 ret
= GetDIBits(hdc
, hcoredib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
602 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
603 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
604 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
605 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
606 "The color table has not been translated to the old BITMAPCOREINFO format\n");
608 DeleteObject(hcoredib
);
611 hdcmem
= CreateCompatibleDC(hdc
);
612 oldbm
= SelectObject(hdcmem
, hdib
);
614 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
615 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
616 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
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(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
, pbmi
->bmiColors
[0].rgbBlue
);
622 c1
= RGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
, pbmi
->bmiColors
[1].rgbBlue
);
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
, 1, 1);
628 test_color(hdcmem
, PALETTEINDEX(1), c0
, 1, 1);
629 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
630 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
,
631 pbmi
->bmiColors
[0].rgbBlue
), c0
, 1, 1);
632 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
,
633 pbmi
->bmiColors
[1].rgbBlue
), c1
, 1, 1);
634 test_color(hdcmem
, PALETTERGB(0, 0, 0), c0
, 1, 1);
635 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
636 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c1
, 1, 1);
638 SelectObject(hdcmem
, oldbm
);
641 pbmi
->bmiColors
[0].rgbRed
= 0xff;
642 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
643 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
644 pbmi
->bmiColors
[1].rgbRed
= 0;
645 pbmi
->bmiColors
[1].rgbGreen
= 0;
646 pbmi
->bmiColors
[1].rgbBlue
= 0;
648 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
649 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
651 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
653 oldbm
= SelectObject(hdcmem
, hdib
);
655 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
656 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
657 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
658 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
659 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
660 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
662 SelectObject(hdcmem
, oldbm
);
663 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
666 pbmi
->bmiHeader
.biBitCount
= 4;
667 for (i
= 0; i
< 16; i
++) {
668 pbmi
->bmiColors
[i
].rgbRed
= i
;
669 pbmi
->bmiColors
[i
].rgbGreen
= 16-i
;
670 pbmi
->bmiColors
[i
].rgbBlue
= 0;
672 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
673 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
674 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
675 ok(dibsec
.dsBmih
.biClrUsed
== 16,
676 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 16);
677 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
680 pbmi
->bmiHeader
.biBitCount
= 8;
682 for (i
= 0; i
< 128; i
++) {
683 pbmi
->bmiColors
[i
].rgbRed
= 255 - i
* 2;
684 pbmi
->bmiColors
[i
].rgbGreen
= i
* 2;
685 pbmi
->bmiColors
[i
].rgbBlue
= 0;
686 pbmi
->bmiColors
[255 - i
].rgbRed
= 0;
687 pbmi
->bmiColors
[255 - i
].rgbGreen
= i
* 2;
688 pbmi
->bmiColors
[255 - i
].rgbBlue
= 255 - i
* 2;
690 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
691 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
692 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
693 ok(dibsec
.dsBmih
.biClrUsed
== 256,
694 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
696 oldbm
= SelectObject(hdcmem
, hdib
);
698 for (i
= 0; i
< 256; i
++) {
699 test_color(hdcmem
, DIBINDEX(i
),
700 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
701 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
),
702 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
705 SelectObject(hdcmem
, oldbm
);
706 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
709 pbmi
->bmiHeader
.biBitCount
= 1;
711 /* Now create a palette and a palette indexed dib section */
712 memset(plogpal
, 0, sizeof(logpalbuf
));
713 plogpal
->palVersion
= 0x300;
714 plogpal
->palNumEntries
= 2;
715 plogpal
->palPalEntry
[0].peRed
= 0xff;
716 plogpal
->palPalEntry
[0].peBlue
= 0xff;
717 plogpal
->palPalEntry
[1].peGreen
= 0xff;
719 index
= (WORD
*)pbmi
->bmiColors
;
722 hpal
= CreatePalette(plogpal
);
723 ok(hpal
!= NULL
, "CreatePalette failed\n");
724 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
725 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
726 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
727 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
728 ok(dibsec
.dsBmih
.biClrUsed
== 2 ||
729 broken(dibsec
.dsBmih
.biClrUsed
== 0), /* win9x */
730 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
732 /* The colour table has already been grabbed from the dc, so we select back the
735 SelectPalette(hdc
, oldpal
, TRUE
);
736 oldbm
= SelectObject(hdcmem
, hdib
);
737 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
739 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
740 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
741 ok(rgb
[0].rgbRed
== 0xff && rgb
[0].rgbBlue
== 0xff && rgb
[0].rgbGreen
== 0 &&
742 rgb
[1].rgbRed
== 0 && rgb
[1].rgbBlue
== 0 && rgb
[1].rgbGreen
== 0xff,
743 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
744 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
745 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
747 c0
= RGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
, plogpal
->palPalEntry
[0].peBlue
);
748 c1
= RGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
, plogpal
->palPalEntry
[1].peBlue
);
750 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
751 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
752 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
753 test_color(hdcmem
, PALETTEINDEX(0), c0
, 0, 1);
754 test_color(hdcmem
, PALETTEINDEX(1), c1
, 0, 1);
755 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
756 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
,
757 plogpal
->palPalEntry
[0].peBlue
), c0
, 1, 1);
758 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
,
759 plogpal
->palPalEntry
[1].peBlue
), c1
, 1, 1);
760 test_color(hdcmem
, PALETTERGB(0, 0, 0), c1
, 1, 1);
761 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
762 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c0
, 1, 1);
763 test_color(hdcmem
, PALETTERGB(0, 1, 0), c1
, 1, 1);
764 test_color(hdcmem
, PALETTERGB(0x3f, 0, 0x3f), c1
, 1, 1);
765 test_color(hdcmem
, PALETTERGB(0x40, 0, 0x40), c0
, 1, 1);
767 /* Bottom and 2nd row from top green, everything else magenta */
768 bits
[0] = bits
[1] = 0xff;
769 bits
[13 * 4] = bits
[13*4 + 1] = 0xff;
771 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
773 pbmi
->bmiHeader
.biBitCount
= 32;
775 hdib2
= CreateDIBSection(NULL
, pbmi
, DIB_RGB_COLORS
, (void **)&bits32
, NULL
, 0);
776 ok(hdib2
!= NULL
, "CreateDIBSection failed\n");
777 hdcmem2
= CreateCompatibleDC(hdc
);
778 oldbm2
= SelectObject(hdcmem2
, hdib2
);
780 BitBlt(hdcmem2
, 0, 0, 16,16, hdcmem
, 0, 0, SRCCOPY
);
782 ok(bits32
[0] == 0xff00, "lower left pixel is %08x\n", bits32
[0]);
783 ok(bits32
[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32
[17]);
785 SelectObject(hdcmem2
, oldbm2
);
786 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
789 SelectObject(hdcmem
, oldbm
);
790 SelectObject(hdcmem
, oldpal
);
795 pbmi
->bmiHeader
.biBitCount
= 8;
797 memset(plogpal
, 0, sizeof(logpalbuf
));
798 plogpal
->palVersion
= 0x300;
799 plogpal
->palNumEntries
= 256;
801 for (i
= 0; i
< 128; i
++) {
802 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
803 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
804 plogpal
->palPalEntry
[i
].peGreen
= 0;
805 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
806 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
807 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
810 index
= (WORD
*)pbmi
->bmiColors
;
811 for (i
= 0; i
< 256; i
++) {
815 hpal
= CreatePalette(plogpal
);
816 ok(hpal
!= NULL
, "CreatePalette failed\n");
817 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
818 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
819 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
820 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
821 ok(dibsec
.dsBmih
.biClrUsed
== 256 ||
822 broken(dibsec
.dsBmih
.biClrUsed
== 0), /* win9x */
823 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
825 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
827 SelectPalette(hdc
, oldpal
, TRUE
);
828 oldbm
= SelectObject(hdcmem
, hdib
);
829 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
831 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
832 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
833 for (i
= 0; i
< 256; i
++) {
834 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
835 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
836 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
837 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
838 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
841 for (i
= 0; i
< 256; i
++) {
842 test_color(hdcmem
, DIBINDEX(i
),
843 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
844 test_color(hdcmem
, PALETTEINDEX(i
),
845 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
846 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
847 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
850 SelectPalette(hdcmem
, oldpal
, TRUE
);
851 SelectObject(hdcmem
, oldbm
);
860 static void test_mono_dibsection(void)
863 HBITMAP old_bm
, mono_ds
;
864 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
865 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
872 memdc
= CreateCompatibleDC(hdc
);
874 memset(pbmi
, 0, sizeof(bmibuf
));
875 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
876 pbmi
->bmiHeader
.biHeight
= 10;
877 pbmi
->bmiHeader
.biWidth
= 10;
878 pbmi
->bmiHeader
.biBitCount
= 1;
879 pbmi
->bmiHeader
.biPlanes
= 1;
880 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
881 pbmi
->bmiColors
[0].rgbRed
= 0xff;
882 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
883 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
884 pbmi
->bmiColors
[1].rgbRed
= 0x0;
885 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
886 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
889 * First dib section is 'inverted' ie color[0] is white, color[1] is black
892 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
893 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
894 old_bm
= SelectObject(memdc
, mono_ds
);
896 /* black border, white interior */
897 Rectangle(memdc
, 0, 0, 10, 10);
898 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
899 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
901 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
903 memset(bits
, 0, sizeof(bits
));
906 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
907 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
909 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
911 pbmi
->bmiColors
[0].rgbRed
= 0x0;
912 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
913 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
914 pbmi
->bmiColors
[1].rgbRed
= 0xff;
915 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
916 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
918 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
919 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
921 SelectObject(memdc
, old_bm
);
922 DeleteObject(mono_ds
);
925 * Next dib section is 'normal' ie color[0] is black, color[1] is white
928 pbmi
->bmiColors
[0].rgbRed
= 0x0;
929 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
930 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
931 pbmi
->bmiColors
[1].rgbRed
= 0xff;
932 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
933 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
935 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
936 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
937 old_bm
= SelectObject(memdc
, mono_ds
);
939 /* black border, white interior */
940 Rectangle(memdc
, 0, 0, 10, 10);
941 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
942 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
944 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
946 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
947 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
949 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
951 pbmi
->bmiColors
[0].rgbRed
= 0xff;
952 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
953 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
954 pbmi
->bmiColors
[1].rgbRed
= 0x0;
955 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
956 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
958 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
959 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
962 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
965 pbmi
->bmiColors
[0].rgbRed
= 0xff;
966 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
967 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
968 pbmi
->bmiColors
[1].rgbRed
= 0x0;
969 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
970 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
971 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
972 ok(num
== 2, "num = %d\n", num
);
974 /* black border, white interior */
975 Rectangle(memdc
, 0, 0, 10, 10);
977 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
978 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
980 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
982 memset(bits
, 0, sizeof(bits
));
985 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
986 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
988 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
990 pbmi
->bmiColors
[0].rgbRed
= 0x0;
991 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
992 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
993 pbmi
->bmiColors
[1].rgbRed
= 0xff;
994 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
995 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
997 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
998 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1000 SelectObject(memdc
, old_bm
);
1001 DeleteObject(mono_ds
);
1004 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1007 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1008 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1009 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1010 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
1011 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1012 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1014 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
1015 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
1016 old_bm
= SelectObject(memdc
, mono_ds
);
1018 /* black border, white interior */
1019 Rectangle(memdc
, 0, 0, 10, 10);
1020 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
1021 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
1023 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1025 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1026 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1027 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1028 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1029 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1030 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1032 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1033 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1035 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1037 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1038 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
1039 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
1040 pbmi
->bmiColors
[1].rgbRed
= 0x0;
1041 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1042 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1044 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1045 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1047 SelectObject(memdc
, old_bm
);
1048 DeleteObject(mono_ds
);
1054 static void test_bitmap(void)
1056 char buf
[256], buf_cmp
[256];
1057 HBITMAP hbmp
, hbmp_old
;
1063 hdc
= CreateCompatibleDC(0);
1066 SetLastError(0xdeadbeef);
1067 hbmp
= CreateBitmap(0x7ffffff, 1, 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, 9, 1, 1, NULL
);
1081 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1082 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1083 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1088 SetLastError(0xdeadbeef);
1089 hbmp
= CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL
);
1090 ok(!hbmp
|| broken(hbmp
!= NULL
/* Win9x */), "CreateBitmap should fail\n");
1092 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1093 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1097 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
1098 assert(hbmp
!= NULL
);
1100 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1101 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1103 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1104 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1105 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1106 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1107 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1108 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1109 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1111 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
1112 assert(sizeof(buf
) == sizeof(buf_cmp
));
1114 ret
= GetBitmapBits(hbmp
, 0, NULL
);
1115 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
|| broken(ret
== 0 /* Win9x */),
1116 "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1118 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
1119 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
1121 memset(buf
, 0xAA, sizeof(buf
));
1122 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1123 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1124 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1125 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1126 "buffers do not match\n");
1128 hbmp_old
= SelectObject(hdc
, hbmp
);
1130 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1131 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1133 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1134 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1135 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1136 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1137 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1138 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1139 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1141 memset(buf
, 0xAA, sizeof(buf
));
1142 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1143 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1144 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1145 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1146 "buffers do not match\n");
1148 hbmp_old
= SelectObject(hdc
, hbmp_old
);
1149 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
1151 /* test various buffer sizes for GetObject */
1152 ret
= GetObject(hbmp
, sizeof(*bma
) * 2, bma
);
1153 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
1155 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
1156 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
1158 ret
= GetObject(hbmp
, 0, &bm
);
1159 ok(ret
== 0, "%d != 0\n", ret
);
1161 ret
= GetObject(hbmp
, 1, &bm
);
1162 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
1168 static void test_bmBits(void)
1174 memset(bits
, 0, sizeof(bits
));
1175 hbmp
= CreateBitmap(2, 2, 1, 4, bits
);
1176 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
1178 memset(&bmp
, 0xFF, sizeof(bmp
));
1179 ok(GetObject(hbmp
, sizeof(bmp
), &bmp
) == sizeof(bmp
),
1180 "GetObject failed or returned a wrong structure size\n");
1181 ok(!bmp
.bmBits
, "bmBits must be NULL for device-dependent bitmaps\n");
1186 static void test_GetDIBits_selected_DIB(UINT bpp
)
1200 /* Create a DIB section with a color table */
1202 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1203 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1207 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1209 /* Choose width and height such that the row length (in bytes)
1210 is a multiple of 4 (makes things easier) */
1211 info
->bmiHeader
.biWidth
= 32;
1212 info
->bmiHeader
.biHeight
= 32;
1213 info
->bmiHeader
.biPlanes
= 1;
1214 info
->bmiHeader
.biBitCount
= bpp
;
1215 info
->bmiHeader
.biCompression
= BI_RGB
;
1217 for (i
=0; i
< (1u << bpp
); i
++)
1219 BYTE c
= i
* (1 << (8 - bpp
));
1220 info
->bmiColors
[i
].rgbRed
= c
;
1221 info
->bmiColors
[i
].rgbGreen
= c
;
1222 info
->bmiColors
[i
].rgbBlue
= c
;
1223 info
->bmiColors
[i
].rgbReserved
= 0;
1226 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1228 dib_size
= bpp
* (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1230 /* Set the bits of the DIB section */
1231 for (i
=0; i
< dib_size
; i
++)
1233 ((BYTE
*)bits
)[i
] = i
% 256;
1236 /* Select the DIB into a DC */
1237 dib_dc
= CreateCompatibleDC(NULL
);
1238 old_bmp
= SelectObject(dib_dc
, dib
);
1239 dc
= CreateCompatibleDC(NULL
);
1240 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dib_size
);
1243 /* Copy the DIB attributes but not the color table */
1244 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1246 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1247 ok(res
, "GetDIBits failed\n");
1249 /* Compare the color table and the bits */
1250 equalContents
= TRUE
;
1251 for (i
=0; i
< (1u << bpp
); i
++)
1253 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1254 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1255 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1256 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1258 equalContents
= FALSE
;
1262 ok(equalContents
, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1264 equalContents
= TRUE
;
1265 for (i
=0; i
< dib_size
/ sizeof(DWORD
); i
++)
1267 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1269 equalContents
= FALSE
;
1273 ok(equalContents
, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp
);
1275 HeapFree(GetProcessHeap(), 0, bits2
);
1278 SelectObject(dib_dc
, old_bmp
);
1282 HeapFree(GetProcessHeap(), 0, info2
);
1283 HeapFree(GetProcessHeap(), 0, info
);
1286 static void test_GetDIBits_selected_DDB(BOOL monochrome
)
1301 width
= height
= 16;
1303 /* Create a DDB (device-dependent bitmap) */
1307 ddb
= CreateBitmap(width
, height
, 1, 1, NULL
);
1311 HDC screen_dc
= GetDC(NULL
);
1312 bpp
= GetDeviceCaps(screen_dc
, BITSPIXEL
) * GetDeviceCaps(screen_dc
, PLANES
);
1313 ddb
= CreateCompatibleBitmap(screen_dc
, width
, height
);
1314 ReleaseDC(NULL
, screen_dc
);
1317 /* Set the pixels */
1318 ddb_dc
= CreateCompatibleDC(NULL
);
1319 old_bmp
= SelectObject(ddb_dc
, ddb
);
1320 for (i
= 0; i
< width
; i
++)
1322 for (j
=0; j
< height
; j
++)
1324 BYTE c
= (i
* width
+ j
) % 256;
1325 SetPixelV(ddb_dc
, i
, j
, RGB(c
, c
, c
));
1328 SelectObject(ddb_dc
, old_bmp
);
1330 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1331 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1335 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1336 info
->bmiHeader
.biWidth
= width
;
1337 info
->bmiHeader
.biHeight
= height
;
1338 info
->bmiHeader
.biPlanes
= 1;
1339 info
->bmiHeader
.biBitCount
= bpp
;
1340 info
->bmiHeader
.biCompression
= BI_RGB
;
1342 dc
= CreateCompatibleDC(NULL
);
1344 /* Fill in biSizeImage */
1345 GetDIBits(dc
, ddb
, 0, height
, NULL
, info
, DIB_RGB_COLORS
);
1346 ok(info
->bmiHeader
.biSizeImage
!= 0, "GetDIBits failed to get the DIB attributes\n");
1348 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1349 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1354 res
= GetDIBits(dc
, ddb
, 0, height
, bits
, info
, DIB_RGB_COLORS
);
1355 ok(res
, "GetDIBits failed\n");
1357 /* Copy the DIB attributes but not the color table */
1358 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1360 /* Select the DDB into another DC */
1361 old_bmp
= SelectObject(ddb_dc
, ddb
);
1364 res
= GetDIBits(dc
, ddb
, 0, height
, bits2
, info2
, DIB_RGB_COLORS
);
1365 ok(res
, "GetDIBits failed\n");
1367 /* Compare the color table and the bits */
1370 equalContents
= TRUE
;
1371 for (i
=0; i
< (1u << bpp
); i
++)
1373 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1374 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1375 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1376 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1378 equalContents
= FALSE
;
1382 ok(equalContents
, "GetDIBits with DDB selected in DC: Got a different color table\n");
1385 equalContents
= TRUE
;
1386 for (i
=0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++)
1388 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1390 equalContents
= FALSE
;
1393 ok(equalContents
, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1395 /* Test the palette */
1396 equalContents
= TRUE
;
1397 if (info2
->bmiHeader
.biBitCount
<= 8)
1399 WORD
*colors
= (WORD
*)info2
->bmiColors
;
1401 /* Get the palette indices */
1402 res
= GetDIBits(dc
, ddb
, 0, 0, NULL
, info2
, DIB_PAL_COLORS
);
1403 if (res
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
) /* Win9x */
1404 res
= GetDIBits(dc
, ddb
, 0, height
, NULL
, info2
, DIB_PAL_COLORS
);
1405 ok(res
, "GetDIBits failed\n");
1407 for (i
=0;i
< 1 << info
->bmiHeader
.biSizeImage
; i
++)
1411 equalContents
= FALSE
;
1417 ok(equalContents
, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1419 HeapFree(GetProcessHeap(), 0, bits2
);
1420 HeapFree(GetProcessHeap(), 0, bits
);
1423 SelectObject(ddb_dc
, old_bmp
);
1427 HeapFree(GetProcessHeap(), 0, info2
);
1428 HeapFree(GetProcessHeap(), 0, info
);
1431 static void test_GetDIBits(void)
1433 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1434 static const BYTE bmp_bits_1
[16 * 2] =
1436 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1437 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1438 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1439 0xff,0xff, 0,0, 0xff,0xff, 0,0
1441 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1442 static const BYTE dib_bits_1
[16 * 4] =
1444 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1445 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1446 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1447 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1449 static const BYTE dib_bits_1_9x
[16 * 4] =
1451 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1452 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1453 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1454 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1456 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1457 static const BYTE bmp_bits_24
[16 * 16*3] =
1459 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1460 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1461 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1462 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1463 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1464 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1465 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1466 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1467 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1468 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1469 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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1471 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1472 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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
1492 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1493 static const BYTE dib_bits_24
[16 * 16*3] =
1495 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1496 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1497 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1498 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1499 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1500 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1501 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1502 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1503 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1504 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1505 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1506 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1507 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1508 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1509 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1510 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1511 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1512 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1513 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1514 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1515 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1516 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1517 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1518 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1519 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1520 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1521 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1522 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1523 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1524 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1525 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1526 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1531 int i
, bytes
, lines
;
1533 char bi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1534 BITMAPINFO
*bi
= (BITMAPINFO
*)bi_buf
;
1538 /* 1-bit source bitmap data */
1539 hbmp
= CreateBitmap(16, 16, 1, 1, bmp_bits_1
);
1540 ok(hbmp
!= 0, "CreateBitmap failed\n");
1542 memset(&bm
, 0xAA, sizeof(bm
));
1543 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1544 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1545 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1546 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1547 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1548 ok(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1549 ok(bm
.bmPlanes
== 1, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1550 ok(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1551 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1553 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1554 ok(bytes
== sizeof(bmp_bits_1
) || broken(bytes
== 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes
);
1555 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1556 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1557 ok(!memcmp(buf
, bmp_bits_1
, sizeof(bmp_bits_1
)), "bitmap bits don't match\n");
1559 /* retrieve 1-bit DIB data */
1560 memset(bi
, 0, sizeof(*bi
));
1561 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1562 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1563 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1564 bi
->bmiHeader
.biPlanes
= 1;
1565 bi
->bmiHeader
.biBitCount
= 1;
1566 bi
->bmiHeader
.biCompression
= BI_RGB
;
1567 bi
->bmiHeader
.biSizeImage
= 0;
1568 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1569 SetLastError(0xdeadbeef);
1570 lines
= GetDIBits(0, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1571 ok(lines
== 0, "GetDIBits copied %d lines with hdc = 0\n", lines
);
1572 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
1573 broken(GetLastError() == 0xdeadbeef), /* winnt */
1574 "wrong error %u\n", GetLastError());
1575 ok(bi
->bmiHeader
.biSizeImage
== 0, "expected 0, got %u\n", bi
->bmiHeader
.biSizeImage
);
1577 memset(buf
, 0xAA, sizeof(buf
));
1578 SetLastError(0xdeadbeef);
1579 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1580 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1581 lines
, bm
.bmHeight
, GetLastError());
1582 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1583 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1584 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1586 /* the color table consists of black and white */
1587 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1588 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1589 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1590 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1591 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1592 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1593 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1594 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1595 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1596 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1597 for (i
= 2; i
< 256; i
++)
1599 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1600 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1601 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1602 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1603 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1606 /* returned bits are DWORD aligned and upside down */
1607 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1608 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1609 "DIB bits don't match\n");
1611 /* Test the palette indices */
1612 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1613 SetLastError(0xdeadbeef);
1614 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1615 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1616 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1619 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1620 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1622 for (i
= 2; i
< 256; i
++)
1623 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[1]);
1625 /* retrieve 24-bit DIB data */
1626 memset(bi
, 0, sizeof(*bi
));
1627 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1628 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1629 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1630 bi
->bmiHeader
.biPlanes
= 1;
1631 bi
->bmiHeader
.biBitCount
= 24;
1632 bi
->bmiHeader
.biCompression
= BI_RGB
;
1633 bi
->bmiHeader
.biSizeImage
= 0;
1634 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1635 memset(buf
, 0xAA, sizeof(buf
));
1636 SetLastError(0xdeadbeef);
1637 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1638 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1639 lines
, bm
.bmHeight
, GetLastError());
1640 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1641 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1642 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1644 /* the color table doesn't exist for 24-bit images */
1645 for (i
= 0; i
< 256; i
++)
1647 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1648 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1649 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1650 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1651 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1654 /* returned bits are DWORD aligned and upside down */
1655 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1658 /* 24-bit source bitmap data */
1659 hbmp
= CreateCompatibleBitmap(hdc
, 16, 16);
1660 ok(hbmp
!= 0, "CreateBitmap failed\n");
1661 SetLastError(0xdeadbeef);
1662 bi
->bmiHeader
.biHeight
= -bm
.bmHeight
; /* indicate bottom-up data */
1663 lines
= SetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, bmp_bits_24
, bi
, DIB_RGB_COLORS
);
1664 ok(lines
== bm
.bmHeight
, "SetDIBits copied %d lines of %d, error %u\n",
1665 lines
, bm
.bmHeight
, GetLastError());
1667 memset(&bm
, 0xAA, sizeof(bm
));
1668 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1669 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1670 ok(bm
.bmType
== 0 ||
1671 broken(bm
.bmType
== 21072), /* win9x */
1672 "wrong bmType %d\n", bm
.bmType
);
1673 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1674 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1675 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1676 ok(bm
.bmPlanes
== GetDeviceCaps(hdc
, PLANES
), "wrong bmPlanes %u\n", bm
.bmPlanes
);
1677 ok(bm
.bmBitsPixel
== GetDeviceCaps(hdc
, BITSPIXEL
), "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1678 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1680 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1681 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
||
1682 broken(bytes
== 0), /* win9x */
1683 "expected %d got %d bytes\n", bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1684 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1685 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1686 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1688 /* retrieve 1-bit DIB data */
1689 memset(bi
, 0, sizeof(*bi
));
1690 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1691 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1692 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1693 bi
->bmiHeader
.biPlanes
= 1;
1694 bi
->bmiHeader
.biBitCount
= 1;
1695 bi
->bmiHeader
.biCompression
= BI_RGB
;
1696 bi
->bmiHeader
.biSizeImage
= 0;
1697 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1698 memset(buf
, 0xAA, sizeof(buf
));
1699 SetLastError(0xdeadbeef);
1700 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1701 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1702 lines
, bm
.bmHeight
, GetLastError());
1703 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1704 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1705 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1707 /* the color table consists of black and white */
1708 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1709 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1710 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1711 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1712 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1713 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1714 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1715 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1716 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1717 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1718 for (i
= 2; i
< 256; i
++)
1720 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1721 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1722 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1723 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1724 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1727 /* returned bits are DWORD aligned and upside down */
1729 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1730 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1731 "DIB bits don't match\n");
1733 /* Test the palette indices */
1734 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1735 SetLastError(0xdeadbeef);
1736 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1737 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1738 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1741 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1742 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1744 for (i
= 2; i
< 256; i
++)
1745 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[i
]);
1747 /* retrieve 24-bit DIB data */
1748 memset(bi
, 0, sizeof(*bi
));
1749 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1750 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1751 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1752 bi
->bmiHeader
.biPlanes
= 1;
1753 bi
->bmiHeader
.biBitCount
= 24;
1754 bi
->bmiHeader
.biCompression
= BI_RGB
;
1755 bi
->bmiHeader
.biSizeImage
= 0;
1756 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1757 memset(buf
, 0xAA, sizeof(buf
));
1758 SetLastError(0xdeadbeef);
1759 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1760 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1761 lines
, bm
.bmHeight
, GetLastError());
1762 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1763 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1764 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1766 /* the color table doesn't exist for 24-bit images */
1767 for (i
= 0; i
< 256; i
++)
1769 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1770 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1771 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1772 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1773 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1776 /* returned bits are DWORD aligned and upside down */
1777 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1783 static void test_GetDIBits_BI_BITFIELDS(void)
1785 /* Try a screen resolution detection technique
1786 * from the September 1999 issue of Windows Developer's Journal
1787 * which seems to be in widespread use.
1788 * http://www.lesher.ws/highcolor.html
1789 * http://www.lesher.ws/vidfmt.c
1790 * It hinges on being able to retrieve the bitmaps
1791 * for the three primary colors in non-paletted 16 bit mode.
1793 char dibinfo_buf
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
1795 LPBITMAPINFO dibinfo
= (LPBITMAPINFO
) dibinfo_buf
;
1800 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1801 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1804 ok(hdc
!= NULL
, "GetDC failed?\n");
1805 hbm
= CreateCompatibleBitmap(hdc
, 1, 1);
1806 ok(hbm
!= NULL
, "CreateCompatibleBitmap failed?\n");
1808 /* Call GetDIBits to fill in bmiHeader. */
1809 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1810 ok(ret
== 1, "GetDIBits failed\n");
1811 if (dibinfo
->bmiHeader
.biBitCount
> 8)
1813 DWORD
*bitmasks
= (DWORD
*)dibinfo
->bmiColors
;
1815 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1816 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1818 ok( !bitmasks
[0], "red mask is set\n" );
1819 ok( !bitmasks
[1], "green mask is set\n" );
1820 ok( !bitmasks
[2], "blue mask is set\n" );
1822 /* test with NULL bits pointer and correct bpp */
1823 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1824 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1825 ok(ret
== 1, "GetDIBits failed\n");
1827 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1828 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1829 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1830 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1832 /* test with valid bits pointer */
1833 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1834 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1835 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1836 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1837 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1838 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1839 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1841 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1842 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1843 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1844 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef ||
1845 broken(dibinfo
->bmiHeader
.biSizeImage
== 0xdeadbeef), /* win9x */
1846 "size image not set\n" );
1848 /* now with bits and 0 lines */
1849 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1850 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1851 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1852 SetLastError(0xdeadbeef);
1853 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1854 if (ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1855 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1858 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1860 ok( !bitmasks
[0], "red mask is set\n" );
1861 ok( !bitmasks
[1], "green mask is set\n" );
1862 ok( !bitmasks
[2], "blue mask is set\n" );
1863 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1865 memset(bitmasks
, 0, 3*sizeof(DWORD
));
1866 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1867 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1868 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1870 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1871 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1872 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1873 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1876 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1879 ReleaseDC(NULL
, hdc
);
1882 static void test_select_object(void)
1885 HBITMAP hbm
, hbm_old
;
1887 DWORD depths
[] = {8, 15, 16, 24, 32};
1892 ok(hdc
!= 0, "GetDC(0) failed\n");
1893 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1894 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1896 hbm_old
= SelectObject(hdc
, hbm
);
1897 ok(hbm_old
== 0, "SelectObject should fail\n");
1902 hdc
= CreateCompatibleDC(0);
1903 ok(hdc
!= 0, "GetDC(0) failed\n");
1904 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1905 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1907 hbm_old
= SelectObject(hdc
, hbm
);
1908 ok(hbm_old
!= 0, "SelectObject failed\n");
1909 hbm_old
= SelectObject(hdc
, hbm_old
);
1910 ok(hbm_old
== hbm
, "SelectObject failed\n");
1914 /* test an 1-bpp bitmap */
1915 planes
= GetDeviceCaps(hdc
, PLANES
);
1918 hbm
= CreateBitmap(10, 10, planes
, bpp
, NULL
);
1919 ok(hbm
!= 0, "CreateBitmap failed\n");
1921 hbm_old
= SelectObject(hdc
, hbm
);
1922 ok(hbm_old
!= 0, "SelectObject failed\n");
1923 hbm_old
= SelectObject(hdc
, hbm_old
);
1924 ok(hbm_old
== hbm
, "SelectObject failed\n");
1928 for(i
= 0; i
< sizeof(depths
)/sizeof(depths
[0]); i
++) {
1929 /* test a color bitmap to dc bpp matching */
1930 planes
= GetDeviceCaps(hdc
, PLANES
);
1931 bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
1933 hbm
= CreateBitmap(10, 10, planes
, depths
[i
], NULL
);
1934 ok(hbm
!= 0, "CreateBitmap failed\n");
1936 hbm_old
= SelectObject(hdc
, hbm
);
1937 if(depths
[i
] == bpp
||
1938 (bpp
== 16 && depths
[i
] == 15) /* 16 and 15 bpp are compatible */
1940 ok(hbm_old
!= 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp
, depths
[i
]);
1941 SelectObject(hdc
, hbm_old
);
1943 ok(hbm_old
== 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp
, depths
[i
]);
1946 memset(&bm
, 0xAA, sizeof(bm
));
1947 bytes
= GetObject(hbm
, sizeof(bm
), &bm
);
1948 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1949 ok(bm
.bmType
== 0 ||
1950 broken(bm
.bmType
== 21072), /* win9x */
1951 "wrong bmType %d\n", bm
.bmType
);
1952 ok(bm
.bmWidth
== 10, "wrong bmWidth %d\n", bm
.bmWidth
);
1953 ok(bm
.bmHeight
== 10, "wrong bmHeight %d\n", bm
.bmHeight
);
1954 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1955 ok(bm
.bmPlanes
== planes
, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1956 if(depths
[i
] == 15) {
1957 ok(bm
.bmBitsPixel
== 16 ||
1958 broken(bm
.bmBitsPixel
== 15), /* Win9x/WinME */
1959 "wrong bmBitsPixel %d(15 bpp special)\n", bm
.bmBitsPixel
);
1961 ok(bm
.bmBitsPixel
== depths
[i
], "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1963 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1971 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp
, int line
)
1976 ret
= GetObjectType(hbmp
);
1977 ok_(__FILE__
, line
)(ret
== OBJ_BITMAP
, "the object %p is not bitmap\n", hbmp
);
1979 ret
= GetObject(hbmp
, 0, 0);
1980 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) /* XP */ ||
1981 ret
== sizeof(DIBSECTION
) /* Win9x */, "object size %d\n", ret
);
1983 memset(&bm
, 0xDA, sizeof(bm
));
1984 SetLastError(0xdeadbeef);
1985 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1986 if (!ret
) /* XP, only for curObj2 */ return;
1987 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) ||
1988 ret
== sizeof(DIBSECTION
) /* Win9x, only for curObj2 */,
1989 "GetObject returned %d, error %u\n", ret
, GetLastError());
1990 ok_(__FILE__
, line
)(bm
.bmType
== 0, "wrong bmType, expected 0 got %d\n", bm
.bmType
);
1991 ok_(__FILE__
, line
)(bm
.bmWidth
== 1, "wrong bmWidth, expected 1 got %d\n", bm
.bmWidth
);
1992 ok_(__FILE__
, line
)(bm
.bmHeight
== 1, "wrong bmHeight, expected 1 got %d\n", bm
.bmHeight
);
1993 ok_(__FILE__
, line
)(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes, expected 2 got %d\n", bm
.bmWidthBytes
);
1994 ok_(__FILE__
, line
)(bm
.bmPlanes
== 1, "wrong bmPlanes, expected 1 got %u\n", bm
.bmPlanes
);
1995 ok_(__FILE__
, line
)(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel, expected 1 got %d\n", bm
.bmBitsPixel
);
1996 ok_(__FILE__
, line
)(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1999 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2001 static void test_CreateBitmap(void)
2004 HDC screenDC
= GetDC(0);
2005 HDC hdc
= CreateCompatibleDC(screenDC
);
2008 /* all of these are the stock monochrome bitmap */
2009 HBITMAP bm
= CreateCompatibleBitmap(hdc
, 0, 0);
2010 HBITMAP bm1
= CreateCompatibleBitmap(screenDC
, 0, 0);
2011 HBITMAP bm4
= CreateBitmap(0, 1, 0, 0, 0);
2012 HBITMAP bm5
= CreateDiscardableBitmap(hdc
, 0, 0);
2013 HBITMAP curObj1
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2014 HBITMAP curObj2
= GetCurrentObject(screenDC
, OBJ_BITMAP
);
2016 /* these 2 are not the stock monochrome bitmap */
2017 HBITMAP bm2
= CreateCompatibleBitmap(hdc
, 1, 1);
2018 HBITMAP bm3
= CreateBitmap(1, 1, 1, 1, 0);
2020 HBITMAP old1
= SelectObject(hdc
, bm2
);
2021 HBITMAP old2
= SelectObject(screenDC
, bm3
);
2022 SelectObject(hdc
, old1
);
2023 SelectObject(screenDC
, old2
);
2025 ok(bm
== bm1
&& bm
== bm4
&& bm
== bm5
&& bm
== curObj1
&& bm
== old1
,
2026 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2027 bm
, bm1
, bm4
, bm5
, curObj1
, old1
);
2028 ok(bm
!= bm2
&& bm
!= bm3
, "0: %p, 2: %p, 3: %p\n", bm
, bm2
, bm3
);
2030 ok(bm
!= curObj2
|| /* WinXP */
2031 broken(bm
== curObj2
) /* Win9x */,
2032 "0: %p, curObj2 %p\n", bm
, curObj2
);
2033 ok(old2
== 0, "old2 %p\n", old2
);
2035 test_mono_1x1_bmp(bm
);
2036 test_mono_1x1_bmp(bm1
);
2037 test_mono_1x1_bmp(bm2
);
2038 test_mono_1x1_bmp(bm3
);
2039 test_mono_1x1_bmp(bm4
);
2040 test_mono_1x1_bmp(bm5
);
2041 test_mono_1x1_bmp(old1
);
2042 test_mono_1x1_bmp(curObj1
);
2052 ReleaseDC(0, screenDC
);
2054 /* show that Windows ignores the provided bm.bmWidthBytes */
2058 bmp
.bmWidthBytes
= 28;
2060 bmp
.bmBitsPixel
= 1;
2062 bm
= CreateBitmapIndirect(&bmp
);
2063 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2064 test_mono_1x1_bmp(bm
);
2067 /* Test how the bmBitsPixel field is treated */
2068 for(i
= 1; i
<= 33; i
++) {
2072 bmp
.bmWidthBytes
= 28;
2074 bmp
.bmBitsPixel
= i
;
2076 SetLastError(0xdeadbeef);
2077 bm
= CreateBitmapIndirect(&bmp
);
2079 DWORD error
= GetLastError();
2081 broken(bm
!= 0), /* Win9x and WinMe */
2082 "CreateBitmapIndirect for %d bpp succeeded\n", i
);
2083 ok(error
== ERROR_INVALID_PARAMETER
||
2084 broken(error
== 0xdeadbeef), /* Win9x and WinME */
2085 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error
);
2089 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2090 GetObject(bm
, sizeof(bmp
), &bmp
);
2097 } else if(i
<= 16) {
2099 } else if(i
<= 24) {
2101 } else if(i
<= 32) {
2104 ok(bmp
.bmBitsPixel
== expect
||
2105 broken(bmp
.bmBitsPixel
== i
), /* Win9x and WinMe */
2106 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2107 i
, bmp
.bmBitsPixel
, expect
);
2112 static void test_bitmapinfoheadersize(void)
2119 memset(&bmi
, 0, sizeof(BITMAPINFO
));
2120 bmi
.bmiHeader
.biHeight
= 100;
2121 bmi
.bmiHeader
.biWidth
= 512;
2122 bmi
.bmiHeader
.biBitCount
= 24;
2123 bmi
.bmiHeader
.biPlanes
= 1;
2125 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) - 1;
2127 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2128 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2130 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2132 SetLastError(0xdeadbeef);
2133 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2134 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2137 bmi
.bmiHeader
.biSize
++;
2139 SetLastError(0xdeadbeef);
2140 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2142 broken(!hdib
), /* Win98, WinMe */
2143 "CreateDIBSection error %d\n", GetLastError());
2146 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFO
);
2148 SetLastError(0xdeadbeef);
2149 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2151 broken(!hdib
), /* Win98, WinMe */
2152 "CreateDIBSection error %d\n", GetLastError());
2155 bmi
.bmiHeader
.biSize
++;
2157 SetLastError(0xdeadbeef);
2158 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2160 broken(!hdib
), /* Win98, WinMe */
2161 "CreateDIBSection error %d\n", GetLastError());
2164 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
2166 SetLastError(0xdeadbeef);
2167 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2168 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2171 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
2173 SetLastError(0xdeadbeef);
2174 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2176 broken(!hdib
), /* Win95 */
2177 "CreateDIBSection error %d\n", GetLastError());
2180 memset(&bci
, 0, sizeof(BITMAPCOREINFO
));
2181 bci
.bmciHeader
.bcHeight
= 100;
2182 bci
.bmciHeader
.bcWidth
= 512;
2183 bci
.bmciHeader
.bcBitCount
= 24;
2184 bci
.bmciHeader
.bcPlanes
= 1;
2186 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
) - 1;
2188 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2189 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2191 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2193 SetLastError(0xdeadbeef);
2194 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2195 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2198 bci
.bmciHeader
.bcSize
++;
2200 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2201 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2203 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREINFO
);
2205 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2206 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2211 static void test_get16dibits(void)
2213 BYTE bits
[4 * (16 / sizeof(BYTE
))];
2215 HDC screen_dc
= GetDC(NULL
);
2218 int info_len
= sizeof(BITMAPINFOHEADER
) + 1024;
2220 int overwritten_bytes
= 0;
2222 memset(bits
, 0, sizeof(bits
));
2223 hbmp
= CreateBitmap(2, 2, 1, 16, bits
);
2224 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
2226 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info_len
);
2229 memset(info
, '!', info_len
);
2230 memset(info
, 0, sizeof(info
->bmiHeader
));
2232 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
2233 info
->bmiHeader
.biWidth
= 2;
2234 info
->bmiHeader
.biHeight
= 2;
2235 info
->bmiHeader
.biPlanes
= 1;
2236 info
->bmiHeader
.biCompression
= BI_RGB
;
2238 ret
= GetDIBits(screen_dc
, hbmp
, 0, 0, NULL
, info
, 0);
2240 broken(ret
== 0), /* win9x */
2241 "GetDIBits failed got %d\n", ret
);
2243 for (p
= ((BYTE
*) info
) + sizeof(info
->bmiHeader
); (p
- ((BYTE
*) info
)) < info_len
; p
++)
2245 overwritten_bytes
++;
2246 ok(overwritten_bytes
== 0, "GetDIBits wrote past the buffer given\n");
2248 HeapFree(GetProcessHeap(), 0, info
);
2250 ReleaseDC(NULL
, screen_dc
);
2253 static void test_GdiAlphaBlend(void)
2255 /* test out-of-bound parameters for GdiAlphaBlend */
2268 BLENDFUNCTION blend
;
2270 if (!pGdiAlphaBlend
)
2272 win_skip("GdiAlphaBlend() is not implemented\n");
2276 hdcNull
= GetDC(NULL
);
2277 hdcDst
= CreateCompatibleDC(hdcNull
);
2278 bmpDst
= CreateCompatibleBitmap(hdcNull
, 100, 100);
2279 hdcSrc
= CreateCompatibleDC(hdcNull
);
2281 memset(&bmi
, 0, sizeof(bmi
)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2282 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
2283 bmi
.bmiHeader
.biHeight
= 20;
2284 bmi
.bmiHeader
.biWidth
= 20;
2285 bmi
.bmiHeader
.biBitCount
= 32;
2286 bmi
.bmiHeader
.biPlanes
= 1;
2287 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2288 bmpSrc
= CreateDIBSection(hdcDst
, &bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2289 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2291 oldDst
= SelectObject(hdcDst
, bmpDst
);
2292 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2294 blend
.BlendOp
= AC_SRC_OVER
;
2295 blend
.BlendFlags
= 0;
2296 blend
.SourceConstantAlpha
= 128;
2297 blend
.AlphaFormat
= 0;
2299 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, 0, 20, 20, blend
), TRUE
, BOOL
, "%d");
2300 SetLastError(0xdeadbeef);
2301 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2302 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER
, int, "%d");
2303 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), FALSE
, BOOL
, "%d");
2304 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 15, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2305 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2306 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2308 SetWindowOrgEx(hdcSrc
, -10, -10, NULL
);
2309 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), TRUE
, BOOL
, "%d");
2310 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), TRUE
, BOOL
, "%d");
2311 SetMapMode(hdcSrc
, MM_ANISOTROPIC
);
2312 ScaleWindowExtEx(hdcSrc
, 10, 1, 10, 1, NULL
);
2313 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 30, 30, blend
), TRUE
, BOOL
, "%d");
2314 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 30, 30, blend
), TRUE
, BOOL
, "%d");
2316 SelectObject(hdcDst
, oldDst
);
2317 SelectObject(hdcSrc
, oldSrc
);
2318 DeleteObject(bmpSrc
);
2319 DeleteObject(bmpDst
);
2323 ReleaseDC(NULL
, hdcNull
);
2327 static void test_clipping(void)
2337 HDC hdcDst
= CreateCompatibleDC( NULL
);
2338 HDC hdcSrc
= CreateCompatibleDC( NULL
);
2340 BITMAPINFO bmpinfo
={{0}};
2341 bmpinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2342 bmpinfo
.bmiHeader
.biWidth
= 100;
2343 bmpinfo
.bmiHeader
.biHeight
= 100;
2344 bmpinfo
.bmiHeader
.biPlanes
= 1;
2345 bmpinfo
.bmiHeader
.biBitCount
= GetDeviceCaps( hdcDst
, BITSPIXEL
);
2346 bmpinfo
.bmiHeader
.biCompression
= BI_RGB
;
2348 bmpDst
= CreateDIBSection( hdcDst
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2349 ok(bmpDst
!= NULL
, "Couldn't create destination bitmap\n");
2350 oldDst
= SelectObject( hdcDst
, bmpDst
);
2352 bmpSrc
= CreateDIBSection( hdcSrc
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2353 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2354 oldSrc
= SelectObject( hdcSrc
, bmpSrc
);
2356 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 100, 100, SRCCOPY
);
2357 ok(result
, "BitBlt failed\n");
2359 hRgn
= CreateRectRgn( 0,0,0,0 );
2360 SelectClipRgn( hdcDst
, hRgn
);
2362 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 0, 0, SRCCOPY
);
2363 ok(result
, "BitBlt failed\n");
2365 DeleteObject( bmpDst
);
2366 DeleteObject( bmpSrc
);
2367 DeleteObject( hRgn
);
2375 is_win9x
= GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
) == 0;
2377 hdll
= GetModuleHandle("gdi32.dll");
2378 pGdiAlphaBlend
= (void*)GetProcAddress(hdll
, "GdiAlphaBlend");
2380 test_createdibitmap();
2382 test_mono_dibsection();
2385 test_GetDIBits_selected_DIB(1);
2386 test_GetDIBits_selected_DIB(4);
2387 test_GetDIBits_selected_DIB(8);
2388 test_GetDIBits_selected_DDB(TRUE
);
2389 test_GetDIBits_selected_DDB(FALSE
);
2391 test_GetDIBits_BI_BITFIELDS();
2392 test_select_object();
2393 test_CreateBitmap();
2394 test_GdiAlphaBlend();
2395 test_bitmapinfoheadersize();