2 * Copyright 2012 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
29 static IWICImagingFactory
*factory
;
31 static void test_createbitmap(void)
36 IWICBitmapLock
*lock
, *lock2
;
37 WICBitmapPaletteType palettetype
;
40 const BYTE bitmap_data
[27] = {
41 128,128,255, 128,128,128, 128,255,128,
42 128,128,128, 128,128,128, 255,255,255,
43 255,128,128, 255,255,255, 255,255,255};
44 BYTE returned_data
[27] = {0};
45 BYTE
*lock_buffer
=NULL
, *base_lock_buffer
=NULL
;
46 UINT lock_buffer_size
=0;
47 UINT lock_buffer_stride
=0;
48 WICPixelFormatGUID pixelformat
= {0};
49 UINT width
=0, height
=0;
50 double dpix
=10.0, dpiy
=10.0;
51 int can_lock_null
= 1;
53 hr
= IWICImagingFactory_CreateBitmap(factory
, 3, 3, &GUID_WICPixelFormat24bppBGR
,
54 WICBitmapCacheOnLoad
, &bitmap
);
55 todo_wine
ok(hr
== S_OK
, "IWICImagingFactory_CreateBitmap failed hr=%x\n", hr
);
60 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
61 ok(hr
== S_OK
, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr
);
63 /* Palette is unavailable until explicitly set */
64 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
65 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
67 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray256
, FALSE
);
68 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
70 hr
= IWICBitmap_SetPalette(bitmap
, palette
);
71 ok(hr
== S_OK
, "IWICBitmap_SetPalette failed hr=%x\n", hr
);
73 hr
= IWICPalette_InitializePredefined(palette
, WICBitmapPaletteTypeFixedGray4
, FALSE
);
74 ok(hr
== S_OK
, "IWICPalette_InitializePredefined failed hr=%x\n", hr
);
76 hr
= IWICBitmap_CopyPalette(bitmap
, palette
);
77 ok(hr
== S_OK
, "IWICBitmap_CopyPalette failed hr=%x\n", hr
);
79 hr
= IWICPalette_GetType(palette
, &palettetype
);
80 ok(hr
== S_OK
, "IWICPalette_GetType failed hr=%x\n", hr
);
81 ok(palettetype
== WICBitmapPaletteTypeFixedGray256
,
82 "expected WICBitmapPaletteTypeFixedGray256, got %x\n", palettetype
);
84 IWICPalette_Release(palette
);
86 /* pixel data is initially zeroed */
87 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 9, 27, returned_data
);
88 ok(hr
== S_OK
, "IWICBitmap_CopyPixels failed hr=%x\n", hr
);
91 ok(returned_data
[i
] == 0, "returned_data[%i] == %i\n", i
, returned_data
[i
]);
93 /* Invalid lock rects */
97 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
98 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
99 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
103 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
104 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
105 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
109 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
110 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
111 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
115 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
116 ok(hr
== E_INVALIDARG
, "IWICBitmap_Lock failed hr=%x\n", hr
);
117 if (SUCCEEDED(hr
)) IWICBitmapLock_Release(lock
);
120 hr
= IWICBitmap_Lock(bitmap
, NULL
, WICBitmapLockRead
, &lock
);
121 ok(hr
== S_OK
|| broken(hr
== E_INVALIDARG
) /* winxp */, "IWICBitmap_Lock failed hr=%x\n", hr
);
125 /* entire bitmap is locked */
126 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
127 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
128 ok(width
== 3, "got %d, expected 3\n", width
);
129 ok(height
== 3, "got %d, expected 3\n", height
);
131 IWICBitmapLock_Release(lock
);
136 /* lock with a valid rect */
138 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock
);
139 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
142 hr
= IWICBitmapLock_GetStride(lock
, &lock_buffer_stride
);
143 ok(hr
== S_OK
, "IWICBitmapLock_GetStride failed hr=%x\n", hr
);
144 /* stride is divisible by 4 */
145 ok(lock_buffer_stride
== 12, "got %i, expected 12\n", lock_buffer_stride
);
147 hr
= IWICBitmapLock_GetDataPointer(lock
, &lock_buffer_size
, &lock_buffer
);
148 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
149 /* buffer size does not include padding from the last row */
150 ok(lock_buffer_size
== 33, "got %i, expected 33\n", lock_buffer_size
);
151 ok(lock_buffer
!= NULL
, "got NULL data pointer\n");
152 base_lock_buffer
= lock_buffer
;
154 hr
= IWICBitmapLock_GetPixelFormat(lock
, &pixelformat
);
155 ok(hr
== S_OK
, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr
);
156 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
158 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
159 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
160 ok(width
== 3, "got %d, expected 3\n", width
);
161 ok(height
== 3, "got %d, expected 3\n", height
);
163 /* We can have multiple simultaneous read locks */
164 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock2
);
165 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
169 hr
= IWICBitmapLock_GetDataPointer(lock2
, &lock_buffer_size
, &lock_buffer
);
170 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
171 ok(lock_buffer_size
== 33, "got %i, expected 33\n", lock_buffer_size
);
172 ok(lock_buffer
== base_lock_buffer
, "got %p, expected %p\n", lock_buffer
, base_lock_buffer
);
174 IWICBitmapLock_Release(lock2
);
177 if (can_lock_null
) /* this hangs on xp/vista */
179 /* But not a read and a write lock */
180 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock2
);
181 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
184 /* But we don't need a write lock to write */
186 memcpy(base_lock_buffer
+ lock_buffer_stride
*i
, bitmap_data
+ i
*9, 9);
188 IWICBitmapLock_Release(lock
);
191 /* test that the data we wrote is returned by CopyPixels */
192 hr
= IWICBitmap_CopyPixels(bitmap
, NULL
, 9, 27, returned_data
);
193 ok(hr
== S_OK
, "IWICBitmap_CopyPixels failed hr=%x\n", hr
);
196 ok(returned_data
[i
] == bitmap_data
[i
], "returned_data[%i] == %i\n", i
, returned_data
[i
]);
198 /* try a valid partial rect, and write mode */
203 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock
);
204 ok(hr
== S_OK
, "IWICBitmap_Lock failed hr=%x\n", hr
);
208 if (can_lock_null
) /* this hangs on xp/vista */
210 /* Can't lock again while locked for writing */
211 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockWrite
, &lock2
);
212 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
214 hr
= IWICBitmap_Lock(bitmap
, &rc
, WICBitmapLockRead
, &lock2
);
215 ok(hr
== WINCODEC_ERR_ALREADYLOCKED
, "IWICBitmap_Lock failed hr=%x\n", hr
);
218 hr
= IWICBitmapLock_GetStride(lock
, &lock_buffer_stride
);
219 ok(hr
== S_OK
, "IWICBitmapLock_GetStride failed hr=%x\n", hr
);
220 ok(lock_buffer_stride
== 12, "got %i, expected 12\n", lock_buffer_stride
);
222 hr
= IWICBitmapLock_GetDataPointer(lock
, &lock_buffer_size
, &lock_buffer
);
223 ok(hr
== S_OK
, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr
);
224 ok(lock_buffer_size
== 15, "got %i, expected 15\n", lock_buffer_size
);
225 ok(lock_buffer
== base_lock_buffer
+6, "got %p, expected %p+6\n", lock_buffer
, base_lock_buffer
);
227 hr
= IWICBitmapLock_GetPixelFormat(lock
, &pixelformat
);
228 ok(hr
== S_OK
, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr
);
229 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
231 hr
= IWICBitmapLock_GetSize(lock
, &width
, &height
);
232 ok(hr
== S_OK
, "IWICBitmapLock_GetSize failed hr=%x\n", hr
);
233 ok(width
== 1, "got %d, expected 1\n", width
);
234 ok(height
== 2, "got %d, expected 2\n", height
);
236 IWICBitmapLock_Release(lock
);
239 hr
= IWICBitmap_GetPixelFormat(bitmap
, &pixelformat
);
240 ok(hr
== S_OK
, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr
);
241 ok(IsEqualGUID(&pixelformat
, &GUID_WICPixelFormat24bppBGR
), "unexpected pixel format\n");
243 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
244 ok(hr
== S_OK
, "IWICBitmap_GetResolution failed hr=%x\n", hr
);
245 ok(dpix
== 0.0, "got %f, expected 0.0\n", dpix
);
246 ok(dpiy
== 0.0, "got %f, expected 0.0\n", dpiy
);
248 hr
= IWICBitmap_SetResolution(bitmap
, 12.0, 34.0);
249 ok(hr
== S_OK
, "IWICBitmap_SetResolution failed hr=%x\n", hr
);
251 hr
= IWICBitmap_GetResolution(bitmap
, &dpix
, &dpiy
);
252 ok(hr
== S_OK
, "IWICBitmap_GetResolution failed hr=%x\n", hr
);
253 ok(dpix
== 12.0, "got %f, expected 12.0\n", dpix
);
254 ok(dpiy
== 34.0, "got %f, expected 34.0\n", dpiy
);
256 hr
= IWICBitmap_GetSize(bitmap
, &width
, &height
);
257 ok(hr
== S_OK
, "IWICBitmap_GetSize failed hr=%x\n", hr
);
258 ok(width
== 3, "got %d, expected 3\n", width
);
259 ok(height
== 3, "got %d, expected 3\n", height
);
261 IWICBitmap_Release(bitmap
);
268 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
270 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
271 &IID_IWICImagingFactory
, (void**)&factory
);
272 ok(SUCCEEDED(hr
), "CoCreateInstance failed, hr=%x\n", hr
);
276 IWICImagingFactory_Release(factory
);