gdiplus: Add GdipGetPenCompoundCount implementation.
[wine.git] / dlls / windowscodecs / tests / bmpformat.c
blobe21fa1ee0359ae6965e32b38997b8ce4a705d8b7
1 /*
2 * Copyright 2009 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
19 #include <stdarg.h>
20 #include <math.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "objbase.h"
26 #include "wincodec.h"
27 #include "wincodecsdk.h"
28 #include "wine/test.h"
30 static const char testbmp_24bpp[] = {
31 /* BITMAPFILEHEADER */
32 66,77, /* "BM" */
33 78,0,0,0, /* file size */
34 0,0,0,0, /* reserved */
35 54,0,0,0, /* offset to bits */
36 /* BITMAPINFOHEADER */
37 40,0,0,0, /* header size */
38 2,0,0,0, /* width */
39 3,0,0,0, /* height */
40 1,0, /* planes */
41 24,0, /* bit count */
42 0,0,0,0, /* compression */
43 0,0,0,0, /* image size */
44 0x74,0x12,0,0, /* X pels per meter => 120 dpi */
45 0,0,0,0, /* Y pels per meter */
46 0,0,0,0, /* colors used */
47 0,0,0,0, /* colors important */
48 /* bits */
49 0,0,0, 0,255,0, 0,0,
50 255,0,0, 255,255,0, 0,0,
51 255,0,255, 255,255,255, 0,0
54 static void test_decode_24bpp(void)
56 IWICBitmapDecoder *decoder, *decoder2;
57 IWICBitmapFrameDecode *framedecode;
58 IWICMetadataQueryReader *queryreader;
59 IWICColorContext *colorcontext;
60 IWICBitmapSource *thumbnail;
61 HRESULT hr;
62 HGLOBAL hbmpdata;
63 char *bmpdata;
64 IStream *bmpstream;
65 DWORD capability=0;
66 GUID guidresult;
67 UINT count=0, width=0, height=0;
68 double dpiX, dpiY;
69 BYTE imagedata[36] = {1};
70 const BYTE expected_imagedata[36] = {
71 255,0,255, 255,255,255,
72 255,0,0, 255,255,0,
73 0,0,0, 0,255,0};
74 WICRect rc;
76 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
77 &IID_IWICBitmapDecoder, (void**)&decoder);
78 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
79 if (FAILED(hr)) return;
81 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
82 ok(hbmpdata != 0, "GlobalAlloc failed\n");
83 if (hbmpdata)
85 bmpdata = GlobalLock(hbmpdata);
86 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
87 GlobalUnlock(hbmpdata);
89 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
90 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
91 if (SUCCEEDED(hr))
93 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
94 ok(hr == S_OK || broken(hr == WINCODEC_ERR_BADIMAGE) /* XP */, "Initialize failed, hr=%lx\n", hr);
95 if (FAILED(hr))
97 win_skip("BMP decoder failed to initialize\n");
98 GlobalFree(hbmpdata);
99 IWICBitmapDecoder_Release(decoder);
100 return;
103 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
104 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
105 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
107 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader);
108 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %lx\n", hr);
110 hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, &colorcontext, &count);
111 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %lx\n", hr);
113 hr = IWICBitmapDecoder_GetThumbnail(decoder, &thumbnail);
114 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %lx\n", hr);
116 hr = IWICBitmapDecoder_GetPreview(decoder, &thumbnail);
117 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %lx\n", hr);
119 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
120 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%lx\n", hr);
121 ok(count == 1, "unexpected count %u\n", count);
123 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
124 ok(hr == E_INVALIDARG || hr == WINCODEC_ERR_FRAMEMISSING, "GetFrame returned %lx\n", hr);
126 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
127 ok(SUCCEEDED(hr), "GetFrame failed, hr=%lx\n", hr);
128 if (SUCCEEDED(hr))
130 IWICImagingFactory *factory;
131 IWICPalette *palette;
133 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
134 ok(SUCCEEDED(hr), "GetSize failed, hr=%lx\n", hr);
135 ok(width == 2, "expected width=2, got %u\n", width);
136 ok(height == 3, "expected height=2, got %u\n", height);
138 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
139 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
140 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
141 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
143 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
144 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%lx\n", hr);
145 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
147 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(framedecode, &queryreader);
148 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %lx\n", hr);
150 hr = IWICBitmapFrameDecode_GetColorContexts(framedecode, 1, &colorcontext, &count);
151 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %lx\n", hr);
153 hr = IWICBitmapFrameDecode_GetThumbnail(framedecode, &thumbnail);
154 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %lx\n", hr);
156 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
157 &IID_IWICImagingFactory, (void**)&factory);
158 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
159 if (SUCCEEDED(hr))
161 hr = IWICImagingFactory_CreatePalette(factory, &palette);
162 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%lx\n", hr);
163 if (SUCCEEDED(hr))
165 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
166 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
168 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
169 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
171 IWICPalette_Release(palette);
174 IWICImagingFactory_Release(factory);
177 rc.X = 0;
178 rc.Y = 0;
179 rc.Width = 3;
180 rc.Height = 3;
181 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
182 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %lx\n", hr);
184 rc.X = -1;
185 rc.Y = 0;
186 rc.Width = 2;
187 rc.Height = 3;
188 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
189 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %lx\n", hr);
191 rc.X = 0;
192 rc.Y = 0;
193 rc.Width = 2;
194 rc.Height = 3;
195 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
196 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %lx\n", hr);
198 rc.X = 0;
199 rc.Y = 0;
200 rc.Width = 2;
201 rc.Height = 3;
202 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
203 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %lx\n", hr);
205 rc.X = 0;
206 rc.Y = 0;
207 rc.Width = 2;
208 rc.Height = 3;
209 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
210 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%lx\n", hr);
211 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
213 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, NULL, 6, sizeof(imagedata), imagedata);
214 ok(SUCCEEDED(hr), "CopyPixels(rect=NULL) failed, hr=%lx\n", hr);
215 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
217 IWICBitmapFrameDecode_Release(framedecode);
220 /* cannot initialize twice */
221 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
222 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%lx\n", hr);
224 /* cannot querycapability after initialize */
225 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
226 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%lx\n", hr);
228 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
229 &IID_IWICBitmapDecoder, (void**)&decoder2);
230 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
231 if (SUCCEEDED(hr))
233 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
234 ok(hr == S_OK, "QueryCapability failed, hr=%lx\n", hr);
235 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
236 "unexpected capabilities: %lx\n", capability);
238 /* cannot initialize after querycapability */
239 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
240 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%lx\n", hr);
242 /* cannot querycapability twice */
243 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
244 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%lx\n", hr);
246 IWICBitmapDecoder_Release(decoder2);
249 IStream_Release(bmpstream);
252 GlobalFree(hbmpdata);
255 IWICBitmapDecoder_Release(decoder);
258 static const char testbmp_1bpp[] = {
259 /* BITMAPFILEHEADER */
260 66,77, /* "BM" */
261 40,0,0,0, /* file size */
262 0,0,0,0, /* reserved */
263 32,0,0,0, /* offset to bits */
264 /* BITMAPCOREHEADER */
265 12,0,0,0, /* header size */
266 2,0, /* width */
267 2,0, /* height */
268 1,0, /* planes */
269 1,0, /* bit count */
270 /* color table */
271 255,0,0,
272 0,255,0,
273 /* bits */
274 0xc0,0,0,0,
275 0x80,0,0,0
278 static void test_decode_1bpp(void)
280 IWICBitmapDecoder *decoder, *decoder2;
281 IWICBitmapFrameDecode *framedecode;
282 HRESULT hr;
283 HGLOBAL hbmpdata;
284 char *bmpdata;
285 IStream *bmpstream;
286 DWORD capability=0;
287 GUID guidresult;
288 UINT count=0, width=0, height=0;
289 double dpiX, dpiY;
290 BYTE imagedata[2] = {1};
291 const BYTE expected_imagedata[2] = {0x80,0xc0};
292 WICColor palettedata[2] = {1};
293 const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
294 WICRect rc;
296 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
297 &IID_IWICBitmapDecoder, (void**)&decoder);
298 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
299 if (FAILED(hr)) return;
301 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
302 ok(hbmpdata != 0, "GlobalAlloc failed\n");
303 if (hbmpdata)
305 bmpdata = GlobalLock(hbmpdata);
306 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
307 GlobalUnlock(hbmpdata);
309 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
310 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
311 if (SUCCEEDED(hr))
313 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
314 ok(hr == S_OK, "Initialize failed, hr=%lx\n", hr);
316 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
317 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
318 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
320 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
321 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%lx\n", hr);
322 ok(count == 1, "unexpected count %u\n", count);
324 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
325 ok(SUCCEEDED(hr), "GetFrame failed, hr=%lx\n", hr);
326 if (SUCCEEDED(hr))
328 IWICImagingFactory *factory;
329 IWICPalette *palette;
331 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
332 ok(SUCCEEDED(hr), "GetSize failed, hr=%lx\n", hr);
333 ok(width == 2, "expected width=2, got %u\n", width);
334 ok(height == 2, "expected height=2, got %u\n", height);
336 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
337 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
338 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
339 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
341 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
342 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%lx\n", hr);
343 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
345 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
346 &IID_IWICImagingFactory, (void**)&factory);
347 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
348 if (SUCCEEDED(hr))
350 hr = IWICImagingFactory_CreatePalette(factory, &palette);
351 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%lx\n", hr);
352 if (SUCCEEDED(hr))
354 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
355 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
357 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
358 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%lx\n", hr);
360 hr = IWICPalette_GetColorCount(palette, &count);
361 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
362 ok(count == 2, "expected count=2, got %u\n", count);
364 hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
365 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
366 ok(count == 2, "expected count=2, got %u\n", count);
367 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
369 IWICPalette_Release(palette);
372 IWICImagingFactory_Release(factory);
375 rc.X = 0;
376 rc.Y = 0;
377 rc.Width = 2;
378 rc.Height = 2;
379 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
380 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%lx\n", hr);
381 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
383 IWICBitmapFrameDecode_Release(framedecode);
386 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
387 &IID_IWICBitmapDecoder, (void**)&decoder2);
388 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
389 if (SUCCEEDED(hr))
391 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
392 ok(hr == S_OK, "QueryCapability failed, hr=%lx\n", hr);
393 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
394 "unexpected capabilities: %lx\n", capability);
395 IWICBitmapDecoder_Release(decoder2);
398 IStream_Release(bmpstream);
401 GlobalFree(hbmpdata);
404 IWICBitmapDecoder_Release(decoder);
407 static const char testbmp_4bpp[] = {
408 /* BITMAPFILEHEADER */
409 66,77, /* "BM" */
410 82,0,0,0, /* file size */
411 0,0,0,0, /* reserved */
412 74,0,0,0, /* offset to bits */
413 /* BITMAPINFOHEADER */
414 40,0,0,0, /* header size */
415 2,0,0,0, /* width */
416 254,255,255,255, /* height = -2 */
417 1,0, /* planes */
418 4,0, /* bit count */
419 0,0,0,0, /* compression = BI_RGB */
420 0,0,0,0, /* image size = 0 */
421 16,39,0,0, /* X pixels per meter = 10000 */
422 32,78,0,0, /* Y pixels per meter = 20000 */
423 5,0,0,0, /* colors used */
424 5,0,0,0, /* colors important */
425 /* color table */
426 255,0,0,0,
427 0,255,0,255,
428 0,0,255,23,
429 128,0,128,1,
430 255,255,255,0,
431 /* bits */
432 0x01,0,0,0,
433 0x23,0,0,0,
436 static void test_decode_4bpp(void)
438 IWICBitmapDecoder *decoder, *decoder2;
439 IWICBitmapFrameDecode *framedecode;
440 HRESULT hr;
441 HGLOBAL hbmpdata;
442 char *bmpdata;
443 IStream *bmpstream;
444 DWORD capability=0;
445 GUID guidresult;
446 UINT count=0, width=0, height=0;
447 double dpiX, dpiY;
448 BYTE imagedata[2] = {1};
449 const BYTE expected_imagedata[2] = {0x01,0x23};
450 WICColor palettedata[5] = {1};
451 const WICColor expected_palettedata[5] =
452 {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
453 WICRect rc;
455 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
456 &IID_IWICBitmapDecoder, (void**)&decoder);
457 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
458 if (FAILED(hr)) return;
460 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
461 ok(hbmpdata != 0, "GlobalAlloc failed\n");
462 if (hbmpdata)
464 bmpdata = GlobalLock(hbmpdata);
465 memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
466 GlobalUnlock(hbmpdata);
468 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
469 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
470 if (SUCCEEDED(hr))
472 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
473 ok(hr == S_OK, "Initialize failed, hr=%lx\n", hr);
475 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
476 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
477 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
479 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
480 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%lx\n", hr);
481 ok(count == 1, "unexpected count %u\n", count);
483 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
484 ok(SUCCEEDED(hr), "GetFrame failed, hr=%lx\n", hr);
485 if (SUCCEEDED(hr))
487 IWICImagingFactory *factory;
488 IWICPalette *palette;
490 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
491 ok(SUCCEEDED(hr), "GetSize failed, hr=%lx\n", hr);
492 ok(width == 2, "expected width=2, got %u\n", width);
493 ok(height == 2, "expected height=2, got %u\n", height);
495 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
496 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
497 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
498 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
500 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
501 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%lx\n", hr);
502 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
504 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
505 &IID_IWICImagingFactory, (void**)&factory);
506 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
507 if (SUCCEEDED(hr))
509 hr = IWICImagingFactory_CreatePalette(factory, &palette);
510 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%lx\n", hr);
511 if (SUCCEEDED(hr))
513 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
514 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
516 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
517 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%lx\n", hr);
519 hr = IWICPalette_GetColorCount(palette, &count);
520 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
521 ok(count == 5, "expected count=5, got %u\n", count);
523 hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
524 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
525 ok(count == 5, "expected count=5, got %u\n", count);
526 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
528 IWICPalette_Release(palette);
531 IWICImagingFactory_Release(factory);
534 rc.X = 0;
535 rc.Y = 0;
536 rc.Width = 2;
537 rc.Height = 2;
538 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
539 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%lx\n", hr);
540 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
542 IWICBitmapFrameDecode_Release(framedecode);
545 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
546 &IID_IWICBitmapDecoder, (void**)&decoder2);
547 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
548 if (SUCCEEDED(hr))
550 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
551 ok(hr == S_OK, "QueryCapability failed, hr=%lx\n", hr);
552 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
553 "unexpected capabilities: %lx\n", capability);
554 IWICBitmapDecoder_Release(decoder2);
557 IStream_Release(bmpstream);
560 GlobalFree(hbmpdata);
563 IWICBitmapDecoder_Release(decoder);
566 static const char testbmp_rle8[] = {
567 /* BITMAPFILEHEADER */
568 66,77, /* "BM" */
569 202,0,0,0, /* file size */
570 0,0,0,0, /* reserved */
571 122,0,0,0, /* offset to bits */
572 /* BITMAPINFOHEADER */
573 40,0,0,0, /* header size */
574 8,0,0,0, /* width */
575 8,0,0,0, /* height */
576 1,0, /* planes */
577 8,0, /* bit count */
578 1,0,0,0, /* compression = BI_RLE8 */
579 80,0,0,0, /* image size */
580 19,11,0,0, /* X pixels per meter */
581 19,11,0,0, /* Y pixels per meter */
582 17,0,0,0, /* colors used */
583 17,0,0,0, /* colors important */
584 /* color table */
585 0,0,0,0,
586 17,17,17,0,
587 255,0,0,0,
588 34,34,34,0,
589 0,0,204,0,
590 0,0,221,0,
591 0,0,238,0,
592 51,51,51,0,
593 0,0,255,0,
594 68,68,68,0,
595 255,0,255,0,
596 85,85,85,0,
597 0,204,0,0,
598 0,221,0,0,
599 0,238,0,0,
600 0,255,0,0,
601 255,255,255,0,
602 /* bits */
603 4,15,0,4,11,9,9,0,0,0,4,14,0,4,3,10,10,7,0,0,4,13,0,4,3,10,10,7,0,0,4,12,0,4,0,1,1,11,0,0,0,4,16,2,16,2,4,4,0,0,0,4,2,16,2,16,4,5,0,0,0,4,16,2,16,2,4,6,0,0,0,4,2,16,2,16,4,8,0,1
606 static void test_decode_rle8(void)
608 IWICBitmapDecoder *decoder, *decoder2;
609 IWICBitmapFrameDecode *framedecode;
610 HRESULT hr;
611 HGLOBAL hbmpdata;
612 char *bmpdata;
613 IStream *bmpstream;
614 DWORD capability=0;
615 GUID guidresult;
616 UINT count=0, width=0, height=0;
617 double dpiX, dpiY;
618 DWORD imagedata[64] = {1};
619 const DWORD expected_imagedata[64] = {
620 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
621 0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
622 0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
623 0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
624 0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
625 0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
626 0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
627 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
628 WICColor palettedata[17] = {1};
629 const WICColor expected_palettedata[17] = {
630 0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
631 0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
632 0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
633 WICRect rc;
635 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
636 &IID_IWICBitmapDecoder, (void**)&decoder);
637 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
638 if (FAILED(hr)) return;
640 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
641 ok(hbmpdata != 0, "GlobalAlloc failed\n");
642 if (hbmpdata)
644 bmpdata = GlobalLock(hbmpdata);
645 memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
646 GlobalUnlock(hbmpdata);
648 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
649 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
650 if (SUCCEEDED(hr))
652 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
653 ok(hr == S_OK, "Initialize failed, hr=%lx\n", hr);
655 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
656 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
657 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
659 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
660 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%lx\n", hr);
661 ok(count == 1, "unexpected count %u\n", count);
663 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
664 ok(SUCCEEDED(hr), "GetFrame failed, hr=%lx\n", hr);
665 if (SUCCEEDED(hr))
667 IWICImagingFactory *factory;
668 IWICPalette *palette;
670 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
671 ok(SUCCEEDED(hr), "GetSize failed, hr=%lx\n", hr);
672 ok(width == 8, "expected width=8, got %u\n", width);
673 ok(height == 8, "expected height=8, got %u\n", height);
675 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
676 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
677 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
678 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
680 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
681 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%lx\n", hr);
682 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
684 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
685 &IID_IWICImagingFactory, (void**)&factory);
686 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
687 if (SUCCEEDED(hr))
689 hr = IWICImagingFactory_CreatePalette(factory, &palette);
690 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%lx\n", hr);
691 if (SUCCEEDED(hr))
693 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
694 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
696 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
697 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%lx\n", hr);
699 hr = IWICPalette_GetColorCount(palette, &count);
700 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
701 ok(count == 17, "expected count=17, got %u\n", count);
703 hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
704 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
705 ok(count == 17, "expected count=17, got %u\n", count);
706 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
708 IWICPalette_Release(palette);
711 IWICImagingFactory_Release(factory);
714 rc.X = 0;
715 rc.Y = 0;
716 rc.Width = 8;
717 rc.Height = 8;
718 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
719 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%lx\n", hr);
720 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
722 IWICBitmapFrameDecode_Release(framedecode);
725 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
726 &IID_IWICBitmapDecoder, (void**)&decoder2);
727 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
728 if (SUCCEEDED(hr))
730 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
731 ok(hr == S_OK, "QueryCapability failed, hr=%lx\n", hr);
732 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
733 "unexpected capabilities: %lx\n", capability);
734 IWICBitmapDecoder_Release(decoder2);
737 IStream_Release(bmpstream);
740 GlobalFree(hbmpdata);
743 IWICBitmapDecoder_Release(decoder);
746 static const char testbmp_rle4[] = {
747 /* BITMAPFILEHEADER */
748 66,77, /* "BM" */
749 142,0,0,0, /* file size */
750 0,0,0,0, /* reserved */
751 78,0,0,0, /* offset to bits */
752 /* BITMAPINFOHEADER */
753 40,0,0,0, /* header size */
754 8,0,0,0, /* width */
755 8,0,0,0, /* height */
756 1,0, /* planes */
757 4,0, /* bit count */
758 2,0,0,0, /* compression = BI_RLE4 */
759 64,0,0,0, /* image size */
760 19,11,0,0, /* X pixels per meter */
761 19,11,0,0, /* Y pixels per meter */
762 6,0,0,0, /* colors used */
763 6,0,0,0, /* colors important */
764 /* color table */
765 0,0,0,0,
766 255,0,0,0,
767 0,0,255,0,
768 255,0,255,0,
769 0,255,0,0,
770 255,255,255,0,
771 /* bits */
772 0,8,68,68,0,0,0,0,0,8,68,68,3,48,0,0,0,8,68,68,3,48,0,0,0,8,68,68,0,0,0,0,0,8,81,81,34,34,0,0,0,8,21,21,34,34,0,0,0,8,81,81,34,34,0,0,0,8,21,21,34,34,0,1
775 static void test_decode_rle4(void)
777 IWICBitmapDecoder *decoder, *decoder2;
778 IWICBitmapFrameDecode *framedecode;
779 HRESULT hr;
780 HGLOBAL hbmpdata;
781 char *bmpdata;
782 IStream *bmpstream;
783 DWORD capability=0;
784 GUID guidresult;
785 UINT count=0, width=0, height=0;
786 double dpiX, dpiY;
787 DWORD imagedata[64] = {1};
788 const DWORD expected_imagedata[64] = {
789 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
790 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
791 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
792 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
793 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
794 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
795 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
796 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
797 WICColor palettedata[6] = {1};
798 const WICColor expected_palettedata[6] = {
799 0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
800 WICRect rc;
802 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
803 &IID_IWICBitmapDecoder, (void**)&decoder);
804 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
805 if (FAILED(hr)) return;
807 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
808 ok(hbmpdata != 0, "GlobalAlloc failed\n");
809 if (hbmpdata)
811 bmpdata = GlobalLock(hbmpdata);
812 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
813 GlobalUnlock(hbmpdata);
815 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
816 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
817 if (SUCCEEDED(hr))
819 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
820 ok(hr == S_OK, "Initialize failed, hr=%lx\n", hr);
822 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
823 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
824 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
826 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
827 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%lx\n", hr);
828 ok(count == 1, "unexpected count %u\n", count);
830 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
831 ok(SUCCEEDED(hr), "GetFrame failed, hr=%lx\n", hr);
832 if (SUCCEEDED(hr))
834 IWICImagingFactory *factory;
835 IWICPalette *palette;
837 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
838 ok(SUCCEEDED(hr), "GetSize failed, hr=%lx\n", hr);
839 ok(width == 8, "expected width=8, got %u\n", width);
840 ok(height == 8, "expected height=8, got %u\n", height);
842 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
843 ok(SUCCEEDED(hr), "GetResolution failed, hr=%lx\n", hr);
844 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
845 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
847 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
848 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%lx\n", hr);
849 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
851 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
852 &IID_IWICImagingFactory, (void**)&factory);
853 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
854 if (SUCCEEDED(hr))
856 hr = IWICImagingFactory_CreatePalette(factory, &palette);
857 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%lx\n", hr);
858 if (SUCCEEDED(hr))
860 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
861 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %lx\n", hr);
863 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
864 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%lx\n", hr);
866 hr = IWICPalette_GetColorCount(palette, &count);
867 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
868 ok(count == 6, "expected count=6, got %u\n", count);
870 hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
871 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%lx\n", hr);
872 ok(count == 6, "expected count=6, got %u\n", count);
873 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
875 IWICPalette_Release(palette);
878 IWICImagingFactory_Release(factory);
881 rc.X = 0;
882 rc.Y = 0;
883 rc.Width = 8;
884 rc.Height = 8;
885 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
886 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%lx\n", hr);
887 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
889 IWICBitmapFrameDecode_Release(framedecode);
892 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
893 &IID_IWICBitmapDecoder, (void**)&decoder2);
894 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
895 if (SUCCEEDED(hr))
897 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
898 ok(hr == S_OK, "QueryCapability failed, hr=%lx\n", hr);
899 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
900 "unexpected capabilities: %lx\n", capability);
901 IWICBitmapDecoder_Release(decoder2);
904 IStream_Release(bmpstream);
907 GlobalFree(hbmpdata);
910 IWICBitmapDecoder_Release(decoder);
913 static void test_componentinfo(void)
915 IWICImagingFactory *factory;
916 IWICComponentInfo *info;
917 IWICBitmapDecoderInfo *decoderinfo;
918 IWICBitmapDecoder *decoder;
919 HRESULT hr;
920 WICBitmapPattern *patterns;
921 UINT pattern_count, pattern_size;
922 WICComponentType type;
923 GUID guidresult;
924 HGLOBAL hbmpdata;
925 char *bmpdata;
926 IStream *bmpstream;
927 BOOL boolresult;
929 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
930 &IID_IWICImagingFactory, (void**)&factory);
931 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
932 if (SUCCEEDED(hr))
934 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
935 ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%lx\n", hr);
936 if (SUCCEEDED(hr))
938 hr = IWICComponentInfo_GetComponentType(info, &type);
939 ok(SUCCEEDED(hr), "GetComponentType failed, hr=%lx\n", hr);
940 ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
942 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
943 ok(SUCCEEDED(hr), "QueryInterface failed, hr=%lx\n", hr);
944 if (SUCCEEDED(hr))
946 pattern_count = 0;
947 pattern_size = 0;
948 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
949 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%lx\n", hr);
950 ok(pattern_count != 0, "pattern count is 0\n");
951 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
953 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
954 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
955 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%lx\n", hr);
956 ok(pattern_count != 0, "pattern count is 0\n");
957 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
958 ok(patterns[0].Length != 0, "pattern length is 0\n");
959 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
960 ok(patterns[0].Mask != NULL, "mask is NULL\n");
962 pattern_size -= 1;
963 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
964 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %lx, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
966 HeapFree(GetProcessHeap(), 0, patterns);
968 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
969 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%lx\n", hr);
970 if (SUCCEEDED(hr))
972 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
973 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
974 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
976 IWICBitmapDecoder_Release(decoder);
979 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
980 ok(hbmpdata != 0, "GlobalAlloc failed\n");
981 if (hbmpdata)
983 bmpdata = GlobalLock(hbmpdata);
984 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
985 GlobalUnlock(hbmpdata);
987 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
988 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
989 if (SUCCEEDED(hr))
991 boolresult = 0;
992 hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
993 ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%lx\n", hr);
994 ok(boolresult, "pattern not matched\n");
996 IStream_Release(bmpstream);
999 GlobalFree(hbmpdata);
1002 IWICBitmapDecoderInfo_Release(decoderinfo);
1005 IWICComponentInfo_Release(info);
1008 IWICImagingFactory_Release(factory);
1012 static void test_createfromstream(void)
1014 IWICBitmapDecoder *decoder;
1015 IWICImagingFactory *factory;
1016 HRESULT hr;
1017 HGLOBAL hbmpdata;
1018 char *bmpdata;
1019 IStream *bmpstream;
1020 GUID guidresult;
1022 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1023 &IID_IWICImagingFactory, (void**)&factory);
1024 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%lx\n", hr);
1025 if (FAILED(hr)) return;
1027 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1028 ok(hbmpdata != 0, "GlobalAlloc failed\n");
1029 if (hbmpdata)
1031 bmpdata = GlobalLock(hbmpdata);
1032 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1033 GlobalUnlock(hbmpdata);
1035 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1036 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%lx\n", hr);
1037 if (SUCCEEDED(hr))
1039 hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1040 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1041 ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%lx\n", hr);
1042 if (SUCCEEDED(hr))
1044 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1045 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%lx\n", hr);
1046 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1048 IWICBitmapDecoder_Release(decoder);
1051 IStream_Release(bmpstream);
1054 GlobalFree(hbmpdata);
1057 IWICImagingFactory_Release(factory);
1060 static void test_create_decoder(void)
1062 IWICBitmapDecoder *decoder;
1063 IWICImagingFactory *factory;
1064 HRESULT hr;
1066 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1067 &IID_IWICImagingFactory, (void **)&factory);
1068 ok(hr == S_OK, "CoCreateInstance error %#lx\n", hr);
1070 hr = IWICImagingFactory_CreateDecoder(factory, NULL, NULL, NULL);
1071 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#lx\n", hr);
1073 hr = IWICImagingFactory_CreateDecoder(factory, NULL, NULL, &decoder);
1074 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#lx\n", hr);
1076 hr = IWICImagingFactory_CreateDecoder(factory, &GUID_ContainerFormatBmp, NULL, &decoder);
1077 ok(hr == S_OK, "CreateDecoder error %#lx\n", hr);
1078 IWICBitmapDecoder_Release(decoder);
1080 hr = IWICImagingFactory_CreateDecoder(factory, &GUID_ContainerFormatBmp, &GUID_VendorMicrosoft, &decoder);
1081 ok(hr == S_OK, "CreateDecoder error %#lx\n", hr);
1082 IWICBitmapDecoder_Release(decoder);
1084 IWICImagingFactory_Release(factory);
1087 static void test_writesource_palette(void)
1089 IWICImagingFactory *factory;
1090 HRESULT hr;
1091 WICColor encode_palette[2] = {0xff111111, 0xffcccccc};
1092 WICColor source_palette[2] = {0xff555555, 0xffaaaaaa};
1093 WICColor result_palette[2];
1094 UINT result_colors;
1095 IWICBitmap *bitmap;
1096 IWICPalette *palette;
1097 IStream *stream;
1098 IWICBitmapEncoder *encoder;
1099 IWICBitmapFrameEncode *frame_encode;
1100 IPropertyBag2 *encode_options;
1101 GUID pixelformat;
1102 IWICBitmapDecoder *decoder;
1103 IWICBitmapFrameDecode *frame_decode;
1105 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1106 &IID_IWICImagingFactory, (void **)&factory);
1107 ok(hr == S_OK, "CoCreateInstance error %#lx\n", hr);
1109 /* Encoder with palette set */
1110 hr = IWICImagingFactory_CreateBitmap(factory, 1, 1, &GUID_WICPixelFormat1bppIndexed,
1111 WICBitmapCacheOnDemand, &bitmap);
1112 ok(hr == S_OK, "CreateBitmap error %#lx\n", hr);
1114 hr = IWICImagingFactory_CreatePalette(factory, &palette);
1115 ok(hr == S_OK, "CreatePalette error %#lx\n", hr);
1117 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1118 ok(hr == S_OK, "CreateStream error %#lx\n", hr);
1120 hr = IWICImagingFactory_CreateEncoder(factory, &GUID_ContainerFormatBmp, &GUID_VendorMicrosoft, &encoder);
1121 ok(hr == S_OK, "CreateDecoder error %#lx\n", hr);
1123 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
1124 ok(hr == S_OK, "IWICBitmapEncoder_Initialize error %#lx\n", hr);
1126 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame_encode, &encode_options);
1127 ok(hr == S_OK, "CreateNewFrame error %#lx\n", hr);
1129 hr = IWICBitmapFrameEncode_Initialize(frame_encode, encode_options);
1130 ok(hr == S_OK, "IWICBitmapFrameEncode_Initialize error %#lx\n", hr);
1132 IPropertyBag2_Release(encode_options);
1134 hr = IWICBitmapFrameEncode_SetSize(frame_encode, 1, 1);
1135 ok(hr == S_OK, "SetSize error %#lx\n", hr);
1137 pixelformat = GUID_WICPixelFormat1bppIndexed;
1138 hr = IWICBitmapFrameEncode_SetPixelFormat(frame_encode, &pixelformat);
1139 ok(hr == S_OK, "SetPixelFormat error %#lx\n", hr);
1140 ok(!memcmp(&pixelformat, &GUID_WICPixelFormat1bppIndexed, sizeof(pixelformat)), "pixel format changed\n");
1142 hr = IWICPalette_InitializeCustom(palette, encode_palette, 2);
1143 ok(hr == S_OK, "InitializeCustom error %#lx\n", hr);
1145 hr = IWICBitmapFrameEncode_SetPalette(frame_encode, palette);
1146 ok(hr == S_OK, "SetPalette error %#lx\n", hr);
1148 hr = IWICPalette_InitializeCustom(palette, source_palette, 2);
1149 ok(hr == S_OK, "InitializeCustom error %#lx\n", hr);
1151 hr = IWICBitmap_SetPalette(bitmap, palette);
1152 ok(hr == S_OK, "SetPalette error %#lx\n", hr);
1154 hr = IWICBitmapFrameEncode_WriteSource(frame_encode, (IWICBitmapSource*)bitmap, NULL);
1155 ok(hr == S_OK, "WriteSource error %#lx\n", hr);
1157 hr = IWICBitmapFrameEncode_Commit(frame_encode);
1158 ok(hr == S_OK, "Commit error %#lx\n", hr);
1160 IWICBitmapFrameEncode_Release(frame_encode);
1162 hr = IWICBitmapEncoder_Commit(encoder);
1163 ok(hr == S_OK, "Commit error %#lx\n", hr);
1165 IWICBitmapEncoder_Release(encoder);
1167 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, WICDecodeMetadataCacheOnLoad, &decoder);
1168 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
1170 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame_decode);
1171 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
1173 hr = IWICBitmapFrameDecode_CopyPalette(frame_decode, palette);
1174 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
1176 hr = IWICPalette_GetColors(palette, 2, result_palette, &result_colors);
1177 ok(hr == S_OK, "GetColors error %#lx\n", hr);
1178 ok(result_colors == 2, "Got %i colors\n", result_colors);
1179 ok(result_palette[0] == encode_palette[0], "Unexpected palette entry: %x\n", result_palette[0]);
1180 ok(result_palette[1] == encode_palette[1], "Unexpected palette entry: %x\n", result_palette[0]);
1182 IWICBitmapFrameDecode_Release(frame_decode);
1183 IWICBitmapDecoder_Release(decoder);
1184 IStream_Release(stream);
1186 /* Encoder with no palette set */
1187 hr = IWICImagingFactory_CreateEncoder(factory, &GUID_ContainerFormatBmp, &GUID_VendorMicrosoft, &encoder);
1188 ok(hr == S_OK, "CreateDecoder error %#lx\n", hr);
1190 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1191 ok(hr == S_OK, "CreateStream error %#lx\n", hr);
1193 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
1194 ok(hr == S_OK, "IWICBitmapEncoder_Initialize error %#lx\n", hr);
1196 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame_encode, &encode_options);
1197 ok(hr == S_OK, "CreateNewFrame error %#lx\n", hr);
1199 hr = IWICBitmapFrameEncode_Initialize(frame_encode, encode_options);
1200 ok(hr == S_OK, "IWICBitmapFrameEncode_Initialize error %#lx\n", hr);
1202 IPropertyBag2_Release(encode_options);
1204 hr = IWICBitmapFrameEncode_SetSize(frame_encode, 1, 1);
1205 ok(hr == S_OK, "SetSize error %#lx\n", hr);
1207 pixelformat = GUID_WICPixelFormat1bppIndexed;
1208 hr = IWICBitmapFrameEncode_SetPixelFormat(frame_encode, &pixelformat);
1209 ok(hr == S_OK, "SetPixelFormat error %#lx\n", hr);
1210 ok(!memcmp(&pixelformat, &GUID_WICPixelFormat1bppIndexed, sizeof(pixelformat)), "pixel format changed\n");
1212 hr = IWICPalette_InitializeCustom(palette, source_palette, 2);
1213 ok(hr == S_OK, "InitializeCustom error %#lx\n", hr);
1215 hr = IWICBitmap_SetPalette(bitmap, palette);
1216 ok(hr == S_OK, "SetPalette error %#lx\n", hr);
1218 hr = IWICBitmapFrameEncode_WriteSource(frame_encode, (IWICBitmapSource*)bitmap, NULL);
1219 if (hr == WINCODEC_ERR_PALETTEUNAVAILABLE)
1221 win_skip("old WriteSource palette behavior\n"); /* winxp */
1222 IWICBitmapFrameEncode_Release(frame_encode);
1223 IWICBitmapEncoder_Release(encoder);
1224 IStream_Release(stream);
1225 IWICPalette_Release(palette);
1226 IWICBitmap_Release(bitmap);
1227 IWICImagingFactory_Release(factory);
1228 return;
1230 ok(hr == S_OK, "WriteSource error %#lx\n", hr);
1232 hr = IWICBitmapFrameEncode_Commit(frame_encode);
1233 ok(hr == S_OK, "Commit error %#lx\n", hr);
1235 IWICBitmapFrameEncode_Release(frame_encode);
1237 hr = IWICBitmapEncoder_Commit(encoder);
1238 ok(hr == S_OK, "Commit error %#lx\n", hr);
1240 IWICBitmapEncoder_Release(encoder);
1242 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, WICDecodeMetadataCacheOnLoad, &decoder);
1243 ok(hr == S_OK, "CreateDecoderFromStream error %#lx\n", hr);
1245 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame_decode);
1246 ok(hr == S_OK, "GetFrame error %#lx\n", hr);
1248 hr = IWICBitmapFrameDecode_CopyPalette(frame_decode, palette);
1249 ok(hr == S_OK, "CopyPalette error %#lx\n", hr);
1251 hr = IWICPalette_GetColors(palette, 2, result_palette, &result_colors);
1252 ok(hr == S_OK, "GetColors error %#lx\n", hr);
1253 ok(result_colors == 2, "Got %i colors\n", result_colors);
1254 ok(result_palette[0] == source_palette[0], "Unexpected palette entry: %x\n", result_palette[0]);
1255 ok(result_palette[1] == source_palette[1], "Unexpected palette entry: %x\n", result_palette[0]);
1257 IWICBitmapFrameDecode_Release(frame_decode);
1258 IWICBitmapDecoder_Release(decoder);
1259 IStream_Release(stream);
1261 IWICPalette_Release(palette);
1262 IWICBitmap_Release(bitmap);
1263 IWICImagingFactory_Release(factory);
1266 START_TEST(bmpformat)
1268 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1270 test_decode_24bpp();
1271 test_decode_1bpp();
1272 test_decode_4bpp();
1273 test_decode_rle8();
1274 test_decode_rle4();
1275 test_componentinfo();
1276 test_createfromstream();
1277 test_create_decoder();
1278 test_writesource_palette();
1280 CoUninitialize();