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); }
39 static INT
BITMAP_GetWidthBytes( INT bmWidth
, INT bpp
)
44 return 2 * ((bmWidth
+15) >> 4);
47 bmWidth
*= 3; /* fall through */
49 return bmWidth
+ (bmWidth
& 1);
59 return 2 * ((bmWidth
+3) >> 2);
62 trace("Unknown depth %d, please report.\n", bpp
);
68 static void test_bitmap_info(HBITMAP hbm
, INT expected_depth
, const BITMAPINFOHEADER
*bmih
)
73 BYTE buf
[512], buf_cmp
[512];
75 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
76 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
78 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
79 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
80 ok(bm
.bmHeight
== bmih
->biHeight
, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
81 width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
82 ok(bm
.bmWidthBytes
== width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, width_bytes
);
83 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
84 ok(bm
.bmBitsPixel
== expected_depth
, "wrong bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, expected_depth
);
85 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
87 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
88 assert(sizeof(buf
) == sizeof(buf_cmp
));
90 SetLastError(0xdeadbeef);
91 ret
= GetBitmapBits(hbm
, 0, NULL
);
92 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
94 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
95 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
97 memset(buf
, 0xAA, sizeof(buf
));
98 ret
= GetBitmapBits(hbm
, sizeof(buf
), buf
);
99 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
100 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)),
101 "buffers do not match, depth %d\n", bmih
->biBitCount
);
103 /* test various buffer sizes for GetObject */
104 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
105 ok(ret
== sizeof(*bma
), "wrong size %d\n", ret
);
107 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
108 ok(ret
== 0, "%d != 0\n", ret
);
110 ret
= GetObject(hbm
, 0, &bm
);
111 ok(ret
== 0, "%d != 0\n", ret
);
113 ret
= GetObject(hbm
, 1, &bm
);
114 ok(ret
== 0, "%d != 0\n", ret
);
116 ret
= GetObject(hbm
, 0, NULL
);
117 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
120 static void test_createdibitmap(void)
123 BITMAPINFOHEADER bmih
;
125 HBITMAP hbm
, hbm_colour
, hbm_old
;
130 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
);
131 memset(&bmih
, 0, sizeof(bmih
));
132 bmih
.biSize
= sizeof(bmih
);
136 bmih
.biBitCount
= 32;
137 bmih
.biCompression
= BI_RGB
;
139 hbm
= CreateDIBitmap(hdc
, NULL
, CBM_INIT
, NULL
, NULL
, 0);
140 ok(hbm
== NULL
, "CreateDIBitmap should fail\n");
141 hbm
= CreateDIBitmap(hdc
, NULL
, 0, NULL
, NULL
, 0);
142 ok(hbm
== NULL
, "CreateDIBitmap should fail\n");
144 /* First create an un-initialised bitmap. The depth of the bitmap
145 should match that of the hdc and not that supplied in bmih.
148 /* First try 32 bits */
149 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
150 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
151 test_bitmap_info(hbm
, screen_depth
, &bmih
);
155 bmih
.biBitCount
= 16;
156 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
157 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
158 test_bitmap_info(hbm
, screen_depth
, &bmih
);
163 hbm
= CreateDIBitmap(hdc
, &bmih
, 0, NULL
, NULL
, 0);
164 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
165 test_bitmap_info(hbm
, screen_depth
, &bmih
);
168 /* Now with a monochrome dc we expect a monochrome bitmap */
169 hdcmem
= CreateCompatibleDC(hdc
);
171 /* First try 32 bits */
172 bmih
.biBitCount
= 32;
173 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
174 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
175 test_bitmap_info(hbm
, 1, &bmih
);
179 bmih
.biBitCount
= 16;
180 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
181 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
182 test_bitmap_info(hbm
, 1, &bmih
);
187 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
188 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
189 test_bitmap_info(hbm
, 1, &bmih
);
192 /* Now select a polychrome bitmap into the dc and we expect
193 screen_depth bitmaps again */
194 hbm_colour
= CreateCompatibleBitmap(hdc
, bmih
.biWidth
, bmih
.biHeight
);
195 test_bitmap_info(hbm_colour
, screen_depth
, &bmih
);
196 hbm_old
= SelectObject(hdcmem
, hbm_colour
);
198 /* First try 32 bits */
199 bmih
.biBitCount
= 32;
200 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
201 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
202 test_bitmap_info(hbm
, screen_depth
, &bmih
);
206 bmih
.biBitCount
= 16;
207 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
208 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
209 test_bitmap_info(hbm
, screen_depth
, &bmih
);
214 hbm
= CreateDIBitmap(hdcmem
, &bmih
, 0, NULL
, NULL
, 0);
215 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
216 test_bitmap_info(hbm
, screen_depth
, &bmih
);
219 SelectObject(hdcmem
, hbm_old
);
220 DeleteObject(hbm_colour
);
223 bmih
.biBitCount
= 32;
224 hbm
= CreateDIBitmap(0, &bmih
, 0, NULL
, NULL
, 0);
225 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
226 test_bitmap_info(hbm
, 1, &bmih
);
229 /* Test how formats are converted */
235 memset(&bm
, 0, sizeof(bm
));
236 bm
.bmiHeader
.biSize
= sizeof(bm
.bmiHeader
);
237 bm
.bmiHeader
.biWidth
= 1;
238 bm
.bmiHeader
.biHeight
= 1;
239 bm
.bmiHeader
.biPlanes
= 1;
240 bm
.bmiHeader
.biBitCount
= 24;
241 bm
.bmiHeader
.biCompression
= BI_RGB
;
242 bm
.bmiHeader
.biSizeImage
= 0;
243 hbm
= CreateDIBitmap(hdc
, &bmih
, CBM_INIT
, &pixel
, &bm
, DIB_RGB_COLORS
);
244 ok(hbm
!= NULL
, "CreateDIBitmap failed\n");
247 bm
.bmiHeader
.biBitCount
= 32;
248 GetDIBits(hdc
, hbm
, 0, 1, &pixel
, &bm
, DIB_RGB_COLORS
);
249 ok(pixel
== 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08x\n", pixel
);
255 static INT
DIB_GetWidthBytes( int width
, int bpp
)
261 case 1: words
= (width
+ 31) / 32; break;
262 case 4: words
= (width
+ 7) / 8; break;
263 case 8: words
= (width
+ 3) / 4; break;
265 case 16: words
= (width
+ 1) / 2; break;
266 case 24: words
= (width
* 3 + 3)/4; break;
267 case 32: words
= width
; break;
271 trace("Unknown depth %d, please report.\n", bpp
);
278 static void test_dib_info(HBITMAP hbm
, const void *bits
, const BITMAPINFOHEADER
*bmih
)
284 INT ret
, bm_width_bytes
, dib_width_bytes
;
287 ret
= GetObject(hbm
, sizeof(bm
), &bm
);
288 ok(ret
== sizeof(bm
), "GetObject returned %d\n", ret
);
290 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
291 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
292 ok(bm
.bmHeight
== abs(bmih
->biHeight
), "wrong bm.bmHeight %d\n", bm
.bmHeight
);
293 dib_width_bytes
= DIB_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
294 bm_width_bytes
= BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
);
295 if (bm
.bmWidthBytes
!= dib_width_bytes
) /* Win2k bug */
296 ok(bm
.bmWidthBytes
== bm_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, bm_width_bytes
);
298 ok(bm
.bmWidthBytes
== dib_width_bytes
, "wrong bm.bmWidthBytes %d != %d\n", bm
.bmWidthBytes
, dib_width_bytes
);
299 ok(bm
.bmPlanes
== bmih
->biPlanes
, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
300 ok(bm
.bmBitsPixel
== bmih
->biBitCount
, "bm.bmBitsPixel %d != %d\n", bm
.bmBitsPixel
, bmih
->biBitCount
);
301 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
303 buf
= HeapAlloc(GetProcessHeap(), 0, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
305 /* GetBitmapBits returns not 32-bit aligned data */
306 SetLastError(0xdeadbeef);
307 ret
= GetBitmapBits(hbm
, 0, NULL
);
308 ok(ret
== bm_width_bytes
* bm
.bmHeight
,
309 "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
311 memset(buf
, 0xAA, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096);
312 ret
= GetBitmapBits(hbm
, bm
.bmWidthBytes
* bm
.bmHeight
+ 4096, buf
);
313 ok(ret
== bm_width_bytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm_width_bytes
* bm
.bmHeight
);
315 HeapFree(GetProcessHeap(), 0, buf
);
317 /* test various buffer sizes for GetObject */
318 memset(&ds
, 0xAA, sizeof(ds
));
319 ret
= GetObject(hbm
, sizeof(*bma
) * 2, bma
);
320 ok(ret
== sizeof(*bma
), "wrong size %d\n", ret
);
321 ok(bm
.bmWidth
== bmih
->biWidth
, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
322 ok(bm
.bmHeight
== abs(bmih
->biHeight
), "wrong bm.bmHeight %d\n", bm
.bmHeight
);
323 ok(bm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", bm
.bmBits
, bits
);
325 ret
= GetObject(hbm
, sizeof(bm
) / 2, &bm
);
326 ok(ret
== 0, "%d != 0\n", ret
);
328 ret
= GetObject(hbm
, 0, &bm
);
329 ok(ret
== 0, "%d != 0\n", ret
);
331 ret
= GetObject(hbm
, 1, &bm
);
332 ok(ret
== 0, "%d != 0\n", ret
);
334 /* test various buffer sizes for GetObject */
335 ret
= GetObject(hbm
, 0, NULL
);
336 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
338 ret
= GetObject(hbm
, sizeof(*dsa
) * 2, dsa
);
339 ok(ret
== sizeof(*dsa
), "wrong size %d\n", ret
);
341 memset(&ds
, 0xAA, sizeof(ds
));
342 ret
= GetObject(hbm
, sizeof(ds
), &ds
);
343 ok(ret
== sizeof(ds
), "wrong size %d\n", ret
);
345 ok(ds
.dsBm
.bmBits
== bits
, "wrong bm.bmBits %p != %p\n", ds
.dsBm
.bmBits
, bits
);
346 if (ds
.dsBm
.bmWidthBytes
!= bm_width_bytes
) /* Win2k bug */
347 ok(ds
.dsBmih
.biSizeImage
== ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
, "%u != %u\n",
348 ds
.dsBmih
.biSizeImage
, ds
.dsBm
.bmWidthBytes
* ds
.dsBm
.bmHeight
);
349 ok(bmih
->biSizeImage
== 0, "%u != 0\n", bmih
->biSizeImage
);
350 ds
.dsBmih
.biSizeImage
= 0;
352 ok(ds
.dsBmih
.biSize
== bmih
->biSize
, "%u != %u\n", ds
.dsBmih
.biSize
, bmih
->biSize
);
353 ok(ds
.dsBmih
.biWidth
== bmih
->biWidth
, "%d != %d\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
354 ok(ds
.dsBmih
.biHeight
== abs(bmih
->biHeight
), "%d != %d\n", ds
.dsBmih
.biHeight
, abs(bmih
->biHeight
));
355 ok(ds
.dsBmih
.biPlanes
== bmih
->biPlanes
, "%u != %u\n", ds
.dsBmih
.biPlanes
, bmih
->biPlanes
);
356 ok(ds
.dsBmih
.biBitCount
== bmih
->biBitCount
, "%u != %u\n", ds
.dsBmih
.biBitCount
, bmih
->biBitCount
);
357 ok(ds
.dsBmih
.biCompression
== bmih
->biCompression
, "%u != %u\n", ds
.dsBmih
.biCompression
, bmih
->biCompression
);
358 ok(ds
.dsBmih
.biSizeImage
== bmih
->biSizeImage
, "%u != %u\n", ds
.dsBmih
.biSizeImage
, bmih
->biSizeImage
);
359 ok(ds
.dsBmih
.biXPelsPerMeter
== bmih
->biXPelsPerMeter
, "%d != %d\n", ds
.dsBmih
.biXPelsPerMeter
, bmih
->biXPelsPerMeter
);
360 ok(ds
.dsBmih
.biYPelsPerMeter
== bmih
->biYPelsPerMeter
, "%d != %d\n", ds
.dsBmih
.biYPelsPerMeter
, bmih
->biYPelsPerMeter
);
362 memset(&ds
, 0xAA, sizeof(ds
));
363 ret
= GetObject(hbm
, sizeof(ds
) - 4, &ds
);
364 ok(ret
== sizeof(ds
.dsBm
), "wrong size %d\n", ret
);
365 ok(ds
.dsBm
.bmWidth
== bmih
->biWidth
, "%d != %d\n", ds
.dsBmih
.biWidth
, bmih
->biWidth
);
366 ok(ds
.dsBm
.bmHeight
== abs(bmih
->biHeight
), "%d != %d\n", ds
.dsBmih
.biHeight
, abs(bmih
->biHeight
));
367 ok(ds
.dsBm
.bmBits
== bits
, "%p != %p\n", ds
.dsBm
.bmBits
, bits
);
369 ret
= GetObject(hbm
, 0, &ds
);
370 ok(ret
== 0, "%d != 0\n", ret
);
372 ret
= GetObject(hbm
, 1, &ds
);
373 ok(ret
== 0, "%d != 0\n", ret
);
376 #define test_color_todo(got, exp, txt, todo) \
377 if (!todo && got != exp && screen_depth < 24) { \
378 todo_wine ok(0, #txt " failed at %d-bit screen depth: got 0x%06x expected 0x%06x - skipping DIB tests\n", \
379 screen_depth, (UINT)got, (UINT)exp); \
381 } else if (todo) todo_wine { ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp); } \
382 else ok(got == exp, #txt " failed: got 0x%06x expected 0x%06x\n", (UINT)got, (UINT)exp) \
384 #define test_color(hdc, color, exp, todo_setp, todo_getp) \
387 c = SetPixel(hdc, 0, 0, color); \
388 test_color_todo(c, exp, SetPixel, todo_setp); \
389 c = GetPixel(hdc, 0, 0); \
390 test_color_todo(c, exp, GetPixel, todo_getp); \
393 static void test_dib_bits_access( HBITMAP hdib
, void *bits
)
395 MEMORY_BASIC_INFORMATION info
;
396 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
398 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
400 char filename
[MAX_PATH
];
405 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
406 "VirtualQuery failed\n");
407 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
408 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
409 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
410 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
411 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
412 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
414 memset( pbmi
, 0, sizeof(bmibuf
) );
415 memset( data
, 0xcc, sizeof(data
) );
416 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
417 pbmi
->bmiHeader
.biHeight
= 16;
418 pbmi
->bmiHeader
.biWidth
= 16;
419 pbmi
->bmiHeader
.biBitCount
= 32;
420 pbmi
->bmiHeader
.biPlanes
= 1;
421 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
425 ret
= SetDIBits( hdc
, hdib
, 0, 16, data
, pbmi
, DIB_RGB_COLORS
);
426 ok(ret
== 16, "SetDIBits failed: expected 16 got %d\n", ret
);
430 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
431 "VirtualQuery failed\n");
432 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
433 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
434 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
435 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
436 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
437 /* it has been protected now */
438 todo_wine
ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
440 /* try writing protected bits to a file */
442 GetTempFileNameA( ".", "dib", 0, filename
);
443 file
= CreateFileA( filename
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
444 CREATE_ALWAYS
, 0, 0 );
445 ok( file
!= INVALID_HANDLE_VALUE
, "failed to open %s error %u\n", filename
, GetLastError() );
446 ret
= WriteFile( file
, bits
, 8192, &written
, NULL
);
447 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
448 if (ret
) ok( written
== 8192, "only wrote %u bytes\n", written
);
450 DeleteFileA( filename
);
453 static void test_dibsections(void)
455 HDC hdc
, hdcmem
, hdcmem2
;
456 HBITMAP hdib
, oldbm
, hdib2
, oldbm2
;
457 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
458 char bcibuf
[sizeof(BITMAPCOREINFO
) + 256 * sizeof(RGBTRIPLE
)];
459 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
460 BITMAPCOREINFO
*pbci
= (BITMAPCOREINFO
*)bcibuf
;
466 char logpalbuf
[sizeof(LOGPALETTE
) + 256 * sizeof(PALETTEENTRY
)];
467 LOGPALETTE
*plogpal
= (LOGPALETTE
*)logpalbuf
;
470 HPALETTE hpal
, oldpal
;
475 MEMORY_BASIC_INFORMATION info
;
478 screen_depth
= GetDeviceCaps(hdc
, BITSPIXEL
) * GetDeviceCaps(hdc
, PLANES
);
480 memset(pbmi
, 0, sizeof(bmibuf
));
481 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
482 pbmi
->bmiHeader
.biHeight
= 100;
483 pbmi
->bmiHeader
.biWidth
= 512;
484 pbmi
->bmiHeader
.biBitCount
= 24;
485 pbmi
->bmiHeader
.biPlanes
= 1;
486 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
488 SetLastError(0xdeadbeef);
490 /* invalid pointer for BITMAPINFO
491 (*bits should be NULL on error) */
492 bits
= (BYTE
*)0xdeadbeef;
493 hdib
= CreateDIBSection(hdc
, NULL
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
494 ok(hdib
== NULL
&& bits
== NULL
, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
496 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
497 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
498 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
499 ok(dibsec
.dsBm
.bmBits
== bits
, "dibsec.dsBits %p != bits %p\n", dibsec
.dsBm
.bmBits
, bits
);
501 /* test the DIB memory */
502 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
503 "VirtualQuery failed\n");
504 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
505 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
506 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
507 ok(info
.RegionSize
== 0x26000, "0x%lx != 0x26000\n", info
.RegionSize
);
508 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
509 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
510 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
512 test_dib_bits_access( hdib
, bits
);
514 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
517 /* Test a top-down DIB. */
518 pbmi
->bmiHeader
.biHeight
= -100;
519 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
520 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
521 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
524 pbmi
->bmiHeader
.biHeight
= 100;
525 pbmi
->bmiHeader
.biBitCount
= 8;
526 pbmi
->bmiHeader
.biCompression
= BI_RLE8
;
527 SetLastError(0xdeadbeef);
528 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
529 ok(hdib
== NULL
, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
530 ok(GetLastError() == 0xdeadbeef, "wrong error %d\n", GetLastError());
532 for (i
= 0; i
< 128; i
++)
534 pbmi
->bmiHeader
.biBitCount
= i
;
535 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
536 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
537 if (i
== 1 || i
== 4 || i
== 8 || i
== 16 || i
== 24 || i
== 32)
538 ok(hdib
!= NULL
, "CreateDIBSection bpp %u\n", i
);
540 ok(hdib
== NULL
, "CreateDIBSection bpp %u succeeded\n", i
);
541 if (hdib
) DeleteObject( hdib
);
544 pbmi
->bmiHeader
.biBitCount
= 16;
545 pbmi
->bmiHeader
.biCompression
= BI_BITFIELDS
;
546 ((PDWORD
)pbmi
->bmiColors
)[0] = 0xf800;
547 ((PDWORD
)pbmi
->bmiColors
)[1] = 0x07e0;
548 ((PDWORD
)pbmi
->bmiColors
)[2] = 0x001f;
549 SetLastError(0xdeadbeef);
550 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
551 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
553 /* test the DIB memory */
554 ok(VirtualQuery(bits
, &info
, sizeof(info
)) == sizeof(info
),
555 "VirtualQuery failed\n");
556 ok(info
.BaseAddress
== bits
, "%p != %p\n", info
.BaseAddress
, bits
);
557 ok(info
.AllocationBase
== bits
, "%p != %p\n", info
.AllocationBase
, bits
);
558 ok(info
.AllocationProtect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.AllocationProtect
);
559 ok(info
.RegionSize
== 0x19000, "0x%lx != 0x19000\n", info
.RegionSize
);
560 ok(info
.State
== MEM_COMMIT
, "%x != MEM_COMMIT\n", info
.State
);
561 ok(info
.Protect
== PAGE_READWRITE
, "%x != PAGE_READWRITE\n", info
.Protect
);
562 ok(info
.Type
== MEM_PRIVATE
, "%x != MEM_PRIVATE\n", info
.Type
);
564 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
567 memset(pbmi
, 0, sizeof(bmibuf
));
568 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
569 pbmi
->bmiHeader
.biHeight
= 16;
570 pbmi
->bmiHeader
.biWidth
= 16;
571 pbmi
->bmiHeader
.biBitCount
= 1;
572 pbmi
->bmiHeader
.biPlanes
= 1;
573 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
574 pbmi
->bmiColors
[0].rgbRed
= 0xff;
575 pbmi
->bmiColors
[0].rgbGreen
= 0;
576 pbmi
->bmiColors
[0].rgbBlue
= 0;
577 pbmi
->bmiColors
[1].rgbRed
= 0;
578 pbmi
->bmiColors
[1].rgbGreen
= 0;
579 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
581 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
582 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
583 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIBSection\n");
584 ok(dibsec
.dsBmih
.biClrUsed
== 2,
585 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
587 /* Test if the old BITMAPCOREINFO structure is supported */
589 pbci
->bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
590 pbci
->bmciHeader
.bcBitCount
= 0;
592 ret
= GetDIBits(hdc
, hdib
, 0, 16, NULL
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
593 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
594 ok((pbci
->bmciHeader
.bcWidth
== 16) && (pbci
->bmciHeader
.bcHeight
== 16)
595 && (pbci
->bmciHeader
.bcBitCount
== 1) && (pbci
->bmciHeader
.bcPlanes
== 1),
596 "GetDIBits did't fill in the BITMAPCOREHEADER structure properly\n");
598 ret
= GetDIBits(hdc
, hdib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
599 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
600 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
601 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
602 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
603 "The color table has not been translated to the old BITMAPCOREINFO format\n");
605 hcoredib
= CreateDIBSection(hdc
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
606 ok(hcoredib
!= NULL
, "CreateDIBSection failed with a BITMAPCOREINFO\n");
608 ZeroMemory(pbci
->bmciColors
, 256 * sizeof(RGBTRIPLE
));
609 ret
= GetDIBits(hdc
, hcoredib
, 0, 16, &coreBits
, (BITMAPINFO
*) pbci
, DIB_RGB_COLORS
);
610 ok(ret
, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
611 ok((pbci
->bmciColors
[0].rgbtRed
== 0xff) && (pbci
->bmciColors
[0].rgbtGreen
== 0) &&
612 (pbci
->bmciColors
[0].rgbtBlue
== 0) && (pbci
->bmciColors
[1].rgbtRed
== 0) &&
613 (pbci
->bmciColors
[1].rgbtGreen
== 0) && (pbci
->bmciColors
[1].rgbtBlue
== 0xff),
614 "The color table has not been translated to the old BITMAPCOREINFO format\n");
616 DeleteObject(hcoredib
);
618 hdcmem
= CreateCompatibleDC(hdc
);
619 oldbm
= SelectObject(hdcmem
, hdib
);
621 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
622 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
623 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
624 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
625 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
626 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
628 c0
= RGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
, pbmi
->bmiColors
[0].rgbBlue
);
629 c1
= RGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
, pbmi
->bmiColors
[1].rgbBlue
);
631 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
632 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
633 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
634 test_color(hdcmem
, PALETTEINDEX(0), c0
, 1, 1);
635 test_color(hdcmem
, PALETTEINDEX(1), c0
, 1, 1);
636 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
637 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[0].rgbRed
, pbmi
->bmiColors
[0].rgbGreen
,
638 pbmi
->bmiColors
[0].rgbBlue
), c0
, 1, 1);
639 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[1].rgbRed
, pbmi
->bmiColors
[1].rgbGreen
,
640 pbmi
->bmiColors
[1].rgbBlue
), c1
, 1, 1);
641 test_color(hdcmem
, PALETTERGB(0, 0, 0), c0
, 1, 1);
642 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
643 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c1
, 1, 1);
645 SelectObject(hdcmem
, oldbm
);
648 pbmi
->bmiColors
[0].rgbRed
= 0xff;
649 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
650 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
651 pbmi
->bmiColors
[1].rgbRed
= 0;
652 pbmi
->bmiColors
[1].rgbGreen
= 0;
653 pbmi
->bmiColors
[1].rgbBlue
= 0;
655 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
656 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
658 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
660 oldbm
= SelectObject(hdcmem
, hdib
);
662 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
663 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
664 ok(!memcmp(rgb
, pbmi
->bmiColors
, 2 * sizeof(RGBQUAD
)),
665 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
666 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
667 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
669 SelectObject(hdcmem
, oldbm
);
670 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
673 pbmi
->bmiHeader
.biBitCount
= 4;
674 for (i
= 0; i
< 16; i
++) {
675 pbmi
->bmiColors
[i
].rgbRed
= i
;
676 pbmi
->bmiColors
[i
].rgbGreen
= 16-i
;
677 pbmi
->bmiColors
[i
].rgbBlue
= 0;
679 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
680 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
681 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
682 ok(dibsec
.dsBmih
.biClrUsed
== 16,
683 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 16);
684 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
687 pbmi
->bmiHeader
.biBitCount
= 8;
689 for (i
= 0; i
< 128; i
++) {
690 pbmi
->bmiColors
[i
].rgbRed
= 255 - i
* 2;
691 pbmi
->bmiColors
[i
].rgbGreen
= i
* 2;
692 pbmi
->bmiColors
[i
].rgbBlue
= 0;
693 pbmi
->bmiColors
[255 - i
].rgbRed
= 0;
694 pbmi
->bmiColors
[255 - i
].rgbGreen
= i
* 2;
695 pbmi
->bmiColors
[255 - i
].rgbBlue
= 255 - i
* 2;
697 hdib
= CreateDIBSection(hdcmem
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
698 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
699 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
700 ok(dibsec
.dsBmih
.biClrUsed
== 256,
701 "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
703 oldbm
= SelectObject(hdcmem
, hdib
);
705 for (i
= 0; i
< 256; i
++) {
706 test_color(hdcmem
, DIBINDEX(i
),
707 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
708 test_color(hdcmem
, PALETTERGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
),
709 RGB(pbmi
->bmiColors
[i
].rgbRed
, pbmi
->bmiColors
[i
].rgbGreen
, pbmi
->bmiColors
[i
].rgbBlue
), 0, 0);
712 SelectObject(hdcmem
, oldbm
);
713 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
716 pbmi
->bmiHeader
.biBitCount
= 1;
718 /* Now create a palette and a palette indexed dib section */
719 memset(plogpal
, 0, sizeof(logpalbuf
));
720 plogpal
->palVersion
= 0x300;
721 plogpal
->palNumEntries
= 2;
722 plogpal
->palPalEntry
[0].peRed
= 0xff;
723 plogpal
->palPalEntry
[0].peBlue
= 0xff;
724 plogpal
->palPalEntry
[1].peGreen
= 0xff;
726 index
= (WORD
*)pbmi
->bmiColors
;
729 hpal
= CreatePalette(plogpal
);
730 ok(hpal
!= NULL
, "CreatePalette failed\n");
731 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
732 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
733 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
734 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
735 ok(dibsec
.dsBmih
.biClrUsed
== 2, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 2);
737 /* The colour table has already been grabbed from the dc, so we select back the
740 SelectPalette(hdc
, oldpal
, TRUE
);
741 oldbm
= SelectObject(hdcmem
, hdib
);
742 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
744 ret
= GetDIBColorTable(hdcmem
, 0, 2, rgb
);
745 ok(ret
== 2, "GetDIBColorTable returned %d\n", ret
);
746 ok(rgb
[0].rgbRed
== 0xff && rgb
[0].rgbBlue
== 0xff && rgb
[0].rgbGreen
== 0 &&
747 rgb
[1].rgbRed
== 0 && rgb
[1].rgbBlue
== 0 && rgb
[1].rgbGreen
== 0xff,
748 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
749 rgb
[0].rgbRed
, rgb
[0].rgbGreen
, rgb
[0].rgbBlue
, rgb
[0].rgbReserved
,
750 rgb
[1].rgbRed
, rgb
[1].rgbGreen
, rgb
[1].rgbBlue
, rgb
[1].rgbReserved
);
752 c0
= RGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
, plogpal
->palPalEntry
[0].peBlue
);
753 c1
= RGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
, plogpal
->palPalEntry
[1].peBlue
);
755 test_color(hdcmem
, DIBINDEX(0), c0
, 0, 1);
756 test_color(hdcmem
, DIBINDEX(1), c1
, 0, 1);
757 test_color(hdcmem
, DIBINDEX(2), c0
, 1, 1);
758 test_color(hdcmem
, PALETTEINDEX(0), c0
, 0, 1);
759 test_color(hdcmem
, PALETTEINDEX(1), c1
, 0, 1);
760 test_color(hdcmem
, PALETTEINDEX(2), c0
, 1, 1);
761 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[0].peRed
, plogpal
->palPalEntry
[0].peGreen
,
762 plogpal
->palPalEntry
[0].peBlue
), c0
, 1, 1);
763 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[1].peRed
, plogpal
->palPalEntry
[1].peGreen
,
764 plogpal
->palPalEntry
[1].peBlue
), c1
, 1, 1);
765 test_color(hdcmem
, PALETTERGB(0, 0, 0), c1
, 1, 1);
766 test_color(hdcmem
, PALETTERGB(0xff, 0xff, 0xff), c0
, 1, 1);
767 test_color(hdcmem
, PALETTERGB(0, 0, 0xfe), c0
, 1, 1);
768 test_color(hdcmem
, PALETTERGB(0, 1, 0), c1
, 1, 1);
769 test_color(hdcmem
, PALETTERGB(0x3f, 0, 0x3f), c1
, 1, 1);
770 test_color(hdcmem
, PALETTERGB(0x40, 0, 0x40), c0
, 1, 1);
772 /* Bottom and 2nd row from top green, everything else magenta */
773 bits
[0] = bits
[1] = 0xff;
774 bits
[13 * 4] = bits
[13*4 + 1] = 0xff;
776 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
778 pbmi
->bmiHeader
.biBitCount
= 32;
780 hdib2
= CreateDIBSection(NULL
, pbmi
, DIB_RGB_COLORS
, (void **)&bits32
, NULL
, 0);
781 ok(hdib2
!= NULL
, "CreateDIBSection failed\n");
782 hdcmem2
= CreateCompatibleDC(hdc
);
783 oldbm2
= SelectObject(hdcmem2
, hdib2
);
785 BitBlt(hdcmem2
, 0, 0, 16,16, hdcmem
, 0, 0, SRCCOPY
);
787 ok(bits32
[0] == 0xff00, "lower left pixel is %08x\n", bits32
[0]);
788 ok(bits32
[17] == 0xff00ff, "bottom but one, left pixel is %08x\n", bits32
[17]);
790 SelectObject(hdcmem2
, oldbm2
);
791 test_dib_info(hdib2
, bits32
, &pbmi
->bmiHeader
);
794 SelectObject(hdcmem
, oldbm
);
795 SelectObject(hdcmem
, oldpal
);
800 pbmi
->bmiHeader
.biBitCount
= 8;
802 memset(plogpal
, 0, sizeof(logpalbuf
));
803 plogpal
->palVersion
= 0x300;
804 plogpal
->palNumEntries
= 256;
806 for (i
= 0; i
< 128; i
++) {
807 plogpal
->palPalEntry
[i
].peRed
= 255 - i
* 2;
808 plogpal
->palPalEntry
[i
].peBlue
= i
* 2;
809 plogpal
->palPalEntry
[i
].peGreen
= 0;
810 plogpal
->palPalEntry
[255 - i
].peRed
= 0;
811 plogpal
->palPalEntry
[255 - i
].peGreen
= i
* 2;
812 plogpal
->palPalEntry
[255 - i
].peBlue
= 255 - i
* 2;
815 index
= (WORD
*)pbmi
->bmiColors
;
816 for (i
= 0; i
< 256; i
++) {
820 hpal
= CreatePalette(plogpal
);
821 ok(hpal
!= NULL
, "CreatePalette failed\n");
822 oldpal
= SelectPalette(hdc
, hpal
, TRUE
);
823 hdib
= CreateDIBSection(hdc
, pbmi
, DIB_PAL_COLORS
, (void**)&bits
, NULL
, 0);
824 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
825 ok(GetObject(hdib
, sizeof(DIBSECTION
), &dibsec
) != 0, "GetObject failed for DIB Section\n");
826 ok(dibsec
.dsBmih
.biClrUsed
== 256, "created DIBSection: wrong biClrUsed field: %u, should be: %u\n", dibsec
.dsBmih
.biClrUsed
, 256);
828 test_dib_info(hdib
, bits
, &pbmi
->bmiHeader
);
830 SelectPalette(hdc
, oldpal
, TRUE
);
831 oldbm
= SelectObject(hdcmem
, hdib
);
832 oldpal
= SelectPalette(hdcmem
, hpal
, TRUE
);
834 ret
= GetDIBColorTable(hdcmem
, 0, 256, rgb
);
835 ok(ret
== 256, "GetDIBColorTable returned %d\n", ret
);
836 for (i
= 0; i
< 256; i
++) {
837 ok(rgb
[i
].rgbRed
== plogpal
->palPalEntry
[i
].peRed
&&
838 rgb
[i
].rgbBlue
== plogpal
->palPalEntry
[i
].peBlue
&&
839 rgb
[i
].rgbGreen
== plogpal
->palPalEntry
[i
].peGreen
,
840 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
841 i
, rgb
[i
].rgbRed
, rgb
[i
].rgbGreen
, rgb
[i
].rgbBlue
, rgb
[i
].rgbReserved
);
844 for (i
= 0; i
< 256; i
++) {
845 test_color(hdcmem
, DIBINDEX(i
),
846 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
847 test_color(hdcmem
, PALETTEINDEX(i
),
848 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
849 test_color(hdcmem
, PALETTERGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
),
850 RGB(plogpal
->palPalEntry
[i
].peRed
, plogpal
->palPalEntry
[i
].peGreen
, plogpal
->palPalEntry
[i
].peBlue
), 0, 0);
853 SelectPalette(hdcmem
, oldpal
, TRUE
);
854 SelectObject(hdcmem
, oldbm
);
863 static void test_mono_dibsection(void)
866 HBITMAP old_bm
, mono_ds
;
867 char bmibuf
[sizeof(BITMAPINFO
) + 256 * sizeof(RGBQUAD
)];
868 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
875 memdc
= CreateCompatibleDC(hdc
);
877 memset(pbmi
, 0, sizeof(bmibuf
));
878 pbmi
->bmiHeader
.biSize
= sizeof(pbmi
->bmiHeader
);
879 pbmi
->bmiHeader
.biHeight
= 10;
880 pbmi
->bmiHeader
.biWidth
= 10;
881 pbmi
->bmiHeader
.biBitCount
= 1;
882 pbmi
->bmiHeader
.biPlanes
= 1;
883 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
884 pbmi
->bmiColors
[0].rgbRed
= 0xff;
885 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
886 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
887 pbmi
->bmiColors
[1].rgbRed
= 0x0;
888 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
889 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
892 * First dib section is 'inverted' ie color[0] is white, color[1] is black
895 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
896 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
897 old_bm
= SelectObject(memdc
, mono_ds
);
899 /* black border, white interior */
900 Rectangle(memdc
, 0, 0, 10, 10);
901 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
902 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
904 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
906 memset(bits
, 0, sizeof(bits
));
909 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
910 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
912 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
914 pbmi
->bmiColors
[0].rgbRed
= 0x0;
915 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
916 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
917 pbmi
->bmiColors
[1].rgbRed
= 0xff;
918 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
919 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
921 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
922 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
924 SelectObject(memdc
, old_bm
);
925 DeleteObject(mono_ds
);
928 * Next dib section is 'normal' ie color[0] is black, color[1] is white
931 pbmi
->bmiColors
[0].rgbRed
= 0x0;
932 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
933 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
934 pbmi
->bmiColors
[1].rgbRed
= 0xff;
935 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
936 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
938 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
939 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
940 old_bm
= SelectObject(memdc
, mono_ds
);
942 /* black border, white interior */
943 Rectangle(memdc
, 0, 0, 10, 10);
944 ok(ds_bits
[0] == 0x00, "out_bits %02x\n", ds_bits
[0]);
945 ok(ds_bits
[4] == 0x7f, "out_bits %02x\n", ds_bits
[4]);
947 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
949 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
950 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
952 /* SetDIBitsToDevice with a inverted bmi -> normal dib section */
954 pbmi
->bmiColors
[0].rgbRed
= 0xff;
955 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
956 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
957 pbmi
->bmiColors
[1].rgbRed
= 0x0;
958 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
959 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
961 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
962 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
965 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
968 pbmi
->bmiColors
[0].rgbRed
= 0xff;
969 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
970 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
971 pbmi
->bmiColors
[1].rgbRed
= 0x0;
972 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
973 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
974 num
= SetDIBColorTable(memdc
, 0, 2, pbmi
->bmiColors
);
975 ok(num
== 2, "num = %d\n", num
);
977 /* black border, white interior */
978 Rectangle(memdc
, 0, 0, 10, 10);
980 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
981 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
983 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
985 memset(bits
, 0, sizeof(bits
));
988 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
989 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
991 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
993 pbmi
->bmiColors
[0].rgbRed
= 0x0;
994 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
995 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
996 pbmi
->bmiColors
[1].rgbRed
= 0xff;
997 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
998 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1000 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1001 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1003 SelectObject(memdc
, old_bm
);
1004 DeleteObject(mono_ds
);
1007 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1010 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1011 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1012 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1013 pbmi
->bmiColors
[1].rgbRed
= 0xfe;
1014 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1015 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1017 mono_ds
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&ds_bits
, NULL
, 0);
1018 ok(mono_ds
!= NULL
, "CreateDIBSection rets NULL\n");
1019 old_bm
= SelectObject(memdc
, mono_ds
);
1021 /* black border, white interior */
1022 Rectangle(memdc
, 0, 0, 10, 10);
1023 ok(ds_bits
[0] == 0xff, "out_bits %02x\n", ds_bits
[0]);
1024 ok(ds_bits
[4] == 0x80, "out_bits %02x\n", ds_bits
[4]);
1026 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1028 pbmi
->bmiColors
[0].rgbRed
= 0x0;
1029 pbmi
->bmiColors
[0].rgbGreen
= 0x0;
1030 pbmi
->bmiColors
[0].rgbBlue
= 0x0;
1031 pbmi
->bmiColors
[1].rgbRed
= 0xff;
1032 pbmi
->bmiColors
[1].rgbGreen
= 0xff;
1033 pbmi
->bmiColors
[1].rgbBlue
= 0xff;
1035 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1036 ok(ds_bits
[0] == 0x55, "out_bits %02x\n", ds_bits
[0]);
1038 /* SetDIBitsToDevice with a inverted bmi -> inverted dib section */
1040 pbmi
->bmiColors
[0].rgbRed
= 0xff;
1041 pbmi
->bmiColors
[0].rgbGreen
= 0xff;
1042 pbmi
->bmiColors
[0].rgbBlue
= 0xff;
1043 pbmi
->bmiColors
[1].rgbRed
= 0x0;
1044 pbmi
->bmiColors
[1].rgbGreen
= 0x0;
1045 pbmi
->bmiColors
[1].rgbBlue
= 0x0;
1047 SetDIBitsToDevice(memdc
, 0, 0, 10, 10, 0, 0, 0, 10, bits
, pbmi
, DIB_RGB_COLORS
);
1048 ok(ds_bits
[0] == 0xaa, "out_bits %02x\n", ds_bits
[0]);
1050 SelectObject(memdc
, old_bm
);
1051 DeleteObject(mono_ds
);
1057 static void test_bitmap(void)
1059 char buf
[256], buf_cmp
[256];
1060 HBITMAP hbmp
, hbmp_old
;
1066 hdc
= CreateCompatibleDC(0);
1069 SetLastError(0xdeadbeef);
1070 hbmp
= CreateBitmap(0x7ffffff, 1, 1, 1, NULL
);
1073 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1074 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1075 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1080 SetLastError(0xdeadbeef);
1081 hbmp
= CreateBitmap(0x7ffffff, 9, 1, 1, NULL
);
1084 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
/* XP */ ||
1085 GetLastError() == ERROR_INVALID_PARAMETER
/* Win2k */,
1086 "expected ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError());
1091 SetLastError(0xdeadbeef);
1092 hbmp
= CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL
);
1093 ok(!hbmp
, "CreateBitmap should fail\n");
1095 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1096 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1100 hbmp
= CreateBitmap(15, 15, 1, 1, NULL
);
1101 assert(hbmp
!= NULL
);
1103 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1104 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1106 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1107 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1108 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1109 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1110 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1111 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1112 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1114 assert(sizeof(buf
) >= bm
.bmWidthBytes
* bm
.bmHeight
);
1115 assert(sizeof(buf
) == sizeof(buf_cmp
));
1117 ret
= GetBitmapBits(hbmp
, 0, NULL
);
1118 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1120 memset(buf_cmp
, 0xAA, sizeof(buf_cmp
));
1121 memset(buf_cmp
, 0, bm
.bmWidthBytes
* bm
.bmHeight
);
1123 memset(buf
, 0xAA, sizeof(buf
));
1124 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1125 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1126 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
1128 hbmp_old
= SelectObject(hdc
, hbmp
);
1130 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
1131 ok(ret
== sizeof(bm
), "wrong size %d\n", ret
);
1133 ok(bm
.bmType
== 0, "wrong bm.bmType %d\n", bm
.bmType
);
1134 ok(bm
.bmWidth
== 15, "wrong bm.bmWidth %d\n", bm
.bmWidth
);
1135 ok(bm
.bmHeight
== 15, "wrong bm.bmHeight %d\n", bm
.bmHeight
);
1136 ok(bm
.bmWidthBytes
== 2, "wrong bm.bmWidthBytes %d\n", bm
.bmWidthBytes
);
1137 ok(bm
.bmPlanes
== 1, "wrong bm.bmPlanes %d\n", bm
.bmPlanes
);
1138 ok(bm
.bmBitsPixel
== 1, "wrong bm.bmBitsPixel %d\n", bm
.bmBitsPixel
);
1139 ok(bm
.bmBits
== NULL
, "wrong bm.bmBits %p\n", bm
.bmBits
);
1141 memset(buf
, 0xAA, sizeof(buf
));
1142 ret
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1143 ok(ret
== bm
.bmWidthBytes
* bm
.bmHeight
, "%d != %d\n", ret
, bm
.bmWidthBytes
* bm
.bmHeight
);
1144 ok(!memcmp(buf
, buf_cmp
, sizeof(buf
)), "buffers do not match\n");
1146 hbmp_old
= SelectObject(hdc
, hbmp_old
);
1147 ok(hbmp_old
== hbmp
, "wrong old bitmap %p\n", hbmp_old
);
1149 /* test various buffer sizes for GetObject */
1150 ret
= GetObject(hbmp
, sizeof(*bma
) * 2, bma
);
1151 ok(ret
== sizeof(*bma
), "wrong size %d\n", ret
);
1153 ret
= GetObject(hbmp
, sizeof(bm
) / 2, &bm
);
1154 ok(ret
== 0, "%d != 0\n", ret
);
1156 ret
= GetObject(hbmp
, 0, &bm
);
1157 ok(ret
== 0, "%d != 0\n", ret
);
1159 ret
= GetObject(hbmp
, 1, &bm
);
1160 ok(ret
== 0, "%d != 0\n", ret
);
1166 static void test_bmBits(void)
1172 memset(bits
, 0, sizeof(bits
));
1173 hbmp
= CreateBitmap(2, 2, 1, 4, bits
);
1174 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
1176 memset(&bmp
, 0xFF, sizeof(bmp
));
1177 ok(GetObject(hbmp
, sizeof(bmp
), &bmp
) == sizeof(bmp
),
1178 "GetObject failed or returned a wrong structure size\n");
1179 ok(!bmp
.bmBits
, "bmBits must be NULL for device-dependent bitmaps\n");
1184 static void test_GetDIBits_selected_DIB(UINT bpp
)
1191 UINT dib_size
, dib32_size
;
1199 /* Create a DIB section with a color table */
1201 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1202 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + (1 << bpp
) * sizeof(RGBQUAD
));
1206 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1208 /* Choose width and height such that the row length (in bytes)
1209 is a multiple of 4 (makes things easier) */
1210 info
->bmiHeader
.biWidth
= 32;
1211 info
->bmiHeader
.biHeight
= 32;
1212 info
->bmiHeader
.biPlanes
= 1;
1213 info
->bmiHeader
.biBitCount
= bpp
;
1214 info
->bmiHeader
.biCompression
= BI_RGB
;
1216 for (i
=0; i
< (1u << bpp
); i
++)
1218 BYTE c
= i
* (1 << (8 - bpp
));
1219 info
->bmiColors
[i
].rgbRed
= c
;
1220 info
->bmiColors
[i
].rgbGreen
= c
;
1221 info
->bmiColors
[i
].rgbBlue
= c
;
1222 info
->bmiColors
[i
].rgbReserved
= 0;
1225 dib
= CreateDIBSection(NULL
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1227 dib_size
= bpp
* (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1228 dib32_size
= 32 * (info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
) / 8;
1230 /* Set the bits of the DIB section */
1231 for (i
=0; i
< dib_size
; i
++)
1233 ((BYTE
*)bits
)[i
] = i
% 256;
1236 /* Select the DIB into a DC */
1237 dib_dc
= CreateCompatibleDC(NULL
);
1238 old_bmp
= SelectObject(dib_dc
, dib
);
1239 dc
= CreateCompatibleDC(NULL
);
1240 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dib32_size
);
1243 /* Copy the DIB attributes but not the color table */
1244 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1246 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1247 ok(res
, "GetDIBits failed\n");
1249 /* Compare the color table and the bits */
1250 equalContents
= TRUE
;
1251 for (i
=0; i
< (1u << bpp
); i
++)
1253 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1254 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1255 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1256 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1258 equalContents
= FALSE
;
1262 ok(equalContents
, "GetDIBits with DIB selected in DC: Invalid DIB color table\n");
1264 equalContents
= TRUE
;
1265 for (i
=0; i
< dib_size
/ sizeof(DWORD
); i
++)
1267 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1269 equalContents
= FALSE
;
1273 ok(equalContents
, "GetDIBits with %d bpp DIB selected in DC: Invalid DIB bits\n",bpp
);
1275 /* Map into a 32bit-DIB */
1276 info2
->bmiHeader
.biBitCount
= 32;
1277 res
= GetDIBits(dc
, dib
, 0, info
->bmiHeader
.biHeight
, bits2
, info2
, DIB_RGB_COLORS
);
1278 ok(res
, "GetDIBits failed\n");
1280 /* Check if last pixel was set */
1281 pixel
= ((DWORD
*)bits2
)[info
->bmiHeader
.biWidth
* info
->bmiHeader
.biHeight
- 1];
1282 ok(pixel
!= 0, "Pixel: 0x%08x\n", pixel
);
1284 HeapFree(GetProcessHeap(), 0, bits2
);
1287 SelectObject(dib_dc
, old_bmp
);
1291 HeapFree(GetProcessHeap(), 0, info2
);
1292 HeapFree(GetProcessHeap(), 0, info
);
1295 static void test_GetDIBits_selected_DDB(BOOL monochrome
)
1310 width
= height
= 16;
1312 /* Create a DDB (device-dependent bitmap) */
1316 ddb
= CreateBitmap(width
, height
, 1, 1, NULL
);
1320 HDC screen_dc
= GetDC(NULL
);
1321 bpp
= GetDeviceCaps(screen_dc
, BITSPIXEL
) * GetDeviceCaps(screen_dc
, PLANES
);
1322 ddb
= CreateCompatibleBitmap(screen_dc
, width
, height
);
1323 ReleaseDC(NULL
, screen_dc
);
1326 /* Set the pixels */
1327 ddb_dc
= CreateCompatibleDC(NULL
);
1328 old_bmp
= SelectObject(ddb_dc
, ddb
);
1329 for (i
= 0; i
< width
; i
++)
1331 for (j
=0; j
< height
; j
++)
1333 BYTE c
= (i
* width
+ j
) % 256;
1334 SetPixelV(ddb_dc
, i
, j
, RGB(c
, c
, c
));
1337 SelectObject(ddb_dc
, old_bmp
);
1339 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1340 info2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1344 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
1345 info
->bmiHeader
.biWidth
= width
;
1346 info
->bmiHeader
.biHeight
= height
;
1347 info
->bmiHeader
.biPlanes
= 1;
1348 info
->bmiHeader
.biBitCount
= bpp
;
1349 info
->bmiHeader
.biCompression
= BI_RGB
;
1351 dc
= CreateCompatibleDC(NULL
);
1353 /* Fill in biSizeImage */
1354 GetDIBits(dc
, ddb
, 0, height
, NULL
, info
, DIB_RGB_COLORS
);
1355 ok(info
->bmiHeader
.biSizeImage
!= 0, "GetDIBits failed to get the DIB attributes\n");
1357 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1358 bits2
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info
->bmiHeader
.biSizeImage
);
1363 res
= GetDIBits(dc
, ddb
, 0, height
, bits
, info
, DIB_RGB_COLORS
);
1364 ok(res
, "GetDIBits failed\n");
1366 /* Copy the DIB attributes but not the color table */
1367 memcpy(info2
, info
, sizeof(BITMAPINFOHEADER
));
1369 /* Select the DDB into another DC */
1370 old_bmp
= SelectObject(ddb_dc
, ddb
);
1373 res
= GetDIBits(dc
, ddb
, 0, height
, bits2
, info2
, DIB_RGB_COLORS
);
1374 ok(res
, "GetDIBits failed\n");
1376 /* Compare the color table and the bits */
1379 equalContents
= TRUE
;
1380 for (i
=0; i
< (1u << bpp
); i
++)
1382 if ((info
->bmiColors
[i
].rgbRed
!= info2
->bmiColors
[i
].rgbRed
)
1383 || (info
->bmiColors
[i
].rgbGreen
!= info2
->bmiColors
[i
].rgbGreen
)
1384 || (info
->bmiColors
[i
].rgbBlue
!= info2
->bmiColors
[i
].rgbBlue
)
1385 || (info
->bmiColors
[i
].rgbReserved
!= info2
->bmiColors
[i
].rgbReserved
))
1387 equalContents
= FALSE
;
1391 ok(equalContents
, "GetDIBits with DDB selected in DC: Got a different color table\n");
1394 equalContents
= TRUE
;
1395 for (i
=0; i
< info
->bmiHeader
.biSizeImage
/ sizeof(DWORD
); i
++)
1397 if (((DWORD
*)bits
)[i
] != ((DWORD
*)bits2
)[i
])
1399 equalContents
= FALSE
;
1402 ok(equalContents
, "GetDIBits with DDB selected in DC: Got different DIB bits\n");
1404 /* Test the palette */
1405 equalContents
= TRUE
;
1406 if (info2
->bmiHeader
.biBitCount
<= 8)
1408 WORD
*colors
= (WORD
*)info2
->bmiColors
;
1410 /* Get the palette indices */
1411 res
= GetDIBits(dc
, ddb
, 0, 0, NULL
, info2
, DIB_PAL_COLORS
);
1412 ok(res
, "GetDIBits failed\n");
1414 for (i
=0;i
< 1 << info
->bmiHeader
.biSizeImage
; i
++)
1418 equalContents
= FALSE
;
1424 ok(equalContents
, "GetDIBits with DDB selected in DC: non 1:1 palette indices\n");
1426 HeapFree(GetProcessHeap(), 0, bits2
);
1427 HeapFree(GetProcessHeap(), 0, bits
);
1430 SelectObject(ddb_dc
, old_bmp
);
1434 HeapFree(GetProcessHeap(), 0, info2
);
1435 HeapFree(GetProcessHeap(), 0, info
);
1438 static void test_GetDIBits(void)
1440 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
1441 static const BYTE bmp_bits_1
[16 * 2] =
1443 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1444 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1445 0xff,0xff, 0,0, 0xff,0xff, 0,0,
1446 0xff,0xff, 0,0, 0xff,0xff, 0,0
1448 /* 4-bytes aligned 1-bit DIB data: 16x16 */
1449 static const BYTE dib_bits_1
[16 * 4] =
1451 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1452 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1453 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
1454 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
1456 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
1457 static const BYTE bmp_bits_24
[16 * 16*3] =
1459 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1460 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1461 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1462 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1463 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1464 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1465 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1466 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1467 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1468 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1469 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1470 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1471 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1472 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1473 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1474 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1475 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1476 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1477 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1478 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1479 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1480 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1481 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1482 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1483 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1484 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1485 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1486 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1487 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1488 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1489 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1490 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1492 /* 4-bytes aligned 24-bit DIB data: 16x16 */
1493 static const BYTE dib_bits_24
[16 * 16*3] =
1495 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1496 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1497 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1498 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1499 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1500 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1501 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1502 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1503 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1504 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1505 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1506 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1507 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1508 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1509 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1510 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1511 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1512 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1513 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1514 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1515 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1516 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1517 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1518 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1519 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1520 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1521 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1522 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1523 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1524 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1525 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
1526 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1531 int i
, bytes
, lines
;
1533 char bi_buf
[sizeof(BITMAPINFOHEADER
) + sizeof(RGBQUAD
) * 256];
1534 BITMAPINFO
*bi
= (BITMAPINFO
*)bi_buf
;
1538 /* 1-bit source bitmap data */
1539 hbmp
= CreateBitmap(16, 16, 1, 1, bmp_bits_1
);
1540 ok(hbmp
!= 0, "CreateBitmap failed\n");
1542 memset(&bm
, 0xAA, sizeof(bm
));
1543 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1544 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1545 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1546 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1547 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1548 ok(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1549 ok(bm
.bmPlanes
== 1, "wrong bmPlanes %u\n", bm
.bmPlanes
);
1550 ok(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1551 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1553 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1554 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1555 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1556 ok(bytes
== sizeof(bmp_bits_1
), "expected 16*2 got %d bytes\n", bytes
);
1557 ok(!memcmp(buf
, bmp_bits_1
, sizeof(bmp_bits_1
)), "bitmap bits don't match\n");
1559 /* retrieve 1-bit DIB data */
1560 memset(bi
, 0, sizeof(*bi
));
1561 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1562 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1563 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1564 bi
->bmiHeader
.biPlanes
= 1;
1565 bi
->bmiHeader
.biBitCount
= 1;
1566 bi
->bmiHeader
.biCompression
= BI_RGB
;
1567 bi
->bmiHeader
.biSizeImage
= 0;
1568 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1569 SetLastError(0xdeadbeef);
1570 lines
= GetDIBits(0, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1571 ok(lines
== 0, "GetDIBits copied %d lines with hdc = 0\n", lines
);
1572 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
1573 broken(GetLastError() == 0xdeadbeef), /* winnt */
1574 "wrong error %u\n", GetLastError());
1575 ok(bi
->bmiHeader
.biSizeImage
== 0, "expected 0, got %u\n", bi
->bmiHeader
.biSizeImage
);
1577 memset(buf
, 0xAA, sizeof(buf
));
1578 SetLastError(0xdeadbeef);
1579 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1580 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1581 lines
, bm
.bmHeight
, GetLastError());
1582 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
), "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1584 /* the color table consists of black and white */
1585 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1586 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1587 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1588 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1589 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1590 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1591 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1592 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1593 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1594 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1595 for (i
= 2; i
< 256; i
++)
1597 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1598 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1599 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1600 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1601 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1604 /* returned bits are DWORD aligned and upside down */
1605 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)), "DIB bits don't match\n");
1607 /* Test the palette indices */
1608 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1609 SetLastError(0xdeadbeef);
1610 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1611 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1612 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1613 for (i
= 2; i
< 256; i
++)
1614 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[1]);
1616 /* retrieve 24-bit DIB data */
1617 memset(bi
, 0, sizeof(*bi
));
1618 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1619 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1620 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1621 bi
->bmiHeader
.biPlanes
= 1;
1622 bi
->bmiHeader
.biBitCount
= 24;
1623 bi
->bmiHeader
.biCompression
= BI_RGB
;
1624 bi
->bmiHeader
.biSizeImage
= 0;
1625 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1626 memset(buf
, 0xAA, sizeof(buf
));
1627 SetLastError(0xdeadbeef);
1628 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1629 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1630 lines
, bm
.bmHeight
, GetLastError());
1631 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
), "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1633 /* the color table doesn't exist for 24-bit images */
1634 for (i
= 0; i
< 256; i
++)
1636 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1637 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1638 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1639 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1640 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1643 /* returned bits are DWORD aligned and upside down */
1644 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1647 /* 24-bit source bitmap data */
1648 hbmp
= CreateCompatibleBitmap(hdc
, 16, 16);
1649 ok(hbmp
!= 0, "CreateBitmap failed\n");
1650 SetLastError(0xdeadbeef);
1651 bi
->bmiHeader
.biHeight
= -bm
.bmHeight
; /* indicate bottom-up data */
1652 lines
= SetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, bmp_bits_24
, bi
, DIB_RGB_COLORS
);
1653 ok(lines
== bm
.bmHeight
, "SetDIBits copied %d lines of %d, error %u\n",
1654 lines
, bm
.bmHeight
, GetLastError());
1656 memset(&bm
, 0xAA, sizeof(bm
));
1657 bytes
= GetObject(hbmp
, sizeof(bm
), &bm
);
1658 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
1659 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
1660 ok(bm
.bmWidth
== 16, "wrong bmWidth %d\n", bm
.bmWidth
);
1661 ok(bm
.bmHeight
== 16, "wrong bmHeight %d\n", bm
.bmHeight
);
1662 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
1663 ok(bm
.bmPlanes
== GetDeviceCaps(hdc
, PLANES
), "wrong bmPlanes %u\n", bm
.bmPlanes
);
1664 ok(bm
.bmBitsPixel
== GetDeviceCaps(hdc
, BITSPIXEL
), "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
1665 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
1667 bytes
= GetBitmapBits(hbmp
, 0, NULL
);
1668 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n", bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1669 bytes
= GetBitmapBits(hbmp
, sizeof(buf
), buf
);
1670 ok(bytes
== bm
.bmWidthBytes
* bm
.bmHeight
, "expected %d got %d bytes\n",
1671 bm
.bmWidthBytes
* bm
.bmHeight
, bytes
);
1673 /* retrieve 1-bit DIB data */
1674 memset(bi
, 0, sizeof(*bi
));
1675 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1676 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1677 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1678 bi
->bmiHeader
.biPlanes
= 1;
1679 bi
->bmiHeader
.biBitCount
= 1;
1680 bi
->bmiHeader
.biCompression
= BI_RGB
;
1681 bi
->bmiHeader
.biSizeImage
= 0;
1682 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1683 memset(buf
, 0xAA, sizeof(buf
));
1684 SetLastError(0xdeadbeef);
1685 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1686 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1687 lines
, bm
.bmHeight
, GetLastError());
1688 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_1
), "expected 16*4, got %u\n", bi
->bmiHeader
.biSizeImage
);
1690 /* the color table consists of black and white */
1691 ok(bi
->bmiColors
[0].rgbRed
== 0 && bi
->bmiColors
[0].rgbGreen
== 0 &&
1692 bi
->bmiColors
[0].rgbBlue
== 0 && bi
->bmiColors
[0].rgbReserved
== 0,
1693 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
1694 bi
->bmiColors
[0].rgbRed
, bi
->bmiColors
[0].rgbGreen
,
1695 bi
->bmiColors
[0].rgbBlue
, bi
->bmiColors
[0].rgbReserved
);
1696 ok(bi
->bmiColors
[1].rgbRed
== 0xff && bi
->bmiColors
[1].rgbGreen
== 0xff &&
1697 bi
->bmiColors
[1].rgbBlue
== 0xff && bi
->bmiColors
[1].rgbReserved
== 0,
1698 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
1699 bi
->bmiColors
[1].rgbRed
, bi
->bmiColors
[1].rgbGreen
,
1700 bi
->bmiColors
[1].rgbBlue
, bi
->bmiColors
[1].rgbReserved
);
1701 for (i
= 2; i
< 256; i
++)
1703 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1704 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1705 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1706 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1707 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1710 /* returned bits are DWORD aligned and upside down */
1712 ok(!memcmp(buf
, dib_bits_1
, sizeof(dib_bits_1
)), "DIB bits don't match\n");
1714 /* Test the palette indices */
1715 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1716 SetLastError(0xdeadbeef);
1717 lines
= GetDIBits(hdc
, hbmp
, 0, 0, NULL
, bi
, DIB_PAL_COLORS
);
1718 ok(((WORD
*)bi
->bmiColors
)[0] == 0, "Color 0 is %d\n", ((WORD
*)bi
->bmiColors
)[0]);
1719 ok(((WORD
*)bi
->bmiColors
)[1] == 1, "Color 1 is %d\n", ((WORD
*)bi
->bmiColors
)[1]);
1720 for (i
= 2; i
< 256; i
++)
1721 ok(((WORD
*)bi
->bmiColors
)[i
] == 0xAAAA, "Color %d is %d\n", i
, ((WORD
*)bi
->bmiColors
)[i
]);
1723 /* retrieve 24-bit DIB data */
1724 memset(bi
, 0, sizeof(*bi
));
1725 bi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1726 bi
->bmiHeader
.biWidth
= bm
.bmWidth
;
1727 bi
->bmiHeader
.biHeight
= bm
.bmHeight
;
1728 bi
->bmiHeader
.biPlanes
= 1;
1729 bi
->bmiHeader
.biBitCount
= 24;
1730 bi
->bmiHeader
.biCompression
= BI_RGB
;
1731 bi
->bmiHeader
.biSizeImage
= 0;
1732 memset(bi
->bmiColors
, 0xAA, sizeof(RGBQUAD
) * 256);
1733 memset(buf
, 0xAA, sizeof(buf
));
1734 SetLastError(0xdeadbeef);
1735 lines
= GetDIBits(hdc
, hbmp
, 0, bm
.bmHeight
, buf
, bi
, DIB_RGB_COLORS
);
1736 ok(lines
== bm
.bmHeight
, "GetDIBits copied %d lines of %d, error %u\n",
1737 lines
, bm
.bmHeight
, GetLastError());
1738 ok(bi
->bmiHeader
.biSizeImage
== sizeof(dib_bits_24
), "expected 16*16*3, got %u\n", bi
->bmiHeader
.biSizeImage
);
1740 /* the color table doesn't exist for 24-bit images */
1741 for (i
= 0; i
< 256; i
++)
1743 ok(bi
->bmiColors
[i
].rgbRed
== 0xAA && bi
->bmiColors
[i
].rgbGreen
== 0xAA &&
1744 bi
->bmiColors
[i
].rgbBlue
== 0xAA && bi
->bmiColors
[i
].rgbReserved
== 0xAA,
1745 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i
,
1746 bi
->bmiColors
[i
].rgbRed
, bi
->bmiColors
[i
].rgbGreen
,
1747 bi
->bmiColors
[i
].rgbBlue
, bi
->bmiColors
[i
].rgbReserved
);
1750 /* returned bits are DWORD aligned and upside down */
1751 ok(!memcmp(buf
, dib_bits_24
, sizeof(dib_bits_24
)), "DIB bits don't match\n");
1757 static void test_GetDIBits_BI_BITFIELDS(void)
1759 /* Try a screen resolution detection technique
1760 * from the September 1999 issue of Windows Developer's Journal
1761 * which seems to be in widespread use.
1762 * http://www.lesher.ws/highcolor.html
1763 * http://www.lesher.ws/vidfmt.c
1764 * It hinges on being able to retrieve the bitmaps
1765 * for the three primary colors in non-paletted 16 bit mode.
1767 char dibinfo_buf
[sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
)];
1769 LPBITMAPINFO dibinfo
= (LPBITMAPINFO
) dibinfo_buf
;
1770 DWORD
*bitmasks
= (DWORD
*)dibinfo
->bmiColors
;
1776 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1777 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1780 ok(hdc
!= NULL
, "GetDC failed?\n");
1781 hbm
= CreateCompatibleBitmap(hdc
, 1, 1);
1782 ok(hbm
!= NULL
, "CreateCompatibleBitmap failed?\n");
1784 /* Call GetDIBits to fill in bmiHeader. */
1785 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1786 ok(ret
== 1, "GetDIBits failed\n");
1787 if (dibinfo
->bmiHeader
.biBitCount
> 8)
1789 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1790 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1792 ok( !bitmasks
[0], "red mask is set\n" );
1793 ok( !bitmasks
[1], "green mask is set\n" );
1794 ok( !bitmasks
[2], "blue mask is set\n" );
1796 /* test with NULL bits pointer and correct bpp */
1797 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1798 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1799 ok(ret
== 1, "GetDIBits failed\n");
1801 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1802 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1803 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1804 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1806 /* test with valid bits pointer */
1807 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1808 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1809 ret
= GetDIBits(hdc
, hbm
, 0, 1, NULL
, dibinfo
, DIB_RGB_COLORS
);
1810 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1811 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1812 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1813 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1815 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1816 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1817 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1818 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1820 /* now with bits and 0 lines */
1821 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1822 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1823 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1824 SetLastError(0xdeadbeef);
1825 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1826 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1828 ok( !bitmasks
[0], "red mask is set\n" );
1829 ok( !bitmasks
[1], "green mask is set\n" );
1830 ok( !bitmasks
[2], "blue mask is set\n" );
1831 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1833 memset(bitmasks
, 0, 3*sizeof(DWORD
));
1834 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1835 ret
= GetDIBits(hdc
, hbm
, 0, 0, bits
, dibinfo
, DIB_RGB_COLORS
);
1836 ok(ret
== 1, "GetDIBits failed ret %u err %u\n",ret
,GetLastError());
1838 ok( bitmasks
[0] != 0, "red mask is not set\n" );
1839 ok( bitmasks
[1] != 0, "green mask is not set\n" );
1840 ok( bitmasks
[2] != 0, "blue mask is not set\n" );
1841 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1843 else skip("not in 16 bpp BI_BITFIELDS mode, skipping that test\n");
1847 /* same thing now with a 32-bpp DIB section */
1849 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1850 dibinfo
->bmiHeader
.biWidth
= 1;
1851 dibinfo
->bmiHeader
.biHeight
= 1;
1852 dibinfo
->bmiHeader
.biPlanes
= 1;
1853 dibinfo
->bmiHeader
.biBitCount
= 32;
1854 dibinfo
->bmiHeader
.biCompression
= BI_RGB
;
1855 dibinfo
->bmiHeader
.biSizeImage
= 0;
1856 dibinfo
->bmiHeader
.biXPelsPerMeter
= 0;
1857 dibinfo
->bmiHeader
.biYPelsPerMeter
= 0;
1858 dibinfo
->bmiHeader
.biClrUsed
= 0;
1859 dibinfo
->bmiHeader
.biClrImportant
= 0;
1860 bitmasks
[0] = 0x0000ff;
1861 bitmasks
[1] = 0x00ff00;
1862 bitmasks
[2] = 0xff0000;
1863 hbm
= CreateDIBSection( hdc
, dibinfo
, DIB_RGB_COLORS
, &ptr
, NULL
, 0 );
1864 ok( hbm
!= 0, "failed to create bitmap\n" );
1866 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1867 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1868 ret
= GetDIBits(hdc
, hbm
, 0, 0, NULL
, dibinfo
, DIB_RGB_COLORS
);
1869 ok(ret
== 1, "GetDIBits failed\n");
1870 ok( dibinfo
->bmiHeader
.biBitCount
== 32, "wrong bit count %u\n", dibinfo
->bmiHeader
.biBitCount
);
1872 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1873 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1874 ok( !bitmasks
[0], "red mask is set\n" );
1875 ok( !bitmasks
[1], "green mask is set\n" );
1876 ok( !bitmasks
[2], "blue mask is set\n" );
1878 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1879 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1880 ok(ret
== 1, "GetDIBits failed\n");
1881 ok( dibinfo
->bmiHeader
.biBitCount
== 32, "wrong bit count %u\n", dibinfo
->bmiHeader
.biBitCount
);
1882 ok( bitmasks
[0] == 0xff0000, "wrong red mask %08x\n", bitmasks
[0] );
1883 ok( bitmasks
[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks
[1] );
1884 ok( bitmasks
[2] == 0x0000ff, "wrong blue mask %08x\n", bitmasks
[2] );
1885 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1889 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1890 dibinfo
->bmiHeader
.biWidth
= 1;
1891 dibinfo
->bmiHeader
.biHeight
= 1;
1892 dibinfo
->bmiHeader
.biPlanes
= 1;
1893 dibinfo
->bmiHeader
.biBitCount
= 32;
1894 dibinfo
->bmiHeader
.biCompression
= BI_BITFIELDS
;
1895 dibinfo
->bmiHeader
.biSizeImage
= 0;
1896 dibinfo
->bmiHeader
.biXPelsPerMeter
= 0;
1897 dibinfo
->bmiHeader
.biYPelsPerMeter
= 0;
1898 dibinfo
->bmiHeader
.biClrUsed
= 0;
1899 dibinfo
->bmiHeader
.biClrImportant
= 0;
1900 bitmasks
[0] = 0x0000ff;
1901 bitmasks
[1] = 0x00ff00;
1902 bitmasks
[2] = 0xff0000;
1903 hbm
= CreateDIBSection( hdc
, dibinfo
, DIB_RGB_COLORS
, &ptr
, NULL
, 0 );
1904 ok( hbm
!= 0, "failed to create bitmap\n" );
1908 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1909 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1910 ret
= GetDIBits(hdc
, hbm
, 0, 0, NULL
, dibinfo
, DIB_RGB_COLORS
);
1911 ok(ret
== 1, "GetDIBits failed\n");
1913 ok( dibinfo
->bmiHeader
.biCompression
== BI_BITFIELDS
,
1914 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1915 ok( !bitmasks
[0], "red mask is set\n" );
1916 ok( !bitmasks
[1], "green mask is set\n" );
1917 ok( !bitmasks
[2], "blue mask is set\n" );
1919 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1920 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1921 ok(ret
== 1, "GetDIBits failed\n");
1922 ok( bitmasks
[0] == 0x0000ff, "wrong red mask %08x\n", bitmasks
[0] );
1923 ok( bitmasks
[1] == 0x00ff00, "wrong green mask %08x\n", bitmasks
[1] );
1924 ok( bitmasks
[2] == 0xff0000, "wrong blue mask %08x\n", bitmasks
[2] );
1925 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1930 /* 24-bpp DIB sections don't have bitfields */
1932 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1933 dibinfo
->bmiHeader
.biWidth
= 1;
1934 dibinfo
->bmiHeader
.biHeight
= 1;
1935 dibinfo
->bmiHeader
.biPlanes
= 1;
1936 dibinfo
->bmiHeader
.biBitCount
= 24;
1937 dibinfo
->bmiHeader
.biCompression
= BI_BITFIELDS
;
1938 dibinfo
->bmiHeader
.biSizeImage
= 0;
1939 dibinfo
->bmiHeader
.biXPelsPerMeter
= 0;
1940 dibinfo
->bmiHeader
.biYPelsPerMeter
= 0;
1941 dibinfo
->bmiHeader
.biClrUsed
= 0;
1942 dibinfo
->bmiHeader
.biClrImportant
= 0;
1943 hbm
= CreateDIBSection( hdc
, dibinfo
, DIB_RGB_COLORS
, &ptr
, NULL
, 0 );
1944 ok( hbm
== 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
1945 dibinfo
->bmiHeader
.biCompression
= BI_RGB
;
1946 hbm
= CreateDIBSection( hdc
, dibinfo
, DIB_RGB_COLORS
, &ptr
, NULL
, 0 );
1947 ok( hbm
!= 0, "failed to create bitmap\n" );
1949 memset(dibinfo
, 0, sizeof(dibinfo_buf
));
1950 dibinfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1951 ret
= GetDIBits(hdc
, hbm
, 0, 0, NULL
, dibinfo
, DIB_RGB_COLORS
);
1952 ok(ret
== 1, "GetDIBits failed\n");
1953 ok( dibinfo
->bmiHeader
.biBitCount
== 24, "wrong bit count %u\n", dibinfo
->bmiHeader
.biBitCount
);
1955 ok( dibinfo
->bmiHeader
.biCompression
== BI_RGB
,
1956 "compression is %u\n", dibinfo
->bmiHeader
.biCompression
);
1957 ok( !bitmasks
[0], "red mask is set\n" );
1958 ok( !bitmasks
[1], "green mask is set\n" );
1959 ok( !bitmasks
[2], "blue mask is set\n" );
1961 dibinfo
->bmiHeader
.biSizeImage
= 0xdeadbeef;
1962 ret
= GetDIBits(hdc
, hbm
, 0, 1, bits
, dibinfo
, DIB_RGB_COLORS
);
1963 ok(ret
== 1, "GetDIBits failed\n");
1964 ok( dibinfo
->bmiHeader
.biBitCount
== 24, "wrong bit count %u\n", dibinfo
->bmiHeader
.biBitCount
);
1965 ok( !bitmasks
[0], "red mask is set\n" );
1966 ok( !bitmasks
[1], "green mask is set\n" );
1967 ok( !bitmasks
[2], "blue mask is set\n" );
1968 ok( dibinfo
->bmiHeader
.biSizeImage
!= 0xdeadbeef, "size image not set\n" );
1971 ReleaseDC(NULL
, hdc
);
1974 static void test_select_object(void)
1977 HBITMAP hbm
, hbm_old
;
1979 DWORD depths
[] = {8, 15, 16, 24, 32};
1984 ok(hdc
!= 0, "GetDC(0) failed\n");
1985 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1986 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1988 hbm_old
= SelectObject(hdc
, hbm
);
1989 ok(hbm_old
== 0, "SelectObject should fail\n");
1994 hdc
= CreateCompatibleDC(0);
1995 ok(hdc
!= 0, "GetDC(0) failed\n");
1996 hbm
= CreateCompatibleBitmap(hdc
, 10, 10);
1997 ok(hbm
!= 0, "CreateCompatibleBitmap failed\n");
1999 hbm_old
= SelectObject(hdc
, hbm
);
2000 ok(hbm_old
!= 0, "SelectObject failed\n");
2001 hbm_old
= SelectObject(hdc
, hbm_old
);
2002 ok(hbm_old
== hbm
, "SelectObject failed\n");
2006 /* test an 1-bpp bitmap */
2007 planes
= GetDeviceCaps(hdc
, PLANES
);
2010 hbm
= CreateBitmap(10, 10, planes
, bpp
, NULL
);
2011 ok(hbm
!= 0, "CreateBitmap failed\n");
2013 hbm_old
= SelectObject(hdc
, hbm
);
2014 ok(hbm_old
!= 0, "SelectObject failed\n");
2015 hbm_old
= SelectObject(hdc
, hbm_old
);
2016 ok(hbm_old
== hbm
, "SelectObject failed\n");
2020 for(i
= 0; i
< sizeof(depths
)/sizeof(depths
[0]); i
++) {
2021 /* test a color bitmap to dc bpp matching */
2022 planes
= GetDeviceCaps(hdc
, PLANES
);
2023 bpp
= GetDeviceCaps(hdc
, BITSPIXEL
);
2025 hbm
= CreateBitmap(10, 10, planes
, depths
[i
], NULL
);
2026 ok(hbm
!= 0, "CreateBitmap failed\n");
2028 hbm_old
= SelectObject(hdc
, hbm
);
2029 if(depths
[i
] == bpp
||
2030 (bpp
== 16 && depths
[i
] == 15) /* 16 and 15 bpp are compatible */
2032 ok(hbm_old
!= 0, "SelectObject failed, BITSPIXEL: %d, created depth: %d\n", bpp
, depths
[i
]);
2033 SelectObject(hdc
, hbm_old
);
2035 ok(hbm_old
== 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %d\n", bpp
, depths
[i
]);
2038 memset(&bm
, 0xAA, sizeof(bm
));
2039 bytes
= GetObject(hbm
, sizeof(bm
), &bm
);
2040 ok(bytes
== sizeof(bm
), "GetObject returned %d\n", bytes
);
2041 ok(bm
.bmType
== 0, "wrong bmType %d\n", bm
.bmType
);
2042 ok(bm
.bmWidth
== 10, "wrong bmWidth %d\n", bm
.bmWidth
);
2043 ok(bm
.bmHeight
== 10, "wrong bmHeight %d\n", bm
.bmHeight
);
2044 ok(bm
.bmWidthBytes
== BITMAP_GetWidthBytes(bm
.bmWidth
, bm
.bmBitsPixel
), "wrong bmWidthBytes %d\n", bm
.bmWidthBytes
);
2045 ok(bm
.bmPlanes
== planes
, "wrong bmPlanes %u\n", bm
.bmPlanes
);
2046 if(depths
[i
] == 15) {
2047 ok(bm
.bmBitsPixel
== 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm
.bmBitsPixel
);
2049 ok(bm
.bmBitsPixel
== depths
[i
], "wrong bmBitsPixel %d\n", bm
.bmBitsPixel
);
2051 ok(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
2059 static void test_mono_1x1_bmp_dbg(HBITMAP hbmp
, int line
)
2064 ret
= GetObjectType(hbmp
);
2065 ok_(__FILE__
, line
)(ret
== OBJ_BITMAP
, "the object %p is not bitmap\n", hbmp
);
2067 ret
= GetObject(hbmp
, 0, 0);
2068 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
), "object size %d\n", ret
);
2070 memset(&bm
, 0xDA, sizeof(bm
));
2071 SetLastError(0xdeadbeef);
2072 ret
= GetObject(hbmp
, sizeof(bm
), &bm
);
2073 if (!ret
) /* XP, only for curObj2 */ return;
2074 ok_(__FILE__
, line
)(ret
== sizeof(BITMAP
), "GetObject returned %d, error %u\n", ret
, GetLastError());
2075 ok_(__FILE__
, line
)(bm
.bmType
== 0, "wrong bmType, expected 0 got %d\n", bm
.bmType
);
2076 ok_(__FILE__
, line
)(bm
.bmWidth
== 1, "wrong bmWidth, expected 1 got %d\n", bm
.bmWidth
);
2077 ok_(__FILE__
, line
)(bm
.bmHeight
== 1, "wrong bmHeight, expected 1 got %d\n", bm
.bmHeight
);
2078 ok_(__FILE__
, line
)(bm
.bmWidthBytes
== 2, "wrong bmWidthBytes, expected 2 got %d\n", bm
.bmWidthBytes
);
2079 ok_(__FILE__
, line
)(bm
.bmPlanes
== 1, "wrong bmPlanes, expected 1 got %u\n", bm
.bmPlanes
);
2080 ok_(__FILE__
, line
)(bm
.bmBitsPixel
== 1, "wrong bmBitsPixel, expected 1 got %d\n", bm
.bmBitsPixel
);
2081 ok_(__FILE__
, line
)(!bm
.bmBits
, "wrong bmBits %p\n", bm
.bmBits
);
2084 #define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2086 static void test_CreateBitmap(void)
2089 HDC screenDC
= GetDC(0);
2090 HDC hdc
= CreateCompatibleDC(screenDC
);
2093 /* all of these are the stock monochrome bitmap */
2094 HBITMAP bm
= CreateCompatibleBitmap(hdc
, 0, 0);
2095 HBITMAP bm1
= CreateCompatibleBitmap(screenDC
, 0, 0);
2096 HBITMAP bm4
= CreateBitmap(0, 1, 0, 0, 0);
2097 HBITMAP bm5
= CreateDiscardableBitmap(hdc
, 0, 0);
2098 HBITMAP curObj1
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2099 HBITMAP curObj2
= GetCurrentObject(screenDC
, OBJ_BITMAP
);
2101 /* these 2 are not the stock monochrome bitmap */
2102 HBITMAP bm2
= CreateCompatibleBitmap(hdc
, 1, 1);
2103 HBITMAP bm3
= CreateBitmap(1, 1, 1, 1, 0);
2105 HBITMAP old1
= SelectObject(hdc
, bm2
);
2106 HBITMAP old2
= SelectObject(screenDC
, bm3
);
2107 SelectObject(hdc
, old1
);
2108 SelectObject(screenDC
, old2
);
2110 ok(bm
== bm1
&& bm
== bm4
&& bm
== bm5
&& bm
== curObj1
&& bm
== old1
,
2111 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2112 bm
, bm1
, bm4
, bm5
, curObj1
, old1
);
2113 ok(bm
!= bm2
&& bm
!= bm3
, "0: %p, 2: %p, 3: %p\n", bm
, bm2
, bm3
);
2115 ok(bm
!= curObj2
, "0: %p, curObj2 %p\n", bm
, curObj2
);
2116 ok(old2
== 0, "old2 %p\n", old2
);
2118 test_mono_1x1_bmp(bm
);
2119 test_mono_1x1_bmp(bm1
);
2120 test_mono_1x1_bmp(bm2
);
2121 test_mono_1x1_bmp(bm3
);
2122 test_mono_1x1_bmp(bm4
);
2123 test_mono_1x1_bmp(bm5
);
2124 test_mono_1x1_bmp(old1
);
2125 test_mono_1x1_bmp(curObj1
);
2135 ReleaseDC(0, screenDC
);
2137 /* show that Windows ignores the provided bm.bmWidthBytes */
2141 bmp
.bmWidthBytes
= 28;
2143 bmp
.bmBitsPixel
= 1;
2145 bm
= CreateBitmapIndirect(&bmp
);
2146 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2147 test_mono_1x1_bmp(bm
);
2150 /* Test how the bmBitsPixel field is treated */
2151 for(i
= 1; i
<= 33; i
++) {
2155 bmp
.bmWidthBytes
= 28;
2157 bmp
.bmBitsPixel
= i
;
2159 SetLastError(0xdeadbeef);
2160 bm
= CreateBitmapIndirect(&bmp
);
2162 DWORD error
= GetLastError();
2163 ok(bm
== 0, "CreateBitmapIndirect for %d bpp succeeded\n", i
);
2164 ok(error
== ERROR_INVALID_PARAMETER
, "Got error %d, expected ERROR_INVALID_PARAMETER\n", error
);
2168 ok(bm
!= 0, "CreateBitmapIndirect error %u\n", GetLastError());
2169 GetObject(bm
, sizeof(bmp
), &bmp
);
2176 } else if(i
<= 16) {
2178 } else if(i
<= 24) {
2180 } else if(i
<= 32) {
2183 ok(bmp
.bmBitsPixel
== expect
, "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2184 i
, bmp
.bmBitsPixel
, expect
);
2189 static void test_bitmapinfoheadersize(void)
2196 memset(&bmi
, 0, sizeof(BITMAPINFO
));
2197 bmi
.bmiHeader
.biHeight
= 100;
2198 bmi
.bmiHeader
.biWidth
= 512;
2199 bmi
.bmiHeader
.biBitCount
= 24;
2200 bmi
.bmiHeader
.biPlanes
= 1;
2202 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
) - 1;
2204 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2205 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2207 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2209 SetLastError(0xdeadbeef);
2210 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2211 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2214 bmi
.bmiHeader
.biSize
++;
2216 SetLastError(0xdeadbeef);
2217 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2219 broken(!hdib
), /* Win98, WinMe */
2220 "CreateDIBSection error %d\n", GetLastError());
2223 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFO
);
2225 SetLastError(0xdeadbeef);
2226 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2228 broken(!hdib
), /* Win98, WinMe */
2229 "CreateDIBSection error %d\n", GetLastError());
2232 bmi
.bmiHeader
.biSize
++;
2234 SetLastError(0xdeadbeef);
2235 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2237 broken(!hdib
), /* Win98, WinMe */
2238 "CreateDIBSection error %d\n", GetLastError());
2241 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV4HEADER
);
2243 SetLastError(0xdeadbeef);
2244 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2245 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2248 bmi
.bmiHeader
.biSize
= sizeof(BITMAPV5HEADER
);
2250 SetLastError(0xdeadbeef);
2251 hdib
= CreateDIBSection(hdc
, &bmi
, 0, NULL
, NULL
, 0);
2253 broken(!hdib
), /* Win95 */
2254 "CreateDIBSection error %d\n", GetLastError());
2257 memset(&bci
, 0, sizeof(BITMAPCOREINFO
));
2258 bci
.bmciHeader
.bcHeight
= 100;
2259 bci
.bmciHeader
.bcWidth
= 512;
2260 bci
.bmciHeader
.bcBitCount
= 24;
2261 bci
.bmciHeader
.bcPlanes
= 1;
2263 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
) - 1;
2265 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2266 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2268 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREHEADER
);
2270 SetLastError(0xdeadbeef);
2271 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2272 ok(hdib
!= NULL
, "CreateDIBSection error %d\n", GetLastError());
2275 bci
.bmciHeader
.bcSize
++;
2277 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2278 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2280 bci
.bmciHeader
.bcSize
= sizeof(BITMAPCOREINFO
);
2282 hdib
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bci
, 0, NULL
, NULL
, 0);
2283 ok(hdib
== NULL
, "CreateDIBSection succeeded\n");
2288 static void test_get16dibits(void)
2290 BYTE bits
[4 * (16 / sizeof(BYTE
))];
2292 HDC screen_dc
= GetDC(NULL
);
2295 int info_len
= sizeof(BITMAPINFOHEADER
) + 1024;
2297 int overwritten_bytes
= 0;
2299 memset(bits
, 0, sizeof(bits
));
2300 hbmp
= CreateBitmap(2, 2, 1, 16, bits
);
2301 ok(hbmp
!= NULL
, "CreateBitmap failed\n");
2303 info
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, info_len
);
2306 memset(info
, '!', info_len
);
2307 memset(info
, 0, sizeof(info
->bmiHeader
));
2309 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
2310 info
->bmiHeader
.biWidth
= 2;
2311 info
->bmiHeader
.biHeight
= 2;
2312 info
->bmiHeader
.biPlanes
= 1;
2313 info
->bmiHeader
.biCompression
= BI_RGB
;
2315 ret
= GetDIBits(screen_dc
, hbmp
, 0, 0, NULL
, info
, 0);
2316 ok(ret
!= 0, "GetDIBits failed got %d\n", ret
);
2318 for (p
= ((BYTE
*) info
) + sizeof(info
->bmiHeader
); (p
- ((BYTE
*) info
)) < info_len
; p
++)
2320 overwritten_bytes
++;
2321 ok(overwritten_bytes
== 0, "GetDIBits wrote past the buffer given\n");
2323 HeapFree(GetProcessHeap(), 0, info
);
2325 ReleaseDC(NULL
, screen_dc
);
2328 static BOOL
compare_buffers_no_alpha(UINT32
*a
, UINT32
*b
, int length
)
2331 for(i
= 0; i
< length
; i
++)
2332 if((a
[i
] & 0x00FFFFFF) != (b
[i
] & 0x00FFFFFF))
2337 static void check_BitBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2338 DWORD dwRop
, UINT32 expected
, int line
)
2340 *srcBuffer
= 0xFEDCBA98;
2341 *dstBuffer
= 0x89ABCDEF;
2342 Rectangle(hdcSrc
, 0, 0, 1, 1); /* A null operation to ensure dibs are coerced to X11 */
2343 BitBlt(hdcDst
, 0, 0, 1, 1, hdcSrc
, 0, 0, dwRop
);
2344 ok(expected
== *dstBuffer
,
2345 "BitBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2346 dwRop
, expected
, *dstBuffer
, line
);
2349 static void test_BitBlt(void)
2351 HBITMAP bmpDst
, bmpSrc
;
2352 HBITMAP oldDst
, oldSrc
;
2353 HDC hdcScreen
, hdcDst
, hdcSrc
;
2354 UINT32
*dstBuffer
, *srcBuffer
;
2355 HBRUSH hBrush
, hOldBrush
;
2356 BITMAPINFO bitmapInfo
;
2358 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2359 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2360 bitmapInfo
.bmiHeader
.biWidth
= 1;
2361 bitmapInfo
.bmiHeader
.biHeight
= 1;
2362 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2363 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2364 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2365 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(UINT32
);
2367 hdcScreen
= CreateCompatibleDC(0);
2368 hdcDst
= CreateCompatibleDC(hdcScreen
);
2369 hdcSrc
= CreateCompatibleDC(hdcDst
);
2371 /* Setup the destination dib section */
2372 bmpDst
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2374 oldDst
= SelectObject(hdcDst
, bmpDst
);
2376 hBrush
= CreateSolidBrush(0x012345678);
2377 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2379 /* Setup the source dib section */
2380 bmpSrc
= CreateDIBSection(hdcScreen
, &bitmapInfo
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2382 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2384 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2385 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2386 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2387 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2388 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2389 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2390 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2391 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2392 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2393 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2394 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2395 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2396 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2397 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2398 check_BitBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2401 SelectObject(hdcSrc
, oldSrc
);
2402 DeleteObject(bmpSrc
);
2405 SelectObject(hdcDst
, hOldBrush
);
2406 DeleteObject(hBrush
);
2407 SelectObject(hdcDst
, oldDst
);
2408 DeleteObject(bmpDst
);
2412 DeleteDC(hdcScreen
);
2415 static void check_StretchBlt_pixel(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2416 DWORD dwRop
, UINT32 expected
, int line
)
2418 *srcBuffer
= 0xFEDCBA98;
2419 *dstBuffer
= 0x89ABCDEF;
2420 StretchBlt(hdcDst
, 0, 0, 2, 1, hdcSrc
, 0, 0, 1, 1, dwRop
);
2421 ok(expected
== *dstBuffer
,
2422 "StretchBlt with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2423 dwRop
, expected
, *dstBuffer
, line
);
2426 static void check_StretchBlt_stretch(HDC hdcDst
, HDC hdcSrc
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2427 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2428 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2429 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2431 memset(dstBuffer
, 0, 16);
2432 StretchBlt(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2433 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
, SRCCOPY
);
2434 ok(memcmp(dstBuffer
, expected
, 16) == 0 ||
2435 broken(compare_buffers_no_alpha(dstBuffer
, legacy_expected
, 4)),
2436 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2437 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2438 expected
[0], expected
[1], expected
[2], expected
[3],
2439 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2440 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2441 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2444 static void test_StretchBlt(void)
2446 HBITMAP bmpDst
, bmpSrc
;
2447 HBITMAP oldDst
, oldSrc
;
2448 HDC hdcScreen
, hdcDst
, hdcSrc
;
2449 UINT32
*dstBuffer
, *srcBuffer
;
2450 HBRUSH hBrush
, hOldBrush
;
2451 BITMAPINFO biDst
, biSrc
;
2452 UINT32 expected
[4], legacy_expected
[4];
2454 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2455 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2456 biDst
.bmiHeader
.biWidth
= 2;
2457 biDst
.bmiHeader
.biHeight
= -2;
2458 biDst
.bmiHeader
.biPlanes
= 1;
2459 biDst
.bmiHeader
.biBitCount
= 32;
2460 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2461 memcpy(&biSrc
, &biDst
, sizeof(BITMAPINFO
));
2463 hdcScreen
= CreateCompatibleDC(0);
2464 hdcDst
= CreateCompatibleDC(hdcScreen
);
2465 hdcSrc
= CreateCompatibleDC(hdcDst
);
2468 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2470 oldDst
= SelectObject(hdcDst
, bmpDst
);
2472 bmpSrc
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2474 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2476 hBrush
= CreateSolidBrush(0x012345678);
2477 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2479 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2480 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2481 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2482 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2483 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2484 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2485 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2486 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2487 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2488 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2489 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2490 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2491 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2492 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2493 check_StretchBlt_pixel(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2495 SelectObject(hdcDst
, hOldBrush
);
2496 DeleteObject(hBrush
);
2498 /* Top-down to top-down tests */
2499 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2500 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2502 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2503 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2504 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2505 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2507 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2508 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2509 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2510 0, 0, 1, 1, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2512 expected
[0] = 0xCAFED00D, expected
[1] = 0xCAFED00D;
2513 expected
[2] = 0xCAFED00D, expected
[3] = 0xCAFED00D;
2514 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2515 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2517 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2518 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2519 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2520 0, 0, 1, 1, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2522 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2523 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2524 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2525 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2527 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2528 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2529 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2530 1, 1, -2, -2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2532 /* This result seems broken. One might expect the following result:
2533 * 0xCAFED00D 0xFEEDFACE
2534 * 0xFEDCBA98 0x76543210
2536 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2537 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2538 legacy_expected
[0] = 0xCAFED00D, legacy_expected
[1] = 0x00000000;
2539 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2540 todo_wine
check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2541 1, 1, -2, -2, 1, 1, -2, -2, expected
,
2542 legacy_expected
, __LINE__
);
2544 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2545 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2546 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2547 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2549 SelectObject(hdcDst
, oldDst
);
2550 DeleteObject(bmpDst
);
2552 /* Top-down to bottom-up tests */
2553 biDst
.bmiHeader
.biHeight
= 2;
2554 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2556 oldDst
= SelectObject(hdcDst
, bmpDst
);
2558 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2559 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2560 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2561 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2563 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2564 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2565 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2566 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2568 SelectObject(hdcSrc
, oldSrc
);
2569 DeleteObject(bmpSrc
);
2571 /* Bottom-up to bottom-up tests */
2572 biSrc
.bmiHeader
.biHeight
= 2;
2573 bmpSrc
= CreateDIBSection(hdcScreen
, &biSrc
, DIB_RGB_COLORS
, (void**)&srcBuffer
,
2575 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2576 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2577 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2579 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2580 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2581 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2582 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2584 expected
[0] = 0x76543210, expected
[1] = 0xFEDCBA98;
2585 expected
[2] = 0xFEEDFACE, expected
[3] = 0xCAFED00D;
2586 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2587 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2589 SelectObject(hdcDst
, oldDst
);
2590 DeleteObject(bmpDst
);
2592 /* Bottom-up to top-down tests */
2593 biDst
.bmiHeader
.biHeight
= -2;
2594 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2596 oldDst
= SelectObject(hdcDst
, bmpDst
);
2598 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2599 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2600 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2601 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2603 expected
[0] = 0xFEEDFACE, expected
[1] = 0xCAFED00D;
2604 expected
[2] = 0x76543210, expected
[3] = 0xFEDCBA98;
2605 check_StretchBlt_stretch(hdcDst
, hdcSrc
, dstBuffer
, srcBuffer
,
2606 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2609 SelectObject(hdcSrc
, oldSrc
);
2610 DeleteObject(bmpSrc
);
2613 SelectObject(hdcDst
, oldDst
);
2614 DeleteObject(bmpDst
);
2617 DeleteDC(hdcScreen
);
2620 static void check_StretchDIBits_pixel(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2621 DWORD dwRop
, UINT32 expected
, int line
)
2623 const UINT32 buffer
[2] = { 0xFEDCBA98, 0 };
2624 BITMAPINFO bitmapInfo
;
2626 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2627 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2628 bitmapInfo
.bmiHeader
.biWidth
= 2;
2629 bitmapInfo
.bmiHeader
.biHeight
= 1;
2630 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2631 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2632 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2633 bitmapInfo
.bmiHeader
.biSizeImage
= sizeof(buffer
);
2635 *dstBuffer
= 0x89ABCDEF;
2637 StretchDIBits(hdcDst
, 0, 0, 2, 1, 0, 0, 1, 1, &buffer
, &bitmapInfo
, DIB_RGB_COLORS
, dwRop
);
2638 ok(expected
== *dstBuffer
,
2639 "StretchDIBits with dwRop %06X. Expected 0x%08X, got 0x%08X from line %d\n",
2640 dwRop
, expected
, *dstBuffer
, line
);
2643 static void check_StretchDIBits_stretch(HDC hdcDst
, UINT32
*dstBuffer
, UINT32
*srcBuffer
,
2644 int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
2645 int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
2646 UINT32 expected
[4], UINT32 legacy_expected
[4], int line
)
2648 BITMAPINFO bitmapInfo
;
2650 memset(&bitmapInfo
, 0, sizeof(BITMAPINFO
));
2651 bitmapInfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2652 bitmapInfo
.bmiHeader
.biWidth
= 2;
2653 bitmapInfo
.bmiHeader
.biHeight
= -2;
2654 bitmapInfo
.bmiHeader
.biPlanes
= 1;
2655 bitmapInfo
.bmiHeader
.biBitCount
= 32;
2656 bitmapInfo
.bmiHeader
.biCompression
= BI_RGB
;
2658 memset(dstBuffer
, 0, 16);
2659 StretchDIBits(hdcDst
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
2660 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2661 srcBuffer
, &bitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);
2662 ok(memcmp(dstBuffer
, expected
, 16) == 0,
2663 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
2664 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
2665 expected
[0], expected
[1], expected
[2], expected
[3],
2666 dstBuffer
[0], dstBuffer
[1], dstBuffer
[2], dstBuffer
[3],
2667 nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
2668 nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
, line
);
2671 static void test_StretchDIBits(void)
2675 HDC hdcScreen
, hdcDst
;
2676 UINT32
*dstBuffer
, srcBuffer
[4];
2677 HBRUSH hBrush
, hOldBrush
;
2679 UINT32 expected
[4], legacy_expected
[4];
2681 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2682 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2683 biDst
.bmiHeader
.biWidth
= 2;
2684 biDst
.bmiHeader
.biHeight
= -2;
2685 biDst
.bmiHeader
.biPlanes
= 1;
2686 biDst
.bmiHeader
.biBitCount
= 32;
2687 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2689 hdcScreen
= CreateCompatibleDC(0);
2690 hdcDst
= CreateCompatibleDC(hdcScreen
);
2693 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2695 oldDst
= SelectObject(hdcDst
, bmpDst
);
2697 hBrush
= CreateSolidBrush(0x012345678);
2698 hOldBrush
= SelectObject(hdcDst
, hBrush
);
2700 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCCOPY
, 0xFEDCBA98, __LINE__
);
2701 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCPAINT
, 0xFFFFFFFF, __LINE__
);
2702 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCAND
, 0x88888888, __LINE__
);
2703 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCINVERT
, 0x77777777, __LINE__
);
2704 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, SRCERASE
, 0x76543210, __LINE__
);
2705 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCCOPY
, 0x01234567, __LINE__
);
2706 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, NOTSRCERASE
, 0x00000000, __LINE__
);
2707 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGECOPY
, 0x00581210, __LINE__
);
2708 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, MERGEPAINT
, 0x89ABCDEF, __LINE__
);
2709 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATCOPY
, 0x00785634, __LINE__
);
2710 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATPAINT
, 0x89FBDFFF, __LINE__
);
2711 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, PATINVERT
, 0x89D39BDB, __LINE__
);
2712 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, DSTINVERT
, 0x76543210, __LINE__
);
2713 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, BLACKNESS
, 0x00000000, __LINE__
);
2714 check_StretchDIBits_pixel(hdcDst
, dstBuffer
, srcBuffer
, WHITENESS
, 0xFFFFFFFF, __LINE__
);
2716 SelectObject(hdcDst
, hOldBrush
);
2717 DeleteObject(hBrush
);
2719 /* Top-down destination tests */
2720 srcBuffer
[0] = 0xCAFED00D, srcBuffer
[1] = 0xFEEDFACE;
2721 srcBuffer
[2] = 0xFEDCBA98, srcBuffer
[3] = 0x76543210;
2723 expected
[0] = 0xCAFED00D, expected
[1] = 0xFEEDFACE;
2724 expected
[2] = 0xFEDCBA98, expected
[3] = 0x76543210;
2725 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2726 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2728 expected
[0] = 0xCAFED00D, expected
[1] = 0x00000000;
2729 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2730 legacy_expected
[0] = 0xFEDCBA98, legacy_expected
[1] = 0x00000000;
2731 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2732 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2733 0, 0, 1, 1, 0, 0, 1, 1, expected
, legacy_expected
, __LINE__
);
2735 expected
[0] = 0xFEDCBA98, expected
[1] = 0xFEDCBA98;
2736 expected
[2] = 0xFEDCBA98, expected
[3] = 0xFEDCBA98;
2737 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2738 0, 0, 2, 2, 0, 0, 1, 1, expected
, expected
, __LINE__
);
2740 expected
[0] = 0x42441000, expected
[1] = 0x00000000;
2741 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2742 legacy_expected
[0] = 0x00543210, legacy_expected
[1] = 0x00000000;
2743 legacy_expected
[2] = 0x00000000, legacy_expected
[3] = 0x00000000;
2744 todo_wine
check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2745 0, 0, 1, 1, 0, 0, 2, 2, expected
, legacy_expected
, __LINE__
);
2747 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2748 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2749 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2750 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2752 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2753 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2754 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2755 0, 0, 2, 2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2757 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2758 expected
[2] = 0x00000000, expected
[3] = 0x00000000;
2759 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2760 1, 1, -2, -2, 1, 1, -2, -2, expected
, expected
, __LINE__
);
2762 expected
[0] = 0x00000000, expected
[1] = 0x00000000;
2763 expected
[2] = 0x00000000, expected
[3] = 0xCAFED00D;
2764 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2765 1, 1, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2767 SelectObject(hdcDst
, oldDst
);
2768 DeleteObject(bmpDst
);
2770 /* Bottom up destination tests */
2771 biDst
.bmiHeader
.biHeight
= 2;
2772 bmpDst
= CreateDIBSection(hdcScreen
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
,
2774 oldDst
= SelectObject(hdcDst
, bmpDst
);
2776 expected
[0] = 0xFEDCBA98, expected
[1] = 0x76543210;
2777 expected
[2] = 0xCAFED00D, expected
[3] = 0xFEEDFACE;
2778 check_StretchDIBits_stretch(hdcDst
, dstBuffer
, srcBuffer
,
2779 0, 0, 2, 2, 0, 0, 2, 2, expected
, expected
, __LINE__
);
2782 SelectObject(hdcDst
, oldDst
);
2783 DeleteObject(bmpDst
);
2786 DeleteDC(hdcScreen
);
2789 static void test_GdiAlphaBlend(void)
2791 /* test out-of-bound parameters for GdiAlphaBlend */
2804 BLENDFUNCTION blend
;
2806 if (!pGdiAlphaBlend
)
2808 win_skip("GdiAlphaBlend() is not implemented\n");
2812 hdcNull
= GetDC(NULL
);
2813 hdcDst
= CreateCompatibleDC(hdcNull
);
2814 bmpDst
= CreateCompatibleBitmap(hdcNull
, 100, 100);
2815 hdcSrc
= CreateCompatibleDC(hdcNull
);
2817 memset(&bmi
, 0, sizeof(bmi
)); /* as of Wine 0.9.44 we require the src to be a DIB section */
2818 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
2819 bmi
.bmiHeader
.biHeight
= 20;
2820 bmi
.bmiHeader
.biWidth
= 20;
2821 bmi
.bmiHeader
.biBitCount
= 32;
2822 bmi
.bmiHeader
.biPlanes
= 1;
2823 bmi
.bmiHeader
.biCompression
= BI_RGB
;
2824 bmpSrc
= CreateDIBSection(hdcDst
, &bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2825 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2827 oldDst
= SelectObject(hdcDst
, bmpDst
);
2828 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2830 blend
.BlendOp
= AC_SRC_OVER
;
2831 blend
.BlendFlags
= 0;
2832 blend
.SourceConstantAlpha
= 128;
2833 blend
.AlphaFormat
= 0;
2835 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, 0, 20, 20, blend
), TRUE
, BOOL
, "%d");
2836 SetLastError(0xdeadbeef);
2837 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2838 expect_eq(GetLastError(), ERROR_INVALID_PARAMETER
, int, "%d");
2839 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), FALSE
, BOOL
, "%d");
2840 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 15, 0, 10, 10, blend
), FALSE
, BOOL
, "%d");
2841 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2842 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 10, 10, -2, 3, blend
), FALSE
, BOOL
, "%d");
2844 SetWindowOrgEx(hdcSrc
, -10, -10, NULL
);
2845 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 10, 10, blend
), TRUE
, BOOL
, "%d");
2846 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 10, 10, blend
), TRUE
, BOOL
, "%d");
2847 SetMapMode(hdcSrc
, MM_ANISOTROPIC
);
2848 ScaleWindowExtEx(hdcSrc
, 10, 1, 10, 1, NULL
);
2849 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, -1, 0, 30, 30, blend
), TRUE
, BOOL
, "%d");
2850 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, hdcSrc
, 0, -1, 30, 30, blend
), TRUE
, BOOL
, "%d");
2852 SetLastError(0xdeadbeef);
2853 expect_eq(pGdiAlphaBlend(hdcDst
, 0, 0, 20, 20, NULL
, 0, 0, 20, 20, blend
), FALSE
, BOOL
, "%d");
2854 expect_eq(GetLastError(), 0xdeadbeef, int, "%d");
2856 SelectObject(hdcDst
, oldDst
);
2857 SelectObject(hdcSrc
, oldSrc
);
2858 DeleteObject(bmpSrc
);
2859 DeleteObject(bmpDst
);
2863 ReleaseDC(NULL
, hdcNull
);
2867 static void test_clipping(void)
2875 HDC hdcDst
= CreateCompatibleDC( NULL
);
2876 HDC hdcSrc
= CreateCompatibleDC( NULL
);
2878 BITMAPINFO bmpinfo
={{0}};
2879 bmpinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2880 bmpinfo
.bmiHeader
.biWidth
= 100;
2881 bmpinfo
.bmiHeader
.biHeight
= 100;
2882 bmpinfo
.bmiHeader
.biPlanes
= 1;
2883 bmpinfo
.bmiHeader
.biBitCount
= GetDeviceCaps( hdcDst
, BITSPIXEL
);
2884 bmpinfo
.bmiHeader
.biCompression
= BI_RGB
;
2886 bmpDst
= CreateDIBSection( hdcDst
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2887 ok(bmpDst
!= NULL
, "Couldn't create destination bitmap\n");
2888 SelectObject( hdcDst
, bmpDst
);
2890 bmpSrc
= CreateDIBSection( hdcSrc
, &bmpinfo
, DIB_RGB_COLORS
, &bits
, NULL
, 0 );
2891 ok(bmpSrc
!= NULL
, "Couldn't create source bitmap\n");
2892 SelectObject( hdcSrc
, bmpSrc
);
2894 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 100, 100, SRCCOPY
);
2895 ok(result
, "BitBlt failed\n");
2897 hRgn
= CreateRectRgn( 0,0,0,0 );
2898 SelectClipRgn( hdcDst
, hRgn
);
2900 result
= BitBlt( hdcDst
, 0, 0, 100, 100, hdcSrc
, 0, 0, SRCCOPY
);
2901 ok(result
, "BitBlt failed\n");
2903 DeleteObject( bmpDst
);
2904 DeleteObject( bmpSrc
);
2905 DeleteObject( hRgn
);
2910 static void test_32bit_bitmap_blt(void)
2913 HBITMAP bmpSrc
, bmpDst
;
2914 HBITMAP oldSrc
, oldDst
;
2915 HDC hdcSrc
, hdcDst
, hdcScreen
;
2917 DWORD colorSrc
= 0x11223344;
2919 memset(&biDst
, 0, sizeof(BITMAPINFO
));
2920 biDst
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2921 biDst
.bmiHeader
.biWidth
= 2;
2922 biDst
.bmiHeader
.biHeight
= -2;
2923 biDst
.bmiHeader
.biPlanes
= 1;
2924 biDst
.bmiHeader
.biBitCount
= 32;
2925 biDst
.bmiHeader
.biCompression
= BI_RGB
;
2927 hdcScreen
= CreateCompatibleDC(0);
2928 if(GetDeviceCaps(hdcScreen
, BITSPIXEL
) != 32)
2930 DeleteDC(hdcScreen
);
2931 trace("Skipping 32-bit DDB test\n");
2935 hdcSrc
= CreateCompatibleDC(hdcScreen
);
2936 bmpSrc
= CreateBitmap(1, 1, 1, 32, &colorSrc
);
2937 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
2939 hdcDst
= CreateCompatibleDC(hdcScreen
);
2940 bmpDst
= CreateDIBSection(hdcDst
, &biDst
, DIB_RGB_COLORS
, (void**)&dstBuffer
, NULL
, 0);
2941 oldDst
= SelectObject(hdcDst
, bmpDst
);
2943 StretchBlt(hdcDst
, 0, 0, 1, 1, hdcSrc
, 0, 0, 1, 1, SRCCOPY
);
2944 ok(dstBuffer
[0] == colorSrc
, "Expected color=%x, received color=%x\n", colorSrc
, dstBuffer
[0]);
2947 SelectObject(hdcDst
, oldDst
);
2948 DeleteObject(bmpDst
);
2951 SelectObject(hdcSrc
, oldSrc
);
2952 DeleteObject(bmpSrc
);
2955 DeleteDC(hdcScreen
);
2959 * Used by test_GetDIBits_top_down to create the bitmap to test against.
2961 static void setup_picture(char *picture
, int bpp
)
2969 /*Set the first byte in each pixel to the index of that pixel.*/
2970 for (i
= 0; i
< 4; i
++)
2971 picture
[i
* (bpp
/ 8)] = i
;
2976 /*Each scanline in a bitmap must be a multiple of 4 bytes long.*/
2983 static void test_GetDIBits_top_down(int bpp
)
2986 HBITMAP bmptb
, bmpbt
;
2992 bi
.bmiHeader
.biSize
=sizeof(bi
.bmiHeader
);
2993 bi
.bmiHeader
.biWidth
=2;
2994 bi
.bmiHeader
.biHeight
=2;
2995 bi
.bmiHeader
.biPlanes
=1;
2996 bi
.bmiHeader
.biBitCount
=bpp
;
2997 bi
.bmiHeader
.biCompression
=BI_RGB
;
2999 /*Get the device context for the screen.*/
3001 ok(hdc
!= NULL
, "Could not get a handle to a device context.\n");
3003 /*Create the bottom to top image (image's bottom scan line is at the top in memory).*/
3004 bmpbt
= CreateDIBSection(hdc
, &bi
, DIB_RGB_COLORS
, (void**)&picture
, NULL
, 0);
3005 ok(bmpbt
!= NULL
, "Could not create a DIB section.\n");
3006 /*Now that we have a pointer to the pixels, we write to them.*/
3007 setup_picture((char*)picture
, bpp
);
3008 /*Create the top to bottom image (images' bottom scan line is at the bottom in memory).*/
3009 bi
.bmiHeader
.biHeight
=-2; /*We specify that we want a top to bottom image by specifying a negative height.*/
3010 bmptb
= CreateDIBSection(hdc
, &bi
, DIB_RGB_COLORS
, (void**)&picture
, NULL
, 0);
3011 ok(bmptb
!= NULL
, "Could not create a DIB section.\n");
3012 /*Write to this top to bottom bitmap.*/
3013 setup_picture((char*)picture
, bpp
);
3015 bi
.bmiHeader
.biWidth
= 1;
3017 bi
.bmiHeader
.biHeight
= 2;
3018 statusCode
= GetDIBits(hdc
, bmpbt
, 0, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3019 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3020 /*Check the first byte of the pixel.*/
3021 ok((char)pictureOut
[0] == 0, "Bottom-up -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut
[0]);
3022 statusCode
= GetDIBits(hdc
, bmptb
, 0, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3023 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3024 ok((char)pictureOut
[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut
[0]);
3025 /*Check second scanline.*/
3026 statusCode
= GetDIBits(hdc
, bmptb
, 1, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3027 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3028 ok((char)pictureOut
[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut
[0]);
3029 statusCode
= GetDIBits(hdc
, bmpbt
, 1, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3030 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3031 ok((char)pictureOut
[0] == 2, "Bottom-up -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut
[0]);
3032 /*Check both scanlines.*/
3033 statusCode
= GetDIBits(hdc
, bmptb
, 0, 2, pictureOut
, &bi
, DIB_RGB_COLORS
);
3034 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3035 ok((char)pictureOut
[0] == 2, "Top-down -> bottom-up: first scanline should be 2 but was %d.\n", (char)pictureOut
[0]);
3036 ok((char)pictureOut
[1] == 0, "Top-down -> bottom-up: second scanline should be 0 but was %d.\n", (char)pictureOut
[0]);
3037 statusCode
= GetDIBits(hdc
, bmpbt
, 0, 2, pictureOut
, &bi
, DIB_RGB_COLORS
);
3038 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3039 ok((char)pictureOut
[0] == 0, "Bottom up -> bottom-up: first scanline should be 0 but was %d.\n", (char)pictureOut
[0]);
3040 ok((char)pictureOut
[1] == 2, "Bottom up -> bottom-up: second scanline should be 2 but was %d.\n", (char)pictureOut
[0]);
3042 /*Make destination bitmap top-down.*/
3043 bi
.bmiHeader
.biHeight
= -2;
3044 statusCode
= GetDIBits(hdc
, bmpbt
, 0, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3045 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3046 ok((char)pictureOut
[0] == 0, "Bottom-up -> top-down: first pixel should be 0 but was %d.\n", (char)pictureOut
[0]);
3047 statusCode
= GetDIBits(hdc
, bmptb
, 0, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3048 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3049 ok((char)pictureOut
[0] == 2, "Top-down -> top-down: first pixel should be 2 but was %d.\n", (char)pictureOut
[0]);
3050 /*Check second scanline.*/
3051 statusCode
= GetDIBits(hdc
, bmptb
, 1, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3052 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3053 ok((char)pictureOut
[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut
[0]);
3054 statusCode
= GetDIBits(hdc
, bmpbt
, 1, 1, pictureOut
, &bi
, DIB_RGB_COLORS
);
3055 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3056 ok((char)pictureOut
[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut
[0]);
3057 /*Check both scanlines.*/
3058 statusCode
= GetDIBits(hdc
, bmptb
, 0, 2, pictureOut
, &bi
, DIB_RGB_COLORS
);
3059 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3060 ok((char)pictureOut
[0] == 0, "Top-down -> top-down: first scanline should be 0 but was %d.\n", (char)pictureOut
[0]);
3061 ok((char)pictureOut
[1] == 2, "Top-down -> top-down: second scanline should be 2 but was %d.\n", (char)pictureOut
[0]);
3062 statusCode
= GetDIBits(hdc
, bmpbt
, 0, 2, pictureOut
, &bi
, DIB_RGB_COLORS
);
3063 ok(statusCode
, "Failed to call GetDIBits. Status code: %d.\n", statusCode
);
3064 ok((char)pictureOut
[0] == 2, "Bottom up -> top-down: first scanline should be 2 but was %d.\n", (char)pictureOut
[0]);
3065 ok((char)pictureOut
[1] == 0, "Bottom up -> top-down: second scanline should be 0 but was %d.\n", (char)pictureOut
[0]);
3067 DeleteObject(bmpbt
);
3068 DeleteObject(bmptb
);
3075 hdll
= GetModuleHandle("gdi32.dll");
3076 pGdiAlphaBlend
= (void*)GetProcAddress(hdll
, "GdiAlphaBlend");
3078 test_createdibitmap();
3080 test_mono_dibsection();
3083 test_GetDIBits_selected_DIB(1);
3084 test_GetDIBits_selected_DIB(4);
3085 test_GetDIBits_selected_DIB(8);
3086 test_GetDIBits_selected_DDB(TRUE
);
3087 test_GetDIBits_selected_DDB(FALSE
);
3089 test_GetDIBits_BI_BITFIELDS();
3090 test_select_object();
3091 test_CreateBitmap();
3094 test_StretchDIBits();
3095 test_GdiAlphaBlend();
3096 test_32bit_bitmap_blt();
3097 test_bitmapinfoheadersize();
3100 test_GetDIBits_top_down(16);
3101 test_GetDIBits_top_down(24);
3102 test_GetDIBits_top_down(32);