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 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 todo_wine ok(hr == S_OK, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr);
156 todo_wine 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 */
185 if (base_lock_buffer)
188 memcpy(base_lock_buffer + lock_buffer_stride*i, bitmap_data + i*9, 9);
191 IWICBitmapLock_Release(lock);
194 /* test that the data we wrote is returned by CopyPixels */
195 hr = IWICBitmap_CopyPixels(bitmap, NULL, 9, 27, returned_data);
196 ok(hr == S_OK, "IWICBitmap_CopyPixels failed hr=%x\n", hr);
199 ok(returned_data[i] == bitmap_data[i], "returned_data[%i] == %i\n", i, returned_data[i]);
201 /* try a valid partial rect, and write mode */
206 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock);
207 ok(hr == S_OK, "IWICBitmap_Lock failed hr=%x\n", hr);
211 if (can_lock_null) /* this hangs on xp/vista */
213 /* Can't lock again while locked for writing */
214 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockWrite, &lock2);
215 ok(hr == WINCODEC_ERR_ALREADYLOCKED, "IWICBitmap_Lock failed hr=%x\n", hr);
217 hr = IWICBitmap_Lock(bitmap, &rc, WICBitmapLockRead, &lock2);
218 ok(hr == WINCODEC_ERR_ALREADYLOCKED, "IWICBitmap_Lock failed hr=%x\n", hr);
221 hr = IWICBitmapLock_GetStride(lock, &lock_buffer_stride);
222 ok(hr == S_OK, "IWICBitmapLock_GetStride failed hr=%x\n", hr);
223 ok(lock_buffer_stride == 12, "got %i, expected 12\n", lock_buffer_stride);
225 hr = IWICBitmapLock_GetDataPointer(lock, &lock_buffer_size, &lock_buffer);
226 ok(hr == S_OK, "IWICBitmapLock_GetDataPointer failed hr=%x\n", hr);
227 ok(lock_buffer_size == 15, "got %i, expected 15\n", lock_buffer_size);
228 ok(lock_buffer == base_lock_buffer+6, "got %p, expected %p+6\n", lock_buffer, base_lock_buffer);
230 hr = IWICBitmapLock_GetPixelFormat(lock, &pixelformat);
231 todo_wine ok(hr == S_OK, "IWICBitmapLock_GetPixelFormat failed hr=%x\n", hr);
232 todo_wine ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
234 hr = IWICBitmapLock_GetSize(lock, &width, &height);
235 ok(hr == S_OK, "IWICBitmapLock_GetSize failed hr=%x\n", hr);
236 ok(width == 1, "got %d, expected 1\n", width);
237 ok(height == 2, "got %d, expected 2\n", height);
239 IWICBitmapLock_Release(lock);
243 hr = IWICBitmap_GetPixelFormat(bitmap, &pixelformat);
244 ok(hr == S_OK, "IWICBitmap_GetPixelFormat failed hr=%x\n", hr);
245 ok(IsEqualGUID(&pixelformat, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
247 hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy);
248 ok(hr == S_OK, "IWICBitmap_GetResolution failed hr=%x\n", hr);
249 ok(dpix == 0.0, "got %f, expected 0.0\n", dpix);
250 ok(dpiy == 0.0, "got %f, expected 0.0\n", dpiy);
252 hr = IWICBitmap_SetResolution(bitmap, 12.0, 34.0);
253 ok(hr == S_OK, "IWICBitmap_SetResolution failed hr=%x\n", hr);
255 hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy);
256 ok(hr == S_OK, "IWICBitmap_GetResolution failed hr=%x\n", hr);
257 ok(dpix == 12.0, "got %f, expected 12.0\n", dpix);
258 ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy);
260 hr = IWICBitmap_GetSize(bitmap, &width, &height);
261 ok(hr == S_OK, "IWICBitmap_GetSize failed hr=%x\n", hr);
262 ok(width == 3, "got %d, expected 3\n", width);
263 ok(height == 3, "got %d, expected 3\n", height);
266 IWICBitmap_Release(bitmap);
273 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
275 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
276 &IID_IWICImagingFactory, (void**)&factory);
277 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
281 IWICImagingFactory_Release(factory);