windowscodecs: Add test for 4-bit indexed color BMP.
[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     HRESULT hr;
53     HGLOBAL hbmpdata;
54     char *bmpdata;
55     IStream *bmpstream;
56     DWORD capability=0;
57     GUID guidresult;
58     UINT count=0, width=0, height=0;
59     double dpiX, dpiY;
60     BYTE imagedata[36] = {1};
61     const BYTE expected_imagedata[36] = {
62         255,0,255, 255,255,255,
63         255,0,0,   255,255,0,
64         0,0,0,     0,255,0};
65     WICRect rc;
66
67     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
68         &IID_IWICBitmapDecoder, (void**)&decoder);
69     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
70     if (!SUCCEEDED(hr)) return;
71
72     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
73     ok(hbmpdata != 0, "GlobalAlloc failed\n");
74     if (hbmpdata)
75     {
76         bmpdata = GlobalLock(hbmpdata);
77         memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
78         GlobalUnlock(hbmpdata);
79
80         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
81         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
82         if (SUCCEEDED(hr))
83         {
84             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
85             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
86
87             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
88             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
89             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
90
91             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
92             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
93             ok(count == 1, "unexpected count %u\n", count);
94
95             hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
96             ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
97
98             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
99             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
100             if (SUCCEEDED(hr))
101             {
102                 IWICImagingFactory *factory;
103                 IWICPalette *palette;
104
105                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
106                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
107                 ok(width == 2, "expected width=2, got %u\n", width);
108                 ok(height == 3, "expected height=2, got %u\n", height);
109
110                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
111                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
112                 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
113                 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
114
115                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
116                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
117                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
118
119                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
120                     &IID_IWICImagingFactory, (void**)&factory);
121                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
122                 if (SUCCEEDED(hr))
123                 {
124                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
125                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
126                     if (SUCCEEDED(hr))
127                     {
128                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
129                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
130
131                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
132                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
133
134                         IWICPalette_Release(palette);
135                     }
136
137                     IWICImagingFactory_Release(factory);
138                 }
139
140                 rc.X = 0;
141                 rc.Y = 0;
142                 rc.Width = 3;
143                 rc.Height = 3;
144                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
145                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
146
147                 rc.X = -1;
148                 rc.Y = 0;
149                 rc.Width = 2;
150                 rc.Height = 3;
151                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
152                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
153
154                 rc.X = 0;
155                 rc.Y = 0;
156                 rc.Width = 2;
157                 rc.Height = 3;
158                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
159                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
160
161                 rc.X = 0;
162                 rc.Y = 0;
163                 rc.Width = 2;
164                 rc.Height = 3;
165                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
166                 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
167
168                 rc.X = 0;
169                 rc.Y = 0;
170                 rc.Width = 2;
171                 rc.Height = 3;
172                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
173                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
174                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
175
176                 IWICBitmapFrameDecode_Release(framedecode);
177             }
178
179             /* cannot initialize twice */
180             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
181             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
182
183             /* cannot querycapability after initialize */
184             hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
185             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
186
187             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
188                 &IID_IWICBitmapDecoder, (void**)&decoder2);
189             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
190             if (SUCCEEDED(hr))
191             {
192                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
193                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
194                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
195                     "unexpected capabilities: %x\n", capability);
196
197                 /* cannot initialize after querycapability */
198                 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
199                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
200
201                 /* cannot querycapability twice */
202                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
203                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
204             }
205
206             IStream_Release(bmpstream);
207         }
208
209         GlobalFree(hbmpdata);
210     }
211
212     IWICBitmapDecoder_Release(decoder);
213 }
214
215 static const char testbmp_1bpp[] = {
216     /* BITMAPFILEHEADER */
217     66,77, /* "BM" */
218     40,0,0,0, /* file size */
219     0,0,0,0, /* reserved */
220     32,0,0,0, /* offset to bits */
221     /* BITMAPCOREHEADER */
222     12,0,0,0, /* header size */
223     2,0, /* width */
224     2,0, /* height */
225     1,0, /* planes */
226     1,0, /* bit count */
227     /* color table */
228     255,0,0,
229     0,255,0,
230     /* bits */
231     0xc0,0,0,0,
232     0x80,0,0,0
233 };
234
235 static void test_decode_1bpp(void)
236 {
237     IWICBitmapDecoder *decoder, *decoder2;
238     IWICBitmapFrameDecode *framedecode;
239     HRESULT hr;
240     HGLOBAL hbmpdata;
241     char *bmpdata;
242     IStream *bmpstream;
243     DWORD capability=0;
244     GUID guidresult;
245     UINT count=0, width=0, height=0;
246     double dpiX, dpiY;
247     BYTE imagedata[2] = {1};
248     const BYTE expected_imagedata[2] = {0x80,0xc0};
249     WICColor palettedata[2] = {1};
250     const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
251     WICRect rc;
252
253     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
254         &IID_IWICBitmapDecoder, (void**)&decoder);
255     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
256     if (!SUCCEEDED(hr)) return;
257
258     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
259     ok(hbmpdata != 0, "GlobalAlloc failed\n");
260     if (hbmpdata)
261     {
262         bmpdata = GlobalLock(hbmpdata);
263         memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
264         GlobalUnlock(hbmpdata);
265
266         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
267         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
268         if (SUCCEEDED(hr))
269         {
270             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
271             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
272
273             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
274             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
275             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
276
277             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
278             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
279             ok(count == 1, "unexpected count %u\n", count);
280
281             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
282             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
283             if (SUCCEEDED(hr))
284             {
285                 IWICImagingFactory *factory;
286                 IWICPalette *palette;
287
288                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
289                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
290                 ok(width == 2, "expected width=2, got %u\n", width);
291                 ok(height == 2, "expected height=2, got %u\n", height);
292
293                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
294                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
295                 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
296                 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
297
298                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
299                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
300                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
301
302                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
303                     &IID_IWICImagingFactory, (void**)&factory);
304                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
305                 if (SUCCEEDED(hr))
306                 {
307                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
308                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
309                     if (SUCCEEDED(hr))
310                     {
311                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
312                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
313
314                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
315                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
316
317                         hr = IWICPalette_GetColorCount(palette, &count);
318                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
319                         ok(count == 2, "expected count=2, got %u\n", count);
320
321                         hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
322                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
323                         ok(count == 2, "expected count=2, got %u\n", count);
324                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
325
326                         IWICPalette_Release(palette);
327                     }
328
329                     IWICImagingFactory_Release(factory);
330                 }
331
332                 rc.X = 0;
333                 rc.Y = 0;
334                 rc.Width = 2;
335                 rc.Height = 2;
336                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
337                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
338                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
339
340                 IWICBitmapFrameDecode_Release(framedecode);
341             }
342
343             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
344                 &IID_IWICBitmapDecoder, (void**)&decoder2);
345             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
346             if (SUCCEEDED(hr))
347             {
348                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
349                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
350                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
351                     "unexpected capabilities: %x\n", capability);
352             }
353
354             IStream_Release(bmpstream);
355         }
356
357         GlobalFree(hbmpdata);
358     }
359
360     IWICBitmapDecoder_Release(decoder);
361 }
362
363 static const char testbmp_4bpp[] = {
364     /* BITMAPFILEHEADER */
365     66,77, /* "BM" */
366     82,0,0,0, /* file size */
367     0,0,0,0, /* reserved */
368     74,0,0,0, /* offset to bits */
369     /* BITMAPINFOHEADER */
370     40,0,0,0, /* header size */
371     2,0,0,0, /* width */
372     254,255,255,255, /* height = -2 */
373     1,0, /* planes */
374     4,0, /* bit count */
375     0,0,0,0, /* compression = BI_RGB */
376     0,0,0,0, /* image size = 0 */
377     16,39,0,0, /* X pixels per meter = 10000 */
378     32,78,0,0, /* Y pixels per meter = 20000 */
379     5,0,0,0, /* colors used */
380     5,0,0,0, /* colors important */
381     /* color table */
382     255,0,0,0,
383     0,255,0,255,
384     0,0,255,23,
385     128,0,128,1,
386     255,255,255,0,
387     /* bits */
388     0x01,0,0,0,
389     0x23,0,0,0,
390 };
391
392 static void test_decode_4bpp(void)
393 {
394     IWICBitmapDecoder *decoder, *decoder2;
395     IWICBitmapFrameDecode *framedecode;
396     HRESULT hr;
397     HGLOBAL hbmpdata;
398     char *bmpdata;
399     IStream *bmpstream;
400     DWORD capability=0;
401     GUID guidresult;
402     UINT count=0, width=0, height=0;
403     double dpiX, dpiY;
404     BYTE imagedata[2] = {1};
405     const BYTE expected_imagedata[2] = {0x01,0x23};
406     WICColor palettedata[5] = {1};
407     const WICColor expected_palettedata[5] =
408         {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
409     WICRect rc;
410
411     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
412         &IID_IWICBitmapDecoder, (void**)&decoder);
413     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
414     if (!SUCCEEDED(hr)) return;
415
416     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
417     ok(hbmpdata != 0, "GlobalAlloc failed\n");
418     if (hbmpdata)
419     {
420         bmpdata = GlobalLock(hbmpdata);
421         memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
422         GlobalUnlock(hbmpdata);
423
424         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
425         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
426         if (SUCCEEDED(hr))
427         {
428             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
429             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
430
431             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
432             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
433             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
434
435             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
436             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
437             ok(count == 1, "unexpected count %u\n", count);
438
439             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
440             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
441             if (SUCCEEDED(hr))
442             {
443                 IWICImagingFactory *factory;
444                 IWICPalette *palette;
445
446                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
447                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
448                 ok(width == 2, "expected width=2, got %u\n", width);
449                 ok(height == 2, "expected height=2, got %u\n", height);
450
451                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
452                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
453                 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
454                 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
455
456                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
457                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
458                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
459
460                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
461                     &IID_IWICImagingFactory, (void**)&factory);
462                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
463                 if (SUCCEEDED(hr))
464                 {
465                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
466                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
467                     if (SUCCEEDED(hr))
468                     {
469                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
470                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
471
472                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
473                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
474
475                         hr = IWICPalette_GetColorCount(palette, &count);
476                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
477                         ok(count == 5, "expected count=5, got %u\n", count);
478
479                         hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
480                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
481                         ok(count == 5, "expected count=5, got %u\n", count);
482                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
483
484                         IWICPalette_Release(palette);
485                     }
486
487                     IWICImagingFactory_Release(factory);
488                 }
489
490                 rc.X = 0;
491                 rc.Y = 0;
492                 rc.Width = 2;
493                 rc.Height = 2;
494                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
495                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
496                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
497
498                 IWICBitmapFrameDecode_Release(framedecode);
499             }
500
501             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
502                 &IID_IWICBitmapDecoder, (void**)&decoder2);
503             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
504             if (SUCCEEDED(hr))
505             {
506                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
507                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
508                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
509                     "unexpected capabilities: %x\n", capability);
510             }
511
512             IStream_Release(bmpstream);
513         }
514
515         GlobalFree(hbmpdata);
516     }
517
518     IWICBitmapDecoder_Release(decoder);
519 }
520
521 START_TEST(bmpformat)
522 {
523     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
524
525     test_decode_24bpp();
526     test_decode_1bpp();
527     test_decode_4bpp();
528
529     CoUninitialize();
530 }