po: Update simplified Chinese translation.
[wine/multimedia.git] / dlls / windowscodecs / tests / bmpformat.c
blobf26453316b398c44e8942072aed505e7fbf0c9ed
1 /*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <math.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "initguid.h"
26 #include "objbase.h"
27 #include "wincodec.h"
28 #include "wincodecsdk.h"
29 #include "wine/test.h"
31 static const char testbmp_24bpp[] = {
32 /* BITMAPFILEHEADER */
33 66,77, /* "BM" */
34 50,0,0,0, /* file size */
35 0,0,0,0, /* reserved */
36 26,0,0,0, /* offset to bits */
37 /* BITMAPCOREHEADER */
38 12,0,0,0, /* header size */
39 2,0, /* width */
40 3,0, /* height */
41 1,0, /* planes */
42 24,0, /* bit count */
43 /* bits */
44 0,0,0, 0,255,0, 0,0,
45 255,0,0, 255,255,0, 0,0,
46 255,0,255, 255,255,255, 0,0
49 static void test_decode_24bpp(void)
51 IWICBitmapDecoder *decoder, *decoder2;
52 IWICBitmapFrameDecode *framedecode;
53 IWICMetadataQueryReader *queryreader;
54 IWICColorContext *colorcontext;
55 IWICBitmapSource *thumbnail;
56 HRESULT hr;
57 HGLOBAL hbmpdata;
58 char *bmpdata;
59 IStream *bmpstream;
60 DWORD capability=0;
61 GUID guidresult;
62 UINT count=0, width=0, height=0;
63 double dpiX, dpiY;
64 BYTE imagedata[36] = {1};
65 const BYTE expected_imagedata[36] = {
66 255,0,255, 255,255,255,
67 255,0,0, 255,255,0,
68 0,0,0, 0,255,0};
69 WICRect rc;
71 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
72 &IID_IWICBitmapDecoder, (void**)&decoder);
73 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
74 if (FAILED(hr)) return;
76 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
77 ok(hbmpdata != 0, "GlobalAlloc failed\n");
78 if (hbmpdata)
80 bmpdata = GlobalLock(hbmpdata);
81 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
82 GlobalUnlock(hbmpdata);
84 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
85 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
86 if (SUCCEEDED(hr))
88 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
89 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
91 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
92 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
93 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
95 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader);
96 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
98 hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, &colorcontext, &count);
99 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
101 hr = IWICBitmapDecoder_GetThumbnail(decoder, &thumbnail);
102 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
104 hr = IWICBitmapDecoder_GetPreview(decoder, &thumbnail);
105 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
107 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
108 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
109 ok(count == 1, "unexpected count %u\n", count);
111 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
112 ok(hr == E_INVALIDARG || hr == WINCODEC_ERR_FRAMEMISSING, "GetFrame returned %x\n", hr);
114 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
115 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
116 if (SUCCEEDED(hr))
118 IWICImagingFactory *factory;
119 IWICPalette *palette;
121 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
122 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
123 ok(width == 2, "expected width=2, got %u\n", width);
124 ok(height == 3, "expected height=2, got %u\n", height);
126 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
127 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
128 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
129 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
131 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
132 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
133 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
135 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(framedecode, &queryreader);
136 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
138 hr = IWICBitmapFrameDecode_GetColorContexts(framedecode, 1, &colorcontext, &count);
139 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
141 hr = IWICBitmapFrameDecode_GetThumbnail(framedecode, &thumbnail);
142 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
144 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
145 &IID_IWICImagingFactory, (void**)&factory);
146 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
147 if (SUCCEEDED(hr))
149 hr = IWICImagingFactory_CreatePalette(factory, &palette);
150 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
151 if (SUCCEEDED(hr))
153 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
154 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
156 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
157 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
159 IWICPalette_Release(palette);
162 IWICImagingFactory_Release(factory);
165 rc.X = 0;
166 rc.Y = 0;
167 rc.Width = 3;
168 rc.Height = 3;
169 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
170 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
172 rc.X = -1;
173 rc.Y = 0;
174 rc.Width = 2;
175 rc.Height = 3;
176 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
177 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
179 rc.X = 0;
180 rc.Y = 0;
181 rc.Width = 2;
182 rc.Height = 3;
183 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
184 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
186 rc.X = 0;
187 rc.Y = 0;
188 rc.Width = 2;
189 rc.Height = 3;
190 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
191 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
193 rc.X = 0;
194 rc.Y = 0;
195 rc.Width = 2;
196 rc.Height = 3;
197 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
198 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
199 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
201 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, NULL, 6, sizeof(imagedata), imagedata);
202 ok(SUCCEEDED(hr), "CopyPixels(rect=NULL) failed, hr=%x\n", hr);
203 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
205 IWICBitmapFrameDecode_Release(framedecode);
208 /* cannot initialize twice */
209 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
210 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
212 /* cannot querycapability after initialize */
213 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
214 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
216 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
217 &IID_IWICBitmapDecoder, (void**)&decoder2);
218 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
219 if (SUCCEEDED(hr))
221 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
222 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
223 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
224 "unexpected capabilities: %x\n", capability);
226 /* cannot initialize after querycapability */
227 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
228 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
230 /* cannot querycapability twice */
231 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
232 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
234 IWICBitmapDecoder_Release(decoder2);
237 IStream_Release(bmpstream);
240 GlobalFree(hbmpdata);
243 IWICBitmapDecoder_Release(decoder);
246 static const char testbmp_1bpp[] = {
247 /* BITMAPFILEHEADER */
248 66,77, /* "BM" */
249 40,0,0,0, /* file size */
250 0,0,0,0, /* reserved */
251 32,0,0,0, /* offset to bits */
252 /* BITMAPCOREHEADER */
253 12,0,0,0, /* header size */
254 2,0, /* width */
255 2,0, /* height */
256 1,0, /* planes */
257 1,0, /* bit count */
258 /* color table */
259 255,0,0,
260 0,255,0,
261 /* bits */
262 0xc0,0,0,0,
263 0x80,0,0,0
266 static void test_decode_1bpp(void)
268 IWICBitmapDecoder *decoder, *decoder2;
269 IWICBitmapFrameDecode *framedecode;
270 HRESULT hr;
271 HGLOBAL hbmpdata;
272 char *bmpdata;
273 IStream *bmpstream;
274 DWORD capability=0;
275 GUID guidresult;
276 UINT count=0, width=0, height=0;
277 double dpiX, dpiY;
278 BYTE imagedata[2] = {1};
279 const BYTE expected_imagedata[2] = {0x80,0xc0};
280 WICColor palettedata[2] = {1};
281 const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
282 WICRect rc;
284 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
285 &IID_IWICBitmapDecoder, (void**)&decoder);
286 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
287 if (FAILED(hr)) return;
289 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
290 ok(hbmpdata != 0, "GlobalAlloc failed\n");
291 if (hbmpdata)
293 bmpdata = GlobalLock(hbmpdata);
294 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
295 GlobalUnlock(hbmpdata);
297 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
298 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
299 if (SUCCEEDED(hr))
301 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
302 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
304 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
305 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
306 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
308 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
309 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
310 ok(count == 1, "unexpected count %u\n", count);
312 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
313 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
314 if (SUCCEEDED(hr))
316 IWICImagingFactory *factory;
317 IWICPalette *palette;
319 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
320 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
321 ok(width == 2, "expected width=2, got %u\n", width);
322 ok(height == 2, "expected height=2, got %u\n", height);
324 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
325 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
326 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
327 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
329 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
330 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
331 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
333 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
334 &IID_IWICImagingFactory, (void**)&factory);
335 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
336 if (SUCCEEDED(hr))
338 hr = IWICImagingFactory_CreatePalette(factory, &palette);
339 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
340 if (SUCCEEDED(hr))
342 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
343 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
345 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
346 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
348 hr = IWICPalette_GetColorCount(palette, &count);
349 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
350 ok(count == 2, "expected count=2, got %u\n", count);
352 hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
353 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
354 ok(count == 2, "expected count=2, got %u\n", count);
355 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
357 IWICPalette_Release(palette);
360 IWICImagingFactory_Release(factory);
363 rc.X = 0;
364 rc.Y = 0;
365 rc.Width = 2;
366 rc.Height = 2;
367 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
368 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
369 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
371 IWICBitmapFrameDecode_Release(framedecode);
374 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
375 &IID_IWICBitmapDecoder, (void**)&decoder2);
376 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
377 if (SUCCEEDED(hr))
379 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
380 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
381 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
382 "unexpected capabilities: %x\n", capability);
383 IWICBitmapDecoder_Release(decoder2);
386 IStream_Release(bmpstream);
389 GlobalFree(hbmpdata);
392 IWICBitmapDecoder_Release(decoder);
395 static const char testbmp_4bpp[] = {
396 /* BITMAPFILEHEADER */
397 66,77, /* "BM" */
398 82,0,0,0, /* file size */
399 0,0,0,0, /* reserved */
400 74,0,0,0, /* offset to bits */
401 /* BITMAPINFOHEADER */
402 40,0,0,0, /* header size */
403 2,0,0,0, /* width */
404 254,255,255,255, /* height = -2 */
405 1,0, /* planes */
406 4,0, /* bit count */
407 0,0,0,0, /* compression = BI_RGB */
408 0,0,0,0, /* image size = 0 */
409 16,39,0,0, /* X pixels per meter = 10000 */
410 32,78,0,0, /* Y pixels per meter = 20000 */
411 5,0,0,0, /* colors used */
412 5,0,0,0, /* colors important */
413 /* color table */
414 255,0,0,0,
415 0,255,0,255,
416 0,0,255,23,
417 128,0,128,1,
418 255,255,255,0,
419 /* bits */
420 0x01,0,0,0,
421 0x23,0,0,0,
424 static void test_decode_4bpp(void)
426 IWICBitmapDecoder *decoder, *decoder2;
427 IWICBitmapFrameDecode *framedecode;
428 HRESULT hr;
429 HGLOBAL hbmpdata;
430 char *bmpdata;
431 IStream *bmpstream;
432 DWORD capability=0;
433 GUID guidresult;
434 UINT count=0, width=0, height=0;
435 double dpiX, dpiY;
436 BYTE imagedata[2] = {1};
437 const BYTE expected_imagedata[2] = {0x01,0x23};
438 WICColor palettedata[5] = {1};
439 const WICColor expected_palettedata[5] =
440 {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
441 WICRect rc;
443 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
444 &IID_IWICBitmapDecoder, (void**)&decoder);
445 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
446 if (FAILED(hr)) return;
448 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
449 ok(hbmpdata != 0, "GlobalAlloc failed\n");
450 if (hbmpdata)
452 bmpdata = GlobalLock(hbmpdata);
453 memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
454 GlobalUnlock(hbmpdata);
456 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
457 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
458 if (SUCCEEDED(hr))
460 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
461 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
463 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
464 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
465 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
467 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
468 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
469 ok(count == 1, "unexpected count %u\n", count);
471 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
472 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
473 if (SUCCEEDED(hr))
475 IWICImagingFactory *factory;
476 IWICPalette *palette;
478 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
479 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
480 ok(width == 2, "expected width=2, got %u\n", width);
481 ok(height == 2, "expected height=2, got %u\n", height);
483 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
484 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
485 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
486 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
488 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
489 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
490 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
492 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
493 &IID_IWICImagingFactory, (void**)&factory);
494 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
495 if (SUCCEEDED(hr))
497 hr = IWICImagingFactory_CreatePalette(factory, &palette);
498 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
499 if (SUCCEEDED(hr))
501 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
502 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
504 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
505 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
507 hr = IWICPalette_GetColorCount(palette, &count);
508 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
509 ok(count == 5, "expected count=5, got %u\n", count);
511 hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
512 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
513 ok(count == 5, "expected count=5, got %u\n", count);
514 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
516 IWICPalette_Release(palette);
519 IWICImagingFactory_Release(factory);
522 rc.X = 0;
523 rc.Y = 0;
524 rc.Width = 2;
525 rc.Height = 2;
526 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
527 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
528 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
530 IWICBitmapFrameDecode_Release(framedecode);
533 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
534 &IID_IWICBitmapDecoder, (void**)&decoder2);
535 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
536 if (SUCCEEDED(hr))
538 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
539 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
540 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
541 "unexpected capabilities: %x\n", capability);
542 IWICBitmapDecoder_Release(decoder2);
545 IStream_Release(bmpstream);
548 GlobalFree(hbmpdata);
551 IWICBitmapDecoder_Release(decoder);
554 static const char testbmp_rle8[] = {
555 /* BITMAPFILEHEADER */
556 66,77, /* "BM" */
557 202,0,0,0, /* file size */
558 0,0,0,0, /* reserved */
559 122,0,0,0, /* offset to bits */
560 /* BITMAPINFOHEADER */
561 40,0,0,0, /* header size */
562 8,0,0,0, /* width */
563 8,0,0,0, /* height */
564 1,0, /* planes */
565 8,0, /* bit count */
566 1,0,0,0, /* compression = BI_RLE8 */
567 80,0,0,0, /* image size */
568 19,11,0,0, /* X pixels per meter */
569 19,11,0,0, /* Y pixels per meter */
570 17,0,0,0, /* colors used */
571 17,0,0,0, /* colors important */
572 /* color table */
573 0,0,0,0,
574 17,17,17,0,
575 255,0,0,0,
576 34,34,34,0,
577 0,0,204,0,
578 0,0,221,0,
579 0,0,238,0,
580 51,51,51,0,
581 0,0,255,0,
582 68,68,68,0,
583 255,0,255,0,
584 85,85,85,0,
585 0,204,0,0,
586 0,221,0,0,
587 0,238,0,0,
588 0,255,0,0,
589 255,255,255,0,
590 /* bits */
591 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
594 static void test_decode_rle8(void)
596 IWICBitmapDecoder *decoder, *decoder2;
597 IWICBitmapFrameDecode *framedecode;
598 HRESULT hr;
599 HGLOBAL hbmpdata;
600 char *bmpdata;
601 IStream *bmpstream;
602 DWORD capability=0;
603 GUID guidresult;
604 UINT count=0, width=0, height=0;
605 double dpiX, dpiY;
606 DWORD imagedata[64] = {1};
607 const DWORD expected_imagedata[64] = {
608 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
609 0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
610 0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
611 0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
612 0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
613 0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
614 0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
615 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
616 WICColor palettedata[17] = {1};
617 const WICColor expected_palettedata[17] = {
618 0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
619 0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
620 0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
621 WICRect rc;
623 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
624 &IID_IWICBitmapDecoder, (void**)&decoder);
625 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
626 if (FAILED(hr)) return;
628 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
629 ok(hbmpdata != 0, "GlobalAlloc failed\n");
630 if (hbmpdata)
632 bmpdata = GlobalLock(hbmpdata);
633 memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
634 GlobalUnlock(hbmpdata);
636 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
637 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
638 if (SUCCEEDED(hr))
640 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
641 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
643 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
644 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
645 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
647 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
648 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
649 ok(count == 1, "unexpected count %u\n", count);
651 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
652 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
653 if (SUCCEEDED(hr))
655 IWICImagingFactory *factory;
656 IWICPalette *palette;
658 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
659 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
660 ok(width == 8, "expected width=8, got %u\n", width);
661 ok(height == 8, "expected height=8, got %u\n", height);
663 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
664 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
665 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
666 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
668 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
669 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
670 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
672 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
673 &IID_IWICImagingFactory, (void**)&factory);
674 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
675 if (SUCCEEDED(hr))
677 hr = IWICImagingFactory_CreatePalette(factory, &palette);
678 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
679 if (SUCCEEDED(hr))
681 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
682 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
684 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
685 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
687 hr = IWICPalette_GetColorCount(palette, &count);
688 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
689 ok(count == 17, "expected count=17, got %u\n", count);
691 hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
692 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
693 ok(count == 17, "expected count=17, got %u\n", count);
694 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
696 IWICPalette_Release(palette);
699 IWICImagingFactory_Release(factory);
702 rc.X = 0;
703 rc.Y = 0;
704 rc.Width = 8;
705 rc.Height = 8;
706 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
707 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
708 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
710 IWICBitmapFrameDecode_Release(framedecode);
713 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
714 &IID_IWICBitmapDecoder, (void**)&decoder2);
715 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
716 if (SUCCEEDED(hr))
718 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
719 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
720 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
721 "unexpected capabilities: %x\n", capability);
722 IWICBitmapDecoder_Release(decoder2);
725 IStream_Release(bmpstream);
728 GlobalFree(hbmpdata);
731 IWICBitmapDecoder_Release(decoder);
734 static const char testbmp_rle4[] = {
735 /* BITMAPFILEHEADER */
736 66,77, /* "BM" */
737 142,0,0,0, /* file size */
738 0,0,0,0, /* reserved */
739 78,0,0,0, /* offset to bits */
740 /* BITMAPINFOHEADER */
741 40,0,0,0, /* header size */
742 8,0,0,0, /* width */
743 8,0,0,0, /* height */
744 1,0, /* planes */
745 4,0, /* bit count */
746 2,0,0,0, /* compression = BI_RLE4 */
747 64,0,0,0, /* image size */
748 19,11,0,0, /* X pixels per meter */
749 19,11,0,0, /* Y pixels per meter */
750 6,0,0,0, /* colors used */
751 6,0,0,0, /* colors important */
752 /* color table */
753 0,0,0,0,
754 255,0,0,0,
755 0,0,255,0,
756 255,0,255,0,
757 0,255,0,0,
758 255,255,255,0,
759 /* bits */
760 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
763 static void test_decode_rle4(void)
765 IWICBitmapDecoder *decoder, *decoder2;
766 IWICBitmapFrameDecode *framedecode;
767 HRESULT hr;
768 HGLOBAL hbmpdata;
769 char *bmpdata;
770 IStream *bmpstream;
771 DWORD capability=0;
772 GUID guidresult;
773 UINT count=0, width=0, height=0;
774 double dpiX, dpiY;
775 DWORD imagedata[64] = {1};
776 const DWORD expected_imagedata[64] = {
777 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
778 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
779 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
780 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
781 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
782 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
783 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
784 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
785 WICColor palettedata[6] = {1};
786 const WICColor expected_palettedata[6] = {
787 0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
788 WICRect rc;
790 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
791 &IID_IWICBitmapDecoder, (void**)&decoder);
792 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
793 if (FAILED(hr)) return;
795 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
796 ok(hbmpdata != 0, "GlobalAlloc failed\n");
797 if (hbmpdata)
799 bmpdata = GlobalLock(hbmpdata);
800 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
801 GlobalUnlock(hbmpdata);
803 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
804 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
805 if (SUCCEEDED(hr))
807 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
808 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
810 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
811 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
812 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
814 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
815 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
816 ok(count == 1, "unexpected count %u\n", count);
818 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
819 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
820 if (SUCCEEDED(hr))
822 IWICImagingFactory *factory;
823 IWICPalette *palette;
825 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
826 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
827 ok(width == 8, "expected width=8, got %u\n", width);
828 ok(height == 8, "expected height=8, got %u\n", height);
830 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
831 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
832 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
833 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
835 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
836 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
837 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
839 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
840 &IID_IWICImagingFactory, (void**)&factory);
841 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
842 if (SUCCEEDED(hr))
844 hr = IWICImagingFactory_CreatePalette(factory, &palette);
845 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
846 if (SUCCEEDED(hr))
848 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
849 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
851 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
852 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
854 hr = IWICPalette_GetColorCount(palette, &count);
855 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
856 ok(count == 6, "expected count=6, got %u\n", count);
858 hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
859 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
860 ok(count == 6, "expected count=6, got %u\n", count);
861 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
863 IWICPalette_Release(palette);
866 IWICImagingFactory_Release(factory);
869 rc.X = 0;
870 rc.Y = 0;
871 rc.Width = 8;
872 rc.Height = 8;
873 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
874 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
875 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
877 IWICBitmapFrameDecode_Release(framedecode);
880 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
881 &IID_IWICBitmapDecoder, (void**)&decoder2);
882 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
883 if (SUCCEEDED(hr))
885 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
886 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
887 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
888 "unexpected capabilities: %x\n", capability);
889 IWICBitmapDecoder_Release(decoder2);
892 IStream_Release(bmpstream);
895 GlobalFree(hbmpdata);
898 IWICBitmapDecoder_Release(decoder);
901 static void test_componentinfo(void)
903 IWICImagingFactory *factory;
904 IWICComponentInfo *info;
905 IWICBitmapDecoderInfo *decoderinfo;
906 IWICBitmapDecoder *decoder;
907 HRESULT hr;
908 WICBitmapPattern *patterns;
909 UINT pattern_count, pattern_size;
910 WICComponentType type;
911 GUID guidresult;
912 HGLOBAL hbmpdata;
913 char *bmpdata;
914 IStream *bmpstream;
915 BOOL boolresult;
917 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
918 &IID_IWICImagingFactory, (void**)&factory);
919 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
920 if (SUCCEEDED(hr))
922 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
923 ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%x\n", hr);
924 if (SUCCEEDED(hr))
926 hr = IWICComponentInfo_GetComponentType(info, &type);
927 ok(SUCCEEDED(hr), "GetComponentType failed, hr=%x\n", hr);
928 ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
930 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
931 ok(SUCCEEDED(hr), "QueryInterface failed, hr=%x\n", hr);
932 if (SUCCEEDED(hr))
934 pattern_count = 0;
935 pattern_size = 0;
936 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
937 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
938 ok(pattern_count != 0, "pattern count is 0\n");
939 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
941 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
942 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
943 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
944 ok(pattern_count != 0, "pattern count is 0\n");
945 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
946 ok(patterns[0].Length != 0, "pattern length is 0\n");
947 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
948 ok(patterns[0].Mask != NULL, "mask is NULL\n");
950 pattern_size -= 1;
951 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
952 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %x, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
954 HeapFree(GetProcessHeap(), 0, patterns);
956 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
957 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%x\n", hr);
958 if (SUCCEEDED(hr))
960 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
961 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
962 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
964 IWICBitmapDecoder_Release(decoder);
967 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
968 ok(hbmpdata != 0, "GlobalAlloc failed\n");
969 if (hbmpdata)
971 bmpdata = GlobalLock(hbmpdata);
972 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
973 GlobalUnlock(hbmpdata);
975 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
976 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
977 if (SUCCEEDED(hr))
979 boolresult = 0;
980 hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
981 ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%x\n", hr);
982 ok(boolresult, "pattern not matched\n");
984 IStream_Release(bmpstream);
987 GlobalFree(hbmpdata);
990 IWICBitmapDecoderInfo_Release(decoderinfo);
993 IWICComponentInfo_Release(info);
996 IWICImagingFactory_Release(factory);
1000 static void test_createfromstream(void)
1002 IWICBitmapDecoder *decoder;
1003 IWICImagingFactory *factory;
1004 HRESULT hr;
1005 HGLOBAL hbmpdata;
1006 char *bmpdata;
1007 IStream *bmpstream;
1008 GUID guidresult;
1010 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1011 &IID_IWICImagingFactory, (void**)&factory);
1012 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
1013 if (FAILED(hr)) return;
1015 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1016 ok(hbmpdata != 0, "GlobalAlloc failed\n");
1017 if (hbmpdata)
1019 bmpdata = GlobalLock(hbmpdata);
1020 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1021 GlobalUnlock(hbmpdata);
1023 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1024 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
1025 if (SUCCEEDED(hr))
1027 hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1028 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1029 ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%x\n", hr);
1030 if (SUCCEEDED(hr))
1032 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1033 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
1034 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1036 IWICBitmapDecoder_Release(decoder);
1039 IStream_Release(bmpstream);
1042 GlobalFree(hbmpdata);
1045 IWICImagingFactory_Release(factory);
1048 /* 1x1 pixel gif, missing trailer */
1049 static unsigned char gifimage_notrailer[] = {
1050 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x71,0xff,0xff,0xff,
1051 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1052 0x01,0x00
1055 static void test_gif_notrailer(void)
1057 IWICBitmapDecoder *decoder;
1058 IWICImagingFactory *factory;
1059 HRESULT hr;
1060 IWICStream *gifstream;
1061 IWICBitmapFrameDecode *framedecode;
1062 double dpiX = 0.0, dpiY = 0.0;
1063 UINT framecount;
1065 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1066 &IID_IWICImagingFactory, (void**)&factory);
1067 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1068 if (FAILED(hr)) return;
1070 hr = IWICImagingFactory_CreateStream(factory, &gifstream);
1071 ok(hr == S_OK, "CreateStream failed, hr=%x\n", hr);
1072 if (SUCCEEDED(hr))
1074 hr = IWICStream_InitializeFromMemory(gifstream, gifimage_notrailer,
1075 sizeof(gifimage_notrailer));
1076 ok(hr == S_OK, "InitializeFromMemory failed, hr=%x\n", hr);
1078 if (SUCCEEDED(hr))
1080 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1081 &IID_IWICBitmapDecoder, (void**)&decoder);
1082 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1085 if (SUCCEEDED(hr))
1087 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)gifstream,
1088 WICDecodeMetadataCacheOnDemand);
1089 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
1091 if (SUCCEEDED(hr))
1093 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
1094 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
1095 if (SUCCEEDED(hr))
1097 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
1098 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
1099 ok(dpiX == 48.0, "expected dpiX=48.0, got %f\n", dpiX);
1100 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
1102 IWICBitmapFrameDecode_Release(framedecode);
1106 if (SUCCEEDED(hr))
1108 hr = IWICBitmapDecoder_GetFrameCount(decoder, &framecount);
1109 ok(hr == S_OK, "GetFrameCount failed, hr=%x\n", hr);
1110 ok(framecount == 1, "framecount=%u\n", framecount);
1113 IWICBitmapDecoder_Release(decoder);
1116 IWICStream_Release(gifstream);
1119 IWICImagingFactory_Release(factory);
1122 START_TEST(bmpformat)
1124 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1126 test_decode_24bpp();
1127 test_decode_1bpp();
1128 test_decode_4bpp();
1129 test_decode_rle8();
1130 test_decode_rle4();
1131 test_componentinfo();
1132 test_createfromstream();
1133 test_gif_notrailer();
1135 CoUninitialize();