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
28 #include "wine/test.h"
30 static const char testbmp_24bpp[] = {
31 /* BITMAPFILEHEADER */
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 */
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;
61 UINT count=0, width=0, height=0;
63 BYTE imagedata[36] = {1};
64 const BYTE expected_imagedata[36] = {
65 255,0,255, 255,255,255,
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");
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);
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);
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);
148 hr = IWICImagingFactory_CreatePalette(factory, &palette);
149 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", 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);
168 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
169 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
175 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
176 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
182 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
183 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
189 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
190 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
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);
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);
230 IStream_Release(bmpstream);
233 GlobalFree(hbmpdata);
236 IWICBitmapDecoder_Release(decoder);
239 static const char testbmp_1bpp[] = {
240 /* BITMAPFILEHEADER */
242 40,0,0,0, /* file size */
243 0,0,0,0, /* reserved */
244 32,0,0,0, /* offset to bits */
245 /* BITMAPCOREHEADER */
246 12,0,0,0, /* header size */
259 static void test_decode_1bpp(void)
261 IWICBitmapDecoder *decoder, *decoder2;
262 IWICBitmapFrameDecode *framedecode;
269 UINT count=0, width=0, height=0;
271 BYTE imagedata[2] = {1};
272 const BYTE expected_imagedata[2] = {0x80,0xc0};
273 WICColor palettedata[2] = {1};
274 const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
277 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
278 &IID_IWICBitmapDecoder, (void**)&decoder);
279 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
280 if (FAILED(hr)) return;
282 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
283 ok(hbmpdata != 0, "GlobalAlloc failed\n");
286 bmpdata = GlobalLock(hbmpdata);
287 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
288 GlobalUnlock(hbmpdata);
290 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
291 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
294 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
295 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
297 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
298 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
299 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
301 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
302 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
303 ok(count == 1, "unexpected count %u\n", count);
305 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
306 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
309 IWICImagingFactory *factory;
310 IWICPalette *palette;
312 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
313 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
314 ok(width == 2, "expected width=2, got %u\n", width);
315 ok(height == 2, "expected height=2, got %u\n", height);
317 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
318 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
319 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
320 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
322 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
323 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
324 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
326 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
327 &IID_IWICImagingFactory, (void**)&factory);
328 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
331 hr = IWICImagingFactory_CreatePalette(factory, &palette);
332 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
335 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
336 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
338 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
339 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
341 hr = IWICPalette_GetColorCount(palette, &count);
342 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
343 ok(count == 2, "expected count=2, got %u\n", count);
345 hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
346 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
347 ok(count == 2, "expected count=2, got %u\n", count);
348 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
350 IWICPalette_Release(palette);
353 IWICImagingFactory_Release(factory);
360 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
361 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
362 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
364 IWICBitmapFrameDecode_Release(framedecode);
367 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
368 &IID_IWICBitmapDecoder, (void**)&decoder2);
369 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
372 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
373 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
374 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
375 "unexpected capabilities: %x\n", capability);
378 IStream_Release(bmpstream);
381 GlobalFree(hbmpdata);
384 IWICBitmapDecoder_Release(decoder);
387 static const char testbmp_4bpp[] = {
388 /* BITMAPFILEHEADER */
390 82,0,0,0, /* file size */
391 0,0,0,0, /* reserved */
392 74,0,0,0, /* offset to bits */
393 /* BITMAPINFOHEADER */
394 40,0,0,0, /* header size */
396 254,255,255,255, /* height = -2 */
399 0,0,0,0, /* compression = BI_RGB */
400 0,0,0,0, /* image size = 0 */
401 16,39,0,0, /* X pixels per meter = 10000 */
402 32,78,0,0, /* Y pixels per meter = 20000 */
403 5,0,0,0, /* colors used */
404 5,0,0,0, /* colors important */
416 static void test_decode_4bpp(void)
418 IWICBitmapDecoder *decoder, *decoder2;
419 IWICBitmapFrameDecode *framedecode;
426 UINT count=0, width=0, height=0;
428 BYTE imagedata[2] = {1};
429 const BYTE expected_imagedata[2] = {0x01,0x23};
430 WICColor palettedata[5] = {1};
431 const WICColor expected_palettedata[5] =
432 {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
435 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
436 &IID_IWICBitmapDecoder, (void**)&decoder);
437 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
438 if (FAILED(hr)) return;
440 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
441 ok(hbmpdata != 0, "GlobalAlloc failed\n");
444 bmpdata = GlobalLock(hbmpdata);
445 memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
446 GlobalUnlock(hbmpdata);
448 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
449 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
452 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
453 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
455 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
456 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
457 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
459 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
460 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
461 ok(count == 1, "unexpected count %u\n", count);
463 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
464 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
467 IWICImagingFactory *factory;
468 IWICPalette *palette;
470 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
471 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
472 ok(width == 2, "expected width=2, got %u\n", width);
473 ok(height == 2, "expected height=2, got %u\n", height);
475 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
476 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
477 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
478 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
480 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
481 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
482 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
484 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
485 &IID_IWICImagingFactory, (void**)&factory);
486 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
489 hr = IWICImagingFactory_CreatePalette(factory, &palette);
490 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
493 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
494 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
496 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
497 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
499 hr = IWICPalette_GetColorCount(palette, &count);
500 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
501 ok(count == 5, "expected count=5, got %u\n", count);
503 hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
504 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
505 ok(count == 5, "expected count=5, got %u\n", count);
506 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
508 IWICPalette_Release(palette);
511 IWICImagingFactory_Release(factory);
518 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
519 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
520 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
522 IWICBitmapFrameDecode_Release(framedecode);
525 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
526 &IID_IWICBitmapDecoder, (void**)&decoder2);
527 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
530 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
531 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
532 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
533 "unexpected capabilities: %x\n", capability);
536 IStream_Release(bmpstream);
539 GlobalFree(hbmpdata);
542 IWICBitmapDecoder_Release(decoder);
545 static const char testbmp_rle8[] = {
546 /* BITMAPFILEHEADER */
548 202,0,0,0, /* file size */
549 0,0,0,0, /* reserved */
550 122,0,0,0, /* offset to bits */
551 /* BITMAPINFOHEADER */
552 40,0,0,0, /* header size */
554 8,0,0,0, /* height */
557 1,0,0,0, /* compression = BI_RLE8 */
558 80,0,0,0, /* image size */
559 19,11,0,0, /* X pixels per meter */
560 19,11,0,0, /* Y pixels per meter */
561 17,0,0,0, /* colors used */
562 17,0,0,0, /* colors important */
582 4,15,0,4,11,9,9,0,0,0,4,14,0,4,3,10,10,7,0,0,4,13,0,4,3,10,10,7,0,0,4,12,0,4,0,1,1,11,0,0,0,4,16,2,16,2,4,4,0,0,0,4,2,16,2,16,4,5,0,0,0,4,16,2,16,2,4,6,0,0,0,4,2,16,2,16,4,8,0,1
585 static void test_decode_rle8(void)
587 IWICBitmapDecoder *decoder, *decoder2;
588 IWICBitmapFrameDecode *framedecode;
595 UINT count=0, width=0, height=0;
597 DWORD imagedata[64] = {1};
598 const DWORD expected_imagedata[64] = {
599 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
600 0xffffff,0x0000ff,0xffffff,0x0000ff,0xee0000,0xee0000,0xee0000,0xee0000,
601 0x0000ff,0xffffff,0x0000ff,0xffffff,0xdd0000,0xdd0000,0xdd0000,0xdd0000,
602 0xffffff,0x0000ff,0xffffff,0x0000ff,0xcc0000,0xcc0000,0xcc0000,0xcc0000,
603 0x00cc00,0x00cc00,0x00cc00,0x00cc00,0x000000,0x111111,0x111111,0x555555,
604 0x00dd00,0x00dd00,0x00dd00,0x00dd00,0x222222,0xff00ff,0xff00ff,0x333333,
605 0x00ee00,0x00ee00,0x00ee00,0x00ee00,0x222222,0xff00ff,0xff00ff,0x333333,
606 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x555555,0x444444,0x444444,0x000000};
607 WICColor palettedata[17] = {1};
608 const WICColor expected_palettedata[17] = {
609 0xff000000,0xff111111,0xff0000ff,0xff222222,0xffcc0000,0xffdd0000,
610 0xffee0000,0xff333333,0xffff0000,0xff444444,0xffff00ff,0xff555555,
611 0xff00cc00,0xff00dd00,0xff00ee00,0xff00ff00,0xffffffff};
614 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
615 &IID_IWICBitmapDecoder, (void**)&decoder);
616 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
617 if (FAILED(hr)) return;
619 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
620 ok(hbmpdata != 0, "GlobalAlloc failed\n");
623 bmpdata = GlobalLock(hbmpdata);
624 memcpy(bmpdata, testbmp_rle8, sizeof(testbmp_rle8));
625 GlobalUnlock(hbmpdata);
627 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
628 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
631 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
632 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
634 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
635 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
636 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
638 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
639 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
640 ok(count == 1, "unexpected count %u\n", count);
642 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
643 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
646 IWICImagingFactory *factory;
647 IWICPalette *palette;
649 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
650 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
651 ok(width == 8, "expected width=8, got %u\n", width);
652 ok(height == 8, "expected height=8, got %u\n", height);
654 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
655 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
656 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
657 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
659 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
660 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
661 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
663 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
664 &IID_IWICImagingFactory, (void**)&factory);
665 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
668 hr = IWICImagingFactory_CreatePalette(factory, &palette);
669 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
672 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
673 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
675 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
676 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
678 hr = IWICPalette_GetColorCount(palette, &count);
679 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
680 ok(count == 17, "expected count=17, got %u\n", count);
682 hr = IWICPalette_GetColors(palette, 17, palettedata, &count);
683 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
684 ok(count == 17, "expected count=17, got %u\n", count);
685 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
687 IWICPalette_Release(palette);
690 IWICImagingFactory_Release(factory);
697 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
698 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
699 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
701 IWICBitmapFrameDecode_Release(framedecode);
704 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
705 &IID_IWICBitmapDecoder, (void**)&decoder2);
706 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
709 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
710 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
711 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
712 "unexpected capabilities: %x\n", capability);
715 IStream_Release(bmpstream);
718 GlobalFree(hbmpdata);
721 IWICBitmapDecoder_Release(decoder);
724 static const char testbmp_rle4[] = {
725 /* BITMAPFILEHEADER */
727 142,0,0,0, /* file size */
728 0,0,0,0, /* reserved */
729 78,0,0,0, /* offset to bits */
730 /* BITMAPINFOHEADER */
731 40,0,0,0, /* header size */
733 8,0,0,0, /* height */
736 2,0,0,0, /* compression = BI_RLE4 */
737 64,0,0,0, /* image size */
738 19,11,0,0, /* X pixels per meter */
739 19,11,0,0, /* Y pixels per meter */
740 6,0,0,0, /* colors used */
741 6,0,0,0, /* colors important */
750 0,8,68,68,0,0,0,0,0,8,68,68,3,48,0,0,0,8,68,68,3,48,0,0,0,8,68,68,0,0,0,0,0,8,81,81,34,34,0,0,0,8,21,21,34,34,0,0,0,8,81,81,34,34,0,0,0,8,21,21,34,34,0,1
753 static void test_decode_rle4(void)
755 IWICBitmapDecoder *decoder, *decoder2;
756 IWICBitmapFrameDecode *framedecode;
763 UINT count=0, width=0, height=0;
765 DWORD imagedata[64] = {1};
766 const DWORD expected_imagedata[64] = {
767 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
768 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
769 0x0000ff,0xffffff,0x0000ff,0xffffff,0xff0000,0xff0000,0xff0000,0xff0000,
770 0xffffff,0x0000ff,0xffffff,0x0000ff,0xff0000,0xff0000,0xff0000,0xff0000,
771 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000,
772 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
773 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0xff00ff,0xff00ff,0x000000,
774 0x00ff00,0x00ff00,0x00ff00,0x00ff00,0x000000,0x000000,0x000000,0x000000};
775 WICColor palettedata[6] = {1};
776 const WICColor expected_palettedata[6] = {
777 0xff000000,0xff0000ff,0xffff0000,0xffff00ff,0xff00ff00,0xffffffff};
780 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
781 &IID_IWICBitmapDecoder, (void**)&decoder);
782 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
783 if (FAILED(hr)) return;
785 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
786 ok(hbmpdata != 0, "GlobalAlloc failed\n");
789 bmpdata = GlobalLock(hbmpdata);
790 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
791 GlobalUnlock(hbmpdata);
793 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
794 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
797 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
798 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
800 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
801 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
802 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
804 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
805 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
806 ok(count == 1, "unexpected count %u\n", count);
808 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
809 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
812 IWICImagingFactory *factory;
813 IWICPalette *palette;
815 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
816 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
817 ok(width == 8, "expected width=8, got %u\n", width);
818 ok(height == 8, "expected height=8, got %u\n", height);
820 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
821 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
822 ok(fabs(dpiX - 72.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
823 ok(fabs(dpiY - 72.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
825 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
826 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
827 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppBGR), "unexpected pixel format\n");
829 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
830 &IID_IWICImagingFactory, (void**)&factory);
831 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
834 hr = IWICImagingFactory_CreatePalette(factory, &palette);
835 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
838 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
839 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
841 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
842 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
844 hr = IWICPalette_GetColorCount(palette, &count);
845 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
846 ok(count == 6, "expected count=6, got %u\n", count);
848 hr = IWICPalette_GetColors(palette, 6, palettedata, &count);
849 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
850 ok(count == 6, "expected count=6, got %u\n", count);
851 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
853 IWICPalette_Release(palette);
856 IWICImagingFactory_Release(factory);
863 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 32, sizeof(imagedata), (BYTE*)imagedata);
864 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
865 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
867 IWICBitmapFrameDecode_Release(framedecode);
870 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
871 &IID_IWICBitmapDecoder, (void**)&decoder2);
872 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
875 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
876 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
877 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
878 "unexpected capabilities: %x\n", capability);
881 IStream_Release(bmpstream);
884 GlobalFree(hbmpdata);
887 IWICBitmapDecoder_Release(decoder);
890 static void test_componentinfo(void)
892 IWICImagingFactory *factory;
893 IWICComponentInfo *info;
894 IWICBitmapDecoderInfo *decoderinfo;
895 IWICBitmapDecoder *decoder;
897 WICBitmapPattern *patterns;
898 UINT pattern_count, pattern_size;
899 WICComponentType type;
906 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
907 &IID_IWICImagingFactory, (void**)&factory);
908 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
911 hr = IWICImagingFactory_CreateComponentInfo(factory, &CLSID_WICBmpDecoder, &info);
912 ok(SUCCEEDED(hr), "CreateComponentInfo failed, hr=%x\n", hr);
915 hr = IWICComponentInfo_GetComponentType(info, &type);
916 ok(SUCCEEDED(hr), "GetComponentType failed, hr=%x\n", hr);
917 ok(type == WICDecoder, "got %i, expected WICDecoder\n", type);
919 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
920 ok(SUCCEEDED(hr), "QueryInterface failed, hr=%x\n", hr);
925 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, 0, NULL, &pattern_count, &pattern_size);
926 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
927 ok(pattern_count != 0, "pattern count is 0\n");
928 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
930 patterns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pattern_size);
931 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
932 ok(SUCCEEDED(hr), "GetPatterns failed, hr=%x\n", hr);
933 ok(pattern_count != 0, "pattern count is 0\n");
934 ok(pattern_size > pattern_count * sizeof(WICBitmapPattern), "size=%i, count=%i\n", pattern_size, pattern_count);
935 ok(patterns[0].Length != 0, "pattern length is 0\n");
936 ok(patterns[0].Pattern != NULL, "pattern is NULL\n");
937 ok(patterns[0].Mask != NULL, "mask is NULL\n");
940 hr = IWICBitmapDecoderInfo_GetPatterns(decoderinfo, pattern_size, patterns, &pattern_count, &pattern_size);
941 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "GetPatterns returned %x, expected WINCODEC_ERR_INSUFFICIENTBUFFER\n", hr);
943 HeapFree(GetProcessHeap(), 0, patterns);
945 hr = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
946 ok(SUCCEEDED(hr), "CreateInstance failed, hr=%x\n", hr);
949 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
950 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
951 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
953 IWICBitmapDecoder_Release(decoder);
956 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
957 ok(hbmpdata != 0, "GlobalAlloc failed\n");
960 bmpdata = GlobalLock(hbmpdata);
961 memcpy(bmpdata, testbmp_rle4, sizeof(testbmp_rle4));
962 GlobalUnlock(hbmpdata);
964 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
965 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
969 hr = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, bmpstream, &boolresult);
970 ok(SUCCEEDED(hr), "MatchesPattern failed, hr=%x\n", hr);
971 ok(boolresult, "pattern not matched\n");
973 IStream_Release(bmpstream);
976 GlobalFree(hbmpdata);
979 IWICBitmapDecoderInfo_Release(decoderinfo);
982 IWICComponentInfo_Release(info);
985 IWICImagingFactory_Release(factory);
989 static void test_createfromstream(void)
991 IWICBitmapDecoder *decoder;
992 IWICImagingFactory *factory;
999 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1000 &IID_IWICImagingFactory, (void**)&factory);
1001 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
1002 if (FAILED(hr)) return;
1004 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
1005 ok(hbmpdata != 0, "GlobalAlloc failed\n");
1008 bmpdata = GlobalLock(hbmpdata);
1009 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
1010 GlobalUnlock(hbmpdata);
1012 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
1013 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
1016 hr = IWICImagingFactory_CreateDecoderFromStream(factory, bmpstream,
1017 NULL, WICDecodeMetadataCacheOnDemand, &decoder);
1018 ok(SUCCEEDED(hr), "CreateDecoderFromStream failed, hr=%x\n", hr);
1021 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
1022 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
1023 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
1025 IWICBitmapDecoder_Release(decoder);
1028 IStream_Release(bmpstream);
1031 GlobalFree(hbmpdata);
1034 IWICImagingFactory_Release(factory);
1037 START_TEST(bmpformat)
1039 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1041 test_decode_24bpp();
1046 test_componentinfo();
1047 test_createfromstream();