advapi32: Make rpcrt4 a delayed import to work around circular dependencies with...
[wine/testsucceed.git] / dlls / windowscodecs / tests / bmpformat.c
blobf817df5178fc620d2c6ce43e3ce1f7fc2a4b2e7c
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 "wine/test.h"
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
48 static void test_decode_24bpp(void)
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;
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;
75 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
76 ok(hbmpdata != 0, "GlobalAlloc failed\n");
77 if (hbmpdata)
79 bmpdata = GlobalLock(hbmpdata);
80 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
81 GlobalUnlock(hbmpdata);
83 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
84 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
85 if (SUCCEEDED(hr))
87 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
88 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
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");
94 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &queryreader);
95 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
97 hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, &colorcontext, &count);
98 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
100 hr = IWICBitmapDecoder_GetThumbnail(decoder, &thumbnail);
101 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
103 hr = IWICBitmapDecoder_GetPreview(decoder, &thumbnail);
104 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
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);
110 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
111 ok(hr == E_INVALIDARG || hr == WINCODEC_ERR_FRAMEMISSING, "GetFrame returned %x\n", hr);
113 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
114 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
115 if (SUCCEEDED(hr))
117 IWICImagingFactory *factory;
118 IWICPalette *palette;
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);
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);
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");
134 hr = IWICBitmapFrameDecode_GetMetadataQueryReader(framedecode, &queryreader);
135 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
137 hr = IWICBitmapFrameDecode_GetColorContexts(framedecode, 1, &colorcontext, &count);
138 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "expected WINCODEC_ERR_UNSUPPORTEDOPERATION, got %x\n", hr);
140 hr = IWICBitmapFrameDecode_GetThumbnail(framedecode, &thumbnail);
141 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "expected WINCODEC_ERR_CODECNOTHUMBNAIL, got %x\n", hr);
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))
148 hr = IWICImagingFactory_CreatePalette(factory, &palette);
149 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
150 if (SUCCEEDED(hr))
152 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
153 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
155 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
156 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
158 IWICPalette_Release(palette);
161 IWICImagingFactory_Release(factory);
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);
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);
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);
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);
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");
200 IWICBitmapFrameDecode_Release(framedecode);
203 /* cannot initialize twice */
204 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
205 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
207 /* cannot querycapability after initialize */
208 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
209 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
211 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
212 &IID_IWICBitmapDecoder, (void**)&decoder2);
213 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
214 if (SUCCEEDED(hr))
216 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
217 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
218 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
219 "unexpected capabilities: %x\n", capability);
221 /* cannot initialize after querycapability */
222 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
223 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
225 /* cannot querycapability twice */
226 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
227 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
229 IWICBitmapDecoder_Release(decoder2);
232 IStream_Release(bmpstream);
235 GlobalFree(hbmpdata);
238 IWICBitmapDecoder_Release(decoder);
241 static const char testbmp_1bpp[] = {
242 /* BITMAPFILEHEADER */
243 66,77, /* "BM" */
244 40,0,0,0, /* file size */
245 0,0,0,0, /* reserved */
246 32,0,0,0, /* offset to bits */
247 /* BITMAPCOREHEADER */
248 12,0,0,0, /* header size */
249 2,0, /* width */
250 2,0, /* height */
251 1,0, /* planes */
252 1,0, /* bit count */
253 /* color table */
254 255,0,0,
255 0,255,0,
256 /* bits */
257 0xc0,0,0,0,
258 0x80,0,0,0
261 static void test_decode_1bpp(void)
263 IWICBitmapDecoder *decoder, *decoder2;
264 IWICBitmapFrameDecode *framedecode;
265 HRESULT hr;
266 HGLOBAL hbmpdata;
267 char *bmpdata;
268 IStream *bmpstream;
269 DWORD capability=0;
270 GUID guidresult;
271 UINT count=0, width=0, height=0;
272 double dpiX, dpiY;
273 BYTE imagedata[2] = {1};
274 const BYTE expected_imagedata[2] = {0x80,0xc0};
275 WICColor palettedata[2] = {1};
276 const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
277 WICRect rc;
279 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
280 &IID_IWICBitmapDecoder, (void**)&decoder);
281 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
282 if (FAILED(hr)) return;
284 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
285 ok(hbmpdata != 0, "GlobalAlloc failed\n");
286 if (hbmpdata)
288 bmpdata = GlobalLock(hbmpdata);
289 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
290 GlobalUnlock(hbmpdata);
292 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
293 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
294 if (SUCCEEDED(hr))
296 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
297 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
299 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
300 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
301 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
303 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
304 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
305 ok(count == 1, "unexpected count %u\n", count);
307 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
308 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
309 if (SUCCEEDED(hr))
311 IWICImagingFactory *factory;
312 IWICPalette *palette;
314 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
315 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
316 ok(width == 2, "expected width=2, got %u\n", width);
317 ok(height == 2, "expected height=2, got %u\n", height);
319 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
320 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
321 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
322 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
324 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
325 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
326 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
328 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
329 &IID_IWICImagingFactory, (void**)&factory);
330 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
331 if (SUCCEEDED(hr))
333 hr = IWICImagingFactory_CreatePalette(factory, &palette);
334 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
335 if (SUCCEEDED(hr))
337 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
338 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
340 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
341 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
343 hr = IWICPalette_GetColorCount(palette, &count);
344 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
345 ok(count == 2, "expected count=2, got %u\n", count);
347 hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
348 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
349 ok(count == 2, "expected count=2, got %u\n", count);
350 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
352 IWICPalette_Release(palette);
355 IWICImagingFactory_Release(factory);
358 rc.X = 0;
359 rc.Y = 0;
360 rc.Width = 2;
361 rc.Height = 2;
362 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
363 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
364 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
366 IWICBitmapFrameDecode_Release(framedecode);
369 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
370 &IID_IWICBitmapDecoder, (void**)&decoder2);
371 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
372 if (SUCCEEDED(hr))
374 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
375 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
376 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
377 "unexpected capabilities: %x\n", capability);
378 IWICBitmapDecoder_Release(decoder2);
381 IStream_Release(bmpstream);
384 GlobalFree(hbmpdata);
387 IWICBitmapDecoder_Release(decoder);
390 static const char testbmp_4bpp[] = {
391 /* BITMAPFILEHEADER */
392 66,77, /* "BM" */
393 82,0,0,0, /* file size */
394 0,0,0,0, /* reserved */
395 74,0,0,0, /* offset to bits */
396 /* BITMAPINFOHEADER */
397 40,0,0,0, /* header size */
398 2,0,0,0, /* width */
399 254,255,255,255, /* height = -2 */
400 1,0, /* planes */
401 4,0, /* bit count */
402 0,0,0,0, /* compression = BI_RGB */
403 0,0,0,0, /* image size = 0 */
404 16,39,0,0, /* X pixels per meter = 10000 */
405 32,78,0,0, /* Y pixels per meter = 20000 */
406 5,0,0,0, /* colors used */
407 5,0,0,0, /* colors important */
408 /* color table */
409 255,0,0,0,
410 0,255,0,255,
411 0,0,255,23,
412 128,0,128,1,
413 255,255,255,0,
414 /* bits */
415 0x01,0,0,0,
416 0x23,0,0,0,
419 static void test_decode_4bpp(void)
421 IWICBitmapDecoder *decoder, *decoder2;
422 IWICBitmapFrameDecode *framedecode;
423 HRESULT hr;
424 HGLOBAL hbmpdata;
425 char *bmpdata;
426 IStream *bmpstream;
427 DWORD capability=0;
428 GUID guidresult;
429 UINT count=0, width=0, height=0;
430 double dpiX, dpiY;
431 BYTE imagedata[2] = {1};
432 const BYTE expected_imagedata[2] = {0x01,0x23};
433 WICColor palettedata[5] = {1};
434 const WICColor expected_palettedata[5] =
435 {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
436 WICRect rc;
438 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
439 &IID_IWICBitmapDecoder, (void**)&decoder);
440 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
441 if (FAILED(hr)) return;
443 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
444 ok(hbmpdata != 0, "GlobalAlloc failed\n");
445 if (hbmpdata)
447 bmpdata = GlobalLock(hbmpdata);
448 memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
449 GlobalUnlock(hbmpdata);
451 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
452 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
453 if (SUCCEEDED(hr))
455 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
456 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
458 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
459 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
460 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
462 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
463 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
464 ok(count == 1, "unexpected count %u\n", count);
466 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
467 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
468 if (SUCCEEDED(hr))
470 IWICImagingFactory *factory;
471 IWICPalette *palette;
473 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
474 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
475 ok(width == 2, "expected width=2, got %u\n", width);
476 ok(height == 2, "expected height=2, got %u\n", height);
478 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
479 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
480 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
481 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
483 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
484 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
485 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
487 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
488 &IID_IWICImagingFactory, (void**)&factory);
489 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
490 if (SUCCEEDED(hr))
492 hr = IWICImagingFactory_CreatePalette(factory, &palette);
493 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
494 if (SUCCEEDED(hr))
496 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
497 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
499 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
500 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
502 hr = IWICPalette_GetColorCount(palette, &count);
503 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
504 ok(count == 5, "expected count=5, got %u\n", count);
506 hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
507 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
508 ok(count == 5, "expected count=5, got %u\n", count);
509 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
511 IWICPalette_Release(palette);
514 IWICImagingFactory_Release(factory);
517 rc.X = 0;
518 rc.Y = 0;
519 rc.Width = 2;
520 rc.Height = 2;
521 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
522 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
523 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
525 IWICBitmapFrameDecode_Release(framedecode);
528 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
529 &IID_IWICBitmapDecoder, (void**)&decoder2);
530 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
531 if (SUCCEEDED(hr))
533 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
534 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
535 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
536 "unexpected capabilities: %x\n", capability);
537 IWICBitmapDecoder_Release(decoder2);
540 IStream_Release(bmpstream);
543 GlobalFree(hbmpdata);
546 IWICBitmapDecoder_Release(decoder);
549 static const char testbmp_rle8[] = {
550 /* BITMAPFILEHEADER */
551 66,77, /* "BM" */
552 202,0,0,0, /* file size */
553 0,0,0,0, /* reserved */
554 122,0,0,0, /* offset to bits */
555 /* BITMAPINFOHEADER */
556 40,0,0,0, /* header size */
557 8,0,0,0, /* width */
558 8,0,0,0, /* height */
559 1,0, /* planes */
560 8,0, /* bit count */
561 1,0,0,0, /* compression = BI_RLE8 */
562 80,0,0,0, /* image size */
563 19,11,0,0, /* X pixels per meter */
564 19,11,0,0, /* Y pixels per meter */
565 17,0,0,0, /* colors used */
566 17,0,0,0, /* colors important */
567 /* color table */
568 0,0,0,0,
569 17,17,17,0,
570 255,0,0,0,
571 34,34,34,0,
572 0,0,204,0,
573 0,0,221,0,
574 0,0,238,0,
575 51,51,51,0,
576 0,0,255,0,
577 68,68,68,0,
578 255,0,255,0,
579 85,85,85,0,
580 0,204,0,0,
581 0,221,0,0,
582 0,238,0,0,
583 0,255,0,0,
584 255,255,255,0,
585 /* bits */
586 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
589 static void test_decode_rle8(void)
591 IWICBitmapDecoder *decoder, *decoder2;
592 IWICBitmapFrameDecode *framedecode;
593 HRESULT hr;
594 HGLOBAL hbmpdata;
595 char *bmpdata;
596 IStream *bmpstream;
597 DWORD capability=0;
598 GUID guidresult;
599 UINT count=0, width=0, height=0;
600 double dpiX, dpiY;
601 DWORD imagedata[64] = {1};
602 const DWORD expected_imagedata[64] = {
603 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
604 0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
605 0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
606 0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
607 0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
608 0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
609 0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
610 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
611 WICColor palettedata[17] = {1};
612 const WICColor expected_palettedata[17] = {
613 0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
614 0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
615 0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
616 WICRect rc;
618 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
619 &IID_IWICBitmapDecoder, (void**)&decoder);
620 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
621 if (FAILED(hr)) return;
623 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
624 ok(hbmpdata != 0, "GlobalAlloc failed\n");
625 if (hbmpdata)
627 bmpdata = GlobalLock(hbmpdata);
628 memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
629 GlobalUnlock(hbmpdata);
631 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
632 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
633 if (SUCCEEDED(hr))
635 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
636 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
638 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
639 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
640 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
642 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
643 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
644 ok(count == 1, "unexpected count %u\n", count);
646 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
647 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
648 if (SUCCEEDED(hr))
650 IWICImagingFactory *factory;
651 IWICPalette *palette;
653 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
654 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
655 ok(width == 8, "expected width=8, got %u\n", width);
656 ok(height == 8, "expected height=8, got %u\n", height);
658 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
659 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
660 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
661 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
663 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
664 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
665 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
667 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
668 &IID_IWICImagingFactory, (void**)&factory);
669 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
670 if (SUCCEEDED(hr))
672 hr = IWICImagingFactory_CreatePalette(factory, &palette);
673 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
674 if (SUCCEEDED(hr))
676 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
677 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
679 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
680 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
682 hr = IWICPalette_GetColorCount(palette, &count);
683 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
684 ok(count == 17, "expected count=17, got %u\n", count);
686 hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
687 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
688 ok(count == 17, "expected count=17, got %u\n", count);
689 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
691 IWICPalette_Release(palette);
694 IWICImagingFactory_Release(factory);
697 rc.X = 0;
698 rc.Y = 0;
699 rc.Width = 8;
700 rc.Height = 8;
701 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
702 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
703 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
705 IWICBitmapFrameDecode_Release(framedecode);
708 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
709 &IID_IWICBitmapDecoder, (void**)&decoder2);
710 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
711 if (SUCCEEDED(hr))
713 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
714 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
715 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
716 "unexpected capabilities: %x\n", capability);
717 IWICBitmapDecoder_Release(decoder2);
720 IStream_Release(bmpstream);
723 GlobalFree(hbmpdata);
726 IWICBitmapDecoder_Release(decoder);
729 static const char testbmp_rle4[] = {
730 /* BITMAPFILEHEADER */
731 66,77, /* "BM" */
732 142,0,0,0, /* file size */
733 0,0,0,0, /* reserved */
734 78,0,0,0, /* offset to bits */
735 /* BITMAPINFOHEADER */
736 40,0,0,0, /* header size */
737 8,0,0,0, /* width */
738 8,0,0,0, /* height */
739 1,0, /* planes */
740 4,0, /* bit count */
741 2,0,0,0, /* compression = BI_RLE4 */
742 64,0,0,0, /* image size */
743 19,11,0,0, /* X pixels per meter */
744 19,11,0,0, /* Y pixels per meter */
745 6,0,0,0, /* colors used */
746 6,0,0,0, /* colors important */
747 /* color table */
748 0,0,0,0,
749 255,0,0,0,
750 0,0,255,0,
751 255,0,255,0,
752 0,255,0,0,
753 255,255,255,0,
754 /* bits */
755 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
758 static void test_decode_rle4(void)
760 IWICBitmapDecoder *decoder, *decoder2;
761 IWICBitmapFrameDecode *framedecode;
762 HRESULT hr;
763 HGLOBAL hbmpdata;
764 char *bmpdata;
765 IStream *bmpstream;
766 DWORD capability=0;
767 GUID guidresult;
768 UINT count=0, width=0, height=0;
769 double dpiX, dpiY;
770 DWORD imagedata[64] = {1};
771 const DWORD expected_imagedata[64] = {
772 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
773 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
774 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
775 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
776 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
777 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
778 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
779 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
780 WICColor palettedata[6] = {1};
781 const WICColor expected_palettedata[6] = {
782 0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
783 WICRect rc;
785 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
786 &IID_IWICBitmapDecoder, (void**)&decoder);
787 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
788 if (FAILED(hr)) return;
790 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
791 ok(hbmpdata != 0, "GlobalAlloc failed\n");
792 if (hbmpdata)
794 bmpdata = GlobalLock(hbmpdata);
795 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
796 GlobalUnlock(hbmpdata);
798 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
799 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
800 if (SUCCEEDED(hr))
802 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
803 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
805 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
806 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
807 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
809 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
810 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
811 ok(count == 1, "unexpected count %u\n", count);
813 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
814 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
815 if (SUCCEEDED(hr))
817 IWICImagingFactory *factory;
818 IWICPalette *palette;
820 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
821 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
822 ok(width == 8, "expected width=8, got %u\n", width);
823 ok(height == 8, "expected height=8, got %u\n", height);
825 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
826 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
827 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
828 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
830 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
831 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
832 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
834 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
835 &IID_IWICImagingFactory, (void**)&factory);
836 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
837 if (SUCCEEDED(hr))
839 hr = IWICImagingFactory_CreatePalette(factory, &palette);
840 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
841 if (SUCCEEDED(hr))
843 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
844 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
846 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
847 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
849 hr = IWICPalette_GetColorCount(palette, &count);
850 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
851 ok(count == 6, "expected count=6, got %u\n", count);
853 hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
854 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
855 ok(count == 6, "expected count=6, got %u\n", count);
856 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
858 IWICPalette_Release(palette);
861 IWICImagingFactory_Release(factory);
864 rc.X = 0;
865 rc.Y = 0;
866 rc.Width = 8;
867 rc.Height = 8;
868 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
869 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
870 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
872 IWICBitmapFrameDecode_Release(framedecode);
875 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
876 &IID_IWICBitmapDecoder, (void**)&decoder2);
877 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
878 if (SUCCEEDED(hr))
880 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
881 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
882 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
883 "unexpected capabilities: %x\n", capability);
884 IWICBitmapDecoder_Release(decoder2);
887 IStream_Release(bmpstream);
890 GlobalFree(hbmpdata);
893 IWICBitmapDecoder_Release(decoder);
896 static void test_componentinfo(void)
898 IWICImagingFactory *factory;
899 IWICComponentInfo *info;
900 IWICBitmapDecoderInfo *decoderinfo;
901 IWICBitmapDecoder *decoder;
902 HRESULT hr;
903 WICBitmapPattern *patterns;
904 UINT pattern_count, pattern_size;
905 WICComponentType type;
906 GUID guidresult;
907 HGLOBAL hbmpdata;
908 char *bmpdata;
909 IStream *bmpstream;
910 BOOL boolresult;
912 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
913 &IID_IWICImagingFactory, (void**)&factory);
914 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
915 if (SUCCEEDED(hr))
917 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
918 ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%x\n", hr);
919 if (SUCCEEDED(hr))
921 hr = IWICComponentInfo_GetComponentType(info, &type);
922 ok(SUCCEEDED(hr), "GetComponentType failed, hr=%x\n", hr);
923 ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
925 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
926 ok(SUCCEEDED(hr), "QueryInterface failed, hr=%x\n", hr);
927 if (SUCCEEDED(hr))
929 pattern_count = 0;
930 pattern_size = 0;
931 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
932 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
933 ok(pattern_count != 0, "pattern count is 0\n");
934 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
936 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
937 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
938 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
939 ok(pattern_count != 0, "pattern count is 0\n");
940 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
941 ok(patterns[0].Length != 0, "pattern length is 0\n");
942 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
943 ok(patterns[0].Mask != NULL, "mask is NULL\n");
945 pattern_size -= 1;
946 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
947 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %x, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
949 HeapFree(GetProcessHeap(), 0, patterns);
951 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
952 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%x\n", hr);
953 if (SUCCEEDED(hr))
955 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
956 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
957 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
959 IWICBitmapDecoder_Release(decoder);
962 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
963 ok(hbmpdata != 0, "GlobalAlloc failed\n");
964 if (hbmpdata)
966 bmpdata = GlobalLock(hbmpdata);
967 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
968 GlobalUnlock(hbmpdata);
970 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
971 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
972 if (SUCCEEDED(hr))
974 boolresult = 0;
975 hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
976 ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%x\n", hr);
977 ok(boolresult, "pattern not matched\n");
979 IStream_Release(bmpstream);
982 GlobalFree(hbmpdata);
985 IWICBitmapDecoderInfo_Release(decoderinfo);
988 IWICComponentInfo_Release(info);
991 IWICImagingFactory_Release(factory);
995 static void test_createfromstream(void)
997 IWICBitmapDecoder *decoder;
998 IWICImagingFactory *factory;
999 HRESULT hr;
1000 HGLOBAL hbmpdata;
1001 char *bmpdata;
1002 IStream *bmpstream;
1003 GUID guidresult;
1005 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1006 &IID_IWICImagingFactory, (void**)&factory);
1007 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
1008 if (FAILED(hr)) return;
1010 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1011 ok(hbmpdata != 0, "GlobalAlloc failed\n");
1012 if (hbmpdata)
1014 bmpdata = GlobalLock(hbmpdata);
1015 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1016 GlobalUnlock(hbmpdata);
1018 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1019 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
1020 if (SUCCEEDED(hr))
1022 hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1023 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1024 ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%x\n", hr);
1025 if (SUCCEEDED(hr))
1027 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1028 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
1029 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1031 IWICBitmapDecoder_Release(decoder);
1034 IStream_Release(bmpstream);
1037 GlobalFree(hbmpdata);
1040 IWICImagingFactory_Release(factory);
1043 /* 1x1 pixel gif, missing trailer */
1044 static unsigned char gifimage_notrailer[] = {
1045 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1046 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1047 0x01,0x00
1050 static void test_gif_notrailer(void)
1052 IWICBitmapDecoder *decoder;
1053 IWICImagingFactory *factory;
1054 HRESULT hr;
1055 IWICStream *gifstream;
1056 IWICBitmapFrameDecode *framedecode;
1057 UINT framecount;
1059 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1060 &IID_IWICImagingFactory, (void**)&factory);
1061 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1062 if (FAILED(hr)) return;
1064 hr = IWICImagingFactory_CreateStream(factory, &gifstream);
1065 ok(hr == S_OK, "CreateStream failed, hr=%x\n", hr);
1066 if (SUCCEEDED(hr))
1068 hr = IWICStream_InitializeFromMemory(gifstream, gifimage_notrailer,
1069 sizeof(gifimage_notrailer));
1070 ok(hr == S_OK, "InitializeFromMemory failed, hr=%x\n", hr);
1072 if (SUCCEEDED(hr))
1074 hr = CoCreateInstance(&CLSID_WICGifDecoder, NULL, CLSCTX_INPROC_SERVER,
1075 &IID_IWICBitmapDecoder, (void**)&decoder);
1076 ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr);
1079 if (SUCCEEDED(hr))
1081 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)gifstream,
1082 WICDecodeMetadataCacheOnDemand);
1083 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
1085 if (SUCCEEDED(hr))
1087 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
1088 ok(hr == S_OK, "GetFrame failed, hr=%x\n", hr);
1089 if (SUCCEEDED(hr)) IWICBitmapFrameDecode_Release(framedecode);
1092 if (SUCCEEDED(hr))
1094 hr = IWICBitmapDecoder_GetFrameCount(decoder, &framecount);
1095 ok(hr == S_OK, "GetFrameCount failed, hr=%x\n", hr);
1096 ok(framecount == 1, "framecount=%u\n", framecount);
1099 IWICBitmapDecoder_Release(decoder);
1102 IWICStream_Release(gifstream);
1105 IWICImagingFactory_Release(factory);
1108 START_TEST(bmpformat)
1110 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1112 test_decode_24bpp();
1113 test_decode_1bpp();
1114 test_decode_4bpp();
1115 test_decode_rle8();
1116 test_decode_rle4();
1117 test_componentinfo();
1118 test_createfromstream();
1119 test_gif_notrailer();
1121 CoUninitialize();