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;
58 UINT count=0, width=0, height=0;
60 BYTE imagedata[36] = {1};
61 const BYTE expected_imagedata[36] = {
62 255,0,255, 255,255,255,
67 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
68 &IID_IWICBitmapDecoder, (void**)&decoder);
69 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
70 if (!SUCCEEDED(hr)) return;
72 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
73 ok(hbmpdata != 0, "GlobalAlloc failed\n");
76 bmpdata = GlobalLock(hbmpdata);
77 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
78 GlobalUnlock(hbmpdata);
80 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
81 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
84 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
85 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
87 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
88 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
89 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
91 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
92 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
93 ok(count == 1, "unexpected count %u\n", count);
95 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
96 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
98 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
99 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
102 IWICImagingFactory *factory;
103 IWICPalette *palette;
105 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
106 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
107 ok(width == 2, "expected width=2, got %u\n", width);
108 ok(height == 3, "expected height=2, got %u\n", height);
110 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
111 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
112 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
113 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
115 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
116 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
117 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
119 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
120 &IID_IWICImagingFactory, (void**)&factory);
121 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
124 hr = IWICImagingFactory_CreatePalette(factory, &palette);
125 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
128 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
129 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
131 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
132 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
134 IWICPalette_Release(palette);
137 IWICImagingFactory_Release(factory);
144 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
145 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
151 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
152 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
158 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
159 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
165 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
166 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
172 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
173 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
174 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
176 IWICBitmapFrameDecode_Release(framedecode);
179 /* cannot initialize twice */
180 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
181 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
183 /* cannot querycapability after initialize */
184 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
185 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
187 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
188 &IID_IWICBitmapDecoder, (void**)&decoder2);
189 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
192 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
193 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
194 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
195 "unexpected capabilities: %x\n", capability);
197 /* cannot initialize after querycapability */
198 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
199 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
201 /* cannot querycapability twice */
202 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
203 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
206 IStream_Release(bmpstream);
209 GlobalFree(hbmpdata);
212 IWICBitmapDecoder_Release(decoder);
215 static const char testbmp_1bpp[] = {
216 /* BITMAPFILEHEADER */
218 40,0,0,0, /* file size */
219 0,0,0,0, /* reserved */
220 32,0,0,0, /* offset to bits */
221 /* BITMAPCOREHEADER */
222 12,0,0,0, /* header size */
235 static void test_decode_1bpp(void)
237 IWICBitmapDecoder *decoder, *decoder2;
238 IWICBitmapFrameDecode *framedecode;
245 UINT count=0, width=0, height=0;
247 BYTE imagedata[2] = {1};
248 const BYTE expected_imagedata[2] = {0x80,0xc0};
249 WICColor palettedata[2] = {1};
250 const WICColor expected_palettedata[2] = {0xff0000ff,0xff00ff00};
253 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
254 &IID_IWICBitmapDecoder, (void**)&decoder);
255 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
256 if (!SUCCEEDED(hr)) return;
258 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
259 ok(hbmpdata != 0, "GlobalAlloc failed\n");
262 bmpdata = GlobalLock(hbmpdata);
263 memcpy(bmpdata, testbmp_1bpp, sizeof(testbmp_1bpp));
264 GlobalUnlock(hbmpdata);
266 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
267 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
270 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
271 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
273 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
274 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
275 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
277 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
278 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
279 ok(count == 1, "unexpected count %u\n", count);
281 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
282 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
285 IWICImagingFactory *factory;
286 IWICPalette *palette;
288 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
289 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
290 ok(width == 2, "expected width=2, got %u\n", width);
291 ok(height == 2, "expected height=2, got %u\n", height);
293 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
294 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
295 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
296 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
298 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
299 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
300 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat1bppIndexed), "unexpected pixel format\n");
302 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
303 &IID_IWICImagingFactory, (void**)&factory);
304 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
307 hr = IWICImagingFactory_CreatePalette(factory, &palette);
308 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
311 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
312 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
314 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
315 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
317 hr = IWICPalette_GetColorCount(palette, &count);
318 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
319 ok(count == 2, "expected count=2, got %u\n", count);
321 hr = IWICPalette_GetColors(palette, 2, palettedata, &count);
322 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
323 ok(count == 2, "expected count=2, got %u\n", count);
324 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
326 IWICPalette_Release(palette);
329 IWICImagingFactory_Release(factory);
336 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
337 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
338 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
340 IWICBitmapFrameDecode_Release(framedecode);
343 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
344 &IID_IWICBitmapDecoder, (void**)&decoder2);
345 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
348 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
349 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
350 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
351 "unexpected capabilities: %x\n", capability);
354 IStream_Release(bmpstream);
357 GlobalFree(hbmpdata);
360 IWICBitmapDecoder_Release(decoder);
363 static const char testbmp_4bpp[] = {
364 /* BITMAPFILEHEADER */
366 82,0,0,0, /* file size */
367 0,0,0,0, /* reserved */
368 74,0,0,0, /* offset to bits */
369 /* BITMAPINFOHEADER */
370 40,0,0,0, /* header size */
372 254,255,255,255, /* height = -2 */
375 0,0,0,0, /* compression = BI_RGB */
376 0,0,0,0, /* image size = 0 */
377 16,39,0,0, /* X pixels per meter = 10000 */
378 32,78,0,0, /* Y pixels per meter = 20000 */
379 5,0,0,0, /* colors used */
380 5,0,0,0, /* colors important */
392 static void test_decode_4bpp(void)
394 IWICBitmapDecoder *decoder, *decoder2;
395 IWICBitmapFrameDecode *framedecode;
402 UINT count=0, width=0, height=0;
404 BYTE imagedata[2] = {1};
405 const BYTE expected_imagedata[2] = {0x01,0x23};
406 WICColor palettedata[5] = {1};
407 const WICColor expected_palettedata[5] =
408 {0xff0000ff,0xff00ff00,0xffff0000,0xff800080,0xffffffff};
411 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
412 &IID_IWICBitmapDecoder, (void**)&decoder);
413 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
414 if (!SUCCEEDED(hr)) return;
416 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
417 ok(hbmpdata != 0, "GlobalAlloc failed\n");
420 bmpdata = GlobalLock(hbmpdata);
421 memcpy(bmpdata, testbmp_4bpp, sizeof(testbmp_4bpp));
422 GlobalUnlock(hbmpdata);
424 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
425 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
428 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
429 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
431 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
432 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
433 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
435 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
436 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
437 ok(count == 1, "unexpected count %u\n", count);
439 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
440 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
443 IWICImagingFactory *factory;
444 IWICPalette *palette;
446 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
447 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
448 ok(width == 2, "expected width=2, got %u\n", width);
449 ok(height == 2, "expected height=2, got %u\n", height);
451 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
452 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
453 ok(fabs(dpiX - 254.0) < 0.01, "expected dpiX=96.0, got %f\n", dpiX);
454 ok(fabs(dpiY - 508.0) < 0.01, "expected dpiY=96.0, got %f\n", dpiY);
456 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
457 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
458 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat4bppIndexed), "unexpected pixel format\n");
460 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
461 &IID_IWICImagingFactory, (void**)&factory);
462 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
465 hr = IWICImagingFactory_CreatePalette(factory, &palette);
466 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
469 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
470 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %x\n", hr);
472 hr = IWICBitmapFrameDecode_CopyPalette(framedecode, palette);
473 ok(SUCCEEDED(hr), "CopyPalette failed, hr=%x\n", hr);
475 hr = IWICPalette_GetColorCount(palette, &count);
476 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
477 ok(count == 5, "expected count=5, got %u\n", count);
479 hr = IWICPalette_GetColors(palette, 5, palettedata, &count);
480 ok(SUCCEEDED(hr), "GetColorCount failed, hr=%x\n", hr);
481 ok(count == 5, "expected count=5, got %u\n", count);
482 ok(!memcmp(palettedata, expected_palettedata, sizeof(palettedata)), "unexpected palette data\n");
484 IWICPalette_Release(palette);
487 IWICImagingFactory_Release(factory);
494 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 1, sizeof(imagedata), imagedata);
495 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
496 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
498 IWICBitmapFrameDecode_Release(framedecode);
501 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
502 &IID_IWICBitmapDecoder, (void**)&decoder2);
503 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
506 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
507 ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
508 ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
509 "unexpected capabilities: %x\n", capability);
512 IStream_Release(bmpstream);
515 GlobalFree(hbmpdata);
518 IWICBitmapDecoder_Release(decoder);
521 START_TEST(bmpformat)
523 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);