comctl32/listview: Free ID array when removing all items.
[wine] / dlls / windowscodecs / tests / bmpformat.c
1 /*
2  * Copyright 2009 Vincent Povirk for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <math.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "initguid.h"
26 #include "objbase.h"
27 #include "wincodec.h"
28 #include "wine/test.h"
29
30 static const char testbmp_24bpp[] = {
31     /* BITMAPFILEHEADER */
32     66,77, /* "BM" */
33     50,0,0,0, /* file size */
34     0,0,0,0, /* reserved */
35     26,0,0,0, /* offset to bits */
36     /* BITMAPCOREHEADER */
37     12,0,0,0, /* header size */
38     2,0, /* width */
39     3,0, /* height */
40     1,0, /* planes */
41     24,0, /* bit count */
42     /* bits */
43     0,0,0,     0,255,0,     0,0,
44     255,0,0,   255,255,0,   0,0,
45     255,0,255, 255,255,255, 0,0
46 };
47
48 static void test_decode_24bpp(void)
49 {
50     IWICBitmapDecoder *decoder, *decoder2;
51     IWICBitmapFrameDecode *framedecode;
52     IWICMetadataQueryReader *queryreader;
53     IWICColorContext *colorcontext;
54     IWICBitmapSource *thumbnail;
55     HRESULT hr;
56     HGLOBAL hbmpdata;
57     char *bmpdata;
58     IStream *bmpstream;
59     DWORD capability=0;
60     GUID guidresult;
61     UINT count=0, width=0, height=0;
62     double dpiX, dpiY;
63     BYTE imagedata[36] = {1};
64     const BYTE expected_imagedata[36] = {
65         255,0,255, 255,255,255,
66         255,0,0,   255,255,0,
67         0,0,0,     0,255,0};
68     WICRect rc;
69
70     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
71         &IID_IWICBitmapDecoder, (void**)&decoder);
72     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
73     if (FAILED(hr)) return;
74
75     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
76     ok(hbmpdata != 0, "GlobalAlloc failed\n");
77     if (hbmpdata)
78     {
79         bmpdata = GlobalLock(hbmpdata);
80         memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
81         GlobalUnlock(hbmpdata);
82
83         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
84         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
85         if (SUCCEEDED(hr))
86         {
87             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
88             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
89
90             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
91             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
92             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
93
94             hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader);
95             ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
96
97             hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, &colorcontext, &count);
98             ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
99
100             hr = IWICBitmapDecoder_GetThumbnail(decoder, &thumbnail);
101             ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
102
103             hr = IWICBitmapDecoder_GetPreview(decoder, &thumbnail);
104             ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
105
106             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
107             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
108             ok(count == 1, "unexpected count %u\n", count);
109
110             hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
111             ok(hr == E_INVALIDARG || hr == WINCODEC_ERR_FRAMEMISSING, "GetFrame returned %x\n", hr);
112
113             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
114             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
115             if (SUCCEEDED(hr))
116             {
117                 IWICImagingFactory *factory;
118                 IWICPalette *palette;
119
120                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
121                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
122                 ok(width == 2, "expected width=2, got %u\n", width);
123                 ok(height == 3, "expected height=2, got %u\n", height);
124
125                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
126                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
127                 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
128                 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
129
130                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
131                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
132                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
133
134                 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(framedecode, &queryreader);
135                 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
136
137                 hr = IWICBitmapFrameDecode_GetColorContexts(framedecode, 1, &colorcontext, &count);
138                 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
139
140                 hr = IWICBitmapFrameDecode_GetThumbnail(framedecode, &thumbnail);
141                 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
142
143                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
144                     &IID_IWICImagingFactory, (void**)&factory);
145                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
146                 if (SUCCEEDED(hr))
147                 {
148                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
149                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
150                     if (SUCCEEDED(hr))
151                     {
152                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
153                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
154
155                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
156                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
157
158                         IWICPalette_Release(palette);
159                     }
160
161                     IWICImagingFactory_Release(factory);
162                 }
163
164                 rc.X = 0;
165                 rc.Y = 0;
166                 rc.Width = 3;
167                 rc.Height = 3;
168                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
169                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
170
171                 rc.X = -1;
172                 rc.Y = 0;
173                 rc.Width = 2;
174                 rc.Height = 3;
175                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
176                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
177
178                 rc.X = 0;
179                 rc.Y = 0;
180                 rc.Width = 2;
181                 rc.Height = 3;
182                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
183                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
184
185                 rc.X = 0;
186                 rc.Y = 0;
187                 rc.Width = 2;
188                 rc.Height = 3;
189                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
190                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
191
192                 rc.X = 0;
193                 rc.Y = 0;
194                 rc.Width = 2;
195                 rc.Height = 3;
196                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
197                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
198                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
199
200                 IWICBitmapFrameDecode_Release(framedecode);
201             }
202
203             /* cannot initialize twice */
204             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
205             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
206
207             /* cannot querycapability after initialize */
208             hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
209             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
210
211             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
212                 &IID_IWICBitmapDecoder, (void**)&decoder2);
213             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
214             if (SUCCEEDED(hr))
215             {
216                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
217                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
218                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
219                     "unexpected capabilities: %x\n", capability);
220
221                 /* cannot initialize after querycapability */
222                 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
223                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
224
225                 /* cannot querycapability twice */
226                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
227                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
228             }
229
230             IStream_Release(bmpstream);
231         }
232
233         GlobalFree(hbmpdata);
234     }
235
236     IWICBitmapDecoder_Release(decoder);
237 }
238
239 static const char testbmp_1bpp[] = {
240     /* BITMAPFILEHEADER */
241     66,77, /* "BM" */
242     40,0,0,0, /* file size */
243     0,0,0,0, /* reserved */
244     32,0,0,0, /* offset to bits */
245     /* BITMAPCOREHEADER */
246     12,0,0,0, /* header size */
247     2,0, /* width */
248     2,0, /* height */
249     1,0, /* planes */
250     1,0, /* bit count */
251     /* color table */
252     255,0,0,
253     0,255,0,
254     /* bits */
255     0xc0,0,0,0,
256     0x80,0,0,0
257 };
258
259 static void test_decode_1bpp(void)
260 {
261     IWICBitmapDecoder *decoder, *decoder2;
262     IWICBitmapFrameDecode *framedecode;
263     HRESULT hr;
264     HGLOBAL hbmpdata;
265     char *bmpdata;
266     IStream *bmpstream;
267     DWORD capability=0;
268     GUID guidresult;
269     UINT count=0, width=0, height=0;
270     double dpiX, dpiY;
271     BYTE imagedata[2] = {1};
272     const BYTE expected_imagedata[2] = {0x80,0xc0};
273     WICColor palettedata[2] = {1};
274     const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
275     WICRect rc;
276
277     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
278         &IID_IWICBitmapDecoder, (void**)&decoder);
279     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
280     if (FAILED(hr)) return;
281
282     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
283     ok(hbmpdata != 0, "GlobalAlloc failed\n");
284     if (hbmpdata)
285     {
286         bmpdata = GlobalLock(hbmpdata);
287         memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
288         GlobalUnlock(hbmpdata);
289
290         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
291         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
292         if (SUCCEEDED(hr))
293         {
294             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
295             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
296
297             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
298             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
299             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
300
301             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
302             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
303             ok(count == 1, "unexpected count %u\n", count);
304
305             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
306             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
307             if (SUCCEEDED(hr))
308             {
309                 IWICImagingFactory *factory;
310                 IWICPalette *palette;
311
312                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
313                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
314                 ok(width == 2, "expected width=2, got %u\n", width);
315                 ok(height == 2, "expected height=2, got %u\n", height);
316
317                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
318                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
319                 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
320                 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
321
322                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
323                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
324                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
325
326                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
327                     &IID_IWICImagingFactory, (void**)&factory);
328                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
329                 if (SUCCEEDED(hr))
330                 {
331                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
332                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
333                     if (SUCCEEDED(hr))
334                     {
335                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
336                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
337
338                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
339                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
340
341                         hr = IWICPalette_GetColorCount(palette, &count);
342                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
343                         ok(count == 2, "expected count=2, got %u\n", count);
344
345                         hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
346                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
347                         ok(count == 2, "expected count=2, got %u\n", count);
348                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
349
350                         IWICPalette_Release(palette);
351                     }
352
353                     IWICImagingFactory_Release(factory);
354                 }
355
356                 rc.X = 0;
357                 rc.Y = 0;
358                 rc.Width = 2;
359                 rc.Height = 2;
360                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
361                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
362                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
363
364                 IWICBitmapFrameDecode_Release(framedecode);
365             }
366
367             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
368                 &IID_IWICBitmapDecoder, (void**)&decoder2);
369             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
370             if (SUCCEEDED(hr))
371             {
372                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
373                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
374                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
375                     "unexpected capabilities: %x\n", capability);
376             }
377
378             IStream_Release(bmpstream);
379         }
380
381         GlobalFree(hbmpdata);
382     }
383
384     IWICBitmapDecoder_Release(decoder);
385 }
386
387 static const char testbmp_4bpp[] = {
388     /* BITMAPFILEHEADER */
389     66,77, /* "BM" */
390     82,0,0,0, /* file size */
391     0,0,0,0, /* reserved */
392     74,0,0,0, /* offset to bits */
393     /* BITMAPINFOHEADER */
394     40,0,0,0, /* header size */
395     2,0,0,0, /* width */
396     254,255,255,255, /* height = -2 */
397     1,0, /* planes */
398     4,0, /* bit count */
399     0,0,0,0, /* compression = BI_RGB */
400     0,0,0,0, /* image size = 0 */
401     16,39,0,0, /* X pixels per meter = 10000 */
402     32,78,0,0, /* Y pixels per meter = 20000 */
403     5,0,0,0, /* colors used */
404     5,0,0,0, /* colors important */
405     /* color table */
406     255,0,0,0,
407     0,255,0,255,
408     0,0,255,23,
409     128,0,128,1,
410     255,255,255,0,
411     /* bits */
412     0x01,0,0,0,
413     0x23,0,0,0,
414 };
415
416 static void test_decode_4bpp(void)
417 {
418     IWICBitmapDecoder *decoder, *decoder2;
419     IWICBitmapFrameDecode *framedecode;
420     HRESULT hr;
421     HGLOBAL hbmpdata;
422     char *bmpdata;
423     IStream *bmpstream;
424     DWORD capability=0;
425     GUID guidresult;
426     UINT count=0, width=0, height=0;
427     double dpiX, dpiY;
428     BYTE imagedata[2] = {1};
429     const BYTE expected_imagedata[2] = {0x01,0x23};
430     WICColor palettedata[5] = {1};
431     const WICColor expected_palettedata[5] =
432         {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
433     WICRect rc;
434
435     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
436         &IID_IWICBitmapDecoder, (void**)&decoder);
437     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
438     if (FAILED(hr)) return;
439
440     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
441     ok(hbmpdata != 0, "GlobalAlloc failed\n");
442     if (hbmpdata)
443     {
444         bmpdata = GlobalLock(hbmpdata);
445         memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
446         GlobalUnlock(hbmpdata);
447
448         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
449         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
450         if (SUCCEEDED(hr))
451         {
452             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
453             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
454
455             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
456             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
457             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
458
459             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
460             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
461             ok(count == 1, "unexpected count %u\n", count);
462
463             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
464             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
465             if (SUCCEEDED(hr))
466             {
467                 IWICImagingFactory *factory;
468                 IWICPalette *palette;
469
470                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
471                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
472                 ok(width == 2, "expected width=2, got %u\n", width);
473                 ok(height == 2, "expected height=2, got %u\n", height);
474
475                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
476                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
477                 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
478                 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
479
480                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
481                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
482                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
483
484                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
485                     &IID_IWICImagingFactory, (void**)&factory);
486                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
487                 if (SUCCEEDED(hr))
488                 {
489                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
490                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
491                     if (SUCCEEDED(hr))
492                     {
493                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
494                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
495
496                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
497                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
498
499                         hr = IWICPalette_GetColorCount(palette, &count);
500                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
501                         ok(count == 5, "expected count=5, got %u\n", count);
502
503                         hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
504                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
505                         ok(count == 5, "expected count=5, got %u\n", count);
506                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
507
508                         IWICPalette_Release(palette);
509                     }
510
511                     IWICImagingFactory_Release(factory);
512                 }
513
514                 rc.X = 0;
515                 rc.Y = 0;
516                 rc.Width = 2;
517                 rc.Height = 2;
518                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
519                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
520                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
521
522                 IWICBitmapFrameDecode_Release(framedecode);
523             }
524
525             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
526                 &IID_IWICBitmapDecoder, (void**)&decoder2);
527             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
528             if (SUCCEEDED(hr))
529             {
530                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
531                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
532                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
533                     "unexpected capabilities: %x\n", capability);
534             }
535
536             IStream_Release(bmpstream);
537         }
538
539         GlobalFree(hbmpdata);
540     }
541
542     IWICBitmapDecoder_Release(decoder);
543 }
544
545 static const char testbmp_rle8[] = {
546     /* BITMAPFILEHEADER */
547     66,77, /* "BM" */
548     202,0,0,0, /* file size */
549     0,0,0,0, /* reserved */
550     122,0,0,0, /* offset to bits */
551     /* BITMAPINFOHEADER */
552     40,0,0,0, /* header size */
553     8,0,0,0, /* width */
554     8,0,0,0, /* height */
555     1,0, /* planes */
556     8,0, /* bit count */
557     1,0,0,0, /* compression = BI_RLE8 */
558     80,0,0,0, /* image size */
559     19,11,0,0, /* X pixels per meter */
560     19,11,0,0, /* Y pixels per meter */
561     17,0,0,0, /* colors used */
562     17,0,0,0, /* colors important */
563     /* color table */
564     0,0,0,0,
565     17,17,17,0,
566     255,0,0,0,
567     34,34,34,0,
568     0,0,204,0,
569     0,0,221,0,
570     0,0,238,0,
571     51,51,51,0,
572     0,0,255,0,
573     68,68,68,0,
574     255,0,255,0,
575     85,85,85,0,
576     0,204,0,0,
577     0,221,0,0,
578     0,238,0,0,
579     0,255,0,0,
580     255,255,255,0,
581     /* bits */
582     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
583 };
584
585 static void test_decode_rle8(void)
586 {
587     IWICBitmapDecoder *decoder, *decoder2;
588     IWICBitmapFrameDecode *framedecode;
589     HRESULT hr;
590     HGLOBAL hbmpdata;
591     char *bmpdata;
592     IStream *bmpstream;
593     DWORD capability=0;
594     GUID guidresult;
595     UINT count=0, width=0, height=0;
596     double dpiX, dpiY;
597     DWORD imagedata[64] = {1};
598     const DWORD expected_imagedata[64] = {
599         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
600         0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
601         0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
602         0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
603         0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
604         0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
605         0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
606         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
607     WICColor palettedata[17] = {1};
608     const WICColor expected_palettedata[17] = {
609         0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
610         0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
611         0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
612     WICRect rc;
613
614     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
615         &IID_IWICBitmapDecoder, (void**)&decoder);
616     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
617     if (FAILED(hr)) return;
618
619     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
620     ok(hbmpdata != 0, "GlobalAlloc failed\n");
621     if (hbmpdata)
622     {
623         bmpdata = GlobalLock(hbmpdata);
624         memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
625         GlobalUnlock(hbmpdata);
626
627         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
628         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
629         if (SUCCEEDED(hr))
630         {
631             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
632             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
633
634             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
635             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
636             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
637
638             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
639             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
640             ok(count == 1, "unexpected count %u\n", count);
641
642             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
643             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
644             if (SUCCEEDED(hr))
645             {
646                 IWICImagingFactory *factory;
647                 IWICPalette *palette;
648
649                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
650                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
651                 ok(width == 8, "expected width=8, got %u\n", width);
652                 ok(height == 8, "expected height=8, got %u\n", height);
653
654                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
655                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
656                 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
657                 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
658
659                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
660                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
661                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
662
663                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
664                     &IID_IWICImagingFactory, (void**)&factory);
665                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
666                 if (SUCCEEDED(hr))
667                 {
668                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
669                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
670                     if (SUCCEEDED(hr))
671                     {
672                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
673                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
674
675                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
676                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
677
678                         hr = IWICPalette_GetColorCount(palette, &count);
679                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
680                         ok(count == 17, "expected count=17, got %u\n", count);
681
682                         hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
683                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
684                         ok(count == 17, "expected count=17, got %u\n", count);
685                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
686
687                         IWICPalette_Release(palette);
688                     }
689
690                     IWICImagingFactory_Release(factory);
691                 }
692
693                 rc.X = 0;
694                 rc.Y = 0;
695                 rc.Width = 8;
696                 rc.Height = 8;
697                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
698                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
699                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
700
701                 IWICBitmapFrameDecode_Release(framedecode);
702             }
703
704             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
705                 &IID_IWICBitmapDecoder, (void**)&decoder2);
706             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
707             if (SUCCEEDED(hr))
708             {
709                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
710                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
711                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
712                     "unexpected capabilities: %x\n", capability);
713             }
714
715             IStream_Release(bmpstream);
716         }
717
718         GlobalFree(hbmpdata);
719     }
720
721     IWICBitmapDecoder_Release(decoder);
722 }
723
724 static const char testbmp_rle4[] = {
725     /* BITMAPFILEHEADER */
726     66,77, /* "BM" */
727     142,0,0,0, /* file size */
728     0,0,0,0, /* reserved */
729     78,0,0,0, /* offset to bits */
730     /* BITMAPINFOHEADER */
731     40,0,0,0, /* header size */
732     8,0,0,0, /* width */
733     8,0,0,0, /* height */
734     1,0, /* planes */
735     4,0, /* bit count */
736     2,0,0,0, /* compression = BI_RLE4 */
737     64,0,0,0, /* image size */
738     19,11,0,0, /* X pixels per meter */
739     19,11,0,0, /* Y pixels per meter */
740     6,0,0,0, /* colors used */
741     6,0,0,0, /* colors important */
742     /* color table */
743     0,0,0,0,
744     255,0,0,0,
745     0,0,255,0,
746     255,0,255,0,
747     0,255,0,0,
748     255,255,255,0,
749     /* bits */
750     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
751 };
752
753 static void test_decode_rle4(void)
754 {
755     IWICBitmapDecoder *decoder, *decoder2;
756     IWICBitmapFrameDecode *framedecode;
757     HRESULT hr;
758     HGLOBAL hbmpdata;
759     char *bmpdata;
760     IStream *bmpstream;
761     DWORD capability=0;
762     GUID guidresult;
763     UINT count=0, width=0, height=0;
764     double dpiX, dpiY;
765     DWORD imagedata[64] = {1};
766     const DWORD expected_imagedata[64] = {
767         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
768         0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
769         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
770         0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
771         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
772         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
773         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
774         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
775     WICColor palettedata[6] = {1};
776     const WICColor expected_palettedata[6] = {
777         0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
778     WICRect rc;
779
780     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
781         &IID_IWICBitmapDecoder, (void**)&decoder);
782     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
783     if (FAILED(hr)) return;
784
785     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
786     ok(hbmpdata != 0, "GlobalAlloc failed\n");
787     if (hbmpdata)
788     {
789         bmpdata = GlobalLock(hbmpdata);
790         memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
791         GlobalUnlock(hbmpdata);
792
793         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
794         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
795         if (SUCCEEDED(hr))
796         {
797             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
798             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
799
800             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
801             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
802             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
803
804             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
805             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
806             ok(count == 1, "unexpected count %u\n", count);
807
808             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
809             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
810             if (SUCCEEDED(hr))
811             {
812                 IWICImagingFactory *factory;
813                 IWICPalette *palette;
814
815                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
816                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
817                 ok(width == 8, "expected width=8, got %u\n", width);
818                 ok(height == 8, "expected height=8, got %u\n", height);
819
820                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
821                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
822                 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
823                 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
824
825                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
826                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
827                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
828
829                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
830                     &IID_IWICImagingFactory, (void**)&factory);
831                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
832                 if (SUCCEEDED(hr))
833                 {
834                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
835                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
836                     if (SUCCEEDED(hr))
837                     {
838                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
839                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
840
841                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
842                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
843
844                         hr = IWICPalette_GetColorCount(palette, &count);
845                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
846                         ok(count == 6, "expected count=6, got %u\n", count);
847
848                         hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
849                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
850                         ok(count == 6, "expected count=6, got %u\n", count);
851                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
852
853                         IWICPalette_Release(palette);
854                     }
855
856                     IWICImagingFactory_Release(factory);
857                 }
858
859                 rc.X = 0;
860                 rc.Y = 0;
861                 rc.Width = 8;
862                 rc.Height = 8;
863                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
864                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
865                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
866
867                 IWICBitmapFrameDecode_Release(framedecode);
868             }
869
870             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
871                 &IID_IWICBitmapDecoder, (void**)&decoder2);
872             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
873             if (SUCCEEDED(hr))
874             {
875                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
876                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
877                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
878                     "unexpected capabilities: %x\n", capability);
879             }
880
881             IStream_Release(bmpstream);
882         }
883
884         GlobalFree(hbmpdata);
885     }
886
887     IWICBitmapDecoder_Release(decoder);
888 }
889
890 static void test_componentinfo(void)
891 {
892     IWICImagingFactory *factory;
893     IWICComponentInfo *info;
894     IWICBitmapDecoderInfo *decoderinfo;
895     IWICBitmapDecoder *decoder;
896     HRESULT hr;
897     WICBitmapPattern *patterns;
898     UINT pattern_count, pattern_size;
899     WICComponentType type;
900     GUID guidresult;
901     HGLOBAL hbmpdata;
902     char *bmpdata;
903     IStream *bmpstream;
904     BOOL boolresult;
905
906     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
907         &IID_IWICImagingFactory, (void**)&factory);
908     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
909     if (SUCCEEDED(hr))
910     {
911         hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
912         ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%x\n", hr);
913         if (SUCCEEDED(hr))
914         {
915             hr = IWICComponentInfo_GetComponentType(info, &type);
916             ok(SUCCEEDED(hr), "GetComponentType failed, hr=%x\n", hr);
917             ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
918
919             hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
920             ok(SUCCEEDED(hr), "QueryInterface failed, hr=%x\n", hr);
921             if (SUCCEEDED(hr))
922             {
923                 pattern_count = 0;
924                 pattern_size = 0;
925                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
926                 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
927                 ok(pattern_count != 0, "pattern count is 0\n");
928                 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
929
930                 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
931                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
932                 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
933                 ok(pattern_count != 0, "pattern count is 0\n");
934                 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
935                 ok(patterns[0].Length != 0, "pattern length is 0\n");
936                 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
937                 ok(patterns[0].Mask != NULL, "mask is NULL\n");
938
939                 pattern_size -= 1;
940                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
941                 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %x, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
942
943                 HeapFree(GetProcessHeap(), 0, patterns);
944
945                 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
946                 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%x\n", hr);
947                 if (SUCCEEDED(hr))
948                 {
949                     hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
950                     ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
951                     ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
952
953                     IWICBitmapDecoder_Release(decoder);
954                 }
955
956                 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
957                 ok(hbmpdata != 0, "GlobalAlloc failed\n");
958                 if (hbmpdata)
959                 {
960                     bmpdata = GlobalLock(hbmpdata);
961                     memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
962                     GlobalUnlock(hbmpdata);
963
964                     hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
965                     ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
966                     if (SUCCEEDED(hr))
967                     {
968                         boolresult = 0;
969                         hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
970                         ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%x\n", hr);
971                         ok(boolresult, "pattern not matched\n");
972
973                         IStream_Release(bmpstream);
974                     }
975
976                     GlobalFree(hbmpdata);
977                 }
978
979                 IWICBitmapDecoderInfo_Release(decoderinfo);
980             }
981
982             IWICComponentInfo_Release(info);
983         }
984
985         IWICImagingFactory_Release(factory);
986     }
987 }
988
989 static void test_createfromstream(void)
990 {
991     IWICBitmapDecoder *decoder;
992     IWICImagingFactory *factory;
993     HRESULT hr;
994     HGLOBAL hbmpdata;
995     char *bmpdata;
996     IStream *bmpstream;
997     GUID guidresult;
998
999     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1000         &IID_IWICImagingFactory, (void**)&factory);
1001     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
1002     if (FAILED(hr)) return;
1003
1004     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1005     ok(hbmpdata != 0, "GlobalAlloc failed\n");
1006     if (hbmpdata)
1007     {
1008         bmpdata = GlobalLock(hbmpdata);
1009         memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1010         GlobalUnlock(hbmpdata);
1011
1012         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1013         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
1014         if (SUCCEEDED(hr))
1015         {
1016             hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1017                 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1018             ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%x\n", hr);
1019             if (SUCCEEDED(hr))
1020             {
1021                 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1022                 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
1023                 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1024
1025                 IWICBitmapDecoder_Release(decoder);
1026             }
1027
1028             IStream_Release(bmpstream);
1029         }
1030
1031         GlobalFree(hbmpdata);
1032     }
1033
1034     IWICImagingFactory_Release(factory);
1035 }
1036
1037 START_TEST(bmpformat)
1038 {
1039     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1040
1041     test_decode_24bpp();
1042     test_decode_1bpp();
1043     test_decode_4bpp();
1044     test_decode_rle8();
1045     test_decode_rle4();
1046     test_componentinfo();
1047     test_createfromstream();
1048
1049     CoUninitialize();
1050 }