ReactOS 0.4.17-dev-116-ga4b6fe9
bitmap.c
Go to the documentation of this file.
1/*
2 * Unit test suite for bitmaps
3 *
4 * Copyright 2004 Huw Davies
5 * Copyright 2006 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdarg.h>
23#include <assert.h>
24#include <string.h>
25
26#include "ntstatus.h"
27#define WIN32_NO_STATUS
28#include "windef.h"
29#include "winbase.h"
30#include "winerror.h"
31#include "wingdi.h"
32#include "winuser.h"
33#include "mmsystem.h"
34#include "winternl.h"
35#include "ddk/d3dkmthk.h"
36
37#include "wine/test.h"
38
39#ifndef __REACTOS__ /* CORE-11331 */
40static NTSTATUS (WINAPI *pD3DKMTCreateDCFromMemory)( D3DKMT_CREATEDCFROMMEMORY *desc );
41static NTSTATUS (WINAPI *pD3DKMTDestroyDCFromMemory)( const D3DKMT_DESTROYDCFROMMEMORY *desc );
42#endif
43static BOOL (WINAPI *pGdiAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
44static BOOL (WINAPI *pGdiGradientFill)(HDC,TRIVERTEX*,ULONG,void*,ULONG,ULONG);
45
46static inline int get_bitmap_stride( int width, int bpp )
47{
48 return ((width * bpp + 15) >> 3) & ~1;
49}
50
51static inline int get_dib_stride( int width, int bpp )
52{
53 return ((width * bpp + 31) >> 3) & ~3;
54}
55
56static inline int get_dib_image_size( const BITMAPINFO *info )
57{
58 return get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount )
59 * abs( info->bmiHeader.biHeight );
60}
61
62static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
63{
64 BITMAP bm;
65 BITMAP bma[2];
67 BYTE buf[512], buf_cmp[512];
68 INT test_size[] = {0 /*first value will be changed */, 0, -1, -1000, ~0, sizeof(buf)};
69
70 ret = GetObjectW(hbm, sizeof(bm), &bm);
71 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
72
73 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
74 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
75 ok(bm.bmHeight == bmih->biHeight, "wrong bm.bmHeight %d\n", bm.bmHeight);
77 ok(bm.bmWidthBytes == width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, width_bytes);
78 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
79 ok(bm.bmBitsPixel == expected_depth, "wrong bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, expected_depth);
80 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
81
82 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
83 assert(sizeof(buf) == sizeof(buf_cmp));
84
85 SetLastError(0xdeadbeef);
86 test_size[0] = bm.bmWidthBytes * bm.bmHeight;
87 /* NULL output buffer with different count values */
88 for (i = 0; i < ARRAY_SIZE(test_size); i++)
89 {
91 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
92 }
93
94 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
95 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
96
97 /* Correct output buffer with different count values */
98 for (i = 0; i < ARRAY_SIZE(test_size); i++)
99 {
100 int expect = i == 1 ? 0 : bm.bmWidthBytes * bm.bmHeight;
101 memset(buf, 0xAA, sizeof(buf));
103 ok(ret == expect, "Test[%d]: %d != %d\n", i, ret, expect);
104 if (expect)
105 ok(!memcmp(buf, buf_cmp, sizeof(buf)),
106 "Test[%d]: buffers do not match, depth %d\n", i, bmih->biBitCount);
107 }
108
109 /* test various buffer sizes for GetObject */
110 ret = GetObjectW(hbm, sizeof(*bma) * 2, bma);
111 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
112
113 ret = GetObjectW(hbm, sizeof(bm) / 2, &bm);
114 ok(ret == 0, "%d != 0\n", ret);
115
116 ret = GetObjectW(hbm, 0, &bm);
117 ok(ret == 0, "%d != 0\n", ret);
118
119 ret = GetObjectW(hbm, 1, &bm);
120 ok(ret == 0, "%d != 0\n", ret);
121
122 ret = GetObjectW(hbm, 0, NULL);
123 ok(ret == sizeof(bm), "wrong size %d\n", ret);
124}
125
126static void test_createdibitmap(void)
127{
128 HDC hdc, hdcmem;
129 BITMAPINFOHEADER bmih;
130 BITMAPINFO bm;
131 HBITMAP hbm, hbm_colour, hbm_old;
132 INT screen_depth;
133 DWORD pixel;
134
135 hdc = GetDC(0);
136 screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
137 memset(&bmih, 0, sizeof(bmih));
138 bmih.biSize = sizeof(bmih);
139 bmih.biWidth = 10;
140 bmih.biHeight = 10;
141 bmih.biPlanes = 1;
142 bmih.biBitCount = 32;
143 bmih.biCompression = BI_RGB;
144
146 ok(hbm == NULL, "CreateDIBitmap should fail\n");
147 hbm = CreateDIBitmap(hdc, NULL, 0, NULL, NULL, 0);
148 ok(hbm == NULL, "CreateDIBitmap should fail\n");
149
150 /* First create an un-initialised bitmap. The depth of the bitmap
151 should match that of the hdc and not that supplied in bmih.
152 */
153
154 /* First try 32 bits */
155 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
156 ok(hbm != NULL, "CreateDIBitmap failed\n");
157 test_bitmap_info(hbm, screen_depth, &bmih);
159
160 /* Then 16 */
161 bmih.biBitCount = 16;
162 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
163 ok(hbm != NULL, "CreateDIBitmap failed\n");
164 test_bitmap_info(hbm, screen_depth, &bmih);
166
167 /* Then 1 */
168 bmih.biBitCount = 1;
169 hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
170 ok(hbm != NULL, "CreateDIBitmap failed\n");
171 test_bitmap_info(hbm, screen_depth, &bmih);
173
174 /* Now with a monochrome dc we expect a monochrome bitmap */
175 hdcmem = CreateCompatibleDC(hdc);
176
177 /* First try 32 bits */
178 bmih.biBitCount = 32;
179 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
180 ok(hbm != NULL, "CreateDIBitmap failed\n");
181 test_bitmap_info(hbm, 1, &bmih);
183
184 /* Then 16 */
185 bmih.biBitCount = 16;
186 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
187 ok(hbm != NULL, "CreateDIBitmap failed\n");
188 test_bitmap_info(hbm, 1, &bmih);
190
191 /* Then 1 */
192 bmih.biBitCount = 1;
193 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
194 ok(hbm != NULL, "CreateDIBitmap failed\n");
195 test_bitmap_info(hbm, 1, &bmih);
197
198 /* Now select a polychrome bitmap into the dc and we expect
199 screen_depth bitmaps again */
200 hbm_colour = CreateCompatibleBitmap(hdc, bmih.biWidth, bmih.biHeight);
201 test_bitmap_info(hbm_colour, screen_depth, &bmih);
202 hbm_old = SelectObject(hdcmem, hbm_colour);
203
204 /* First try 32 bits */
205 bmih.biBitCount = 32;
206 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
207 ok(hbm != NULL, "CreateDIBitmap failed\n");
208 test_bitmap_info(hbm, screen_depth, &bmih);
210
211 /* Then 16 */
212 bmih.biBitCount = 16;
213 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
214 ok(hbm != NULL, "CreateDIBitmap failed\n");
215 test_bitmap_info(hbm, screen_depth, &bmih);
217
218 /* Then 1 */
219 bmih.biBitCount = 1;
220 hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
221 ok(hbm != NULL, "CreateDIBitmap failed\n");
222 test_bitmap_info(hbm, screen_depth, &bmih);
224
225 SelectObject(hdcmem, hbm_old);
226 DeleteObject(hbm_colour);
227 DeleteDC(hdcmem);
228
229 bmih.biBitCount = 32;
230 hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
231 ok(hbm != NULL, "CreateDIBitmap failed\n");
232 test_bitmap_info(hbm, 1, &bmih);
234
235 /* Test how formats are converted */
236 pixel = 0xffffffff;
237 bmih.biBitCount = 1;
238 bmih.biWidth = 1;
239 bmih.biHeight = 1;
240
241 memset(&bm, 0, sizeof(bm));
242 bm.bmiHeader.biSize = sizeof(bm.bmiHeader);
243 bm.bmiHeader.biWidth = 1;
244 bm.bmiHeader.biHeight = 1;
245 bm.bmiHeader.biPlanes = 1;
246 bm.bmiHeader.biBitCount= 24;
248 bm.bmiHeader.biSizeImage = 0;
249 hbm = CreateDIBitmap(hdc, &bmih, CBM_INIT, &pixel, &bm, DIB_RGB_COLORS);
250 ok(hbm != NULL, "CreateDIBitmap failed\n");
251
252 pixel = 0xdeadbeef;
253 bm.bmiHeader.biBitCount= 32;
254 GetDIBits(hdc, hbm, 0, 1, &pixel, &bm, DIB_RGB_COLORS);
255 ok(pixel == 0x00ffffff, "Reading a 32 bit pixel from a DDB returned %08lx\n", pixel);
257
258 ReleaseDC(0, hdc);
259}
260
261static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
262{
263 BITMAP bm;
264 BITMAP bma[2];
266 DIBSECTION dsa[2];
267 INT ret, bm_width_bytes, dib_width_bytes;
268 BYTE *buf;
269
270 ret = GetObjectW(hbm, sizeof(bm), &bm);
271 ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
272
273 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
274 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
275 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
276 dib_width_bytes = get_dib_stride(bm.bmWidth, bm.bmBitsPixel);
277 bm_width_bytes = get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel);
278 if (bm.bmWidthBytes != dib_width_bytes) /* Win2k bug */
279 ok(bm.bmWidthBytes == bm_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, bm_width_bytes);
280 else
281 ok(bm.bmWidthBytes == dib_width_bytes, "wrong bm.bmWidthBytes %d != %d\n", bm.bmWidthBytes, dib_width_bytes);
282 ok(bm.bmPlanes == bmih->biPlanes, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
283 ok(bm.bmBitsPixel == bmih->biBitCount, "bm.bmBitsPixel %d != %d\n", bm.bmBitsPixel, bmih->biBitCount);
284 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
285
286 buf = malloc(bm.bmWidthBytes * bm.bmHeight + 4096);
287
288 /* GetBitmapBits returns not 32-bit aligned data */
289 SetLastError(0xdeadbeef);
290 ret = GetBitmapBits(hbm, 0, NULL);
291 ok(ret == bm_width_bytes * bm.bmHeight,
292 "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
293
294 memset(buf, 0xAA, bm.bmWidthBytes * bm.bmHeight + 4096);
295 ret = GetBitmapBits(hbm, bm.bmWidthBytes * bm.bmHeight + 4096, buf);
296 ok(ret == bm_width_bytes * bm.bmHeight, "%d != %d\n", ret, bm_width_bytes * bm.bmHeight);
297
298 free(buf);
299
300 /* test various buffer sizes for GetObject */
301 memset(&ds, 0xAA, sizeof(ds));
302 ret = GetObjectW(hbm, sizeof(*bma) * 2, bma);
303 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
304 ok(bm.bmWidth == bmih->biWidth, "wrong bm.bmWidth %d\n", bm.bmWidth);
305 ok(bm.bmHeight == abs(bmih->biHeight), "wrong bm.bmHeight %d\n", bm.bmHeight);
306 ok(bm.bmBits == bits, "wrong bm.bmBits %p != %p\n", bm.bmBits, bits);
307
308 ret = GetObjectW(hbm, sizeof(bm) / 2, &bm);
309 ok(ret == 0, "%d != 0\n", ret);
310
311 ret = GetObjectW(hbm, 0, &bm);
312 ok(ret == 0, "%d != 0\n", ret);
313
314 ret = GetObjectW(hbm, 1, &bm);
315 ok(ret == 0, "%d != 0\n", ret);
316
317 /* test various buffer sizes for GetObject */
318 ret = GetObjectW(hbm, 0, NULL);
319 ok(ret == sizeof(bm), "wrong size %d\n", ret);
320
321 ret = GetObjectW(hbm, sizeof(*dsa) * 2, dsa);
322 ok(ret == sizeof(*dsa), "wrong size %d\n", ret);
323
324 memset(&ds, 0xAA, sizeof(ds));
325 ret = GetObjectW(hbm, sizeof(ds), &ds);
326 ok(ret == sizeof(ds), "wrong size %d\n", ret);
327
328 ok(ds.dsBm.bmBits == bits, "wrong bm.bmBits %p != %p\n", ds.dsBm.bmBits, bits);
329 if (ds.dsBm.bmWidthBytes != bm_width_bytes) /* Win2k bug */
330 ok(ds.dsBmih.biSizeImage == ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight, "%lu != %u\n",
331 ds.dsBmih.biSizeImage, ds.dsBm.bmWidthBytes * ds.dsBm.bmHeight);
332 ok(bmih->biSizeImage == 0, "%lu != 0\n", bmih->biSizeImage);
333 ds.dsBmih.biSizeImage = 0;
334
335 ok(ds.dsBmih.biSize == bmih->biSize, "%lu != %lu\n", ds.dsBmih.biSize, bmih->biSize);
336 ok(ds.dsBmih.biWidth == bmih->biWidth, "%ld != %ld\n", ds.dsBmih.biWidth, bmih->biWidth);
337 ok(ds.dsBmih.biHeight == abs(bmih->biHeight), "%ld != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
338 ok(ds.dsBmih.biPlanes == bmih->biPlanes, "%u != %u\n", ds.dsBmih.biPlanes, bmih->biPlanes);
339 ok(ds.dsBmih.biBitCount == bmih->biBitCount, "%u != %u\n", ds.dsBmih.biBitCount, bmih->biBitCount);
340 ok(ds.dsBmih.biCompression == bmih->biCompression ||
341 ((bmih->biBitCount == 32) && broken(ds.dsBmih.biCompression == BI_BITFIELDS)), /* nt4 sp1 and 2 */
342 "%lu != %lu\n", ds.dsBmih.biCompression, bmih->biCompression);
343 ok(ds.dsBmih.biSizeImage == bmih->biSizeImage, "%lu != %lu\n", ds.dsBmih.biSizeImage, bmih->biSizeImage);
344 ok(ds.dsBmih.biXPelsPerMeter == bmih->biXPelsPerMeter, "%ld != %ld\n", ds.dsBmih.biXPelsPerMeter, bmih->biXPelsPerMeter);
345 ok(ds.dsBmih.biYPelsPerMeter == bmih->biYPelsPerMeter, "%ld != %ld\n", ds.dsBmih.biYPelsPerMeter, bmih->biYPelsPerMeter);
346
347 memset(&ds, 0xAA, sizeof(ds));
348 ret = GetObjectW(hbm, sizeof(ds) - 4, &ds);
349 ok(ret == sizeof(ds.dsBm), "wrong size %d\n", ret);
350 ok(ds.dsBm.bmWidth == bmih->biWidth, "%ld != %ld\n", ds.dsBmih.biWidth, bmih->biWidth);
351 ok(ds.dsBm.bmHeight == abs(bmih->biHeight), "%ld != %d\n", ds.dsBmih.biHeight, abs(bmih->biHeight));
352 ok(ds.dsBm.bmBits == bits, "%p != %p\n", ds.dsBm.bmBits, bits);
353
354 ret = GetObjectW(hbm, 0, &ds);
355 ok(ret == 0, "%d != 0\n", ret);
356
357 ret = GetObjectW(hbm, 1, &ds);
358 ok(ret == 0, "%d != 0\n", ret);
359}
360
362{
363 COLORREF c;
364 c = SetPixel(hdc, 0, 0, color);
365 ok_(__FILE__, line)(c == exp, "SetPixel failed: got 0x%06lx expected 0x%06lx\n", c, exp);
366 c = GetPixel(hdc, 0, 0);
367 ok_(__FILE__, line)(c == exp, "GetPixel failed: got 0x%06lx expected 0x%06lx\n", c, exp);
369 ok_(__FILE__, line)(c == exp, "GetNearestColor failed: got 0x%06lx expected 0x%06lx\n", c, exp);
370}
371#define test_color(hdc, color, exp) _test_color( __LINE__, hdc, color, exp )
372
373
374static void test_dib_bits_access( HBITMAP hdib, void *bits )
375{
377 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
378 DWORD data[256];
379 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
380 HDC hdc;
381 char filename[MAX_PATH];
382 HANDLE file;
383 DWORD written;
384 INT ret;
385
386 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
387 "VirtualQuery failed\n");
388 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
389 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
390 ok(info.AllocationProtect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.AllocationProtect);
391 ok(info.State == MEM_COMMIT, "%lx != MEM_COMMIT\n", info.State);
392 ok(info.Protect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.Protect);
393 ok(info.Type == MEM_PRIVATE, "%lx != MEM_PRIVATE\n", info.Type);
394
395 memset( pbmi, 0, sizeof(bmibuf) );
396 memset( data, 0xcc, sizeof(data) );
397 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
398 pbmi->bmiHeader.biHeight = 16;
399 pbmi->bmiHeader.biWidth = 16;
403
404 hdc = GetDC(0);
405
406 ret = SetDIBits( hdc, hdib, 0, 16, data, pbmi, DIB_RGB_COLORS );
407 ok(ret == 16, "SetDIBits failed: expected 16 got %d\n", ret);
408
409 ReleaseDC(0, hdc);
410
411 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
412 "VirtualQuery failed\n");
413 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
414 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
415 ok(info.AllocationProtect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.AllocationProtect);
416 ok(info.State == MEM_COMMIT, "%lx != MEM_COMMIT\n", info.State);
417 ok(info.Type == MEM_PRIVATE, "%lx != MEM_PRIVATE\n", info.Type);
418 ok(info.Protect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.Protect);
419
420 /* try writing protected bits to a file */
421
422 GetTempFileNameA( ".", "dib", 0, filename );
424 CREATE_ALWAYS, 0, 0 );
425 ok( file != INVALID_HANDLE_VALUE, "failed to open %s error %lu\n", filename, GetLastError() );
426 ret = WriteFile( file, bits, 8192, &written, NULL );
427 ok( ret, "WriteFile failed error %lu\n", GetLastError() );
428 if (ret) ok( written == 8192, "only wrote %lu bytes\n", written );
429 CloseHandle( file );
431}
432
433static void test_dibsections(void)
434{
435 HDC hdc, hdcmem, hdcmem2;
436 HBITMAP hdib, oldbm, hdib2, oldbm2;
437 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
438 char bcibuf[sizeof(BITMAPCOREINFO) + 256 * sizeof(RGBTRIPLE)];
439 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
440 BITMAPCOREINFO *pbci = (BITMAPCOREINFO *)bcibuf;
441 RGBQUAD *colors = pbmi->bmiColors;
442 RGBTRIPLE *ccolors = pbci->bmciColors;
443 HBITMAP hcoredib;
444 char coreBits[256];
445 BYTE *bits;
446 RGBQUAD rgb[256];
447 int ret;
448 char logpalbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
449 LOGPALETTE *plogpal = (LOGPALETTE*)logpalbuf;
450 PALETTEENTRY *palent = plogpal->palPalEntry;
451 WORD *index;
452 DWORD *bits32;
453 HPALETTE hpal, oldpal;
454 DIBSECTION dibsec;
455 COLORREF c0, c1;
456 int i;
458
459 hdc = GetDC(0);
460
461 memset(pbmi, 0, sizeof(bmibuf));
462 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
463 pbmi->bmiHeader.biHeight = 100;
464 pbmi->bmiHeader.biWidth = 512;
468
469 SetLastError(0xdeadbeef);
470
471 /* invalid pointer for BITMAPINFO
472 (*bits should be NULL on error) */
473 bits = (BYTE*)0xdeadbeef;
474 hdib = CreateDIBSection(hdc, NULL, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
475 ok(hdib == NULL && bits == NULL, "CreateDIBSection failed for invalid parameter: bmi == 0x0\n");
476
477 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
478 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
479 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
480 ok(dibsec.dsBm.bmBits == bits, "dibsec.dsBits %p != bits %p\n", dibsec.dsBm.bmBits, bits);
481
482 /* test the DIB memory */
483 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
484 "VirtualQuery failed\n");
485 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
486 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
487 ok(info.AllocationProtect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.AllocationProtect);
488 ok(info.RegionSize == 0x26000, "0x%Ix != 0x26000\n", info.RegionSize);
489 ok(info.State == MEM_COMMIT, "%lx != MEM_COMMIT\n", info.State);
490 ok(info.Protect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.Protect);
491 ok(info.Type == MEM_PRIVATE, "%lx != MEM_PRIVATE\n", info.Type);
492
493 test_dib_bits_access( hdib, bits );
494
496 DeleteObject(hdib);
497
498 /* Test a top-down DIB. */
499 pbmi->bmiHeader.biHeight = -100;
500 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
501 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
503 DeleteObject(hdib);
504
505 pbmi->bmiHeader.biHeight = 100;
508 SetLastError(0xdeadbeef);
509 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
510 ok(hdib == NULL, "CreateDIBSection should fail when asked to create a compressed DIB section\n");
511 ok(GetLastError() == 0xdeadbeef, "wrong error %ld\n", GetLastError());
512
515 ((PDWORD)pbmi->bmiColors)[0] = 0xf800;
516 ((PDWORD)pbmi->bmiColors)[1] = 0x07e0;
517 ((PDWORD)pbmi->bmiColors)[2] = 0x001f;
518 SetLastError(0xdeadbeef);
519 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
520 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
521
522 /* test the DIB memory */
523 ok(VirtualQuery(bits, &info, sizeof(info)) == sizeof(info),
524 "VirtualQuery failed\n");
525 ok(info.BaseAddress == bits, "%p != %p\n", info.BaseAddress, bits);
526 ok(info.AllocationBase == bits, "%p != %p\n", info.AllocationBase, bits);
527 ok(info.AllocationProtect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.AllocationProtect);
528 ok(info.RegionSize == 0x19000, "0x%Ix != 0x19000\n", info.RegionSize);
529 ok(info.State == MEM_COMMIT, "%lx != MEM_COMMIT\n", info.State);
530 ok(info.Protect == PAGE_READWRITE, "%lx != PAGE_READWRITE\n", info.Protect);
531 ok(info.Type == MEM_PRIVATE, "%lx != MEM_PRIVATE\n", info.Type);
532
534 DeleteObject(hdib);
535
536 memset(pbmi, 0, sizeof(bmibuf));
537 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
538 pbmi->bmiHeader.biHeight = 16;
539 pbmi->bmiHeader.biWidth = 16;
543 colors[0].rgbRed = 0xff;
544 colors[0].rgbGreen = 0;
545 colors[0].rgbBlue = 0;
546 colors[1].rgbRed = 0;
547 colors[1].rgbGreen = 0;
548 colors[1].rgbBlue = 0xff;
549
550 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
551 ok(hdib != NULL, "CreateDIBSection failed\n");
552 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIBSection\n");
553 ok(dibsec.dsBmih.biClrUsed == 2,
554 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
555
556 /* Test if the old BITMAPCOREINFO structure is supported */
557
558 pbci->bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
559 pbci->bmciHeader.bcBitCount = 0;
560
561 ret = GetDIBits(hdc, hdib, 0, 16, NULL, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
562 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
563 ok((pbci->bmciHeader.bcWidth == 16) && (pbci->bmciHeader.bcHeight == 16)
564 && (pbci->bmciHeader.bcBitCount == 1) && (pbci->bmciHeader.bcPlanes == 1),
565 "GetDIBits didn't fill in the BITMAPCOREHEADER structure properly\n");
566
567 ret = GetDIBits(hdc, hdib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
568 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
569 ok((ccolors[0].rgbtRed == 0xff) && (ccolors[0].rgbtGreen == 0) &&
570 (ccolors[0].rgbtBlue == 0) && (ccolors[1].rgbtRed == 0) &&
571 (ccolors[1].rgbtGreen == 0) && (ccolors[1].rgbtBlue == 0xff),
572 "The color table has not been translated to the old BITMAPCOREINFO format\n");
573
574 hcoredib = CreateDIBSection(hdc, (BITMAPINFO*) pbci, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
575 ok(hcoredib != NULL, "CreateDIBSection failed with a BITMAPCOREINFO\n");
576
577 ZeroMemory(ccolors, 256 * sizeof(RGBTRIPLE));
578 ret = GetDIBits(hdc, hcoredib, 0, 16, &coreBits, (BITMAPINFO*) pbci, DIB_RGB_COLORS);
579 ok(ret, "GetDIBits doesn't work with a BITMAPCOREHEADER\n");
580 ok((ccolors[0].rgbtRed == 0xff) && (ccolors[0].rgbtGreen == 0) &&
581 (ccolors[0].rgbtBlue == 0) && (ccolors[1].rgbtRed == 0) &&
582 (ccolors[1].rgbtGreen == 0) && (ccolors[1].rgbtBlue == 0xff),
583 "The color table has not been translated to the old BITMAPCOREINFO format\n");
584
585 DeleteObject(hcoredib);
586
587 hdcmem = CreateCompatibleDC(hdc);
588 oldbm = SelectObject(hdcmem, hdib);
589
590 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
591 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
592 ok(!memcmp(rgb, pbmi->bmiColors, 2 * sizeof(RGBQUAD)),
593 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
594 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
595 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
596
597 c0 = RGB(colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue);
598 c1 = RGB(colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue);
599
600 test_color(hdcmem, DIBINDEX(0), c0);
601 test_color(hdcmem, DIBINDEX(1), c1);
602 test_color(hdcmem, DIBINDEX(2), c0);
603 test_color(hdcmem, PALETTEINDEX(0), c0);
604 test_color(hdcmem, PALETTEINDEX(1), c0);
605 test_color(hdcmem, PALETTEINDEX(2), c0);
606 test_color(hdcmem, PALETTERGB(colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue), c0);
607 test_color(hdcmem, PALETTERGB(colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue), c1);
608 test_color(hdcmem, PALETTERGB(0, 0, 0), c0);
609 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0);
610 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c1);
611
612 SelectObject(hdcmem, oldbm);
613 DeleteObject(hdib);
614
615 colors[0].rgbRed = 0xff;
616 colors[0].rgbGreen = 0xff;
617 colors[0].rgbBlue = 0xff;
618 colors[1].rgbRed = 0;
619 colors[1].rgbGreen = 0;
620 colors[1].rgbBlue = 0;
621
622 hdib = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
623 ok(hdib != NULL, "CreateDIBSection failed\n");
624
626
627 oldbm = SelectObject(hdcmem, hdib);
628
629 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
630 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
631 ok(!memcmp(rgb, colors, 2 * sizeof(RGBQUAD)),
632 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
633 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
634 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
635
636 SelectObject(hdcmem, oldbm);
638 DeleteObject(hdib);
639
641 for (i = 0; i < 16; i++) {
642 colors[i].rgbRed = i;
643 colors[i].rgbGreen = 16-i;
644 colors[i].rgbBlue = 0;
645 }
646 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
647 ok(hdib != NULL, "CreateDIBSection failed\n");
648 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
649 ok(dibsec.dsBmih.biClrUsed == 16,
650 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 16);
652 DeleteObject(hdib);
653
655
656 for (i = 0; i < 128; i++) {
657 colors[i].rgbRed = 255 - i * 2;
658 colors[i].rgbGreen = i * 2;
659 colors[i].rgbBlue = 0;
660 colors[255 - i].rgbRed = 0;
661 colors[255 - i].rgbGreen = i * 2;
662 colors[255 - i].rgbBlue = 255 - i * 2;
663 }
664 hdib = CreateDIBSection(hdcmem, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
665 ok(hdib != NULL, "CreateDIBSection failed\n");
666 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
667 ok(dibsec.dsBmih.biClrUsed == 256,
668 "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
669
670 oldbm = SelectObject(hdcmem, hdib);
671
672 for (i = 0; i < 256; i++) {
673 test_color(hdcmem, DIBINDEX(i), RGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue));
674 test_color(hdcmem, PALETTERGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue),
675 RGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue));
676 }
677
678 SelectObject(hdcmem, oldbm);
680 DeleteObject(hdib);
681
683
684 /* Now create a palette and a palette indexed dib section */
685 memset(plogpal, 0, sizeof(logpalbuf));
686 plogpal->palVersion = 0x300;
687 plogpal->palNumEntries = 2;
688 palent[0].peRed = 0xff;
689 palent[0].peBlue = 0xff;
690 palent[1].peGreen = 0xff;
691
693 *index++ = 0;
694 *index = 1;
695 hpal = CreatePalette(plogpal);
696 ok(hpal != NULL, "CreatePalette failed\n");
697 oldpal = SelectPalette(hdc, hpal, TRUE);
698 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
699 ok(hdib != NULL, "CreateDIBSection failed\n");
700 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
701 ok(dibsec.dsBmih.biClrUsed == 2, "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 2);
702
703 /* The colour table has already been grabbed from the dc, so we select back the
704 old palette */
705
706 SelectPalette(hdc, oldpal, TRUE);
707 oldbm = SelectObject(hdcmem, hdib);
708 oldpal = SelectPalette(hdcmem, hpal, TRUE);
709
710 ret = GetDIBColorTable(hdcmem, 0, 2, rgb);
711 ok(ret == 2, "GetDIBColorTable returned %d\n", ret);
712 ok(rgb[0].rgbRed == 0xff && rgb[0].rgbBlue == 0xff && rgb[0].rgbGreen == 0 &&
713 rgb[1].rgbRed == 0 && rgb[1].rgbBlue == 0 && rgb[1].rgbGreen == 0xff,
714 "GetDIBColorTable returns table 0: r%02x g%02x b%02x res%02x 1: r%02x g%02x b%02x res%02x\n",
715 rgb[0].rgbRed, rgb[0].rgbGreen, rgb[0].rgbBlue, rgb[0].rgbReserved,
716 rgb[1].rgbRed, rgb[1].rgbGreen, rgb[1].rgbBlue, rgb[1].rgbReserved);
717
718 c0 = RGB(palent[0].peRed, palent[0].peGreen, palent[0].peBlue);
719 c1 = RGB(palent[1].peRed, palent[1].peGreen, palent[1].peBlue);
720
721 test_color(hdcmem, DIBINDEX(0), c0);
722 test_color(hdcmem, DIBINDEX(1), c1);
723 test_color(hdcmem, DIBINDEX(2), c0);
724 test_color(hdcmem, PALETTEINDEX(0), c0);
725 test_color(hdcmem, PALETTEINDEX(1), c1);
726 test_color(hdcmem, PALETTEINDEX(2), c0);
727 test_color(hdcmem, PALETTERGB(palent[0].peRed, palent[0].peGreen, palent[0].peBlue), c0);
728 test_color(hdcmem, PALETTERGB(palent[1].peRed, palent[1].peGreen, palent[1].peBlue), c1);
729 test_color(hdcmem, PALETTERGB(0, 0, 0), c1);
730 test_color(hdcmem, PALETTERGB(0xff, 0xff, 0xff), c0);
731 test_color(hdcmem, PALETTERGB(0, 0, 0xfe), c0);
732 test_color(hdcmem, PALETTERGB(0, 1, 0), c1);
733 test_color(hdcmem, PALETTERGB(0x3f, 0, 0x3f), c1);
734 test_color(hdcmem, PALETTERGB(0x40, 0, 0x40), c0);
735
736 /* Bottom and 2nd row from top green, everything else magenta */
737 bits[0] = bits[1] = 0xff;
738 bits[13 * 4] = bits[13*4 + 1] = 0xff;
739
741
743
744 hdib2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (void **)&bits32, NULL, 0);
745 ok(hdib2 != NULL, "CreateDIBSection failed\n");
746 hdcmem2 = CreateCompatibleDC(hdc);
747 oldbm2 = SelectObject(hdcmem2, hdib2);
748
749 BitBlt(hdcmem2, 0, 0, 16,16, hdcmem, 0, 0, SRCCOPY);
750
751 ok(bits32[0] == 0xff00, "lower left pixel is %08lx\n", bits32[0]);
752 ok(bits32[17] == 0xff00ff, "bottom but one, left pixel is %08lx\n", bits32[17]);
753
754 SelectObject(hdcmem2, oldbm2);
755 test_dib_info(hdib2, bits32, &pbmi->bmiHeader);
756 DeleteObject(hdib2);
757
758 SelectObject(hdcmem, oldbm);
759 SelectPalette(hdcmem, oldpal, TRUE);
760 DeleteObject(hdib);
761 DeleteObject(hpal);
762
763
765
766 memset(plogpal, 0, sizeof(logpalbuf));
767 plogpal->palVersion = 0x300;
768 plogpal->palNumEntries = 256;
769
770 for (i = 0; i < 128; i++) {
771 palent[i].peRed = 255 - i * 2;
772 palent[i].peBlue = i * 2;
773 palent[i].peGreen = 0;
774 palent[255 - i].peRed = 0;
775 palent[255 - i].peGreen = i * 2;
776 palent[255 - i].peBlue = 255 - i * 2;
777 }
778
780 for (i = 0; i < 256; i++) {
781 *index++ = i;
782 }
783
784 hpal = CreatePalette(plogpal);
785 ok(hpal != NULL, "CreatePalette failed\n");
786 oldpal = SelectPalette(hdc, hpal, TRUE);
787 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
788 ok(hdib != NULL, "CreateDIBSection failed\n");
789 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
790 ok(dibsec.dsBmih.biClrUsed == 256, "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
791
793
794 SelectPalette(hdc, oldpal, TRUE);
795 oldbm = SelectObject(hdcmem, hdib);
796 oldpal = SelectPalette(hdcmem, hpal, TRUE);
797
798 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
799 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
800 for (i = 0; i < 256; i++) {
801 ok(rgb[i].rgbRed == palent[i].peRed &&
802 rgb[i].rgbBlue == palent[i].peBlue &&
803 rgb[i].rgbGreen == palent[i].peGreen,
804 "GetDIBColorTable returns table %d: r%02x g%02x b%02x res%02x\n",
805 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
806 }
807
808 for (i = 0; i < 256; i++) {
809 test_color(hdcmem, DIBINDEX(i), RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
810 test_color(hdcmem, PALETTEINDEX(i), RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
811 test_color(hdcmem, PALETTERGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue),
812 RGB(palent[i].peRed, palent[i].peGreen, palent[i].peBlue));
813 }
814
815 SelectPalette(hdcmem, oldpal, TRUE);
816 SelectObject(hdcmem, oldbm);
817 DeleteObject(hdib);
818 DeleteObject(hpal);
819
820 plogpal->palNumEntries = 37;
821 hpal = CreatePalette(plogpal);
822 ok(hpal != NULL, "CreatePalette failed\n");
823 oldpal = SelectPalette(hdc, hpal, TRUE);
824 pbmi->bmiHeader.biClrUsed = 142;
825 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
826 ok(hdib != NULL, "CreateDIBSection failed\n");
827 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
828 ok(dibsec.dsBmih.biClrUsed == 256, "created DIBSection: wrong biClrUsed field: %lu, should be: %u\n", dibsec.dsBmih.biClrUsed, 256);
829
831
832 SelectPalette(hdc, oldpal, TRUE);
833 oldbm = SelectObject(hdcmem, hdib);
834
835 memset( rgb, 0xcc, sizeof(rgb) );
836 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
837 ok(ret == 256, "GetDIBColorTable returned %d\n", ret);
838 for (i = 0; i < 256; i++)
839 {
840 if (i < pbmi->bmiHeader.biClrUsed)
841 {
842 ok(rgb[i].rgbRed == palent[i % 37].peRed &&
843 rgb[i].rgbBlue == palent[i % 37].peBlue &&
844 rgb[i].rgbGreen == palent[i % 37].peGreen,
845 "GetDIBColorTable returns table %d: r %02x g %02x b %02x res%02x\n",
846 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
847 test_color(hdcmem, DIBINDEX(i),
848 RGB(palent[i % 37].peRed, palent[i % 37].peGreen, palent[i % 37].peBlue));
849 }
850 else
851 {
852 ok(rgb[i].rgbRed == 0 && rgb[i].rgbBlue == 0 && rgb[i].rgbGreen == 0,
853 "GetDIBColorTable returns table %d: r %02x g %02x b %02x res%02x\n",
854 i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue, rgb[i].rgbReserved);
855 test_color(hdcmem, DIBINDEX(i), 0 );
856 }
857 }
858 pbmi->bmiHeader.biClrUsed = 173;
859 memset( pbmi->bmiColors, 0xcc, 256 * sizeof(RGBQUAD) );
860 GetDIBits( hdc, hdib, 0, 1, NULL, pbmi, DIB_RGB_COLORS );
861 ok( pbmi->bmiHeader.biClrUsed == 0, "wrong colors %lu\n", pbmi->bmiHeader.biClrUsed );
862 for (i = 0; i < 256; i++)
863 {
864 if (i < 142)
865 ok(colors[i].rgbRed == palent[i % 37].peRed &&
866 colors[i].rgbBlue == palent[i % 37].peBlue &&
867 colors[i].rgbGreen == palent[i % 37].peGreen,
868 "GetDIBits returns table %d: r %02x g %02x b %02x res%02x\n",
869 i, colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
870 else
871 ok(colors[i].rgbRed == 0 && colors[i].rgbBlue == 0 && colors[i].rgbGreen == 0,
872 "GetDIBits returns table %d: r %02x g %02x b %02x res%02x\n",
873 i, colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
874 }
875
876 rgb[0].rgbRed = 1;
877 rgb[0].rgbGreen = 2;
878 rgb[0].rgbBlue = 3;
879 rgb[0].rgbReserved = 123;
880 ret = SetDIBColorTable( hdcmem, 0, 1, rgb );
881 ok( ret == 1, "SetDIBColorTable returned unexpected result %u\n", ret );
882 ok( rgb[0].rgbReserved == 123, "Expected rgbReserved = 123, got %u\n", rgb[0].rgbReserved );
883
884 rgb[0].rgbRed = rgb[0].rgbGreen = rgb[0].rgbBlue = rgb[0].rgbReserved = -1;
885 ret = GetDIBColorTable( hdcmem, 0, 1, rgb );
886 ok( ret == 1, "GetDIBColorTable returned unexpected result %u\n", ret );
887 ok( rgb[0].rgbRed == 1, "Expected rgbRed = 1, got %u\n", rgb[0].rgbRed );
888 ok( rgb[0].rgbGreen == 2, "Expected rgbGreen = 2, got %u\n", rgb[0].rgbGreen );
889 ok( rgb[0].rgbBlue == 3, "Expected rgbBlue = 3, got %u\n", rgb[0].rgbBlue );
890 ok( rgb[0].rgbReserved == 0, "Expected rgbReserved = 0, got %u\n", rgb[0].rgbReserved );
891
892 SelectObject(hdcmem, oldbm);
893 DeleteObject(hdib);
894 DeleteObject(hpal);
895
896 /* ClrUsed ignored on > 8bpp */
899 hdib = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (void**)&bits, NULL, 0);
900 ok(hdib != NULL, "CreateDIBSection failed\n");
901 ok(GetObjectW(hdib, sizeof(DIBSECTION), &dibsec) != 0, "GetObject failed for DIB Section\n");
902 ok(dibsec.dsBmih.biClrUsed == 0, "created DIBSection: wrong biClrUsed field: %lu\n", dibsec.dsBmih.biClrUsed);
903 oldbm = SelectObject(hdcmem, hdib);
904 ret = GetDIBColorTable(hdcmem, 0, 256, rgb);
905 ok(ret == 0, "GetDIBColorTable returned %d\n", ret);
906 SelectObject(hdcmem, oldbm);
907 DeleteObject(hdib);
908
909 DeleteDC(hdcmem);
910 DeleteDC(hdcmem2);
911 ReleaseDC(0, hdc);
912}
913
914static void test_dib_formats(void)
915{
916 BITMAPINFO *bi;
917 char data[2048]; /* 2 x 2 pixels, max 64 bits-per-pixel, max 64 planes */
918 void *bits;
919 int planes, bpp, compr, format;
920 HBITMAP hdib, hbmp, hbmp_mono;
921 HDC hdc, memdc;
922 UINT ret;
923 BOOL format_ok, expect_ok;
924
925 bi = malloc( FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
926 hdc = GetDC( 0 );
927 memdc = CreateCompatibleDC( 0 );
928 hbmp = CreateCompatibleBitmap( hdc, 10, 10 );
929 hbmp_mono = CreateBitmap( 10, 10, 1, 1, NULL );
930
931 memset( data, 0xaa, sizeof(data) );
932
934 skip("ROSTESTS-152: Skipping loop in test_dib_formats because it's too big and causes too many failures\n");
935 else
936 for (bpp = 0; bpp <= 64; bpp++)
937 {
938 for (planes = 0; planes <= 64; planes++)
939 {
940 for (compr = 0; compr < 8; compr++)
941 {
943 {
944 switch (bpp)
945 {
946 case 1:
947 case 4:
948 case 8:
949 case 24: expect_ok = (compr == BI_RGB); break;
950 case 16:
951 case 32: expect_ok = (compr == BI_RGB || compr == BI_BITFIELDS); break;
952 default: expect_ok = FALSE; break;
953 }
954
955 memset( bi, 0, sizeof(bi->bmiHeader) );
956 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
957 bi->bmiHeader.biWidth = 2;
958 bi->bmiHeader.biHeight = 2;
959 bi->bmiHeader.biPlanes = planes;
962 bi->bmiHeader.biSizeImage = 0;
963 memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
964 ret = GetDIBits(hdc, hbmp, 0, 0, data, bi, format);
965 if (expect_ok || (!bpp && compr != BI_JPEG && compr != BI_PNG) ||
966 (bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8))
967 ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
968 else
969 ok( !ret || broken(!bpp && (compr == BI_JPEG || compr == BI_PNG)), /* nt4 */
970 "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
971
972 /* all functions check planes except GetDIBits with 0 lines */
973 format_ok = expect_ok;
974 if (!planes) expect_ok = FALSE;
975 memset( bi, 0, sizeof(bi->bmiHeader) );
976 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
977 bi->bmiHeader.biWidth = 2;
978 bi->bmiHeader.biHeight = 2;
979 bi->bmiHeader.biPlanes = planes;
982 bi->bmiHeader.biSizeImage = 0;
983 memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
984
985 hdib = CreateDIBSection(hdc, bi, format, &bits, NULL, 0);
986 if (expect_ok && (planes == 1 || planes * bpp <= 16) &&
988 ok( hdib != NULL, "CreateDIBSection failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
989 else
990 ok( hdib == NULL, "CreateDIBSection succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
991 if (hdib) DeleteObject( hdib );
992
993 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, data, bi, format );
994 /* no sanity checks in CreateDIBitmap except compression */
995 if (compr == BI_JPEG || compr == BI_PNG)
996 ok( hdib == NULL || broken(hdib != NULL), /* nt4 */
997 "CreateDIBitmap succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
998 else
999 ok( hdib != NULL, "CreateDIBitmap failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1000 if (hdib) DeleteObject( hdib );
1001
1002 /* RLE needs a size */
1003 bi->bmiHeader.biSizeImage = 0;
1004 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, format);
1005 if (expect_ok)
1006 ok( ret, "SetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1007 else
1008 ok( !ret ||
1009 broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
1010 "SetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1011 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, format );
1012 if (expect_ok)
1013 ok( ret, "SetDIBitsToDevice failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1014 else
1015 ok( !ret ||
1016 broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
1017 "SetDIBitsToDevice succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1018 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, format, SRCCOPY );
1019 if (expect_ok)
1020 ok( ret, "StretchDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1021 else
1022 ok( !ret ||
1023 broken((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)), /* nt4 */
1024 "StretchDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1025
1026 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, format);
1027 if (expect_ok)
1028 ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1029 else
1030 ok( !ret, "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1031 ok( bi->bmiHeader.biBitCount == bpp, "GetDIBits modified bpp %u/%u\n",
1032 bpp, bi->bmiHeader.biBitCount );
1033
1034 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1035 bi->bmiHeader.biWidth = 2;
1036 bi->bmiHeader.biHeight = 2;
1037 bi->bmiHeader.biPlanes = planes;
1038 bi->bmiHeader.biBitCount = bpp;
1040 bi->bmiHeader.biSizeImage = 1;
1041 memset( bi->bmiColors, 0xaa, sizeof(RGBQUAD) * 256 );
1042 /* RLE allowed with valid biSizeImage */
1043 if ((bpp == 4 && compr == BI_RLE4) || (bpp == 8 && compr == BI_RLE8)) expect_ok = TRUE;
1044
1045 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, format);
1046 if (expect_ok)
1047 ok( ret, "SetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1048 else
1049 ok( !ret, "SetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1050 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, format );
1051 if (expect_ok)
1052 ok( ret, "SetDIBitsToDevice failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1053 else
1054 ok( !ret, "SetDIBitsToDevice succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1055 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, format, SRCCOPY );
1056 if (expect_ok)
1057 ok( ret, "StretchDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1058 else
1059 ok( !ret, "StretchDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1060
1061 bi->bmiHeader.biSizeImage = 0;
1062 ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, format);
1063 if (expect_ok || !bpp)
1064 ok( ret, "GetDIBits failed for %u/%u/%u/%u\n", bpp, planes, compr, format );
1065 else
1066 ok( !ret || broken(format_ok && !planes), /* nt4 */
1067 "GetDIBits succeeded for %u/%u/%u/%u\n", bpp, planes, compr, format );
1068 }
1069 }
1070 }
1071 }
1072
1073 memset( bi, 0, sizeof(bi->bmiHeader) );
1074 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1075 bi->bmiHeader.biWidth = 2;
1076 bi->bmiHeader.biHeight = 2;
1077 bi->bmiHeader.biPlanes = 1;
1078 bi->bmiHeader.biBitCount = 16;
1080 bi->bmiHeader.biSizeImage = 0;
1081 *(DWORD *)&bi->bmiColors[0] = 0;
1082 *(DWORD *)&bi->bmiColors[1] = 0;
1083 *(DWORD *)&bi->bmiColors[2] = 0;
1084
1085 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1086 ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" );
1087 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1088 ok( !ret, "SetDIBits succeeded with null bitfields\n" );
1089 /* other functions don't check */
1090 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1091 ok( hdib != NULL, "CreateDIBitmap failed with null bitfields\n" );
1092 DeleteObject( hdib );
1093 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
1094 ok( ret, "SetDIBitsToDevice failed with null bitfields\n" );
1095 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
1096 ok( ret, "StretchDIBits failed with null bitfields\n" );
1097 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
1098 ok( ret, "GetDIBits failed with null bitfields\n" );
1099 bi->bmiHeader.biPlanes = 1;
1100 bi->bmiHeader.biBitCount = 16;
1102 bi->bmiHeader.biSizeImage = 0;
1103 *(DWORD *)&bi->bmiColors[0] = 0;
1104 *(DWORD *)&bi->bmiColors[1] = 0;
1105 *(DWORD *)&bi->bmiColors[2] = 0;
1106 ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1107 ok( ret, "GetDIBits failed with null bitfields\n" );
1108
1109 /* all fields must be non-zero */
1110 *(DWORD *)&bi->bmiColors[0] = 3;
1111 *(DWORD *)&bi->bmiColors[1] = 0;
1112 *(DWORD *)&bi->bmiColors[2] = 7;
1113 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1114 ok( hdib == NULL, "CreateDIBSection succeeded with null bitfields\n" );
1115 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1116 ok( !ret, "SetDIBits succeeded with null bitfields\n" );
1117
1118 /* garbage is ok though */
1119 *(DWORD *)&bi->bmiColors[0] = 0x55;
1120 *(DWORD *)&bi->bmiColors[1] = 0x44;
1121 *(DWORD *)&bi->bmiColors[2] = 0x33;
1122 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1123 ok( hdib != NULL, "CreateDIBSection failed with bad bitfields\n" );
1124 if (hdib) DeleteObject( hdib );
1125 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1126 ok( ret, "SetDIBits failed with bad bitfields\n" );
1127
1128 bi->bmiHeader.biWidth = -2;
1129 bi->bmiHeader.biHeight = 2;
1130 bi->bmiHeader.biBitCount = 32;
1132 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1133 ok( hdib == NULL, "CreateDIBSection succeeded with negative width\n" );
1134 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1135 ok( hdib == NULL, "CreateDIBitmap succeeded with negative width\n" );
1136 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1137 ok( !ret, "SetDIBits succeeded with negative width\n" );
1138 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
1139 ok( !ret, "SetDIBitsToDevice succeeded with negative width\n" );
1140 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
1141 ok( !ret, "StretchDIBits succeeded with negative width\n" );
1142 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
1143 ok( !ret, "GetDIBits succeeded with negative width\n" );
1144 bi->bmiHeader.biWidth = -2;
1145 bi->bmiHeader.biHeight = 2;
1146 bi->bmiHeader.biBitCount = 32;
1148 ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1149 ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with negative width\n" );
1150
1151 bi->bmiHeader.biWidth = 0;
1152 bi->bmiHeader.biHeight = 2;
1153 bi->bmiHeader.biBitCount = 32;
1155 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1156 ok( hdib == NULL, "CreateDIBSection succeeded with zero width\n" );
1157 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1158 ok( hdib != NULL, "CreateDIBitmap failed with zero width\n" );
1159 DeleteObject( hdib );
1160 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1161 ok( !ret || broken(ret), /* nt4 */ "SetDIBits succeeded with zero width\n" );
1162 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
1163 ok( !ret || broken(ret), /* nt4 */ "SetDIBitsToDevice succeeded with zero width\n" );
1164 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
1165 ok( !ret || broken(ret), /* nt4 */ "StretchDIBits succeeded with zero width\n" );
1166 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
1167 ok( !ret, "GetDIBits succeeded with zero width\n" );
1168 bi->bmiHeader.biWidth = 0;
1169 bi->bmiHeader.biHeight = 2;
1170 bi->bmiHeader.biBitCount = 32;
1172 ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1173 ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with zero width\n" );
1174
1175 bi->bmiHeader.biWidth = 2;
1176 bi->bmiHeader.biHeight = 0;
1177 bi->bmiHeader.biBitCount = 32;
1179 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1180 ok( hdib == NULL, "CreateDIBSection succeeded with zero height\n" );
1181 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_RGB_COLORS );
1182 ok( hdib != NULL, "CreateDIBitmap failed with zero height\n" );
1183 DeleteObject( hdib );
1184 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS);
1185 ok( !ret, "SetDIBits succeeded with zero height\n" );
1186 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_RGB_COLORS );
1187 ok( !ret, "SetDIBitsToDevice succeeded with zero height\n" );
1188 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_RGB_COLORS, SRCCOPY );
1189 ok( !ret, "StretchDIBits succeeded with zero height\n" );
1190 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_RGB_COLORS);
1191 ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with zero height\n" );
1192 bi->bmiHeader.biWidth = 2;
1193 bi->bmiHeader.biHeight = 0;
1194 bi->bmiHeader.biBitCount = 32;
1196 ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS);
1197 ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with zero height\n" );
1198
1199 /* some functions accept DIB_PAL_COLORS+1, but not beyond */
1200
1201 bi->bmiHeader.biWidth = 2;
1202 bi->bmiHeader.biHeight = 2;
1203 bi->bmiHeader.biBitCount = 1;
1205 hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+1, &bits, NULL, 0);
1206 ok( hdib == NULL, "CreateDIBSection succeeded with DIB_PAL_COLORS+1\n" );
1207 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_PAL_COLORS+1 );
1208 ok( hdib != NULL, "CreateDIBitmap failed with DIB_PAL_COLORS+1\n" );
1209 DeleteObject( hdib );
1210 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_PAL_COLORS+1);
1211 ok( !ret, "SetDIBits succeeded with DIB_PAL_COLORS+1\n" );
1212 ret = SetDIBits(hdc, hbmp_mono, 0, 1, data, bi, DIB_PAL_COLORS+1);
1213 ok( ret, "SetDIBits failed with DIB_PAL_COLORS+1\n" );
1214 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_PAL_COLORS+1 );
1215 ok( ret, "SetDIBitsToDevice failed with DIB_PAL_COLORS+1\n" );
1216 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_PAL_COLORS+1, SRCCOPY );
1217 ok( ret, "StretchDIBits failed with DIB_PAL_COLORS+1\n" );
1218 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_PAL_COLORS+1);
1219 ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+1\n" );
1220 bi->bmiHeader.biWidth = 2;
1221 bi->bmiHeader.biHeight = 2;
1222 bi->bmiHeader.biBitCount = 1;
1224 ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+1);
1225 ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+1\n" );
1226
1227 bi->bmiHeader.biWidth = 2;
1228 bi->bmiHeader.biHeight = 2;
1229 bi->bmiHeader.biBitCount = 1;
1231 hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+2, &bits, NULL, 0);
1232 ok( hdib == NULL, "CreateDIBSection succeeded with DIB_PAL_COLORS+2\n" );
1233 hdib = CreateDIBitmap( hdc, &bi->bmiHeader, 0, bits, bi, DIB_PAL_COLORS+2 );
1234 ok( hdib == NULL, "CreateDIBitmap succeeded with DIB_PAL_COLORS+2\n" );
1235 DeleteObject( hdib );
1236 ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_PAL_COLORS+2);
1237 ok( !ret, "SetDIBits succeeded with DIB_PAL_COLORS+2\n" );
1238 ret = SetDIBits(hdc, hbmp_mono, 0, 1, data, bi, DIB_PAL_COLORS+2);
1239 ok( !ret, "SetDIBits succeeded with DIB_PAL_COLORS+2\n" );
1240 ret = SetDIBitsToDevice( memdc, 0, 0, 1, 1, 0, 0, 0, 1, data, bi, DIB_PAL_COLORS+2 );
1241 ok( !ret, "SetDIBitsToDevice succeeded with DIB_PAL_COLORS+2\n" );
1242 ret = StretchDIBits( memdc, 0, 0, 1, 1, 0, 0, 1, 1, data, bi, DIB_PAL_COLORS+2, SRCCOPY );
1243 ok( !ret, "StretchDIBits succeeded with DIB_PAL_COLORS+2\n" );
1244 ret = GetDIBits(hdc, hbmp, 0, 2, data, bi, DIB_PAL_COLORS+2);
1245 ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+2\n" );
1246 bi->bmiHeader.biWidth = 2;
1247 bi->bmiHeader.biHeight = 2;
1248 bi->bmiHeader.biBitCount = 1;
1250 ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+2);
1251 ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+2\n" );
1252
1253 bi->bmiHeader.biWidth = 0x4000;
1254 bi->bmiHeader.biHeight = 0x4000;
1255 bi->bmiHeader.biBitCount = 1;
1257 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1258 ok( hdib != NULL, "CreateDIBSection failed with large size\n" );
1259 DeleteObject( hdib );
1260
1261 bi->bmiHeader.biWidth = 0x8001;
1262 bi->bmiHeader.biHeight = 0x8001;
1263 bi->bmiHeader.biBitCount = 32;
1265 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1266 ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
1267
1268 bi->bmiHeader.biWidth = 1;
1269 bi->bmiHeader.biHeight = 0x40000001;
1270 bi->bmiHeader.biBitCount = 32;
1272 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1273 ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
1274
1275 bi->bmiHeader.biWidth = 2;
1276 bi->bmiHeader.biHeight = 0x40000001;
1277 bi->bmiHeader.biBitCount = 16;
1279 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1280 ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
1281
1282 bi->bmiHeader.biWidth = 0x40000001;
1283 bi->bmiHeader.biHeight = 1;
1284 bi->bmiHeader.biBitCount = 32;
1286 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1287 ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
1288
1289 bi->bmiHeader.biWidth = 0x40000001;
1290 bi->bmiHeader.biHeight = 4;
1291 bi->bmiHeader.biBitCount = 8;
1293 hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
1294 ok( hdib == NULL, "CreateDIBSection succeeded with size overflow\n" );
1295
1296 DeleteDC( memdc );
1297 DeleteObject( hbmp );
1298 DeleteObject( hbmp_mono );
1299 ReleaseDC( 0, hdc );
1300 free( bi );
1301}
1302
1303static void test_mono_dibsection(void)
1304{
1305 HDC hdc, memdc;
1306 HBITMAP old_bm, mono_ds;
1307 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
1308 BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
1309 RGBQUAD *colors = pbmi->bmiColors;
1310 BYTE bits[10 * 4];
1311 BYTE *ds_bits;
1312 int num;
1313
1314 hdc = GetDC(0);
1315
1316 memdc = CreateCompatibleDC(hdc);
1317
1318 memset(pbmi, 0, sizeof(bmibuf));
1319 pbmi->bmiHeader.biSize = sizeof(pbmi->bmiHeader);
1320 pbmi->bmiHeader.biHeight = 10;
1321 pbmi->bmiHeader.biWidth = 10;
1323 pbmi->bmiHeader.biPlanes = 1;
1325 colors[0].rgbRed = 0xff;
1326 colors[0].rgbGreen = 0xff;
1327 colors[0].rgbBlue = 0xff;
1328 colors[1].rgbRed = 0x0;
1329 colors[1].rgbGreen = 0x0;
1330 colors[1].rgbBlue = 0x0;
1331
1332 /*
1333 * First dib section is 'inverted' ie color[0] is white, color[1] is black
1334 */
1335
1336 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1337 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1338 old_bm = SelectObject(memdc, mono_ds);
1339
1340 /* black border, white interior */
1341 Rectangle(memdc, 0, 0, 10, 10);
1342 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1343 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1344
1345 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
1346
1347 memset(bits, 0, sizeof(bits));
1348 bits[0] = 0xaa;
1349
1350 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1351 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1352
1353 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1354
1355 colors[0].rgbRed = 0x0;
1356 colors[0].rgbGreen = 0x0;
1357 colors[0].rgbBlue = 0x0;
1358 colors[1].rgbRed = 0xff;
1359 colors[1].rgbGreen = 0xff;
1360 colors[1].rgbBlue = 0xff;
1361
1362 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1363 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1364
1365 SelectObject(memdc, old_bm);
1366 DeleteObject(mono_ds);
1367
1368 /*
1369 * Next dib section is 'normal' ie color[0] is black, color[1] is white
1370 */
1371
1372 colors[0].rgbRed = 0x0;
1373 colors[0].rgbGreen = 0x0;
1374 colors[0].rgbBlue = 0x0;
1375 colors[1].rgbRed = 0xff;
1376 colors[1].rgbGreen = 0xff;
1377 colors[1].rgbBlue = 0xff;
1378
1379 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1380 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1381 old_bm = SelectObject(memdc, mono_ds);
1382
1383 /* black border, white interior */
1384 Rectangle(memdc, 0, 0, 10, 10);
1385 ok(ds_bits[0] == 0x00, "out_bits %02x\n", ds_bits[0]);
1386 ok(ds_bits[4] == 0x7f, "out_bits %02x\n", ds_bits[4]);
1387
1388 /* SetDIBitsToDevice with a normal bmi -> normal dib section */
1389
1390 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1391 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1392
1393 /* SetDIBitsToDevice with an inverted bmi -> normal dib section */
1394
1395 colors[0].rgbRed = 0xff;
1396 colors[0].rgbGreen = 0xff;
1397 colors[0].rgbBlue = 0xff;
1398 colors[1].rgbRed = 0x0;
1399 colors[1].rgbGreen = 0x0;
1400 colors[1].rgbBlue = 0x0;
1401
1402 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1403 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1404
1405 /*
1406 * Take that 'normal' dibsection and change its colour table to an 'inverted' one
1407 */
1408
1409 colors[0].rgbRed = 0xff;
1410 colors[0].rgbGreen = 0xff;
1411 colors[0].rgbBlue = 0xff;
1412 colors[1].rgbRed = 0x0;
1413 colors[1].rgbGreen = 0x0;
1414 colors[1].rgbBlue = 0x0;
1415 num = SetDIBColorTable(memdc, 0, 2, colors);
1416 ok(num == 2, "num = %d\n", num);
1417
1418 /* black border, white interior */
1419 Rectangle(memdc, 0, 0, 10, 10);
1420 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1421 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1422
1423 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
1424
1425 memset(bits, 0, sizeof(bits));
1426 bits[0] = 0xaa;
1427
1428 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1429 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1430
1431 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1432
1433 colors[0].rgbRed = 0x0;
1434 colors[0].rgbGreen = 0x0;
1435 colors[0].rgbBlue = 0x0;
1436 colors[1].rgbRed = 0xff;
1437 colors[1].rgbGreen = 0xff;
1438 colors[1].rgbBlue = 0xff;
1439
1440 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1441 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1442
1443 SelectObject(memdc, old_bm);
1444 DeleteObject(mono_ds);
1445
1446 /*
1447 * Now a dib section with a strange colour map just for fun. This behaves just like an inverted one.
1448 */
1449
1450 colors[0].rgbRed = 0xff;
1451 colors[0].rgbGreen = 0x0;
1452 colors[0].rgbBlue = 0x0;
1453 colors[1].rgbRed = 0xfe;
1454 colors[1].rgbGreen = 0x0;
1455 colors[1].rgbBlue = 0x0;
1456
1457 mono_ds = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (void**)&ds_bits, NULL, 0);
1458 ok(mono_ds != NULL, "CreateDIBSection rets NULL\n");
1459 old_bm = SelectObject(memdc, mono_ds);
1460
1461 /* black border, white interior */
1462 Rectangle(memdc, 0, 0, 10, 10);
1463 ok(ds_bits[0] == 0xff, "out_bits %02x\n", ds_bits[0]);
1464 ok(ds_bits[4] == 0x80, "out_bits %02x\n", ds_bits[4]);
1465
1466 /* SetDIBitsToDevice with a normal bmi -> inverted dib section */
1467
1468 colors[0].rgbRed = 0x0;
1469 colors[0].rgbGreen = 0x0;
1470 colors[0].rgbBlue = 0x0;
1471 colors[1].rgbRed = 0xff;
1472 colors[1].rgbGreen = 0xff;
1473 colors[1].rgbBlue = 0xff;
1474
1475 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1476 ok(ds_bits[0] == 0x55, "out_bits %02x\n", ds_bits[0]);
1477
1478 /* SetDIBitsToDevice with an inverted bmi -> inverted dib section */
1479
1480 colors[0].rgbRed = 0xff;
1481 colors[0].rgbGreen = 0xff;
1482 colors[0].rgbBlue = 0xff;
1483 colors[1].rgbRed = 0x0;
1484 colors[1].rgbGreen = 0x0;
1485 colors[1].rgbBlue = 0x0;
1486
1487 SetDIBitsToDevice(memdc, 0, 0, 10, 10, 0, 0, 0, 10, bits, pbmi, DIB_RGB_COLORS);
1488 ok(ds_bits[0] == 0xaa, "out_bits %02x\n", ds_bits[0]);
1489
1490 SelectObject(memdc, old_bm);
1491 DeleteObject(mono_ds);
1492
1493 DeleteDC(memdc);
1494 ReleaseDC(0, hdc);
1495}
1496
1497static void test_bitmap(void)
1498{
1499 char buf[256], buf_cmp[256];
1500 HBITMAP hbmp, hbmp_old;
1501 HDC hdc;
1502 BITMAP bm;
1503 BITMAP bma[2];
1504 INT ret;
1505
1507 assert(hdc != 0);
1508
1509 SetLastError(0xdeadbeef);
1510 hbmp = CreateBitmap(0x7ffffff, 1, 1, 1, NULL);
1511 if (!hbmp)
1512 {
1513 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1514 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1515 "expected ERROR_NOT_ENOUGH_MEMORY, got %lu\n", GetLastError());
1516 }
1517 else
1519
1520 SetLastError(0xdeadbeef);
1521 hbmp = CreateBitmap(0x7ffffff, 9, 1, 1, NULL);
1522 if (!hbmp)
1523 {
1524 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY /* XP */ ||
1525 GetLastError() == ERROR_INVALID_PARAMETER /* Win2k */,
1526 "expected ERROR_NOT_ENOUGH_MEMORY, got %lu\n", GetLastError());
1527 }
1528 else
1530
1531 SetLastError(0xdeadbeef);
1532 hbmp = CreateBitmap(0x7ffffff + 1, 1, 1, 1, NULL);
1533 ok(!hbmp, "CreateBitmap should fail\n");
1534 if (!hbmp)
1536 "expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
1537 else
1539
1540 hbmp = CreateBitmap(15, 15, 1, 1, NULL);
1541 assert(hbmp != NULL);
1542
1543 ret = GetObjectW(hbmp, sizeof(bm), &bm);
1544 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1545
1546 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1547 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1548 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1549 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1550 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1551 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1552 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1553
1554 assert(sizeof(buf) >= bm.bmWidthBytes * bm.bmHeight);
1555 assert(sizeof(buf) == sizeof(buf_cmp));
1556
1557 ret = GetBitmapBits(hbmp, 0, NULL);
1558 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1559
1560 memset(buf_cmp, 0xAA, sizeof(buf_cmp));
1561 memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
1562
1563 memset(buf, 0xAA, sizeof(buf));
1564 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1565 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1566 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1567
1568 hbmp_old = SelectObject(hdc, hbmp);
1569
1570 ret = GetObjectW(hbmp, sizeof(bm), &bm);
1571 ok(ret == sizeof(bm), "wrong size %d\n", ret);
1572
1573 ok(bm.bmType == 0, "wrong bm.bmType %d\n", bm.bmType);
1574 ok(bm.bmWidth == 15, "wrong bm.bmWidth %d\n", bm.bmWidth);
1575 ok(bm.bmHeight == 15, "wrong bm.bmHeight %d\n", bm.bmHeight);
1576 ok(bm.bmWidthBytes == 2, "wrong bm.bmWidthBytes %d\n", bm.bmWidthBytes);
1577 ok(bm.bmPlanes == 1, "wrong bm.bmPlanes %d\n", bm.bmPlanes);
1578 ok(bm.bmBitsPixel == 1, "wrong bm.bmBitsPixel %d\n", bm.bmBitsPixel);
1579 ok(bm.bmBits == NULL, "wrong bm.bmBits %p\n", bm.bmBits);
1580
1581 memset(buf, 0xAA, sizeof(buf));
1582 ret = GetBitmapBits(hbmp, sizeof(buf), buf);
1583 ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
1584 ok(!memcmp(buf, buf_cmp, sizeof(buf)), "buffers do not match\n");
1585
1586 hbmp_old = SelectObject(hdc, hbmp_old);
1587 ok(hbmp_old == hbmp, "wrong old bitmap %p\n", hbmp_old);
1588
1589 /* test various buffer sizes for GetObject */
1590 ret = GetObjectW(hbmp, sizeof(*bma) * 2, bma);
1591 ok(ret == sizeof(*bma), "wrong size %d\n", ret);
1592
1593 ret = GetObjectW(hbmp, sizeof(bm) / 2, &bm);
1594 ok(ret == 0, "%d != 0\n", ret);
1595
1596 ret = GetObjectW(hbmp, 0, &bm);
1597 ok(ret == 0, "%d != 0\n", ret);
1598
1599 ret = GetObjectW(hbmp, 1, &bm);
1600 ok(ret == 0, "%d != 0\n", ret);
1601
1603 DeleteDC(hdc);
1604}
1605
1606static COLORREF get_nearest( int r, int g, int b )
1607{
1608 return (r*r + g*g + b*b < (255-r)*(255-r) + (255-g)*(255-g) + (255-b)*(255-b)) ? 0x000000 : 0xffffff;
1609}
1610
1611static BOOL is_black_pen( COLORREF fg, COLORREF bg, int r, int g, int b )
1612{
1613 if (fg == 0 || bg == 0xffffff) return RGB(r,g,b) != 0xffffff && RGB(r,g,b) != bg;
1614 return RGB(r,g,b) == 0x000000 || RGB(r,g,b) == bg;
1615}
1616
1617static void test_bitmap_colors( HDC hdc, COLORREF fg, COLORREF bg, int r, int g, int b )
1618{
1619 static const WORD pattern_bits[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
1620 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors ) + 256 * sizeof(RGBQUAD)];
1622 RGBQUAD *colors = info->bmiColors;
1623 WORD bits[16];
1624 void *bits_ptr;
1625 COLORREF res;
1626 HBRUSH old_brush;
1627 HPEN old_pen;
1629 HDC memdc;
1630
1631 res = SetPixel( hdc, 0, 0, RGB(r,g,b) );
1632 ok( res == get_nearest( r, g, b ),
1633 "wrong result %06lx for %02x,%02x,%02x fg %06lx bg %06lx\n", res, r, g, b, fg, bg );
1634 res = GetPixel( hdc, 0, 0 );
1635 ok( res == get_nearest( r, g, b ),
1636 "wrong result %06lx for %02x,%02x,%02x fg %06lx bg %06lx\n", res, r, g, b, fg, bg );
1637 res = GetNearestColor( hdc, RGB(r,g,b) );
1638 ok( res == get_nearest( r, g, b ),
1639 "wrong result %06lx for %02x,%02x,%02x fg %06lx bg %06lx\n", res, r, g, b, fg, bg );
1640
1641 /* solid pen */
1642 old_pen = SelectObject( hdc, CreatePen( PS_SOLID, 1, RGB(r,g,b) ));
1643 MoveToEx( hdc, 0, 0, NULL );
1644 LineTo( hdc, 16, 0 );
1645 res = GetPixel( hdc, 0, 0 );
1646 ok( res == (is_black_pen( fg, bg, r, g, b ) ? 0 : 0xffffff),
1647 "wrong result %06lx for %02x,%02x,%02x fg %06lx bg %06lx\n", res, r, g, b, fg, bg );
1649 ok( bits[0] == (is_black_pen( fg, bg, r, g, b ) ? 0x00 : 0xffff),
1650 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1651 DeleteObject( SelectObject( hdc, old_pen ));
1652
1653 /* mono DDB pattern brush */
1654 bitmap = CreateBitmap( 16, 8, 1, 1, pattern_bits );
1655 old_brush = SelectObject( hdc, CreatePatternBrush( bitmap ));
1656 PatBlt( hdc, 0, 0, 16, 16, PATCOPY );
1658 ok( bits[0] == 0x5555 || broken(bits[0] == 0xaada) /* XP SP1 & 2003 SP0 */,
1659 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1660 DeleteObject( SelectObject( hdc, old_brush ));
1661
1662 /* mono DDB bitmap */
1663 memdc = CreateCompatibleDC( hdc );
1664 SelectObject( memdc, bitmap );
1665 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1667 ok( bits[0] == 0x5555,
1668 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1669 SetTextColor( memdc, RGB(255,255,255) );
1670 SetBkColor( memdc, RGB(0,0,0) );
1671 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1673 ok( bits[0] == 0x5555,
1674 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1675
1676 /* mono DIB section */
1677 memset( buffer, 0, sizeof(buffer) );
1678 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1679 info->bmiHeader.biHeight = -16;
1680 info->bmiHeader.biWidth = 16;
1681 info->bmiHeader.biBitCount = 1;
1682 info->bmiHeader.biPlanes = 1;
1683 info->bmiHeader.biCompression = BI_RGB;
1684 colors[0].rgbRed = 0xff;
1685 colors[0].rgbGreen = 0xff;
1686 colors[0].rgbBlue = 0xf0;
1687 colors[1].rgbRed = 0x20;
1688 colors[1].rgbGreen = 0x0;
1689 colors[1].rgbBlue = 0x0;
1690 bitmap = CreateDIBSection( 0, info, DIB_RGB_COLORS, &bits_ptr, NULL, 0 );
1691 memset( bits_ptr, 0x55, 64 );
1692 DeleteObject( SelectObject( memdc, bitmap ));
1693 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1695 ok( bits[0] == 0x5555,
1696 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1697
1698 colors[0].rgbRed = 0x0;
1699 colors[0].rgbGreen = 0x0;
1700 colors[0].rgbBlue = 0x10;
1701 colors[1].rgbRed = 0xff;
1702 colors[1].rgbGreen = 0xf0;
1703 colors[1].rgbBlue = 0xff;
1704 bitmap = CreateDIBSection( 0, info, DIB_RGB_COLORS, &bits_ptr, NULL, 0 );
1705 memset( bits_ptr, 0x55, 64 );
1706 DeleteObject( SelectObject( memdc, bitmap ));
1707 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1709 ok( bits[0] == 0xaaaa,
1710 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1711
1712 SetTextColor( memdc, RGB(0,20,0) );
1713 SetBkColor( memdc, RGB(240,240,240) );
1714 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1716 ok( bits[0] == 0x5555,
1717 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1718
1719 SetTextColor( memdc, RGB(250,250,250) );
1720 SetBkColor( memdc, RGB(10,10,10) );
1721 BitBlt( hdc, 0, 0, 16, 8, memdc, 0, 0, SRCCOPY );
1723 ok( bits[0] == 0xaaaa,
1724 "wrong bits %04x for %02x,%02x,%02x fg %06lx bg %06lx\n", bits[0], r, g, b, fg, bg );
1725 DeleteDC( memdc );
1727}
1728
1729static void test_mono_bitmap(void)
1730{
1731 static const COLORREF colors[][2] =
1732 {
1733 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff) },
1734 { RGB(0xff,0xff,0xff), RGB(0x00,0x00,0x00) },
1735 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xfe) },
1736 { RGB(0x00,0x01,0x00), RGB(0xff,0xff,0xff) },
1737 { RGB(0x00,0x00,0x00), RGB(0x80,0x80,0x80) },
1738 { RGB(0x80,0x80,0x80), RGB(0xff,0xff,0xff) },
1739 { RGB(0x30,0x40,0x50), RGB(0x60,0x70,0x80) },
1740 { RGB(0xa0,0xa0,0xa0), RGB(0x20,0x30,0x10) },
1741 { PALETTEINDEX(0), PALETTEINDEX(255) },
1742 { PALETTEINDEX(1), PALETTEINDEX(2) },
1743 };
1744
1745 HBITMAP hbmp;
1746 HDC hdc;
1747 DWORD col;
1748 int i, r, g, b;
1749
1751 {
1752 skip("ROSTESTS-153: Skipping test_mono_bitmap because it causes too many failures and takes too long\n");
1753 return;
1754 }
1755
1757 assert(hdc != 0);
1758
1759 hbmp = CreateBitmap(16, 16, 1, 1, NULL);
1760 assert(hbmp != NULL);
1761
1762 SelectObject( hdc, hbmp );
1763
1764 for (col = 0; col < ARRAY_SIZE(colors); col++)
1765 {
1766 SetTextColor( hdc, colors[col][0] );
1767 SetBkColor( hdc, colors[col][1] );
1768
1769 for (i = 0; i < 256; i++)
1770 {
1771 HPALETTE pal = GetCurrentObject( hdc, OBJ_PAL );
1772 PALETTEENTRY ent;
1773
1774 if (!GetPaletteEntries( pal, i, 1, &ent )) GetPaletteEntries( pal, 0, 1, &ent );
1776 test_color( hdc, DIBINDEX(i), (i == 1) ? 0xffffff : 0x000000 );
1777 }
1778
1779 for (r = 0; r < 256; r += 15)
1780 for (g = 0; g < 256; g += 15)
1781 for (b = 0; b < 256; b += 15)
1782 test_bitmap_colors( hdc, colors[col][0], colors[col][1], r, g, b );
1783 }
1784
1785 DeleteDC(hdc);
1787}
1788
1789static void test_bmBits(void)
1790{
1791 BYTE bits[4];
1792 HBITMAP hbmp;
1793 BITMAP bmp;
1794
1795 memset(bits, 0, sizeof(bits));
1796 hbmp = CreateBitmap(2, 2, 1, 4, bits);
1797 ok(hbmp != NULL, "CreateBitmap failed\n");
1798
1799 memset(&bmp, 0xFF, sizeof(bmp));
1800 ok(GetObjectW(hbmp, sizeof(bmp), &bmp) == sizeof(bmp),
1801 "GetObject failed or returned a wrong structure size\n");
1802 ok(!bmp.bmBits, "bmBits must be NULL for device-dependent bitmaps\n");
1803
1805}
1806
1808{
1809 HBITMAP dib;
1811 BITMAPINFO *info2;
1812 void * bits;
1813 void * bits2;
1814 UINT dib_size, dib32_size;
1815 DWORD pixel;
1816 HDC dib_dc, dc;
1817 HBITMAP old_bmp;
1818 UINT i;
1819 int res;
1820
1821 info = malloc(FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
1822 info2 = malloc(FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
1823
1824 /* Create a DIB section with a color table */
1825
1826 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1827 info->bmiHeader.biWidth = 32;
1828 info->bmiHeader.biHeight = 32;
1829 info->bmiHeader.biPlanes = 1;
1830 info->bmiHeader.biBitCount = bpp;
1831 info->bmiHeader.biCompression = BI_RGB;
1832 info->bmiHeader.biXPelsPerMeter = 0;
1833 info->bmiHeader.biYPelsPerMeter = 0;
1834 info->bmiHeader.biClrUsed = 0;
1835 info->bmiHeader.biClrImportant = 0;
1836
1837 for (i=0; i < (1u << bpp); i++)
1838 {
1839 BYTE c = i * (1 << (8 - bpp));
1840 info->bmiColors[i].rgbRed = c;
1841 info->bmiColors[i].rgbGreen = c;
1842 info->bmiColors[i].rgbBlue = c;
1843 info->bmiColors[i].rgbReserved = 0;
1844 }
1845
1847 dib_size = bpp * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1848 dib32_size = 32 * (info->bmiHeader.biWidth * info->bmiHeader.biHeight) / 8;
1849
1850 /* Set the bits of the DIB section */
1851 for (i=0; i < dib_size; i++)
1852 {
1853 ((BYTE *)bits)[i] = i % 256;
1854 }
1855
1856 /* Select the DIB into a DC */
1857 dib_dc = CreateCompatibleDC(NULL);
1858 old_bmp = SelectObject(dib_dc, dib);
1860 bits2 = calloc(1, dib32_size);
1861
1862 /* Copy the DIB attributes but not the color table */
1863 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1864
1865 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1866 ok( res == info->bmiHeader.biHeight, "got %d (bpp %d)\n", res, bpp );
1867
1868 /* Compare the color table and the bits */
1869 for (i=0; i < (1u << bpp); i++)
1870 ok( info->bmiColors[i].rgbRed == info2->bmiColors[i].rgbRed &&
1871 info->bmiColors[i].rgbGreen == info2->bmiColors[i].rgbGreen &&
1872 info->bmiColors[i].rgbBlue == info2->bmiColors[i].rgbBlue &&
1873 info->bmiColors[i].rgbReserved == info2->bmiColors[i].rgbReserved,
1874 "color table entry %d differs (bpp %d)\n", i, bpp );
1875
1876 ok( !memcmp( bits, bits2, dib_size ), "bit mismatch (bpp %d)\n", bpp );
1877
1878 /* Test various combinations of lines = 0 and bits2 = NULL */
1879 memset( info2->bmiColors, 0xcc, 256 * sizeof(RGBQUAD) );
1880 res = GetDIBits( dc, dib, 0, 0, bits2, info2, DIB_RGB_COLORS );
1881 ok( res == 1, "got %d (bpp %d)\n", res, bpp );
1882 ok( !memcmp( info->bmiColors, info2->bmiColors, (1 << bpp) * sizeof(RGBQUAD) ),
1883 "color table mismatch (bpp %d)\n", bpp );
1884
1885 memset( info2->bmiColors, 0xcc, 256 * sizeof(RGBQUAD) );
1886 res = GetDIBits( dc, dib, 0, 0, NULL, info2, DIB_RGB_COLORS );
1887 ok( res == 1, "got %d (bpp %d)\n", res, bpp );
1888 ok( !memcmp( info->bmiColors, info2->bmiColors, (1 << bpp) * sizeof(RGBQUAD) ),
1889 "color table mismatch (bpp %d)\n", bpp );
1890
1891 memset( info2->bmiColors, 0xcc, 256 * sizeof(RGBQUAD) );
1892 res = GetDIBits( dc, dib, 0, info->bmiHeader.biHeight, NULL, info2, DIB_RGB_COLORS );
1893 ok( res == 1, "got %d (bpp %d)\n", res, bpp );
1894 ok( !memcmp( info->bmiColors, info2->bmiColors, (1 << bpp) * sizeof(RGBQUAD) ),
1895 "color table mismatch (bpp %d)\n", bpp );
1896
1897 /* Map into a 32bit-DIB */
1898 info2->bmiHeader.biBitCount = 32;
1899 res = GetDIBits(dc, dib, 0, info->bmiHeader.biHeight, bits2, info2, DIB_RGB_COLORS);
1900 ok( res == info->bmiHeader.biHeight, "got %d (bpp %d)\n", res, bpp );
1901
1902 /* Check if last pixel was set */
1903 pixel = ((DWORD *)bits2)[info->bmiHeader.biWidth * info->bmiHeader.biHeight - 1];
1904 ok(pixel != 0, "Pixel: 0x%08lx\n", pixel);
1905
1906 free(bits2);
1907 DeleteDC(dc);
1908
1909 SelectObject(dib_dc, old_bmp);
1910 DeleteDC(dib_dc);
1911 DeleteObject(dib);
1912 free(info2);
1913 free(info);
1914}
1915
1916static void test_GetDIBits_selected_DDB(BOOL monochrome)
1917{
1918 HBITMAP ddb;
1920 BITMAPINFO *info2;
1921 void * bits;
1922 void * bits2;
1923 HDC ddb_dc, dc;
1924 HBITMAP old_bmp;
1925 UINT width, height;
1926 UINT bpp;
1927 UINT i, j;
1928 int res;
1929
1930 info = malloc(FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
1931 info2 = malloc(FIELD_OFFSET(BITMAPINFO, bmiColors[256]));
1932
1933 width = height = 16;
1934
1935 /* Create a DDB (device-dependent bitmap) */
1936 if (monochrome)
1937 {
1938 bpp = 1;
1939 ddb = CreateBitmap(width, height, 1, 1, NULL);
1940 }
1941 else
1942 {
1943 HDC screen_dc = GetDC(NULL);
1944 bpp = GetDeviceCaps(screen_dc, BITSPIXEL) * GetDeviceCaps(screen_dc, PLANES);
1945 ddb = CreateCompatibleBitmap(screen_dc, width, height);
1946 ReleaseDC(NULL, screen_dc);
1947 }
1948
1949 /* Set the pixels */
1950 ddb_dc = CreateCompatibleDC(NULL);
1951 old_bmp = SelectObject(ddb_dc, ddb);
1952 for (i = 0; i < width; i++)
1953 {
1954 for (j=0; j < height; j++)
1955 {
1956 BYTE c = (i * width + j) % 256;
1957 SetPixelV(ddb_dc, i, j, RGB(c, c, c));
1958 }
1959 }
1960 SelectObject(ddb_dc, old_bmp);
1961
1962 info->bmiHeader.biSize = sizeof(info->bmiHeader);
1963 info->bmiHeader.biWidth = width;
1964 info->bmiHeader.biHeight = height;
1965 info->bmiHeader.biPlanes = 1;
1966 info->bmiHeader.biBitCount = bpp;
1967 info->bmiHeader.biCompression = BI_RGB;
1968
1970
1971 /* Fill in biSizeImage */
1973 ok(info->bmiHeader.biSizeImage != 0, "GetDIBits failed to get the DIB attributes\n");
1974
1975 bits = calloc(1, info->bmiHeader.biSizeImage);
1976 bits2 = calloc(1, info->bmiHeader.biSizeImage);
1977
1978 /* Get the bits */
1979 res = GetDIBits(dc, ddb, 0, height, bits, info, DIB_RGB_COLORS);
1980 ok( res == height, "got %d (bpp %d)\n", res, bpp );
1981
1982 /* Copy the DIB attributes but not the color table */
1983 memcpy(info2, info, sizeof(BITMAPINFOHEADER));
1984
1985 /* Select the DDB into another DC */
1986 old_bmp = SelectObject(ddb_dc, ddb);
1987
1988 /* Get the bits */
1989 res = GetDIBits(dc, ddb, 0, height, bits2, info2, DIB_RGB_COLORS);
1990 ok( res == height, "got %d (bpp %d)\n", res, bpp );
1991
1992 /* Compare the color table and the bits */
1993 if (bpp <= 8)
1994 {
1995 for (i=0; i < (1u << bpp); i++)
1996 ok( info->bmiColors[i].rgbRed == info2->bmiColors[i].rgbRed &&
1997 info->bmiColors[i].rgbGreen == info2->bmiColors[i].rgbGreen &&
1998 info->bmiColors[i].rgbBlue == info2->bmiColors[i].rgbBlue &&
1999 info->bmiColors[i].rgbReserved == info2->bmiColors[i].rgbReserved,
2000 "color table entry %d differs (bpp %d)\n", i, bpp );
2001 }
2002
2003 ok( !memcmp( bits, bits2, info->bmiHeader.biSizeImage ), "bit mismatch (bpp %d)\n", bpp );
2004
2005 /* Test the palette */
2006 if (info2->bmiHeader.biBitCount <= 8)
2007 {
2008 WORD *colors = (WORD*)info2->bmiColors;
2009
2010 /* Get the palette indices */
2011 res = GetDIBits(dc, ddb, 0, 0, NULL, info2, DIB_PAL_COLORS);
2012 ok( res == 1, "got %d (bpp %d)\n", res, bpp );
2013
2014 for (i = 0; i < (1 << info->bmiHeader.biBitCount); i++)
2015 ok( colors[i] == i, "%d: got %d (bpp %d)\n", i, colors[i], bpp );
2016 }
2017
2018 free(bits2);
2019 free(bits);
2020 DeleteDC(dc);
2021
2022 SelectObject(ddb_dc, old_bmp);
2023 DeleteDC(ddb_dc);
2024 DeleteObject(ddb);
2025 free(info2);
2026 free(info);
2027}
2028
2029static void test_GetDIBits(void)
2030{
2031 /* 2-bytes aligned 1-bit bitmap data: 16x16 */
2032 static const BYTE bmp_bits_1[16 * 2] =
2033 {
2034 0xff,0xff, 0,0, 0xff,0xff, 0,0,
2035 0xff,0xff, 0,0, 0xff,0xff, 0,0,
2036 0xff,0xff, 0,0, 0xff,0xff, 0,0,
2037 0xff,0xff, 0,0, 0xff,0xff, 0,0
2038 };
2039 /* 4-bytes aligned 1-bit DIB data: 16x16 */
2040 static const BYTE dib_bits_1[16 * 4] =
2041 {
2042 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
2043 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
2044 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0,
2045 0,0,0,0, 0xff,0xff,0,0, 0,0,0,0, 0xff,0xff,0,0
2046 };
2047 /* 2-bytes aligned 24-bit bitmap data: 16x16 */
2048 static const BYTE bmp_bits_24[16 * 16*3] =
2049 {
2050 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2051 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2052 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2053 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2054 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2055 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2056 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2057 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2058 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2059 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2060 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2061 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2062 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2063 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2064 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2065 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2066 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2067 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2068 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2069 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2070 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2071 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2072 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2073 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2074 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2075 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2076 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2077 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2078 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2079 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2080 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2081 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2082 };
2083 /* 4-bytes aligned 24-bit DIB data: 16x16 */
2084 static const BYTE dib_bits_24[16 * 16*3] =
2085 {
2086 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2087 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2088 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2089 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2090 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2091 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2092 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2093 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2094 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2095 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2096 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2097 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2098 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2099 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2100 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2101 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2102 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2103 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2104 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2105 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2106 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2107 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2108 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2109 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2110 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2111 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2112 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2113 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2114 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2115 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
2116 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
2117 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
2118 };
2119 HBITMAP hbmp;
2120 BITMAP bm;
2121 HDC hdc;
2122 int i, bytes, lines;
2123 BYTE buf[1024];
2124 char bi_buf[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
2125 BITMAPINFO *bi = (BITMAPINFO *)bi_buf;
2126 RGBQUAD *colors = bi->bmiColors;
2127 PALETTEENTRY pal_ents[20];
2128
2129 hdc = GetDC(0);
2130
2131 /* 1-bit source bitmap data */
2132 hbmp = CreateBitmap(16, 16, 1, 1, bmp_bits_1);
2133 ok(hbmp != 0, "CreateBitmap failed\n");
2134
2135 memset(&bm, 0xAA, sizeof(bm));
2136 bytes = GetObjectW(hbmp, sizeof(bm), &bm);
2137 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2138 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2139 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
2140 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
2141 ok(bm.bmWidthBytes == 2, "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2142 ok(bm.bmPlanes == 1, "wrong bmPlanes %u\n", bm.bmPlanes);
2143 ok(bm.bmBitsPixel == 1, "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2144 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2145
2147 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
2148 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
2149 ok(bytes == sizeof(bmp_bits_1), "expected 16*2 got %d bytes\n", bytes);
2150 ok(!memcmp(buf, bmp_bits_1, sizeof(bmp_bits_1)), "bitmap bits don't match\n");
2151
2152 /* retrieve 1-bit DIB data */
2153 memset(bi, 0, sizeof(*bi));
2154 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2155 bi->bmiHeader.biWidth = bm.bmWidth;
2156 bi->bmiHeader.biHeight = bm.bmHeight;
2157 bi->bmiHeader.biPlanes = 1;
2158 bi->bmiHeader.biBitCount = 1;
2160 bi->bmiHeader.biClrUsed = 37;
2161 bi->bmiHeader.biSizeImage = 0;
2162 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2163 SetLastError(0xdeadbeef);
2164 lines = GetDIBits(0, hbmp, 0, bm.bmHeight, buf, bi, DIB_RGB_COLORS);
2165 ok(lines == 0, "GetDIBits copied %d lines with hdc = 0\n", lines);
2167 broken(GetLastError() == 0xdeadbeef), /* winnt */
2168 "wrong error %lu\n", GetLastError());
2169 ok(bi->bmiHeader.biSizeImage == 0, "expected 0, got %lu\n", bi->bmiHeader.biSizeImage);
2170 ok(bi->bmiHeader.biClrUsed == 37 || broken(bi->bmiHeader.biClrUsed == 0),
2171 "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2172
2173 memset(buf, 0xAA, sizeof(buf));
2174 SetLastError(0xdeadbeef);
2176 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2177 lines, bm.bmHeight, GetLastError());
2178 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %lu\n", bi->bmiHeader.biSizeImage);
2179 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2180
2181 /* the color table consists of black and white */
2182 ok(colors[0].rgbRed == 0 && colors[0].rgbGreen == 0 &&
2183 colors[0].rgbBlue == 0 && colors[0].rgbReserved == 0,
2184 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
2185 colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue, colors[0].rgbReserved);
2186 ok(colors[1].rgbRed == 0xff && colors[1].rgbGreen == 0xff &&
2187 colors[1].rgbBlue == 0xff && colors[1].rgbReserved == 0,
2188 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
2189 colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue, colors[1].rgbReserved);
2190 for (i = 2; i < 256; i++)
2191 {
2192 ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
2193 colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
2194 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
2195 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2196 }
2197
2198 /* returned bits are DWORD aligned and upside down */
2199 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
2200
2201 /* Test the palette indices */
2202 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2203 SetLastError(0xdeadbeef);
2204 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
2205 ok(((WORD*)colors)[0] == 0, "Color 0 is %d\n", ((WORD*)colors)[0]);
2206 ok(((WORD*)colors)[1] == 1, "Color 1 is %d\n", ((WORD*)colors)[1]);
2207 for (i = 2; i < 256; i++)
2208 ok(((WORD*)colors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)colors)[1]);
2209
2210 /* retrieve 24-bit DIB data */
2211 memset(bi, 0, sizeof(*bi));
2212 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2213 bi->bmiHeader.biWidth = bm.bmWidth;
2214 bi->bmiHeader.biHeight = bm.bmHeight;
2215 bi->bmiHeader.biPlanes = 1;
2216 bi->bmiHeader.biBitCount = 24;
2218 bi->bmiHeader.biClrUsed = 37;
2219 bi->bmiHeader.biSizeImage = 0;
2220 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2221 memset(buf, 0xAA, sizeof(buf));
2222 SetLastError(0xdeadbeef);
2224 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2225 lines, bm.bmHeight, GetLastError());
2226 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %lu\n", bi->bmiHeader.biSizeImage);
2227 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2228
2229 /* the color table doesn't exist for 24-bit images */
2230 for (i = 0; i < 256; i++)
2231 {
2232 ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
2233 colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
2234 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
2235 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2236 }
2237
2238 /* returned bits are DWORD aligned and upside down */
2239 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
2241
2242 /* 24-bit source bitmap data */
2243 hbmp = CreateCompatibleBitmap(hdc, 16, 16);
2244 ok(hbmp != 0, "CreateBitmap failed\n");
2245 SetLastError(0xdeadbeef);
2246 bi->bmiHeader.biHeight = -bm.bmHeight; /* indicate bottom-up data */
2247 lines = SetDIBits(hdc, hbmp, 0, bm.bmHeight, bmp_bits_24, bi, DIB_RGB_COLORS);
2248 ok(lines == bm.bmHeight, "SetDIBits copied %d lines of %d, error %lu\n",
2249 lines, bm.bmHeight, GetLastError());
2250
2251 memset(&bm, 0xAA, sizeof(bm));
2252 bytes = GetObjectW(hbmp, sizeof(bm), &bm);
2253 ok(bytes == sizeof(bm), "GetObject returned %d\n", bytes);
2254 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2255 ok(bm.bmWidth == 16, "wrong bmWidth %d\n", bm.bmWidth);
2256 ok(bm.bmHeight == 16, "wrong bmHeight %d\n", bm.bmHeight);
2257 ok(bm.bmWidthBytes == get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2258 ok(bm.bmPlanes == GetDeviceCaps(hdc, PLANES), "wrong bmPlanes %u\n", bm.bmPlanes);
2259 ok(bm.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2260 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2261
2263 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n", bm.bmWidthBytes * bm.bmHeight, bytes);
2264 bytes = GetBitmapBits(hbmp, sizeof(buf), buf);
2265 ok(bytes == bm.bmWidthBytes * bm.bmHeight, "expected %d got %d bytes\n",
2266 bm.bmWidthBytes * bm.bmHeight, bytes);
2267
2268 /* retrieve 1-bit DIB data */
2269 memset(bi, 0, sizeof(*bi));
2270 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2271 bi->bmiHeader.biWidth = bm.bmWidth;
2272 bi->bmiHeader.biHeight = bm.bmHeight;
2273 bi->bmiHeader.biPlanes = 1;
2274 bi->bmiHeader.biBitCount = 1;
2276 bi->bmiHeader.biClrUsed = 37;
2277 bi->bmiHeader.biSizeImage = 0;
2278 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2279 memset(buf, 0xAA, sizeof(buf));
2280 SetLastError(0xdeadbeef);
2282 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2283 lines, bm.bmHeight, GetLastError());
2284 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_1), "expected 16*4, got %lu\n", bi->bmiHeader.biSizeImage);
2285 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2286
2287 /* the color table consists of black and white */
2288 ok(colors[0].rgbRed == 0 && colors[0].rgbGreen == 0 &&
2289 colors[0].rgbBlue == 0 && colors[0].rgbReserved == 0,
2290 "expected bmiColors[0] 0,0,0,0 - got %x %x %x %x\n",
2291 colors[0].rgbRed, colors[0].rgbGreen, colors[0].rgbBlue, colors[0].rgbReserved);
2292 ok(colors[1].rgbRed == 0xff && colors[1].rgbGreen == 0xff &&
2293 colors[1].rgbBlue == 0xff && colors[1].rgbReserved == 0,
2294 "expected bmiColors[0] 0xff,0xff,0xff,0 - got %x %x %x %x\n",
2295 colors[1].rgbRed, colors[1].rgbGreen, colors[1].rgbBlue, colors[1].rgbReserved);
2296 for (i = 2; i < 256; i++)
2297 {
2298 ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
2299 colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
2300 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
2301 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2302 }
2303
2304 /* returned bits are DWORD aligned and upside down */
2305 ok(!memcmp(buf, dib_bits_1, sizeof(dib_bits_1)), "DIB bits don't match\n");
2306
2307 /* Test the palette indices */
2308 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2309 SetLastError(0xdeadbeef);
2310 lines = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS);
2311 ok(((WORD*)colors)[0] == 0, "Color 0 is %d\n", ((WORD*)colors)[0]);
2312 ok(((WORD*)colors)[1] == 1, "Color 1 is %d\n", ((WORD*)colors)[1]);
2313 for (i = 2; i < 256; i++)
2314 ok(((WORD*)colors)[i] == 0xAAAA, "Color %d is %d\n", i, ((WORD*)colors)[i]);
2315
2316 /* retrieve 4-bit DIB data */
2317 memset(bi, 0, sizeof(*bi));
2318 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2319 bi->bmiHeader.biWidth = bm.bmWidth;
2320 bi->bmiHeader.biHeight = bm.bmHeight;
2321 bi->bmiHeader.biPlanes = 1;
2322 bi->bmiHeader.biBitCount = 4;
2324 bi->bmiHeader.biClrUsed = 37;
2325 bi->bmiHeader.biSizeImage = 0;
2326 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2327 memset(buf, 0xAA, sizeof(buf));
2328 SetLastError(0xdeadbeef);
2330 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2331 lines, bm.bmHeight, GetLastError());
2332 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2333
2335
2336 for (i = 0; i < 16; i++)
2337 {
2339 int entry = i < 8 ? i : i + 4;
2340
2341 if(entry == 7) entry = 12;
2342 else if(entry == 12) entry = 7;
2343
2344 expect.rgbRed = pal_ents[entry].peRed;
2345 expect.rgbGreen = pal_ents[entry].peGreen;
2346 expect.rgbBlue = pal_ents[entry].peBlue;
2347 expect.rgbReserved = 0;
2348
2349 ok(!memcmp(colors + i, &expect, sizeof(expect)),
2350 "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
2351 expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
2352 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2353 }
2354
2355 /* retrieve 8-bit DIB data */
2356 memset(bi, 0, sizeof(*bi));
2357 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2358 bi->bmiHeader.biWidth = bm.bmWidth;
2359 bi->bmiHeader.biHeight = bm.bmHeight;
2360 bi->bmiHeader.biPlanes = 1;
2361 bi->bmiHeader.biBitCount = 8;
2363 bi->bmiHeader.biClrUsed = 37;
2364 bi->bmiHeader.biSizeImage = 0;
2365 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2366 memset(buf, 0xAA, sizeof(buf));
2367 SetLastError(0xdeadbeef);
2369 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2370 lines, bm.bmHeight, GetLastError());
2371 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2372
2374
2375 for (i = 0; i < 256; i++)
2376 {
2378
2379 if (i < 10 || i >= 246)
2380 {
2381 int entry = i < 10 ? i : i - 236;
2382 expect.rgbRed = pal_ents[entry].peRed;
2383 expect.rgbGreen = pal_ents[entry].peGreen;
2384 expect.rgbBlue = pal_ents[entry].peBlue;
2385 }
2386 else
2387 {
2388 expect.rgbRed = (i & 0x07) << 5;
2389 expect.rgbGreen = (i & 0x38) << 2;
2390 expect.rgbBlue = i & 0xc0;
2391 }
2392 expect.rgbReserved = 0;
2393
2394 ok(!memcmp(colors + i, &expect, sizeof(expect)),
2395 "expected bmiColors[%d] %x %x %x %x - got %x %x %x %x\n", i,
2396 expect.rgbRed, expect.rgbGreen, expect.rgbBlue, expect.rgbReserved,
2397 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2398 }
2399
2400 /* retrieve 24-bit DIB data */
2401 memset(bi, 0, sizeof(*bi));
2402 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2403 bi->bmiHeader.biWidth = bm.bmWidth;
2404 bi->bmiHeader.biHeight = bm.bmHeight;
2405 bi->bmiHeader.biPlanes = 1;
2406 bi->bmiHeader.biBitCount = 24;
2408 bi->bmiHeader.biClrUsed = 37;
2409 bi->bmiHeader.biSizeImage = 0;
2410 memset(colors, 0xAA, sizeof(RGBQUAD) * 256);
2411 memset(buf, 0xAA, sizeof(buf));
2412 SetLastError(0xdeadbeef);
2414 ok(lines == bm.bmHeight, "GetDIBits copied %d lines of %d, error %lu\n",
2415 lines, bm.bmHeight, GetLastError());
2416 ok(bi->bmiHeader.biSizeImage == sizeof(dib_bits_24), "expected 16*16*3, got %lu\n", bi->bmiHeader.biSizeImage);
2417 ok(bi->bmiHeader.biClrUsed == 0, "wrong biClrUsed %lu\n", bi->bmiHeader.biClrUsed);
2418
2419 /* the color table doesn't exist for 24-bit images */
2420 for (i = 0; i < 256; i++)
2421 {
2422 ok(colors[i].rgbRed == 0xAA && colors[i].rgbGreen == 0xAA &&
2423 colors[i].rgbBlue == 0xAA && colors[i].rgbReserved == 0xAA,
2424 "expected bmiColors[%d] 0xAA,0xAA,0xAA,0xAA - got %x %x %x %x\n", i,
2425 colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue, colors[i].rgbReserved);
2426 }
2427
2428 /* returned bits are DWORD aligned and upside down */
2429 ok(!memcmp(buf, dib_bits_24, sizeof(dib_bits_24)), "DIB bits don't match\n");
2431
2432 ReleaseDC(0, hdc);
2433}
2434
2436{
2437 /* Try a screen resolution detection technique
2438 * from the September 1999 issue of Windows Developer's Journal
2439 * which seems to be in widespread use.
2440 * http://www.lesher.ws/highcolor.html
2441 * http://www.lesher.ws/vidfmt.c
2442 * It hinges on being able to retrieve the bitmaps
2443 * for the three primary colors in non-paletted 16 bit mode.
2444 */
2445 char dibinfo_buf[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
2446 DWORD bits[32];
2447 LPBITMAPINFO dibinfo = (LPBITMAPINFO) dibinfo_buf;
2448 DWORD *bitmasks = (DWORD *)dibinfo->bmiColors;
2449 HDC hdc;
2450 HBITMAP hbm;
2451 int ret;
2452 void *ptr;
2453
2454 memset(dibinfo, 0, sizeof(dibinfo_buf));
2455 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2456
2457 hdc = GetDC(NULL);
2458 ok(hdc != NULL, "GetDC failed?\n");
2460 ok(hbm != NULL, "CreateCompatibleBitmap failed?\n");
2461
2462 /* Call GetDIBits to fill in bmiHeader. */
2463 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
2464 ok(ret == 1, "GetDIBits failed\n");
2465 if (dibinfo->bmiHeader.biBitCount > 8)
2466 {
2467 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
2468 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
2469 "compression is %lu (%d bpp)\n", dibinfo->bmiHeader.biCompression, dibinfo->bmiHeader.biBitCount );
2470
2471 if (dibinfo->bmiHeader.biCompression == BI_BITFIELDS)
2472 {
2473 ok( !bitmasks[0], "red mask is set\n" );
2474 ok( !bitmasks[1], "green mask is set\n" );
2475 ok( !bitmasks[2], "blue mask is set\n" );
2476
2477 /* test with NULL bits pointer and correct bpp */
2478 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2479 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
2480 ok(ret == 1, "GetDIBits failed\n");
2481
2482 ok( bitmasks[0] != 0, "red mask is not set\n" );
2483 ok( bitmasks[1] != 0, "green mask is not set\n" );
2484 ok( bitmasks[2] != 0, "blue mask is not set\n" );
2485 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2486
2487 /* test with valid bits pointer */
2488 memset(dibinfo, 0, sizeof(dibinfo_buf));
2489 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2490 ret = GetDIBits(hdc, hbm, 0, 1, NULL, dibinfo, DIB_RGB_COLORS);
2491 ok(ret == 1, "GetDIBits failed ret %u err %lu\n",ret,GetLastError());
2492 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2493 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2494 ok(ret == 1, "GetDIBits failed ret %u err %lu\n",ret,GetLastError());
2495
2496 ok( bitmasks[0] != 0, "red mask is not set\n" );
2497 ok( bitmasks[1] != 0, "green mask is not set\n" );
2498 ok( bitmasks[2] != 0, "blue mask is not set\n" );
2499 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2500
2501 /* now with bits and 0 lines */
2502 memset(dibinfo, 0, sizeof(dibinfo_buf));
2503 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2504 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2505 SetLastError(0xdeadbeef);
2506 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
2507 ok(ret == 1, "GetDIBits failed ret %u err %lu\n",ret,GetLastError());
2508
2509 ok( !bitmasks[0], "red mask is set\n" );
2510 ok( !bitmasks[1], "green mask is set\n" );
2511 ok( !bitmasks[2], "blue mask is set\n" );
2512 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2513
2514 memset(bitmasks, 0, 3*sizeof(DWORD));
2515 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2516 ret = GetDIBits(hdc, hbm, 0, 0, bits, dibinfo, DIB_RGB_COLORS);
2517 ok(ret == 1, "GetDIBits failed ret %u err %lu\n",ret,GetLastError());
2518
2519 ok( bitmasks[0] != 0, "red mask is not set\n" );
2520 ok( bitmasks[1] != 0, "green mask is not set\n" );
2521 ok( bitmasks[2] != 0, "blue mask is not set\n" );
2522 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2523 }
2524 }
2525 else skip("bitmap in colortable mode, skipping BI_BITFIELDS tests\n");
2526
2528
2529 /* same thing now with a 32-bpp DIB section */
2530
2531 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2532 dibinfo->bmiHeader.biWidth = 1;
2533 dibinfo->bmiHeader.biHeight = 1;
2534 dibinfo->bmiHeader.biPlanes = 1;
2535 dibinfo->bmiHeader.biBitCount = 32;
2536 dibinfo->bmiHeader.biCompression = BI_RGB;
2537 dibinfo->bmiHeader.biSizeImage = 0;
2538 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2539 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2540 dibinfo->bmiHeader.biClrUsed = 0;
2541 dibinfo->bmiHeader.biClrImportant = 0;
2542 bitmasks[0] = 0x0000ff;
2543 bitmasks[1] = 0x00ff00;
2544 bitmasks[2] = 0xff0000;
2545 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2546 ok( hbm != 0, "failed to create bitmap\n" );
2547
2548 memset(dibinfo, 0, sizeof(dibinfo_buf));
2549 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2550 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2551 ok(ret == 1, "GetDIBits failed\n");
2552 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2553
2554 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
2555 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
2556 "compression is %lu\n", dibinfo->bmiHeader.biCompression );
2557 ok( !bitmasks[0], "red mask is set\n" );
2558 ok( !bitmasks[1], "green mask is set\n" );
2559 ok( !bitmasks[2], "blue mask is set\n" );
2560
2561 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2562 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2563 ok(ret == 1, "GetDIBits failed\n");
2564 ok( dibinfo->bmiHeader.biBitCount == 32, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2565 ok( dibinfo->bmiHeader.biCompression == BI_BITFIELDS ||
2566 broken( dibinfo->bmiHeader.biCompression == BI_RGB ), /* nt4 sp3 */
2567 "compression is %lu\n", dibinfo->bmiHeader.biCompression );
2568 if (dibinfo->bmiHeader.biCompression == BI_BITFIELDS)
2569 {
2570 ok( bitmasks[0] == 0xff0000, "wrong red mask %08lx\n", bitmasks[0] );
2571 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08lx\n", bitmasks[1] );
2572 ok( bitmasks[2] == 0x0000ff, "wrong blue mask %08lx\n", bitmasks[2] );
2573 }
2574 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2575
2577
2578 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2579 dibinfo->bmiHeader.biWidth = 1;
2580 dibinfo->bmiHeader.biHeight = 1;
2581 dibinfo->bmiHeader.biPlanes = 1;
2582 dibinfo->bmiHeader.biBitCount = 32;
2584 dibinfo->bmiHeader.biSizeImage = 0;
2585 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2586 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2587 dibinfo->bmiHeader.biClrUsed = 0;
2588 dibinfo->bmiHeader.biClrImportant = 0;
2589 bitmasks[0] = 0x0000ff;
2590 bitmasks[1] = 0x00ff00;
2591 bitmasks[2] = 0xff0000;
2592 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2593 ok( hbm != 0, "failed to create bitmap\n" );
2594
2595 if (hbm)
2596 {
2597 memset(dibinfo, 0, sizeof(dibinfo_buf));
2598 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2599 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2600 ok(ret == 1, "GetDIBits failed\n");
2601
2603 "compression is %lu\n", dibinfo->bmiHeader.biCompression );
2604 ok( !bitmasks[0], "red mask is set\n" );
2605 ok( !bitmasks[1], "green mask is set\n" );
2606 ok( !bitmasks[2], "blue mask is set\n" );
2607
2608 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2609 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2610 ok(ret == 1, "GetDIBits failed\n");
2611 ok( bitmasks[0] == 0x0000ff, "wrong red mask %08lx\n", bitmasks[0] );
2612 ok( bitmasks[1] == 0x00ff00, "wrong green mask %08lx\n", bitmasks[1] );
2613 ok( bitmasks[2] == 0xff0000, "wrong blue mask %08lx\n", bitmasks[2] );
2614 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2615
2617 }
2618
2619 /* 24-bpp DIB sections don't have bitfields */
2620
2621 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2622 dibinfo->bmiHeader.biWidth = 1;
2623 dibinfo->bmiHeader.biHeight = 1;
2624 dibinfo->bmiHeader.biPlanes = 1;
2625 dibinfo->bmiHeader.biBitCount = 24;
2627 dibinfo->bmiHeader.biSizeImage = 0;
2628 dibinfo->bmiHeader.biXPelsPerMeter = 0;
2629 dibinfo->bmiHeader.biYPelsPerMeter = 0;
2630 dibinfo->bmiHeader.biClrUsed = 0;
2631 dibinfo->bmiHeader.biClrImportant = 0;
2632 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2633 ok( hbm == 0, "creating 24-bpp BI_BITFIELDS dibsection should fail\n" );
2634 dibinfo->bmiHeader.biCompression = BI_RGB;
2635 hbm = CreateDIBSection( hdc, dibinfo, DIB_RGB_COLORS, &ptr, NULL, 0 );
2636 ok( hbm != 0, "failed to create bitmap\n" );
2637
2638 memset(dibinfo, 0, sizeof(dibinfo_buf));
2639 dibinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2640 ret = GetDIBits(hdc, hbm, 0, 0, NULL, dibinfo, DIB_RGB_COLORS);
2641 ok(ret == 1, "GetDIBits failed\n");
2642 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2643
2644 ok( dibinfo->bmiHeader.biCompression == BI_RGB,
2645 "compression is %lu\n", dibinfo->bmiHeader.biCompression );
2646 ok( !bitmasks[0], "red mask is set\n" );
2647 ok( !bitmasks[1], "green mask is set\n" );
2648 ok( !bitmasks[2], "blue mask is set\n" );
2649
2650 dibinfo->bmiHeader.biSizeImage = 0xdeadbeef;
2651 ret = GetDIBits(hdc, hbm, 0, 1, bits, dibinfo, DIB_RGB_COLORS);
2652 ok(ret == 1, "GetDIBits failed\n");
2653 ok( dibinfo->bmiHeader.biBitCount == 24, "wrong bit count %u\n", dibinfo->bmiHeader.biBitCount );
2654 ok( !bitmasks[0], "red mask is set\n" );
2655 ok( !bitmasks[1], "green mask is set\n" );
2656 ok( !bitmasks[2], "blue mask is set\n" );
2657 ok( dibinfo->bmiHeader.biSizeImage != 0xdeadbeef, "size image not set\n" );
2658
2660 ReleaseDC(NULL, hdc);
2661}
2662
2663static void test_select_object(void)
2664{
2665 HDC hdc;
2666 HBITMAP hbm, hbm_old;
2667 INT planes, bpp, i;
2668 DWORD depths[] = {8, 15, 16, 24, 32};
2669 BITMAP bm;
2670 DWORD bytes;
2671
2672 hdc = GetDC(0);
2673 ok(hdc != 0, "GetDC(0) failed\n");
2674 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2675 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2676
2677 hbm_old = SelectObject(hdc, hbm);
2678 ok(hbm_old == 0, "SelectObject should fail\n");
2679
2681 ReleaseDC(0, hdc);
2682
2684 ok(hdc != 0, "GetDC(0) failed\n");
2685 hbm = CreateCompatibleBitmap(hdc, 10, 10);
2686 ok(hbm != 0, "CreateCompatibleBitmap failed\n");
2687
2688 hbm_old = SelectObject(hdc, hbm);
2689 ok(hbm_old != 0, "SelectObject failed\n");
2690 hbm_old = SelectObject(hdc, hbm_old);
2691 ok(hbm_old == hbm, "SelectObject failed\n");
2692
2693 SetLastError(0xdeadbeef);
2694 hbm_old = SelectObject(NULL, hbm);
2695 ok(!hbm_old, "SelectObject returned %p\n", hbm_old);
2696 ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() = %lu\n",
2697 GetLastError());
2698
2700
2701 /* test an 1-bpp bitmap */
2702 planes = GetDeviceCaps(hdc, PLANES);
2703 bpp = 1;
2704
2705 hbm = CreateBitmap(10, 10, planes, bpp, NULL);
2706 ok(hbm != 0, "CreateBitmap failed\n");
2707
2708 hbm_old = SelectObject(hdc, hbm);
2709 ok(hbm_old != 0, "SelectObject failed\n");
2710 hbm_old = SelectObject(hdc, hbm_old);
2711 ok(hbm_old == hbm, "SelectObject failed\n");
2712
2714
2715 for(i = 0; i < ARRAY_SIZE(depths); i++) {
2716 /* test a color bitmap to dc bpp matching */
2717 planes = GetDeviceCaps(hdc, PLANES);
2719
2720 hbm = CreateBitmap(10, 10, planes, depths[i], NULL);
2721 ok(hbm != 0, "CreateBitmap failed\n");
2722
2723 hbm_old = SelectObject(hdc, hbm);
2724 if(depths[i] == bpp ||
2725 (bpp == 16 && depths[i] == 15) /* 16 and 15 bpp are compatible */
2726 ) {
2727 ok(hbm_old != 0, "SelectObject failed, BITSPIXEL: %d, created depth: %ld\n", bpp, depths[i]);
2728 SelectObject(hdc, hbm_old);
2729 } else {
2730 ok(hbm_old == 0, "SelectObject should fail. BITSPIXELS: %d, created depth: %ld\n", bpp, depths[i]);
2731 }
2732
2733 memset(&bm, 0xAA, sizeof(bm));
2734 bytes = GetObjectW(hbm, sizeof(bm), &bm);
2735 ok(bytes == sizeof(bm), "GetObject returned %ld\n", bytes);
2736 ok(bm.bmType == 0, "wrong bmType %d\n", bm.bmType);
2737 ok(bm.bmWidth == 10, "wrong bmWidth %d\n", bm.bmWidth);
2738 ok(bm.bmHeight == 10, "wrong bmHeight %d\n", bm.bmHeight);
2739 ok(bm.bmWidthBytes == get_bitmap_stride(bm.bmWidth, bm.bmBitsPixel), "wrong bmWidthBytes %d\n", bm.bmWidthBytes);
2740 ok(bm.bmPlanes == planes, "wrong bmPlanes %u\n", bm.bmPlanes);
2741 if(depths[i] == 15) {
2742 ok(bm.bmBitsPixel == 16, "wrong bmBitsPixel %d(15 bpp special)\n", bm.bmBitsPixel);
2743 } else {
2744 ok(bm.bmBitsPixel == depths[i], "wrong bmBitsPixel %d\n", bm.bmBitsPixel);
2745 }
2746 ok(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2747
2749 }
2750
2751 DeleteDC(hdc);
2752}
2753
2755{
2756 INT ret;
2757 BITMAP bm;
2758
2760 ok_(__FILE__, line)(ret == OBJ_BITMAP, "the object %p is not bitmap\n", hbmp);
2761
2762 ret = GetObjectW(hbmp, 0, 0);
2763 ok_(__FILE__, line)(ret == sizeof(BITMAP), "object size %d\n", ret);
2764
2765 memset(&bm, 0xDA, sizeof(bm));
2766 SetLastError(0xdeadbeef);
2767 ret = GetObjectW(hbmp, sizeof(bm), &bm);
2768 if (!ret) /* XP, only for curObj2 */ return;
2769 ok_(__FILE__, line)(ret == sizeof(BITMAP), "GetObject returned %d, error %lu\n", ret, GetLastError());
2770 ok_(__FILE__, line)(bm.bmType == 0, "wrong bmType, expected 0 got %d\n", bm.bmType);
2771 ok_(__FILE__, line)(bm.bmWidth == 1, "wrong bmWidth, expected 1 got %d\n", bm.bmWidth);
2772 ok_(__FILE__, line)(bm.bmHeight == 1, "wrong bmHeight, expected 1 got %d\n", bm.bmHeight);
2773 ok_(__FILE__, line)(bm.bmWidthBytes == 2, "wrong bmWidthBytes, expected 2 got %d\n", bm.bmWidthBytes);
2774 ok_(__FILE__, line)(bm.bmPlanes == 1, "wrong bmPlanes, expected 1 got %u\n", bm.bmPlanes);
2775 ok_(__FILE__, line)(bm.bmBitsPixel == 1, "wrong bmBitsPixel, expected 1 got %d\n", bm.bmBitsPixel);
2776 ok_(__FILE__, line)(!bm.bmBits, "wrong bmBits %p\n", bm.bmBits);
2777}
2778
2779#define test_mono_1x1_bmp(a) test_mono_1x1_bmp_dbg((a), __LINE__)
2780
2781static void test_CreateBitmap(void)
2782{
2783 BITMAP bmp;
2784 HDC screenDC = GetDC(0);
2785 HDC hdc = CreateCompatibleDC(screenDC);
2786 UINT i, expect = 0;
2787
2788 /* all of these are the stock monochrome bitmap */
2790 HBITMAP bm1 = CreateCompatibleBitmap(screenDC, 0, 0);
2791 HBITMAP bm4 = CreateBitmap(0, 1, 0, 0, 0);
2792 HBITMAP bm5 = CreateDiscardableBitmap(hdc, 0, 0);
2794 HBITMAP curObj2 = GetCurrentObject(screenDC, OBJ_BITMAP);
2795
2796 /* these 2 are not the stock monochrome bitmap */
2797 HBITMAP bm2 = CreateCompatibleBitmap(hdc, 1, 1);
2798 HBITMAP bm3 = CreateBitmap(1, 1, 1, 1, 0);
2799
2800 HBITMAP old1 = SelectObject(hdc, bm2);
2801 HBITMAP old2 = SelectObject(screenDC, bm3);
2802 SelectObject(hdc, old1);
2803 SelectObject(screenDC, old2);
2804
2805 ok(bm == bm1 && bm == bm4 && bm == bm5 && bm == curObj1 && bm == old1,
2806 "0: %p, 1: %p, 4: %p, 5: %p, curObj1 %p, old1 %p\n",
2807 bm, bm1, bm4, bm5, curObj1, old1);
2808 ok(bm != bm2 && bm != bm3, "0: %p, 2: %p, 3: %p\n", bm, bm2, bm3);
2809 ok(bm != curObj2, "0: %p, curObj2 %p\n", bm, curObj2);
2810 ok(old2 == 0, "old2 %p\n", old2);
2811
2813 test_mono_1x1_bmp(bm1);
2814 test_mono_1x1_bmp(bm2);
2815 test_mono_1x1_bmp(bm3);
2816 test_mono_1x1_bmp(bm4);
2817 test_mono_1x1_bmp(bm5);
2818 test_mono_1x1_bmp(old1);
2819 test_mono_1x1_bmp(curObj1);
2820
2821 DeleteObject(bm);
2822 DeleteObject(bm1);
2823 DeleteObject(bm2);
2824 DeleteObject(bm3);
2825 DeleteObject(bm4);
2826 DeleteObject(bm5);
2827
2828 DeleteDC(hdc);
2829 ReleaseDC(0, screenDC);
2830
2831 /* show that Windows ignores the provided bm.bmWidthBytes */
2832 bmp.bmType = 0;
2833 bmp.bmWidth = 1;
2834 bmp.bmHeight = 1;
2835 bmp.bmWidthBytes = 28;
2836 bmp.bmPlanes = 1;
2837 bmp.bmBitsPixel = 1;
2838 bmp.bmBits = NULL;
2840 ok(bm != 0, "CreateBitmapIndirect error %lu\n", GetLastError());
2842 DeleteObject(bm);
2843
2844 /* Test how the bmBitsPixel field is treated */
2845 for(i = 1; i <= 33; i++) {
2846 bmp.bmType = 0;
2847 bmp.bmWidth = 1;
2848 bmp.bmHeight = 1;
2849 bmp.bmWidthBytes = 28;
2850 bmp.bmPlanes = 1;
2851 bmp.bmBitsPixel = i;
2852 bmp.bmBits = NULL;
2853 SetLastError(0xdeadbeef);
2855 if(i > 32) {
2857 ok(bm == 0, "CreateBitmapIndirect for %d bpp succeeded\n", i);
2858 ok(error == ERROR_INVALID_PARAMETER, "Got error %ld, expected ERROR_INVALID_PARAMETER\n", error);
2859 DeleteObject(bm);
2860 continue;
2861 }
2862 ok(bm != 0, "CreateBitmapIndirect error %lu\n", GetLastError());
2863 GetObjectW(bm, sizeof(bmp), &bmp);
2864 if(i == 1) {
2865 expect = 1;
2866 } else if(i <= 4) {
2867 expect = 4;
2868 } else if(i <= 8) {
2869 expect = 8;
2870 } else if(i <= 16) {
2871 expect = 16;
2872 } else if(i <= 24) {
2873 expect = 24;
2874 } else if(i <= 32) {
2875 expect = 32;
2876 }
2877 ok(bmp.bmBitsPixel == expect, "CreateBitmapIndirect for a %d bpp bitmap created a %d bpp bitmap, expected %d\n",
2879 DeleteObject(bm);
2880 }
2881}
2882
2884{
2885 HBITMAP hdib;
2886 BITMAPINFO bmi;
2887 BITMAPCOREINFO bci;
2888 HDC hdc = GetDC(0);
2889
2890 memset(&bmi, 0, sizeof(BITMAPINFO));
2891 bmi.bmiHeader.biHeight = 100;
2892 bmi.bmiHeader.biWidth = 512;
2893 bmi.bmiHeader.biBitCount = 24;
2894 bmi.bmiHeader.biPlanes = 1;
2895
2896 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER) - 1;
2897
2898 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2899 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2900
2901 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2902
2903 SetLastError(0xdeadbeef);
2904 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2905 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
2906 DeleteObject(hdib);
2907
2908 bmi.bmiHeader.biSize++;
2909
2910 SetLastError(0xdeadbeef);
2911 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2912 ok(hdib != NULL ||
2913 broken(!hdib), /* Win98, WinMe */
2914 "CreateDIBSection error %ld\n", GetLastError());
2915 DeleteObject(hdib);
2916
2917 bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
2918
2919 SetLastError(0xdeadbeef);
2920 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2921 ok(hdib != NULL ||
2922 broken(!hdib), /* Win98, WinMe */
2923 "CreateDIBSection error %ld\n", GetLastError());
2924 DeleteObject(hdib);
2925
2926 bmi.bmiHeader.biSize++;
2927
2928 SetLastError(0xdeadbeef);
2929 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2930 ok(hdib != NULL ||
2931 broken(!hdib), /* Win98, WinMe */
2932 "CreateDIBSection error %ld\n", GetLastError());
2933 DeleteObject(hdib);
2934
2935 bmi.bmiHeader.biSize = sizeof(BITMAPV4HEADER);
2936
2937 SetLastError(0xdeadbeef);
2938 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2939 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
2940 DeleteObject(hdib);
2941
2942 bmi.bmiHeader.biSize = sizeof(BITMAPV5HEADER);
2943
2944 SetLastError(0xdeadbeef);
2945 hdib = CreateDIBSection(hdc, &bmi, 0, NULL, NULL, 0);
2946 ok(hdib != NULL ||
2947 broken(!hdib), /* Win95 */
2948 "CreateDIBSection error %ld\n", GetLastError());
2949 DeleteObject(hdib);
2950
2951 memset(&bci, 0, sizeof(BITMAPCOREINFO));
2952 bci.bmciHeader.bcHeight = 100;
2953 bci.bmciHeader.bcWidth = 512;
2954 bci.bmciHeader.bcBitCount = 24;
2955 bci.bmciHeader.bcPlanes = 1;
2956
2957 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER) - 1;
2958
2959 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2960 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2961
2962 bci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
2963
2964 SetLastError(0xdeadbeef);
2965 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2966 ok(hdib != NULL, "CreateDIBSection error %ld\n", GetLastError());
2967 DeleteObject(hdib);
2968
2969 bci.bmciHeader.bcSize++;
2970
2971 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2972 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2973
2974 bci.bmciHeader.bcSize = sizeof(BITMAPCOREINFO);
2975
2976 hdib = CreateDIBSection(hdc, (BITMAPINFO *)&bci, 0, NULL, NULL, 0);
2977 ok(hdib == NULL, "CreateDIBSection succeeded\n");
2978
2979 ReleaseDC(0, hdc);
2980}
2981
2982static void test_get16dibits(void)
2983{
2984 BYTE bits[4 * (16 / sizeof(BYTE))];
2985 HBITMAP hbmp;
2986 HDC screen_dc = GetDC(NULL);
2987 int ret;
2988 BITMAPINFO * info;
2989 int info_len = sizeof(BITMAPINFOHEADER) + 1024;
2990 BYTE *p;
2991 int overwritten_bytes = 0;
2992
2993 memset(bits, 0, sizeof(bits));
2994 hbmp = CreateBitmap(2, 2, 1, 16, bits);
2995 ok(hbmp != NULL, "CreateBitmap failed\n");
2996
2997 info = calloc(1, info_len);
2998 assert(info);
2999
3000 memset(info, '!', info_len);
3001 memset(info, 0, sizeof(info->bmiHeader));
3002
3003 info->bmiHeader.biSize = sizeof(info->bmiHeader);
3004 info->bmiHeader.biWidth = 2;
3005 info->bmiHeader.biHeight = 2;
3006 info->bmiHeader.biPlanes = 1;
3007 info->bmiHeader.biCompression = BI_RGB;
3008
3009 ret = GetDIBits(screen_dc, hbmp, 0, 0, NULL, info, 0);
3010 ok(ret != 0, "GetDIBits failed got %d\n", ret);
3011
3012 for (p = ((BYTE *) info) + sizeof(info->bmiHeader); (p - ((BYTE *) info)) < info_len; p++)
3013 if (*p != '!')
3014 overwritten_bytes++;
3015 ok(overwritten_bytes == 0, "GetDIBits wrote past the buffer given\n");
3016
3017 free(info);
3019 ReleaseDC(NULL, screen_dc);
3020}
3021
3022static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
3023 DWORD dwRop, UINT32 expected, int line)
3024{
3025 *srcBuffer = 0xFEDCBA98;
3026 *dstBuffer = 0x89ABCDEF;
3027 BitBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, dwRop);
3028 ok(expected == *dstBuffer,
3029 "BitBlt with dwRop %06lX. Expected 0x%08X, got 0x%08X from line %d\n",
3030 dwRop, expected, *dstBuffer, line);
3031}
3032
3033static void test_BitBlt(void)
3034{
3035 HBITMAP bmpDst, bmpSrc;
3036 HBITMAP oldDst, oldSrc;
3037 HDC hdcScreen, hdcDst, hdcSrc;
3038 UINT32 *dstBuffer, *srcBuffer;
3039 HBRUSH hBrush, hOldBrush;
3040 BITMAPINFO bitmapInfo;
3041
3042 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
3043 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3044 bitmapInfo.bmiHeader.biWidth = 1;
3045 bitmapInfo.bmiHeader.biHeight = 1;
3046 bitmapInfo.bmiHeader.biPlanes = 1;
3047 bitmapInfo.bmiHeader.biBitCount = 32;
3048 bitmapInfo.bmiHeader.biCompression = BI_RGB;
3049 bitmapInfo.bmiHeader.biSizeImage = sizeof(UINT32);
3050
3051 hdcScreen = CreateCompatibleDC(0);
3052 hdcDst = CreateCompatibleDC(hdcScreen);
3054
3055 /* Setup the destination dib section */
3056 bmpDst = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&dstBuffer,
3057 NULL, 0);
3058 oldDst = SelectObject(hdcDst, bmpDst);
3059
3060 hBrush = CreateSolidBrush(0x12345678);
3061 hOldBrush = SelectObject(hdcDst, hBrush);
3062
3063 /* Setup the source dib section */
3064 bmpSrc = CreateDIBSection(hdcScreen, &bitmapInfo, DIB_RGB_COLORS, (void**)&srcBuffer,
3065 NULL, 0);
3066 oldSrc = SelectObject(hdcSrc, bmpSrc);
3067
3068 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
3069 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
3070 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
3071 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
3072 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
3073 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
3074 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
3075 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
3076 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
3077 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
3078 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
3079 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
3080 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
3081 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
3082 check_BitBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
3083
3084 /* Tidy up */
3085 SelectObject(hdcSrc, oldSrc);
3086 DeleteObject(bmpSrc);
3088
3089 SelectObject(hdcDst, hOldBrush);
3090 DeleteObject(hBrush);
3091 SelectObject(hdcDst, oldDst);
3092 DeleteObject(bmpDst);
3094
3095
3096 DeleteDC(hdcScreen);
3097}
3098
3099static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer,
3100 DWORD dwRop, UINT32 expected, int line)
3101{
3102 *srcBuffer = 0xFEDCBA98;
3103 *dstBuffer = 0x89ABCDEF;
3104 StretchBlt(hdcDst, 0, 0, 2, 1, hdcSrc, 0, 0, 1, 1, dwRop);
3105 ok(expected == *dstBuffer,
3106 "StretchBlt with dwRop %06lX. Expected 0x%08X, got 0x%08X from line %d\n",
3107 dwRop, expected, *dstBuffer, line);
3108}
3109
3110static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, BITMAPINFO *dst_info, UINT32 *dstBuffer, UINT32 *srcBuffer,
3111 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
3112 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
3113 UINT32 *expected, int line)
3114{
3115 int dst_size = get_dib_image_size( dst_info );
3116
3117 memset(dstBuffer, 0, dst_size);
3118 StretchBlt(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
3119 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
3120 ok(memcmp(dstBuffer, expected, dst_size) == 0,
3121 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
3122 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
3123 expected[0], expected[1], expected[2], expected[3],
3124 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
3125 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
3126 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
3127}
3128
3129static void test_StretchBlt(void)
3130{
3131 HBITMAP bmpDst, bmpSrc;
3132 HBITMAP oldDst, oldSrc;
3133 HDC hdcScreen, hdcDst, hdcSrc;
3134 UINT32 *dstBuffer, *srcBuffer;
3135 HBRUSH hBrush, hOldBrush;
3136 BITMAPINFO biDst, biSrc;
3137 UINT32 expected[256];
3138 RGBQUAD colors[2];
3139
3140 memset(&biDst, 0, sizeof(BITMAPINFO));
3141 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3142 biDst.bmiHeader.biWidth = 16;
3143 biDst.bmiHeader.biHeight = -16;
3144 biDst.bmiHeader.biPlanes = 1;
3145 biDst.bmiHeader.biBitCount = 32;
3147 memcpy(&biSrc, &biDst, sizeof(BITMAPINFO));
3148
3149 hdcScreen = CreateCompatibleDC(0);
3150 hdcDst = CreateCompatibleDC(hdcScreen);
3152
3153 /* Pixel Tests */
3154 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
3155 NULL, 0);
3156 oldDst = SelectObject(hdcDst, bmpDst);
3157
3158 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
3159 NULL, 0);
3160 oldSrc = SelectObject(hdcSrc, bmpSrc);
3161
3162 hBrush = CreateSolidBrush(0x012345678);
3163 hOldBrush = SelectObject(hdcDst, hBrush);
3164
3165 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
3166 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
3167 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
3168 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
3169 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
3170 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
3171 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
3172 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
3173 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
3174 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
3175 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
3176 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
3177 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
3178 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
3179 check_StretchBlt_pixel(hdcDst, hdcSrc, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
3180
3181 SelectObject(hdcDst, hOldBrush);
3182 DeleteObject(hBrush);
3183
3184 /* Top-down to top-down tests */
3185 srcBuffer[0] = 0xCAFED00D; srcBuffer[1] = 0xFEEDFACE;
3186 srcBuffer[16] = 0xFEDCBA98; srcBuffer[17] = 0x76543210;
3187
3188 memset( expected, 0, get_dib_image_size( &biDst ) );
3189 expected[0] = 0xCAFED00D; expected[1] = 0xFEEDFACE;
3190 expected[16] = 0xFEDCBA98; expected[17] = 0x76543210;
3191 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3192 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3193
3194 expected[0] = 0xCAFED00D; expected[1] = 0x00000000;
3195 expected[16] = 0x00000000; expected[17] = 0x00000000;
3196 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3197 0, 0, 1, 1, 0, 0, 1, 1, expected, __LINE__);
3198
3199 expected[0] = 0xCAFED00D; expected[1] = 0xCAFED00D;
3200 expected[16] = 0xCAFED00D; expected[17] = 0xCAFED00D;
3201 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3202 0, 0, 2, 2, 0, 0, 1, 1, expected, __LINE__);
3203
3204 /* This is an example of the dst width (height) == 1 exception, explored below */
3205 expected[0] = 0xCAFED00D; expected[1] = 0x00000000;
3206 expected[16] = 0x00000000; expected[17] = 0x00000000;
3207 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3208 0, 0, 1, 1, 0, 0, 2, 2, expected, __LINE__);
3209
3210 expected[0] = 0x76543210; expected[1] = 0xFEDCBA98;
3211 expected[16] = 0xFEEDFACE; expected[17] = 0xCAFED00D;
3212 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3213 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3214
3215 expected[0] = 0x76543210; expected[1] = 0xFEDCBA98;
3216 expected[16] = 0xFEEDFACE; expected[17] = 0xCAFED00D;
3217 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3218 1, 1, -2, -2, 0, 0, 2, 2, expected, __LINE__);
3219
3220 expected[0] = 0xCAFED00D; expected[1] = 0x00000000;
3221 expected[16] = 0x00000000; expected[17] = 0x00000000;
3222 todo_wine check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3223 1, 1, -2, -2, 1, 1, -2, -2, expected, __LINE__);
3224
3225 expected[0] = 0x00000000; expected[1] = 0x00000000;
3226 expected[16] = 0x00000000; expected[17] = 0xCAFED00D; expected[18] = 0xFEEDFACE;
3227 expected[32] = 0x00000000; expected[33] = 0xFEDCBA98; expected[34] = 0x76543210;
3228
3229 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3230 1, 1, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3231
3232 /* when dst width is 1 merge src width - 1 pixels */
3233 memset( srcBuffer, 0, get_dib_image_size( &biSrc ) );
3234 srcBuffer[0] = 0x0000ff00; srcBuffer[1] = 0x0000f0f0; srcBuffer[2] = 0x0000cccc; srcBuffer[3] = 0x0000aaaa;
3235 srcBuffer[16] = 0xFEDCBA98; srcBuffer[17] = 0x76543210;
3236
3237 memset( expected, 0, get_dib_image_size( &biDst ) );
3238 expected[0] = srcBuffer[0];
3239 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3240 0, 0, 1, 1, 0, 0, 2, 1, expected, __LINE__);
3241
3242 expected[0] = srcBuffer[0] & srcBuffer[1];
3243 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3244 0, 0, 1, 1, 0, 0, 3, 1, expected, __LINE__);
3245
3246 expected[0] = srcBuffer[0] & srcBuffer[1] & srcBuffer[2];
3247 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3248 0, 0, 1, 1, 0, 0, 4, 1, expected, __LINE__);
3249
3250 /* this doesn't happen if the src width is -ve */
3251 expected[0] = srcBuffer[1] & srcBuffer[2];
3252 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3253 0, 0, 1, 1, 2, 0, -2, 1, expected, __LINE__);
3254
3255 /* when dst width > 1 behaviour reverts to what one would expect */
3256 expected[0] = srcBuffer[0] & srcBuffer[1]; expected[1] = srcBuffer[2] & srcBuffer[3];
3257 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3258 0, 0, 2, 1, 0, 0, 4, 1, expected, __LINE__);
3259
3260 /* similarly in the vertical direction */
3261 memset( expected, 0, get_dib_image_size( &biDst ) );
3262 expected[0] = srcBuffer[0];
3263 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3264 0, 0, 1, 1, 0, 0, 1, 2, expected, __LINE__);
3265
3266 /* check that it's the dst size in device units that needs to be 1 */
3268 SetWindowExtEx( hdcDst, 200, 200, NULL );
3269 SetViewportExtEx( hdcDst, 100, 100, NULL );
3270
3271 expected[0] = srcBuffer[0] & srcBuffer[1] & srcBuffer[2];
3272 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3273 0, 0, 2, 2, 0, 0, 4, 1, expected, __LINE__);
3275
3276 /* the destination rectangle doesn't fit in the device area */
3277 memset( expected, 0, get_dib_image_size( &biDst ) );
3278 expected[17] = 0x76543210; expected[18] = 0xfedcba98;
3279 expected[32] = 0x0000cccc; expected[33] = 0x0000f0f0; expected[34] = 0x0000ff00;
3280 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3281 2, 2, -8, -8, 0, 0, 8, 8, expected, __LINE__);
3282
3283 /* the source rectangle doesn't fit in the device area */
3284 memset( expected, 0, get_dib_image_size( &biDst ) );
3285 expected[102] = 0x76543210; expected[103] = 0xfedcba98;
3286 expected[117] = 0x0000cccc; expected[118] = 0x0000f0f0; expected[119] = 0x0000ff00;
3287 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3288 0, 0, 8, 8, 2, 2, -8, -8, expected, __LINE__);
3289
3290 memset( expected, 0, get_dib_image_size( &biDst ) );
3291 expected[85] = 0x76543210; expected[86] = 0xfedcba98;
3292 expected[99] = 0x0000aaaa; expected[100] = 0x0000cccc; expected[101] = 0x0000f0f0; expected[102] = 0x0000ff00;
3293 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3294 8, 8, -18, -18, 0, 0, 18, 18, expected, __LINE__);
3295
3296 SelectObject(hdcDst, oldDst);
3297 DeleteObject(bmpDst);
3298
3299 /* Top-down to bottom-up tests */
3300 memset( srcBuffer, 0, get_dib_image_size( &biSrc ) );
3301 srcBuffer[0] = 0xCAFED00D; srcBuffer[1] = 0xFEEDFACE;
3302 srcBuffer[16] = 0xFEDCBA98; srcBuffer[17] = 0x76543210;
3303
3304 biDst.bmiHeader.biHeight = 16;
3305 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
3306 NULL, 0);
3307 oldDst = SelectObject(hdcDst, bmpDst);
3308
3309 memset( expected, 0, get_dib_image_size( &biDst ) );
3310
3311 expected[224] = 0xFEDCBA98; expected[225] = 0x76543210;
3312 expected[240] = 0xCAFED00D; expected[241] = 0xFEEDFACE;
3313 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3314 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3315
3316 expected[224] = 0xFEEDFACE; expected[225] = 0xCAFED00D;
3317 expected[240] = 0x76543210; expected[241] = 0xFEDCBA98;
3318 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3319 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3320
3321 SelectObject(hdcSrc, oldSrc);
3322 DeleteObject(bmpSrc);
3323
3324 /* Bottom-up to bottom-up tests */
3325 biSrc.bmiHeader.biHeight = 16;
3326 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer,
3327 NULL, 0);
3328 srcBuffer[224] = 0xCAFED00D; srcBuffer[225] = 0xFEEDFACE;
3329 srcBuffer[240] = 0xFEDCBA98; srcBuffer[241] = 0x76543210;
3330 oldSrc = SelectObject(hdcSrc, bmpSrc);
3331
3332 memset( expected, 0, get_dib_image_size( &biDst ) );
3333
3334 expected[224] = 0xCAFED00D; expected[225] = 0xFEEDFACE;
3335 expected[240] = 0xFEDCBA98; expected[241] = 0x76543210;
3336 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3337 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3338
3339 expected[224] = 0x76543210; expected[225] = 0xFEDCBA98;
3340 expected[240] = 0xFEEDFACE; expected[241] = 0xCAFED00D;
3341 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3342 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3343
3344 SelectObject(hdcDst, oldDst);
3345 DeleteObject(bmpDst);
3346
3347 /* Bottom-up to top-down tests */
3348 biDst.bmiHeader.biHeight = -16;
3349 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
3350 NULL, 0);
3351 oldDst = SelectObject(hdcDst, bmpDst);
3352
3353 memset( expected, 0, get_dib_image_size( &biDst ) );
3354 expected[0] = 0xFEDCBA98; expected[1] = 0x76543210;
3355 expected[16] = 0xCAFED00D; expected[17] = 0xFEEDFACE;
3356 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3357 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3358
3359 expected[0] = 0xFEEDFACE; expected[1] = 0xCAFED00D;
3360 expected[16] = 0x76543210; expected[17] = 0xFEDCBA98;
3361 check_StretchBlt_stretch(hdcDst, hdcSrc, &biDst, dstBuffer, srcBuffer,
3362 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3363
3364 SelectObject(hdcSrc, oldSrc);
3365 DeleteObject(bmpSrc);
3366
3367 biSrc.bmiHeader.biHeight = -2;
3368 biSrc.bmiHeader.biBitCount = 24;
3369 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer, NULL, 0);
3370 oldSrc = SelectObject(hdcSrc, bmpSrc);
3371
3372 memset( expected, 0, get_dib_image_size( &biDst ) );
3373 expected[0] = 0xFEEDFACE; expected[1] = 0xCAFED00D;
3374 expected[2] = 0x76543210; expected[3] = 0xFEDCBA98;
3375 memcpy(dstBuffer, expected, 4 * sizeof(*dstBuffer));
3376 StretchBlt(hdcSrc, 0, 0, 4, 1, hdcDst, 0, 0, 4, 1, SRCCOPY );
3377 memset(dstBuffer, 0x55, 4 * sizeof(*dstBuffer));
3378 StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
3379 expected[0] = 0x00EDFACE; expected[1] = 0x00FED00D;
3380 expected[2] = 0x00543210; expected[3] = 0x00DCBA98;
3381 ok(!memcmp(dstBuffer, expected, 16),
3382 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
3383 expected[0], expected[1], expected[2], expected[3],
3384 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
3385
3386 expected[0] = 0xFEEDFACE; expected[1] = 0xCAFED00D;
3387 expected[2] = 0x76543210; expected[3] = 0xFEDCBA98;
3388 memcpy(srcBuffer, expected, 4 * sizeof(*dstBuffer));
3389 memset(dstBuffer, 0x55, 4 * sizeof(*dstBuffer));
3390 StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
3391 expected[0] = 0x00EDFACE; expected[1] = 0x00D00DFE;
3392 expected[2] = 0x0010CAFE; expected[3] = 0x00765432;
3393 ok(!memcmp(dstBuffer, expected, 16),
3394 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
3395 expected[0], expected[1], expected[2], expected[3],
3396 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
3397
3398 SelectObject(hdcSrc, oldSrc);
3399 DeleteObject(bmpSrc);
3400
3401 biSrc.bmiHeader.biBitCount = 1;
3402 bmpSrc = CreateDIBSection(hdcScreen, &biSrc, DIB_RGB_COLORS, (void**)&srcBuffer, NULL, 0);
3403 oldSrc = SelectObject(hdcSrc, bmpSrc);
3404 *((DWORD *)colors + 0) = 0x123456;
3405 *((DWORD *)colors + 1) = 0x335577;
3406 SetDIBColorTable( hdcSrc, 0, 2, colors );
3407 srcBuffer[0] = 0x55555555;
3408 memset(dstBuffer, 0xcc, 4 * sizeof(*dstBuffer));
3409 SetTextColor( hdcDst, 0 );
3410 SetBkColor( hdcDst, 0 );
3411 StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
3412 expected[0] = expected[2] = 0x00123456;
3413 expected[1] = expected[3] = 0x00335577;
3414 ok(!memcmp(dstBuffer, expected, 16),
3415 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
3416 expected[0], expected[1], expected[2], expected[3],
3417 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
3418
3419 SelectObject(hdcSrc, oldSrc);
3420 DeleteObject(bmpSrc);
3421
3422 bmpSrc = CreateBitmap( 16, 16, 1, 1, 0 );
3423 oldSrc = SelectObject(hdcSrc, bmpSrc);
3424 SetPixel( hdcSrc, 0, 0, 0 );
3425 SetPixel( hdcSrc, 1, 0, 0xffffff );
3426 SetPixel( hdcSrc, 2, 0, 0xffffff );
3427 SetPixel( hdcSrc, 3, 0, 0 );
3428 memset(dstBuffer, 0xcc, 4 * sizeof(*dstBuffer));
3429 SetTextColor( hdcDst, RGB(0x22,0x44,0x66) );
3430 SetBkColor( hdcDst, RGB(0x65,0x43,0x21) );
3431 StretchBlt(hdcDst, 0, 0, 4, 1, hdcSrc, 0, 0, 4, 1, SRCCOPY );
3432 expected[0] = expected[3] = 0x00224466;
3433 expected[1] = expected[2] = 0x00654321;
3434 ok(!memcmp(dstBuffer, expected, 16),
3435 "StretchBlt expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X }\n",
3436 expected[0], expected[1], expected[2], expected[3],
3437 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3] );
3438
3439 SelectObject(hdcSrc, oldSrc);
3440 DeleteObject(bmpSrc);
3441
3443
3444 SelectObject(hdcDst, oldDst);
3445 DeleteObject(bmpDst);
3447
3448 DeleteDC(hdcScreen);
3449}
3450
3451static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
3452 DWORD dwRop, UINT32 expected, int line)
3453{
3454 const UINT32 buffer[2] = { 0xFEDCBA98, 0 };
3455 BITMAPINFO bitmapInfo;
3456
3457 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
3458 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3459 bitmapInfo.bmiHeader.biWidth = 2;
3460 bitmapInfo.bmiHeader.biHeight = 1;
3461 bitmapInfo.bmiHeader.biPlanes = 1;
3462 bitmapInfo.bmiHeader.biBitCount = 32;
3463 bitmapInfo.bmiHeader.biCompression = BI_RGB;
3464 bitmapInfo.bmiHeader.biSizeImage = sizeof(buffer);
3465
3466 *dstBuffer = 0x89ABCDEF;
3467
3468 StretchDIBits(hdcDst, 0, 0, 2, 1, 0, 0, 1, 1, &buffer, &bitmapInfo, DIB_RGB_COLORS, dwRop);
3469 ok(expected == *dstBuffer,
3470 "StretchDIBits with dwRop %06lX. Expected 0x%08X, got 0x%08X from line %d\n",
3471 dwRop, expected, *dstBuffer, line);
3472}
3473
3474static INT check_StretchDIBits_stretch( HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer,
3475 int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
3476 int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
3477 UINT32 expected[4], int line)
3478{
3479 BITMAPINFO bitmapInfo;
3480 INT ret;
3481
3482 memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
3483 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3484 bitmapInfo.bmiHeader.biWidth = 2;
3485 bitmapInfo.bmiHeader.biHeight = -2;
3486 bitmapInfo.bmiHeader.biPlanes = 1;
3487 bitmapInfo.bmiHeader.biBitCount = 32;
3488 bitmapInfo.bmiHeader.biCompression = BI_RGB;
3489
3490 memset(dstBuffer, 0, 16);
3491 ret = StretchDIBits(hdcDst, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
3492 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
3493 srcBuffer, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
3494 ok(memcmp(dstBuffer, expected, 16) == 0,
3495 "StretchDIBits expected { %08X, %08X, %08X, %08X } got { %08X, %08X, %08X, %08X } "
3496 "stretching { %d, %d, %d, %d } to { %d, %d, %d, %d } from line %d\n",
3497 expected[0], expected[1], expected[2], expected[3],
3498 dstBuffer[0], dstBuffer[1], dstBuffer[2], dstBuffer[3],
3499 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
3500 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, line);
3501 return ret;
3502}
3503
3504static void test_StretchDIBits(void)
3505{
3506 HBITMAP bmpDst;
3507 HBITMAP oldDst;
3508 HDC hdcScreen, hdcDst;
3509 UINT32 *dstBuffer, srcBuffer[4];
3510 HBRUSH hBrush, hOldBrush;
3511 BITMAPINFO biDst;
3512 UINT32 expected[4];
3513 INT ret;
3514
3515 memset(&biDst, 0, sizeof(BITMAPINFO));
3516 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3517 biDst.bmiHeader.biWidth = 2;
3518 biDst.bmiHeader.biHeight = -2;
3519 biDst.bmiHeader.biPlanes = 1;
3520 biDst.bmiHeader.biBitCount = 32;
3522
3523 hdcScreen = CreateCompatibleDC(0);
3524 hdcDst = CreateCompatibleDC(hdcScreen);
3525
3526 /* Pixel Tests */
3527 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
3528 NULL, 0);
3529 oldDst = SelectObject(hdcDst, bmpDst);
3530
3531 hBrush = CreateSolidBrush(0x012345678);
3532 hOldBrush = SelectObject(hdcDst, hBrush);
3533
3534 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCCOPY, 0xFEDCBA98, __LINE__);
3535 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCPAINT, 0xFFFFFFFF, __LINE__);
3536 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCAND, 0x88888888, __LINE__);
3537 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCINVERT, 0x77777777, __LINE__);
3538 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, SRCERASE, 0x76543210, __LINE__);
3539 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCCOPY, 0x01234567, __LINE__);
3540 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, NOTSRCERASE, 0x00000000, __LINE__);
3541 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGECOPY, 0x00581210, __LINE__);
3542 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, MERGEPAINT, 0x89ABCDEF, __LINE__);
3543 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATCOPY, 0x00785634, __LINE__);
3544 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATPAINT, 0x89FBDFFF, __LINE__);
3545 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, PATINVERT, 0x89D39BDB, __LINE__);
3546 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, DSTINVERT, 0x76543210, __LINE__);
3547 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, BLACKNESS, 0x00000000, __LINE__);
3548 check_StretchDIBits_pixel(hdcDst, dstBuffer, srcBuffer, WHITENESS, 0xFFFFFFFF, __LINE__);
3549
3550 SelectObject(hdcDst, hOldBrush);
3551 DeleteObject(hBrush);
3552
3553 /* Top-down destination tests */
3554 srcBuffer[0] = 0xCAFED00D; srcBuffer[1] = 0xFEEDFACE;
3555 srcBuffer[2] = 0xFEDCBA98; srcBuffer[3] = 0x76543210;
3556
3557 expected[0] = 0xCAFED00D; expected[1] = 0xFEEDFACE;
3558 expected[2] = 0xFEDCBA98; expected[3] = 0x76543210;
3559 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3560 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3561 ok( ret == 2, "got ret %d\n", ret );
3562
3563 expected[0] = 0xCAFED00D; expected[1] = 0x00000000;
3564 expected[2] = 0x00000000; expected[3] = 0x00000000;
3565 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3566 0, 0, 1, 1, 0, 0, 1, 1, expected, __LINE__);
3567 todo_wine ok( ret == 1, "got ret %d\n", ret );
3568
3569 expected[0] = 0xFEDCBA98; expected[1] = 0xFEDCBA98;
3570 expected[2] = 0xFEDCBA98; expected[3] = 0xFEDCBA98;
3571 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3572 0, 0, 2, 2, 0, 0, 1, 1, expected, __LINE__);
3573 ok( ret == 2, "got ret %d\n", ret );
3574
3575 expected[0] = 0x42441000; expected[1] = 0x00000000;
3576 expected[2] = 0x00000000; expected[3] = 0x00000000;
3577 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3578 0, 0, 1, 1, 0, 0, 2, 2, expected, __LINE__);
3579 ok( ret == 2, "got ret %d\n", ret );
3580
3581 expected[0] = 0x00000000; expected[1] = 0x00000000;
3582 expected[2] = 0x00000000; expected[3] = 0x00000000;
3583 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3584 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3585 ok( ret == 0, "got ret %d\n", ret );
3586
3587 expected[0] = 0x00000000; expected[1] = 0x00000000;
3588 expected[2] = 0x00000000; expected[3] = 0x00000000;
3589 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3590 0, 0, 2, 2, 1, 1, -2, -2, expected, __LINE__);
3591 ok( ret == 0, "got ret %d\n", ret );
3592
3593 expected[0] = 0x00000000; expected[1] = 0x00000000;
3594 expected[2] = 0x00000000; expected[3] = 0x00000000;
3595 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3596 1, 1, -2, -2, 1, 1, -2, -2, expected, __LINE__);
3597 ok( ret == 0, "got ret %d\n", ret );
3598
3599 expected[0] = 0x00000000; expected[1] = 0x00000000;
3600 expected[2] = 0x00000000; expected[3] = 0xCAFED00D;
3601 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3602 1, 1, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3603 ok( ret == 2, "got ret %d\n", ret );
3604
3605 expected[0] = 0x00000000; expected[1] = 0x00000000;
3606 expected[2] = 0x00000000; expected[3] = 0x00000000;
3607 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3608 2, 2, 4, 4, 0, 0, 2, 2, expected, __LINE__);
3609 ok( ret == 2, "got ret %d\n", ret );
3610
3611 expected[0] = 0x00000000; expected[1] = 0x00000000;
3612 expected[2] = 0x00000000; expected[3] = 0x00000000;
3613 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3614 -4, -4, 4, 4, 0, 0, 4, 4, expected, __LINE__);
3615 ok( ret == 2, "got ret %d\n", ret );
3616
3617 expected[0] = 0x00000000; expected[1] = 0x00000000;
3618 expected[2] = 0xFEEDFACE; expected[3] = 0x00000000;
3619 ret = check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3620 1, 1, -2, -2, 1, 1, 2, 2, expected, __LINE__);
3621 ok( ret == 2, "got ret %d\n", ret );
3622
3623 SelectObject(hdcDst, oldDst);
3624 DeleteObject(bmpDst);
3625
3626 /* Bottom up destination tests */
3627 biDst.bmiHeader.biHeight = 2;
3628 bmpDst = CreateDIBSection(hdcScreen, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer,
3629 NULL, 0);
3630 oldDst = SelectObject(hdcDst, bmpDst);
3631
3632 expected[0] = 0xFEDCBA98; expected[1] = 0x76543210;
3633 expected[2] = 0xCAFED00D; expected[3] = 0xFEEDFACE;
3634 check_StretchDIBits_stretch(hdcDst, dstBuffer, srcBuffer,
3635 0, 0, 2, 2, 0, 0, 2, 2, expected, __LINE__);
3636
3637 /* Tidy up */
3638 SelectObject(hdcDst, oldDst);
3639 DeleteObject(bmpDst);
3641
3642 DeleteDC(hdcScreen);
3643}
3644
3645static void test_GdiAlphaBlend(void)
3646{
3647 HDC hdcNull;
3648 HDC hdcDst;
3649 HBITMAP bmpDst;
3650 BITMAPINFO *bmi;
3651 HDC hdcSrc;
3652 HBITMAP bmpSrc;
3653 HBITMAP oldSrc;
3654 LPVOID bits;
3655 BOOL ret;
3656 BLENDFUNCTION blend;
3657
3658 if (!pGdiAlphaBlend)
3659 {
3660 win_skip("GdiAlphaBlend() is not implemented\n");
3661 return;
3662 }
3663
3664 hdcNull = GetDC(NULL);
3665 hdcDst = CreateCompatibleDC(hdcNull);
3666 bmpDst = CreateCompatibleBitmap(hdcNull, 100, 100);
3667 hdcSrc = CreateCompatibleDC(hdcNull);
3668
3669 bmi = calloc(1, FIELD_OFFSET(BITMAPINFO, bmiColors[3]));
3670 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
3671 bmi->bmiHeader.biHeight = 20;
3672 bmi->bmiHeader.biWidth = 20;
3673 bmi->bmiHeader.biBitCount = 32;
3674 bmi->bmiHeader.biPlanes = 1;
3676 bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3677 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3678
3679 SelectObject(hdcDst, bmpDst);
3680 oldSrc = SelectObject(hdcSrc, bmpSrc);
3681
3682 blend.BlendOp = AC_SRC_OVER;
3683 blend.BlendFlags = 0;
3684 blend.SourceConstantAlpha = 128;
3685 blend.AlphaFormat = 0;
3686
3687 SetLastError(0xdeadbeef);
3688 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3689 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3690
3691 SetLastError(0xdeadbeef);
3692 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend);
3693 ok( !ret, "GdiAlphaBlend succeeded\n" );
3694 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3695
3696 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend);
3697 ok( !ret, "GdiAlphaBlend succeeded\n" );
3698 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 15, 0, 10, 10, blend);
3699 ok( !ret, "GdiAlphaBlend succeeded\n" );
3700 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend);
3701 ok( !ret, "GdiAlphaBlend succeeded\n" );
3702 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 10, 10, -2, 3, blend);
3703 ok( !ret, "GdiAlphaBlend succeeded\n" );
3704
3705 SetWindowOrgEx(hdcSrc, -10, -10, NULL);
3706 SetLastError(0xdeadbeef);
3707 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 10, 10, blend);
3708 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3709 SetLastError(0xdeadbeef);
3710 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 10, 10, blend);
3711 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3713 ScaleWindowExtEx(hdcSrc, 10, 1, 10, 1, NULL);
3714 SetLastError(0xdeadbeef);
3715 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -1, 0, 30, 30, blend);
3716 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3717 SetLastError(0xdeadbeef);
3718 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 30, 30, blend);
3719 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3720
3722 SetViewportExtEx(hdcDst, -1, -1, NULL);
3723 SetLastError(0xdeadbeef);
3724 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, -1, 50, 50, blend);
3725 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3726 SetLastError(0xdeadbeef);
3727 ret = pGdiAlphaBlend(hdcDst, -20, -20, 20, 20, hdcSrc, 0, -1, 50, 50, blend);
3728 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3729 SetLastError(0xdeadbeef);
3730 ret = pGdiAlphaBlend(hdcDst, -20, -20, -20, -20, hdcSrc, 0, -1, 50, 50, blend);
3731 ok( !ret, "GdiAlphaBlend succeeded\n" );
3732 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3733 SetLastError(0xdeadbeef);
3734 ret = pGdiAlphaBlend(hdcDst, -20, 0, -20, 20, hdcSrc, 0, -1, 50, 50, blend);
3735 ok( !ret, "GdiAlphaBlend succeeded\n" );
3736 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3737 SetLastError(0xdeadbeef);
3738 ret = pGdiAlphaBlend(hdcDst, 0, -20, 20, -20, hdcSrc, 0, -1, 50, 50, blend);
3739 ok( !ret, "GdiAlphaBlend succeeded\n" );
3740 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3742
3743 SetViewportExtEx(hdcSrc, -1, -1, NULL);
3744 SetLastError(0xdeadbeef);
3745 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -20, -20, -30, -30, blend);
3746 ok( !ret, "GdiAlphaBlend succeeded\n" );
3747 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3748 SetLastError(0xdeadbeef);
3749 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -20, -20, 30, -30, blend);
3750 ok( !ret, "GdiAlphaBlend succeeded\n" );
3751 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3752 SetLastError(0xdeadbeef);
3753 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -20, -20, -30, 30, blend);
3754 ok( !ret, "GdiAlphaBlend succeeded\n" );
3755 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3756 SetLastError(0xdeadbeef);
3757 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -20, -20, 30, 30, blend);
3758 ok( !ret, "GdiAlphaBlend succeeded\n" );
3759 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3760 SetLastError(0xdeadbeef);
3761 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 20, 20, 30, 30, blend);
3762 ok( !ret, "GdiAlphaBlend succeeded\n" );
3763 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3764 SetLastError(0xdeadbeef);
3765 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, -60, -60, 30, 30, blend);
3766 ok( !ret, "GdiAlphaBlend succeeded\n" );
3767 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3769
3770 SetLastError(0xdeadbeef);
3771 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, NULL, 0, 0, 20, 20, blend);
3772 ok( !ret, "GdiAlphaBlend succeeded\n" );
3773 ok( GetLastError() == 0xdeadbeef, "wrong error %lu\n", GetLastError() );
3774
3775 /* overlapping source and dest not allowed */
3776
3777 SetLastError(0xdeadbeef);
3778 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 19, 19, 20, 20, blend);
3779 ok( !ret, "GdiAlphaBlend succeeded\n" );
3780 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3781
3782 SetLastError(0xdeadbeef);
3783 ret = pGdiAlphaBlend(hdcDst, 20, 20, 20, 20, hdcDst, 1, 1, 20, 20, blend);
3784 ok( !ret, "GdiAlphaBlend succeeded\n" );
3785 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3786
3787 SetLastError(0xdeadbeef);
3788 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 20, 10, 20, 20, blend);
3789 ok( ret, "GdiAlphaBlend succeeded\n" );
3790 SetLastError(0xdeadbeef);
3791 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcDst, 10, 20, 20, 20, blend);
3792 ok( ret, "GdiAlphaBlend succeeded\n" );
3793
3794 /* AC_SRC_ALPHA requires 32-bpp BI_RGB format */
3795
3796 blend.AlphaFormat = AC_SRC_ALPHA;
3797 SetLastError(0xdeadbeef);
3798 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3799 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3800
3802 ((DWORD *)bmi->bmiColors)[0] = 0xff0000;
3803 ((DWORD *)bmi->bmiColors)[1] = 0x00ff00;
3804 ((DWORD *)bmi->bmiColors)[2] = 0x0000ff;
3805 bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3806 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3807 oldSrc = SelectObject(hdcSrc, bmpSrc);
3808 DeleteObject( oldSrc );
3809
3810 SetLastError(0xdeadbeef);
3811 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3812 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
3813
3815 ((DWORD *)bmi->bmiColors)[0] = 0x0000ff;
3816 ((DWORD *)bmi->bmiColors)[1] = 0x00ff00;
3817 ((DWORD *)bmi->bmiColors)[2] = 0xff0000;
3818 bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3819 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3820 oldSrc = SelectObject(hdcSrc, bmpSrc);
3821 DeleteObject( oldSrc );
3822
3823 SetLastError(0xdeadbeef);
3824 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3825 ok( !ret, "GdiAlphaBlend succeeded\n" );
3826 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3827
3828 bmi->bmiHeader.biBitCount = 24;
3830 bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3831 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3832 oldSrc = SelectObject(hdcSrc, bmpSrc);
3833 DeleteObject( oldSrc );
3834
3835 SetLastError(0xdeadbeef);
3836 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3837 ok( !ret, "GdiAlphaBlend succeeded\n" );
3838 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3839
3840 bmi->bmiHeader.biBitCount = 1;
3841 bmpSrc = CreateDIBSection(hdcDst, bmi, DIB_RGB_COLORS, &bits, NULL, 0);
3842 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3843 oldSrc = SelectObject(hdcSrc, bmpSrc);
3844 DeleteObject( oldSrc );
3845
3846 SetLastError(0xdeadbeef);
3847 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3848 ok( !ret, "GdiAlphaBlend succeeded\n" );
3849 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3850
3851 bmpSrc = CreateBitmap( 100, 100, 1, 1, NULL );
3852 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
3853 oldSrc = SelectObject(hdcSrc, bmpSrc);
3854 DeleteObject( oldSrc );
3855
3856 SetLastError(0xdeadbeef);
3857 ret = pGdiAlphaBlend(hdcDst, 0, 0, 20, 20, hdcSrc, 0, 0, 20, 20, blend);
3858 ok( !ret, "GdiAlphaBlend succeeded\n" );
3859 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3860
3863 DeleteObject(bmpSrc);
3864 DeleteObject(bmpDst);
3865
3866 ReleaseDC(NULL, hdcNull);
3867 free(bmi);
3868}
3869
3870static void test_GdiGradientFill(void)
3871{
3872 HDC hdc;
3873 BOOL ret;
3874 HBITMAP bmp;
3875 BITMAPINFO *bmi;
3876 void *bits;
3877 GRADIENT_RECT rect[] = { { 0, 0 }, { 0, 1 }, { 2, 3 } };
3878 GRADIENT_TRIANGLE tri[] = { { 0, 0, 0 }, { 0, 1, 2 }, { 0, 2, 1 }, { 0, 1, 3 } };
3879 TRIVERTEX vt[3] = { { 2, 2, 0xff00, 0x0000, 0x0000, 0x8000 },
3880 { 10, 10, 0x0000, 0xff00, 0x0000, 0x8000 },
3881 { 20, 10, 0x0000, 0x0000, 0xff00, 0xff00 } };
3882
3883 if (!pGdiGradientFill)
3884 {
3885 win_skip( "GdiGradientFill is not implemented\n" );
3886 return;
3887 }
3888
3890 bmi = calloc( 1, FIELD_OFFSET(BITMAPINFO, bmiColors[3]) );
3891 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
3892 bmi->bmiHeader.biHeight = 20;
3893 bmi->bmiHeader.biWidth = 20;
3894 bmi->bmiHeader.biBitCount = 32;
3895 bmi->bmiHeader.biPlanes = 1;
3898 ok( bmp != NULL, "couldn't create bitmap\n" );
3899 SelectObject( hdc, bmp );
3900
3901 SetLastError( 0xdeadbeef );
3902 ret = pGdiGradientFill( hdc, vt, 3, rect, 1, GRADIENT_FILL_RECT_H );
3903 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3904 SetLastError( 0xdeadbeef );
3905 ret = pGdiGradientFill( hdc, vt, 3, rect, 1, 3 );
3906 ok( !ret, "GdiGradientFill succeeded\n" );
3907 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3908 SetLastError( 0xdeadbeef );
3909 ret = pGdiGradientFill( (HDC)0xdead, vt, 3, rect, 1, GRADIENT_FILL_RECT_H );
3910 ok( !ret, "GdiGradientFill succeeded\n" );
3911 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3912 SetLastError( 0xdeadbeef );
3913 ret = pGdiGradientFill( NULL, NULL, 0, rect, 1, GRADIENT_FILL_RECT_H );
3914 ok( !ret, "GdiGradientFill succeeded\n" );
3915 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3916 ret = pGdiGradientFill( hdc, NULL, 0, rect, 1, GRADIENT_FILL_RECT_H );
3917 ok( !ret, "GdiGradientFill succeeded\n" );
3918 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3919 SetLastError( 0xdeadbeef );
3920 ret = pGdiGradientFill( hdc, NULL, 3, rect, 1, GRADIENT_FILL_RECT_H );
3921 ok( !ret, "GdiGradientFill succeeded\n" );
3922 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3923 SetLastError( 0xdeadbeef );
3924 ret = pGdiGradientFill( hdc, vt, 3, NULL, 0, GRADIENT_FILL_RECT_H );
3925 ok( !ret, "GdiGradientFill succeeded\n" );
3926 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3927 SetLastError( 0xdeadbeef );
3928 ret = pGdiGradientFill( hdc, vt, 3, NULL, 1, GRADIENT_FILL_RECT_H );
3929 ok( !ret, "GdiGradientFill succeeded\n" );
3930 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3931 SetLastError( 0xdeadbeef );
3932 ret = pGdiGradientFill( hdc, vt, 3, rect, 0, GRADIENT_FILL_RECT_H );
3933 ok( !ret, "GdiGradientFill succeeded\n" );
3934 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3935 SetLastError( 0xdeadbeef );
3936 ret = pGdiGradientFill( hdc, vt, 3, rect, 3, GRADIENT_FILL_RECT_H );
3937 ok( !ret, "GdiGradientFill succeeded\n" );
3938 ok( GetLastError() == 0xdeadbeef, "wrong error %lu\n", GetLastError() );
3939 rect[2].UpperLeft = rect[2].LowerRight = 1;
3940 SetLastError( 0xdeadbeef );
3941 ret = pGdiGradientFill( hdc, vt, 3, rect, 3, GRADIENT_FILL_RECT_H );
3942 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3943 SetLastError( 0xdeadbeef );
3944 ret = pGdiGradientFill( hdc, vt, 1, rect, 1, GRADIENT_FILL_RECT_H );
3945 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3946 SetLastError( 0xdeadbeef );
3947 ret = pGdiGradientFill( hdc, vt, 1, tri, 0, GRADIENT_FILL_TRIANGLE );
3948 ok( !ret, "GdiGradientFill succeeded\n" );
3949 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %lu\n", GetLastError() );
3950 SetLastError( 0xdeadbeef );
3951 ret = pGdiGradientFill( hdc, vt, 1, tri, 1, GRADIENT_FILL_TRIANGLE );
3952 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3953 SetLastError( 0xdeadbeef );
3954 ret = pGdiGradientFill( hdc, vt, 3, tri, 2, GRADIENT_FILL_TRIANGLE );
3955 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3956 SetLastError( 0xdeadbeef );
3957 ret = pGdiGradientFill( hdc, vt, 3, tri, 3, GRADIENT_FILL_TRIANGLE );
3958 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3959 SetLastError( 0xdeadbeef );
3960 ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
3961 ok( !ret, "GdiGradientFill succeeded\n" );
3962 ok( GetLastError() == 0xdeadbeef, "wrong error %lu\n", GetLastError() );
3963 tri[3].Vertex3 = 1;
3964 SetLastError( 0xdeadbeef );
3965 ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
3966 ok( !ret, "GdiGradientFill succeeded\n" );
3967 ok( GetLastError() == 0xdeadbeef, "wrong error %lu\n", GetLastError() );
3968 tri[3].Vertex3 = 0;
3969 SetLastError( 0xdeadbeef );
3970 ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
3971 ok( !ret, "GdiGradientFill succeeded\n" );
3972 ok( GetLastError() == 0xdeadbeef, "wrong error %lu\n", GetLastError() );
3973 tri[3].Vertex1 = tri[3].Vertex2 = tri[3].Vertex3 = 1;
3974 SetLastError( 0xdeadbeef );
3975 ret = pGdiGradientFill( hdc, vt, 3, tri, 4, GRADIENT_FILL_TRIANGLE );
3976 ok( ret, "GdiGradientFill failed err %lu\n", GetLastError() );
3977
3978 DeleteDC( hdc );
3979 DeleteObject( bmp );
3980 free( bmi );
3981}
3982
3983static void test_clipping(void)
3984{
3985 HBITMAP bmpDst;
3986 HBITMAP bmpSrc;
3987 HRGN hRgn;
3988 LPVOID bits;
3989 BOOL result;
3990
3993
3994 BITMAPINFO bmpinfo={{0}};
3995 bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3996 bmpinfo.bmiHeader.biWidth = 100;
3997 bmpinfo.bmiHeader.biHeight = 100;
3998 bmpinfo.bmiHeader.biPlanes = 1;
4000 bmpinfo.bmiHeader.biCompression = BI_RGB;
4001
4002 bmpDst = CreateDIBSection( hdcDst, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
4003 ok(bmpDst != NULL, "Couldn't create destination bitmap\n");
4004 SelectObject( hdcDst, bmpDst );
4005
4006 bmpSrc = CreateDIBSection( hdcSrc, &bmpinfo, DIB_RGB_COLORS, &bits, NULL, 0 );
4007 ok(bmpSrc != NULL, "Couldn't create source bitmap\n");
4008 SelectObject( hdcSrc, bmpSrc );
4009
4010 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 100, 100, SRCCOPY );
4011 ok(result, "BitBlt failed\n");
4012
4013 hRgn = CreateRectRgn( 0,0,0,0 );
4015
4016 result = BitBlt( hdcDst, 0, 0, 100, 100, hdcSrc, 0, 0, SRCCOPY );
4017 ok(result, "BitBlt failed\n");
4018
4019 DeleteObject( bmpDst );
4020 DeleteObject( bmpSrc );
4021 DeleteObject( hRgn );
4022 DeleteDC( hdcDst );
4023 DeleteDC( hdcSrc );
4024}
4025
4026static void test_32bit_ddb(void)
4027{
4028 char buffer[sizeof(BITMAPINFOHEADER) + sizeof(DWORD)];
4029 BITMAPINFO *biDst = (BITMAPINFO *)buffer;
4030 HBITMAP bmpSrc, bmpDst;
4031 HBITMAP oldSrc, oldDst;
4032 HDC hdcSrc, hdcDst, hdcScreen;
4033 HBRUSH brush;
4034 DWORD *dstBuffer, *data;
4035 DWORD colorSrc = 0x40201008;
4036
4037 memset(biDst, 0, sizeof(BITMAPINFOHEADER));
4038 biDst->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
4039 biDst->bmiHeader.biWidth = 1;
4040 biDst->bmiHeader.biHeight = -1;
4041 biDst->bmiHeader.biPlanes = 1;
4042 biDst->bmiHeader.biBitCount = 32;
4044
4045 hdcScreen = CreateCompatibleDC(0);
4046 if(GetDeviceCaps(hdcScreen, BITSPIXEL) != 32)
4047 {
4048 DeleteDC(hdcScreen);
4049 trace("Skipping 32-bit DDB test\n");
4050 return;
4051 }
4052
4053 hdcSrc = CreateCompatibleDC(hdcScreen);
4054 bmpSrc = CreateBitmap(1, 1, 1, 32, &colorSrc);
4055 oldSrc = SelectObject(hdcSrc, bmpSrc);
4056
4057 hdcDst = CreateCompatibleDC(hdcScreen);
4058 bmpDst = CreateDIBSection(hdcDst, biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
4059 oldDst = SelectObject(hdcDst, bmpDst);
4060
4061 StretchBlt(hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, SRCCOPY);
4062 ok(dstBuffer[0] == colorSrc, "Expected color=%lx, received color=%lx\n", colorSrc, dstBuffer[0]);
4063
4064 if (pGdiAlphaBlend)
4065 {
4066 BLENDFUNCTION blend;
4067 BOOL ret;
4068
4069 blend.BlendOp = AC_SRC_OVER;
4070 blend.BlendFlags = 0;
4071 blend.SourceConstantAlpha = 128;
4072 blend.AlphaFormat = 0;
4073 dstBuffer[0] = 0x80808080;
4074 ret = pGdiAlphaBlend( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, blend );
4075 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
4076 ok(dstBuffer[0] == 0x60504844, "wrong color %lx\n", dstBuffer[0]);
4077 blend.AlphaFormat = AC_SRC_ALPHA;
4078 dstBuffer[0] = 0x80808080;
4079 ret = pGdiAlphaBlend( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, 1, 1, blend );
4080 ok( ret, "GdiAlphaBlend failed err %lu\n", GetLastError() );
4081 ok(dstBuffer[0] == 0x90807874, "wrong color %lx\n", dstBuffer[0]);
4082 }
4083
4084 data = (DWORD *)biDst->bmiColors;
4085 data[0] = 0x20304050;
4086 brush = CreateDIBPatternBrushPt( biDst, DIB_RGB_COLORS );
4087 ok( brush != 0, "brush creation failed\n" );
4088 SelectObject( hdcSrc, brush );
4089 PatBlt( hdcSrc, 0, 0, 1, 1, PATCOPY );
4090 BitBlt( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, SRCCOPY );
4091 ok(dstBuffer[0] == data[0], "Expected color=%lx, received color=%lx\n", data[0], dstBuffer[0]);
4093 DeleteObject( brush );
4094
4095 biDst->bmiHeader.biBitCount = 24;
4096 brush = CreateDIBPatternBrushPt( biDst, DIB_RGB_COLORS );
4097 ok( brush != 0, "brush creation failed\n" );
4098 SelectObject( hdcSrc, brush );
4099 PatBlt( hdcSrc, 0, 0, 1, 1, PATCOPY );
4100 BitBlt( hdcDst, 0, 0, 1, 1, hdcSrc, 0, 0, SRCCOPY );
4101 ok(dstBuffer[0] == (data[0] & ~0xff000000),
4102 "Expected color=%lx, received color=%lx\n", data[0] & 0xff000000, dstBuffer[0]);
4104 DeleteObject( brush );
4105
4106 /* Tidy up */
4107 SelectObject(hdcDst, oldDst);
4108 DeleteObject(bmpDst);
4110
4111 SelectObject(hdcSrc, oldSrc);
4112 DeleteObject(bmpSrc);
4114
4115 DeleteDC(hdcScreen);
4116}
4117
4118/*
4119 * Used by test_GetDIBits_top_down to create the bitmap to test against.
4120 */
4121static void setup_picture(char *picture, int bpp)
4122{
4123 int i;
4124
4125 switch(bpp)
4126 {
4127 case 16:
4128 case 32:
4129 /*Set the first byte in each pixel to the index of that pixel.*/
4130 for (i = 0; i < 4; i++)
4131 picture[i * (bpp / 8)] = i;
4132 break;
4133 case 24:
4134 picture[0] = 0;
4135 picture[3] = 1;
4136 /*Each scanline in a bitmap must be a multiple of 4 bytes long.*/
4137 picture[8] = 2;
4138 picture[11] = 3;
4139 break;
4140 }
4141}
4142
4144{
4145 BITMAPINFO bi;
4146 HBITMAP bmptb, bmpbt;
4147 HDC hdc;
4148 int pictureOut[4];
4149 int *picture;
4150 int statusCode;
4151
4152 memset( &bi, 0, sizeof(bi) );
4153 bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
4154 bi.bmiHeader.biWidth=2;
4155 bi.bmiHeader.biHeight=2;
4156 bi.bmiHeader.biPlanes=1;
4159
4160 /*Get the device context for the screen.*/
4161 hdc = GetDC(NULL);
4162 ok(hdc != NULL, "Could not get a handle to a device context.\n");
4163
4164 /*Create the bottom to top image (image's bottom scan line is at the top in memory).*/
4165 bmpbt = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
4166 ok(bmpbt != NULL, "Could not create a DIB section.\n");
4167 /*Now that we have a pointer to the pixels, we write to them.*/
4168 setup_picture((char*)picture, bpp);
4169 /*Create the top to bottom image (images' bottom scan line is at the bottom in memory).*/
4170 bi.bmiHeader.biHeight=-2; /*We specify that we want a top to bottom image by specifying a negative height.*/
4171 bmptb = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&picture, NULL, 0);
4172 ok(bmptb != NULL, "Could not create a DIB section.\n");
4173 /*Write to this top to bottom bitmap.*/
4174 setup_picture((char*)picture, bpp);
4175
4176 bi.bmiHeader.biWidth = 1;
4177
4178 bi.bmiHeader.biHeight = 2;
4179 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
4180 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4181 /*Check the first byte of the pixel.*/
4182 ok((char)pictureOut[0] == 0, "Bottom-up -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
4183 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
4184 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4185 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
4186 /*Check second scanline.*/
4187 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
4188 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4189 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
4190 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
4191 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4192 ok((char)pictureOut[0] == 2, "Bottom-up -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
4193 /*Check both scanlines.*/
4194 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
4195 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4196 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
4197 ok((char)pictureOut[1] == 0, "Top-down -> bottom-up: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
4198 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
4199 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4200 ok((char)pictureOut[0] == 0, "Bottom up -> bottom-up: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
4201 ok((char)pictureOut[1] == 2, "Bottom up -> bottom-up: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
4202
4203 /*Make destination bitmap top-down.*/
4204 bi.bmiHeader.biHeight = -2;
4205 statusCode = GetDIBits(hdc, bmpbt, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
4206 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4207 ok((char)pictureOut[0] == 0, "Bottom-up -> top-down: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
4208 statusCode = GetDIBits(hdc, bmptb, 0, 1, pictureOut, &bi, DIB_RGB_COLORS);
4209 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4210 ok((char)pictureOut[0] == 2, "Top-down -> top-down: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
4211 /*Check second scanline.*/
4212 statusCode = GetDIBits(hdc, bmptb, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
4213 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4214 ok((char)pictureOut[0] == 0, "Top-down -> bottom-up: first pixel should be 0 but was %d.\n", (char)pictureOut[0]);
4215 statusCode = GetDIBits(hdc, bmpbt, 1, 1, pictureOut, &bi, DIB_RGB_COLORS);
4216 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4217 ok((char)pictureOut[0] == 2, "Top-down -> bottom-up: first pixel should be 2 but was %d.\n", (char)pictureOut[0]);
4218 /*Check both scanlines.*/
4219 statusCode = GetDIBits(hdc, bmptb, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
4220 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4221 ok((char)pictureOut[0] == 0, "Top-down -> top-down: first scanline should be 0 but was %d.\n", (char)pictureOut[0]);
4222 ok((char)pictureOut[1] == 2, "Top-down -> top-down: second scanline should be 2 but was %d.\n", (char)pictureOut[0]);
4223 statusCode = GetDIBits(hdc, bmpbt, 0, 2, pictureOut, &bi, DIB_RGB_COLORS);
4224 ok(statusCode, "Failed to call GetDIBits. Status code: %d.\n", statusCode);
4225 ok((char)pictureOut[0] == 2, "Bottom up -> top-down: first scanline should be 2 but was %d.\n", (char)pictureOut[0]);
4226 ok((char)pictureOut[1] == 0, "Bottom up -> top-down: second scanline should be 0 but was %d.\n", (char)pictureOut[0]);
4227
4228 DeleteObject(bmpbt);
4229 DeleteObject(bmptb);
4230}
4231
4232static void test_GetSetDIBits_rtl(void)
4233{
4234 HDC hdc, hdc_mem;
4235 HBITMAP bitmap, orig_bitmap;
4237 int ret;
4238 DWORD bits_1[8 * 8], bits_2[8 * 8];
4239
4240 hdc = GetDC( NULL );
4241 hdc_mem = CreateCompatibleDC( hdc );
4242 SetLayout( hdc_mem, LAYOUT_LTR );
4243
4245 orig_bitmap = SelectObject( hdc_mem, bitmap );
4246 SetPixel( hdc_mem, 0, 0, RGB(0xff, 0, 0) );
4247 SelectObject( hdc_mem, orig_bitmap );
4248
4249 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
4250 info.bmiHeader.biWidth = 8;
4251 info.bmiHeader.biHeight = 8;
4252 info.bmiHeader.biPlanes = 1;
4253 info.bmiHeader.biBitCount = 32;
4254 info.bmiHeader.biCompression = BI_RGB;
4255
4256 /* First show that GetDIBits ignores the layout mode. */
4257
4258 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
4259 ok(ret == 8, "got %d\n", ret);
4260 ok(bits_1[56] == 0xff0000, "got %08lx\n", bits_1[56]); /* check we have a red pixel */
4261
4262 SetLayout( hdc_mem, LAYOUT_RTL );
4263
4264 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
4265 ok(ret == 8, "got %d\n", ret);
4266
4267 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
4268
4269 /* Now to show that SetDIBits also ignores the mode, we perform a SetDIBits
4270 followed by a GetDIBits and show that the bits remain unchanged. */
4271
4272 SetLayout( hdc_mem, LAYOUT_LTR );
4273
4274 ret = SetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
4275 ok(ret == 8, "got %d\n", ret);
4276 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
4277 ok(ret == 8, "got %d\n", ret);
4278 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
4279
4280 SetLayout( hdc_mem, LAYOUT_RTL );
4281
4282 ret = SetDIBits( hdc_mem, bitmap, 0, 8, bits_1, &info, DIB_RGB_COLORS );
4283 ok(ret == 8, "got %d\n", ret);
4284 ret = GetDIBits( hdc_mem, bitmap, 0, 8, bits_2, &info, DIB_RGB_COLORS );
4285 ok(ret == 8, "got %d\n", ret);
4286 ok(!memcmp( bits_1, bits_2, sizeof(bits_1) ), "bits differ\n");
4287
4289 DeleteDC( hdc_mem );
4290 ReleaseDC( NULL, hdc );
4291}
4292
4294{
4296 DWORD *dib_bits;
4297 HDC hdc = GetDC( NULL );
4298 HBITMAP dib;
4299 DWORD data[128], inverted_bits[64];
4300 int i, ret;
4301
4302 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4303
4304 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4305 info->bmiHeader.biWidth = 8;
4306 info->bmiHeader.biHeight = 8;
4307 info->bmiHeader.biPlanes = 1;
4308 info->bmiHeader.biBitCount = 32;
4309 info->bmiHeader.biCompression = BI_RGB;
4310
4311 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4312
4313 for (i = 0; i < 64; i++)
4314 {
4315 dib_bits[i] = i;
4316 inverted_bits[56 - (i & ~7) + (i & 7)] = i;
4317 }
4318
4319 /* b-u -> b-u */
4320
4321 memset( data, 0xaa, sizeof(data) );
4322
4323 ret = GetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4324 ok( ret == 8, "got %d\n", ret );
4325 ok( !memcmp( data, dib_bits, 64 * 4 ), "bits differ\n");
4326 memset( data, 0xaa, sizeof(data) );
4327
4328 ret = GetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4329 ok( ret == 5, "got %d\n", ret );
4330 ok( !memcmp( data, dib_bits + 8, 40 * 4 ), "bits differ\n");
4331 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4332 memset( data, 0xaa, sizeof(data) );
4333
4334 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4335 ok( ret == 7, "got %d\n", ret );
4336 ok( !memcmp( data, dib_bits + 8, 56 * 4 ), "bits differ\n");
4337 for (i = 56; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4338 memset( data, 0xaa, sizeof(data) );
4339
4340 ret = GetDIBits( hdc, dib, 9, 12, data, info, DIB_RGB_COLORS );
4341 ok( ret == 1, "got %d\n", ret );
4342 for (i = 0; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4343 memset( data, 0xaa, sizeof(data) );
4344
4345 info->bmiHeader.biHeight = 16;
4346 info->bmiHeader.biSizeImage = 0;
4347 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4348 ok( ret == 5, "got %d\n", ret );
4349 ok( info->bmiHeader.biSizeImage == 128 * 4, "got %ld\n", info->bmiHeader.biSizeImage );
4350 for (i = 0; i < 56; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4351 ok( !memcmp( data + 56, dib_bits, 40 * 4 ), "bits differ\n");
4352 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4353 memset( data, 0xaa, sizeof(data) );
4354
4355 ret = GetDIBits( hdc, dib, 2, 12, data, info, DIB_RGB_COLORS );
4356 ok( ret == 6, "got %d\n", ret );
4357 for (i = 0; i < 48; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4358 ok( !memcmp( data + 48, dib_bits, 48 * 4 ), "bits differ\n");
4359 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4360 memset( data, 0xaa, sizeof(data) );
4361
4362 ret = GetDIBits( hdc, dib, 2, 3, data, info, DIB_RGB_COLORS );
4363 ok( ret == 0, "got %d\n", ret );
4364 for (i = 0; i < 24; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4365 for (i = 24; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4366 memset( data, 0xaa, sizeof(data) );
4367
4368 info->bmiHeader.biHeight = 5;
4369 ret = GetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4370 ok( ret == 2, "got %d\n", ret );
4371 ok( !memcmp( data, dib_bits + 32, 16 * 4 ), "bits differ\n");
4372 for (i = 16; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4373 memset( data, 0xaa, sizeof(data) );
4374
4375 /* b-u -> t-d */
4376
4377 info->bmiHeader.biHeight = -8;
4378 ret = GetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4379 ok( ret == 8, "got %d\n", ret );
4380 ok( !memcmp( data, inverted_bits, 64 * 4 ), "bits differ\n");
4381 memset( data, 0xaa, sizeof(data) );
4382
4383 ret = GetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4384 ok( ret == 5, "got %d\n", ret );
4385 ok( !memcmp( data, inverted_bits + 16, 40 * 4 ), "bits differ\n");
4386 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4387 memset( data, 0xaa, sizeof(data) );
4388
4389 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4390 ok( ret == 7, "got %d\n", ret );
4391 ok( !memcmp( data, inverted_bits, 56 * 4 ), "bits differ\n");
4392 for (i = 56; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4393 memset( data, 0xaa, sizeof(data) );
4394
4395 ret = GetDIBits( hdc, dib, 4, 12, data, info, DIB_RGB_COLORS );
4396 ok( ret == 4, "got %d\n", ret );
4397 ok( !memcmp( data, inverted_bits, 32 * 4 ), "bits differ\n");
4398 for (i = 32; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4399 memset( data, 0xaa, sizeof(data) );
4400
4401 ret = GetDIBits( hdc, dib, 3, 12, data, info, DIB_RGB_COLORS );
4402 ok( ret == 5, "got %d\n", ret );
4403 ok( !memcmp( data, inverted_bits, 40 * 4 ), "bits differ\n");
4404 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4405 memset( data, 0xaa, sizeof(data) );
4406
4407 ret = GetDIBits( hdc, dib, 3, 13, data, info, DIB_RGB_COLORS );
4408 ok( ret == 5, "got %d\n", ret );
4409 ok( !memcmp( data, inverted_bits, 40 * 4 ), "bits differ\n");
4410 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4411 memset( data, 0xaa, sizeof(data) );
4412
4413 info->bmiHeader.biHeight = -16;
4414 ret = GetDIBits( hdc, dib, 0, 16, data, info, DIB_RGB_COLORS );
4415 ok( ret == 8, "got %d\n", ret );
4416 ok( !memcmp( data, inverted_bits, 64 * 4 ), "bits differ\n");
4417 for (i = 64; i < 128; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4418 memset( data, 0xaa, sizeof(data) );
4419
4420 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4421 ok( ret == 5, "got %d\n", ret );
4422 ok( !memcmp( data, inverted_bits + 24, 40 * 4 ), "bits differ\n");
4423 for (i = 40; i < 96; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4424 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4425 memset( data, 0xaa, sizeof(data) );
4426
4427 ret = GetDIBits( hdc, dib, 4, 12, data, info, DIB_RGB_COLORS );
4428 ok( ret == 8, "got %d\n", ret );
4429 ok( !memcmp( data, inverted_bits, 64 * 4 ), "bits differ\n");
4430 for (i = 64; i < 96; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4431 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4432 memset( data, 0xaa, sizeof(data) );
4433
4434 ret = GetDIBits( hdc, dib, 5, 12, data, info, DIB_RGB_COLORS );
4435 ok( ret == 8, "got %d\n", ret );
4436 ok( !memcmp( data, inverted_bits, 64 * 4 ), "bits differ\n");
4437 for (i = 64; i < 88; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4438 for (i = 88; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4439 memset( data, 0xaa, sizeof(data) );
4440
4441 ret = GetDIBits( hdc, dib, 9, 12, data, info, DIB_RGB_COLORS );
4442 ok( ret == 7, "got %d\n", ret );
4443 ok( !memcmp( data, inverted_bits, 56 * 4 ), "bits differ\n");
4444 for (i = 56; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4445 memset( data, 0xaa, sizeof(data) );
4446
4447 ret = GetDIBits( hdc, dib, 18, 12, data, info, DIB_RGB_COLORS );
4448 ok( ret == 1, "got %d\n", ret );
4449 for (i = 0; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4450 memset( data, 0xaa, sizeof(data) );
4451
4452 info->bmiHeader.biHeight = -5;
4453 ret = GetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4454 ok( ret == 2, "got %d\n", ret );
4455 ok( !memcmp( data, inverted_bits + 16, 16 * 4 ), "bits differ\n");
4456 for (i = 16; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4457 memset( data, 0xaa, sizeof(data) );
4458
4459 DeleteObject( dib );
4460
4461 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4462 info->bmiHeader.biWidth = 8;
4463 info->bmiHeader.biHeight = -8;
4464 info->bmiHeader.biPlanes = 1;
4465 info->bmiHeader.biBitCount = 32;
4466 info->bmiHeader.biCompression = BI_RGB;
4467
4468 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4469
4470 for (i = 0; i < 64; i++) dib_bits[i] = i;
4471
4472 /* t-d -> t-d */
4473
4474 info->bmiHeader.biHeight = -8;
4475 ret = GetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4476 ok( ret == 8, "got %d\n", ret );
4477 ok( !memcmp( data, dib_bits, 64 * 4 ), "bits differ\n");
4478 memset( data, 0xaa, sizeof(data) );
4479
4480 ret = GetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4481 ok( ret == 5, "got %d\n", ret );
4482 ok( !memcmp( data, dib_bits + 16, 40 * 4 ), "bits differ\n");
4483 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4484 memset( data, 0xaa, sizeof(data) );
4485
4486 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4487 ok( ret == 7, "got %d\n", ret );
4488 ok( !memcmp( data, dib_bits, 56 * 4 ), "bits differ\n");
4489 for (i = 56; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4490 memset( data, 0xaa, sizeof(data) );
4491
4492 ret = GetDIBits( hdc, dib, 4, 12, data, info, DIB_RGB_COLORS );
4493 ok( ret == 4, "got %d\n", ret );
4494 ok( !memcmp( data, dib_bits, 32 * 4 ), "bits differ\n");
4495 for (i = 32; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4496 memset( data, 0xaa, sizeof(data) );
4497
4498 ret = GetDIBits( hdc, dib, 3, 12, data, info, DIB_RGB_COLORS );
4499 ok( ret == 5, "got %d\n", ret );
4500 ok( !memcmp( data, dib_bits, 40 * 4 ), "bits differ\n");
4501 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4502 memset( data, 0xaa, sizeof(data) );
4503
4504 ret = GetDIBits( hdc, dib, 3, 13, data, info, DIB_RGB_COLORS );
4505 ok( ret == 5, "got %d\n", ret );
4506 ok( !memcmp( data, dib_bits, 40 * 4 ), "bits differ\n");
4507 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4508 memset( data, 0xaa, sizeof(data) );
4509
4510 info->bmiHeader.biHeight = -16;
4511 ret = GetDIBits( hdc, dib, 0, 16, data, info, DIB_RGB_COLORS );
4512 ok( ret == 8, "got %d\n", ret );
4513 ok( !memcmp( data, dib_bits, 64 * 4 ), "bits differ\n");
4514 for (i = 64; i < 128; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4515 memset( data, 0xaa, sizeof(data) );
4516
4517 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4518 ok( ret == 5, "got %d\n", ret );
4519 ok( !memcmp( data, dib_bits + 24, 40 * 4 ), "bits differ\n");
4520 for (i = 40; i < 96; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4521 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4522 memset( data, 0xaa, sizeof(data) );
4523
4524 ret = GetDIBits( hdc, dib, 4, 12, data, info, DIB_RGB_COLORS );
4525 ok( ret == 8, "got %d\n", ret );
4526 ok( !memcmp( data, dib_bits, 64 * 4 ), "bits differ\n");
4527 for (i = 64; i < 96; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4528 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4529 memset( data, 0xaa, sizeof(data) );
4530
4531 ret = GetDIBits( hdc, dib, 5, 12, data, info, DIB_RGB_COLORS );
4532 ok( ret == 8, "got %d\n", ret );
4533 ok( !memcmp( data, dib_bits, 64 * 4 ), "bits differ\n");
4534 for (i = 64; i < 88; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4535 for (i = 88; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4536 memset( data, 0xaa, sizeof(data) );
4537
4538 ret = GetDIBits( hdc, dib, 9, 12, data, info, DIB_RGB_COLORS );
4539 ok( ret == 7, "got %d\n", ret );
4540 ok( !memcmp( data, dib_bits, 56 * 4 ), "bits differ\n");
4541 for (i = 56; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4542 memset( data, 0xaa, sizeof(data) );
4543
4544 info->bmiHeader.biHeight = -5;
4545 ret = GetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4546 ok( ret == 2, "got %d\n", ret );
4547 ok( !memcmp( data, dib_bits + 16, 16 * 4 ), "bits differ\n");
4548 for (i = 16; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4549 memset( data, 0xaa, sizeof(data) );
4550
4551
4552 /* t-d -> b-u */
4553
4554 info->bmiHeader.biHeight = 8;
4555
4556 ret = GetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4557 ok( ret == 8, "got %d\n", ret );
4558 ok( !memcmp( data, inverted_bits, 64 * 4 ), "bits differ\n");
4559 memset( data, 0xaa, sizeof(data) );
4560
4561 ret = GetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4562 ok( ret == 5, "got %d\n", ret );
4563 ok( !memcmp( data, inverted_bits + 8, 40 * 4 ), "bits differ\n");
4564 for (i = 40; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4565 memset( data, 0xaa, sizeof(data) );
4566
4567 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4568 ok( ret == 7, "got %d\n", ret );
4569 ok( !memcmp( data, inverted_bits + 8, 56 * 4 ), "bits differ\n");
4570 for (i = 56; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4571 memset( data, 0xaa, sizeof(data) );
4572
4573 ret = GetDIBits( hdc, dib, 9, 12, data, info, DIB_RGB_COLORS );
4574 ok( ret == 1, "got %d\n", ret );
4575 for (i = 0; i < 64; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4576 memset( data, 0xaa, sizeof(data) );
4577
4578 info->bmiHeader.biHeight = 16;
4579 ret = GetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4580 ok( ret == 5, "got %d\n", ret );
4581 for (i = 0; i < 56; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4582 ok( !memcmp( data + 56, inverted_bits, 40 * 4 ), "bits differ\n");
4583 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4584 memset( data, 0xaa, sizeof(data) );
4585
4586 ret = GetDIBits( hdc, dib, 2, 12, data, info, DIB_RGB_COLORS );
4587 ok( ret == 6, "got %d\n", ret );
4588 for (i = 0; i < 48; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4589 ok( !memcmp( data + 48, inverted_bits, 48 * 4 ), "bits differ\n");
4590 for (i = 96; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4591 memset( data, 0xaa, sizeof(data) );
4592
4593 ret = GetDIBits( hdc, dib, 2, 3, data, info, DIB_RGB_COLORS );
4594 ok( ret == 0, "got %d\n", ret );
4595 for (i = 0; i < 24; i++) ok( data[i] == 0, "%d: got %08lx\n", i, data[i] );
4596 for (i = 24; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4597 memset( data, 0xaa, sizeof(data) );
4598
4599 info->bmiHeader.biHeight = 5;
4600 ret = GetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4601 ok( ret == 2, "got %d\n", ret );
4602 ok( !memcmp( data, inverted_bits + 32, 16 * 4 ), "bits differ\n");
4603 for (i = 16; i < 128; i++) ok( data[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, data[i] );
4604
4605 DeleteObject( dib );
4606
4607 ReleaseDC( NULL, hdc );
4608 free( info );
4609}
4610
4611
4612static void test_SetDIBits(void)
4613{
4614 char palbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
4615 LOGPALETTE *pal = (LOGPALETTE *)palbuf;
4616 PALETTEENTRY *palent = pal->palPalEntry;
4617 HPALETTE palette;
4619 DWORD *dib_bits;
4620 HDC hdc = GetDC( NULL );
4621 DWORD data[128], inverted_data[128];
4622 HBITMAP dib;
4623 int i, ret;
4624
4625 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4626
4627 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4628 info->bmiHeader.biWidth = 8;
4629 info->bmiHeader.biHeight = 8;
4630 info->bmiHeader.biPlanes = 1;
4631 info->bmiHeader.biBitCount = 32;
4632 info->bmiHeader.biCompression = BI_RGB;
4633
4634 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4635 memset( dib_bits, 0xaa, 64 * 4 );
4636
4637 for (i = 0; i < 128; i++)
4638 {
4639 data[i] = i;
4640 inverted_data[120 - (i & ~7) + (i & 7)] = i;
4641 }
4642
4643 /* b-u -> b-u */
4644
4645 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4646 ok( ret == 8, "got %d\n", ret );
4647 ok( !memcmp( dib_bits, data, 64 * 4 ), "bits differ\n");
4648 memset( dib_bits, 0xaa, 64 * 4 );
4649
4650 ret = SetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4651 ok( ret == 5, "got %d\n", ret );
4652 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4653 ok( !memcmp( dib_bits + 8, data, 40 * 4 ), "bits differ\n");
4654 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4655 memset( dib_bits, 0xaa, 64 * 4 );
4656
4657 /* top of dst is aligned with startscans down for the top of the src.
4658 Then starting from the bottom of src, lines rows are copied across. */
4659
4660 info->bmiHeader.biHeight = 16;
4661 ret = SetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4662 ok( ret == 12, "got %d\n", ret );
4663 ok( !memcmp( dib_bits, data + 56, 40 * 4 ), "bits differ\n");
4664 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4665 memset( dib_bits, 0xaa, 64 * 4 );
4666
4667 info->bmiHeader.biHeight = 5;
4668 ret = SetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4669 ok( ret == 2, "got %d\n", ret );
4670 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4671 ok( !memcmp( dib_bits + 32, data, 16 * 4 ), "bits differ\n");
4672 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4673 memset( dib_bits, 0xaa, 64 * 4 );
4674
4675 /* t-d -> b-u */
4676 info->bmiHeader.biHeight = -8;
4677 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4678 ok( ret == 8, "got %d\n", ret );
4679 ok( !memcmp( dib_bits, inverted_data + 64, 64 * 4 ), "bits differ\n");
4680 memset( dib_bits, 0xaa, 64 * 4 );
4681
4682 /* top of dst now lines up with -(abs(src_h) - startscan - lines) and
4683 we copy lines rows from the top of the src */
4684
4685 ret = SetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4686 ok( ret == 5, "got %d\n", ret );
4687 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4688 ok( !memcmp( dib_bits + 8, inverted_data + 88, 40 * 4 ), "bits differ\n");
4689 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4690 memset( dib_bits, 0xaa, 64 * 4 );
4691
4692 info->bmiHeader.biHeight = -16;
4693 ret = SetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4694 ok( ret == 12, "got %d\n", ret );
4695 ok( !memcmp( dib_bits, inverted_data + 88, 40 * 4 ), "bits differ\n");
4696 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4697 memset( dib_bits, 0xaa, 64 * 4 );
4698
4699 ret = SetDIBits( hdc, dib, 4, 12, data, info, DIB_RGB_COLORS );
4700 ok( ret == 12, "got %d\n", ret );
4701 ok( !memcmp( dib_bits, inverted_data + 64, 64 * 4 ), "bits differ\n");
4702 memset( dib_bits, 0xaa, 64 * 4 );
4703
4704 ret = SetDIBits( hdc, dib, 5, 12, data, info, DIB_RGB_COLORS );
4705 ok( ret == 12, "got %d\n", ret );
4706 ok( !memcmp( dib_bits, inverted_data + 56, 64 * 4 ), "bits differ\n");
4707 memset( dib_bits, 0xaa, 64 * 4 );
4708
4709 info->bmiHeader.biHeight = -5;
4710 ret = SetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4711 ok( ret == 2, "got %d\n", ret );
4712 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4713 ok( !memcmp( dib_bits + 32, inverted_data + 112, 16 * 4 ), "bits differ\n");
4714 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4715 memset( dib_bits, 0xaa, 64 * 4 );
4716
4717 DeleteObject( dib );
4718
4719 info->bmiHeader.biHeight = -8;
4720
4721 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4722 memset( dib_bits, 0xaa, 16 * 16 * 4 );
4723
4724 /* t-d -> t-d */
4725
4726 /* like the t-d -> b-u case. */
4727
4728 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4729 ok( ret == 8, "got %d\n", ret );
4730 ok( !memcmp( dib_bits, data, 64 * 4 ), "bits differ\n");
4731 memset( dib_bits, 0xaa, 64 * 4 );
4732
4733 ret = SetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4734 ok( ret == 5, "got %d\n", ret );
4735 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4736 ok( !memcmp( dib_bits + 16, data, 40 * 4 ), "bits differ\n");
4737 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4738 memset( dib_bits, 0xaa, 64 * 4 );
4739
4740 info->bmiHeader.biHeight = -16;
4741 ret = SetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4742 ok( ret == 12, "got %d\n", ret );
4743 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4744 ok( !memcmp( dib_bits + 24, data, 40 * 4 ), "bits differ\n");
4745 memset( dib_bits, 0xaa, 64 * 4 );
4746
4747 info->bmiHeader.biHeight = -5;
4748 ret = SetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4749 ok( ret == 2, "got %d\n", ret );
4750 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4751 ok( !memcmp( dib_bits + 16, data, 16 * 4 ), "bits differ\n");
4752 for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4753 memset( dib_bits, 0xaa, 64 * 4 );
4754
4755 /* b-u -> t-d */
4756 /* like the b-u -> b-u case */
4757
4758 info->bmiHeader.biHeight = 8;
4759 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4760 ok( ret == 8, "got %d\n", ret );
4761 ok( !memcmp( dib_bits, inverted_data + 64, 64 * 4 ), "bits differ\n");
4762 memset( dib_bits, 0xaa, 64 * 4 );
4763
4764 ret = SetDIBits( hdc, dib, 1, 5, data, info, DIB_RGB_COLORS );
4765 ok( ret == 5, "got %d\n", ret );
4766 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4767 ok( !memcmp( dib_bits + 16, inverted_data + 88, 40 * 4 ), "bits differ\n");
4768 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4769 memset( dib_bits, 0xaa, 64 * 4 );
4770
4771 info->bmiHeader.biHeight = 16;
4772 ret = SetDIBits( hdc, dib, 1, 12, data, info, DIB_RGB_COLORS );
4773 ok( ret == 12, "got %d\n", ret );
4774 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4775 ok( !memcmp( dib_bits + 24, inverted_data + 32, 40 * 4 ), "bits differ\n");
4776 memset( dib_bits, 0xaa, 64 * 4 );
4777
4778 info->bmiHeader.biHeight = 5;
4779 ret = SetDIBits( hdc, dib, 1, 2, data, info, DIB_RGB_COLORS );
4780 ok( ret == 2, "got %d\n", ret );
4781 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4782 ok( !memcmp( dib_bits + 16, inverted_data + 112, 16 * 4 ), "bits differ\n");
4783 for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4784 memset( dib_bits, 0xaa, 64 * 4 );
4785
4786 /* handling of partial color table */
4787
4788 info->bmiHeader.biHeight = -8;
4789 info->bmiHeader.biBitCount = 8;
4790 info->bmiHeader.biClrUsed = 137;
4791 for (i = 0; i < 256; i++)
4792 {
4793 info->bmiColors[i].rgbRed = 255 - i;
4794 info->bmiColors[i].rgbGreen = i * 2;
4795 info->bmiColors[i].rgbBlue = i;
4796 info->bmiColors[i].rgbReserved = 0;
4797 }
4798 for (i = 0; i < 64; i++) ((BYTE *)data)[i] = i * 4 + 1;
4799 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_RGB_COLORS );
4800 ok( ret == 8, "got %d\n", ret );
4801 for (i = 0; i < 64; i++)
4802 {
4803 int idx = i * 4 + 1;
4804 DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 : (info->bmiColors[idx].rgbRed << 16 |
4805 info->bmiColors[idx].rgbGreen << 8 |
4806 info->bmiColors[idx].rgbBlue);
4807 ok( dib_bits[i] == expect, "%d: got %08lx instead of %08lx\n", i, dib_bits[i], expect );
4808 }
4809 memset( dib_bits, 0xaa, 64 * 4 );
4810
4811 /* handling of DIB_PAL_COLORS */
4812
4813 pal->palVersion = 0x300;
4814 pal->palNumEntries = 137;
4815 info->bmiHeader.biClrUsed = 221;
4816 for (i = 0; i < 256; i++)
4817 {
4818 palent[i].peRed = i * 2;
4819 palent[i].peGreen = 255 - i;
4820 palent[i].peBlue = i;
4821 }
4822 palette = CreatePalette( pal );
4823 ok( palette != 0, "palette creation failed\n" );
4825 for (i = 0; i < 256; i++) ((WORD *)info->bmiColors)[i] = 255 - i;
4826 ret = SetDIBits( hdc, dib, 0, 8, data, info, DIB_PAL_COLORS );
4827 ok( ret == 8, "got %d\n", ret );
4828 for (i = 0; i < 64; i++)
4829 {
4830 int idx = i * 4 + 1;
4831 int ent = (255 - idx) % pal->palNumEntries;
4832 DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 :
4833 (palent[ent].peRed << 16 | palent[ent].peGreen << 8 | palent[ent].peBlue);
4834 ok( dib_bits[i] == expect || broken(dib_bits[i] == 0), /* various Windows versions get some values wrong */
4835 "%d: got %08lx instead of %08lx\n", i, dib_bits[i], expect );
4836 }
4837 memset( dib_bits, 0xaa, 64 * 4 );
4838
4839 ReleaseDC( NULL, hdc );
4840 DeleteObject( dib );
4842 free( info );
4843}
4844
4845static void test_SetDIBits_RLE4(void)
4846{
4848 DWORD *dib_bits;
4849 HDC hdc = GetDC( NULL );
4850 BYTE rle4_data[26] = { 0x03, 0x52, 0x07, 0x68, 0x00, 0x00, /* 5, 2, 5, 6, 8, 6, 8, 6, (8, 6,) <eol> */
4851 0x00, 0x03, 0x14, 0x50, 0x00, 0x05,
4852 0x79, 0xfd, 0xb0, 0x00, 0x00, 0x00, /* 1, 4, 5, 7, 9, f, d, b <pad> <eol> */
4853 0x00, 0x02, 0x01, 0x02, 0x05, 0x87, /* dx=1, dy=2, 8, 7, 8, 7, 8 */
4854 0x00, 0x01 }; /* <eod> */
4855 HBITMAP dib;
4856 int i, ret;
4857 DWORD bottom_up[64] = { 0x00050505, 0x00020202, 0x00050505, 0x00060606, 0x00080808, 0x00060606, 0x00080808, 0x00060606,
4858 0x00010101, 0x00040404, 0x00050505, 0x00070707, 0x00090909, 0x000f0f0f, 0x000d0d0d, 0x000b0b0b,
4859 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4860 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4861 0xaaaaaaaa, 0x00080808, 0x00070707, 0x00080808, 0x00070707, 0x00080808, 0xaaaaaaaa, 0xaaaaaaaa,
4862 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4863 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4864 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa };
4865
4866 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4867
4868 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4869 info->bmiHeader.biWidth = 8;
4870 info->bmiHeader.biHeight = 8;
4871 info->bmiHeader.biPlanes = 1;
4872 info->bmiHeader.biBitCount = 32;
4873 info->bmiHeader.biCompression = BI_RGB;
4874
4875 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4876 memset( dib_bits, 0xaa, 64 * 4 );
4877
4878 info->bmiHeader.biBitCount = 4;
4879 info->bmiHeader.biCompression = BI_RLE4;
4880 info->bmiHeader.biSizeImage = sizeof(rle4_data);
4881
4882 for (i = 0; i < 16; i++)
4883 {
4884 info->bmiColors[i].rgbRed = i;
4885 info->bmiColors[i].rgbGreen = i;
4886 info->bmiColors[i].rgbBlue = i;
4887 info->bmiColors[i].rgbReserved = 0;
4888 }
4889
4890 ret = SetDIBits( hdc, dib, 0, 8, rle4_data, info, DIB_RGB_COLORS );
4891 ok( ret == 8, "got %d\n", ret );
4892 ok( !memcmp( dib_bits, bottom_up, sizeof(bottom_up) ), "bits differ\n" );
4893 memset( dib_bits, 0xaa, 64 * 4 );
4894
4895 DeleteObject( dib );
4896 ReleaseDC( NULL, hdc );
4897 free( info );
4898}
4899
4900static void test_SetDIBits_RLE8(void)
4901{
4903 DWORD *dib_bits;
4904 HDC hdc = GetDC( NULL );
4905 BYTE rle8_data[20] = { 0x03, 0x02, 0x04, 0xf0, 0x00, 0x00, /* 2, 2, 2, f0, f0, f0, f0, <eol> */
4906 0x00, 0x03, 0x04, 0x05, 0x06, 0x00, /* 4, 5, 6, <pad> */
4907 0x00, 0x02, 0x01, 0x02, 0x05, 0x80, /* dx=1, dy=2, 80, 80, 80, 80, (80) */
4908 0x00, 0x01 }; /* <eod> */
4909 HBITMAP dib;
4910 int i, ret;
4911 DWORD bottom_up[64] = { 0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa,
4912 0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4913 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4914 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0x00808080, 0x00808080, 0x00808080, 0x00808080,
4915 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4916 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4917 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4918 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa };
4919 DWORD top_down[64] = { 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4920 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4921 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4922 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4923 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0x00808080, 0x00808080, 0x00808080, 0x00808080,
4924 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4925 0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
4926 0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa };
4927
4928 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
4929
4930 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4931 info->bmiHeader.biWidth = 8;
4932 info->bmiHeader.biHeight = 8;
4933 info->bmiHeader.biPlanes = 1;
4934 info->bmiHeader.biBitCount = 32;
4935 info->bmiHeader.biCompression = BI_RGB;
4936
4937 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
4938 memset( dib_bits, 0xaa, 64 * 4 );
4939
4940 info->bmiHeader.biBitCount = 8;
4941 info->bmiHeader.biCompression = BI_RLE8;
4942 info->bmiHeader.biSizeImage = sizeof(rle8_data);
4943
4944 for (i = 0; i < 256; i++)
4945 {
4946 info->bmiColors[i].rgbRed = i;
4947 info->bmiColors[i].rgbGreen = i;
4948 info->bmiColors[i].rgbBlue = i;
4949 info->bmiColors[i].rgbReserved = 0;
4950 }
4951
4952 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
4953 ok( ret == 8, "got %d\n", ret );
4954 ok( !memcmp( dib_bits, bottom_up, sizeof(bottom_up) ), "bits differ\n");
4955 memset( dib_bits, 0xaa, 64 * 4 );
4956
4957 /* startscan and lines are ignored, unless lines == 0 */
4958 ret = SetDIBits( hdc, dib, 1, 8, rle8_data, info, DIB_RGB_COLORS );
4959 ok( ret == 8, "got %d\n", ret );
4960 ok( !memcmp( dib_bits, bottom_up, sizeof(bottom_up) ), "bits differ\n");
4961 memset( dib_bits, 0xaa, 64 * 4 );
4962
4963 ret = SetDIBits( hdc, dib, 1, 1, rle8_data, info, DIB_RGB_COLORS );
4964 ok( ret == 8, "got %d\n", ret );
4965 ok( !memcmp( dib_bits, bottom_up, sizeof(bottom_up) ), "bits differ\n");
4966 memset( dib_bits, 0xaa, 64 * 4 );
4967
4968 ret = SetDIBits( hdc, dib, 1, 0, rle8_data, info, DIB_RGB_COLORS );
4969 ok( ret == 0, "got %d\n", ret );
4970 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4971 memset( dib_bits, 0xaa, 64 * 4 );
4972
4973 /* reduce width to 4, left-hand side of dst is touched. */
4974 info->bmiHeader.biWidth = 4;
4975 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
4976 ok( ret == 8, "got %d\n", ret );
4977 for (i = 0; i < 64; i++)
4978 {
4979 DWORD expect = (i & 4) ? 0xaaaaaaaa : bottom_up[i];
4980 ok( dib_bits[i] == expect, "%d: got %08lx\n", i, dib_bits[i] );
4981 }
4982 memset( dib_bits, 0xaa, 64 * 4 );
4983
4984 /* Show that the top lines are aligned by adjusting the height of the src */
4985
4986 /* reduce the height to 4 -> top 4 lines of dst are touched (corresponding to last half of the bits). */
4987 info->bmiHeader.biWidth = 8;
4988 info->bmiHeader.biHeight = 4;
4989 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
4990 ok( ret == 4, "got %d\n", ret );
4991 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
4992 ok( !memcmp( dib_bits + 32, bottom_up, 32 * 4 ), "bits differ\n");
4993 memset( dib_bits, 0xaa, 64 * 4 );
4994
4995 /* increase the height to 9 -> everything moves down one row. */
4996 info->bmiHeader.biHeight = 9;
4997 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
4998 ok( ret == 9, "got %d\n", ret );
4999 ok( !memcmp( dib_bits, bottom_up + 8, 56 * 4 ), "bits differ\n");
5000 for (i = 0; i < 8; i++) ok( dib_bits[56 + i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[56 + i] );
5001 memset( dib_bits, 0xaa, 64 * 4 );
5002
5003 /* top-down compressed dibs are invalid */
5004 info->bmiHeader.biHeight = -8;
5005 SetLastError( 0xdeadbeef );
5006 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5007 ok( ret == 0, "got %d\n", ret );
5008 ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %lx\n", GetLastError() );
5009 DeleteObject( dib );
5010
5011 /* top-down dst */
5012
5013 info->bmiHeader.biHeight = -8;
5014 info->bmiHeader.biBitCount = 32;
5015 info->bmiHeader.biCompression = BI_RGB;
5016 info->bmiHeader.biSizeImage = 0;
5017
5018 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
5019 memset( dib_bits, 0xaa, 16 * 16 * 4 );
5020
5021 info->bmiHeader.biHeight = 8;
5022 info->bmiHeader.biBitCount = 8;
5023 info->bmiHeader.biCompression = BI_RLE8;
5024 info->bmiHeader.biSizeImage = sizeof(rle8_data);
5025
5026 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5027 ok( ret == 8, "got %d\n", ret );
5028 ok( !memcmp( dib_bits, top_down, sizeof(top_down) ), "bits differ\n");
5029 memset( dib_bits, 0xaa, 64 * 4 );
5030
5031 info->bmiHeader.biHeight = 4;
5032 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5033 ok( ret == 4, "got %d\n", ret );
5034 ok( !memcmp( dib_bits, top_down + 32, 32 * 4 ), "bits differ\n");
5035 for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5036 memset( dib_bits, 0xaa, 64 * 4 );
5037
5038 info->bmiHeader.biHeight = 9;
5039 ret = SetDIBits( hdc, dib, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5040 ok( ret == 9, "got %d\n", ret );
5041 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5042 ok( !memcmp( dib_bits + 8, top_down, 56 * 4 ), "bits differ\n");
5043 memset( dib_bits, 0xaa, 64 * 4 );
5044
5045 DeleteObject( dib );
5046 ReleaseDC( NULL, hdc );
5047 free( info );
5048}
5049
5050static void test_SetDIBitsToDevice(void)
5051{
5052 char palbuf[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
5053 LOGPALETTE *pal = (LOGPALETTE *)palbuf;
5054 PALETTEENTRY *palent = pal->palPalEntry;
5055 HPALETTE palette;
5057 DWORD *dib_bits;
5058 HDC hdc = CreateCompatibleDC( 0 );
5059 DWORD data[128], inverted_data[128];
5060 HBITMAP dib;
5061 int i, ret;
5062
5063 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
5064
5065 info->bmiHeader.biSize = sizeof(info->bmiHeader);
5066 info->bmiHeader.biWidth = 8;
5067 info->bmiHeader.biHeight = 8;
5068 info->bmiHeader.biPlanes = 1;
5069 info->bmiHeader.biBitCount = 32;
5070 info->bmiHeader.biCompression = BI_RGB;
5071
5072 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
5073 memset( dib_bits, 0xaa, 64 * 4 );
5074 SelectObject( hdc, dib );
5075
5076 for (i = 0; i < 128; i++)
5077 {
5078 data[i] = i;
5079 inverted_data[120 - (i & ~7) + (i & 7)] = i;
5080 }
5081
5082 /* b-u -> b-u */
5083
5084 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
5085 ok( ret == 8, "got %d\n", ret );
5086 for (i = 0; i < 64; i++) ok( dib_bits[i] == data[i], "%d: got %08lx\n", i, dib_bits[i] );
5087 memset( dib_bits, 0xaa, 64 * 4 );
5088
5089 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 5, data, info, DIB_RGB_COLORS );
5090 ok( ret == 5, "got %d\n", ret );
5091 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5092 for (i = 8; i < 48; i++) ok( dib_bits[i] == data[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5093 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5094 memset( dib_bits, 0xaa, 64 * 4 );
5095
5096 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 3, 1, 5, data, info, DIB_RGB_COLORS );
5097 ok( ret == 5, "got %d\n", ret );
5098 for (i = 0; i < 24; i++) ok( dib_bits[i] == data[i + 16], "%d: got %08lx\n", i, dib_bits[i] );
5099 for (i = 24; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5100 memset( dib_bits, 0xaa, 64 * 4 );
5101
5102 info->bmiHeader.biHeight = 16;
5103 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 12, data, info, DIB_RGB_COLORS );
5104 ok( ret == 7, "got %d\n", ret );
5105 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5106 for (i = 8; i < 64; i++) ok( dib_bits[i] == data[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5107 memset( dib_bits, 0xaa, 64 * 4 );
5108
5109 ret = SetDIBitsToDevice( hdc, 0, 2, 8, 8, 0, 6, 1, 12, data, info, DIB_RGB_COLORS );
5110 ok( ret == 12, "got %d\n", ret );
5111 for (i = 0; i < 40; i++) ok( dib_bits[i] == data[i + 56], "%d: got %08lx\n", i, dib_bits[i] );
5112 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5113 memset( dib_bits, 0xaa, 64 * 4 );
5114
5115 ret = SetDIBitsToDevice( hdc, 0, -4, 8, 8, 0, 3, 1, 12, data, info, DIB_RGB_COLORS );
5116 ok( ret == 10, "got %d\n", ret );
5117 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5118 for (i = 32; i < 64; i++) ok( dib_bits[i] == data[i - 16], "%d: got %08lx\n", i, dib_bits[i] );
5119 memset( dib_bits, 0xaa, 64 * 4 );
5120
5121 ret = SetDIBitsToDevice( hdc, 0, 4, 8, 8, 0, -3, 1, 12, data, info, DIB_RGB_COLORS );
5122 ok( ret == 4, "got %d\n", ret );
5123 for (i = 0; i < 32; i++) ok( dib_bits[i] == data[i], "%d: got %08lx\n", i, dib_bits[i] );
5124 for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5125 memset( dib_bits, 0xaa, 64 * 4 );
5126
5127 ret = SetDIBitsToDevice( hdc, 0, 2, 8, 5, 0, -2, 1, 12, data, info, DIB_RGB_COLORS );
5128 ok( ret == 2, "got %d\n", ret );
5129 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5130 for (i = 32; i < 48; i++) ok( dib_bits[i] == data[i - 32], "%d: got %08lx\n", i, dib_bits[i] );
5131 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5132 memset( dib_bits, 0xaa, 64 * 4 );
5133
5134 info->bmiHeader.biHeight = 5;
5135 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 2, 2, data, info, DIB_RGB_COLORS );
5136 ok( ret == 2, "got %d\n", ret );
5137 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5138 for (i = 16; i < 32; i++) ok( dib_bits[i] == data[i - 16], "%d: got %08lx\n", i, dib_bits[i] );
5139 for (i = 32; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5140 memset( dib_bits, 0xaa, 64 * 4 );
5141
5142 ret = SetDIBitsToDevice( hdc, 3, 3, 2, 2, 1, 2, 1, 5, data, info, DIB_RGB_COLORS );
5143 ok( ret == 3, "got %d\n", ret );
5144 for (i = 0; i < 64; i++)
5145 if (i == 27 || i == 28 || i == 35 || i == 36)
5146 ok( dib_bits[i] == data[i - 18], "%d: got %08lx\n", i, dib_bits[i] );
5147 else
5148 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5149 memset( dib_bits, 0xaa, 64 * 4 );
5150
5151 ret = SetDIBitsToDevice( hdc, 0, 0, 16, 16, 0, 0, 0, 5, data, info, DIB_RGB_COLORS );
5152 ok( ret == 5, "got %d\n", ret );
5153 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5154 memset( dib_bits, 0xaa, 64 * 4 );
5155
5156 ret = SetDIBitsToDevice( hdc, 0, 2, 8, 4, 0, -1, 3, 12, data, info, DIB_RGB_COLORS );
5157 ok( ret == 0, "got %d\n", ret );
5158 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5159 memset( dib_bits, 0xaa, 64 * 4 );
5160
5162 SetWindowExtEx( hdc, 3, 3, NULL );
5163 ret = SetDIBitsToDevice( hdc, 2, 2, 2, 2, 1, 2, 1, 5, data, info, DIB_RGB_COLORS );
5164 ok( ret == 3, "got %d\n", ret );
5165 for (i = 0; i < 64; i++)
5166 if (i == 41 || i == 42 || i == 49 || i == 50)
5167 ok( dib_bits[i] == data[i - 32], "%d: got %08lx\n", i, dib_bits[i] );
5168 else
5169 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5170 memset( dib_bits, 0xaa, 64 * 4 );
5171
5172 SetWindowExtEx( hdc, -1, -1, NULL );
5173 ret = SetDIBitsToDevice( hdc, 2, 2, 4, 4, 1, 2, 1, 5, data, info, DIB_RGB_COLORS );
5174 ok( ret == 4, "got %d\n", ret );
5175 for (i = 0; i < 64; i++)
5176 if (i == 48 || i == 49 || i == 56 || i == 57)
5177 ok( dib_bits[i] == data[i - 37], "%d: got %08lx\n", i, dib_bits[i] );
5178 else
5179 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5180 memset( dib_bits, 0xaa, 64 * 4 );
5182
5184 ret = SetDIBitsToDevice( hdc, 1, 2, 3, 2, 1, 2, 1, 5, data, info, DIB_RGB_COLORS );
5185 ok( ret == 3, "got %d\n", ret );
5186 for (i = 0; i < 64; i++)
5187 if (i == 36 || i == 37 || i == 38 || i == 44 || i == 45 || i == 46)
5188 ok( dib_bits[i] == data[i - 27], "%d: got %08lx\n", i, dib_bits[i] );
5189 else
5190 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5191 memset( dib_bits, 0xaa, 64 * 4 );
5193
5194 /* t-d -> b-u */
5195 info->bmiHeader.biHeight = -8;
5196 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
5197 ok( ret == 8, "got %d\n", ret );
5198 for (i = 0; i < 64; i++) ok( dib_bits[i] == inverted_data[i + 64], "%d: got %08lx\n", i, dib_bits[i] );
5199 memset( dib_bits, 0xaa, 64 * 4 );
5200
5201 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 5, data, info, DIB_RGB_COLORS );
5202 ok( ret == 5, "got %d\n", ret );
5203 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5204 for (i = 8; i < 48; i++) ok( dib_bits[i] == inverted_data[i + 80], "%d: got %08lx\n", i, dib_bits[i] );
5205 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5206 memset( dib_bits, 0xaa, 64 * 4 );
5207
5208 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 4, 1, 5, data, info, DIB_RGB_COLORS );
5209 ok( ret == 5, "got %d\n", ret );
5210 for (i = 0; i < 16; i++) ok( dib_bits[i] == inverted_data[i + 112], "%d: got %08lx\n", i, dib_bits[i] );
5211 for (i = 16; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5212 memset( dib_bits, 0xaa, 64 * 4 );
5213
5214 info->bmiHeader.biHeight = -16;
5215 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 12, data, info, DIB_RGB_COLORS );
5216 ok( ret == 12, "got %d\n", ret );
5217 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5218 for (i = 8; i < 64; i++) ok( dib_bits[i] == inverted_data[i + 24], "%d: got %08lx\n", i, dib_bits[i] );
5219 memset( dib_bits, 0xaa, 64 * 4 );
5220
5221 ret = SetDIBitsToDevice( hdc, 0, 4, 8, 8, 0, 7, 1, 12, data, info, DIB_RGB_COLORS );
5222 ok( ret == 12, "got %d\n", ret );
5223 for (i = 0; i < 16; i++) ok( dib_bits[i] == inverted_data[i + 112], "%d: got %08lx\n", i, dib_bits[i] );
5224 for (i = 16; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5225 memset( dib_bits, 0xaa, 64 * 4 );
5226
5227 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 4, 12, data, info, DIB_RGB_COLORS );
5228 ok( ret == 12, "got %d\n", ret );
5229 for (i = 0; i < 32; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5230 for (i = 32; i < 64; i++) ok( dib_bits[i] == inverted_data[i], "%d: got %08lx\n", i, dib_bits[i] );
5231 memset( dib_bits, 0xaa, 64 * 4 );
5232
5233 ret = SetDIBitsToDevice( hdc, 0, -3, 8, 8, 0, 2, 4, 12, data, info, DIB_RGB_COLORS );
5234 ok( ret == 12, "got %d\n", ret );
5235 for (i = 0; i < 40; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5236 for (i = 40; i < 64; i++) ok( dib_bits[i] == inverted_data[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5237 memset( dib_bits, 0xaa, 64 * 4 );
5238
5239 ret = SetDIBitsToDevice( hdc, 0, 3, 8, 8, 0, -2, 4, 12, data, info, DIB_RGB_COLORS );
5240 ok( ret == 12, "got %d\n", ret );
5241 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5242 for (i = 24; i < 40; i++) ok( dib_bits[i] == inverted_data[i + 8], "%d: got %08lx\n", i, dib_bits[i] );
5243 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5244 memset( dib_bits, 0xaa, 64 * 4 );
5245
5246 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 5, 12, data, info, DIB_RGB_COLORS );
5247 ok( ret == 12, "got %d\n", ret );
5248 for (i = 0; i < 40; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5249 for (i = 40; i < 64; i++) ok( dib_bits[i] == inverted_data[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5250 memset( dib_bits, 0xaa, 64 * 4 );
5251
5252 ret = SetDIBitsToDevice( hdc, 0, 2, 8, 4, 0, -1, 3, 12, data, info, DIB_RGB_COLORS );
5253 ok( ret == 12, "got %d\n", ret );
5254 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5255 memset( dib_bits, 0xaa, 64 * 4 );
5256
5257 ret = SetDIBitsToDevice( hdc, 5, -7, 8, 16, -2, -4, 0, 12, data, info, DIB_RGB_COLORS );
5258 ok( ret == 12, "got %d\n", ret );
5259 for (i = 0; i < 64; i++)
5260 if (i == 31 || i == 39 || i == 47 || i == 55 || i == 63)
5261 ok( dib_bits[i] == inverted_data[i + 1], "%d: got %08lx\n", i, dib_bits[i] );
5262 else
5263 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5264 memset( dib_bits, 0xaa, 64 * 4 );
5265
5266 info->bmiHeader.biHeight = -5;
5267 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 2, data, info, DIB_RGB_COLORS );
5268 ok( ret == 2, "got %d\n", ret );
5269 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5270 for (i = 8; i < 24; i++) ok( dib_bits[i] == inverted_data[i + 104], "%d: got %08lx\n", i, dib_bits[i] );
5271 for (i = 24; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5272 memset( dib_bits, 0xaa, 64 * 4 );
5273
5274 ret = SetDIBitsToDevice( hdc, 5, 4, 2, 2, 6, 3, 1, 5, data, info, DIB_RGB_COLORS );
5275 ok( ret == 5, "got %d\n", ret );
5276 for (i = 0; i < 64; i++)
5277 if (i == 21 || i == 22 || i == 29 || i == 30)
5278 ok( dib_bits[i] == inverted_data[i + 89], "%d: got %08lx\n", i, dib_bits[i] );
5279 else
5280 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5281 memset( dib_bits, 0xaa, 64 * 4 );
5282
5283 ret = SetDIBitsToDevice( hdc, 0, 0, 16, 16, 0, 0, 0, 5, data, info, DIB_RGB_COLORS );
5284 ok( ret == 5, "got %d\n", ret );
5285 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5286 memset( dib_bits, 0xaa, 64 * 4 );
5287
5288 info->bmiHeader.biHeight = -8;
5289
5290 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
5291 DeleteObject( SelectObject( hdc, dib ));
5292 memset( dib_bits, 0xaa, 16 * 16 * 4 );
5293
5294 /* t-d -> t-d */
5295
5296 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
5297 ok( ret == 8, "got %d\n", ret );
5298 for (i = 0; i < 64; i++) ok( dib_bits[i] == data[i], "%d: got %08lx\n", i, dib_bits[i] );
5299 memset( dib_bits, 0xaa, 64 * 4 );
5300
5301 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 5, data, info, DIB_RGB_COLORS );
5302 ok( ret == 5, "got %d\n", ret );
5303 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5304 for (i = 16; i < 56; i++) ok( dib_bits[i] == data[i - 16], "%d: got %08lx\n", i, dib_bits[i] );
5305 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5306 memset( dib_bits, 0xaa, 64 * 4 );
5307
5308 ret = SetDIBitsToDevice( hdc, 0, 3, 8, 3, 0, 2, 1, 5, data, info, DIB_RGB_COLORS );
5309 ok( ret == 5, "got %d\n", ret );
5310 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5311 for (i = 24; i < 48; i++) ok( dib_bits[i] == data[i - 16], "%d: got %08lx\n", i, dib_bits[i] );
5312 for (i = 48; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5313 memset( dib_bits, 0xaa, 64 * 4 );
5314
5315 info->bmiHeader.biHeight = -16;
5316 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 12, data, info, DIB_RGB_COLORS );
5317 ok( ret == 12, "got %d\n", ret );
5318 for (i = 0; i < 56; i++) ok( dib_bits[i] == data[i + 40], "%d: got %08lx\n", i, dib_bits[i] );
5319 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5320 memset( dib_bits, 0xaa, 64 * 4 );
5321
5322 ret = SetDIBitsToDevice( hdc, 5, -7, 8, 16, -1, -8, 0, 12, data, info, DIB_RGB_COLORS );
5323 ok( ret == 12, "got %d\n", ret );
5324 for (i = 0; i < 64; i++)
5325 if (i == 6 || i == 7)
5326 ok( dib_bits[i] == data[i + 82], "%d: got %08lx\n", i, dib_bits[i] );
5327 else
5328 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5329 memset( dib_bits, 0xaa, 64 * 4 );
5330
5331 info->bmiHeader.biHeight = -5;
5332 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 2, data, info, DIB_RGB_COLORS );
5333 ok( ret == 2, "got %d\n", ret );
5334 for (i = 0; i < 40; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5335 for (i = 40; i < 56; i++) ok( dib_bits[i] == data[i - 40], "%d: got %08lx\n", i, dib_bits[i] );
5336 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5337 memset( dib_bits, 0xaa, 64 * 4 );
5338
5339 ret = SetDIBitsToDevice( hdc, 7, 2, 8, 8, 1, 0, 0, 5, data, info, DIB_RGB_COLORS );
5340 ok( ret == 5, "got %d\n", ret );
5341 for (i = 0; i < 64; i++)
5342 if (i == 47 || i == 55 || i == 63)
5343 ok( dib_bits[i] == data[i - 46], "%d: got %08lx\n", i, dib_bits[i] );
5344 else
5345 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5346 memset( dib_bits, 0xaa, 64 * 4 );
5347
5348 ret = SetDIBitsToDevice( hdc, 0, 0, 16, 16, 0, 0, 0, 5, data, info, DIB_RGB_COLORS );
5349 ok( ret == 5, "got %d\n", ret );
5350 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5351 memset( dib_bits, 0xaa, 64 * 4 );
5352
5353 /* b-u -> t-d */
5354
5355 info->bmiHeader.biHeight = 8;
5356 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
5357 ok( ret == 8, "got %d\n", ret );
5358 for (i = 0; i < 64; i++) ok( dib_bits[i] == inverted_data[i + 64], "%d: got %08lx\n", i, dib_bits[i] );
5359 memset( dib_bits, 0xaa, 64 * 4 );
5360
5361 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 5, data, info, DIB_RGB_COLORS );
5362 ok( ret == 5, "got %d\n", ret );
5363 for (i = 0; i < 16; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5364 for (i = 16; i < 56; i++) ok( dib_bits[i] == inverted_data[i + 72], "%d: got %08lx\n", i, dib_bits[i] );
5365 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5366 memset( dib_bits, 0xaa, 64 * 4 );
5367
5368 info->bmiHeader.biHeight = 16;
5369 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 12, data, info, DIB_RGB_COLORS );
5370 ok( ret == 7, "got %d\n", ret );
5371 for (i = 0; i < 56; i++) ok( dib_bits[i] == inverted_data[i + 72], "%d: got %08lx\n", i, dib_bits[i] );
5372 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5373 memset( dib_bits, 0xaa, 64 * 4 );
5374
5375 ret = SetDIBitsToDevice( hdc, 4, 4, 8, 8, 0, -4, 1, 12, data, info, DIB_RGB_COLORS );
5376 ok( ret == 3, "got %d\n", ret );
5377 for (i = 0; i < 64; i++)
5378 if ((i >= 36 && i <= 39) || (i >= 44 && i <= 47) || (i >= 52 && i <= 55))
5379 ok( dib_bits[i] == inverted_data[i + 68], "%d: got %08lx\n", i, dib_bits[i] );
5380 else
5381 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5382 memset( dib_bits, 0xaa, 64 * 4 );
5383
5384 ret = SetDIBitsToDevice( hdc, 4, 4, 8, 8, -30, -30, 1, 12, data, info, DIB_RGB_COLORS );
5385 ok( ret == 0, "got %d\n", ret );
5386 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5387 memset( dib_bits, 0xaa, 64 * 4 );
5388
5389 ret = SetDIBitsToDevice( hdc, 5, -5, 8, 16, -2, -4, 4, 12, data, info, DIB_RGB_COLORS );
5390 ok( ret == 8, "got %d\n", ret );
5391 for (i = 0; i < 64; i++)
5392 if (i == 7 || i == 15 || i == 23)
5393 ok( dib_bits[i] == inverted_data[i + 97], "%d: got %08lx\n", i, dib_bits[i] );
5394 else
5395 ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5396 memset( dib_bits, 0xaa, 64 * 4 );
5397
5398 info->bmiHeader.biHeight = 5;
5399 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 2, data, info, DIB_RGB_COLORS );
5400 ok( ret == 2, "got %d\n", ret );
5401 for (i = 0; i < 40; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5402 for (i = 40; i < 56; i++) ok( dib_bits[i] == inverted_data[i + 72], "%d: got %08lx\n", i, dib_bits[i] );
5403 for (i = 56; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5404 memset( dib_bits, 0xaa, 64 * 4 );
5405
5406 ret = SetDIBitsToDevice( hdc, 0, 0, 16, 16, 0, 0, 0, 5, data, info, DIB_RGB_COLORS );
5407 ok( ret == 5, "got %d\n", ret );
5408 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5409 memset( dib_bits, 0xaa, 64 * 4 );
5410
5411 /* handling of partial color table */
5412
5413 info->bmiHeader.biHeight = -8;
5414 info->bmiHeader.biBitCount = 8;
5415 info->bmiHeader.biClrUsed = 137;
5416 for (i = 0; i < 256; i++)
5417 {
5418 info->bmiColors[i].rgbRed = 255 - i;
5419 info->bmiColors[i].rgbGreen = i * 2;
5420 info->bmiColors[i].rgbBlue = i;
5421 info->bmiColors[i].rgbReserved = 0;
5422 }
5423 for (i = 0; i < 64; i++) ((BYTE *)data)[i] = i * 4 + 1;
5424 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_RGB_COLORS );
5425 ok( ret == 8, "got %d\n", ret );
5426 for (i = 0; i < 64; i++)
5427 {
5428 int idx = i * 4 + 1;
5429 DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 : (info->bmiColors[idx].rgbRed << 16 |
5430 info->bmiColors[idx].rgbGreen << 8 |
5431 info->bmiColors[idx].rgbBlue);
5432 ok( dib_bits[i] == expect, "%d: got %08lx instead of %08lx\n", i, dib_bits[i], expect );
5433 }
5434 memset( dib_bits, 0xaa, 64 * 4 );
5435
5436 /* handling of DIB_PAL_COLORS */
5437
5438 pal->palVersion = 0x300;
5439 pal->palNumEntries = 137;
5440 info->bmiHeader.biClrUsed = 221;
5441 for (i = 0; i < 256; i++)
5442 {
5443 palent[i].peRed = i * 2;
5444 palent[i].peGreen = 255 - i;
5445 palent[i].peBlue = i;
5446 }
5447 palette = CreatePalette( pal );
5448 ok( palette != 0, "palette creation failed\n" );
5450 for (i = 0; i < 256; i++) ((WORD *)info->bmiColors)[i] = 255 - i;
5451 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, data, info, DIB_PAL_COLORS );
5452 ok( ret == 8, "got %d\n", ret );
5453 for (i = 0; i < 64; i++)
5454 {
5455 int idx = i * 4 + 1;
5456 int ent = (255 - idx) % pal->palNumEntries;
5457 DWORD expect = idx >= info->bmiHeader.biClrUsed ? 0 :
5458 (palent[ent].peRed << 16 | palent[ent].peGreen << 8 | palent[ent].peBlue);
5459 ok( dib_bits[i] == expect || broken(dib_bits[i] == 0),
5460 "%d: got %08lx instead of %08lx\n", i, dib_bits[i], expect );
5461 }
5462 memset( dib_bits, 0xaa, 64 * 4 );
5463
5464 DeleteDC( hdc );
5465 DeleteObject( dib );
5467 free( info );
5468}
5469
5471{
5473 DWORD *dib_bits;
5474 HDC hdc = CreateCompatibleDC( 0 );
5475 BYTE rle8_data[20] = { 0x04, 0x02, 0x03, 0xf0, 0x00, 0x00, /* 2, 2, 2, 2, f0, f0, f0, <eol> */
5476 0x00, 0x03, 0x04, 0x05, 0x06, 0x00, /* 4, 5, 6, <pad> */
5477 0x00, 0x02, 0x01, 0x02, 0x05, 0x80, /* dx=1, dy=2, 80, 80, 80, 80, (80) */
5478 0x00, 0x01 }; /* <eod> */
5479 HBITMAP dib;
5480 int i, ret;
5481 DWORD bottom_up[64] = { 0x00020202, 0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa,
5482 0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5483 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5484 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0x00808080, 0x00808080, 0x00808080, 0x00808080,
5485 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5486 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5487 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5488 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa };
5489 DWORD top_down[64] = { 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5490 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5491 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5492 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5493 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0x00808080, 0x00808080, 0x00808080, 0x00808080,
5494 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5495 0x00040404, 0x00050505, 0x00060606, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa,
5496 0x00020202, 0x00020202, 0x00020202, 0x00020202, 0x00f0f0f0, 0x00f0f0f0, 0x00f0f0f0, 0xaaaaaaaa };
5497
5498 info = calloc( 1, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ) );
5499
5500 info->bmiHeader.biSize = sizeof(info->bmiHeader);
5501 info->bmiHeader.biWidth = 8;
5502 info->bmiHeader.biHeight = 8;
5503 info->bmiHeader.biPlanes = 1;
5504 info->bmiHeader.biBitCount = 32;
5505 info->bmiHeader.biCompression = BI_RGB;
5506
5507 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
5508 memset( dib_bits, 0xaa, 64 * 4 );
5509 SelectObject( hdc, dib );
5510
5511 info->bmiHeader.biBitCount = 8;
5512 info->bmiHeader.biCompression = BI_RLE8;
5513 info->bmiHeader.biSizeImage = sizeof(rle8_data);
5514
5515 for (i = 0; i < 256; i++)
5516 {
5517 info->bmiColors[i].rgbRed = i;
5518 info->bmiColors[i].rgbGreen = i;
5519 info->bmiColors[i].rgbBlue = i;
5520 info->bmiColors[i].rgbReserved = 0;
5521 }
5522
5523 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5524 ok( ret == 8, "got %d\n", ret );
5525 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5526 memset( dib_bits, 0xaa, 64 * 4 );
5527
5528 /* startscan and lines are ignored, unless lines == 0 */
5529 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 8, rle8_data, info, DIB_RGB_COLORS );
5530 ok( ret == 8, "got %d\n", ret );
5531 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5532 memset( dib_bits, 0xaa, 64 * 4 );
5533
5534 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 1, rle8_data, info, DIB_RGB_COLORS );
5535 ok( ret == 8, "got %d\n", ret );
5536 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5537 memset( dib_bits, 0xaa, 64 * 4 );
5538
5539 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 0, rle8_data, info, DIB_RGB_COLORS );
5540 ok( ret == 0, "got %d\n", ret );
5541 for (i = 0; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5542 memset( dib_bits, 0xaa, 64 * 4 );
5543
5544 info->bmiHeader.biWidth = 2;
5545 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5546 ok( ret == 8, "got %d\n", ret );
5547 if (dib_bits[0] == 0xaaaaaaaa)
5548 {
5549 win_skip("SetDIBitsToDevice is broken on Windows 2008.\n");
5550 goto cleanup;
5551 }
5552 for (i = 0; i < 64; i += 8)
5553 {
5554 ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5555 ok( dib_bits[i+1] == bottom_up[i+1], "%d: got %08lx\n", i+1, dib_bits[i+1] );
5556 }
5557 memset( dib_bits, 0xaa, 64 * 4 );
5558
5559 info->bmiHeader.biWidth = 8;
5560 info->bmiHeader.biHeight = 2;
5561 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5562 ok( ret == 2, "got %d\n", ret );
5563 for (i = 0; i < 16; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5564 memset( dib_bits, 0xaa, 64 * 4 );
5565
5566 info->bmiHeader.biHeight = 9;
5567 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5568 ok( ret == 9, "got %d\n", ret );
5569 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5570 memset( dib_bits, 0xaa, 64 * 4 );
5571
5572 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 9, rle8_data, info, DIB_RGB_COLORS );
5573 ok( ret == 9, "got %d\n", ret );
5574 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5575 memset( dib_bits, 0xaa, 64 * 4 );
5576
5577 info->bmiHeader.biHeight = 8;
5578 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 1, 9, rle8_data, info, DIB_RGB_COLORS );
5579 ok( ret == 8, "got %d\n", ret );
5580 for (i = 0; i < 64; i++) ok( dib_bits[i] == bottom_up[i], "%d: got %08lx\n", i, dib_bits[i] );
5581 memset( dib_bits, 0xaa, 64 * 4 );
5582
5583 ret = SetDIBitsToDevice( hdc, 0, 3, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5584 ok( ret == 8, "got %d\n", ret );
5585 for (i = 0; i < 40; i++) ok( dib_bits[i] == bottom_up[i + 24], "%d: got %08lx\n", i, dib_bits[i] );
5586 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5587 memset( dib_bits, 0xaa, 64 * 4 );
5588
5589 ret = SetDIBitsToDevice( hdc, 0, 3, 4, 4, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5590 ok( ret == 8, "got %d\n", ret );
5591 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5592 for (i = 8; i < 40; i++)
5593 if (i & 4) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5594 else ok( dib_bits[i] == bottom_up[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5595 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5596 memset( dib_bits, 0xaa, 64 * 4 );
5597
5598 ret = SetDIBitsToDevice( hdc, 3, 3, 8, 4, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5599 ok( ret == 8, "got %d\n", ret );
5600 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5601 for (i = 8; i < 40; i++)
5602 if ((i & 7) < 3) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5603 else ok( dib_bits[i] == bottom_up[i - 11], "%d: got %08lx\n", i, dib_bits[i] );
5604 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5605 memset( dib_bits, 0xaa, 64 * 4 );
5606
5607 ret = SetDIBitsToDevice( hdc, 2, 3, 8, 4, 2, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5608 ok( ret == 8, "got %d\n", ret );
5609 for (i = 0; i < 8; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5610 for (i = 8; i < 40; i++)
5611 if ((i & 7) < 2) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5612 else ok( dib_bits[i] == bottom_up[i - 8], "%d: got %08lx\n", i, dib_bits[i] );
5613 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5614 memset( dib_bits, 0xaa, 64 * 4 );
5615
5616 info->bmiHeader.biWidth = 37;
5617 info->bmiHeader.biHeight = 37;
5618 ret = SetDIBitsToDevice( hdc, -2, 1, 10, 5, 2, -1, 12, 24, rle8_data, info, DIB_RGB_COLORS );
5619 ok( ret == 37, "got %d\n", ret );
5620 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5621 for (i = 24; i < 64; i++)
5622 if (i == 52) ok( dib_bits[i] == 0x00808080, "%d: got %08lx\n", i, dib_bits[i] );
5623 else if (i & 4) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5624 else ok( dib_bits[i] == bottom_up[i - 20], "%d: got %08lx\n", i, dib_bits[i] );
5625 memset( dib_bits, 0xaa, 64 * 4 );
5626
5627 /* top-down compressed dibs are invalid */
5628 info->bmiHeader.biWidth = 8;
5629 info->bmiHeader.biHeight = -8;
5630 SetLastError( 0xdeadbeef );
5631 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5632 ok( ret == 0, "got %d\n", ret );
5633 ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %lx\n", GetLastError() );
5634
5635 /* top-down dst */
5636
5637 info->bmiHeader.biHeight = -8;
5638 info->bmiHeader.biBitCount = 32;
5639 info->bmiHeader.biCompression = BI_RGB;
5640 info->bmiHeader.biSizeImage = 0;
5641
5642 dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 );
5643 memset( dib_bits, 0xaa, 16 * 16 * 4 );
5644 DeleteObject( SelectObject( hdc, dib ));
5645
5646 info->bmiHeader.biHeight = 8;
5647 info->bmiHeader.biBitCount = 8;
5648 info->bmiHeader.biCompression = BI_RLE8;
5649 info->bmiHeader.biSizeImage = sizeof(rle8_data);
5650
5651 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5652 ok( ret == 8, "got %d\n", ret );
5653 for (i = 0; i < 64; i++) ok( dib_bits[i] == top_down[i], "%d: got %08lx\n", i, dib_bits[i] );
5654 memset( dib_bits, 0xaa, 64 * 4 );
5655
5656 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 9, rle8_data, info, DIB_RGB_COLORS );
5657 ok( ret == 8, "got %d\n", ret );
5658 for (i = 0; i < 64; i++) ok( dib_bits[i] == top_down[i], "%d: got %08lx\n", i, dib_bits[i] );
5659 memset( dib_bits, 0xaa, 64 * 4 );
5660
5661 info->bmiHeader.biHeight = 4;
5662 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5663 ok( ret == 4, "got %d\n", ret );
5664 for (i = 0; i < 64; i++) ok( dib_bits[i] == top_down[i], "%d: got %08lx\n", i, dib_bits[i] );
5665 memset( dib_bits, 0xaa, 64 * 4 );
5666
5667 info->bmiHeader.biHeight = 9;
5668 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5669 ok( ret == 9, "got %d\n", ret );
5670 for (i = 0; i < 64; i++) ok( dib_bits[i] == top_down[i], "%d: got %08lx\n", i, dib_bits[i] );
5671 memset( dib_bits, 0xaa, 64 * 4 );
5672
5673 ret = SetDIBitsToDevice( hdc, 0, 0, 8, 8, 0, 0, 0, 9, rle8_data, info, DIB_RGB_COLORS );
5674 ok( ret == 9, "got %d\n", ret );
5675 for (i = 0; i < 64; i++) ok( dib_bits[i] == top_down[i], "%d: got %08lx\n", i, dib_bits[i] );
5676 memset( dib_bits, 0xaa, 64 * 4 );
5677
5678 ret = SetDIBitsToDevice( hdc, 2, 3, 8, 6, 2, 2, 0, 8, rle8_data, info, DIB_RGB_COLORS );
5679 ok( ret == 9, "got %d\n", ret );
5680 for (i = 0; i < 24; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5681 for (i = 24; i < 64; i++) ok( dib_bits[i] == top_down[i - 24], "%d: got %08lx\n", i, dib_bits[i] );
5682 memset( dib_bits, 0xaa, 64 * 4 );
5683
5684 info->bmiHeader.biWidth = 37;
5685 info->bmiHeader.biHeight = 37;
5686 ret = SetDIBitsToDevice( hdc, -2, 1, 10, 5, 2, -1, 12, 24, rle8_data, info, DIB_RGB_COLORS );
5687 ok( ret == 37, "got %d\n", ret );
5688 for (i = 0; i < 40; i++)
5689 if (i == 12) ok( dib_bits[i] == 0x00808080, "%d: got %08lx\n", i, dib_bits[i] );
5690 else if (i & 4) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5691 else ok( dib_bits[i] == top_down[i + 28], "%d: got %08lx\n", i, dib_bits[i] );
5692 for (i = 40; i < 64; i++) ok( dib_bits[i] == 0xaaaaaaaa, "%d: got %08lx\n", i, dib_bits[i] );
5693 memset( dib_bits, 0xaa, 64 * 4 );
5694
5695cleanup:
5696 DeleteDC( hdc );
5697 DeleteObject( dib );
5698 free( info );
5699}
5700
5701#ifndef __REACTOS__ /* CORE-11331 */
5703{
5704 D3DKMT_DESTROYDCFROMMEMORY destroy_desc;
5705 D3DKMT_CREATEDCFROMMEMORY create_desc;
5706 MEMORY_BASIC_INFORMATION memory_info;
5707 unsigned int width_bytes;
5708 unsigned int i, x, y, z;
5709 DWORD expected, colour;
5710 BYTE data[12][48];
5711 void *alloc_data;
5713 HGDIOBJ *bitmap;
5714 DIBSECTION dib;
5715 BOOL fail, ret;
5716 DWORD type, pixel;
5717 int size;
5718 HDC bmp_dc;
5719 HBITMAP bmp;
5720
5721 static const struct
5722 {
5723 const char *name;
5725 unsigned int bit_count;
5726 DWORD mask_r, mask_g, mask_b;
5728 }
5729 test_data[] =
5730 {
5731 { "R8G8B8", D3DDDIFMT_R8G8B8, 24, 0x00000000, 0x00000000, 0x00000000, STATUS_SUCCESS },
5732 { "A8R8G8B8", D3DDDIFMT_A8R8G8B8, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_SUCCESS },
5733 { "X8R8G8B8", D3DDDIFMT_X8R8G8B8, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_SUCCESS },
5734 { "R5G6B5", D3DDDIFMT_R5G6B5, 16, 0x0000f800, 0x000007e0, 0x0000001f, STATUS_SUCCESS },
5735 { "X1R5G5B5", D3DDDIFMT_X1R5G5B5, 16, 0x00007c00, 0x000003e0, 0x0000001f, STATUS_SUCCESS },
5736 { "A1R5G5B5", D3DDDIFMT_A1R5G5B5, 16, 0x00007c00, 0x000003e0, 0x0000001f, STATUS_SUCCESS },
5737 { "R3G3B2", D3DDDIFMT_R3G3B2, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5738 { "A2B10G10R10", D3DDDIFMT_A2B10G10R10, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5739 { "A8B8G8R8", D3DDDIFMT_A8B8G8R8, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5740 { "X8B8G8R8", D3DDDIFMT_A8B8G8R8, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5741 { "A2R10G10B10", D3DDDIFMT_A2R10G10B10, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5742 { "P8", D3DDDIFMT_P8, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_SUCCESS },
5743 { "L8", D3DDDIFMT_L8, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5744 { "A8L8", D3DDDIFMT_A8L8, 16, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5745 { "V8U8", D3DDDIFMT_V8U8, 16, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5746 { "Q8W8V8U8", D3DDDIFMT_Q8W8V8U8, 32, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5747 { "DXT1", D3DDDIFMT_DXT1, 4, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5748 { "DXT2", D3DDDIFMT_DXT2, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5749 { "DXT3", D3DDDIFMT_DXT3, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5750 { "DXT4", D3DDDIFMT_DXT4, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5751 { "DXT5", D3DDDIFMT_DXT5, 8, 0x00000000, 0x00000000, 0x00000000, STATUS_INVALID_PARAMETER },
5752 };
5753
5754 if (!pD3DKMTCreateDCFromMemory)
5755 {
5756 win_skip("D3DKMTCreateDCFromMemory() is not implemented.\n");
5757 return;
5758 }
5759
5760 status = pD3DKMTCreateDCFromMemory( NULL );
5761 ok(status == STATUS_INVALID_PARAMETER, "Got unexpected status %#lx.\n", status);
5762
5763 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5764 {
5765 memset( data, 0xaa, sizeof(data) );
5766
5767 create_desc.pMemory = data;
5768 create_desc.Format = test_data[i].format;
5769 create_desc.Width = 9;
5770 create_desc.Height = 7;
5771 create_desc.Pitch = sizeof(*data);
5772 create_desc.hDeviceDc = NULL;
5773 create_desc.pColorTable = NULL;
5774 create_desc.hDc = (void *)0x010baade;
5775 create_desc.hBitmap = (void *)0x020baade;
5776
5777 status = pD3DKMTCreateDCFromMemory( &create_desc );
5778 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n",
5780
5781 create_desc.hDeviceDc = CreateCompatibleDC( NULL );
5782 create_desc.pMemory = NULL;
5783 status = pD3DKMTCreateDCFromMemory( &create_desc );
5784 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n",
5786
5787 create_desc.pMemory = data;
5788 create_desc.Height = 0;
5789 status = pD3DKMTCreateDCFromMemory( &create_desc );
5790 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n",
5792 ok(create_desc.hDc == (void *)0x010baade, "%s: Got unexpected dc %p.\n",
5793 test_data[i].name, create_desc.hDc);
5794 ok(create_desc.hBitmap == (void *)0x020baade, "%s: Got unexpected bitmap %p.\n",
5795 test_data[i].name, create_desc.hBitmap);
5796
5797 create_desc.Height = 7;
5798 create_desc.Pitch = 0;
5799 status = pD3DKMTCreateDCFromMemory( &create_desc );
5800 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n",
5802 ok(create_desc.hDc == (void *)0x010baade, "%s: Got unexpected dc %p.\n",
5803 test_data[i].name, create_desc.hDc);
5804 ok(create_desc.hBitmap == (void *)0x020baade, "%s: Got unexpected bitmap %p.\n",
5805 test_data[i].name, create_desc.hBitmap);
5806
5807 create_desc.Width = 9;
5808 create_desc.Pitch = sizeof(*data);
5809 status = pD3DKMTCreateDCFromMemory( &create_desc );
5810 ok(status == test_data[i].status, "%s: Got unexpected status %#lx, expected %#lx.\n",
5812 if (status == STATUS_SUCCESS)
5813 {
5814 ok(!!create_desc.hDc, "%s: Got unexpected dc %p.\n",
5815 test_data[i].name, create_desc.hDc);
5816 ok(!!create_desc.hBitmap, "%s: Got unexpected bitmap %p.\n",
5817 test_data[i].name, create_desc.hBitmap);
5818 }
5819 else
5820 {
5821 ok(create_desc.hDc == (void *)0x010baade, "%s: Got unexpected dc %p.\n",
5822 test_data[i].name, create_desc.hDc);
5823 ok(create_desc.hBitmap == (void *)0x020baade, "%s: Got unexpected bitmap %p.\n",
5824 test_data[i].name, create_desc.hBitmap);
5825 continue;
5826 }
5827
5828 type = GetObjectType( create_desc.hDc );
5829 ok(type == OBJ_MEMDC, "%s: Got unexpected object type %#lx.\n", test_data[i].name, type);
5830 type = GetObjectType( create_desc.hBitmap );
5831 ok(type == OBJ_BITMAP, "%s: Got unexpected object type %#lx.\n", test_data[i].name, type);
5832 bitmap = GetCurrentObject( create_desc.hDc, OBJ_BITMAP );
5833 ok(bitmap == create_desc.hBitmap, "%s: Got unexpected bitmap %p, expected %p.\n",
5834 test_data[i].name, bitmap, create_desc.hBitmap);
5835
5836 size = GetObjectA( bitmap, sizeof(dib), &dib );
5837 ok(size == sizeof(dib), "%s: Got unexpected size %d.\n", test_data[i].name, size);
5838 ok(!dib.dsBm.bmType, "%s: Got unexpected type %#x.\n",
5839 test_data[i].name, dib.dsBm.bmType);
5840 ok(dib.dsBm.bmWidth == create_desc.Width, "%s: Got unexpected width %d.\n",
5841 test_data[i].name, dib.dsBm.bmWidth);
5842 ok(dib.dsBm.bmHeight == create_desc.Height, "%s: Got unexpected height %d.\n",
5843 test_data[i].name, dib.dsBm.bmHeight);
5844 width_bytes = get_dib_stride( create_desc.Width, test_data[i].bit_count );
5845 ok(dib.dsBm.bmWidthBytes == width_bytes, "%s: Got unexpected width bytes %d.\n",
5846 test_data[i].name, dib.dsBm.bmWidthBytes);
5847 ok(dib.dsBm.bmPlanes == 1, "%s: Got unexpected plane count %d.\n",
5848 test_data[i].name, dib.dsBm.bmPlanes);
5849 ok(dib.dsBm.bmBitsPixel == test_data[i].bit_count, "%s: Got unexpected bit count %d.\n",
5850 test_data[i].name, dib.dsBm.bmBitsPixel);
5851 ok(dib.dsBm.bmBits == create_desc.pMemory, "%s: Got unexpected bits %p, expected %p.\n",
5852 test_data[i].name, dib.dsBm.bmBits, create_desc.pMemory);
5853
5854 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "%s: Got unexpected size %lu.\n",
5855 test_data[i].name, dib.dsBmih.biSize);
5856 ok(dib.dsBmih.biWidth == create_desc.Width, "%s: Got unexpected width %ld.\n",
5857 test_data[i].name, dib.dsBmih.biHeight);
5858 ok(dib.dsBmih.biHeight == create_desc.Height, "%s: Got unexpected height %ld.\n",
5859 test_data[i].name, dib.dsBmih.biHeight);
5860 ok(dib.dsBmih.biPlanes == 1, "%s: Got unexpected plane count %u.\n",
5861 test_data[i].name, dib.dsBmih.biPlanes);
5862 ok(dib.dsBmih.biBitCount == test_data[i].bit_count, "%s: Got unexpected bit count %u.\n",
5863 test_data[i].name, dib.dsBmih.biBitCount);
5864 ok(dib.dsBmih.biCompression == (test_data[i].bit_count == 16 ? BI_BITFIELDS : BI_RGB),
5865 "%s: Got unexpected compression %#lx.\n",
5866 test_data[i].name, dib.dsBmih.biCompression);
5867 ok(!dib.dsBmih.biSizeImage, "%s: Got unexpected image size %lu.\n",
5868 test_data[i].name, dib.dsBmih.biSizeImage);
5869 ok(!dib.dsBmih.biXPelsPerMeter, "%s: Got unexpected horizontal resolution %ld.\n",
5870 test_data[i].name, dib.dsBmih.biXPelsPerMeter);
5871 ok(!dib.dsBmih.biYPelsPerMeter, "%s: Got unexpected vertical resolution %ld.\n",
5872 test_data[i].name, dib.dsBmih.biYPelsPerMeter);
5874 {
5875 ok(dib.dsBmih.biClrUsed == 256, "%s: Got unexpected used colour count %lu.\n",
5876 test_data[i].name, dib.dsBmih.biClrUsed);
5877 ok(dib.dsBmih.biClrImportant == 256, "%s: Got unexpected important colour count %lu.\n",
5878 test_data[i].name, dib.dsBmih.biClrImportant);
5879 }
5880 else
5881 {
5882 ok(!dib.dsBmih.biClrUsed, "%s: Got unexpected used colour count %lu.\n",
5883 test_data[i].name, dib.dsBmih.biClrUsed);
5884 ok(!dib.dsBmih.biClrImportant, "%s: Got unexpected important colour count %lu.\n",
5885 test_data[i].name, dib.dsBmih.biClrImportant);
5886 }
5887
5888 ok(dib.dsBitfields[0] == test_data[i].mask_r && dib.dsBitfields[1] == test_data[i].mask_g
5889 && dib.dsBitfields[2] == test_data[i].mask_b,
5890 "%s: Got unexpected colour masks 0x%08lx 0x%08lx 0x%08lx.\n",
5891 test_data[i].name, dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2]);
5892 ok(!dib.dshSection, "%s: Got unexpected section %p.\n", test_data[i].name, dib.dshSection);
5893 ok(!dib.dsOffset, "%s: Got unexpected offset %lu.\n", test_data[i].name, dib.dsOffset);
5894
5895 ret = BitBlt( create_desc.hDc, 0, 0, 4, 10, NULL, 0, 0, BLACKNESS );
5896 ok(ret, "Failed to blit.\n");
5897 ret = BitBlt( create_desc.hDc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS );
5898 ok(ret, "Failed to blit.\n");
5899
5900 /* Also test blitting to a regular bitmap */
5901 bmp_dc = CreateCompatibleDC( create_desc.hDeviceDc );
5902 ok(bmp_dc != NULL, "failed to create DC\n");
5903 bmp = CreateCompatibleBitmap( bmp_dc, create_desc.Width, create_desc.Height );
5904 ok(bmp != NULL, "failed to create bmp\n");
5905 bmp = SelectObject( bmp_dc, bmp );
5906 ret = BitBlt( bmp_dc, 0, 0, create_desc.Width, create_desc.Height, create_desc.hDc, 0, 0, SRCCOPY );
5907 ok(ret, "Failed to blit.\n");
5908
5909 destroy_desc.hDc = create_desc.hDc;
5910 destroy_desc.hBitmap = create_desc.hBitmap;
5911
5912 status = pD3DKMTDestroyDCFromMemory( NULL );
5913 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n", test_data[i].name, status);
5914 status = pD3DKMTDestroyDCFromMemory( &destroy_desc );
5915 ok(status == STATUS_SUCCESS, "%s: Got unexpected status %#lx.\n", test_data[i].name, status);
5916 status = pD3DKMTDestroyDCFromMemory( &destroy_desc );
5917 ok(status == STATUS_INVALID_PARAMETER, "%s: Got unexpected status %#lx.\n", test_data[i].name, status);
5918
5919 ret = DeleteDC( create_desc.hDeviceDc );
5920 ok(ret, "Failed to delete dc.\n");
5921
5922 for (y = 0, fail = FALSE; y < 12 && !fail; ++y)
5923 {
5924 for (x = 0; x < sizeof(*data) / (test_data[i].bit_count / 8) && !fail; ++x)
5925 {
5926 for (z = 0, colour = 0; z < test_data[i].bit_count / 8; ++z)
5927 {
5928 colour = colour << 8 | data[y][x * (test_data[i].bit_count / 8) + z];
5929 }
5930
5931 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5932 expected = 0xffffffff >> (32 - test_data[i].bit_count);
5933 else if (x < 4 && y < 7)
5934 expected = 0x00000000;
5935 else
5936 expected = 0xaaaaaaaa >> (32 - test_data[i].bit_count);
5937 ok(colour == expected, "%s: Got unexpected colour 0x%08lx at %u, %u, expected 0x%08lx.\n",
5938 test_data[i].name, colour, x, y, expected);
5939 if (colour != expected)
5940 fail = TRUE;
5941
5942 /* 'Xn' or 'An' formats don't successfully blit to the regular bmp */
5944 {
5945 pixel = GetPixel( bmp_dc, x, y );
5946 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5947 expected = 0x00ffffff;
5948 else if (x < create_desc.Width && y < create_desc.Height)
5949 expected = 0x00000000;
5950 else
5952 ok(pixel == expected, "%s: got 0x%08lx at %u, %u, expect 0x%08lx\n", test_data[i].name,
5953 pixel, x, y, expected);
5954 }
5955 }
5956 }
5957
5958 DeleteObject( SelectObject( bmp_dc, bmp ) );
5959 DeleteDC( bmp_dc );
5960 }
5961
5962 alloc_data = VirtualAlloc( NULL, 4096, MEM_COMMIT, PAGE_READWRITE );
5963 ok(!!alloc_data, "Failed to allocate memory, error %lu.\n", GetLastError());
5964
5965 create_desc.pMemory = alloc_data;
5966 create_desc.Format = D3DDDIFMT_A8R8G8B8;
5967 create_desc.Width = 16;
5968 create_desc.Height = 16;
5969 create_desc.Pitch = 16 * 4;
5970 create_desc.hDeviceDc = CreateCompatibleDC( NULL );
5971 create_desc.pColorTable = NULL;
5972
5973 status = pD3DKMTCreateDCFromMemory( &create_desc );
5974 ok(!status, "Got unexpected status %#lx.\n", status);
5975
5976 size = VirtualQuery( alloc_data, &memory_info, sizeof(memory_info) );
5977 ok(size == sizeof(memory_info), "Got unexpected size %u.\n", size);
5978 ok(memory_info.State == MEM_COMMIT, "Got state %#lx.\n", memory_info.State);
5979 ok(memory_info.Protect == PAGE_READWRITE, "Got protection %#lx.\n", memory_info.Protect);
5980
5981 destroy_desc.hDc = create_desc.hDc;
5982 destroy_desc.hBitmap = create_desc.hBitmap;
5983
5984 status = pD3DKMTDestroyDCFromMemory( &destroy_desc );
5985 ok(!status, "Got unexpected status %#lx.\n", status);
5986
5987 size = VirtualQuery( alloc_data, &memory_info, sizeof(memory_info) );
5988 ok(size == sizeof(memory_info), "Got unexpected size %u.\n", size);
5989 ok(memory_info.State == MEM_COMMIT, "Got state %#lx.\n", memory_info.State);
5990 ok(memory_info.Protect == PAGE_READWRITE, "Got protection %#lx.\n", memory_info.Protect);
5991
5992 ret = VirtualFree( alloc_data, 0, MEM_RELEASE );
5993 ok(ret, "Failed to free memory, error %lu.\n", GetLastError());
5994}
5995#endif /* __REACTOS__ */
5996
5997static void test_arcs(void)
5998{
5999 static const unsigned int dib_width = 100, dib_height = 100;
6000 unsigned int *bits;
6002 XFORM xform;
6003 BOOL ret;
6004 HPEN pen;
6005 HDC dc;
6006
6007 BITMAPINFO bitmap_info =
6008 {
6010 .bmiHeader.biWidth = dib_width,
6011 .bmiHeader.biHeight = dib_height,
6012 .bmiHeader.biBitCount = 32,
6013 .bmiHeader.biPlanes = 1,
6014 };
6015
6016 dc = CreateCompatibleDC( 0 );
6017 bitmap = CreateDIBSection( dc, &bitmap_info, DIB_RGB_COLORS, (void **)&bits, NULL, 0 );
6019 pen = CreatePen( PS_SOLID, 1, 0x111111 );
6020 SelectObject( dc, pen );
6021
6023
6024 /* Don't test exact pixels, since approximating the native arc drawing
6025 * algorithm is difficult. Do test that we're drawing to the right bounds,
6026 * though. */
6027
6028 memset( bits, 0, dib_width * dib_height * 4 );
6029 Arc( dc, 10, 10, 40, 25, 0, 15, 20, 0 );
6030
6031 for (unsigned int y = 9; y <= 26; ++y)
6032 {
6033 for (unsigned int x = 9; x <= 41; ++x)
6034 {
6035 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6036
6037 if (x < 10 || y < 10 || x >= 40 || y >= 25 || (x < 22 && y < 16))
6038 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6039
6040 if (((x == 24 || x == 25) && (y == 10 || y == 24)) /* top/bottom center */
6041 || ((x == 10 || x == 39) && y == 17)) /* left/right center */
6042 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6043 }
6044 }
6045
6046 memset( bits, 0, dib_width * dib_height * 4 );
6047 RoundRect( dc, 10, 10, 40, 25, 6, 9 );
6048
6049 for (unsigned int y = 9; y <= 26; ++y)
6050 {
6051 for (unsigned int x = 9; x <= 41; ++x)
6052 {
6053 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6054
6055 if (x < 10 || y < 10 || x >= 40 || y >= 25
6056 || ((x == 10 || x == 39) && (y == 10 || y == 24))) /* corners */
6057 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6058
6059 if (((x >= 13 && x < 37) && (y == 10 || y == 24)) /* top/bottom edge */
6060 || ((y >= 14 && y < 21) && (x == 10 || x == 39))) /* left/right edge */
6061 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6062 }
6063 }
6064
6065 /* Same round rect, but with the ellipse width and height inverted. */
6066 memset( bits, 0, dib_width * dib_height * 4 );
6067 RoundRect( dc, 10, 10, 40, 25, -6, -9 );
6068
6069 for (unsigned int y = 9; y <= 26; ++y)
6070 {
6071 for (unsigned int x = 9; x <= 41; ++x)
6072 {
6073 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6074
6075 if (x < 10 || y < 10 || x >= 40 || y >= 25
6076 || ((x == 10 || x == 39) && (y == 10 || y == 24))) /* corners */
6077 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6078
6079 if (((x >= 13 && x < 37) && (y == 10 || y == 24)) /* top/bottom edge */
6080 || ((y >= 14 && y < 21) && (x == 10 || x == 39))) /* left/right edge */
6081 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6082 }
6083 }
6084
6085 /* Round rect with ellipse sizes larger than the rectangle dimensions.
6086 * This draws the whole ellipse, effectively clamping to the relevant dimensions. */
6087
6088 memset( bits, 0, dib_width * dib_height * 4 );
6089 RoundRect( dc, 10, 10, 40, 25, 6, 20 );
6090
6091 for (unsigned int y = 9; y <= 26; ++y)
6092 {
6093 for (unsigned int x = 9; x <= 41; ++x)
6094 {
6095 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6096
6097 if (x < 10 || y < 10 || x >= 40 || y >= 25)
6098 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6099
6100 if (((x >= 13 && x < 37) && (y == 10 || y == 24)) /* top/bottom edge */
6101 || ((x == 10 || x == 39) && y == 17)) /* left/right center */
6102 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6103 }
6104 }
6105
6106 /* Round rect with a 1-pixel ellipse. */
6107
6108 memset( bits, 0, dib_width * dib_height * 4 );
6109 RoundRect( dc, 10, 10, 40, 25, 1, 1 );
6110
6111 for (unsigned int y = 9; y <= 26; ++y)
6112 {
6113 for (unsigned int x = 9; x <= 41; ++x)
6114 {
6115 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6116
6117 if (x < 10 || y < 10 || x >= 40 || y >= 25)
6118 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6119
6120 if (((x >= 11 && x < 39) && (y == 10 || y == 24)) /* top/bottom edge */
6121 || ((x == 10 || x == 39) && (y >= 11 && y < 24))) /* left/right edge */
6122 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6123 }
6124 }
6125
6126 /* Round rect with a 0-pixel ellipse, which is identical to a simple rect. */
6127
6128 memset( bits, 0, dib_width * dib_height * 4 );
6129 RoundRect( dc, 10, 10, 40, 25, 0, 0 );
6130
6131 for (unsigned int y = 9; y <= 26; ++y)
6132 {
6133 for (unsigned int x = 9; x <= 41; ++x)
6134 {
6135 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6136
6137 if (((x >= 10 && x < 40) && (y == 10 || y == 24)) /* top/bottom edge */
6138 || ((x == 10 || x == 39) && (y >= 10 && y < 25))) /* left/right edge */
6139 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6140 else
6141 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6142 }
6143 }
6144
6145 /* 0-pixel arc. */
6146
6147 memset( bits, 0, dib_width * dib_height * 4 );
6148 ret = Arc( dc, 10, 10, 40, 10, 0, 1, 1, 0 );
6149 ok(ret == TRUE, "Got %d.\n", ret);
6150
6151 for (unsigned int y = 9; y <= 11; ++y)
6152 {
6153 for (unsigned int x = 9; x <= 41; ++x)
6154 {
6155 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6156
6157 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6158 }
6159 }
6160
6161 /* Arc with identical start/end points draws the whole ellipse. */
6162
6163 memset( bits, 0, dib_width * dib_height * 4 );
6164 Arc( dc, 10, 10, 40, 25, 0, 1, 0, 1 );
6165
6166 for (unsigned int y = 9; y <= 26; ++y)
6167 {
6168 for (unsigned int x = 9; x <= 41; ++x)
6169 {
6170 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6171
6172 if (x < 10 || y < 10 || x >= 40 || y >= 25)
6173 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6174
6175 if (((x == 24 || x == 25) && (y == 10 || y == 24)) /* top/bottom center */
6176 || ((x == 10 || x == 39) && y == 17)) /* left/right center */
6177 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6178 }
6179 }
6180
6181 /* Flipped arc direction. */
6182
6184
6185 memset( bits, 0, dib_width * dib_height * 4 );
6186 Arc( dc, 10, 10, 40, 25, 20, 0, 0, 15 );
6187
6188 for (unsigned int y = 9; y <= 26; ++y)
6189 {
6190 for (unsigned int x = 9; x <= 41; ++x)
6191 {
6192 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6193
6194 if (x < 10 || y < 10 || x >= 40 || y >= 25 || (x < 22 && y < 16))
6195 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6196
6197 if (((x == 24 || x == 25) && (y == 10 || y == 24)) /* top/bottom center */
6198 || ((x == 10 || x == 39) && y == 17)) /* left/right center */
6199 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6200 }
6201 }
6202
6203 /* Flip the arc rect. */
6204
6205 memset( bits, 0, dib_width * dib_height * 4 );
6206 Arc( dc, 40, 10, 10, 25, 20, 0, 0, 15 );
6207
6208 for (unsigned int y = 9; y <= 26; ++y)
6209 {
6210 for (unsigned int x = 9; x <= 41; ++x)
6211 {
6212 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6213
6214 if (x < 10 || y < 10 || x >= 40 || y >= 25 || (x < 22 && y < 16))
6215 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6216
6217 if (((x == 24 || x == 25) && (y == 10 || y == 24)) /* top/bottom center */
6218 || ((x == 10 || x == 39) && y == 17)) /* left/right center */
6219 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6220 }
6221 }
6222
6223 /* Test with GM_ADVANCED. */
6224
6226
6227 memset( bits, 0, dib_width * dib_height * 4 );
6228 Arc( dc, 10, 10, 40, 25, 20, 0, 0, 14 );
6229
6230 for (unsigned int y = 9; y <= 26; ++y)
6231 {
6232 for (unsigned int x = 9; x <= 41; ++x)
6233 {
6234 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6235
6236 if (x < 10 || y < 10 || x > 40 || y > 25 || (x < 22 && y < 16))
6237 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6238
6239todo_wine_if (y == 25 || x == 40)
6240{
6241 if ((x == 25 && (y == 10 || y == 25)) /* top/bottom center */
6242 || ((x == 10 || x == 40) && (y == 17 || y == 18))) /* left/right center */
6243 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6244}
6245 }
6246 }
6247
6248 memset( bits, 0, dib_width * dib_height * 4 );
6249 RoundRect( dc, 10, 10, 40, 25, 6, 9 );
6250
6251 for (unsigned int y = 9; y <= 26; ++y)
6252 {
6253 for (unsigned int x = 9; x <= 41; ++x)
6254 {
6255 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6256
6257 if (x < 10 || y < 10 || x > 40 || y > 25)
6258 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6259
6260todo_wine_if (y == 25 || x == 40)
6261{
6262 if (((x >= 13 && x <= 37) && (y == 10 || y == 25)) /* top/bottom edge */
6263 || ((y >= 14 && y <= 21) && (x == 10 || x == 40))) /* left/right edge */
6264 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6265}
6266 }
6267 }
6268
6269 /* Flip the world transform. */
6270
6271 memset( &xform, 0, sizeof(xform) );
6272 xform.eM11 = 1.0f;
6273 xform.eM22 = -1.0f;
6274 xform.eDy = 35.0f;
6275 SetWorldTransform( dc, &xform );
6276
6277 memset( bits, 0, dib_width * dib_height * 4 );
6278 Arc( dc, 10, 10, 40, 25, 20, 0, 0, 14 );
6279
6280 for (unsigned int y = 9; y <= 26; ++y)
6281 {
6282 for (unsigned int x = 9; x <= 41; ++x)
6283 {
6284 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6285
6286 if (x < 10 || y < 10 || x > 40 || y > 25 || (x < 22 && y > 19))
6287 todo_wine_if (colour) ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6288
6290{
6291 if ((x == 25 && (y == 10 || y == 25)) /* top/bottom center */
6292 || ((x == 10 || x == 40) && (y == 17 || y == 18))) /* left/right center */
6293 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6294}
6295 }
6296 }
6297
6298 memset( bits, 0, dib_width * dib_height * 4 );
6299 RoundRect( dc, 10, 10, 40, 25, 6, 9 );
6300
6301 for (unsigned int y = 9; y <= 26; ++y)
6302 {
6303 for (unsigned int x = 9; x <= 41; ++x)
6304 {
6305 int colour = bits[(dib_height - 1 - y) * dib_width + x];
6306
6307 if (x < 10 || y < 10 || x > 40 || y > 25)
6308 ok(!colour, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6309
6310todo_wine_if (y == 25 || x == 40)
6311{
6312 if (((x >= 13 && x <= 37) && (y == 10 || y == 25)) /* top/bottom edge */
6313 || ((y >= 14 && y <= 21) && (x == 10 || x == 40))) /* left/right edge */
6314 ok(colour == 0x111111, "Got unexpected colour %08x at (%u, %u).\n", colour, x, y);
6315}
6316 }
6317 }
6318
6320 DeleteObject( pen );
6321 DeleteDC( dc );
6322}
6323
6325{
6326 HMODULE hdll;
6327
6328 hdll = GetModuleHandleA("gdi32.dll");
6329#ifndef __REACTOS__ /* CORE-11331 */
6330 pD3DKMTCreateDCFromMemory = (void *)GetProcAddress( hdll, "D3DKMTCreateDCFromMemory" );
6331 pD3DKMTDestroyDCFromMemory = (void *)GetProcAddress( hdll, "D3DKMTDestroyDCFromMemory" );
6332#endif
6333 pGdiAlphaBlend = (void *)GetProcAddress( hdll, "GdiAlphaBlend" );
6334 pGdiGradientFill = (void *)GetProcAddress( hdll, "GdiGradientFill" );
6335
6340 test_bitmap();
6342 test_bmBits();
6352 test_BitBlt();
6360 test_clipping();
6371#ifndef __REACTOS__ /* CORE-11331 */
6373#endif
6374 test_arcs();
6375}
#define DIBINDEX(n)
Definition: NtGdiLineTo.c:11
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: bootvid.c:52
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
LONG NTSTATUS
Definition: precomp.h:26
#define index(s, c)
Definition: various.h:29
#define ARRAY_SIZE(A)
Definition: main.h:20
DWORD GetPixel(LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
Definition: blt.cpp:2
HBITMAP hbmp
Definition: arc.h:55
RECT rect
Definition: combotst.c:67
HDC dc
Definition: cylfrac.c:34
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD bpp
Definition: surface.c:185
unsigned int idx
Definition: utils.c:41
#define NTSTATUS
Definition: precomp.h:19
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define MAX_PATH
Definition: compat.h:34
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define FILE_SHARE_READ
Definition: compat.h:136
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:91
#define assert(_expr)
Definition: assert.h:32
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Height *Stride) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Stride)
Definition: common.c:42
#define BI_RLE4
Definition: precomp.h:45
#define RGB(r, g, b)
Definition: precomp.h:67
ULONG RGBQUAD
Definition: precomp.h:47
return ret
Definition: mutex.c:146
#define abs(i)
Definition: fconv.c:206
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
for(i=0;i< ARRAY_SIZE(offsets);i++)
pKey DeleteObject()
DWORD WINAPI SetLayout(_In_ HDC hdc, _In_ DWORD dwLayout)
Definition: coord.c:780
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint color
Definition: glext.h:6243
const GLubyte * c
Definition: glext.h:8905
GLuint index
Definition: glext.h:6031
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLboolean GLboolean g
Definition: glext.h:6204
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
GLuint GLuint num
Definition: glext.h:9618
GLdouble GLdouble z
Definition: glext.h:5874
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define ds
Definition: i386-dis.c:443
@ picture
Definition: id3.c:95
#define bits
Definition: infblock.c:15
const char * filename
Definition: ioapi.h:137
uint32_t entry
Definition: isohybrid.c:63
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
#define win_skip
Definition: minitest.h:67
int winetest_interactive
#define todo_wine_if(is_todo)
Definition: minitest.h:81
#define todo_wine
Definition: minitest.h:80
#define ZeroMemory
Definition: minwinbase.h:31
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define BI_BITFIELDS
Definition: mmreg.h:507
#define CREATE_ALWAYS
Definition: disk.h:72
static PVOID ptr
Definition: dispmode.c:27
BITMAP bmp
Definition: alphablend.c:62
#define AC_SRC_ALPHA
Definition: alphablend.c:9
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static void test_size(void)
Definition: monthcal.c:1559
BOOL expected
Definition: store.c:2000
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1204
static void test_StretchDIBits(void)
Definition: bitmap.c:3504
static void test_GetDIBits_BI_BITFIELDS(void)
Definition: bitmap.c:2435
static TRIVERTEX ULONG
Definition: bitmap.c:44
#define test_mono_1x1_bmp(a)
Definition: bitmap.c:2779
static void test_clipping(void)
Definition: bitmap.c:3983
static int get_dib_stride(int width, int bpp)
Definition: bitmap.c:51
static void test_createdibitmap(void)
Definition: bitmap.c:126
static void test_dibsections(void)
Definition: bitmap.c:433
static void test_GetDIBits(void)
Definition: bitmap.c:2029
static void test_get16dibits(void)
Definition: bitmap.c:2982
static HDC
Definition: bitmap.c:43
static void test_bitmapinfoheadersize(void)
Definition: bitmap.c:2883
static void test_bmBits(void)
Definition: bitmap.c:1789
static COLORREF get_nearest(int r, int g, int b)
Definition: bitmap.c:1606
static void check_StretchDIBits_pixel(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer, DWORD dwRop, UINT32 expected, int line)
Definition: bitmap.c:3451
static void test_GetDIBits_selected_DDB(BOOL monochrome)
Definition: bitmap.c:1916
static void test_SetDIBits_RLE4(void)
Definition: bitmap.c:4845
static void test_mono_dibsection(void)
Definition: bitmap.c:1303
static void test_mono_bitmap(void)
Definition: bitmap.c:1729
static BOOL is_black_pen(COLORREF fg, COLORREF bg, int r, int g, int b)
Definition: bitmap.c:1611
static void test_bitmap_colors(HDC hdc, COLORREF fg, COLORREF bg, int r, int g, int b)
Definition: bitmap.c:1617
static void test_dib_bits_access(HBITMAP hdib, void *bits)
Definition: bitmap.c:374
static BLENDFUNCTION
Definition: bitmap.c:43
static void test_select_object(void)
Definition: bitmap.c:2663
static void test_GetDIBits_selected_DIB(UINT bpp)
Definition: bitmap.c:1807
static void test_dib_formats(void)
Definition: bitmap.c:914
static int
Definition: bitmap.c:43
static int get_bitmap_stride(int width, int bpp)
Definition: bitmap.c:46
static void test_GdiAlphaBlend(void)
Definition: bitmap.c:3645
static void test_32bit_ddb(void)
Definition: bitmap.c:4026
static void test_D3DKMTCreateDCFromMemory(void)
Definition: bitmap.c:5702
static void test_arcs(void)
Definition: bitmap.c:5997
#define test_color(hdc, color, exp)
Definition: bitmap.c:371
static void test_BitBlt(void)
Definition: bitmap.c:3033
static void test_bitmap(void)
Definition: bitmap.c:1497
static INT check_StretchDIBits_stretch(HDC hdcDst, UINT32 *dstBuffer, UINT32 *srcBuffer, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT32 expected[4], int line)
Definition: bitmap.c:3474
static void test_SetDIBitsToDevice_RLE8(void)
Definition: bitmap.c:5470
static void test_GetSetDIBits_rtl(void)
Definition: bitmap.c:4232
static void test_SetDIBitsToDevice(void)
Definition: bitmap.c:5050
static void test_StretchBlt(void)
Definition: bitmap.c:3129
static void _test_color(int line, HDC hdc, COLORREF color, COLORREF exp)
Definition: bitmap.c:361
static void check_BitBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer, DWORD dwRop, UINT32 expected, int line)
Definition: bitmap.c:3022
static void test_GetDIBits_top_down(int bpp)
Definition: bitmap.c:4143
static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHEADER *bmih)
Definition: bitmap.c:62
static void test_SetDIBits(void)
Definition: bitmap.c:4612
static void test_CreateBitmap(void)
Definition: bitmap.c:2781
static void setup_picture(char *picture, int bpp)
Definition: bitmap.c:4121
static void test_dib_info(HBITMAP hbm, const void *bits, const BITMAPINFOHEADER *bmih)
Definition: bitmap.c:261
static void test_GetDIBits_scanlines(void)
Definition: bitmap.c:4293
static void test_mono_1x1_bmp_dbg(HBITMAP hbmp, int line)
Definition: bitmap.c:2754
static int get_dib_image_size(const BITMAPINFO *info)
Definition: bitmap.c:56
static void test_SetDIBits_RLE8(void)
Definition: bitmap.c:4900
static void check_StretchBlt_pixel(HDC hdcDst, HDC hdcSrc, UINT32 *dstBuffer, UINT32 *srcBuffer, DWORD dwRop, UINT32 expected, int line)
Definition: bitmap.c:3099
static void test_GdiGradientFill(void)
Definition: bitmap.c:3870
static void check_StretchBlt_stretch(HDC hdcDst, HDC hdcSrc, BITMAPINFO *dst_info, UINT32 *dstBuffer, UINT32 *srcBuffer, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT32 *expected, int line)
Definition: bitmap.c:3110
#define LAYOUT_LTR
Definition: dc.c:33
static const BYTE rle8_data[20]
Definition: dib.c:1611
static HRGN hRgn
Definition: mapping.c:32
static HPALETTE palette
Definition: clipboard.c:1457
DWORD exp
Definition: msg.c:18625
unsigned int UINT
Definition: ndis.h:50
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define MEM_PRIVATE
Definition: nt_native.h:1321
#define BOOL
Definition: nt_native.h:43
#define MEM_RELEASE
Definition: nt_native.h:1319
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_COMMIT
Definition: nt_native.h:1316
#define OBJ_BITMAP
Definition: objidl.idl:1020
#define OBJ_PAL
Definition: objidl.idl:1018
#define OBJ_MEMDC
Definition: objidl.idl:1023
DWORD * PDWORD
Definition: pedump.c:68
#define BITMAP
Definition: pedump.c:503
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
#define calloc
Definition: rosglue.h:14
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
static PVOID hdll
Definition: shimdbg.c:126
LONG biYPelsPerMeter
Definition: amvideo.idl:38
DWORD biCompression
Definition: amvideo.idl:35
LONG biXPelsPerMeter
Definition: amvideo.idl:37
DWORD biSizeImage
Definition: amvideo.idl:36
BITMAPCOREHEADER bmciHeader
Definition: wingdi.h:1899
RGBTRIPLE bmciColors[1]
Definition: wingdi.h:1900
BYTE BlendOp
Definition: wingdi.h:3205
BYTE BlendFlags
Definition: wingdi.h:3206
BYTE AlphaFormat
Definition: wingdi.h:3208
BYTE SourceConstantAlpha
Definition: wingdi.h:3207
PALETTEENTRY * pColorTable
Definition: d3dkmthk.h:167
FLOAT eDy
Definition: wingdi.h:2172
FLOAT eM11
Definition: wingdi.h:2167
FLOAT eM22
Definition: wingdi.h:2170
Definition: uimain.c:89
Definition: fci.c:127
Definition: format.c:58
Definition: parser.c:49
Definition: name.c:39
Definition: ps.c:97
ULONG biClrImportant
Definition: precomp.h:40
USHORT biBitCount
Definition: precomp.h:34
LONG biYPelsPerMeter
Definition: precomp.h:38
ULONG biCompression
Definition: precomp.h:35
LONG biXPelsPerMeter
Definition: precomp.h:37
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
RGBQUAD bmiColors[1]
Definition: wingdi.h:1923
LONG bmHeight
Definition: wingdi.h:1869
LONG bmWidth
Definition: wingdi.h:1868
LONG bmType
Definition: wingdi.h:1867
LONG bmWidthBytes
Definition: wingdi.h:1870
LPVOID bmBits
Definition: wingdi.h:1873
WORD bmPlanes
Definition: wingdi.h:1871
WORD bmBitsPixel
Definition: wingdi.h:1872
DWORD dsBitfields[3]
Definition: wingdi.h:2117
DWORD dsOffset
Definition: wingdi.h:2119
HANDLE dshSection
Definition: wingdi.h:2118
BITMAP dsBm
Definition: wingdi.h:2115
BITMAPINFOHEADER dsBmih
Definition: wingdi.h:2116
WORD palNumEntries
Definition: wingdi.h:2280
WORD palVersion
Definition: wingdi.h:2279
UCHAR rgbReserved
Definition: bootanim.c:106
UCHAR rgbBlue
Definition: bootanim.c:103
UCHAR rgbRed
Definition: bootanim.c:105
UCHAR rgbGreen
Definition: bootanim.c:104
static UINT width_bytes(UINT width, UINT bpp)
Definition: tiffformat.c:859
eMaj lines
Definition: tritemp.h:206
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
int32_t INT
Definition: typedefs.h:58
uint32_t UINT32
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define BI_RGB
Definition: uefivid.c:46
static int __cdecl compr(const void *a, const void *b)
Definition: bidi.c:641
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:211
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
UINT WINAPI GetPaletteEntries(HPALETTE hpal, UINT iStartIndex, UINT cEntries, LPPALETTEENTRY ppe)
Definition: palette.c:64
UINT WINAPI GetDIBColorTable(HDC hDC, UINT iStartIndex, UINT cEntries, RGBQUAD *pColors)
Definition: palette.c:123
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ ULONG _In_ ULONG rgb
Definition: winddi.h:3521
DWORD COLORREF
Definition: windef.h:100
#define WINAPI
Definition: msvc.h:6
@ D3DDDIFMT_A8R8G8B8
Definition: d3dukmdt.h:34
@ D3DDDIFMT_V8U8
Definition: d3dukmdt.h:55
@ D3DDDIFMT_L8
Definition: d3dukmdt.h:52
@ D3DDDIFMT_DXT2
Definition: d3dukmdt.h:129
@ D3DDDIFMT_P8
Definition: d3dukmdt.h:51
@ D3DDDIFMT_A8B8G8R8
Definition: d3dukmdt.h:45
@ D3DDDIFMT_A2R10G10B10
Definition: d3dukmdt.h:48
@ D3DDDIFMT_R5G6B5
Definition: d3dukmdt.h:36
@ D3DDDIFMT_R8G8B8
Definition: d3dukmdt.h:33
@ D3DDDIFMT_A8L8
Definition: d3dukmdt.h:53
@ D3DDDIFMT_DXT3
Definition: d3dukmdt.h:130
@ D3DDDIFMT_DXT4
Definition: d3dukmdt.h:131
@ D3DDDIFMT_R3G3B2
Definition: d3dukmdt.h:40
@ D3DDDIFMT_DXT5
Definition: d3dukmdt.h:132
@ D3DDDIFMT_X8R8G8B8
Definition: d3dukmdt.h:35
@ D3DDDIFMT_A1R5G5B5
Definition: d3dukmdt.h:38
@ D3DDDIFMT_Q8W8V8U8
Definition: d3dukmdt.h:58
@ D3DDDIFMT_A2B10G10R10
Definition: d3dukmdt.h:44
@ D3DDDIFMT_X1R5G5B5
Definition: d3dukmdt.h:37
@ D3DDDIFMT_DXT1
Definition: d3dukmdt.h:128
enum _D3DDDIFORMAT D3DDDIFORMAT
#define BLACKNESS
Definition: wingdi.h:323
int WINAPI SetMapMode(_In_ HDC, _In_ int)
#define PALETTEINDEX(i)
Definition: wingdi.h:3389
#define DIB_RGB_COLORS
Definition: wingdi.h:367
int WINAPI SetDIBitsToDevice(_In_ HDC, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ int, _In_ int, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)
#define PATPAINT
Definition: wingdi.h:336
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
int WINAPI SetGraphicsMode(_In_ HDC, _In_ int)
Definition: dc.c:1233
#define DEFAULT_PALETTE
Definition: wingdi.h:913
#define GM_ADVANCED
Definition: wingdi.h:865
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:999
HRGN WINAPI CreateRectRgn(_In_ int, _In_ int, _In_ int, _In_ int)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
#define PATINVERT
Definition: wingdi.h:328
#define WHITENESS
Definition: wingdi.h:337
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
BOOL WINAPI SetViewportExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
Definition: coord.c:465
int WINAPI SetDIBits(_In_opt_ HDC, _In_ HBITMAP, _In_ UINT, _In_ UINT, _In_ CONST VOID *, _In_ CONST BITMAPINFO *, _In_ UINT)
#define AC_SRC_OVER
Definition: wingdi.h:1369
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HBITMAP WINAPI CreateBitmapIndirect(_In_ const BITMAP *pbm)
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
struct tagLOGPALETTE LOGPALETTE
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
int WINAPI SetArcDirection(_In_ HDC, _In_ int)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
#define MM_ANISOTROPIC
Definition: wingdi.h:867
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
struct tagBITMAPINFO * LPBITMAPINFO
#define DIB_PAL_COLORS
Definition: wingdi.h:366
#define PALETTERGB(r, g, b)
Definition: wingdi.h:3388
BOOL WINAPI SetWindowExtEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPSIZE)
#define SRCERASE
Definition: wingdi.h:326
BOOL WINAPI StretchBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define CLR_INVALID
Definition: wingdi.h:883
#define SRCINVERT
Definition: wingdi.h:329
#define SRCCOPY
Definition: wingdi.h:333
#define LAYOUT_RTL
Definition: wingdi.h:1371
LONG WINAPI GetBitmapBits(_In_ HBITMAP hbit, _In_ LONG cb, _Out_writes_bytes_(cb) LPVOID lpvBits)
BOOL WINAPI ScaleWindowExtEx(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _Out_opt_ LPSIZE)
#define PATCOPY
Definition: wingdi.h:335
#define BI_JPEG
Definition: wingdi.h:38
#define DSTINVERT
Definition: wingdi.h:327
#define SRCPAINT
Definition: wingdi.h:334
#define MM_ISOTROPIC
Definition: wingdi.h:870
#define PLANES
Definition: wingdi.h:721
#define MERGEPAINT
Definition: wingdi.h:331
#define MM_TEXT
Definition: wingdi.h:873
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define MERGECOPY
Definition: wingdi.h:332
#define BLACK_BRUSH
Definition: wingdi.h:896
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
UINT WINAPI SetDIBColorTable(_In_ HDC hdc, _In_ UINT iStart, _In_ UINT cEntries, _In_reads_(cEntries) const RGBQUAD *prgbq)
BOOL WINAPI SetPixelV(_In_ HDC, _In_ int, _In_ int, _In_ COLORREF)
#define BITSPIXEL
Definition: wingdi.h:720
COLORREF WINAPI GetNearestColor(_In_ HDC, _In_ COLORREF)
struct tagBITMAPINFO BITMAPINFO
struct _BITMAPCOREINFO BITMAPCOREINFO
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define CBM_INIT
Definition: wingdi.h:365
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:917
#define BI_PNG
Definition: wingdi.h:39
#define NOTSRCCOPY
Definition: wingdi.h:325
BOOL WINAPI SetWorldTransform(_In_ HDC, _In_ const XFORM *)
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
#define BI_RLE8
Definition: wingdi.h:35
BOOL WINAPI RoundRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
int WINAPI SelectClipRgn(_In_ HDC, _In_opt_ HRGN)
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
#define AD_CLOCKWISE
Definition: wingdi.h:668
#define NOTSRCERASE
Definition: wingdi.h:324
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
#define PS_SOLID
Definition: wingdi.h:586
HBITMAP WINAPI CreateDiscardableBitmap(_In_ HDC, _In_ int, _In_ int)
#define SRCAND
Definition: wingdi.h:330
int WINAPI StretchDIBits(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_opt_ const VOID *, _In_ const BITMAPINFO *, _In_ UINT, _In_ DWORD)
HBRUSH WINAPI CreatePatternBrush(_In_ HBITMAP)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC hdcSrc
Definition: xlate.c:32
static HDC hdcDst
Definition: xlate.c:32
unsigned char BYTE
Definition: xxhash.c:193