2 * Copyright 2012 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
31 static IWICImagingFactory *factory;
33 static const char *debugstr_guid(const GUID *guid)
37 if (!guid) return "(null)";
38 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
39 guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
40 guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
41 guid->Data4[5], guid->Data4[6], guid->Data4[7]);
45 static void test_createbitmap(void)
50 IWICBitmapLock *lock, *lock2;
51 WICBitmapPaletteType palettetype;
54 const BYTE bitmap_data[27] = {
55 128,128,255, 128,128,128, 128,255,128,
56 128,128,128, 128,128,128, 255,255,255,
57 255,128,128, 255,255,255, 255,255,255};
58 BYTE returned_data[27] = {0};
59 BYTE *lock_buffer=NULL, *base_lock_buffer=NULL;
60 UINT lock_buffer_size=0;
61 UINT lock_buffer_stride=0;
62 WICPixelFormatGUID pixelformat = {0};
63 UINT width=0, height=0;
64 double dpix=10.0, dpiy=10.0;
65 int can_lock_null = 1;
67 hr = IWICImagingFactory_CreateBitmap(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
68 WICBitmapCacheOnLoad, &bitmap);
69 ok(hr == S_OK, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr);
74 hr = IWICImagingFactory_CreatePalette(factory, &palette);
75 ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
77 /* Palette is unavailable until explicitly set */
78 hr = IWICBitmap_CopyPalette(bitmap, palette);
79 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
81 hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray256, FALSE);
82 ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
84 hr = IWICBitmap_SetPalette(bitmap, palette);
85 ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
87 hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray4, FALSE);
88 ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
90 hr = IWICBitmap_CopyPalette(bitmap, palette);
91 ok(hr == S_OK, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
93 hr = IWICPalette_GetType(palette, &palettetype);
94 ok(hr == S_OK, "IWICPalette_GetType failed hr=%x\n", hr);
95 ok(palettetype == WICBitmapPaletteTypeFixedGray256,
96 "expected WICBitmapPaletteTypeFixedGray256, got %x\n", palettetype);
98 IWICPalette_Release(palette);
100 /* pixel data is initially zeroed */
101 hr = IWICBitmap_CopyPixels(bitmap, NULL, 9, 27, returned_data);
102 ok(hr == S_OK, "IWICBitmap_CopyPixels failed hr=%x\n", hr);
105 ok(returned_data[i] == 0, "returned_data[%i] == %i\n", i, returned_data[i]);
107 /* Invalid lock rects */
111 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
112 ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
113 if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
117 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
118 ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
119 if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
123 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
124 ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
125 if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
129 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
130 ok(hr == E_INVALIDARG, "IWICBitmap_Lock failed hr=%x\n", hr);
131 if (SUCCEEDED(hr)) IWICBitmapLock_Release(lock);
134 hr = IWICBitmap_Lock(bitmap, NULL, WICBitmapLockRead, &lock);
135 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* winxp */, "IWICBitmap_Lock failed hr=%x\n", hr);
139 /* entire bitmap is locked */
140 hr = IWICBitmapLock_GetSize(lock, &width, &height);
141 ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
142 ok(width == 3, "got %d, expected 3\n", width);
143 ok(height == 3, "got %d, expected 3\n", height);
145 IWICBitmapLock_Release(lock);
150 /* lock with a valid rect */
152 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock);
153 ok(hr == S_OK, "IWICBitmap_Lock failed hr=%x\n", hr);
156 hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
157 ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
158 /* stride is divisible by 4 */
159 ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
161 hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
162 ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
163 /* buffer size does not include padding from the last row */
164 ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
165 ok(lock_buffer != NULL, "got NULL data pointer\n");
166 base_lock_buffer = lock_buffer;
168 hr = IWICBitmapLock_GetPixelFormat(lock, &pixelformat);
169 ok(hr == S_OK, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr);
170 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
172 hr = IWICBitmapLock_GetSize(lock, &width, &height);
173 ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
174 ok(width == 3, "got %d, expected 3\n", width);
175 ok(height == 3, "got %d, expected 3\n", height);
177 /* We can have multiple simultaneous read locks */
178 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock2);
179 ok(hr == S_OK, "IWICBitmap_Lock failed hr=%x\n", hr);
183 hr = IWICBitmapLock_GetDataPointer(lock2, &lock_buffer_size, &lock_buffer);
184 ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
185 ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
186 ok(lock_buffer == base_lock_buffer, "got %p, expected %p\n", lock_buffer, base_lock_buffer);
188 IWICBitmapLock_Release(lock2);
191 if (can_lock_null) /* this hangs on xp/vista */
193 /* But not a read and a write lock */
194 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock2);
195 ok(hr == WINCODEC_ERR_ALREADYLOCKED, "IWICBitmap_Lock failed hr=%x\n", hr);
198 /* But we don't need a write lock to write */
199 if (base_lock_buffer)
202 memcpy(base_lock_buffer + lock_buffer_stride*i, bitmap_data + i*9, 9);
205 IWICBitmapLock_Release(lock);
208 /* test that the data we wrote is returned by CopyPixels */
209 hr = IWICBitmap_CopyPixels(bitmap, NULL, 9, 27, returned_data);
210 ok(hr == S_OK, "IWICBitmap_CopyPixels failed hr=%x\n", hr);
213 ok(returned_data[i] == bitmap_data[i], "returned_data[%i] == %i\n", i, returned_data[i]);
215 /* try a valid partial rect, and write mode */
220 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock);
221 ok(hr == S_OK, "IWICBitmap_Lock failed hr=%x\n", hr);
225 if (can_lock_null) /* this hangs on xp/vista */
227 /* Can't lock again while locked for writing */
228 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock2);
229 ok(hr == WINCODEC_ERR_ALREADYLOCKED, "IWICBitmap_Lock failed hr=%x\n", hr);
231 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock2);
232 ok(hr == WINCODEC_ERR_ALREADYLOCKED, "IWICBitmap_Lock failed hr=%x\n", hr);
235 hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
236 ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
237 ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
239 hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
240 ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
241 ok(lock_buffer_size == 15, "got %i, expected 15\n", lock_buffer_size);
242 ok(lock_buffer == base_lock_buffer+6, "got %p, expected %p+6\n", lock_buffer, base_lock_buffer);
244 hr = IWICBitmapLock_GetPixelFormat(lock, &pixelformat);
245 ok(hr == S_OK, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr);
246 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
248 hr = IWICBitmapLock_GetSize(lock, &width, &height);
249 ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
250 ok(width == 1, "got %d, expected 1\n", width);
251 ok(height == 2, "got %d, expected 2\n", height);
253 IWICBitmapLock_Release(lock);
256 hr = IWICBitmap_GetPixelFormat(bitmap, &pixelformat);
257 ok(hr == S_OK, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr);
258 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
260 hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy);
261 ok(hr == S_OK, "IWICBitmap_GetResolution failed hr=%x\n", hr);
262 ok(dpix == 0.0, "got %f, expected 0.0\n", dpix);
263 ok(dpiy == 0.0, "got %f, expected 0.0\n", dpiy);
265 hr = IWICBitmap_SetResolution(bitmap, 12.0, 34.0);
266 ok(hr == S_OK, "IWICBitmap_SetResolution failed hr=%x\n", hr);
268 hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy);
269 ok(hr == S_OK, "IWICBitmap_GetResolution failed hr=%x\n", hr);
270 ok(dpix == 12.0, "got %f, expected 12.0\n", dpix);
271 ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy);
273 hr = IWICBitmap_GetSize(bitmap, &width, &height);
274 ok(hr == S_OK, "IWICBitmap_GetSize failed hr=%x\n", hr);
275 ok(width == 3, "got %d, expected 3\n", width);
276 ok(height == 3, "got %d, expected 3\n", height);
278 IWICBitmap_Release(bitmap);
281 static void test_createbitmapfromsource(void)
284 IWICBitmap *bitmap, *bitmap2;
285 IWICPalette *palette;
286 IWICBitmapLock *lock;
289 const BYTE bitmap_data[27] = {
290 128,128,255, 128,128,128, 128,255,128,
291 128,128,128, 128,128,128, 255,255,255,
292 255,128,128, 255,255,255, 255,255,255};
293 BYTE returned_data[27] = {0};
294 BYTE *lock_buffer=NULL;
295 UINT lock_buffer_stride=0;
296 UINT lock_buffer_size=0;
297 WICPixelFormatGUID pixelformat = {0};
298 UINT width=0, height=0;
299 double dpix=10.0, dpiy=10.0;
301 WICBitmapPaletteType palette_type;
303 hr = IWICImagingFactory_CreateBitmap(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
304 WICBitmapCacheOnLoad, &bitmap);
305 ok(hr == S_OK, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr);
310 hr = IWICImagingFactory_CreatePalette(factory, &palette);
311 ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
313 hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray256, FALSE);
314 ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
316 hr = IWICBitmap_SetPalette(bitmap, palette);
317 ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
319 IWICPalette_Release(palette);
324 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock);
325 ok(hr == S_OK, "IWICBitmap_Lock failed hr=%x\n", hr);
328 hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
329 ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
330 ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
332 hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
333 ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
334 ok(lock_buffer_size == 33, "got %i, expected 33\n", lock_buffer_size);
335 ok(lock_buffer != NULL, "got NULL data pointer\n");
338 memcpy(lock_buffer + lock_buffer_stride*i, bitmap_data + i*9, 9);
340 IWICBitmapLock_Release(lock);
343 hr = IWICBitmap_SetResolution(bitmap, 12.0, 34.0);
344 ok(hr == S_OK, "IWICBitmap_SetResolution failed hr=%x\n", hr);
346 hr = IWICImagingFactory_CreateBitmapFromSource(factory, (IWICBitmapSource*)bitmap,
347 WICBitmapCacheOnLoad, &bitmap2);
348 ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr);
350 IWICBitmap_Release(bitmap);
352 if (FAILED(hr)) return;
354 hr = IWICImagingFactory_CreatePalette(factory, &palette);
355 ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
357 /* palette isn't copied for non-indexed formats? */
358 hr = IWICBitmap_CopyPalette(bitmap2, palette);
359 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
361 IWICPalette_Release(palette);
363 hr = IWICBitmap_CopyPixels(bitmap2, NULL, 9, 27, returned_data);
364 ok(hr == S_OK, "IWICBitmap_CopyPixels failed hr=%x\n", hr);
367 ok(returned_data[i] == bitmap_data[i], "returned_data[%i] == %i\n", i, returned_data[i]);
369 hr = IWICBitmap_GetPixelFormat(bitmap2, &pixelformat);
370 ok(hr == S_OK, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr);
371 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
373 hr = IWICBitmap_GetResolution(bitmap2, &dpix, &dpiy);
374 ok(hr == S_OK, "IWICBitmap_GetResolution failed hr=%x\n", hr);
375 ok(dpix == 12.0, "got %f, expected 12.0\n", dpix);
376 ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy);
378 hr = IWICBitmap_GetSize(bitmap2, &width, &height);
379 ok(hr == S_OK, "IWICBitmap_GetSize failed hr=%x\n", hr);
380 ok(width == 3, "got %d, expected 3\n", width);
381 ok(height == 3, "got %d, expected 3\n", height);
383 IWICBitmap_Release(bitmap2);
385 /* Ensure palette is copied for indexed formats */
386 hr = IWICImagingFactory_CreateBitmap(factory, 3, 3, &GUID_WICPixelFormat4bppIndexed,
387 WICBitmapCacheOnLoad, &bitmap);
388 ok(hr == S_OK, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr);
390 hr = IWICImagingFactory_CreatePalette(factory, &palette);
391 ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
393 hr = IWICPalette_InitializePredefined(palette, WICBitmapPaletteTypeFixedGray256, FALSE);
394 ok(hr == S_OK, "IWICPalette_InitializePredefined failed hr=%x\n", hr);
396 hr = IWICBitmap_SetPalette(bitmap, palette);
397 ok(hr == S_OK, "IWICBitmap_SetPalette failed hr=%x\n", hr);
399 IWICPalette_Release(palette);
401 hr = IWICImagingFactory_CreateBitmapFromSource(factory, (IWICBitmapSource*)bitmap,
402 WICBitmapCacheOnLoad, &bitmap2);
403 ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr);
405 IWICBitmap_Release(bitmap);
407 hr = IWICImagingFactory_CreatePalette(factory, &palette);
408 ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
410 hr = IWICBitmap_CopyPalette(bitmap2, palette);
411 ok(hr == S_OK, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
413 hr = IWICPalette_GetColorCount(palette, &count);
414 ok(hr == S_OK, "IWICPalette_GetColorCount failed hr=%x\n", hr);
415 ok(count == 256, "unexpected count %d\n", count);
417 hr = IWICPalette_GetType(palette, &palette_type);
418 ok(hr == S_OK, "IWICPalette_GetType failed hr=%x\n", hr);
419 ok(palette_type == WICBitmapPaletteTypeFixedGray256, "unexpected palette type %d\n", palette_type);
421 IWICPalette_Release(palette);
423 hr = IWICBitmap_GetPixelFormat(bitmap2, &pixelformat);
424 ok(hr == S_OK, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr);
425 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
427 hr = IWICBitmap_GetSize(bitmap2, &width, &height);
428 ok(hr == S_OK, "IWICBitmap_GetSize failed hr=%x\n", hr);
429 ok(width == 3, "got %d, expected 3\n", width);
430 ok(height == 3, "got %d, expected 3\n", height);
432 IWICBitmap_Release(bitmap2);
435 static void test_CreateBitmapFromMemory(void)
437 BYTE orig_data3x3[27] = {
438 128,128,255, 128,128,128, 128,255,128,
439 128,128,128, 128,128,128, 255,255,255,
440 255,128,128, 255,255,255, 255,255,255 };
443 128,128,255, 128,128,128, 128,255,128,
444 0,0,0, 0,128,128, 255,255,255,
445 255,128,128, 255,0,0, 0,0,0 };
449 UINT width, height, i;
451 memcpy(data3x3, orig_data3x3, sizeof(data3x3));
453 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
454 0, 0, NULL, &bitmap);
455 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
457 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
458 0, sizeof(data3x3), data3x3, &bitmap);
459 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
461 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
462 6, sizeof(data3x3), data3x3, &bitmap);
463 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
465 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
466 12, sizeof(data3x3), data3x3, &bitmap);
467 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr);
469 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
470 9, sizeof(data3x3) - 1, data3x3, &bitmap);
471 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr);
473 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR,
474 9, sizeof(data3x3), data3x3, &bitmap);
475 ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr);
477 hr = IWICBitmap_GetSize(bitmap, &width, &height);
478 ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr);
479 ok(width == 3, "expected 3, got %u\n", width);
480 ok(height == 3, "expected 3, got %u\n", height);
484 memset(data, 0, sizeof(data));
485 hr = IWICBitmap_CopyPixels(bitmap, NULL, 9, sizeof(data), data);
486 ok(hr == S_OK, "IWICBitmap_CopyPixels error %#x\n", hr);
487 for (i = 0; i < sizeof(data); i++)
488 ok(data[i] == orig_data3x3[i], "%u: expected %u, got %u\n", i, data[i], data3x3[i]);
490 IWICBitmap_Release(bitmap);
492 hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 2, &GUID_WICPixelFormat24bppBGR,
493 13, sizeof(orig_data3x3), orig_data3x3, &bitmap);
494 ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr);
496 hr = IWICBitmap_GetSize(bitmap, &width, &height);
497 ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr);
498 ok(width == 3, "expected 3, got %u\n", width);
499 ok(height == 2, "expected 2, got %u\n", height);
501 memset(data, 0, sizeof(data));
502 hr = IWICBitmap_CopyPixels(bitmap, NULL, 13, sizeof(data), data);
503 ok(hr == S_OK, "IWICBitmap_CopyPixels error %#x\n", hr);
504 for (i = 0; i < sizeof(data); i++)
505 ok(data[i] == data3x2[i], "%u: expected %u, got %u\n", i, data3x2[i], data[i]);
507 IWICBitmap_Release(bitmap);
510 static void test_CreateBitmapFromHICON(void)
512 static const char bits[4096];
518 WICPixelFormatGUID format;
525 info.hbmMask = CreateBitmap(16, 32, 1, 1, bits);
526 ok(info.hbmMask != 0, "CreateBitmap failed\n");
527 icon = CreateIconIndirect(&info);
528 ok(icon != 0, "CreateIconIndirect failed\n");
529 DeleteObject(info.hbmMask);
531 hr = IWICImagingFactory_CreateBitmapFromHICON(factory, 0, NULL);
533 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
535 hr = IWICImagingFactory_CreateBitmapFromHICON(factory, 0, &bitmap);
537 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_CURSOR_HANDLE), "expected ERROR_INVALID_CURSOR_HANDLE, got %#x\n", hr);
539 hr = IWICImagingFactory_CreateBitmapFromHICON(factory, icon, NULL);
541 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
543 hr = IWICImagingFactory_CreateBitmapFromHICON(factory, icon, &bitmap);
545 ok(hr == S_OK, "CreateBitmapFromHICON error %#x\n", hr);
547 if (hr != S_OK) return;
549 IWICBitmap_GetPixelFormat(bitmap, &format);
550 ok(IsEqualGUID(&format, &GUID_WICPixelFormat32bppBGRA),
551 "unexpected pixel format %s\n", debugstr_guid(&format));
553 IWICBitmap_GetSize(bitmap, &width, &height);
554 ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr);
555 ok(width == 16, "expected 16, got %u\n", width);
556 ok(height == 16, "expected 16, got %u\n", height);
558 IWICBitmap_Release(bitmap);
560 /* 24 bpp color, 1 bpp mask */
564 info.hbmColor = CreateBitmap(16, 16, 1, 24, bits);
565 ok(info.hbmColor != 0, "CreateBitmap failed\n");
566 info.hbmMask = CreateBitmap(16, 16, 1, 1, bits);
567 ok(info.hbmMask != 0, "CreateBitmap failed\n");
568 icon = CreateIconIndirect(&info);
569 ok(icon != 0, "CreateIconIndirect failed\n");
570 DeleteObject(info.hbmColor);
571 DeleteObject(info.hbmMask);
573 hr = IWICImagingFactory_CreateBitmapFromHICON(factory, icon, &bitmap);
574 ok(hr == S_OK, "CreateBitmapFromHICON error %#x\n", hr);
577 IWICBitmap_GetPixelFormat(bitmap, &format);
578 ok(IsEqualGUID(&format, &GUID_WICPixelFormat32bppBGRA),
579 "unexpected pixel format %s\n", debugstr_guid(&format));
581 IWICBitmap_GetSize(bitmap, &width, &height);
582 ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr);
583 ok(width == 16, "expected 16, got %u\n", width);
584 ok(height == 16, "expected 16, got %u\n", height);
586 IWICBitmap_Release(bitmap);
593 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
595 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
596 &IID_IWICImagingFactory, (void**)&factory);
597 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
600 test_createbitmapfromsource();
601 test_CreateBitmapFromMemory();
602 test_CreateBitmapFromHICON();
604 IWICImagingFactory_Release(factory);