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
== abs(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
== abs(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
, "%d != %d\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
367 ok(ds
.dsBmih
.biHeight
== abs(bmih
->biHeight
) ||
368 broken(ds
.dsBmih
.biHeight
== bmih
->biHeight
), /* Win9x/WinMe */
369 "%d != %d\n", ds
.dsBmih
.biHeight
, abs(bmih
->biHeight
));
370 ok(ds
.dsBmih
.biPlanes
== bmih
->biPlanes
, "%u != %u\n", ds
.dsBmih
.biPlanes
, bmih
->biPlanes
);
371 ok(ds
.dsBmih
.biBitCount
== bmih
->biBitCount
, "%u != %u\n", ds
.dsBmih
.biBitCount
, bmih
->biBitCount
);
372 ok(ds
.dsBmih
.biCompression
== bmih
->biCompression
, "%u != %u\n", ds
.dsBmih
.biCompression
, bmih
->biCompression
);
373 ok(ds
.dsBmih
.biSizeImage
== bmih
->biSizeImage
, "%u != %u\n", ds
.dsBmih
.biSizeImage
, bmih
->biSizeImage
);
374 ok(ds
.dsBmih
.biXPelsPerMeter
== bmih
->biXPelsPerMeter
, "%d != %d\n", ds
.dsBmih
.biXPelsPerMeter
, bmih
->biXPelsPerMeter
);
375 ok(ds
.dsBmih
.biYPelsPerMeter
== bmih
->biYPelsPerMeter
, "%d != %d\n", ds
.dsBmih
.biYPelsPerMeter
, bmih
->biYPelsPerMeter
);
377 memset(&ds
, 0xAA, sizeof(ds
));
378 ret
= GetObject(hbm
, sizeof(ds
) - 4, &ds
);
379 ok(ret
== sizeof(ds
.dsBm
) || broken(ret
== (sizeof(ds
) - 4) /* Win9x */), "wrong size %d\n", ret
);
380 ok(ds
.dsBm
.bmWidth
== bmih
->biWidth
, "%d != %d\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
381 ok(ds
.dsBm
.bmHeight
== abs(bmih
->biHeight
), "%d != %d\n", ds
.dsBmih
.biHeight
, abs(bmih
->biHeight
));
382 ok(ds
.dsBm
.bmBits
== bits
, "%p != %p\n", ds
.dsBm
.bmBits
, bits
);
384 ret
= GetObject(hbm
, 0, &ds
);
385 ok(ret
== 0, "%d != 0\n", ret
);
387 ret
= GetObject(hbm
, 1, &ds
);
388 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
391 #define test_color_todo(got, exp, txt, todo) \
392 if (!todo && got != exp && screen_depth < 24) { \
393 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
394 screen_depth, (UINT)got, (UINT)exp); \
396 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
397 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
399 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
402 c = SetPixel(hdc, 0, 0, color); \
403 if (!is_win9x) { test_color_todo(c, exp, SetPixel, todo_setp); } \
404 c = GetPixel(hdc, 0, 0); \
405 test_color_todo(c, exp, GetPixel, todo_getp); \
408 static void test_dib_bits_access( HBITMAP hdib
, void *bits
)
410 MEMORY_BASIC_INFORMATION info
;
411 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
413 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
415 char filename
[MAX_PATH
];
420 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
421 "VirtualQuery failed\n");
422 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
423 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
424 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
425 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
426 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
427 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
429 memset( pbmi
, 0, sizeof(bmibuf
) );
430 memset( data
, 0xcc, sizeof(data
) );
431 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
432 pbmi
->bmiHeader
.biHeight
= 16;
433 pbmi
->bmiHeader
.biWidth
= 16;
434 pbmi
->bmiHeader
.biBitCount
= 32;
435 pbmi
->bmiHeader
.biPlanes
= 1;
436 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
440 ret
= SetDIBits( hdc
, hdib
, 0, 16, data
, pbmi
, DIB_RGB_COLORS
);
442 broken(ret
== 0), /* win9x */
443 "SetDIBits failed: expected 16 got %d\n", ret
);
447 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
448 "VirtualQuery failed\n");
449 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
450 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
451 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
452 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
453 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
454 /* it has been protected now */
455 todo_wine
ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
457 /* try writing protected bits to a file */
459 GetTempFileNameA( ".", "dib", 0, filename
);
460 file
= CreateFileA( filename
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
461 CREATE_ALWAYS
, 0, 0 );
462 ok( file
!= INVALID_HANDLE_VALUE
, "failed to open %s error %u\n", filename
, GetLastError() );
463 ret
= WriteFile( file
, bits
, 8192, &written
, NULL
);
464 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
465 if (ret
) ok( written
== 8192, "only wrote %u bytes\n", written
);
467 DeleteFileA( filename
);
470 static void test_dibsections(void)
472 HDC hdc
, hdcmem
, hdcmem2
;
473 HBITMAP hdib
, oldbm
, hdib2
, oldbm2
;
474 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
475 char bcibuf
[sizeof(BITMAPCOREINFO
) + 256 * sizeof(RGBTRIPLE
)];
476 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
477 BITMAPCOREINFO
*pbci
= (BITMAPCOREINFO
*)bcibuf
;
483 char logpalbuf
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
484 LOGPALETTE
*plogpal
= (LOGPALETTE
*)logpalbuf
;
487 HPALETTE hpal
, oldpal
;
492 MEMORY_BASIC_INFORMATION info
;
495 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
497 memset(pbmi
, 0, sizeof(bmibuf
));
498 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
499 pbmi
->bmiHeader
.biHeight
= 100;
500 pbmi
->bmiHeader
.biWidth
= 512;
501 pbmi
->bmiHeader
.biBitCount
= 24;
502 pbmi
->bmiHeader
.biPlanes
= 1;
503 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
505 SetLastError(0xdeadbeef);
507 /* invalid pointer for BITMAPINFO
508 (*bits should be NULL on error) */
509 bits
= (BYTE
*)0xdeadbeef;
510 hdib
= CreateDIBSection(hdc
, NULL
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
511 ok(hdib
== NULL
&& bits
== NULL
, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
513 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
514 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
515 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
516 ok(dibsec
.dsBm
.bmBits
== bits
, "dibsec.dsBits %p != bits %p\n", dibsec
.dsBm
.bmBits
, bits
);
518 /* test the DIB memory */
519 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
520 "VirtualQuery failed\n");
521 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
522 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
523 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
524 ok(info
.RegionSize
== 0x26000, "0x%lx != 0x26000\n", info
.RegionSize
);
525 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
526 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
527 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
529 test_dib_bits_access( hdib
, bits
);
531 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
534 /* Test a top-down DIB. */
535 pbmi
->bmiHeader
.biHeight
= -100;
536 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
537 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
538 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
541 pbmi
->bmiHeader
.biHeight
= 100;
542 pbmi
->bmiHeader
.biBitCount
= 8;
543 pbmi
->bmiHeader
.biCompression
= BI_RLE8
;
544 SetLastError(0xdeadbeef);
545 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
546 ok(hdib
== NULL
, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
547 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
549 pbmi
->bmiHeader
.biBitCount
= 16;
550 pbmi
->bmiHeader
.biCompression
= BI_BITFIELDS
;
551 ((PDWORD
)pbmi
->bmiColors
)[0] = 0xf800;
552 ((PDWORD
)pbmi
->bmiColors
)[1] = 0x07e0;
553 ((PDWORD
)pbmi
->bmiColors
)[2] = 0x001f;
554 SetLastError(0xdeadbeef);
555 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
556 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
558 /* test the DIB memory */
559 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
560 "VirtualQuery failed\n");
561 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
562 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
563 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
564 ok(info
.RegionSize
== 0x19000, "0x%lx != 0x19000\n", info
.RegionSize
);
565 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
566 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
567 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
569 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
572 memset(pbmi
, 0, sizeof(bmibuf
));
573 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
574 pbmi
->bmiHeader
.biHeight
= 16;
575 pbmi
->bmiHeader
.biWidth
= 16;
576 pbmi
->bmiHeader
.biBitCount
= 1;
577 pbmi
->bmiHeader
.biPlanes
= 1;
578 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
579 pbmi
->bmiColors
[0].rgbRed
= 0xff;
580 pbmi
->bmiColors
[0].rgbGreen
= 0;
581 pbmi
->bmiColors
[0].rgbBlue
= 0;
582 pbmi
->bmiColors
[1].rgbRed
= 0;
583 pbmi
->bmiColors
[1].rgbGreen
= 0;
584 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
586 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
587 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
588 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
589 ok(dibsec
.dsBmih
.biClrUsed
== 2,
590 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
592 /* Test if the old BITMAPCOREINFO structure is supported */
594 pbci
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
595 pbci
->bmciHeader
.bcBitCount
= 0;
598 ret
= GetDIBits(hdc
, hdib
, 0, 16, NULL
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
599 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
600 ok((pbci
->bmciHeader
.bcWidth
== 16) && (pbci
->bmciHeader
.bcHeight
== 16)
601 && (pbci
->bmciHeader
.bcBitCount
== 1) && (pbci
->bmciHeader
.bcPlanes
== 1),
602 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
604 ret
= GetDIBits(hdc
, hdib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
605 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
606 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
607 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
608 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
609 "The color table has not been translated to the old BITMAPCOREINFO format\n");
611 hcoredib
= CreateDIBSection(hdc
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
612 ok(hcoredib
!= NULL
, "CreateDIBSection failed with a BITMAPCOREINFO\n");
614 ZeroMemory(pbci
->bmciColors
, 256 * sizeof(RGBTRIPLE
));
615 ret
= GetDIBits(hdc
, hcoredib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
616 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
617 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
618 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
619 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
620 "The color table has not been translated to the old BITMAPCOREINFO format\n");
622 DeleteObject(hcoredib
);
625 hdcmem
= CreateCompatibleDC(hdc
);
626 oldbm
= SelectObject(hdcmem
, hdib
);
628 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
629 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
630 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
631 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
632 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
633 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
635 c0
= RGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
, pbmi
->bmiColors
[0].rgbBlue
);
636 c1
= RGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
, pbmi
->bmiColors
[1].rgbBlue
);
638 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
639 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
640 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
641 test_color(hdcmem
, PALETTEINDEX(0), c0
, 1, 1);
642 test_color(hdcmem
, PALETTEINDEX(1), c0
, 1, 1);
643 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
644 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
,
645 pbmi
->bmiColors
[0].rgbBlue
), c0
, 1, 1);
646 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
,
647 pbmi
->bmiColors
[1].rgbBlue
), c1
, 1, 1);
648 test_color(hdcmem
, PALETTERGB(0, 0, 0), c0
, 1, 1);
649 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
650 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c1
, 1, 1);
652 SelectObject(hdcmem
, oldbm
);
655 pbmi
->bmiColors
[0].rgbRed
= 0xff;
656 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
657 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
658 pbmi
->bmiColors
[1].rgbRed
= 0;
659 pbmi
->bmiColors
[1].rgbGreen
= 0;
660 pbmi
->bmiColors
[1].rgbBlue
= 0;
662 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
663 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
665 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
667 oldbm
= SelectObject(hdcmem
, hdib
);
669 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
670 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
671 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
672 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
673 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
674 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
676 SelectObject(hdcmem
, oldbm
);
677 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
680 pbmi
->bmiHeader
.biBitCount
= 4;
681 for (i
= 0; i
< 16; i
++) {
682 pbmi
->bmiColors
[i
].rgbRed
= i
;
683 pbmi
->bmiColors
[i
].rgbGreen
= 16-i
;
684 pbmi
->bmiColors
[i
].rgbBlue
= 0;
686 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
687 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
688 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
689 ok(dibsec
.dsBmih
.biClrUsed
== 16,
690 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 16);
691 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
694 pbmi
->bmiHeader
.biBitCount
= 8;
696 for (i
= 0; i
< 128; i
++) {
697 pbmi
->bmiColors
[i
].rgbRed
= 255 - i
* 2;
698 pbmi
->bmiColors
[i
].rgbGreen
= i
* 2;
699 pbmi
->bmiColors
[i
].rgbBlue
= 0;
700 pbmi
->bmiColors
[255 - i
].rgbRed
= 0;
701 pbmi
->bmiColors
[255 - i
].rgbGreen
= i
* 2;
702 pbmi
->bmiColors
[255 - i
].rgbBlue
= 255 - i
* 2;
704 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
705 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
706 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
707 ok(dibsec
.dsBmih
.biClrUsed
== 256,
708 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
710 oldbm
= SelectObject(hdcmem
, hdib
);
712 for (i
= 0; i
< 256; i
++) {
713 test_color(hdcmem
, DIBINDEX(i
),
714 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
715 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
),
716 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
719 SelectObject(hdcmem
, oldbm
);
720 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
723 pbmi
->bmiHeader
.biBitCount
= 1;
725 /* Now create a palette and a palette indexed dib section */
726 memset(plogpal
, 0, sizeof(logpalbuf
));
727 plogpal
->palVersion
= 0x300;
728 plogpal
->palNumEntries
= 2;
729 plogpal
->palPalEntry
[0].peRed
= 0xff;
730 plogpal
->palPalEntry
[0].peBlue
= 0xff;
731 plogpal
->palPalEntry
[1].peGreen
= 0xff;
733 index
= (WORD
*)pbmi
->bmiColors
;
736 hpal
= CreatePalette(plogpal
);
737 ok(hpal
!= NULL
, "CreatePalette failed\n");
738 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
739 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
740 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
741 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
742 ok(dibsec
.dsBmih
.biClrUsed
== 2 ||
743 broken(dibsec
.dsBmih
.biClrUsed
== 0), /* win9x */
744 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
746 /* The colour table has already been grabbed from the dc, so we select back the
749 SelectPalette(hdc
, oldpal
, TRUE
);
750 oldbm
= SelectObject(hdcmem
, hdib
);
751 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
753 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
754 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
755 ok(rgb
[0].rgbRed
== 0xff && rgb
[0].rgbBlue
== 0xff && rgb
[0].rgbGreen
== 0 &&
756 rgb
[1].rgbRed
== 0 && rgb
[1].rgbBlue
== 0 && rgb
[1].rgbGreen
== 0xff,
757 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
758 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
759 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
761 c0
= RGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
, plogpal
->palPalEntry
[0].peBlue
);
762 c1
= RGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
, plogpal
->palPalEntry
[1].peBlue
);
764 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
765 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
766 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
767 test_color(hdcmem
, PALETTEINDEX(0), c0
, 0, 1);
768 test_color(hdcmem
, PALETTEINDEX(1), c1
, 0, 1);
769 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
770 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
,
771 plogpal
->palPalEntry
[0].peBlue
), c0
, 1, 1);
772 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
,
773 plogpal
->palPalEntry
[1].peBlue
), c1
, 1, 1);
774 test_color(hdcmem
, PALETTERGB(0, 0, 0), c1
, 1, 1);
775 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
776 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c0
, 1, 1);
777 test_color(hdcmem
, PALETTERGB(0, 1, 0), c1
, 1, 1);
778 test_color(hdcmem
, PALETTERGB(0x3f, 0, 0x3f), c1
, 1, 1);
779 test_color(hdcmem
, PALETTERGB(0x40, 0, 0x40), c0
, 1, 1);
781 /* Bottom and 2nd row from top green, everything else magenta */
782 bits
[0] = bits
[1] = 0xff;
783 bits
[13 * 4] = bits
[13*4 + 1] = 0xff;
785 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
787 pbmi
->bmiHeader
.biBitCount
= 32;
789 hdib2
= CreateDIBSection(NULL
, pbmi
, DIB_RGB_COLORS
, (void **)&bits32
, NULL
, 0);
790 ok(hdib2
!= NULL
, "CreateDIBSection failed\n");
791 hdcmem2
= CreateCompatibleDC(hdc
);
792 oldbm2
= SelectObject(hdcmem2
, hdib2
);
794 BitBlt(hdcmem2
, 0, 0, 16,16, hdcmem
, 0, 0, SRCCOPY
);
796 ok(bits32
[0] == 0xff00, "lower left pixel is %08x\n", bits32
[0]);
797 ok(bits32
[17] == 0xff00ff ||
798 broken(bits32
[17] == 0x00ff00), /* Intermittent on Win9x/ME */
799 "bottom but one, left pixel is %08x\n", bits32
[17]);
801 SelectObject(hdcmem2
, oldbm2
);
802 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
805 SelectObject(hdcmem
, oldbm
);
806 SelectObject(hdcmem
, oldpal
);
811 pbmi
->bmiHeader
.biBitCount
= 8;
813 memset(plogpal
, 0, sizeof(logpalbuf
));
814 plogpal
->palVersion
= 0x300;
815 plogpal
->palNumEntries
= 256;
817 for (i
= 0; i
< 128; i
++) {
818 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
819 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
820 plogpal
->palPalEntry
[i
].peGreen
= 0;
821 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
822 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
823 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
826 index
= (WORD
*)pbmi
->bmiColors
;
827 for (i
= 0; i
< 256; i
++) {
831 hpal
= CreatePalette(plogpal
);
832 ok(hpal
!= NULL
, "CreatePalette failed\n");
833 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
834 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
835 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
836 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
837 ok(dibsec
.dsBmih
.biClrUsed
== 256 ||
838 broken(dibsec
.dsBmih
.biClrUsed
== 0), /* win9x */
839 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
841 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
843 SelectPalette(hdc
, oldpal
, TRUE
);
844 oldbm
= SelectObject(hdcmem
, hdib
);
845 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
847 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
848 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
849 for (i
= 0; i
< 256; i
++) {
850 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
851 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
852 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
853 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
854 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
857 for (i
= 0; i
< 256; i
++) {
858 test_color(hdcmem
, DIBINDEX(i
),
859 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
860 test_color(hdcmem
, PALETTEINDEX(i
),
861 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
862 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
863 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
866 SelectPalette(hdcmem
, oldpal
, TRUE
);
867 SelectObject(hdcmem
, oldbm
);
876 static void test_mono_dibsection(void)
879 HBITMAP old_bm
, mono_ds
;
880 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
881 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
888 memdc
= CreateCompatibleDC(hdc
);
890 memset(pbmi
, 0, sizeof(bmibuf
));
891 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
892 pbmi
->bmiHeader
.biHeight
= 10;
893 pbmi
->bmiHeader
.biWidth
= 10;
894 pbmi
->bmiHeader
.biBitCount
= 1;
895 pbmi
->bmiHeader
.biPlanes
= 1;
896 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
897 pbmi
->bmiColors
[0].rgbRed
= 0xff;
898 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
899 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
900 pbmi
->bmiColors
[1].rgbRed
= 0x0;
901 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
902 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
905 * First dib section is 'inverted' ie color[0] is white, color[1] is black
908 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
909 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
910 old_bm
= SelectObject(memdc
, mono_ds
);
912 /* black border, white interior */
913 Rectangle(memdc
, 0, 0, 10, 10);
914 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
915 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
917 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
919 memset(bits
, 0, sizeof(bits
));
922 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
923 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
925 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
927 pbmi
->bmiColors
[0].rgbRed
= 0x0;
928 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
929 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
930 pbmi
->bmiColors
[1].rgbRed
= 0xff;
931 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
932 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
934 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
935 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
937 SelectObject(memdc
, old_bm
);
938 DeleteObject(mono_ds
);
941 * Next dib section is 'normal' ie color[0] is black, color[1] is white
944 pbmi
->bmiColors
[0].rgbRed
= 0x0;
945 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
946 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
947 pbmi
->bmiColors
[1].rgbRed
= 0xff;
948 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
949 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
951 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
952 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
953 old_bm
= SelectObject(memdc
, mono_ds
);
955 /* black border, white interior */
956 Rectangle(memdc
, 0, 0, 10, 10);
957 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
958 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
960 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
962 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
963 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
965 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
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;
974 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
975 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
978 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
981 pbmi
->bmiColors
[0].rgbRed
= 0xff;
982 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
983 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
984 pbmi
->bmiColors
[1].rgbRed
= 0x0;
985 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
986 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
987 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
988 ok(num
== 2, "num = %d\n", num
);
990 /* black border, white interior */
991 Rectangle(memdc
, 0, 0, 10, 10);
993 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
994 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
996 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
998 memset(bits
, 0, sizeof(bits
));
1001 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1002 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1004 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1006 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1007 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1008 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1009 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1010 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1011 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1013 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1014 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1016 SelectObject(memdc
, old_bm
);
1017 DeleteObject(mono_ds
);
1020 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1023 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1024 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1025 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1026 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
1027 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1028 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1030 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
1031 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
1032 old_bm
= SelectObject(memdc
, mono_ds
);
1034 /* black border, white interior */
1035 Rectangle(memdc
, 0, 0, 10, 10);
1036 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
1037 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
1039 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1041 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1042 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1043 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1044 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1045 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1046 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1048 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1049 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1051 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1053 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1054 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
1055 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
1056 pbmi
->bmiColors
[1].rgbRed
= 0x0;
1057 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1058 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1060 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1061 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1063 SelectObject(memdc
, old_bm
);
1064 DeleteObject(mono_ds
);
1070 static void test_bitmap(void)
1072 char buf
[256], buf_cmp
[256];
1073 HBITMAP hbmp
, hbmp_old
;
1079 hdc
= CreateCompatibleDC(0);
1082 SetLastError(0xdeadbeef);
1083 hbmp
= CreateBitmap(0x7ffffff, 1, 1, 1, NULL
);
1086 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1087 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1088 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1093 SetLastError(0xdeadbeef);
1094 hbmp
= CreateBitmap(0x7ffffff, 9, 1, 1, NULL
);
1097 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1098 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1099 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1104 SetLastError(0xdeadbeef);
1105 hbmp
= CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL
);
1106 ok(!hbmp
|| broken(hbmp
!= NULL
/* Win9x */), "CreateBitmap should fail\n");
1108 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1109 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1113 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
1114 assert(hbmp
!= NULL
);
1116 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1117 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1119 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1120 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1121 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1122 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1123 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1124 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1125 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1127 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
1128 assert(sizeof(buf
) == sizeof(buf_cmp
));
1130 ret
= GetBitmapBits(hbmp
, 0, NULL
);
1131 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
|| broken(ret
== 0 /* Win9x */),
1132 "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1134 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
1135 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
1137 memset(buf
, 0xAA, sizeof(buf
));
1138 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1139 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1140 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1141 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1142 "buffers do not match\n");
1144 hbmp_old
= SelectObject(hdc
, hbmp
);
1146 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1147 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1149 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1150 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1151 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1152 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1153 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1154 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1155 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1157 memset(buf
, 0xAA, sizeof(buf
));
1158 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1159 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1160 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)) ||
1161 broken(memcmp(buf
, buf_cmp
, sizeof(buf
))), /* win9x doesn't init the bitmap bits */
1162 "buffers do not match\n");
1164 hbmp_old
= SelectObject(hdc
, hbmp_old
);
1165 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
1167 /* test various buffer sizes for GetObject */
1168 ret
= GetObject(hbmp
, sizeof(*bma
) * 2, bma
);
1169 ok(ret
== sizeof(*bma
) || broken(ret
== sizeof(*bma
) * 2 /* Win9x */), "wrong size %d\n", ret
);
1171 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
1172 ok(ret
== 0 || broken(ret
== sizeof(bm
) / 2 /* Win9x */), "%d != 0\n", ret
);
1174 ret
= GetObject(hbmp
, 0, &bm
);
1175 ok(ret
== 0, "%d != 0\n", ret
);
1177 ret
= GetObject(hbmp
, 1, &bm
);
1178 ok(ret
== 0 || broken(ret
== 1 /* Win9x */), "%d != 0\n", ret
);
1184 static void test_bmBits(void)
1190 memset(bits
, 0, sizeof(bits
));
1191 hbmp
= CreateBitmap(2, 2, 1, 4, bits
);
1192 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
1194 memset(&bmp
, 0xFF, sizeof(bmp
));
1195 ok(GetObject(hbmp
, sizeof(bmp
), &bmp
) == sizeof(bmp
),
1196 "GetObject failed or returned a wrong structure size\n");
1197 ok(!bmp
.bmBits
, "bmBits must be NULL for device-dependent bitmaps\n");
1202 static void test_GetDIBits_selected_DIB(UINT bpp
)
1216 /* Create a DIB section with a color table */
1218 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1219 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1223 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1225 /* Choose width and height such that the row length (in bytes)
1226 is a multiple of 4 (makes things easier) */
1227 info
->bmiHeader
.biWidth
= 32;
1228 info
->bmiHeader
.biHeight
= 32;
1229 info
->bmiHeader
.biPlanes
= 1;
1230 info
->bmiHeader
.biBitCount
= bpp
;
1231 info
->bmiHeader
.biCompression
= BI_RGB
;
1233 for (i
=0; i
< (1u << bpp
); i
++)
1235 BYTE c
= i
* (1 << (8 - bpp
));
1236 info
->bmiColors
[i
].rgbRed
= c
;
1237 info
->bmiColors
[i
].rgbGreen
= c
;
1238 info
->bmiColors
[i
].rgbBlue
= c
;
1239 info
->bmiColors
[i
].rgbReserved
= 0;
1242 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1244 dib_size
= bpp
* (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1246 /* Set the bits of the DIB section */
1247 for (i
=0; i
< dib_size
; i
++)
1249 ((BYTE
*)bits
)[i
] = i
% 256;
1252 /* Select the DIB into a DC */
1253 dib_dc
= CreateCompatibleDC(NULL
);
1254 old_bmp
= SelectObject(dib_dc
, dib
);
1255 dc
= CreateCompatibleDC(NULL
);
1256 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dib_size
);
1259 /* Copy the DIB attributes but not the color table */
1260 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1262 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1263 ok(res
, "GetDIBits failed\n");
1265 /* Compare the color table and the bits */
1266 equalContents
= TRUE
;
1267 for (i
=0; i
< (1u << bpp
); i
++)
1269 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1270 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1271 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1272 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1274 equalContents
= FALSE
;
1278 ok(equalContents
, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1280 equalContents
= TRUE
;
1281 for (i
=0; i
< dib_size
/ sizeof(DWORD
); i
++)
1283 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1285 equalContents
= FALSE
;
1289 ok(equalContents
, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp
);
1291 HeapFree(GetProcessHeap(), 0, bits2
);
1294 SelectObject(dib_dc
, old_bmp
);
1298 HeapFree(GetProcessHeap(), 0, info2
);
1299 HeapFree(GetProcessHeap(), 0, info
);
1302 static void test_GetDIBits_selected_DDB(BOOL monochrome
)
1317 width
= height
= 16;
1319 /* Create a DDB (device-dependent bitmap) */
1323 ddb
= CreateBitmap(width
, height
, 1, 1, NULL
);
1327 HDC screen_dc
= GetDC(NULL
);
1328 bpp
= GetDeviceCaps(screen_dc
, BITSPIXEL
) * GetDeviceCaps(screen_dc
, PLANES
);
1329 ddb
= CreateCompatibleBitmap(screen_dc
, width
, height
);
1330 ReleaseDC(NULL
, screen_dc
);
1333 /* Set the pixels */
1334 ddb_dc
= CreateCompatibleDC(NULL
);
1335 old_bmp
= SelectObject(ddb_dc
, ddb
);
1336 for (i
= 0; i
< width
; i
++)
1338 for (j
=0; j
< height
; j
++)
1340 BYTE c
= (i
* width
+ j
) % 256;
1341 SetPixelV(ddb_dc
, i
, j
, RGB(c
, c
, c
));
1344 SelectObject(ddb_dc
, old_bmp
);
1346 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1347 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1351 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1352 info
->bmiHeader
.biWidth
= width
;
1353 info
->bmiHeader
.biHeight
= height
;
1354 info
->bmiHeader
.biPlanes
= 1;
1355 info
->bmiHeader
.biBitCount
= bpp
;
1356 info
->bmiHeader
.biCompression
= BI_RGB
;
1358 dc
= CreateCompatibleDC(NULL
);
1360 /* Fill in biSizeImage */
1361 GetDIBits(dc
, ddb
, 0, height
, NULL
, info
, DIB_RGB_COLORS
);
1362 ok(info
->bmiHeader
.biSizeImage
!= 0, "GetDIBits failed to get the DIB attributes\n");
1364 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1365 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1370 res
= GetDIBits(dc
, ddb
, 0, height
, bits
, info
, DIB_RGB_COLORS
);
1371 ok(res
, "GetDIBits failed\n");
1373 /* Copy the DIB attributes but not the color table */
1374 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1376 /* Select the DDB into another DC */
1377 old_bmp
= SelectObject(ddb_dc
, ddb
);
1380 res
= GetDIBits(dc
, ddb
, 0, height
, bits2
, info2
, DIB_RGB_COLORS
);
1381 ok(res
, "GetDIBits failed\n");
1383 /* Compare the color table and the bits */
1386 equalContents
= TRUE
;
1387 for (i
=0; i
< (1u << bpp
); i
++)
1389 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1390 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1391 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1392 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1394 equalContents
= FALSE
;
1398 ok(equalContents
, "GetDIBits with DDB selected in DC: Got a different color table\n");
1401 equalContents
= TRUE
;
1402 for (i
=0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++)
1404 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1406 equalContents
= FALSE
;
1409 ok(equalContents
, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1411 /* Test the palette */
1412 equalContents
= TRUE
;
1413 if (info2
->bmiHeader
.biBitCount
<= 8)
1415 WORD
*colors
= (WORD
*)info2
->bmiColors
;
1417 /* Get the palette indices */
1418 res
= GetDIBits(dc
, ddb
, 0, 0, NULL
, info2
, DIB_PAL_COLORS
);
1419 if (res
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
) /* Win9x */
1420 res
= GetDIBits(dc
, ddb
, 0, height
, NULL
, info2
, DIB_PAL_COLORS
);
1421 ok(res
, "GetDIBits failed\n");
1423 for (i
=0;i
< 1 << info
->bmiHeader
.biSizeImage
; i
++)
1427 equalContents
= FALSE
;
1433 ok(equalContents
, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1435 HeapFree(GetProcessHeap(), 0, bits2
);
1436 HeapFree(GetProcessHeap(), 0, bits
);
1439 SelectObject(ddb_dc
, old_bmp
);
1443 HeapFree(GetProcessHeap(), 0, info2
);
1444 HeapFree(GetProcessHeap(), 0, info
);
1447 static void test_GetDIBits(void)
1449 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1450 static const BYTE bmp_bits_1
[16 * 2] =
1452 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1453 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1454 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1455 0xff,0xff, 0,0, 0xff,0xff, 0,0
1457 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1458 static const BYTE dib_bits_1
[16 * 4] =
1460 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1461 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1462 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1463 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1465 static const BYTE dib_bits_1_9x
[16 * 4] =
1467 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1468 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1469 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa,
1470 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa, 0,0,0xaa,0xaa, 0xff,0xff,0xaa,0xaa
1472 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1473 static const BYTE bmp_bits_24
[16 * 16*3] =
1475 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1476 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1477 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1478 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1479 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1480 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1481 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1482 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1483 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1484 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1485 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1486 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1487 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1488 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1489 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1490 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1491 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1492 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1493 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1494 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1495 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1496 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1497 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1498 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1499 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1500 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1501 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1502 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1503 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1504 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
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
1508 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1509 static const BYTE dib_bits_24
[16 * 16*3] =
1511 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1512 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1513 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1514 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1515 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1516 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1517 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1518 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1519 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1520 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1521 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1522 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1523 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1524 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1525 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1526 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1527 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1528 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1529 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1530 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1531 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1532 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1533 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1534 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1535 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1536 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1537 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1538 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1539 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1540 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1541 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1542 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1547 int i
, bytes
, lines
;
1549 char bi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1550 BITMAPINFO
*bi
= (BITMAPINFO
*)bi_buf
;
1554 /* 1-bit source bitmap data */
1555 hbmp
= CreateBitmap(16, 16, 1, 1, bmp_bits_1
);
1556 ok(hbmp
!= 0, "CreateBitmap failed\n");
1558 memset(&bm
, 0xAA, sizeof(bm
));
1559 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1560 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1561 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1562 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1563 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1564 ok(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1565 ok(bm
.bmPlanes
== 1, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1566 ok(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1567 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1569 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1570 ok(bytes
== sizeof(bmp_bits_1
) || broken(bytes
== 0 /* Win9x */), "expected 16*2 got %d bytes\n", bytes
);
1571 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1572 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1573 ok(!memcmp(buf
, bmp_bits_1
, sizeof(bmp_bits_1
)), "bitmap bits don't match\n");
1575 /* retrieve 1-bit DIB data */
1576 memset(bi
, 0, sizeof(*bi
));
1577 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1578 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1579 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1580 bi
->bmiHeader
.biPlanes
= 1;
1581 bi
->bmiHeader
.biBitCount
= 1;
1582 bi
->bmiHeader
.biCompression
= BI_RGB
;
1583 bi
->bmiHeader
.biSizeImage
= 0;
1584 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1585 SetLastError(0xdeadbeef);
1586 lines
= GetDIBits(0, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1587 ok(lines
== 0, "GetDIBits copied %d lines with hdc = 0\n", lines
);
1588 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
1589 broken(GetLastError() == 0xdeadbeef), /* winnt */
1590 "wrong error %u\n", GetLastError());
1591 ok(bi
->bmiHeader
.biSizeImage
== 0, "expected 0, got %u\n", bi
->bmiHeader
.biSizeImage
);
1593 memset(buf
, 0xAA, sizeof(buf
));
1594 SetLastError(0xdeadbeef);
1595 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1596 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1597 lines
, bm
.bmHeight
, GetLastError());
1598 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1599 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1600 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1602 /* the color table consists of black and white */
1603 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1604 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1605 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1606 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1607 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1608 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1609 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1610 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1611 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1612 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1613 for (i
= 2; i
< 256; i
++)
1615 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1616 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1617 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1618 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1619 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1622 /* returned bits are DWORD aligned and upside down */
1623 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1624 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1625 "DIB bits don't match\n");
1627 /* Test the palette indices */
1628 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1629 SetLastError(0xdeadbeef);
1630 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1631 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1632 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1635 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1636 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1638 for (i
= 2; i
< 256; i
++)
1639 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[1]);
1641 /* retrieve 24-bit DIB data */
1642 memset(bi
, 0, sizeof(*bi
));
1643 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1644 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1645 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1646 bi
->bmiHeader
.biPlanes
= 1;
1647 bi
->bmiHeader
.biBitCount
= 24;
1648 bi
->bmiHeader
.biCompression
= BI_RGB
;
1649 bi
->bmiHeader
.biSizeImage
= 0;
1650 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1651 memset(buf
, 0xAA, sizeof(buf
));
1652 SetLastError(0xdeadbeef);
1653 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1654 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1655 lines
, bm
.bmHeight
, GetLastError());
1656 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1657 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1658 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1660 /* the color table doesn't exist for 24-bit images */
1661 for (i
= 0; i
< 256; i
++)
1663 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1664 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1665 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1666 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1667 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1670 /* returned bits are DWORD aligned and upside down */
1671 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1674 /* 24-bit source bitmap data */
1675 hbmp
= CreateCompatibleBitmap(hdc
, 16, 16);
1676 ok(hbmp
!= 0, "CreateBitmap failed\n");
1677 SetLastError(0xdeadbeef);
1678 bi
->bmiHeader
.biHeight
= -bm
.bmHeight
; /* indicate bottom-up data */
1679 lines
= SetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, bmp_bits_24
, bi
, DIB_RGB_COLORS
);
1680 ok(lines
== bm
.bmHeight
, "SetDIBits copied %d lines of %d, error %u\n",
1681 lines
, bm
.bmHeight
, GetLastError());
1683 memset(&bm
, 0xAA, sizeof(bm
));
1684 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1685 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1686 ok(bm
.bmType
== 0 ||
1687 broken(bm
.bmType
== 21072), /* win9x */
1688 "wrong bmType %d\n", bm
.bmType
);
1689 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1690 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1691 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1692 ok(bm
.bmPlanes
== GetDeviceCaps(hdc
, PLANES
), "wrong bmPlanes %u\n", bm
.bmPlanes
);
1693 ok(bm
.bmBitsPixel
== GetDeviceCaps(hdc
, BITSPIXEL
), "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1694 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1696 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1697 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
||
1698 broken(bytes
== 0), /* win9x */
1699 "expected %d got %d bytes\n", bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1700 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1701 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1702 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1704 /* retrieve 1-bit DIB data */
1705 memset(bi
, 0, sizeof(*bi
));
1706 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1707 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1708 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1709 bi
->bmiHeader
.biPlanes
= 1;
1710 bi
->bmiHeader
.biBitCount
= 1;
1711 bi
->bmiHeader
.biCompression
= BI_RGB
;
1712 bi
->bmiHeader
.biSizeImage
= 0;
1713 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1714 memset(buf
, 0xAA, sizeof(buf
));
1715 SetLastError(0xdeadbeef);
1716 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1717 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1718 lines
, bm
.bmHeight
, GetLastError());
1719 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
) ||
1720 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1721 "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1723 /* the color table consists of black and white */
1724 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1725 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1726 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1727 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1728 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1729 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1730 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1731 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1732 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1733 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1734 for (i
= 2; i
< 256; i
++)
1736 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1737 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1738 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1739 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1740 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1743 /* returned bits are DWORD aligned and upside down */
1745 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)) ||
1746 broken(!memcmp(buf
, dib_bits_1_9x
, sizeof(dib_bits_1_9x
))), /* Win9x, WinME */
1747 "DIB bits don't match\n");
1749 /* Test the palette indices */
1750 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1751 SetLastError(0xdeadbeef);
1752 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1753 if (lines
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1754 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1757 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1758 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1760 for (i
= 2; i
< 256; i
++)
1761 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[i
]);
1763 /* retrieve 24-bit DIB data */
1764 memset(bi
, 0, sizeof(*bi
));
1765 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1766 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1767 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1768 bi
->bmiHeader
.biPlanes
= 1;
1769 bi
->bmiHeader
.biBitCount
= 24;
1770 bi
->bmiHeader
.biCompression
= BI_RGB
;
1771 bi
->bmiHeader
.biSizeImage
= 0;
1772 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1773 memset(buf
, 0xAA, sizeof(buf
));
1774 SetLastError(0xdeadbeef);
1775 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1776 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1777 lines
, bm
.bmHeight
, GetLastError());
1778 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
) ||
1779 broken(bi
->bmiHeader
.biSizeImage
== 0), /* win9x */
1780 "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1782 /* the color table doesn't exist for 24-bit images */
1783 for (i
= 0; i
< 256; i
++)
1785 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1786 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1787 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1788 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1789 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1792 /* returned bits are DWORD aligned and upside down */
1793 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1799 static void test_GetDIBits_BI_BITFIELDS(void)
1801 /* Try a screen resolution detection technique
1802 * from the September 1999 issue of Windows Developer's Journal
1803 * which seems to be in widespread use.
1804 * http://www.lesher.ws/highcolor.html
1805 * http://www.lesher.ws/vidfmt.c
1806 * It hinges on being able to retrieve the bitmaps
1807 * for the three primary colors in non-paletted 16 bit mode.
1809 char dibinfo_buf
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
1811 LPBITMAPINFO dibinfo
= (LPBITMAPINFO
) dibinfo_buf
;
1816 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1817 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1820 ok(hdc
!= NULL
, "GetDC failed?\n");
1821 hbm
= CreateCompatibleBitmap(hdc
, 1, 1);
1822 ok(hbm
!= NULL
, "CreateCompatibleBitmap failed?\n");
1824 /* Call GetDIBits to fill in bmiHeader. */
1825 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1826 ok(ret
== 1, "GetDIBits failed\n");
1827 if (dibinfo
->bmiHeader
.biBitCount
> 8)
1829 DWORD
*bitmasks
= (DWORD
*)dibinfo
->bmiColors
;
1831 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1832 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1834 ok( !bitmasks
[0], "red mask is set\n" );
1835 ok( !bitmasks
[1], "green mask is set\n" );
1836 ok( !bitmasks
[2], "blue mask is set\n" );
1838 /* test with NULL bits pointer and correct bpp */
1839 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1840 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1841 ok(ret
== 1, "GetDIBits failed\n");
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, "size image not set\n" );
1848 /* test with valid bits pointer */
1849 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1850 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1851 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1852 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1853 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1854 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1855 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1857 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1858 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1859 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1860 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef ||
1861 broken(dibinfo
->bmiHeader
.biSizeImage
== 0xdeadbeef), /* win9x */
1862 "size image not set\n" );
1864 /* now with bits and 0 lines */
1865 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1866 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1867 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1868 SetLastError(0xdeadbeef);
1869 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1870 if (ret
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
)
1871 win_skip("Win9x/WinMe doesn't handle 0 for the number of scan lines\n");
1874 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1876 ok( !bitmasks
[0], "red mask is set\n" );
1877 ok( !bitmasks
[1], "green mask is set\n" );
1878 ok( !bitmasks
[2], "blue mask is set\n" );
1879 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1881 memset(bitmasks
, 0, 3*sizeof(DWORD
));
1882 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1883 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1884 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1886 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1887 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1888 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1889 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1892 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1895 ReleaseDC(NULL
, hdc
);
1898 static void test_select_object(void)
1901 HBITMAP hbm
, hbm_old
;
1903 DWORD depths
[] = {8, 15, 16, 24, 32};
1908 ok(hdc
!= 0, "GetDC(0) failed\n");
1909 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1910 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1912 hbm_old
= SelectObject(hdc
, hbm
);
1913 ok(hbm_old
== 0, "SelectObject should fail\n");
1918 hdc
= CreateCompatibleDC(0);
1919 ok(hdc
!= 0, "GetDC(0) failed\n");
1920 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1921 ok(hbm
!= 0, "CreateCompatibleBitmap 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 /* test an 1-bpp bitmap */
1931 planes
= GetDeviceCaps(hdc
, PLANES
);
1934 hbm
= CreateBitmap(10, 10, planes
, bpp
, NULL
);
1935 ok(hbm
!= 0, "CreateBitmap failed\n");
1937 hbm_old
= SelectObject(hdc
, hbm
);
1938 ok(hbm_old
!= 0, "SelectObject failed\n");
1939 hbm_old
= SelectObject(hdc
, hbm_old
);
1940 ok(hbm_old
== hbm
, "SelectObject failed\n");
1944 for(i
= 0; i
< sizeof(depths
)/sizeof(depths
[0]); i
++) {
1945 /* test a color bitmap to dc bpp matching */
1946 planes
= GetDeviceCaps(hdc
, PLANES
);
1947 bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
1949 hbm
= CreateBitmap(10, 10, planes
, depths
[i
], NULL
);
1950 ok(hbm
!= 0, "CreateBitmap failed\n");
1952 hbm_old
= SelectObject(hdc
, hbm
);
1953 if(depths
[i
] == bpp
||
1954 (bpp
== 16 && depths
[i
] == 15) /* 16 and 15 bpp are compatible */
1956 ok(hbm_old
!= 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp
, depths
[i
]);
1957 SelectObject(hdc
, hbm_old
);
1959 ok(hbm_old
== 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp
, depths
[i
]);
1962 memset(&bm
, 0xAA, sizeof(bm
));
1963 bytes
= GetObject(hbm
, sizeof(bm
), &bm
);
1964 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1965 ok(bm
.bmType
== 0 ||
1966 broken(bm
.bmType
== 21072), /* win9x */
1967 "wrong bmType %d\n", bm
.bmType
);
1968 ok(bm
.bmWidth
== 10, "wrong bmWidth %d\n", bm
.bmWidth
);
1969 ok(bm
.bmHeight
== 10, "wrong bmHeight %d\n", bm
.bmHeight
);
1970 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1971 ok(bm
.bmPlanes
== planes
, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1972 if(depths
[i
] == 15) {
1973 ok(bm
.bmBitsPixel
== 16 ||
1974 broken(bm
.bmBitsPixel
== 15), /* Win9x/WinME */
1975 "wrong bmBitsPixel %d(15 bpp special)\n", bm
.bmBitsPixel
);
1977 ok(bm
.bmBitsPixel
== depths
[i
], "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1979 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1987 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp
, int line
)
1992 ret
= GetObjectType(hbmp
);
1993 ok_(__FILE__
, line
)(ret
== OBJ_BITMAP
, "the object %p is not bitmap\n", hbmp
);
1995 ret
= GetObject(hbmp
, 0, 0);
1996 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) /* XP */ ||
1997 ret
== sizeof(DIBSECTION
) /* Win9x */, "object size %d\n", ret
);
1999 memset(&bm
, 0xDA, sizeof(bm
));
2000 SetLastError(0xdeadbeef);
2001 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
2002 if (!ret
) /* XP, only for curObj2 */ return;
2003 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
) ||
2004 ret
== sizeof(DIBSECTION
) /* Win9x, only for curObj2 */,
2005 "GetObject returned %d, error %u\n", ret
, GetLastError());
2006 ok_(__FILE__
, line
)(bm
.bmType
== 0, "wrong bmType, expected 0 got %d\n", bm
.bmType
);
2007 ok_(__FILE__
, line
)(bm
.bmWidth
== 1, "wrong bmWidth, expected 1 got %d\n", bm
.bmWidth
);
2008 ok_(__FILE__
, line
)(bm
.bmHeight
== 1, "wrong bmHeight, expected 1 got %d\n", bm
.bmHeight
);
2009 ok_(__FILE__
, line
)(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes, expected 2 got %d\n", bm
.bmWidthBytes
);
2010 ok_(__FILE__
, line
)(bm
.bmPlanes
== 1, "wrong bmPlanes, expected 1 got %u\n", bm
.bmPlanes
);
2011 ok_(__FILE__
, line
)(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel, expected 1 got %d\n", bm
.bmBitsPixel
);
2012 ok_(__FILE__
, line
)(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
2015 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2017 static void test_CreateBitmap(void)
2020 HDC screenDC
= GetDC(0);
2021 HDC hdc
= CreateCompatibleDC(screenDC
);
2024 /* all of these are the stock monochrome bitmap */
2025 HBITMAP bm
= CreateCompatibleBitmap(hdc
, 0, 0);
2026 HBITMAP bm1
= CreateCompatibleBitmap(screenDC
, 0, 0);
2027 HBITMAP bm4
= CreateBitmap(0, 1, 0, 0, 0);
2028 HBITMAP bm5
= CreateDiscardableBitmap(hdc
, 0, 0);
2029 HBITMAP curObj1
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2030 HBITMAP curObj2
= GetCurrentObject(screenDC
, OBJ_BITMAP
);
2032 /* these 2 are not the stock monochrome bitmap */
2033 HBITMAP bm2
= CreateCompatibleBitmap(hdc
, 1, 1);
2034 HBITMAP bm3
= CreateBitmap(1, 1, 1, 1, 0);
2036 HBITMAP old1
= SelectObject(hdc
, bm2
);
2037 HBITMAP old2
= SelectObject(screenDC
, bm3
);
2038 SelectObject(hdc
, old1
);
2039 SelectObject(screenDC
, old2
);
2041 ok(bm
== bm1
&& bm
== bm4
&& bm
== bm5
&& bm
== curObj1
&& bm
== old1
,
2042 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2043 bm
, bm1
, bm4
, bm5
, curObj1
, old1
);
2044 ok(bm
!= bm2
&& bm
!= bm3
, "0: %p, 2: %p, 3: %p\n", bm
, bm2
, bm3
);
2046 ok(bm
!= curObj2
|| /* WinXP */
2047 broken(bm
== curObj2
) /* Win9x */,
2048 "0: %p, curObj2 %p\n", bm
, curObj2
);
2049 ok(old2
== 0, "old2 %p\n", old2
);
2051 test_mono_1x1_bmp(bm
);
2052 test_mono_1x1_bmp(bm1
);
2053 test_mono_1x1_bmp(bm2
);
2054 test_mono_1x1_bmp(bm3
);
2055 test_mono_1x1_bmp(bm4
);
2056 test_mono_1x1_bmp(bm5
);
2057 test_mono_1x1_bmp(old1
);
2058 test_mono_1x1_bmp(curObj1
);
2068 ReleaseDC(0, screenDC
);
2070 /* show that Windows ignores the provided bm.bmWidthBytes */
2074 bmp
.bmWidthBytes
= 28;
2076 bmp
.bmBitsPixel
= 1;
2078 bm
= CreateBitmapIndirect(&bmp
);
2079 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2080 test_mono_1x1_bmp(bm
);
2083 /* Test how the bmBitsPixel field is treated */
2084 for(i
= 1; i
<= 33; i
++) {
2088 bmp
.bmWidthBytes
= 28;
2090 bmp
.bmBitsPixel
= i
;
2092 SetLastError(0xdeadbeef);
2093 bm
= CreateBitmapIndirect(&bmp
);
2095 DWORD error
= GetLastError();
2097 broken(bm
!= 0), /* Win9x and WinMe */
2098 "CreateBitmapIndirect for %d bpp succeeded\n", i
);
2099 ok(error
== ERROR_INVALID_PARAMETER
||
2100 broken(error
== 0xdeadbeef), /* Win9x and WinME */
2101 "Got error %d, expected ERROR_INVALID_PARAMETER\n", error
);
2105 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2106 GetObject(bm
, sizeof(bmp
), &bmp
);
2113 } else if(i
<= 16) {
2115 } else if(i
<= 24) {
2117 } else if(i
<= 32) {
2120 ok(bmp
.bmBitsPixel
== expect
||
2121 broken(bmp
.bmBitsPixel
== i
), /* Win9x and WinMe */
2122 "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2123 i
, bmp
.bmBitsPixel
, expect
);
2128 static void test_bitmapinfoheadersize(void)
2135 memset(&bmi
, 0, sizeof(BITMAPINFO
));
2136 bmi
.bmiHeader
.biHeight
= 100;
2137 bmi
.bmiHeader
.biWidth
= 512;
2138 bmi
.bmiHeader
.biBitCount
= 24;
2139 bmi
.bmiHeader
.biPlanes
= 1;
2141 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) - 1;
2143 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2144 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2146 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2148 SetLastError(0xdeadbeef);
2149 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2150 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2153 bmi
.bmiHeader
.biSize
++;
2155 SetLastError(0xdeadbeef);
2156 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2158 broken(!hdib
), /* Win98, WinMe */
2159 "CreateDIBSection error %d\n", GetLastError());
2162 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFO
);
2164 SetLastError(0xdeadbeef);
2165 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2167 broken(!hdib
), /* Win98, WinMe */
2168 "CreateDIBSection error %d\n", GetLastError());
2171 bmi
.bmiHeader
.biSize
++;
2173 SetLastError(0xdeadbeef);
2174 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2176 broken(!hdib
), /* Win98, WinMe */
2177 "CreateDIBSection error %d\n", GetLastError());
2180 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
2182 SetLastError(0xdeadbeef);
2183 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2184 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2187 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
2189 SetLastError(0xdeadbeef);
2190 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2192 broken(!hdib
), /* Win95 */
2193 "CreateDIBSection error %d\n", GetLastError());
2196 memset(&bci
, 0, sizeof(BITMAPCOREINFO
));
2197 bci
.bmciHeader
.bcHeight
= 100;
2198 bci
.bmciHeader
.bcWidth
= 512;
2199 bci
.bmciHeader
.bcBitCount
= 24;
2200 bci
.bmciHeader
.bcPlanes
= 1;
2202 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
) - 1;
2204 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2205 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2207 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2209 SetLastError(0xdeadbeef);
2210 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2211 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2214 bci
.bmciHeader
.bcSize
++;
2216 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2217 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2219 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREINFO
);
2221 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2222 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2227 static void test_get16dibits(void)
2229 BYTE bits
[4 * (16 / sizeof(BYTE
))];
2231 HDC screen_dc
= GetDC(NULL
);
2234 int info_len
= sizeof(BITMAPINFOHEADER
) + 1024;
2236 int overwritten_bytes
= 0;
2238 memset(bits
, 0, sizeof(bits
));
2239 hbmp
= CreateBitmap(2, 2, 1, 16, bits
);
2240 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
2242 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info_len
);
2245 memset(info
, '!', info_len
);
2246 memset(info
, 0, sizeof(info
->bmiHeader
));
2248 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
2249 info
->bmiHeader
.biWidth
= 2;
2250 info
->bmiHeader
.biHeight
= 2;
2251 info
->bmiHeader
.biPlanes
= 1;
2252 info
->bmiHeader
.biCompression
= BI_RGB
;
2254 ret
= GetDIBits(screen_dc
, hbmp
, 0, 0, NULL
, info
, 0);
2256 broken(ret
== 0), /* win9x */
2257 "GetDIBits failed got %d\n", ret
);
2259 for (p
= ((BYTE
*) info
) + sizeof(info
->bmiHeader
); (p
- ((BYTE
*) info
)) < info_len
; p
++)
2261 overwritten_bytes
++;
2262 ok(overwritten_bytes
== 0, "GetDIBits wrote past the buffer given\n");
2264 HeapFree(GetProcessHeap(), 0, info
);
2266 ReleaseDC(NULL
, screen_dc
);
2269 static BOOL
compare_buffers_no_alpha(UINT32
*a
, UINT32
*b
, int length
)
2272 for(i
= 0; i
< length
; i
++)
2273 if((a
[i
] & 0x00FFFFFF) != (b
[i
] & 0x00FFFFFF))
2278 static void check_BitBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2279 DWORD dwRop
, UINT32 expected
, int line
)
2281 *srcBuffer
= 0xFEDCBA98;
2282 *dstBuffer
= 0x89ABCDEF;
2283 Rectangle(hdcSrc
, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2284 BitBlt(hdcDst
, 0, 0, 1, 1, hdcSrc
, 0, 0, dwRop
);
2285 ok(expected
== *dstBuffer
,
2286 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2287 dwRop
, expected
, *dstBuffer
, line
);
2290 static void test_BitBlt(void)
2292 HBITMAP bmpDst
, bmpSrc
;
2293 HBITMAP oldDst
, oldSrc
;
2294 HDC hdcScreen
, hdcDst
, hdcSrc
;
2295 UINT32
*dstBuffer
, *srcBuffer
;
2296 HBRUSH hBrush
, hOldBrush
;
2297 BITMAPINFO bitmapInfo
;
2299 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2300 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2301 bitmapInfo
.bmiHeader
.biWidth
= 1;
2302 bitmapInfo
.bmiHeader
.biHeight
= 1;
2303 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2304 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2305 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2306 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
2308 hdcScreen
= CreateCompatibleDC(0);
2309 hdcDst
= CreateCompatibleDC(hdcScreen
);
2310 hdcSrc
= CreateCompatibleDC(hdcDst
);
2312 /* Setup the destination dib section */
2313 bmpDst
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2315 oldDst
= SelectObject(hdcDst
, bmpDst
);
2317 hBrush
= CreateSolidBrush(0x012345678);
2318 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2320 /* Setup the source dib section */
2321 bmpSrc
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2323 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2325 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2326 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2327 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2328 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2329 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2330 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2331 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2332 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2333 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2334 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2335 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2336 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2337 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2338 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2339 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2342 SelectObject(hdcSrc
, oldSrc
);
2343 DeleteObject(bmpSrc
);
2346 SelectObject(hdcDst
, hOldBrush
);
2347 DeleteObject(hBrush
);
2348 SelectObject(hdcDst
, oldDst
);
2349 DeleteObject(bmpDst
);
2353 DeleteDC(hdcScreen
);
2356 static void check_StretchBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2357 DWORD dwRop
, UINT32 expected
, int line
)
2359 *srcBuffer
= 0xFEDCBA98;
2360 *dstBuffer
= 0x89ABCDEF;
2361 StretchBlt(hdcDst
, 0, 0, 2, 1, hdcSrc
, 0, 0, 1, 1, dwRop
);
2362 ok(expected
== *dstBuffer
,
2363 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2364 dwRop
, expected
, *dstBuffer
, line
);
2367 static void check_StretchBlt_stretch(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2368 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2369 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2370 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2372 memset(dstBuffer
, 0, 16);
2373 StretchBlt(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2374 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
, SRCCOPY
);
2375 ok(memcmp(dstBuffer
, expected
, 16) == 0 ||
2376 broken(compare_buffers_no_alpha(dstBuffer
, legacy_expected
, 4)),
2377 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2378 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2379 expected
[0], expected
[1], expected
[2], expected
[3],
2380 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2381 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2382 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2385 static void test_StretchBlt(void)
2387 HBITMAP bmpDst
, bmpSrc
;
2388 HBITMAP oldDst
, oldSrc
;
2389 HDC hdcScreen
, hdcDst
, hdcSrc
;
2390 UINT32
*dstBuffer
, *srcBuffer
;
2391 HBRUSH hBrush
, hOldBrush
;
2392 BITMAPINFO biDst
, biSrc
;
2393 UINT32 expected
[4], legacy_expected
[4];
2395 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2396 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2397 biDst
.bmiHeader
.biWidth
= 2;
2398 biDst
.bmiHeader
.biHeight
= -2;
2399 biDst
.bmiHeader
.biPlanes
= 1;
2400 biDst
.bmiHeader
.biBitCount
= 32;
2401 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2402 memcpy(&biSrc
, &biDst
, sizeof(BITMAPINFO
));
2404 hdcScreen
= CreateCompatibleDC(0);
2405 hdcDst
= CreateCompatibleDC(hdcScreen
);
2406 hdcSrc
= CreateCompatibleDC(hdcDst
);
2409 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2411 oldDst
= SelectObject(hdcDst
, bmpDst
);
2413 bmpSrc
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2415 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2417 hBrush
= CreateSolidBrush(0x012345678);
2418 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2420 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2421 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2422 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2423 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2424 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2425 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2426 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2427 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2428 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2429 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2430 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2431 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2432 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2433 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2434 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2436 SelectObject(hdcDst
, hOldBrush
);
2437 DeleteObject(hBrush
);
2439 /* Top-down to top-down tests */
2440 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2441 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2443 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2444 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2445 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2446 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2448 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2449 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2450 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2451 0, 0, 1, 1, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2453 expected
[0] = 0xCAFED00D, expected
[1] = 0xCAFED00D;
2454 expected
[2] = 0xCAFED00D, expected
[3] = 0xCAFED00D;
2455 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2456 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2458 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2459 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2460 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2461 0, 0, 1, 1, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2463 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2464 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2465 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2466 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2468 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2469 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2470 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2471 1, 1, -2, -2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2473 /* This result seems broken. One might expect the following result:
2474 * 0xCAFED00D 0xFEEDFACE
2475 * 0xFEDCBA98 0x76543210
2477 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2478 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2479 legacy_expected
[0] = 0xCAFED00D, legacy_expected
[1] = 0x00000000;
2480 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2481 todo_wine
check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2482 1, 1, -2, -2, 1, 1, -2, -2, expected
,
2483 legacy_expected
, __LINE__
);
2485 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2486 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2487 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2488 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2490 SelectObject(hdcDst
, oldDst
);
2491 DeleteObject(bmpDst
);
2493 /* Top-down to bottom-up tests */
2494 biDst
.bmiHeader
.biHeight
= 2;
2495 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2497 oldDst
= SelectObject(hdcDst
, bmpDst
);
2499 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2500 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2501 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2502 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2504 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2505 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2506 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2507 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2509 SelectObject(hdcSrc
, oldSrc
);
2510 DeleteObject(bmpSrc
);
2512 /* Bottom-up to bottom-up tests */
2513 biSrc
.bmiHeader
.biHeight
= 2;
2514 bmpSrc
= CreateDIBSection(hdcScreen
, &biSrc
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2516 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2517 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2518 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2520 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2521 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2522 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2523 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2525 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2526 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2527 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2528 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2530 SelectObject(hdcDst
, oldDst
);
2531 DeleteObject(bmpDst
);
2533 /* Bottom-up to top-down tests */
2534 biDst
.bmiHeader
.biHeight
= -2;
2535 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2537 oldDst
= SelectObject(hdcDst
, bmpDst
);
2539 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2540 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2541 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2542 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2544 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2545 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2546 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2547 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2550 SelectObject(hdcSrc
, oldSrc
);
2551 DeleteObject(bmpSrc
);
2554 SelectObject(hdcDst
, oldDst
);
2555 DeleteObject(bmpDst
);
2558 DeleteDC(hdcScreen
);
2561 static void check_StretchDIBits_pixel(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2562 DWORD dwRop
, UINT32 expected
, int line
)
2564 const UINT32 buffer
[2] = { 0xFEDCBA98, 0 };
2565 BITMAPINFO bitmapInfo
;
2567 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2568 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2569 bitmapInfo
.bmiHeader
.biWidth
= 2;
2570 bitmapInfo
.bmiHeader
.biHeight
= 1;
2571 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2572 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2573 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2574 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(buffer
);
2576 *dstBuffer
= 0x89ABCDEF;
2578 StretchDIBits(hdcDst
, 0, 0, 2, 1, 0, 0, 1, 1, &buffer
, &bitmapInfo
, DIB_RGB_COLORS
, dwRop
);
2579 ok(expected
== *dstBuffer
,
2580 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2581 dwRop
, expected
, *dstBuffer
, line
);
2584 static void check_StretchDIBits_stretch(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2585 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2586 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2587 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2589 BITMAPINFO bitmapInfo
;
2591 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2592 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2593 bitmapInfo
.bmiHeader
.biWidth
= 2;
2594 bitmapInfo
.bmiHeader
.biHeight
= -2;
2595 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2596 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2597 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2599 memset(dstBuffer
, 0, 16);
2600 StretchDIBits(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2601 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2602 srcBuffer
, &bitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
2603 ok(memcmp(dstBuffer
, expected
, 16) == 0 || /* Win2k/XP */
2604 broken(compare_buffers_no_alpha(dstBuffer
, legacy_expected
, 4)) || /* Win9X/ME */
2605 broken(nWidthSrc
< 0 || nHeightSrc
< 0), /* Win9X/ME */
2606 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2607 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2608 expected
[0], expected
[1], expected
[2], expected
[3],
2609 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2610 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2611 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2614 static void test_StretchDIBits(void)
2618 HDC hdcScreen
, hdcDst
;
2619 UINT32
*dstBuffer
, srcBuffer
[4];
2620 HBRUSH hBrush
, hOldBrush
;
2622 UINT32 expected
[4], legacy_expected
[4];
2624 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2625 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2626 biDst
.bmiHeader
.biWidth
= 2;
2627 biDst
.bmiHeader
.biHeight
= -2;
2628 biDst
.bmiHeader
.biPlanes
= 1;
2629 biDst
.bmiHeader
.biBitCount
= 32;
2630 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2632 hdcScreen
= CreateCompatibleDC(0);
2633 hdcDst
= CreateCompatibleDC(hdcScreen
);
2636 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2638 oldDst
= SelectObject(hdcDst
, bmpDst
);
2640 hBrush
= CreateSolidBrush(0x012345678);
2641 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2643 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2644 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2645 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2646 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2647 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2648 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2649 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2650 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2651 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2652 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2653 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2654 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2655 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2656 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2657 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2659 SelectObject(hdcDst
, hOldBrush
);
2660 DeleteObject(hBrush
);
2662 /* Top-down destination tests */
2663 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2664 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2666 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2667 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2668 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2669 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2671 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2672 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2673 legacy_expected
[0] = 0xFEDCBA98, legacy_expected
[1] = 0x00000000;
2674 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2675 todo_wine
check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2676 0, 0, 1, 1, 0, 0, 1, 1, expected
, legacy_expected
, __LINE__
);
2678 expected
[0] = 0xFEDCBA98, expected
[1] = 0xFEDCBA98;
2679 expected
[2] = 0xFEDCBA98, expected
[3] = 0xFEDCBA98;
2680 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2681 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2683 expected
[0] = 0x42441000, expected
[1] = 0x00000000;
2684 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2685 legacy_expected
[0] = 0x00543210, legacy_expected
[1] = 0x00000000;
2686 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2687 todo_wine
check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2688 0, 0, 1, 1, 0, 0, 2, 2, expected
, legacy_expected
, __LINE__
);
2690 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2691 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2692 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2693 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2695 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2696 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2697 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2698 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2700 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2701 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2702 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2703 1, 1, -2, -2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2705 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2706 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2707 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2708 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2710 SelectObject(hdcDst
, oldDst
);
2711 DeleteObject(bmpDst
);
2713 /* Bottom up destination tests */
2714 biDst
.bmiHeader
.biHeight
= 2;
2715 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2717 oldDst
= SelectObject(hdcDst
, bmpDst
);
2719 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2720 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2721 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2722 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2725 SelectObject(hdcDst
, oldDst
);
2726 DeleteObject(bmpDst
);
2729 DeleteDC(hdcScreen
);
2732 static void test_GdiAlphaBlend(void)
2734 /* test out-of-bound parameters for GdiAlphaBlend */
2747 BLENDFUNCTION blend
;
2749 if (!pGdiAlphaBlend
)
2751 win_skip("GdiAlphaBlend() is not implemented\n");
2755 hdcNull
= GetDC(NULL
);
2756 hdcDst
= CreateCompatibleDC(hdcNull
);
2757 bmpDst
= CreateCompatibleBitmap(hdcNull
, 100, 100);
2758 hdcSrc
= CreateCompatibleDC(hdcNull
);
2760 memset(&bmi
, 0, sizeof(bmi
)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2761 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
2762 bmi
.bmiHeader
.biHeight
= 20;
2763 bmi
.bmiHeader
.biWidth
= 20;
2764 bmi
.bmiHeader
.biBitCount
= 32;
2765 bmi
.bmiHeader
.biPlanes
= 1;
2766 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2767 bmpSrc
= CreateDIBSection(hdcDst
, &bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2768 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2770 oldDst
= SelectObject(hdcDst
, bmpDst
);
2771 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2773 blend
.BlendOp
= AC_SRC_OVER
;
2774 blend
.BlendFlags
= 0;
2775 blend
.SourceConstantAlpha
= 128;
2776 blend
.AlphaFormat
= 0;
2778 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, 0, 20, 20, blend
), TRUE
, BOOL
, "%d");
2779 SetLastError(0xdeadbeef);
2780 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2781 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER
, int, "%d");
2782 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), FALSE
, BOOL
, "%d");
2783 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 15, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2784 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2785 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2787 SetWindowOrgEx(hdcSrc
, -10, -10, NULL
);
2788 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), TRUE
, BOOL
, "%d");
2789 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), TRUE
, BOOL
, "%d");
2790 SetMapMode(hdcSrc
, MM_ANISOTROPIC
);
2791 ScaleWindowExtEx(hdcSrc
, 10, 1, 10, 1, NULL
);
2792 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 30, 30, blend
), TRUE
, BOOL
, "%d");
2793 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 30, 30, blend
), TRUE
, BOOL
, "%d");
2795 SetLastError(0xdeadbeef);
2796 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, NULL
, 0, 0, 20, 20, blend
), FALSE
, BOOL
, "%d");
2797 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2799 SelectObject(hdcDst
, oldDst
);
2800 SelectObject(hdcSrc
, oldSrc
);
2801 DeleteObject(bmpSrc
);
2802 DeleteObject(bmpDst
);
2806 ReleaseDC(NULL
, hdcNull
);
2810 static void test_clipping(void)
2820 HDC hdcDst
= CreateCompatibleDC( NULL
);
2821 HDC hdcSrc
= CreateCompatibleDC( NULL
);
2823 BITMAPINFO bmpinfo
={{0}};
2824 bmpinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2825 bmpinfo
.bmiHeader
.biWidth
= 100;
2826 bmpinfo
.bmiHeader
.biHeight
= 100;
2827 bmpinfo
.bmiHeader
.biPlanes
= 1;
2828 bmpinfo
.bmiHeader
.biBitCount
= GetDeviceCaps( hdcDst
, BITSPIXEL
);
2829 bmpinfo
.bmiHeader
.biCompression
= BI_RGB
;
2831 bmpDst
= CreateDIBSection( hdcDst
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2832 ok(bmpDst
!= NULL
, "Couldn't create destination bitmap\n");
2833 oldDst
= SelectObject( hdcDst
, bmpDst
);
2835 bmpSrc
= CreateDIBSection( hdcSrc
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2836 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2837 oldSrc
= SelectObject( hdcSrc
, bmpSrc
);
2839 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 100, 100, SRCCOPY
);
2840 ok(result
, "BitBlt failed\n");
2842 hRgn
= CreateRectRgn( 0,0,0,0 );
2843 SelectClipRgn( hdcDst
, hRgn
);
2845 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 0, 0, SRCCOPY
);
2846 ok(result
, "BitBlt failed\n");
2848 DeleteObject( bmpDst
);
2849 DeleteObject( bmpSrc
);
2850 DeleteObject( hRgn
);
2855 static void test_32bit_bitmap_blt(void)
2858 HBITMAP bmpSrc
, bmpDst
;
2859 HBITMAP oldSrc
, oldDst
;
2860 HDC hdcSrc
, hdcDst
, hdcScreen
;
2862 DWORD colorSrc
= 0x11223344;
2864 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2865 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2866 biDst
.bmiHeader
.biWidth
= 2;
2867 biDst
.bmiHeader
.biHeight
= -2;
2868 biDst
.bmiHeader
.biPlanes
= 1;
2869 biDst
.bmiHeader
.biBitCount
= 32;
2870 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2872 hdcScreen
= CreateCompatibleDC(0);
2873 if(GetDeviceCaps(hdcScreen
, BITSPIXEL
) != 32)
2875 DeleteDC(hdcScreen
);
2876 trace("Skipping 32-bit DDB test\n");
2880 hdcSrc
= CreateCompatibleDC(hdcScreen
);
2881 bmpSrc
= CreateBitmap(1, 1, 1, 32, &colorSrc
);
2882 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2884 hdcDst
= CreateCompatibleDC(hdcScreen
);
2885 bmpDst
= CreateDIBSection(hdcDst
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
2886 oldDst
= SelectObject(hdcDst
, bmpDst
);
2888 StretchBlt(hdcDst
, 0, 0, 1, 1, hdcSrc
, 0, 0, 1, 1, SRCCOPY
);
2889 ok(dstBuffer
[0] == colorSrc
, "Expected color=%x, received color=%x\n", colorSrc
, dstBuffer
[0]);
2892 SelectObject(hdcDst
, oldDst
);
2893 DeleteObject(bmpDst
);
2896 SelectObject(hdcSrc
, oldSrc
);
2897 DeleteObject(bmpSrc
);
2900 DeleteDC(hdcScreen
);
2906 is_win9x
= GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC
) == 0;
2908 hdll
= GetModuleHandle("gdi32.dll");
2909 pGdiAlphaBlend
= (void*)GetProcAddress(hdll
, "GdiAlphaBlend");
2911 test_createdibitmap();
2913 test_mono_dibsection();
2916 test_GetDIBits_selected_DIB(1);
2917 test_GetDIBits_selected_DIB(4);
2918 test_GetDIBits_selected_DIB(8);
2919 test_GetDIBits_selected_DDB(TRUE
);
2920 test_GetDIBits_selected_DDB(FALSE
);
2922 test_GetDIBits_BI_BITFIELDS();
2923 test_select_object();
2924 test_CreateBitmap();
2927 test_StretchDIBits();
2928 test_GdiAlphaBlend();
2929 test_32bit_bitmap_blt();
2930 test_bitmapinfoheadersize();