~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/windowscodecs/tests/bmpformat.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, NULL, 6, sizeof(imagedata), imagedata);
201                 ok(SUCCEEDED(hr), "CopyPixels(rect=NULL) failed, hr=%x\n", hr);
202                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
203 
204                 IWICBitmapFrameDecode_Release(framedecode);
205             }
206 
207             /* cannot initialize twice */
208             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
209             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
210 
211             /* cannot querycapability after initialize */
212             hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
213             ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
214 
215             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
216                 &IID_IWICBitmapDecoder, (void**)&decoder2);
217             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
218             if (SUCCEEDED(hr))
219             {
220                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
221                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
222                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
223                     "unexpected capabilities: %x\n", capability);
224 
225                 /* cannot initialize after querycapability */
226                 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
227                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
228 
229                 /* cannot querycapability twice */
230                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
231                 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
232 
233                 IWICBitmapDecoder_Release(decoder2);
234             }
235 
236             IStream_Release(bmpstream);
237         }
238 
239         GlobalFree(hbmpdata);
240     }
241 
242     IWICBitmapDecoder_Release(decoder);
243 }
244 
245 static const char testbmp_1bpp[] = {
246     /* BITMAPFILEHEADER */
247     66,77, /* "BM" */
248     40,0,0,0, /* file size */
249     0,0,0,0, /* reserved */
250     32,0,0,0, /* offset to bits */
251     /* BITMAPCOREHEADER */
252     12,0,0,0, /* header size */
253     2,0, /* width */
254     2,0, /* height */
255     1,0, /* planes */
256     1,0, /* bit count */
257     /* color table */
258     255,0,0,
259     0,255,0,
260     /* bits */
261     0xc0,0,0,0,
262     0x80,0,0,0
263 };
264 
265 static void test_decode_1bpp(void)
266 {
267     IWICBitmapDecoder *decoder, *decoder2;
268     IWICBitmapFrameDecode *framedecode;
269     HRESULT hr;
270     HGLOBAL hbmpdata;
271     char *bmpdata;
272     IStream *bmpstream;
273     DWORD capability=0;
274     GUID guidresult;
275     UINT count=0, width=0, height=0;
276     double dpiX, dpiY;
277     BYTE imagedata[2] = {1};
278     const BYTE expected_imagedata[2] = {0x80,0xc0};
279     WICColor palettedata[2] = {1};
280     const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
281     WICRect rc;
282 
283     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
284         &IID_IWICBitmapDecoder, (void**)&decoder);
285     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
286     if (FAILED(hr)) return;
287 
288     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
289     ok(hbmpdata != 0, "GlobalAlloc failed\n");
290     if (hbmpdata)
291     {
292         bmpdata = GlobalLock(hbmpdata);
293         memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
294         GlobalUnlock(hbmpdata);
295 
296         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
297         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
298         if (SUCCEEDED(hr))
299         {
300             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
301             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
302 
303             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
304             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
305             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
306 
307             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
308             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
309             ok(count == 1, "unexpected count %u\n", count);
310 
311             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
312             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
313             if (SUCCEEDED(hr))
314             {
315                 IWICImagingFactory *factory;
316                 IWICPalette *palette;
317 
318                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
319                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
320                 ok(width == 2, "expected width=2, got %u\n", width);
321                 ok(height == 2, "expected height=2, got %u\n", height);
322 
323                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
324                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
325                 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
326                 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
327 
328                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
329                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
330                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
331 
332                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
333                     &IID_IWICImagingFactory, (void**)&factory);
334                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
335                 if (SUCCEEDED(hr))
336                 {
337                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
338                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
339                     if (SUCCEEDED(hr))
340                     {
341                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
342                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
343 
344                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
345                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
346 
347                         hr = IWICPalette_GetColorCount(palette, &count);
348                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
349                         ok(count == 2, "expected count=2, got %u\n", count);
350 
351                         hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
352                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
353                         ok(count == 2, "expected count=2, got %u\n", count);
354                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
355 
356                         IWICPalette_Release(palette);
357                     }
358 
359                     IWICImagingFactory_Release(factory);
360                 }
361 
362                 rc.X = 0;
363                 rc.Y = 0;
364                 rc.Width = 2;
365                 rc.Height = 2;
366                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
367                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
368                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
369 
370                 IWICBitmapFrameDecode_Release(framedecode);
371             }
372 
373             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
374                 &IID_IWICBitmapDecoder, (void**)&decoder2);
375             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
376             if (SUCCEEDED(hr))
377             {
378                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
379                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
380                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
381                     "unexpected capabilities: %x\n", capability);
382                 IWICBitmapDecoder_Release(decoder2);
383             }
384 
385             IStream_Release(bmpstream);
386         }
387 
388         GlobalFree(hbmpdata);
389     }
390 
391     IWICBitmapDecoder_Release(decoder);
392 }
393 
394 static const char testbmp_4bpp[] = {
395     /* BITMAPFILEHEADER */
396     66,77, /* "BM" */
397     82,0,0,0, /* file size */
398     0,0,0,0, /* reserved */
399     74,0,0,0, /* offset to bits */
400     /* BITMAPINFOHEADER */
401     40,0,0,0, /* header size */
402     2,0,0,0, /* width */
403     254,255,255,255, /* height = -2 */
404     1,0, /* planes */
405     4,0, /* bit count */
406     0,0,0,0, /* compression = BI_RGB */
407     0,0,0,0, /* image size = 0 */
408     16,39,0,0, /* X pixels per meter = 10000 */
409     32,78,0,0, /* Y pixels per meter = 20000 */
410     5,0,0,0, /* colors used */
411     5,0,0,0, /* colors important */
412     /* color table */
413     255,0,0,0,
414     0,255,0,255,
415     0,0,255,23,
416     128,0,128,1,
417     255,255,255,0,
418     /* bits */
419     0x01,0,0,0,
420     0x23,0,0,0,
421 };
422 
423 static void test_decode_4bpp(void)
424 {
425     IWICBitmapDecoder *decoder, *decoder2;
426     IWICBitmapFrameDecode *framedecode;
427     HRESULT hr;
428     HGLOBAL hbmpdata;
429     char *bmpdata;
430     IStream *bmpstream;
431     DWORD capability=0;
432     GUID guidresult;
433     UINT count=0, width=0, height=0;
434     double dpiX, dpiY;
435     BYTE imagedata[2] = {1};
436     const BYTE expected_imagedata[2] = {0x01,0x23};
437     WICColor palettedata[5] = {1};
438     const WICColor expected_palettedata[5] =
439         {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
440     WICRect rc;
441 
442     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
443         &IID_IWICBitmapDecoder, (void**)&decoder);
444     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
445     if (FAILED(hr)) return;
446 
447     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
448     ok(hbmpdata != 0, "GlobalAlloc failed\n");
449     if (hbmpdata)
450     {
451         bmpdata = GlobalLock(hbmpdata);
452         memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
453         GlobalUnlock(hbmpdata);
454 
455         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
456         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
457         if (SUCCEEDED(hr))
458         {
459             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
460             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
461 
462             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
463             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
464             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
465 
466             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
467             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
468             ok(count == 1, "unexpected count %u\n", count);
469 
470             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
471             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
472             if (SUCCEEDED(hr))
473             {
474                 IWICImagingFactory *factory;
475                 IWICPalette *palette;
476 
477                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
478                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
479                 ok(width == 2, "expected width=2, got %u\n", width);
480                 ok(height == 2, "expected height=2, got %u\n", height);
481 
482                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
483                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
484                 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
485                 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
486 
487                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
488                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
489                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
490 
491                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
492                     &IID_IWICImagingFactory, (void**)&factory);
493                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
494                 if (SUCCEEDED(hr))
495                 {
496                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
497                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
498                     if (SUCCEEDED(hr))
499                     {
500                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
501                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
502 
503                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
504                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
505 
506                         hr = IWICPalette_GetColorCount(palette, &count);
507                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
508                         ok(count == 5, "expected count=5, got %u\n", count);
509 
510                         hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
511                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
512                         ok(count == 5, "expected count=5, got %u\n", count);
513                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
514 
515                         IWICPalette_Release(palette);
516                     }
517 
518                     IWICImagingFactory_Release(factory);
519                 }
520 
521                 rc.X = 0;
522                 rc.Y = 0;
523                 rc.Width = 2;
524                 rc.Height = 2;
525                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
526                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
527                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
528 
529                 IWICBitmapFrameDecode_Release(framedecode);
530             }
531 
532             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
533                 &IID_IWICBitmapDecoder, (void**)&decoder2);
534             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
535             if (SUCCEEDED(hr))
536             {
537                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
538                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
539                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
540                     "unexpected capabilities: %x\n", capability);
541                 IWICBitmapDecoder_Release(decoder2);
542             }
543 
544             IStream_Release(bmpstream);
545         }
546 
547         GlobalFree(hbmpdata);
548     }
549 
550     IWICBitmapDecoder_Release(decoder);
551 }
552 
553 static const char testbmp_rle8[] = {
554     /* BITMAPFILEHEADER */
555     66,77, /* "BM" */
556     202,0,0,0, /* file size */
557     0,0,0,0, /* reserved */
558     122,0,0,0, /* offset to bits */
559     /* BITMAPINFOHEADER */
560     40,0,0,0, /* header size */
561     8,0,0,0, /* width */
562     8,0,0,0, /* height */
563     1,0, /* planes */
564     8,0, /* bit count */
565     1,0,0,0, /* compression = BI_RLE8 */
566     80,0,0,0, /* image size */
567     19,11,0,0, /* X pixels per meter */
568     19,11,0,0, /* Y pixels per meter */
569     17,0,0,0, /* colors used */
570     17,0,0,0, /* colors important */
571     /* color table */
572     0,0,0,0,
573     17,17,17,0,
574     255,0,0,0,
575     34,34,34,0,
576     0,0,204,0,
577     0,0,221,0,
578     0,0,238,0,
579     51,51,51,0,
580     0,0,255,0,
581     68,68,68,0,
582     255,0,255,0,
583     85,85,85,0,
584     0,204,0,0,
585     0,221,0,0,
586     0,238,0,0,
587     0,255,0,0,
588     255,255,255,0,
589     /* bits */
590     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
591 };
592 
593 static void test_decode_rle8(void)
594 {
595     IWICBitmapDecoder *decoder, *decoder2;
596     IWICBitmapFrameDecode *framedecode;
597     HRESULT hr;
598     HGLOBAL hbmpdata;
599     char *bmpdata;
600     IStream *bmpstream;
601     DWORD capability=0;
602     GUID guidresult;
603     UINT count=0, width=0, height=0;
604     double dpiX, dpiY;
605     DWORD imagedata[64] = {1};
606     const DWORD expected_imagedata[64] = {
607         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
608         0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
609         0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
610         0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
611         0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
612         0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
613         0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
614         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
615     WICColor palettedata[17] = {1};
616     const WICColor expected_palettedata[17] = {
617         0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
618         0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
619         0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
620     WICRect rc;
621 
622     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
623         &IID_IWICBitmapDecoder, (void**)&decoder);
624     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
625     if (FAILED(hr)) return;
626 
627     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
628     ok(hbmpdata != 0, "GlobalAlloc failed\n");
629     if (hbmpdata)
630     {
631         bmpdata = GlobalLock(hbmpdata);
632         memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
633         GlobalUnlock(hbmpdata);
634 
635         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
636         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
637         if (SUCCEEDED(hr))
638         {
639             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
640             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
641 
642             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
643             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
644             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
645 
646             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
647             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
648             ok(count == 1, "unexpected count %u\n", count);
649 
650             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
651             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
652             if (SUCCEEDED(hr))
653             {
654                 IWICImagingFactory *factory;
655                 IWICPalette *palette;
656 
657                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
658                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
659                 ok(width == 8, "expected width=8, got %u\n", width);
660                 ok(height == 8, "expected height=8, got %u\n", height);
661 
662                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
663                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
664                 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
665                 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
666 
667                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
668                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
669                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
670 
671                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
672                     &IID_IWICImagingFactory, (void**)&factory);
673                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
674                 if (SUCCEEDED(hr))
675                 {
676                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
677                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
678                     if (SUCCEEDED(hr))
679                     {
680                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
681                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
682 
683                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
684                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
685 
686                         hr = IWICPalette_GetColorCount(palette, &count);
687                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
688                         ok(count == 17, "expected count=17, got %u\n", count);
689 
690                         hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
691                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
692                         ok(count == 17, "expected count=17, got %u\n", count);
693                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
694 
695                         IWICPalette_Release(palette);
696                     }
697 
698                     IWICImagingFactory_Release(factory);
699                 }
700 
701                 rc.X = 0;
702                 rc.Y = 0;
703                 rc.Width = 8;
704                 rc.Height = 8;
705                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
706                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
707                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
708 
709                 IWICBitmapFrameDecode_Release(framedecode);
710             }
711 
712             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
713                 &IID_IWICBitmapDecoder, (void**)&decoder2);
714             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
715             if (SUCCEEDED(hr))
716             {
717                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
718                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
719                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
720                     "unexpected capabilities: %x\n", capability);
721                 IWICBitmapDecoder_Release(decoder2);
722             }
723 
724             IStream_Release(bmpstream);
725         }
726 
727         GlobalFree(hbmpdata);
728     }
729 
730     IWICBitmapDecoder_Release(decoder);
731 }
732 
733 static const char testbmp_rle4[] = {
734     /* BITMAPFILEHEADER */
735     66,77, /* "BM" */
736     142,0,0,0, /* file size */
737     0,0,0,0, /* reserved */
738     78,0,0,0, /* offset to bits */
739     /* BITMAPINFOHEADER */
740     40,0,0,0, /* header size */
741     8,0,0,0, /* width */
742     8,0,0,0, /* height */
743     1,0, /* planes */
744     4,0, /* bit count */
745     2,0,0,0, /* compression = BI_RLE4 */
746     64,0,0,0, /* image size */
747     19,11,0,0, /* X pixels per meter */
748     19,11,0,0, /* Y pixels per meter */
749     6,0,0,0, /* colors used */
750     6,0,0,0, /* colors important */
751     /* color table */
752     0,0,0,0,
753     255,0,0,0,
754     0,0,255,0,
755     255,0,255,0,
756     0,255,0,0,
757     255,255,255,0,
758     /* bits */
759     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
760 };
761 
762 static void test_decode_rle4(void)
763 {
764     IWICBitmapDecoder *decoder, *decoder2;
765     IWICBitmapFrameDecode *framedecode;
766     HRESULT hr;
767     HGLOBAL hbmpdata;
768     char *bmpdata;
769     IStream *bmpstream;
770     DWORD capability=0;
771     GUID guidresult;
772     UINT count=0, width=0, height=0;
773     double dpiX, dpiY;
774     DWORD imagedata[64] = {1};
775     const DWORD expected_imagedata[64] = {
776         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
777         0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
778         0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
779         0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
780         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
781         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
782         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
783         0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
784     WICColor palettedata[6] = {1};
785     const WICColor expected_palettedata[6] = {
786         0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
787     WICRect rc;
788 
789     hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
790         &IID_IWICBitmapDecoder, (void**)&decoder);
791     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
792     if (FAILED(hr)) return;
793 
794     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
795     ok(hbmpdata != 0, "GlobalAlloc failed\n");
796     if (hbmpdata)
797     {
798         bmpdata = GlobalLock(hbmpdata);
799         memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
800         GlobalUnlock(hbmpdata);
801 
802         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
803         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
804         if (SUCCEEDED(hr))
805         {
806             hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
807             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
808 
809             hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
810             ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
811             ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
812 
813             hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
814             ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
815             ok(count == 1, "unexpected count %u\n", count);
816 
817             hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
818             ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
819             if (SUCCEEDED(hr))
820             {
821                 IWICImagingFactory *factory;
822                 IWICPalette *palette;
823 
824                 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
825                 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
826                 ok(width == 8, "expected width=8, got %u\n", width);
827                 ok(height == 8, "expected height=8, got %u\n", height);
828 
829                 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
830                 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
831                 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
832                 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
833 
834                 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
835                 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
836                 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
837 
838                 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
839                     &IID_IWICImagingFactory, (void**)&factory);
840                 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
841                 if (SUCCEEDED(hr))
842                 {
843                     hr = IWICImagingFactory_CreatePalette(factory, &palette);
844                     ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
845                     if (SUCCEEDED(hr))
846                     {
847                         hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
848                         ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
849 
850                         hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
851                         ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
852 
853                         hr = IWICPalette_GetColorCount(palette, &count);
854                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
855                         ok(count == 6, "expected count=6, got %u\n", count);
856 
857                         hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
858                         ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
859                         ok(count == 6, "expected count=6, got %u\n", count);
860                         ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
861 
862                         IWICPalette_Release(palette);
863                     }
864 
865                     IWICImagingFactory_Release(factory);
866                 }
867 
868                 rc.X = 0;
869                 rc.Y = 0;
870                 rc.Width = 8;
871                 rc.Height = 8;
872                 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
873                 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
874                 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
875 
876                 IWICBitmapFrameDecode_Release(framedecode);
877             }
878 
879             hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
880                 &IID_IWICBitmapDecoder, (void**)&decoder2);
881             ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
882             if (SUCCEEDED(hr))
883             {
884                 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
885                 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
886                 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
887                     "unexpected capabilities: %x\n", capability);
888                 IWICBitmapDecoder_Release(decoder2);
889             }
890 
891             IStream_Release(bmpstream);
892         }
893 
894         GlobalFree(hbmpdata);
895     }
896 
897     IWICBitmapDecoder_Release(decoder);
898 }
899 
900 static void test_componentinfo(void)
901 {
902     IWICImagingFactory *factory;
903     IWICComponentInfo *info;
904     IWICBitmapDecoderInfo *decoderinfo;
905     IWICBitmapDecoder *decoder;
906     HRESULT hr;
907     WICBitmapPattern *patterns;
908     UINT pattern_count, pattern_size;
909     WICComponentType type;
910     GUID guidresult;
911     HGLOBAL hbmpdata;
912     char *bmpdata;
913     IStream *bmpstream;
914     BOOL boolresult;
915 
916     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
917         &IID_IWICImagingFactory, (void**)&factory);
918     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
919     if (SUCCEEDED(hr))
920     {
921         hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
922         ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%x\n", hr);
923         if (SUCCEEDED(hr))
924         {
925             hr = IWICComponentInfo_GetComponentType(info, &type);
926             ok(SUCCEEDED(hr), "GetComponentType failed, hr=%x\n", hr);
927             ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
928 
929             hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
930             ok(SUCCEEDED(hr), "QueryInterface failed, hr=%x\n", hr);
931             if (SUCCEEDED(hr))
932             {
933                 pattern_count = 0;
934                 pattern_size = 0;
935                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
936                 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
937                 ok(pattern_count != 0, "pattern count is 0\n");
938                 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
939 
940                 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
941                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
942                 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
943                 ok(pattern_count != 0, "pattern count is 0\n");
944                 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
945                 ok(patterns[0].Length != 0, "pattern length is 0\n");
946                 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
947                 ok(patterns[0].Mask != NULL, "mask is NULL\n");
948 
949                 pattern_size -= 1;
950                 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
951                 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %x, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
952 
953                 HeapFree(GetProcessHeap(), 0, patterns);
954 
955                 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
956                 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%x\n", hr);
957                 if (SUCCEEDED(hr))
958                 {
959                     hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
960                     ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
961                     ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
962 
963                     IWICBitmapDecoder_Release(decoder);
964                 }
965 
966                 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
967                 ok(hbmpdata != 0, "GlobalAlloc failed\n");
968                 if (hbmpdata)
969                 {
970                     bmpdata = GlobalLock(hbmpdata);
971                     memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
972                     GlobalUnlock(hbmpdata);
973 
974                     hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
975                     ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
976                     if (SUCCEEDED(hr))
977                     {
978                         boolresult = 0;
979                         hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
980                         ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%x\n", hr);
981                         ok(boolresult, "pattern not matched\n");
982 
983                         IStream_Release(bmpstream);
984                     }
985 
986                     GlobalFree(hbmpdata);
987                 }
988 
989                 IWICBitmapDecoderInfo_Release(decoderinfo);
990             }
991 
992             IWICComponentInfo_Release(info);
993         }
994 
995         IWICImagingFactory_Release(factory);
996     }
997 }
998 
999 static void test_createfromstream(void)
1000 {
1001     IWICBitmapDecoder *decoder;
1002     IWICImagingFactory *factory;
1003     HRESULT hr;
1004     HGLOBAL hbmpdata;
1005     char *bmpdata;
1006     IStream *bmpstream;
1007     GUID guidresult;
1008 
1009     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1010         &IID_IWICImagingFactory, (void**)&factory);
1011     ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
1012     if (FAILED(hr)) return;
1013 
1014     hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1015     ok(hbmpdata != 0, "GlobalAlloc failed\n");
1016     if (hbmpdata)
1017     {
1018         bmpdata = GlobalLock(hbmpdata);
1019         memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1020         GlobalUnlock(hbmpdata);
1021 
1022         hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1023         ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
1024         if (SUCCEEDED(hr))
1025         {
1026             hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1027                 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1028             ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%x\n", hr);
1029             if (SUCCEEDED(hr))
1030             {
1031                 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1032                 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
1033                 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1034 
1035                 IWICBitmapDecoder_Release(decoder);
1036             }
1037 
1038             IStream_Release(bmpstream);
1039         }
1040 
1041         GlobalFree(hbmpdata);
1042     }
1043 
1044     IWICImagingFactory_Release(factory);
1045 }
1046 
1047 /* 1x1 pixel gif, missing trailer */
1048 static unsigned char gifimage_notrailer[] = {
1049 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x71,0xff,0xff,0xff,
1050 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1051 0x01,0x00
1052 };
1053 
1054 static void test_gif_notrailer(void)
1055 {
1056     IWICBitmapDecoder *decoder;
1057     IWICImagingFactory *factory;
1058     HRESULT hr;
1059     IWICStream *gifstream;
1060     IWICBitmapFrameDecode *framedecode;
1061     double dpiX = 0.0, dpiY = 0.0;
1062     UINT framecount;
1063 
1064     hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1065         &IID_IWICImagingFactory, (void**)&factory);
1066     ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1067     if (FAILED(hr)) return;
1068 
1069     hr = IWICImagingFactory_CreateStream(factory, &gifstream);
1070     ok(hr == S_OK, "CreateStream failed, hr=%x\n", hr);
1071     if (SUCCEEDED(hr))
1072     {
1073         hr = IWICStream_InitializeFromMemory(gifstream, gifimage_notrailer,
1074             sizeof(gifimage_notrailer));
1075         ok(hr == S_OK, "InitializeFromMemory failed, hr=%x\n", hr);
1076 
1077         if (SUCCEEDED(hr))
1078         {
1079             hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1080                 &IID_IWICBitmapDecoder, (void**)&decoder);
1081             ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1082         }
1083 
1084         if (SUCCEEDED(hr))
1085         {
1086             hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)gifstream,
1087                 WICDecodeMetadataCacheOnDemand);
1088             ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
1089 
1090             if (SUCCEEDED(hr))
1091             {
1092                 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
1093                 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
1094                 if (SUCCEEDED(hr))
1095                 {
1096                     hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
1097                     ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
1098                     ok(dpiX == 48.0, "expected dpiX=48.0, got %f\n", dpiX);
1099                     ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
1100 
1101                     IWICBitmapFrameDecode_Release(framedecode);
1102                 }
1103             }
1104 
1105             if (SUCCEEDED(hr))
1106             {
1107                 hr = IWICBitmapDecoder_GetFrameCount(decoder, &framecount);
1108                 ok(hr == S_OK, "GetFrameCount failed, hr=%x\n", hr);
1109                 ok(framecount == 1, "framecount=%u\n", framecount);
1110             }
1111 
1112             IWICBitmapDecoder_Release(decoder);
1113         }
1114 
1115         IWICStream_Release(gifstream);
1116     }
1117 
1118     IWICImagingFactory_Release(factory);
1119 }
1120 
1121 START_TEST(bmpformat)
1122 {
1123     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1124 
1125     test_decode_24bpp();
1126     test_decode_1bpp();
1127     test_decode_4bpp();
1128     test_decode_rle8();
1129     test_decode_rle4();
1130     test_componentinfo();
1131     test_createfromstream();
1132     test_gif_notrailer();
1133 
1134     CoUninitialize();
1135 }
1136 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.