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
31 #include "wine/test.h"
33 extern IID IID_IMILBitmap
;
34 extern IID IID_IMILBitmapSource
;
35 extern IID IID_IMILBitmapLock
;
36 extern IID IID_IMILBitmapScaler
;
37 extern IID IID_IMILFormatConverter
;
38 extern IID IID_IMILPalette
;
41 #define INTERFACE IMILBitmapSource
42 DECLARE_INTERFACE_(IMILBitmapSource
,IUnknown
)
44 STDMETHOD_(HRESULT
,QueryInterface
)(THIS_ REFIID
,void **) PURE
;
45 STDMETHOD_(ULONG
,AddRef
)(THIS
) PURE
;
46 STDMETHOD_(ULONG
,Release
)(THIS
) PURE
;
47 /*** IWICBitmapSource methods ***/
48 STDMETHOD_(HRESULT
,GetSize
)(THIS_ UINT
*,UINT
*) PURE
;
49 STDMETHOD_(HRESULT
,GetPixelFormat
)(THIS_
int *) PURE
;
50 STDMETHOD_(HRESULT
,GetResolution
)(THIS_
double *,double *) PURE
;
51 STDMETHOD_(HRESULT
,CopyPalette
)(THIS_ IWICPalette
*) PURE
;
52 STDMETHOD_(HRESULT
,CopyPixels
)(THIS_
const WICRect
*,UINT
,UINT
,BYTE
*) PURE
;
56 #define INTERFACE IMILBitmap
57 DECLARE_INTERFACE_(IMILBitmap
,IMILBitmapSource
)
59 STDMETHOD_(HRESULT
,QueryInterface
)(THIS_ REFIID
,void **) PURE
;
60 STDMETHOD_(ULONG
,AddRef
)(THIS
) PURE
;
61 STDMETHOD_(ULONG
,Release
)(THIS
) PURE
;
62 /*** IWICBitmapSource methods ***/
63 STDMETHOD_(HRESULT
,GetSize
)(THIS_ UINT
*,UINT
*) PURE
;
64 STDMETHOD_(HRESULT
,GetPixelFormat
)(THIS_
int *) PURE
;
65 STDMETHOD_(HRESULT
,GetResolution
)(THIS_
double *,double *) PURE
;
66 STDMETHOD_(HRESULT
,CopyPalette
)(THIS_ IWICPalette
*) PURE
;
67 STDMETHOD_(HRESULT
,CopyPixels
)(THIS_
const WICRect
*,UINT
,UINT
,BYTE
*) PURE
;
68 /*** IMILBitmap methods ***/
69 STDMETHOD_(HRESULT
,unknown1
)(THIS_
void **) PURE
;
70 STDMETHOD_(HRESULT
,Lock
)(THIS_
const WICRect
*,DWORD
,IWICBitmapLock
**) PURE
;
71 STDMETHOD_(HRESULT
,Unlock
)(THIS_ IWICBitmapLock
*) PURE
;
72 STDMETHOD_(HRESULT
,SetPalette
)(THIS_ IWICPalette
*) PURE
;
73 STDMETHOD_(HRESULT
,SetResolution
)(THIS_
double,double) PURE
;
74 STDMETHOD_(HRESULT
,AddDirtyRect
)(THIS_
const WICRect
*) PURE
;
78 #define INTERFACE IMILBitmapScaler
79 DECLARE_INTERFACE_(IMILBitmapScaler
,IMILBitmapSource
)
81 /*** IUnknown methods ***/
82 STDMETHOD_(HRESULT
,QueryInterface
)(THIS_ REFIID
,void **) PURE
;
83 STDMETHOD_(ULONG
,AddRef
)(THIS
) PURE
;
84 STDMETHOD_(ULONG
,Release
)(THIS
) PURE
;
85 /*** IWICBitmapSource methods ***/
86 STDMETHOD_(HRESULT
,GetSize
)(THIS_ UINT
*,UINT
*) PURE
;
87 STDMETHOD_(HRESULT
,GetPixelFormat
)(THIS_
int *) PURE
;
88 STDMETHOD_(HRESULT
,GetResolution
)(THIS_
double *,double *) PURE
;
89 STDMETHOD_(HRESULT
,CopyPalette
)(THIS_ IWICPalette
*) PURE
;
90 STDMETHOD_(HRESULT
,CopyPixels
)(THIS_
const WICRect
*,UINT
,UINT
,BYTE
*) PURE
;
91 /*** IMILBitmapScaler methods ***/
92 STDMETHOD_(HRESULT
,unknown1
)(THIS_
void **) PURE
;
93 STDMETHOD_(HRESULT
,Initialize
)(THIS_ IMILBitmapSource
*,UINT
,UINT
,WICBitmapInterpolationMode
);
96 static IWICImagingFactory
*factory
;
98 static HRESULT WINAPI
bitmapsource_QueryInterface(IWICBitmapSource
*iface
, REFIID iid
, void **ppv
)
100 if (IsEqualIID(&IID_IUnknown
, iid
) ||
101 IsEqualIID(&IID_IWICBitmapSource
, iid
))
108 return E_NOINTERFACE
;
114 static ULONG WINAPI
bitmapsource_AddRef(IWICBitmapSource
*iface
)
119 static ULONG WINAPI
bitmapsource_Release(IWICBitmapSource
*iface
)
124 static HRESULT WINAPI
bitmapsource_GetSize(IWICBitmapSource
*iface
, UINT
*width
, UINT
*height
)
126 *width
= *height
= 10;
130 static HRESULT WINAPI
bitmapsource_GetPixelFormat(IWICBitmapSource
*iface
,
131 WICPixelFormatGUID
*format
)
136 static HRESULT WINAPI
bitmapsource_GetResolution(IWICBitmapSource
*iface
,
137 double *dpiX
, double *dpiY
)
142 static HRESULT WINAPI
bitmapsource_CopyPalette(IWICBitmapSource
*iface
,
143 IWICPalette
*palette
)
148 static WICRect g_rect
;
149 static BOOL called_CopyPixels
;
151 static HRESULT WINAPI
bitmapsource_CopyPixels(IWICBitmapSource
*iface
,
152 const WICRect
*rc
, UINT stride
, UINT buffer_size
, BYTE
*buffer
)
154 if (rc
) g_rect
= *rc
;
155 called_CopyPixels
= TRUE
;
159 static const IWICBitmapSourceVtbl sourcevtbl
= {
160 bitmapsource_QueryInterface
,
162 bitmapsource_Release
,
163 bitmapsource_GetSize
,
164 bitmapsource_GetPixelFormat
,
165 bitmapsource_GetResolution
,
166 bitmapsource_CopyPalette
,
167 bitmapsource_CopyPixels
170 static IWICBitmapSource bitmapsource
= { &sourcevtbl
};
172 static HBITMAP
create_dib(int width
, int height
, int bpp
, LOGPALETTE
*pal
, const void *data
)
174 char bmibuf
[sizeof(BITMAPINFO
) + sizeof(RGBQUAD
) * 255];
175 BITMAPINFO
*bmi
= (BITMAPINFO
*)bmibuf
;
180 memset(bmibuf
, 0, sizeof(bmibuf
));
181 bmi
->bmiHeader
.biSize
= sizeof(bmi
->bmiHeader
);
182 bmi
->bmiHeader
.biWidth
= width
;
183 bmi
->bmiHeader
.biHeight
= -height
;
184 bmi
->bmiHeader
.biBitCount
= bpp
;
185 bmi
->bmiHeader
.biPlanes
= 1;
186 bmi
->bmiHeader
.biCompression
= BI_RGB
;
191 assert(pal
->palNumEntries
<= 256);
192 for (i
= 0; i
< pal
->palNumEntries
; i
++)
194 bmi
->bmiColors
[i
].rgbRed
= pal
->palPalEntry
[i
].peRed
;
195 bmi
->bmiColors
[i
].rgbGreen
= pal
->palPalEntry
[i
].peGreen
;
196 bmi
->bmiColors
[i
].rgbBlue
= pal
->palPalEntry
[i
].peBlue
;
197 bmi
->bmiColors
[i
].rgbReserved
= 0;
200 bmi
->bmiHeader
.biClrUsed
= pal
->palNumEntries
;
201 bmi
->bmiHeader
.biClrImportant
= pal
->palNumEntries
;
203 hdib
= CreateDIBSection(0, bmi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
204 ok(hdib
!= 0, "CreateDIBSection(%dx%d,%d bpp) failed\n", width
, height
, bpp
);
206 GetObjectW(hdib
, sizeof(bm
), &bm
);
207 ok(bm
.bmWidth
== width
, "expected %d, got %d\n", width
, bm
.bmWidth
);
208 ok(bm
.bmHeight
== height
, "expected %d, got %d\n", height
, bm
.bmHeight
);
209 ok(bm
.bmPlanes
== 1, "expected 1, got %d\n", bm
.bmPlanes
);
210 ok(bm
.bmBitsPixel
== bpp
, "expected %d, got %d\n", bpp
, bm
.bmBitsPixel
);
212 if (data
) memcpy(bits
, data
, bm
.bmWidthBytes
* bm
.bmHeight
);
217 static void test_createbitmap(void)
221 IWICPalette
*palette
;
222 IWICBitmapLock
*lock
, *lock2
;
223 WICBitmapPaletteType palettetype
;
226 const BYTE bitmap_data
[27] = {
227 128,128,255, 128,128,128, 128,255,128,
228 128,128,128, 128,128,128, 255,255,255,
229 255,128,128, 255,255,255, 255,255,255};
230 BYTE returned_data
[27] = {0};
231 BYTE
*lock_buffer
=NULL
, *base_lock_buffer
=NULL
;
232 UINT lock_buffer_size
=0;
233 UINT lock_buffer_stride
=0;
234 WICPixelFormatGUID pixelformat
= {0};
235 UINT width
=0, height
=0;
236 double dpix
=10.0, dpiy
=10.0;
237 int can_lock_null
= 1;
239 hr
= IWICImagingFactory_CreateBitmap(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
240 WICBitmapCacheOnLoad
, &bitmap
);
241 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr
);
246 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
247 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
249 /* Palette is unavailable until explicitly set */
250 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
251 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
253 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray256
, FALSE
);
254 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
256 hr
= IWICBitmap_SetPalette(bitmap
, palette
);
257 ok(hr
== S_OK
, "IWICBitmap_SetPalette failed hr=%x\n", hr
);
259 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray4
, FALSE
);
260 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
262 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
263 ok(hr
== S_OK
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
265 hr
= IWICPalette_GetType(palette
, &palettetype
);
266 ok(hr
== S_OK
, "IWICPalette_GetType failed hr=%x\n", hr
);
267 ok(palettetype
== WICBitmapPaletteTypeFixedGray256
,
268 "expected WICBitmapPaletteTypeFixedGray256, got %x\n", palettetype
);
270 IWICPalette_Release(palette
);
272 /* pixel data is initially zeroed */
273 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 9, 27, returned_data
);
274 ok(hr
== S_OK
, "IWICBitmap_CopyPixels failed hr=%x\n", hr
);
277 ok(returned_data
[i
] == 0, "returned_data[%i] == %i\n", i
, returned_data
[i
]);
279 /* Invalid lock rects */
283 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
284 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
285 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
289 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
290 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
291 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
295 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
296 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
297 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
301 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
302 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
303 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
306 hr
= IWICBitmap_Lock(bitmap
, NULL
, WICBitmapLockRead
, &lock
);
307 ok(hr
== S_OK
|| broken(hr
== E_INVALIDARG
) /* winxp */, "IWICBitmap_Lock failed hr=%x\n", hr
);
311 /* entire bitmap is locked */
312 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
313 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
314 ok(width
== 3, "got %d, expected 3\n", width
);
315 ok(height
== 3, "got %d, expected 3\n", height
);
317 IWICBitmapLock_Release(lock
);
322 /* lock with a valid rect */
324 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &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 /* stride is divisible by 4 */
331 ok(lock_buffer_stride
== 12, "got %i, expected 12\n", lock_buffer_stride
);
333 hr
= IWICBitmapLock_GetDataPointer(lock
, &lock_buffer_size
, &lock_buffer
);
334 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
335 /* buffer size does not include padding from the last row */
336 ok(lock_buffer_size
== 33, "got %i, expected 33\n", lock_buffer_size
);
337 ok(lock_buffer
!= NULL
, "got NULL data pointer\n");
338 base_lock_buffer
= lock_buffer
;
340 hr
= IWICBitmapLock_GetPixelFormat(lock
, &pixelformat
);
341 ok(hr
== S_OK
, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr
);
342 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
344 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
345 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
346 ok(width
== 3, "got %d, expected 3\n", width
);
347 ok(height
== 3, "got %d, expected 3\n", height
);
349 /* We can have multiple simultaneous read locks */
350 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock2
);
351 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
355 hr
= IWICBitmapLock_GetDataPointer(lock2
, &lock_buffer_size
, &lock_buffer
);
356 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
357 ok(lock_buffer_size
== 33, "got %i, expected 33\n", lock_buffer_size
);
358 ok(lock_buffer
== base_lock_buffer
, "got %p, expected %p\n", lock_buffer
, base_lock_buffer
);
360 IWICBitmapLock_Release(lock2
);
363 if (can_lock_null
) /* this hangs on xp/vista */
365 /* But not a read and a write lock */
366 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock2
);
367 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
370 /* But we don't need a write lock to write */
371 if (base_lock_buffer
)
374 memcpy(base_lock_buffer
+ lock_buffer_stride
*i
, bitmap_data
+ i
*9, 9);
377 IWICBitmapLock_Release(lock
);
380 /* test that the data we wrote is returned by CopyPixels */
381 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 9, 27, returned_data
);
382 ok(hr
== S_OK
, "IWICBitmap_CopyPixels failed hr=%x\n", hr
);
385 ok(returned_data
[i
] == bitmap_data
[i
], "returned_data[%i] == %i\n", i
, returned_data
[i
]);
387 /* try a valid partial rect, and write mode */
392 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock
);
393 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
397 if (can_lock_null
) /* this hangs on xp/vista */
399 /* Can't lock again while locked for writing */
400 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock2
);
401 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
403 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock2
);
404 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
407 hr
= IWICBitmapLock_GetStride(lock
, &lock_buffer_stride
);
408 ok(hr
== S_OK
, "IWICBitmapLock_GetStride failed hr=%x\n", hr
);
409 ok(lock_buffer_stride
== 12, "got %i, expected 12\n", lock_buffer_stride
);
411 hr
= IWICBitmapLock_GetDataPointer(lock
, &lock_buffer_size
, &lock_buffer
);
412 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
413 ok(lock_buffer_size
== 15, "got %i, expected 15\n", lock_buffer_size
);
414 ok(lock_buffer
== base_lock_buffer
+6, "got %p, expected %p+6\n", lock_buffer
, base_lock_buffer
);
416 hr
= IWICBitmapLock_GetPixelFormat(lock
, &pixelformat
);
417 ok(hr
== S_OK
, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr
);
418 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
420 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
421 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
422 ok(width
== 1, "got %d, expected 1\n", width
);
423 ok(height
== 2, "got %d, expected 2\n", height
);
425 IWICBitmapLock_Release(lock
);
428 hr
= IWICBitmap_GetPixelFormat(bitmap
, &pixelformat
);
429 ok(hr
== S_OK
, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr
);
430 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
432 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
433 ok(hr
== S_OK
, "IWICBitmap_GetResolution failed hr=%x\n", hr
);
434 ok(dpix
== 0.0, "got %f, expected 0.0\n", dpix
);
435 ok(dpiy
== 0.0, "got %f, expected 0.0\n", dpiy
);
437 hr
= IWICBitmap_SetResolution(bitmap
, 12.0, 34.0);
438 ok(hr
== S_OK
, "IWICBitmap_SetResolution failed hr=%x\n", hr
);
440 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
441 ok(hr
== S_OK
, "IWICBitmap_GetResolution failed hr=%x\n", hr
);
442 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
443 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
445 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
446 ok(hr
== S_OK
, "IWICBitmap_GetSize failed hr=%x\n", hr
);
447 ok(width
== 3, "got %d, expected 3\n", width
);
448 ok(height
== 3, "got %d, expected 3\n", height
);
450 IWICBitmap_Release(bitmap
);
453 static void test_createbitmapfromsource(void)
456 IWICBitmap
*bitmap
, *bitmap2
;
457 IWICPalette
*palette
;
458 IWICBitmapLock
*lock
;
461 const BYTE bitmap_data
[27] = {
462 128,128,255, 128,128,128, 128,255,128,
463 128,128,128, 128,128,128, 255,255,255,
464 255,128,128, 255,255,255, 255,255,255};
465 BYTE returned_data
[27] = {0};
466 BYTE
*lock_buffer
=NULL
;
467 UINT lock_buffer_stride
=0;
468 UINT lock_buffer_size
=0;
469 WICPixelFormatGUID pixelformat
= {0};
470 UINT width
=0, height
=0;
471 double dpix
=10.0, dpiy
=10.0;
473 WICBitmapPaletteType palette_type
;
475 hr
= IWICImagingFactory_CreateBitmap(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
476 WICBitmapCacheOnLoad
, &bitmap
);
477 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr
);
482 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
483 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
485 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray256
, FALSE
);
486 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
488 hr
= IWICBitmap_SetPalette(bitmap
, palette
);
489 ok(hr
== S_OK
, "IWICBitmap_SetPalette failed hr=%x\n", hr
);
491 IWICPalette_Release(palette
);
496 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock
);
497 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
500 hr
= IWICBitmapLock_GetStride(lock
, &lock_buffer_stride
);
501 ok(hr
== S_OK
, "IWICBitmapLock_GetStride failed hr=%x\n", hr
);
502 ok(lock_buffer_stride
== 12, "got %i, expected 12\n", lock_buffer_stride
);
504 hr
= IWICBitmapLock_GetDataPointer(lock
, &lock_buffer_size
, &lock_buffer
);
505 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
506 ok(lock_buffer_size
== 33, "got %i, expected 33\n", lock_buffer_size
);
507 ok(lock_buffer
!= NULL
, "got NULL data pointer\n");
510 memcpy(lock_buffer
+ lock_buffer_stride
*i
, bitmap_data
+ i
*9, 9);
512 IWICBitmapLock_Release(lock
);
515 hr
= IWICBitmap_SetResolution(bitmap
, 12.0, 34.0);
516 ok(hr
== S_OK
, "IWICBitmap_SetResolution failed hr=%x\n", hr
);
518 /* WICBitmapNoCache */
519 hr
= IWICImagingFactory_CreateBitmapFromSource(factory
, (IWICBitmapSource
*)bitmap
,
520 WICBitmapNoCache
, &bitmap2
);
521 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr
);
522 ok(bitmap2
== bitmap
, "Unexpected bitmap instance.\n");
524 IWICBitmap_Release(bitmap2
);
526 bitmap2
= (void *)0xdeadbeef;
527 hr
= IWICImagingFactory_CreateBitmapFromSource(factory
, &bitmapsource
, WICBitmapNoCache
, &bitmap2
);
528 ok(hr
== E_NOTIMPL
, "Unexpected hr %#x.\n", hr
);
529 ok(bitmap2
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", bitmap2
);
531 hr
= IWICImagingFactory_CreateBitmapFromSource(factory
, (IWICBitmapSource
*)bitmap
,
532 WICBitmapCacheOnLoad
, &bitmap2
);
533 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr
);
535 IWICBitmap_Release(bitmap
);
537 if (FAILED(hr
)) return;
539 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
540 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
542 /* palette isn't copied for non-indexed formats? */
543 hr
= IWICBitmap_CopyPalette(bitmap2
, palette
);
544 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
546 IWICPalette_Release(palette
);
548 hr
= IWICBitmap_CopyPixels(bitmap2
, NULL
, 9, 27, returned_data
);
549 ok(hr
== S_OK
, "IWICBitmap_CopyPixels failed hr=%x\n", hr
);
552 ok(returned_data
[i
] == bitmap_data
[i
], "returned_data[%i] == %i\n", i
, returned_data
[i
]);
554 hr
= IWICBitmap_GetPixelFormat(bitmap2
, &pixelformat
);
555 ok(hr
== S_OK
, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr
);
556 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
558 hr
= IWICBitmap_GetResolution(bitmap2
, &dpix
, &dpiy
);
559 ok(hr
== S_OK
, "IWICBitmap_GetResolution failed hr=%x\n", hr
);
560 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
561 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
563 hr
= IWICBitmap_GetSize(bitmap2
, &width
, &height
);
564 ok(hr
== S_OK
, "IWICBitmap_GetSize failed hr=%x\n", hr
);
565 ok(width
== 3, "got %d, expected 3\n", width
);
566 ok(height
== 3, "got %d, expected 3\n", height
);
568 IWICBitmap_Release(bitmap2
);
570 /* Ensure palette is copied for indexed formats */
571 hr
= IWICImagingFactory_CreateBitmap(factory
, 3, 3, &GUID_WICPixelFormat4bppIndexed
,
572 WICBitmapCacheOnLoad
, &bitmap
);
573 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr
);
575 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
576 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
578 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray256
, FALSE
);
579 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
581 hr
= IWICBitmap_SetPalette(bitmap
, palette
);
582 ok(hr
== S_OK
, "IWICBitmap_SetPalette failed hr=%x\n", hr
);
584 IWICPalette_Release(palette
);
586 hr
= IWICImagingFactory_CreateBitmapFromSource(factory
, (IWICBitmapSource
*)bitmap
,
587 WICBitmapCacheOnLoad
, &bitmap2
);
588 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr
);
590 IWICBitmap_Release(bitmap
);
592 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
593 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
595 hr
= IWICBitmap_CopyPalette(bitmap2
, palette
);
596 ok(hr
== S_OK
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
598 hr
= IWICPalette_GetColorCount(palette
, &count
);
599 ok(hr
== S_OK
, "IWICPalette_GetColorCount failed hr=%x\n", hr
);
600 ok(count
== 256, "unexpected count %d\n", count
);
602 hr
= IWICPalette_GetType(palette
, &palette_type
);
603 ok(hr
== S_OK
, "IWICPalette_GetType failed hr=%x\n", hr
);
604 ok(palette_type
== WICBitmapPaletteTypeFixedGray256
, "unexpected palette type %d\n", palette_type
);
606 IWICPalette_Release(palette
);
608 hr
= IWICBitmap_GetPixelFormat(bitmap2
, &pixelformat
);
609 ok(hr
== S_OK
, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr
);
610 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat4bppIndexed
), "unexpected pixel format\n");
612 hr
= IWICBitmap_GetSize(bitmap2
, &width
, &height
);
613 ok(hr
== S_OK
, "IWICBitmap_GetSize failed hr=%x\n", hr
);
614 ok(width
== 3, "got %d, expected 3\n", width
);
615 ok(height
== 3, "got %d, expected 3\n", height
);
617 /* CreateBitmapFromSourceRect */
618 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 0, 0, 16, 32, &bitmap
);
619 ok(hr
== S_OK
, "Failed to create a bitmap, hr %#x.\n", hr
);
620 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
621 ok(hr
== S_OK
, "Failed to get bitmap size, hr %#x.\n", hr
);
622 ok(width
== 3, "Unexpected width %u.\n", width
);
623 ok(height
== 3, "Unexpected height %u.\n", height
);
624 IWICBitmap_Release(bitmap
);
626 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 0, 0, 1, 1, &bitmap
);
627 ok(hr
== S_OK
, "Failed to create a bitmap, hr %#x.\n", hr
);
628 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
629 ok(hr
== S_OK
, "Failed to get bitmap size, hr %#x.\n", hr
);
630 ok(width
== 1, "Unexpected width %u.\n", width
);
631 ok(height
== 1, "Unexpected height %u.\n", height
);
632 IWICBitmap_Release(bitmap
);
634 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 2, 1, 16, 32, &bitmap
);
635 ok(hr
== S_OK
, "Failed to create a bitmap, hr %#x.\n", hr
);
636 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
637 ok(hr
== S_OK
, "Failed to get bitmap size, hr %#x.\n", hr
);
638 ok(width
== 1, "Unexpected width %u.\n", width
);
639 ok(height
== 2, "Unexpected height %u.\n", height
);
640 IWICBitmap_Release(bitmap
);
642 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 0, 0, 0, 2, &bitmap
);
643 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
645 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 0, 0, 2, 0, &bitmap
);
646 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
648 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 1, 3, 16, 32, &bitmap
);
649 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
651 hr
= IWICImagingFactory_CreateBitmapFromSourceRect(factory
, (IWICBitmapSource
*)bitmap2
, 3, 1, 16, 32, &bitmap
);
652 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
654 IWICBitmap_Release(bitmap2
);
657 static void test_CreateBitmapFromMemory(void)
659 BYTE orig_data3x3
[27] = {
660 128,128,255, 128,128,128, 128,255,128,
661 128,128,128, 128,128,128, 255,255,255,
662 255,128,128, 255,255,255, 255,255,255 };
665 128,128,255, 128,128,128, 128,255,128,
666 0,0,0, 0,128,128, 255,255,255,
667 255,128,128, 255,0,0, 0,0,0 };
671 UINT width
, height
, i
;
673 memcpy(data3x3
, orig_data3x3
, sizeof(data3x3
));
675 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
676 0, 0, NULL
, &bitmap
);
677 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
679 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
680 0, sizeof(data3x3
), data3x3
, &bitmap
);
681 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
683 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
684 6, sizeof(data3x3
), data3x3
, &bitmap
);
685 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
687 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
688 12, sizeof(data3x3
), data3x3
, &bitmap
);
689 ok(hr
== WINCODEC_ERR_INSUFFICIENTBUFFER
, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr
);
691 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
692 9, sizeof(data3x3
) - 1, data3x3
, &bitmap
);
693 ok(hr
== WINCODEC_ERR_INSUFFICIENTBUFFER
, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr
);
695 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
696 9, sizeof(data3x3
), data3x3
, &bitmap
);
697 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr
);
699 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
700 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
701 ok(width
== 3, "expected 3, got %u\n", width
);
702 ok(height
== 3, "expected 3, got %u\n", height
);
706 memset(data
, 0, sizeof(data
));
707 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 9, sizeof(data
), data
);
708 ok(hr
== S_OK
, "IWICBitmap_CopyPixels error %#x\n", hr
);
709 for (i
= 0; i
< sizeof(data
); i
++)
710 ok(data
[i
] == orig_data3x3
[i
], "%u: expected %u, got %u\n", i
, data
[i
], data3x3
[i
]);
712 IWICBitmap_Release(bitmap
);
714 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, 3, 2, &GUID_WICPixelFormat24bppBGR
,
715 13, sizeof(orig_data3x3
), orig_data3x3
, &bitmap
);
716 ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr
);
718 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
719 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
720 ok(width
== 3, "expected 3, got %u\n", width
);
721 ok(height
== 2, "expected 2, got %u\n", height
);
723 memset(data
, 0, sizeof(data
));
724 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 13, sizeof(data
), data
);
725 ok(hr
== S_OK
, "IWICBitmap_CopyPixels error %#x\n", hr
);
726 for (i
= 0; i
< sizeof(data
); i
++)
727 ok(data
[i
] == data3x2
[i
], "%u: expected %u, got %u\n", i
, data3x2
[i
], data
[i
]);
729 IWICBitmap_Release(bitmap
);
732 static void test_CreateBitmapFromHICON(void)
734 static const char bits
[4096];
740 WICPixelFormatGUID format
;
747 info
.hbmMask
= CreateBitmap(16, 32, 1, 1, bits
);
748 ok(info
.hbmMask
!= 0, "CreateBitmap failed\n");
749 icon
= CreateIconIndirect(&info
);
750 ok(icon
!= 0, "CreateIconIndirect failed\n");
751 DeleteObject(info
.hbmMask
);
753 hr
= IWICImagingFactory_CreateBitmapFromHICON(factory
, 0, NULL
);
754 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
756 hr
= IWICImagingFactory_CreateBitmapFromHICON(factory
, 0, &bitmap
);
757 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_CURSOR_HANDLE
), "expected ERROR_INVALID_CURSOR_HANDLE, got %#x\n", hr
);
759 hr
= IWICImagingFactory_CreateBitmapFromHICON(factory
, icon
, NULL
);
760 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
762 hr
= IWICImagingFactory_CreateBitmapFromHICON(factory
, icon
, &bitmap
);
763 ok(hr
== S_OK
, "CreateBitmapFromHICON error %#x\n", hr
);
765 if (hr
!= S_OK
) return;
767 IWICBitmap_GetPixelFormat(bitmap
, &format
);
768 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppBGRA
),
769 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
771 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
772 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
773 ok(width
== 16, "expected 16, got %u\n", width
);
774 ok(height
== 16, "expected 16, got %u\n", height
);
776 IWICBitmap_Release(bitmap
);
778 /* 24 bpp color, 1 bpp mask */
782 info
.hbmColor
= CreateBitmap(16, 16, 1, 24, bits
);
783 ok(info
.hbmColor
!= 0, "CreateBitmap failed\n");
784 info
.hbmMask
= CreateBitmap(16, 16, 1, 1, bits
);
785 ok(info
.hbmMask
!= 0, "CreateBitmap failed\n");
786 icon
= CreateIconIndirect(&info
);
787 ok(icon
!= 0, "CreateIconIndirect failed\n");
788 DeleteObject(info
.hbmColor
);
789 DeleteObject(info
.hbmMask
);
791 hr
= IWICImagingFactory_CreateBitmapFromHICON(factory
, icon
, &bitmap
);
792 ok(hr
== S_OK
, "CreateBitmapFromHICON error %#x\n", hr
);
795 IWICBitmap_GetPixelFormat(bitmap
, &format
);
796 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppBGRA
),
797 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
799 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
800 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
801 ok(width
== 16, "expected 16, got %u\n", width
);
802 ok(height
== 16, "expected 16, got %u\n", height
);
804 IWICBitmap_Release(bitmap
);
807 static void test_CreateBitmapFromHBITMAP(void)
809 /* 8 bpp data must be aligned to a DWORD boundary for a DIB */
810 static const BYTE data_8bpp_pal_dib
[12] = { 0,1,2,0, 1,2,0,0, 2,1,0,0 };
811 static const BYTE data_8bpp_rgb_dib
[12] = { 0xf0,0x0f,0xff,0, 0x0f,0xff,0xf0,0, 0xf0,0x0f,0xff,0 };
812 static const BYTE data_8bpp_pal_wic
[12] = { 0xd,0xe,0x10,0, 0xe,0x10,0xd,0, 0x10,0xe,0xd,0 };
813 static const PALETTEENTRY pal_data
[3] = { {0xff,0,0,0}, {0,0xff,0,0}, {0,0,0xff,0} };
814 char pal_buf
[sizeof(LOGPALETTE
) + sizeof(PALETTEENTRY
) * 255];
815 LOGPALETTE
*pal
= (LOGPALETTE
*)pal_buf
;
821 UINT width
, height
, i
, count
;
822 WICPixelFormatGUID format
;
823 IWICPalette
*palette
;
824 WICBitmapPaletteType type
;
826 /* 8 bpp without palette */
827 hbmp
= create_dib(3, 3, 8, NULL
, data_8bpp_rgb_dib
);
828 ok(hbmp
!= 0, "failed to create bitmap\n");
830 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, 0, 0, WICBitmapIgnoreAlpha
, &bitmap
);
831 ok(hr
== WINCODEC_ERR_WIN32ERROR
|| hr
== 0x88980003 /*XP*/, "expected WINCODEC_ERR_WIN32ERROR, got %#x\n", hr
);
833 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, 0, WICBitmapIgnoreAlpha
, NULL
);
834 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got %#x\n", hr
);
836 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, 0, WICBitmapIgnoreAlpha
, &bitmap
);
837 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
839 IWICBitmap_GetPixelFormat(bitmap
, &format
);
840 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
841 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
843 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
844 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
845 ok(width
== 3, "expected 3, got %u\n", width
);
846 ok(height
== 3, "expected 3, got %u\n", height
);
848 memset(data
, 0, sizeof(data
));
849 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 4, sizeof(data
), data
);
850 ok(hr
== S_OK
, "IWICBitmap_CopyPixels error %#x\n", hr
);
851 for (i
= 0; i
< sizeof(data
); i
++)
852 ok(data
[i
] == data_8bpp_rgb_dib
[i
], "%u: expected %#x, got %#x\n", i
, data_8bpp_rgb_dib
[i
], data
[i
]);
854 IWICBitmap_Release(bitmap
);
857 /* 8 bpp with a 3 entries palette */
858 memset(pal_buf
, 0, sizeof(pal_buf
));
859 pal
->palVersion
= 0x300;
860 pal
->palNumEntries
= 3;
861 memcpy(pal
->palPalEntry
, pal_data
, sizeof(pal_data
));
862 hpal
= CreatePalette(pal
);
863 ok(hpal
!= 0, "CreatePalette failed\n");
865 hbmp
= create_dib(3, 3, 8, pal
, data_8bpp_pal_dib
);
866 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, hpal
, WICBitmapIgnoreAlpha
, &bitmap
);
867 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
869 IWICBitmap_GetPixelFormat(bitmap
, &format
);
871 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat4bppIndexed
),
872 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
874 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
875 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
876 ok(width
== 3, "expected 3, got %u\n", width
);
877 ok(height
== 3, "expected 3, got %u\n", height
);
879 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
880 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
881 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
882 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
884 hr
= IWICPalette_GetType(palette
, &type
);
885 ok(hr
== S_OK
, "%u: GetType error %#x\n", i
, hr
);
886 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
888 hr
= IWICPalette_GetColorCount(palette
, &count
);
889 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
891 ok(count
== 16, "expected 16, got %u\n", count
);
893 IWICPalette_Release(palette
);
895 IWICBitmap_Release(bitmap
);
899 /* 8 bpp with a 256 entries palette */
900 memset(pal_buf
, 0, sizeof(pal_buf
));
901 pal
->palVersion
= 0x300;
902 pal
->palNumEntries
= 256;
903 memcpy(pal
->palPalEntry
, pal_data
, sizeof(pal_data
));
904 hpal
= CreatePalette(pal
);
905 ok(hpal
!= 0, "CreatePalette failed\n");
907 hbmp
= create_dib(3, 3, 8, pal
, data_8bpp_pal_dib
);
908 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, hpal
, WICBitmapIgnoreAlpha
, &bitmap
);
909 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
911 IWICBitmap_GetPixelFormat(bitmap
, &format
);
912 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
913 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
915 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
916 ok(hr
== S_OK
, "IWICBitmap_GetSize error %#x\n", hr
);
917 ok(width
== 3, "expected 3, got %u\n", width
);
918 ok(height
== 3, "expected 3, got %u\n", height
);
920 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
921 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
922 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
923 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
925 hr
= IWICPalette_GetType(palette
, &type
);
926 ok(hr
== S_OK
, "%u: GetType error %#x\n", i
, hr
);
927 ok(type
== WICBitmapPaletteTypeCustom
, "expected WICBitmapPaletteTypeCustom, got %#x\n", type
);
929 hr
= IWICPalette_GetColorCount(palette
, &count
);
930 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
931 ok(count
== 256, "expected 256, got %u\n", count
);
933 IWICPalette_Release(palette
);
935 memset(data
, 0, sizeof(data
));
936 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 4, sizeof(data
), data
);
937 ok(hr
== S_OK
, "IWICBitmap_CopyPixels error %#x\n", hr
);
938 for (i
= 0; i
< sizeof(data
); i
++)
939 todo_wine_if (data
[i
] != data_8bpp_pal_wic
[i
])
940 ok(data
[i
] == data_8bpp_pal_wic
[i
], "%u: expected %#x, got %#x\n", i
, data_8bpp_pal_wic
[i
], data
[i
]);
942 IWICBitmap_Release(bitmap
);
947 hbmp
= create_dib(2, 2, 32, NULL
, NULL
);
948 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, NULL
, WICBitmapUseAlpha
, &bitmap
);
949 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
951 hr
= IWICBitmap_GetPixelFormat(bitmap
, &format
);
952 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
953 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppBGRA
),
954 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
956 IWICBitmap_Release(bitmap
);
958 /* 32bpp pre-multiplied alpha */
959 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, NULL
, WICBitmapUsePremultipliedAlpha
, &bitmap
);
960 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
962 hr
= IWICBitmap_GetPixelFormat(bitmap
, &format
);
963 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
964 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppPBGRA
),
965 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
967 IWICBitmap_Release(bitmap
);
970 hr
= IWICImagingFactory_CreateBitmapFromHBITMAP(factory
, hbmp
, NULL
, WICBitmapIgnoreAlpha
, &bitmap
);
971 ok(hr
== S_OK
, "CreateBitmapFromHBITMAP error %#x\n", hr
);
973 hr
= IWICBitmap_GetPixelFormat(bitmap
, &format
);
974 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
975 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppBGR
),
976 "unexpected pixel format %s\n", wine_dbgstr_guid(&format
));
978 IWICBitmap_Release(bitmap
);
982 static void test_clipper(void)
984 IWICBitmapClipper
*clipper
;
991 hr
= IWICImagingFactory_CreateBitmap(factory
, 10, 10, &GUID_WICPixelFormat24bppBGR
,
992 WICBitmapCacheOnLoad
, &bitmap
);
993 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
995 hr
= IWICImagingFactory_CreateBitmapClipper(factory
, &clipper
);
996 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
999 rect
.Width
= rect
.Height
= 11;
1000 hr
= IWICBitmapClipper_Initialize(clipper
, (IWICBitmapSource
*)bitmap
, &rect
);
1001 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1003 rect
.X
= rect
.Y
= 5;
1004 rect
.Width
= rect
.Height
= 6;
1005 hr
= IWICBitmapClipper_Initialize(clipper
, (IWICBitmapSource
*)bitmap
, &rect
);
1006 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1008 rect
.X
= rect
.Y
= 5;
1009 rect
.Width
= rect
.Height
= 5;
1010 hr
= IWICBitmapClipper_Initialize(clipper
, (IWICBitmapSource
*)bitmap
, &rect
);
1011 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1014 hr
= IWICBitmapClipper_GetSize(clipper
, &width
, &height
);
1015 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1016 ok(width
== 5, "got %d\n", width
);
1017 ok(height
== 5, "got %d\n", height
);
1019 IWICBitmapClipper_Release(clipper
);
1020 IWICBitmap_Release(bitmap
);
1023 hr
= IWICImagingFactory_CreateBitmapClipper(factory
, &clipper
);
1024 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1026 rect
.X
= rect
.Y
= 5;
1027 rect
.Width
= rect
.Height
= 5;
1028 hr
= IWICBitmapClipper_Initialize(clipper
, &bitmapsource
, &rect
);
1029 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1031 rect
.X
= rect
.Y
= 0;
1032 rect
.Width
= rect
.Height
= 2;
1034 /* passed rectangle is relative to clipper rectangle, underlying source gets intersected
1036 memset(&g_rect
, 0, sizeof(g_rect
));
1037 called_CopyPixels
= FALSE
;
1038 hr
= IWICBitmapClipper_CopyPixels(clipper
, &rect
, 0, sizeof(buffer
), buffer
);
1039 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1040 ok(called_CopyPixels
, "CopyPixels not called\n");
1041 ok(g_rect
.X
== 5 && g_rect
.Y
== 5 && g_rect
.Width
== 2 && g_rect
.Height
== 2,
1042 "got wrong rectangle (%d,%d)-(%d,%d)\n", g_rect
.X
, g_rect
.Y
, g_rect
.Width
, g_rect
.Height
);
1044 /* whole clipping rectangle */
1045 memset(&g_rect
, 0, sizeof(g_rect
));
1046 called_CopyPixels
= FALSE
;
1048 rect
.X
= rect
.Y
= 0;
1049 rect
.Width
= rect
.Height
= 5;
1051 hr
= IWICBitmapClipper_CopyPixels(clipper
, &rect
, 0, sizeof(buffer
), buffer
);
1052 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1053 ok(called_CopyPixels
, "CopyPixels not called\n");
1054 ok(g_rect
.X
== 5 && g_rect
.Y
== 5 && g_rect
.Width
== 5 && g_rect
.Height
== 5,
1055 "got wrong rectangle (%d,%d)-(%d,%d)\n", g_rect
.X
, g_rect
.Y
, g_rect
.Width
, g_rect
.Height
);
1057 /* larger than clipping rectangle */
1058 memset(&g_rect
, 0, sizeof(g_rect
));
1059 called_CopyPixels
= FALSE
;
1061 rect
.X
= rect
.Y
= 0;
1062 rect
.Width
= rect
.Height
= 20;
1064 hr
= IWICBitmapClipper_CopyPixels(clipper
, &rect
, 0, sizeof(buffer
), buffer
);
1065 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1066 ok(!called_CopyPixels
, "CopyPixels called\n");
1068 rect
.X
= rect
.Y
= 5;
1069 rect
.Width
= rect
.Height
= 5;
1071 hr
= IWICBitmapClipper_CopyPixels(clipper
, &rect
, 0, sizeof(buffer
), buffer
);
1072 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1073 ok(!called_CopyPixels
, "CopyPixels called\n");
1075 /* null rectangle */
1076 memset(&g_rect
, 0, sizeof(g_rect
));
1077 called_CopyPixels
= FALSE
;
1079 hr
= IWICBitmapClipper_CopyPixels(clipper
, NULL
, 0, sizeof(buffer
), buffer
);
1080 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1081 ok(called_CopyPixels
, "CopyPixels not called\n");
1082 ok(g_rect
.X
== 5 && g_rect
.Y
== 5 && g_rect
.Width
== 5 && g_rect
.Height
== 5,
1083 "got wrong rectangle (%d,%d)-(%d,%d)\n", g_rect
.X
, g_rect
.Y
, g_rect
.Width
, g_rect
.Height
);
1085 IWICBitmapClipper_Release(clipper
);
1088 static HRESULT (WINAPI
*pWICCreateBitmapFromSectionEx
)
1089 (UINT
, UINT
, REFWICPixelFormatGUID
, HANDLE
, UINT
, UINT
, WICSectionAccessLevel
, IWICBitmap
**);
1091 static void test_WICCreateBitmapFromSectionEx(void)
1093 SYSTEM_INFO sysinfo
;
1100 pWICCreateBitmapFromSectionEx
=
1101 (void *)GetProcAddress(LoadLibraryA("windowscodecs"), "WICCreateBitmapFromSectionEx");
1103 if (!pWICCreateBitmapFromSectionEx
)
1105 win_skip("WICCreateBitmapFromSectionEx not available\n");
1109 GetSystemInfo(&sysinfo
);
1110 hsection
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0,
1111 sysinfo
.dwAllocationGranularity
* 2, NULL
);
1112 ok(hsection
!= NULL
, "CreateFileMapping failed %u\n", GetLastError());
1114 memset(&info
, 0, sizeof(info
));
1115 info
.bmiHeader
.biSize
= sizeof(info
.bmiHeader
);
1116 info
.bmiHeader
.biWidth
= 3;
1117 info
.bmiHeader
.biHeight
= -3;
1118 info
.bmiHeader
.biBitCount
= 24;
1119 info
.bmiHeader
.biPlanes
= 1;
1120 info
.bmiHeader
.biCompression
= BI_RGB
;
1122 hdib
= CreateDIBSection(0, &info
, DIB_RGB_COLORS
, &bits
, hsection
, 0);
1123 ok(hdib
!= NULL
, "CreateDIBSection failed\n");
1125 hr
= pWICCreateBitmapFromSectionEx(3, 3, &GUID_WICPixelFormat24bppBGR
, hsection
, 0, 0,
1126 WICSectionAccessLevelReadWrite
, &bitmap
);
1127 ok(hr
== S_OK
, "WICCreateBitmapFromSectionEx returned %#x\n", hr
);
1128 IWICBitmap_Release(bitmap
);
1130 /* non-zero offset, smaller than allocation granularity */
1131 hr
= pWICCreateBitmapFromSectionEx(3, 3, &GUID_WICPixelFormat24bppBGR
, hsection
, 0, 0x100,
1132 WICSectionAccessLevelReadWrite
, &bitmap
);
1133 ok(hr
== S_OK
, "WICCreateBitmapFromSectionEx returned %#x\n", hr
);
1134 IWICBitmap_Release(bitmap
);
1136 /* offset larger than allocation granularity */
1137 hr
= pWICCreateBitmapFromSectionEx(3, 3, &GUID_WICPixelFormat24bppBGR
, hsection
, 0,
1138 sysinfo
.dwAllocationGranularity
+ 1,
1139 WICSectionAccessLevelReadWrite
, &bitmap
);
1140 ok(hr
== S_OK
, "WICCreateBitmapFromSectionEx returned %#x\n", hr
);
1141 IWICBitmap_Release(bitmap
);
1143 CloseHandle(hsection
);
1146 static void test_bitmap_scaler(void)
1148 WICPixelFormatGUID pixel_format
;
1149 IWICBitmapScaler
*scaler
;
1150 IWICPalette
*palette
;
1151 double res_x
, res_y
;
1157 hr
= IWICImagingFactory_CreateBitmap(factory
, 4, 2, &GUID_WICPixelFormat24bppBGR
, WICBitmapCacheOnLoad
, &bitmap
);
1158 ok(hr
== S_OK
, "Failed to create a bitmap, hr %#x.\n", hr
);
1160 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
1161 ok(hr
== S_OK
, "Failed to get bitmap size, hr %#x.\n", hr
);
1162 ok(width
== 4, "Unexpected width %u.\n", width
);
1163 ok(height
== 2, "Unexpected height %u.\n", height
);
1165 hr
= IWICBitmap_GetResolution(bitmap
, &res_x
, &res_y
);
1166 ok(hr
== S_OK
, "Failed to get bitmap resolution, hr %#x.\n", hr
);
1167 ok(res_x
== 0.0 && res_y
== 0.0, "Unexpected resolution %f x %f.\n", res_x
, res_y
);
1169 hr
= IWICImagingFactory_CreateBitmapScaler(factory
, &scaler
);
1170 ok(hr
== S_OK
, "Failed to create bitmap scaler, hr %#x.\n", hr
);
1172 hr
= IWICBitmapScaler_Initialize(scaler
, NULL
, 0, 0,
1173 WICBitmapInterpolationModeNearestNeighbor
);
1174 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1176 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 0, 0,
1177 WICBitmapInterpolationModeNearestNeighbor
);
1178 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1180 hr
= IWICBitmapScaler_GetSize(scaler
, NULL
, &height
);
1181 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1183 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, NULL
);
1184 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1186 hr
= IWICBitmapScaler_GetResolution(scaler
, NULL
, NULL
);
1187 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1190 hr
= IWICBitmapScaler_GetResolution(scaler
, &res_x
, NULL
);
1191 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1192 ok(res_x
== 0.1, "Unexpected resolution %f.\n", res_x
);
1194 hr
= IWICBitmapScaler_GetResolution(scaler
, NULL
, &res_y
);
1195 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1197 hr
= IWICBitmapScaler_GetResolution(scaler
, &res_x
, &res_y
);
1198 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1200 hr
= IWICBitmapScaler_GetPixelFormat(scaler
, NULL
);
1201 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1203 memset(&pixel_format
, 0, sizeof(pixel_format
));
1204 hr
= IWICBitmapScaler_GetPixelFormat(scaler
, &pixel_format
);
1205 ok(hr
== S_OK
, "Failed to get pixel format, hr %#x.\n", hr
);
1206 ok(IsEqualGUID(&pixel_format
, &GUID_WICPixelFormatDontCare
), "Unexpected pixel format %s.\n",
1207 wine_dbgstr_guid(&pixel_format
));
1211 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, &height
);
1212 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1213 ok(width
== 123, "Unexpected width %u.\n", width
);
1214 ok(height
== 321, "Unexpected height %u.\n", height
);
1216 hr
= IWICBitmapScaler_CopyPalette(scaler
, NULL
);
1217 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1219 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
1220 ok(hr
== S_OK
, "Failed to create a palette, hr %#x.\n", hr
);
1221 hr
= IWICBitmapScaler_CopyPalette(scaler
, palette
);
1222 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "Unexpected hr %#x.\n", hr
);
1223 IWICPalette_Release(palette
);
1225 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 4, 0,
1226 WICBitmapInterpolationModeNearestNeighbor
);
1227 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1229 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, &height
);
1230 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1232 hr
= IWICBitmapScaler_CopyPixels(scaler
, NULL
, 1, sizeof(buf
), buf
);
1233 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1235 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 0, 2,
1236 WICBitmapInterpolationModeNearestNeighbor
);
1237 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1239 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, &height
);
1240 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "Unexpected hr %#x.\n", hr
);
1242 hr
= IWICBitmapScaler_Initialize(scaler
, NULL
, 8, 4,
1243 WICBitmapInterpolationModeNearestNeighbor
);
1244 ok(hr
== E_INVALIDARG
, "Failed to initialize bitmap scaler, hr %#x.\n", hr
);
1246 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 8, 4,
1247 WICBitmapInterpolationModeNearestNeighbor
);
1248 ok(hr
== S_OK
, "Failed to initialize bitmap scaler, hr %#x.\n", hr
);
1250 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 0, 4,
1251 WICBitmapInterpolationModeNearestNeighbor
);
1252 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1254 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 8, 0,
1255 WICBitmapInterpolationModeNearestNeighbor
);
1256 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1258 hr
= IWICBitmapScaler_Initialize(scaler
, NULL
, 8, 4, WICBitmapInterpolationModeNearestNeighbor
);
1259 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1261 hr
= IWICBitmapScaler_Initialize(scaler
, (IWICBitmapSource
*)bitmap
, 8, 4,
1262 WICBitmapInterpolationModeNearestNeighbor
);
1263 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "Unexpected hr %#x.\n", hr
);
1265 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, &height
);
1266 ok(hr
== S_OK
, "Failed to get scaler size, hr %#x.\n", hr
);
1267 ok(width
== 8, "Unexpected width %u.\n", width
);
1268 ok(height
== 4, "Unexpected height %u.\n", height
);
1270 hr
= IWICBitmapScaler_GetSize(scaler
, NULL
, &height
);
1271 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1273 hr
= IWICBitmapScaler_GetSize(scaler
, &width
, NULL
);
1274 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1276 hr
= IWICBitmapScaler_GetSize(scaler
, NULL
, NULL
);
1277 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1279 hr
= IWICBitmapScaler_GetPixelFormat(scaler
, NULL
);
1280 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1282 memset(&pixel_format
, 0, sizeof(pixel_format
));
1283 hr
= IWICBitmapScaler_GetPixelFormat(scaler
, &pixel_format
);
1284 ok(hr
== S_OK
, "Failed to get pixel format, hr %#x.\n", hr
);
1285 ok(IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat24bppBGR
), "Unexpected pixel format %s.\n",
1286 wine_dbgstr_guid(&pixel_format
));
1288 hr
= IWICBitmapScaler_GetResolution(scaler
, NULL
, NULL
);
1289 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1292 hr
= IWICBitmapScaler_GetResolution(scaler
, &res_x
, NULL
);
1293 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1294 ok(res_x
== 0.1, "Unexpected resolution %f.\n", res_x
);
1296 hr
= IWICBitmapScaler_GetResolution(scaler
, NULL
, &res_y
);
1297 ok(hr
== E_INVALIDARG
, "Unexpected hr %#x.\n", hr
);
1299 res_x
= res_y
= 1.0;
1300 hr
= IWICBitmapScaler_GetResolution(scaler
, &res_x
, &res_y
);
1301 ok(hr
== S_OK
, "Failed to get scaler resolution, hr %#x.\n", hr
);
1302 ok(res_x
== 0.0 && res_y
== 0.0, "Unexpected resolution %f x %f.\n", res_x
, res_y
);
1304 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
1305 ok(hr
== S_OK
, "Failed to create a palette, hr %#x.\n", hr
);
1306 hr
= IWICBitmapScaler_CopyPalette(scaler
, palette
);
1307 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "Unexpected hr %#x.\n", hr
);
1308 IWICPalette_Release(palette
);
1310 IWICBitmapScaler_Release(scaler
);
1312 IWICBitmap_Release(bitmap
);
1315 static LONG
obj_refcount(void *obj
)
1317 IUnknown_AddRef((IUnknown
*)obj
);
1318 return IUnknown_Release((IUnknown
*)obj
);
1321 static void test_IMILBitmap(void)
1325 IWICBitmapScaler
*scaler
;
1326 IMILBitmap
*mil_bitmap
;
1327 IMILBitmapSource
*mil_source
;
1328 IMILBitmapScaler
*mil_scaler
;
1329 IUnknown
*wic_unknown
, *mil_unknown
;
1330 WICPixelFormatGUID format
;
1337 hr
= IWICImagingFactory_CreateBitmap(factory
, 1, 1, &GUID_WICPixelFormat24bppBGR
,
1338 WICBitmapCacheOnDemand
, &bitmap
);
1339 ok(hr
== S_OK
, "CreateBitmap error %#x\n", hr
);
1341 ok(obj_refcount(bitmap
) == 1, "ref count %d\n", obj_refcount(bitmap
));
1343 hr
= IWICBitmap_GetPixelFormat(bitmap
, &format
);
1344 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
1345 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat24bppBGR
), "wrong format %s\n", wine_dbgstr_guid(&format
));
1347 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
1348 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
1349 ok(dpix
== 0.0, "got %f, expected 0.0\n", dpix
);
1350 ok(dpiy
== 0.0, "got %f, expected 0.0\n", dpiy
);
1352 hr
= IWICBitmap_SetResolution(bitmap
, 12.0, 34.0);
1353 ok(hr
== S_OK
, "SetResolution error %#x\n", hr
);
1355 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
1356 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
1357 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
1358 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
1360 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
1361 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
1362 ok(width
== 1, "got %u, expected 1\n", width
);
1363 ok(height
== 1, "got %u, expected 1\n", height
);
1365 hr
= IWICBitmap_QueryInterface(bitmap
, &IID_IMILBitmap
, (void **)&mil_bitmap
);
1366 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1368 ok(obj_refcount(bitmap
) == 2, "ref count %d\n", obj_refcount(bitmap
));
1369 ok(obj_refcount(mil_bitmap
) == 2, "ref count %d\n", obj_refcount(mil_bitmap
));
1371 hr
= IWICBitmap_QueryInterface(bitmap
, &IID_IUnknown
, (void **)&wic_unknown
);
1372 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1374 hr
= mil_bitmap
->lpVtbl
->QueryInterface(mil_bitmap
, &IID_IUnknown
, (void **)&mil_unknown
);
1375 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1376 ok((void *)wic_unknown
->lpVtbl
== (void *)mil_unknown
->lpVtbl
, "wrong lpVtbl ptrs %p != %p\n", wic_unknown
->lpVtbl
, mil_unknown
->lpVtbl
);
1378 IUnknown_Release(wic_unknown
);
1379 IUnknown_Release(mil_unknown
);
1381 hr
= IWICBitmap_QueryInterface(bitmap
, &IID_IMILBitmapSource
, (void **)&mil_source
);
1382 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1383 ok((void *)mil_source
->lpVtbl
== (void *)mil_bitmap
->lpVtbl
, "IMILBitmap->lpVtbl should be equal to IMILBitmapSource->lpVtbl\n");
1385 ok(obj_refcount(bitmap
) == 3, "ref count %d\n", obj_refcount(bitmap
));
1386 ok(obj_refcount(mil_bitmap
) == 3, "ref count %d\n", obj_refcount(mil_bitmap
));
1387 ok(obj_refcount(mil_source
) == 3, "ref count %d\n", obj_refcount(mil_source
));
1389 hr
= mil_source
->lpVtbl
->GetPixelFormat(mil_source
, &MIL_format
);
1390 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
1391 ok(MIL_format
== 0x0c, "wrong format %d\n", MIL_format
);
1393 hr
= mil_source
->lpVtbl
->GetResolution(mil_source
, &dpix
, &dpiy
);
1394 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
1395 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
1396 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
1398 hr
= mil_source
->lpVtbl
->GetSize(mil_source
, &width
, &height
);
1399 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
1400 ok(width
== 1, "got %u, expected 1\n", width
);
1401 ok(height
== 1, "got %u, expected 1\n", height
);
1404 hr
= IWICImagingFactory_CreateBitmapScaler(factory
, &scaler
);
1405 ok(hr
== S_OK
, "CreateBitmapScaler error %#x\n", hr
);
1407 ok(obj_refcount(scaler
) == 1, "ref count %d\n", obj_refcount(scaler
));
1409 hr
= IWICBitmapScaler_QueryInterface(scaler
, &IID_IMILBitmapScaler
, (void **)&mil_scaler
);
1410 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1412 ok(obj_refcount(scaler
) == 2, "ref count %d\n", obj_refcount(scaler
));
1413 ok(obj_refcount(mil_scaler
) == 2, "ref count %d\n", obj_refcount(mil_scaler
));
1415 hr
= IWICBitmapScaler_QueryInterface(scaler
, &IID_IUnknown
, (void **)&wic_unknown
);
1416 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1418 hr
= mil_scaler
->lpVtbl
->QueryInterface(mil_scaler
, &IID_IUnknown
, (void **)&mil_unknown
);
1419 ok(hr
== S_OK
, "QueryInterface error %#x\n", hr
);
1420 ok((void *)wic_unknown
->lpVtbl
== (void *)mil_unknown
->lpVtbl
, "wrong lpVtbl ptrs %p != %p\n", wic_unknown
->lpVtbl
, mil_unknown
->lpVtbl
);
1422 IUnknown_Release(wic_unknown
);
1423 IUnknown_Release(mil_unknown
);
1425 hr
= mil_scaler
->lpVtbl
->GetPixelFormat(mil_scaler
, &MIL_format
);
1426 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "GetPixelFormat error %#x\n", hr
);
1428 hr
= mil_scaler
->lpVtbl
->GetResolution(mil_scaler
, &dpix
, &dpiy
);
1429 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "GetResolution error %#x\n", hr
);
1431 hr
= mil_scaler
->lpVtbl
->GetSize(mil_scaler
, &width
, &height
);
1432 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "GetSize error %#x\n", hr
);
1434 memset(buf
, 0xde, sizeof(buf
));
1435 hr
= mil_scaler
->lpVtbl
->CopyPixels(mil_scaler
, NULL
, 3, sizeof(buf
), buf
);
1436 ok(hr
== WINCODEC_ERR_NOTINITIALIZED
, "CopyPixels error %#x\n", hr
);
1438 hr
= mil_scaler
->lpVtbl
->Initialize(mil_scaler
, mil_source
, 1, 1, 1);
1439 ok(hr
== S_OK
, "Initialize error %#x\n", hr
);
1441 hr
= mil_scaler
->lpVtbl
->GetPixelFormat(mil_scaler
, &MIL_format
);
1442 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
1443 ok(MIL_format
== 0x0c, "wrong format %d\n", MIL_format
);
1445 hr
= mil_scaler
->lpVtbl
->GetResolution(mil_scaler
, &dpix
, &dpiy
);
1446 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
1447 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
1448 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
1450 hr
= mil_scaler
->lpVtbl
->GetSize(mil_scaler
, &width
, &height
);
1451 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
1452 ok(width
== 1, "got %u, expected 1\n", width
);
1453 ok(height
== 1, "got %u, expected 1\n", height
);
1455 memset(buf
, 0xde, sizeof(buf
));
1456 hr
= mil_scaler
->lpVtbl
->CopyPixels(mil_scaler
, NULL
, 3, sizeof(buf
), buf
);
1457 ok(hr
== S_OK
, "CopyPixels error %#x\n", hr
);
1458 ok(buf
[0] == 0 && buf
[1] == 0 && buf
[2] == 0 && buf
[3] == 0xde,"wrong data: %02x %02x %02x %02x\n", buf
[0], buf
[1], buf
[2], buf
[3]);
1460 mil_scaler
->lpVtbl
->Release(mil_scaler
);
1461 IWICBitmapScaler_Release(scaler
);
1462 mil_source
->lpVtbl
->Release(mil_source
);
1463 mil_bitmap
->lpVtbl
->Release(mil_bitmap
);
1464 IWICBitmap_Release(bitmap
);
1471 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1473 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
1474 &IID_IWICImagingFactory
, (void**)&factory
);
1475 ok(SUCCEEDED(hr
), "CoCreateInstance failed, hr=%x\n", hr
);
1478 test_createbitmap();
1479 test_createbitmapfromsource();
1480 test_CreateBitmapFromMemory();
1481 test_CreateBitmapFromHICON();
1482 test_CreateBitmapFromHBITMAP();
1484 test_bitmap_scaler();
1486 IWICImagingFactory_Release(factory
);
1490 test_WICCreateBitmapFromSectionEx();