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 ||
784 broken(bits32
[17] == 0x00ff00), /* Intermittent on Win9x/ME */
785 "bottom but one, left pixel is %08x\n", bits32
[17]);
787 SelectObject(hdcmem2
, oldbm2
);
788 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
791 SelectObject(hdcmem
, oldbm
);
792 SelectObject(hdcmem
, oldpal
);
797 pbmi
->bmiHeader
.biBitCount
= 8;
799 memset(plogpal
, 0, sizeof(logpalbuf
));
800 plogpal
->palVersion
= 0x300;
801 plogpal
->palNumEntries
= 256;
803 for (i
= 0; i
< 128; i
++) {
804 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
805 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
806 plogpal
->palPalEntry
[i
].peGreen
= 0;
807 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
808 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
809 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
812 index
= (WORD
*)pbmi
->bmiColors
;
813 for (i
= 0; i
< 256; i
++) {
817 hpal
= CreatePalette(plogpal
);
818 ok(hpal
!= NULL
, "CreatePalette failed\n");
819 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
820 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
821 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
822 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
823 ok(dibsec
.dsBmih
.biClrUsed
== 256 ||
824 broken(dibsec
.dsBmih
.biClrUsed
== 0), /* win9x */
825 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
827 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
829 SelectPalette(hdc
, oldpal
, TRUE
);
830 oldbm
= SelectObject(hdcmem
, hdib
);
831 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
833 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
834 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
835 for (i
= 0; i
< 256; i
++) {
836 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
837 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
838 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
839 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
840 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
843 for (i
= 0; i
< 256; i
++) {
844 test_color(hdcmem
, DIBINDEX(i
),
845 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
846 test_color(hdcmem
, PALETTEINDEX(i
),
847 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
848 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
849 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
852 SelectPalette(hdcmem
, oldpal
, TRUE
);
853 SelectObject(hdcmem
, oldbm
);
862 static void test_mono_dibsection(void)
865 HBITMAP old_bm
, mono_ds
;
866 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
867 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
874 memdc
= CreateCompatibleDC(hdc
);
876 memset(pbmi
, 0, sizeof(bmibuf
));
877 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
878 pbmi
->bmiHeader
.biHeight
= 10;
879 pbmi
->bmiHeader
.biWidth
= 10;
880 pbmi
->bmiHeader
.biBitCount
= 1;
881 pbmi
->bmiHeader
.biPlanes
= 1;
882 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
883 pbmi
->bmiColors
[0].rgbRed
= 0xff;
884 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
885 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
886 pbmi
->bmiColors
[1].rgbRed
= 0x0;
887 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
888 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
891 * First dib section is 'inverted' ie color[0] is white, color[1] is black
894 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
895 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
896 old_bm
= SelectObject(memdc
, mono_ds
);
898 /* black border, white interior */
899 Rectangle(memdc
, 0, 0, 10, 10);
900 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
901 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
903 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
905 memset(bits
, 0, sizeof(bits
));
908 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
909 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
911 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
913 pbmi
->bmiColors
[0].rgbRed
= 0x0;
914 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
915 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
916 pbmi
->bmiColors
[1].rgbRed
= 0xff;
917 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
918 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
920 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
921 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
923 SelectObject(memdc
, old_bm
);
924 DeleteObject(mono_ds
);
927 * Next dib section is 'normal' ie color[0] is black, color[1] is white
930 pbmi
->bmiColors
[0].rgbRed
= 0x0;
931 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
932 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
933 pbmi
->bmiColors
[1].rgbRed
= 0xff;
934 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
935 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
937 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
938 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
939 old_bm
= SelectObject(memdc
, mono_ds
);
941 /* black border, white interior */
942 Rectangle(memdc
, 0, 0, 10, 10);
943 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
944 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
946 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
948 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
949 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
951 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
953 pbmi
->bmiColors
[0].rgbRed
= 0xff;
954 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
955 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
956 pbmi
->bmiColors
[1].rgbRed
= 0x0;
957 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
958 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
960 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
961 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
964 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
967 pbmi
->bmiColors
[0].rgbRed
= 0xff;
968 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
969 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
970 pbmi
->bmiColors
[1].rgbRed
= 0x0;
971 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
972 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
973 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
974 ok(num
== 2, "num = %d\n", num
);
976 /* black border, white interior */
977 Rectangle(memdc
, 0, 0, 10, 10);
979 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
980 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
982 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
984 memset(bits
, 0, sizeof(bits
));
987 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
988 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
990 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
992 pbmi
->bmiColors
[0].rgbRed
= 0x0;
993 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
994 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
995 pbmi
->bmiColors
[1].rgbRed
= 0xff;
996 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
997 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
999 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1000 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1002 SelectObject(memdc
, old_bm
);
1003 DeleteObject(mono_ds
);
1006 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1009 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1010 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1011 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1012 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
1013 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1014 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1016 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
1017 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
1018 old_bm
= SelectObject(memdc
, mono_ds
);
1020 /* black border, white interior */
1021 Rectangle(memdc
, 0, 0, 10, 10);
1022 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
1023 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
1025 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1027 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1028 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1029 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1030 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1031 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1032 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1034 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1035 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1037 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1039 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1040 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
1041 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
1042 pbmi
->bmiColors
[1].rgbRed
= 0x0;
1043 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1044 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1046 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1047 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1049 SelectObject(memdc
, old_bm
);
1050 DeleteObject(mono_ds
);
1056 static void test_bitmap(void)
1058 char buf
[256], buf_cmp
[256];
1059 HBITMAP hbmp
, hbmp_old
;
1065 hdc
= CreateCompatibleDC(0);
1068 SetLastError(0xdeadbeef);
1069 hbmp
= CreateBitmap(0x7ffffff, 1, 1, 1, NULL
);
1072 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1073 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1074 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1079 SetLastError(0xdeadbeef);
1080 hbmp
= CreateBitmap(0x7ffffff, 9, 1, 1, NULL
);
1083 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1084 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1085 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1090 SetLastError(0xdeadbeef);
1091 hbmp
= CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL
);
1092 ok(!hbmp
|| broken(hbmp
!= NULL
/* Win9x */), "CreateBitmap should fail\n");
1094 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1095 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1099 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
1100 assert(hbmp
!= NULL
);
1102 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1103 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1105 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1106 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1107 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1108 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1109 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1110 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1111 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1113 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
1114 assert(sizeof(buf
) == sizeof(buf_cmp
));
1116 ret
= GetBitmapBits(hbmp
, 0, NULL
);
1117 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
|| broken(ret
== 0 /* Win9x */),
1118 "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1120 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
1121 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
1123 memset(buf
, 0xAA, sizeof(buf
));
1124 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1125 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1126 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1127 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1128 "buffers do not match\n");
1130 hbmp_old
= SelectObject(hdc
, hbmp
);
1132 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1133 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1135 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1136 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1137 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1138 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1139 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1140 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1141 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1143 memset(buf
, 0xAA, sizeof(buf
));
1144 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1145 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1146 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1147 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1148 "buffers do not match\n");
1150 hbmp_old
= SelectObject(hdc
, hbmp_old
);
1151 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
1153 /* test various buffer sizes for GetObject */
1154 ret
= GetObject(hbmp
, sizeof(*bma
) * 2, bma
);
1155 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
1157 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
1158 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
1160 ret
= GetObject(hbmp
, 0, &bm
);
1161 ok(ret
== 0, "%d != 0\n", ret
);
1163 ret
= GetObject(hbmp
, 1, &bm
);
1164 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
1170 static void test_bmBits(void)
1176 memset(bits
, 0, sizeof(bits
));
1177 hbmp
= CreateBitmap(2, 2, 1, 4, bits
);
1178 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
1180 memset(&bmp
, 0xFF, sizeof(bmp
));
1181 ok(GetObject(hbmp
, sizeof(bmp
), &bmp
) == sizeof(bmp
),
1182 "GetObject failed or returned a wrong structure size\n");
1183 ok(!bmp
.bmBits
, "bmBits must be NULL for device-dependent bitmaps\n");
1188 static void test_GetDIBits_selected_DIB(UINT bpp
)
1202 /* Create a DIB section with a color table */
1204 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1205 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1209 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1211 /* Choose width and height such that the row length (in bytes)
1212 is a multiple of 4 (makes things easier) */
1213 info
->bmiHeader
.biWidth
= 32;
1214 info
->bmiHeader
.biHeight
= 32;
1215 info
->bmiHeader
.biPlanes
= 1;
1216 info
->bmiHeader
.biBitCount
= bpp
;
1217 info
->bmiHeader
.biCompression
= BI_RGB
;
1219 for (i
=0; i
< (1u << bpp
); i
++)
1221 BYTE c
= i
* (1 << (8 - bpp
));
1222 info
->bmiColors
[i
].rgbRed
= c
;
1223 info
->bmiColors
[i
].rgbGreen
= c
;
1224 info
->bmiColors
[i
].rgbBlue
= c
;
1225 info
->bmiColors
[i
].rgbReserved
= 0;
1228 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1230 dib_size
= bpp
* (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1232 /* Set the bits of the DIB section */
1233 for (i
=0; i
< dib_size
; i
++)
1235 ((BYTE
*)bits
)[i
] = i
% 256;
1238 /* Select the DIB into a DC */
1239 dib_dc
= CreateCompatibleDC(NULL
);
1240 old_bmp
= SelectObject(dib_dc
, dib
);
1241 dc
= CreateCompatibleDC(NULL
);
1242 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dib_size
);
1245 /* Copy the DIB attributes but not the color table */
1246 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1248 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1249 ok(res
, "GetDIBits failed\n");
1251 /* Compare the color table and the bits */
1252 equalContents
= TRUE
;
1253 for (i
=0; i
< (1u << bpp
); i
++)
1255 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1256 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1257 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1258 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1260 equalContents
= FALSE
;
1264 ok(equalContents
, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1266 equalContents
= TRUE
;
1267 for (i
=0; i
< dib_size
/ sizeof(DWORD
); i
++)
1269 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1271 equalContents
= FALSE
;
1275 ok(equalContents
, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp
);
1277 HeapFree(GetProcessHeap(), 0, bits2
);
1280 SelectObject(dib_dc
, old_bmp
);
1284 HeapFree(GetProcessHeap(), 0, info2
);
1285 HeapFree(GetProcessHeap(), 0, info
);
1288 static void test_GetDIBits_selected_DDB(BOOL monochrome
)
1303 width
= height
= 16;
1305 /* Create a DDB (device-dependent bitmap) */
1309 ddb
= CreateBitmap(width
, height
, 1, 1, NULL
);
1313 HDC screen_dc
= GetDC(NULL
);
1314 bpp
= GetDeviceCaps(screen_dc
, BITSPIXEL
) * GetDeviceCaps(screen_dc
, PLANES
);
1315 ddb
= CreateCompatibleBitmap(screen_dc
, width
, height
);
1316 ReleaseDC(NULL
, screen_dc
);
1319 /* Set the pixels */
1320 ddb_dc
= CreateCompatibleDC(NULL
);
1321 old_bmp
= SelectObject(ddb_dc
, ddb
);
1322 for (i
= 0; i
< width
; i
++)
1324 for (j
=0; j
< height
; j
++)
1326 BYTE c
= (i
* width
+ j
) % 256;
1327 SetPixelV(ddb_dc
, i
, j
, RGB(c
, c
, c
));
1330 SelectObject(ddb_dc
, old_bmp
);
1332 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1333 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1337 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1338 info
->bmiHeader
.biWidth
= width
;
1339 info
->bmiHeader
.biHeight
= height
;
1340 info
->bmiHeader
.biPlanes
= 1;
1341 info
->bmiHeader
.biBitCount
= bpp
;
1342 info
->bmiHeader
.biCompression
= BI_RGB
;
1344 dc
= CreateCompatibleDC(NULL
);
1346 /* Fill in biSizeImage */
1347 GetDIBits(dc
, ddb
, 0, height
, NULL
, info
, DIB_RGB_COLORS
);
1348 ok(info
->bmiHeader
.biSizeImage
!= 0, "GetDIBits failed to get the DIB attributes\n");
1350 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1351 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1356 res
= GetDIBits(dc
, ddb
, 0, height
, bits
, info
, DIB_RGB_COLORS
);
1357 ok(res
, "GetDIBits failed\n");
1359 /* Copy the DIB attributes but not the color table */
1360 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1362 /* Select the DDB into another DC */
1363 old_bmp
= SelectObject(ddb_dc
, ddb
);
1366 res
= GetDIBits(dc
, ddb
, 0, height
, bits2
, info2
, DIB_RGB_COLORS
);
1367 ok(res
, "GetDIBits failed\n");
1369 /* Compare the color table and the bits */
1372 equalContents
= TRUE
;
1373 for (i
=0; i
< (1u << bpp
); i
++)
1375 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1376 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1377 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1378 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1380 equalContents
= FALSE
;
1384 ok(equalContents
, "GetDIBits with DDB selected in DC: Got a different color table\n");
1387 equalContents
= TRUE
;
1388 for (i
=0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++)
1390 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1392 equalContents
= FALSE
;
1395 ok(equalContents
, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1397 /* Test the palette */
1398 equalContents
= TRUE
;
1399 if (info2
->bmiHeader
.biBitCount
<= 8)
1401 WORD
*colors
= (WORD
*)info2
->bmiColors
;
1403 /* Get the palette indices */
1404 res
= GetDIBits(dc
, ddb
, 0, 0, NULL
, info2
, DIB_PAL_COLORS
);
1405 if (res
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
) /* Win9x */
1406 res
= GetDIBits(dc
, ddb
, 0, height
, NULL
, info2
, DIB_PAL_COLORS
);
1407 ok(res
, "GetDIBits failed\n");
1409 for (i
=0;i
< 1 << info
->bmiHeader
.biSizeImage
; i
++)
1413 equalContents
= FALSE
;
1419 ok(equalContents
, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1421 HeapFree(GetProcessHeap(), 0, bits2
);
1422 HeapFree(GetProcessHeap(), 0, bits
);
1425 SelectObject(ddb_dc
, old_bmp
);
1429 HeapFree(GetProcessHeap(), 0, info2
);
1430 HeapFree(GetProcessHeap(), 0, info
);
1433 static void test_GetDIBits(void)
1435 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1436 static const BYTE bmp_bits_1
[16 * 2] =
1438 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1439 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1440 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1441 0xff,0xff, 0,0, 0xff,0xff, 0,0
1443 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1444 static const BYTE dib_bits_1
[16 * 4] =
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,
1448 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1449 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1451 static const BYTE dib_bits_1_9x
[16 * 4] =
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,
1455 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1456 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1458 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1459 static const BYTE bmp_bits_24
[16 * 16*3] =
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,
1469 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1470 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1471 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1472 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1473 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1474 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1475 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1476 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1477 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1478 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1479 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1480 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1481 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1482 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1483 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1484 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1485 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1486 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1487 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1488 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1489 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1490 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1491 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 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 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1495 static const BYTE dib_bits_24
[16 * 16*3] =
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,
1505 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1506 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1507 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1508 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 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1510 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1511 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1512 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1513 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1514 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1515 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1516 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1517 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1518 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1519 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1520 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1522 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1523 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1524 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1525 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1526 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1527 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1528 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1533 int i
, bytes
, lines
;
1535 char bi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1536 BITMAPINFO
*bi
= (BITMAPINFO
*)bi_buf
;
1540 /* 1-bit source bitmap data */
1541 hbmp
= CreateBitmap(16, 16, 1, 1, bmp_bits_1
);
1542 ok(hbmp
!= 0, "CreateBitmap failed\n");
1544 memset(&bm
, 0xAA, sizeof(bm
));
1545 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1546 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1547 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1548 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1549 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1550 ok(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1551 ok(bm
.bmPlanes
== 1, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1552 ok(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1553 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1555 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1556 ok(bytes
== sizeof(bmp_bits_1
) || broken(bytes
== 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes
);
1557 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1558 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1559 ok(!memcmp(buf
, bmp_bits_1
, sizeof(bmp_bits_1
)), "bitmap bits don't match\n");
1561 /* retrieve 1-bit DIB data */
1562 memset(bi
, 0, sizeof(*bi
));
1563 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1564 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1565 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1566 bi
->bmiHeader
.biPlanes
= 1;
1567 bi
->bmiHeader
.biBitCount
= 1;
1568 bi
->bmiHeader
.biCompression
= BI_RGB
;
1569 bi
->bmiHeader
.biSizeImage
= 0;
1570 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1571 SetLastError(0xdeadbeef);
1572 lines
= GetDIBits(0, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1573 ok(lines
== 0, "GetDIBits copied %d lines with hdc = 0\n", lines
);
1574 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
1575 broken(GetLastError() == 0xdeadbeef), /* winnt */
1576 "wrong error %u\n", GetLastError());
1577 ok(bi
->bmiHeader
.biSizeImage
== 0, "expected 0, got %u\n", bi
->bmiHeader
.biSizeImage
);
1579 memset(buf
, 0xAA, sizeof(buf
));
1580 SetLastError(0xdeadbeef);
1581 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1582 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1583 lines
, bm
.bmHeight
, GetLastError());
1584 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1585 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1586 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1588 /* the color table consists of black and white */
1589 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1590 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1591 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1592 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1593 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1594 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1595 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1596 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1597 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1598 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1599 for (i
= 2; i
< 256; i
++)
1601 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1602 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1603 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1604 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1605 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1608 /* returned bits are DWORD aligned and upside down */
1609 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1610 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1611 "DIB bits don't match\n");
1613 /* Test the palette indices */
1614 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1615 SetLastError(0xdeadbeef);
1616 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1617 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1618 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1621 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1622 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1624 for (i
= 2; i
< 256; i
++)
1625 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[1]);
1627 /* retrieve 24-bit DIB data */
1628 memset(bi
, 0, sizeof(*bi
));
1629 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1630 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1631 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1632 bi
->bmiHeader
.biPlanes
= 1;
1633 bi
->bmiHeader
.biBitCount
= 24;
1634 bi
->bmiHeader
.biCompression
= BI_RGB
;
1635 bi
->bmiHeader
.biSizeImage
= 0;
1636 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1637 memset(buf
, 0xAA, sizeof(buf
));
1638 SetLastError(0xdeadbeef);
1639 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1640 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1641 lines
, bm
.bmHeight
, GetLastError());
1642 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1643 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1644 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1646 /* the color table doesn't exist for 24-bit images */
1647 for (i
= 0; i
< 256; i
++)
1649 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1650 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1651 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1652 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1653 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1656 /* returned bits are DWORD aligned and upside down */
1657 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1660 /* 24-bit source bitmap data */
1661 hbmp
= CreateCompatibleBitmap(hdc
, 16, 16);
1662 ok(hbmp
!= 0, "CreateBitmap failed\n");
1663 SetLastError(0xdeadbeef);
1664 bi
->bmiHeader
.biHeight
= -bm
.bmHeight
; /* indicate bottom-up data */
1665 lines
= SetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, bmp_bits_24
, bi
, DIB_RGB_COLORS
);
1666 ok(lines
== bm
.bmHeight
, "SetDIBits copied %d lines of %d, error %u\n",
1667 lines
, bm
.bmHeight
, GetLastError());
1669 memset(&bm
, 0xAA, sizeof(bm
));
1670 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1671 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1672 ok(bm
.bmType
== 0 ||
1673 broken(bm
.bmType
== 21072), /* win9x */
1674 "wrong bmType %d\n", bm
.bmType
);
1675 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1676 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1677 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1678 ok(bm
.bmPlanes
== GetDeviceCaps(hdc
, PLANES
), "wrong bmPlanes %u\n", bm
.bmPlanes
);
1679 ok(bm
.bmBitsPixel
== GetDeviceCaps(hdc
, BITSPIXEL
), "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1680 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1682 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1683 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
||
1684 broken(bytes
== 0), /* win9x */
1685 "expected %d got %d bytes\n", bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1686 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1687 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1688 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1690 /* retrieve 1-bit DIB data */
1691 memset(bi
, 0, sizeof(*bi
));
1692 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1693 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1694 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1695 bi
->bmiHeader
.biPlanes
= 1;
1696 bi
->bmiHeader
.biBitCount
= 1;
1697 bi
->bmiHeader
.biCompression
= BI_RGB
;
1698 bi
->bmiHeader
.biSizeImage
= 0;
1699 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1700 memset(buf
, 0xAA, sizeof(buf
));
1701 SetLastError(0xdeadbeef);
1702 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1703 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1704 lines
, bm
.bmHeight
, GetLastError());
1705 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1706 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1707 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1709 /* the color table consists of black and white */
1710 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1711 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1712 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1713 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1714 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1715 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1716 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1717 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1718 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1719 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1720 for (i
= 2; i
< 256; i
++)
1722 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1723 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1724 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1725 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1726 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1729 /* returned bits are DWORD aligned and upside down */
1731 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1732 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1733 "DIB bits don't match\n");
1735 /* Test the palette indices */
1736 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1737 SetLastError(0xdeadbeef);
1738 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1739 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1740 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1743 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1744 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1746 for (i
= 2; i
< 256; i
++)
1747 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[i
]);
1749 /* retrieve 24-bit DIB data */
1750 memset(bi
, 0, sizeof(*bi
));
1751 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1752 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1753 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1754 bi
->bmiHeader
.biPlanes
= 1;
1755 bi
->bmiHeader
.biBitCount
= 24;
1756 bi
->bmiHeader
.biCompression
= BI_RGB
;
1757 bi
->bmiHeader
.biSizeImage
= 0;
1758 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1759 memset(buf
, 0xAA, sizeof(buf
));
1760 SetLastError(0xdeadbeef);
1761 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1762 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1763 lines
, bm
.bmHeight
, GetLastError());
1764 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1765 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1766 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1768 /* the color table doesn't exist for 24-bit images */
1769 for (i
= 0; i
< 256; i
++)
1771 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1772 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1773 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1774 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1775 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1778 /* returned bits are DWORD aligned and upside down */
1779 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1785 static void test_GetDIBits_BI_BITFIELDS(void)
1787 /* Try a screen resolution detection technique
1788 * from the September 1999 issue of Windows Developer's Journal
1789 * which seems to be in widespread use.
1790 * http://www.lesher.ws/highcolor.html
1791 * http://www.lesher.ws/vidfmt.c
1792 * It hinges on being able to retrieve the bitmaps
1793 * for the three primary colors in non-paletted 16 bit mode.
1795 char dibinfo_buf
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
1797 LPBITMAPINFO dibinfo
= (LPBITMAPINFO
) dibinfo_buf
;
1802 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1803 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1806 ok(hdc
!= NULL
, "GetDC failed?\n");
1807 hbm
= CreateCompatibleBitmap(hdc
, 1, 1);
1808 ok(hbm
!= NULL
, "CreateCompatibleBitmap failed?\n");
1810 /* Call GetDIBits to fill in bmiHeader. */
1811 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1812 ok(ret
== 1, "GetDIBits failed\n");
1813 if (dibinfo
->bmiHeader
.biBitCount
> 8)
1815 DWORD
*bitmasks
= (DWORD
*)dibinfo
->bmiColors
;
1817 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1818 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1820 ok( !bitmasks
[0], "red mask is set\n" );
1821 ok( !bitmasks
[1], "green mask is set\n" );
1822 ok( !bitmasks
[2], "blue mask is set\n" );
1824 /* test with NULL bits pointer and correct bpp */
1825 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1826 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1827 ok(ret
== 1, "GetDIBits failed\n");
1829 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1830 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1831 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1832 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1834 /* test with valid bits pointer */
1835 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1836 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1837 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1838 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1839 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1840 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1841 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1843 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1844 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1845 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1846 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef ||
1847 broken(dibinfo
->bmiHeader
.biSizeImage
== 0xdeadbeef), /* win9x */
1848 "size image not set\n" );
1850 /* now with bits and 0 lines */
1851 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1852 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1853 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1854 SetLastError(0xdeadbeef);
1855 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1856 if (ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1857 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1860 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1862 ok( !bitmasks
[0], "red mask is set\n" );
1863 ok( !bitmasks
[1], "green mask is set\n" );
1864 ok( !bitmasks
[2], "blue mask is set\n" );
1865 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1867 memset(bitmasks
, 0, 3*sizeof(DWORD
));
1868 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1869 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1870 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1872 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1873 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1874 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1875 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1878 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1881 ReleaseDC(NULL
, hdc
);
1884 static void test_select_object(void)
1887 HBITMAP hbm
, hbm_old
;
1889 DWORD depths
[] = {8, 15, 16, 24, 32};
1894 ok(hdc
!= 0, "GetDC(0) failed\n");
1895 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1896 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1898 hbm_old
= SelectObject(hdc
, hbm
);
1899 ok(hbm_old
== 0, "SelectObject should fail\n");
1904 hdc
= CreateCompatibleDC(0);
1905 ok(hdc
!= 0, "GetDC(0) failed\n");
1906 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1907 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1909 hbm_old
= SelectObject(hdc
, hbm
);
1910 ok(hbm_old
!= 0, "SelectObject failed\n");
1911 hbm_old
= SelectObject(hdc
, hbm_old
);
1912 ok(hbm_old
== hbm
, "SelectObject failed\n");
1916 /* test an 1-bpp bitmap */
1917 planes
= GetDeviceCaps(hdc
, PLANES
);
1920 hbm
= CreateBitmap(10, 10, planes
, bpp
, NULL
);
1921 ok(hbm
!= 0, "CreateBitmap failed\n");
1923 hbm_old
= SelectObject(hdc
, hbm
);
1924 ok(hbm_old
!= 0, "SelectObject failed\n");
1925 hbm_old
= SelectObject(hdc
, hbm_old
);
1926 ok(hbm_old
== hbm
, "SelectObject failed\n");
1930 for(i
= 0; i
< sizeof(depths
)/sizeof(depths
[0]); i
++) {
1931 /* test a color bitmap to dc bpp matching */
1932 planes
= GetDeviceCaps(hdc
, PLANES
);
1933 bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
1935 hbm
= CreateBitmap(10, 10, planes
, depths
[i
], NULL
);
1936 ok(hbm
!= 0, "CreateBitmap failed\n");
1938 hbm_old
= SelectObject(hdc
, hbm
);
1939 if(depths
[i
] == bpp
||
1940 (bpp
== 16 && depths
[i
] == 15) /* 16 and 15 bpp are compatible */
1942 ok(hbm_old
!= 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp
, depths
[i
]);
1943 SelectObject(hdc
, hbm_old
);
1945 ok(hbm_old
== 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp
, depths
[i
]);
1948 memset(&bm
, 0xAA, sizeof(bm
));
1949 bytes
= GetObject(hbm
, sizeof(bm
), &bm
);
1950 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1951 ok(bm
.bmType
== 0 ||
1952 broken(bm
.bmType
== 21072), /* win9x */
1953 "wrong bmType %d\n", bm
.bmType
);
1954 ok(bm
.bmWidth
== 10, "wrong bmWidth %d\n", bm
.bmWidth
);
1955 ok(bm
.bmHeight
== 10, "wrong bmHeight %d\n", bm
.bmHeight
);
1956 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1957 ok(bm
.bmPlanes
== planes
, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1958 if(depths
[i
] == 15) {
1959 ok(bm
.bmBitsPixel
== 16 ||
1960 broken(bm
.bmBitsPixel
== 15), /* Win9x/WinME */
1961 "wrong bmBitsPixel %d(15 bpp special)\n", bm
.bmBitsPixel
);
1963 ok(bm
.bmBitsPixel
== depths
[i
], "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1965 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1973 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp
, int line
)
1978 ret
= GetObjectType(hbmp
);
1979 ok_(__FILE__
, line
)(ret
== OBJ_BITMAP
, "the object %p is not bitmap\n", hbmp
);
1981 ret
= GetObject(hbmp
, 0, 0);
1982 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) /* XP */ ||
1983 ret
== sizeof(DIBSECTION
) /* Win9x */, "object size %d\n", ret
);
1985 memset(&bm
, 0xDA, sizeof(bm
));
1986 SetLastError(0xdeadbeef);
1987 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1988 if (!ret
) /* XP, only for curObj2 */ return;
1989 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) ||
1990 ret
== sizeof(DIBSECTION
) /* Win9x, only for curObj2 */,
1991 "GetObject returned %d, error %u\n", ret
, GetLastError());
1992 ok_(__FILE__
, line
)(bm
.bmType
== 0, "wrong bmType, expected 0 got %d\n", bm
.bmType
);
1993 ok_(__FILE__
, line
)(bm
.bmWidth
== 1, "wrong bmWidth, expected 1 got %d\n", bm
.bmWidth
);
1994 ok_(__FILE__
, line
)(bm
.bmHeight
== 1, "wrong bmHeight, expected 1 got %d\n", bm
.bmHeight
);
1995 ok_(__FILE__
, line
)(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes, expected 2 got %d\n", bm
.bmWidthBytes
);
1996 ok_(__FILE__
, line
)(bm
.bmPlanes
== 1, "wrong bmPlanes, expected 1 got %u\n", bm
.bmPlanes
);
1997 ok_(__FILE__
, line
)(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel, expected 1 got %d\n", bm
.bmBitsPixel
);
1998 ok_(__FILE__
, line
)(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
2001 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2003 static void test_CreateBitmap(void)
2006 HDC screenDC
= GetDC(0);
2007 HDC hdc
= CreateCompatibleDC(screenDC
);
2010 /* all of these are the stock monochrome bitmap */
2011 HBITMAP bm
= CreateCompatibleBitmap(hdc
, 0, 0);
2012 HBITMAP bm1
= CreateCompatibleBitmap(screenDC
, 0, 0);
2013 HBITMAP bm4
= CreateBitmap(0, 1, 0, 0, 0);
2014 HBITMAP bm5
= CreateDiscardableBitmap(hdc
, 0, 0);
2015 HBITMAP curObj1
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2016 HBITMAP curObj2
= GetCurrentObject(screenDC
, OBJ_BITMAP
);
2018 /* these 2 are not the stock monochrome bitmap */
2019 HBITMAP bm2
= CreateCompatibleBitmap(hdc
, 1, 1);
2020 HBITMAP bm3
= CreateBitmap(1, 1, 1, 1, 0);
2022 HBITMAP old1
= SelectObject(hdc
, bm2
);
2023 HBITMAP old2
= SelectObject(screenDC
, bm3
);
2024 SelectObject(hdc
, old1
);
2025 SelectObject(screenDC
, old2
);
2027 ok(bm
== bm1
&& bm
== bm4
&& bm
== bm5
&& bm
== curObj1
&& bm
== old1
,
2028 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2029 bm
, bm1
, bm4
, bm5
, curObj1
, old1
);
2030 ok(bm
!= bm2
&& bm
!= bm3
, "0: %p, 2: %p, 3: %p\n", bm
, bm2
, bm3
);
2032 ok(bm
!= curObj2
|| /* WinXP */
2033 broken(bm
== curObj2
) /* Win9x */,
2034 "0: %p, curObj2 %p\n", bm
, curObj2
);
2035 ok(old2
== 0, "old2 %p\n", old2
);
2037 test_mono_1x1_bmp(bm
);
2038 test_mono_1x1_bmp(bm1
);
2039 test_mono_1x1_bmp(bm2
);
2040 test_mono_1x1_bmp(bm3
);
2041 test_mono_1x1_bmp(bm4
);
2042 test_mono_1x1_bmp(bm5
);
2043 test_mono_1x1_bmp(old1
);
2044 test_mono_1x1_bmp(curObj1
);
2054 ReleaseDC(0, screenDC
);
2056 /* show that Windows ignores the provided bm.bmWidthBytes */
2060 bmp
.bmWidthBytes
= 28;
2062 bmp
.bmBitsPixel
= 1;
2064 bm
= CreateBitmapIndirect(&bmp
);
2065 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2066 test_mono_1x1_bmp(bm
);
2069 /* Test how the bmBitsPixel field is treated */
2070 for(i
= 1; i
<= 33; i
++) {
2074 bmp
.bmWidthBytes
= 28;
2076 bmp
.bmBitsPixel
= i
;
2078 SetLastError(0xdeadbeef);
2079 bm
= CreateBitmapIndirect(&bmp
);
2081 DWORD error
= GetLastError();
2083 broken(bm
!= 0), /* Win9x and WinMe */
2084 "CreateBitmapIndirect for %d bpp succeeded\n", i
);
2085 ok(error
== ERROR_INVALID_PARAMETER
||
2086 broken(error
== 0xdeadbeef), /* Win9x and WinME */
2087 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error
);
2091 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2092 GetObject(bm
, sizeof(bmp
), &bmp
);
2099 } else if(i
<= 16) {
2101 } else if(i
<= 24) {
2103 } else if(i
<= 32) {
2106 ok(bmp
.bmBitsPixel
== expect
||
2107 broken(bmp
.bmBitsPixel
== i
), /* Win9x and WinMe */
2108 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2109 i
, bmp
.bmBitsPixel
, expect
);
2114 static void test_bitmapinfoheadersize(void)
2121 memset(&bmi
, 0, sizeof(BITMAPINFO
));
2122 bmi
.bmiHeader
.biHeight
= 100;
2123 bmi
.bmiHeader
.biWidth
= 512;
2124 bmi
.bmiHeader
.biBitCount
= 24;
2125 bmi
.bmiHeader
.biPlanes
= 1;
2127 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) - 1;
2129 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2130 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2132 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2134 SetLastError(0xdeadbeef);
2135 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2136 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2139 bmi
.bmiHeader
.biSize
++;
2141 SetLastError(0xdeadbeef);
2142 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2144 broken(!hdib
), /* Win98, WinMe */
2145 "CreateDIBSection error %d\n", GetLastError());
2148 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFO
);
2150 SetLastError(0xdeadbeef);
2151 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2153 broken(!hdib
), /* Win98, WinMe */
2154 "CreateDIBSection error %d\n", GetLastError());
2157 bmi
.bmiHeader
.biSize
++;
2159 SetLastError(0xdeadbeef);
2160 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2162 broken(!hdib
), /* Win98, WinMe */
2163 "CreateDIBSection error %d\n", GetLastError());
2166 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
2168 SetLastError(0xdeadbeef);
2169 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2170 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2173 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
2175 SetLastError(0xdeadbeef);
2176 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2178 broken(!hdib
), /* Win95 */
2179 "CreateDIBSection error %d\n", GetLastError());
2182 memset(&bci
, 0, sizeof(BITMAPCOREINFO
));
2183 bci
.bmciHeader
.bcHeight
= 100;
2184 bci
.bmciHeader
.bcWidth
= 512;
2185 bci
.bmciHeader
.bcBitCount
= 24;
2186 bci
.bmciHeader
.bcPlanes
= 1;
2188 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
) - 1;
2190 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2191 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2193 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2195 SetLastError(0xdeadbeef);
2196 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2197 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2200 bci
.bmciHeader
.bcSize
++;
2202 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2203 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2205 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREINFO
);
2207 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2208 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2213 static void test_get16dibits(void)
2215 BYTE bits
[4 * (16 / sizeof(BYTE
))];
2217 HDC screen_dc
= GetDC(NULL
);
2220 int info_len
= sizeof(BITMAPINFOHEADER
) + 1024;
2222 int overwritten_bytes
= 0;
2224 memset(bits
, 0, sizeof(bits
));
2225 hbmp
= CreateBitmap(2, 2, 1, 16, bits
);
2226 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
2228 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info_len
);
2231 memset(info
, '!', info_len
);
2232 memset(info
, 0, sizeof(info
->bmiHeader
));
2234 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
2235 info
->bmiHeader
.biWidth
= 2;
2236 info
->bmiHeader
.biHeight
= 2;
2237 info
->bmiHeader
.biPlanes
= 1;
2238 info
->bmiHeader
.biCompression
= BI_RGB
;
2240 ret
= GetDIBits(screen_dc
, hbmp
, 0, 0, NULL
, info
, 0);
2242 broken(ret
== 0), /* win9x */
2243 "GetDIBits failed got %d\n", ret
);
2245 for (p
= ((BYTE
*) info
) + sizeof(info
->bmiHeader
); (p
- ((BYTE
*) info
)) < info_len
; p
++)
2247 overwritten_bytes
++;
2248 ok(overwritten_bytes
== 0, "GetDIBits wrote past the buffer given\n");
2250 HeapFree(GetProcessHeap(), 0, info
);
2252 ReleaseDC(NULL
, screen_dc
);
2255 static BOOL
compare_buffers_no_alpha(UINT32
*a
, UINT32
*b
, int length
)
2258 for(i
= 0; i
< length
; i
++)
2259 if((a
[i
] & 0x00FFFFFF) != (b
[i
] & 0x00FFFFFF))
2264 static void check_BitBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2265 DWORD dwRop
, UINT32 expected
, int line
)
2267 *srcBuffer
= 0xFEDCBA98;
2268 *dstBuffer
= 0x89ABCDEF;
2269 Rectangle(hdcSrc
, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2270 BitBlt(hdcDst
, 0, 0, 1, 1, hdcSrc
, 0, 0, dwRop
);
2271 ok(expected
== *dstBuffer
,
2272 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2273 dwRop
, expected
, *dstBuffer
, line
);
2276 static void test_BitBlt(void)
2278 HBITMAP bmpDst
, bmpSrc
;
2279 HBITMAP oldDst
, oldSrc
;
2280 HDC hdcScreen
, hdcDst
, hdcSrc
;
2281 UINT32
*dstBuffer
, *srcBuffer
;
2282 HBRUSH hBrush
, hOldBrush
;
2283 BITMAPINFO bitmapInfo
;
2285 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2286 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2287 bitmapInfo
.bmiHeader
.biWidth
= 1;
2288 bitmapInfo
.bmiHeader
.biHeight
= 1;
2289 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2290 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2291 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2292 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
2294 hdcScreen
= CreateCompatibleDC(0);
2295 hdcDst
= CreateCompatibleDC(hdcScreen
);
2296 hdcSrc
= CreateCompatibleDC(hdcDst
);
2298 /* Setup the destination dib section */
2299 bmpDst
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2301 oldDst
= SelectObject(hdcDst
, bmpDst
);
2303 hBrush
= CreateSolidBrush(0x012345678);
2304 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2306 /* Setup the source dib section */
2307 bmpSrc
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2309 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2311 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2312 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2313 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2314 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2315 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2316 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2317 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2318 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2319 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2320 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2321 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2322 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2323 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2324 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2325 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2328 SelectObject(hdcSrc
, oldSrc
);
2329 DeleteObject(bmpSrc
);
2332 SelectObject(hdcDst
, hOldBrush
);
2333 DeleteObject(hBrush
);
2334 SelectObject(hdcDst
, oldDst
);
2335 DeleteObject(bmpDst
);
2339 DeleteDC(hdcScreen
);
2342 static void check_StretchBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2343 DWORD dwRop
, UINT32 expected
, int line
)
2345 *srcBuffer
= 0xFEDCBA98;
2346 *dstBuffer
= 0x89ABCDEF;
2347 StretchBlt(hdcDst
, 0, 0, 2, 1, hdcSrc
, 0, 0, 1, 1, dwRop
);
2348 ok(expected
== *dstBuffer
,
2349 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2350 dwRop
, expected
, *dstBuffer
, line
);
2353 static void check_StretchBlt_stretch(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2354 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2355 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2356 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2358 memset(dstBuffer
, 0, 16);
2359 StretchBlt(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2360 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
, SRCCOPY
);
2361 ok(memcmp(dstBuffer
, expected
, 16) == 0 ||
2362 broken(compare_buffers_no_alpha(dstBuffer
, legacy_expected
, 4)),
2363 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2364 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2365 expected
[0], expected
[1], expected
[2], expected
[3],
2366 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2367 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2368 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2371 static void test_StretchBlt(void)
2373 HBITMAP bmpDst
, bmpSrc
;
2374 HBITMAP oldDst
, oldSrc
;
2375 HDC hdcScreen
, hdcDst
, hdcSrc
;
2376 UINT32
*dstBuffer
, *srcBuffer
;
2377 HBRUSH hBrush
, hOldBrush
;
2378 BITMAPINFO biDst
, biSrc
;
2379 UINT32 expected
[4], legacy_expected
[4];
2381 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2382 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2383 biDst
.bmiHeader
.biWidth
= 2;
2384 biDst
.bmiHeader
.biHeight
= -2;
2385 biDst
.bmiHeader
.biPlanes
= 1;
2386 biDst
.bmiHeader
.biBitCount
= 32;
2387 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2388 memcpy(&biSrc
, &biDst
, sizeof(BITMAPINFO
));
2390 hdcScreen
= CreateCompatibleDC(0);
2391 hdcDst
= CreateCompatibleDC(hdcScreen
);
2392 hdcSrc
= CreateCompatibleDC(hdcDst
);
2395 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2397 oldDst
= SelectObject(hdcDst
, bmpDst
);
2399 bmpSrc
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2401 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2403 hBrush
= CreateSolidBrush(0x012345678);
2404 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2406 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2407 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2408 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2409 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2410 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2411 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2412 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2413 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2414 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2415 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2416 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2417 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2418 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2419 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2420 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2422 SelectObject(hdcDst
, hOldBrush
);
2423 DeleteObject(hBrush
);
2425 /* Top-down to top-down tests */
2426 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2427 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2429 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2430 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2431 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2432 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2434 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2435 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2436 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2437 0, 0, 1, 1, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2439 expected
[0] = 0xCAFED00D, expected
[1] = 0xCAFED00D;
2440 expected
[2] = 0xCAFED00D, expected
[3] = 0xCAFED00D;
2441 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2442 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2444 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2445 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2446 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2447 0, 0, 1, 1, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2449 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2450 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2451 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2452 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2454 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2455 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2456 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2457 1, 1, -2, -2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2459 /* This result seems broken. One might expect the following result:
2460 * 0xCAFED00D 0xFEEDFACE
2461 * 0xFEDCBA98 0x76543210
2463 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2464 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2465 legacy_expected
[0] = 0xCAFED00D, legacy_expected
[1] = 0x00000000;
2466 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2467 todo_wine
check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2468 1, 1, -2, -2, 1, 1, -2, -2, expected
,
2469 legacy_expected
, __LINE__
);
2471 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2472 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2473 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2474 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2476 SelectObject(hdcDst
, oldDst
);
2477 DeleteObject(bmpDst
);
2479 /* Top-down to bottom-up tests */
2480 biDst
.bmiHeader
.biHeight
= 2;
2481 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2483 oldDst
= SelectObject(hdcDst
, bmpDst
);
2485 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2486 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2487 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2488 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2490 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2491 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2492 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2493 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2495 SelectObject(hdcSrc
, oldSrc
);
2496 DeleteObject(bmpSrc
);
2498 /* Bottom-up to bottom-up tests */
2499 biSrc
.bmiHeader
.biHeight
= 2;
2500 bmpSrc
= CreateDIBSection(hdcScreen
, &biSrc
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2502 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2503 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2504 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2506 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2507 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2508 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2509 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2511 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2512 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2513 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2514 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2516 SelectObject(hdcDst
, oldDst
);
2517 DeleteObject(bmpDst
);
2519 /* Bottom-up to top-down tests */
2520 biDst
.bmiHeader
.biHeight
= -2;
2521 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2523 oldDst
= SelectObject(hdcDst
, bmpDst
);
2525 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2526 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2527 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2528 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2530 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2531 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2532 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2533 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2536 SelectObject(hdcSrc
, oldSrc
);
2537 DeleteObject(bmpSrc
);
2540 SelectObject(hdcDst
, oldDst
);
2541 DeleteObject(bmpDst
);
2544 DeleteDC(hdcScreen
);
2547 static void check_StretchDIBits_pixel(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2548 DWORD dwRop
, UINT32 expected
, int line
)
2550 const UINT32 buffer
[2] = { 0xFEDCBA98, 0 };
2551 BITMAPINFO bitmapInfo
;
2553 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2554 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2555 bitmapInfo
.bmiHeader
.biWidth
= 2;
2556 bitmapInfo
.bmiHeader
.biHeight
= 1;
2557 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2558 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2559 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2560 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(buffer
);
2562 *dstBuffer
= 0x89ABCDEF;
2564 StretchDIBits(hdcDst
, 0, 0, 2, 1, 0, 0, 1, 1, &buffer
, &bitmapInfo
, DIB_RGB_COLORS
, dwRop
);
2565 ok(expected
== *dstBuffer
,
2566 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2567 dwRop
, expected
, *dstBuffer
, line
);
2570 static void check_StretchDIBits_stretch(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2571 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2572 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2573 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2575 BITMAPINFO bitmapInfo
;
2577 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2578 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2579 bitmapInfo
.bmiHeader
.biWidth
= 2;
2580 bitmapInfo
.bmiHeader
.biHeight
= -2;
2581 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2582 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2583 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2585 memset(dstBuffer
, 0, 16);
2586 StretchDIBits(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2587 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2588 srcBuffer
, &bitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
2589 ok(memcmp(dstBuffer
, expected
, 16) == 0 || /* Win2k/XP */
2590 broken(compare_buffers_no_alpha(dstBuffer
, legacy_expected
, 4)) || /* Win9X/ME */
2591 broken(nWidthSrc
< 0 || nHeightSrc
< 0), /* Win9X/ME */
2592 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2593 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2594 expected
[0], expected
[1], expected
[2], expected
[3],
2595 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2596 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2597 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2600 static void test_StretchDIBits(void)
2604 HDC hdcScreen
, hdcDst
;
2605 UINT32
*dstBuffer
, srcBuffer
[4];
2606 HBRUSH hBrush
, hOldBrush
;
2608 UINT32 expected
[4], legacy_expected
[4];
2610 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2611 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2612 biDst
.bmiHeader
.biWidth
= 2;
2613 biDst
.bmiHeader
.biHeight
= -2;
2614 biDst
.bmiHeader
.biPlanes
= 1;
2615 biDst
.bmiHeader
.biBitCount
= 32;
2616 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2618 hdcScreen
= CreateCompatibleDC(0);
2619 hdcDst
= CreateCompatibleDC(hdcScreen
);
2622 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2624 oldDst
= SelectObject(hdcDst
, bmpDst
);
2626 hBrush
= CreateSolidBrush(0x012345678);
2627 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2629 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2630 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2631 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2632 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2633 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2634 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2635 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2636 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2637 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2638 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2639 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2640 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2641 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2642 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2643 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2645 SelectObject(hdcDst
, hOldBrush
);
2646 DeleteObject(hBrush
);
2648 /* Top-down destination tests */
2649 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2650 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2652 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2653 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2654 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2655 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2657 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2658 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2659 legacy_expected
[0] = 0xFEDCBA98, legacy_expected
[1] = 0x00000000;
2660 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2661 todo_wine
check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2662 0, 0, 1, 1, 0, 0, 1, 1, expected
, legacy_expected
, __LINE__
);
2664 expected
[0] = 0xFEDCBA98, expected
[1] = 0xFEDCBA98;
2665 expected
[2] = 0xFEDCBA98, expected
[3] = 0xFEDCBA98;
2666 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2667 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2669 expected
[0] = 0x42441000, expected
[1] = 0x00000000;
2670 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2671 legacy_expected
[0] = 0x00543210, legacy_expected
[1] = 0x00000000;
2672 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2673 todo_wine
check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2674 0, 0, 1, 1, 0, 0, 2, 2, expected
, legacy_expected
, __LINE__
);
2676 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2677 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2678 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2679 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2681 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2682 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2683 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2684 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2686 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2687 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2688 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2689 1, 1, -2, -2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2691 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2692 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2693 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2694 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2696 SelectObject(hdcDst
, oldDst
);
2697 DeleteObject(bmpDst
);
2699 /* Bottom up destination tests */
2700 biDst
.bmiHeader
.biHeight
= 2;
2701 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2703 oldDst
= SelectObject(hdcDst
, bmpDst
);
2705 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2706 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2707 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2708 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2711 SelectObject(hdcDst
, oldDst
);
2712 DeleteObject(bmpDst
);
2715 DeleteDC(hdcScreen
);
2718 static void test_GdiAlphaBlend(void)
2720 /* test out-of-bound parameters for GdiAlphaBlend */
2733 BLENDFUNCTION blend
;
2735 if (!pGdiAlphaBlend
)
2737 win_skip("GdiAlphaBlend() is not implemented\n");
2741 hdcNull
= GetDC(NULL
);
2742 hdcDst
= CreateCompatibleDC(hdcNull
);
2743 bmpDst
= CreateCompatibleBitmap(hdcNull
, 100, 100);
2744 hdcSrc
= CreateCompatibleDC(hdcNull
);
2746 memset(&bmi
, 0, sizeof(bmi
)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2747 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
2748 bmi
.bmiHeader
.biHeight
= 20;
2749 bmi
.bmiHeader
.biWidth
= 20;
2750 bmi
.bmiHeader
.biBitCount
= 32;
2751 bmi
.bmiHeader
.biPlanes
= 1;
2752 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2753 bmpSrc
= CreateDIBSection(hdcDst
, &bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2754 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2756 oldDst
= SelectObject(hdcDst
, bmpDst
);
2757 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2759 blend
.BlendOp
= AC_SRC_OVER
;
2760 blend
.BlendFlags
= 0;
2761 blend
.SourceConstantAlpha
= 128;
2762 blend
.AlphaFormat
= 0;
2764 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, 0, 20, 20, blend
), TRUE
, BOOL
, "%d");
2765 SetLastError(0xdeadbeef);
2766 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2767 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER
, int, "%d");
2768 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), FALSE
, BOOL
, "%d");
2769 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 15, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2770 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2771 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2773 SetWindowOrgEx(hdcSrc
, -10, -10, NULL
);
2774 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), TRUE
, BOOL
, "%d");
2775 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), TRUE
, BOOL
, "%d");
2776 SetMapMode(hdcSrc
, MM_ANISOTROPIC
);
2777 ScaleWindowExtEx(hdcSrc
, 10, 1, 10, 1, NULL
);
2778 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 30, 30, blend
), TRUE
, BOOL
, "%d");
2779 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 30, 30, blend
), TRUE
, BOOL
, "%d");
2781 SetLastError(0xdeadbeef);
2782 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, NULL
, 0, 0, 20, 20, blend
), FALSE
, BOOL
, "%d");
2783 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2785 SelectObject(hdcDst
, oldDst
);
2786 SelectObject(hdcSrc
, oldSrc
);
2787 DeleteObject(bmpSrc
);
2788 DeleteObject(bmpDst
);
2792 ReleaseDC(NULL
, hdcNull
);
2796 static void test_clipping(void)
2806 HDC hdcDst
= CreateCompatibleDC( NULL
);
2807 HDC hdcSrc
= CreateCompatibleDC( NULL
);
2809 BITMAPINFO bmpinfo
={{0}};
2810 bmpinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2811 bmpinfo
.bmiHeader
.biWidth
= 100;
2812 bmpinfo
.bmiHeader
.biHeight
= 100;
2813 bmpinfo
.bmiHeader
.biPlanes
= 1;
2814 bmpinfo
.bmiHeader
.biBitCount
= GetDeviceCaps( hdcDst
, BITSPIXEL
);
2815 bmpinfo
.bmiHeader
.biCompression
= BI_RGB
;
2817 bmpDst
= CreateDIBSection( hdcDst
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2818 ok(bmpDst
!= NULL
, "Couldn't create destination bitmap\n");
2819 oldDst
= SelectObject( hdcDst
, bmpDst
);
2821 bmpSrc
= CreateDIBSection( hdcSrc
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2822 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2823 oldSrc
= SelectObject( hdcSrc
, bmpSrc
);
2825 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 100, 100, SRCCOPY
);
2826 ok(result
, "BitBlt failed\n");
2828 hRgn
= CreateRectRgn( 0,0,0,0 );
2829 SelectClipRgn( hdcDst
, hRgn
);
2831 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 0, 0, SRCCOPY
);
2832 ok(result
, "BitBlt failed\n");
2834 DeleteObject( bmpDst
);
2835 DeleteObject( bmpSrc
);
2836 DeleteObject( hRgn
);
2844 is_win9x
= GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
) == 0;
2846 hdll
= GetModuleHandle("gdi32.dll");
2847 pGdiAlphaBlend
= (void*)GetProcAddress(hdll
, "GdiAlphaBlend");
2849 test_createdibitmap();
2851 test_mono_dibsection();
2854 test_GetDIBits_selected_DIB(1);
2855 test_GetDIBits_selected_DIB(4);
2856 test_GetDIBits_selected_DIB(8);
2857 test_GetDIBits_selected_DDB(TRUE
);
2858 test_GetDIBits_selected_DDB(FALSE
);
2860 test_GetDIBits_BI_BITFIELDS();
2861 test_select_object();
2862 test_CreateBitmap();
2865 test_StretchDIBits();
2866 test_GdiAlphaBlend();
2867 test_bitmapinfoheadersize();