push(f) 5db305932526e04c957eecf195d0c75656cfa181
[wine/hacks.git] / dlls / windowscodecs / tests / bmpformat.c
blob5dc9cae70298d029a5960085138e0fc7604c5ba1
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 (!SUCCEEDED(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, "expected E_INVALIDARG, got %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);
230 IStream_Release(bmpstream);
233 GlobalFree(hbmpdata);
236 IWICBitmapDecoder_Release(decoder);
239 static const char testbmp_1bpp[] = {
240 /* BITMAPFILEHEADER */
241 66,77, /* "BM" */
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 */
247 2,0, /* width */
248 2,0, /* height */
249 1,0, /* planes */
250 1,0, /* bit count */
251 /* color table */
252 255,0,0,
253 0,255,0,
254 /* bits */
255 0xc0,0,0,0,
256 0x80,0,0,0
259 static void test_decode_1bpp(void)
261 IWICBitmapDecoder *decoder, *decoder2;
262 IWICBitmapFrameDecode *framedecode;
263 HRESULT hr;
264 HGLOBAL hbmpdata;
265 char *bmpdata;
266 IStream *bmpstream;
267 DWORD capability=0;
268 GUID guidresult;
269 UINT count=0, width=0, height=0;
270 double dpiX, dpiY;
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};
275 WICRect rc;
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 (!SUCCEEDED(hr)) return;
282 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_1bpp));
283 ok(hbmpdata != 0, "GlobalAlloc failed\n");
284 if (hbmpdata)
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);
292 if (SUCCEEDED(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);
307 if (SUCCEEDED(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);
329 if (SUCCEEDED(hr))
331 hr = IWICImagingFactory_CreatePalette(factory, &palette);
332 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
333 if (SUCCEEDED(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);
356 rc.X = 0;
357 rc.Y = 0;
358 rc.Width = 2;
359 rc.Height = 2;
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);
370 if (SUCCEEDED(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 */
389 66,77, /* "BM" */
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 */
395 2,0,0,0, /* width */
396 254,255,255,255, /* height = -2 */
397 1,0, /* planes */
398 4,0, /* bit count */
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 */
405 /* color table */
406 255,0,0,0,
407 0,255,0,255,
408 0,0,255,23,
409 128,0,128,1,
410 255,255,255,0,
411 /* bits */
412 0x01,0,0,0,
413 0x23,0,0,0,
416 static void test_decode_4bpp(void)
418 IWICBitmapDecoder *decoder, *decoder2;
419 IWICBitmapFrameDecode *framedecode;
420 HRESULT hr;
421 HGLOBAL hbmpdata;
422 char *bmpdata;
423 IStream *bmpstream;
424 DWORD capability=0;
425 GUID guidresult;
426 UINT count=0, width=0, height=0;
427 double dpiX, dpiY;
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};
433 WICRect rc;
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 (!SUCCEEDED(hr)) return;
440 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_4bpp));
441 ok(hbmpdata != 0, "GlobalAlloc failed\n");
442 if (hbmpdata)
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);
450 if (SUCCEEDED(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);
465 if (SUCCEEDED(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);
487 if (SUCCEEDED(hr))
489 hr = IWICImagingFactory_CreatePalette(factory, &palette);
490 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
491 if (SUCCEEDED(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);
514 rc.X = 0;
515 rc.Y = 0;
516 rc.Width = 2;
517 rc.Height = 2;
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);
528 if (SUCCEEDED(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 */
547 66,77, /* "BM" */
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 */
553 8,0,0,0, /* width */
554 8,0,0,0, /* height */
555 1,0, /* planes */
556 8,0, /* bit count */
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 */
563 /* color table */
564 0,0,0,0,
565 17,17,17,0,
566 255,0,0,0,
567 34,34,34,0,
568 0,0,204,0,
569 0,0,221,0,
570 0,0,238,0,
571 51,51,51,0,
572 0,0,255,0,
573 68,68,68,0,
574 255,0,255,0,
575 85,85,85,0,
576 0,204,0,0,
577 0,221,0,0,
578 0,238,0,0,
579 0,255,0,0,
580 255,255,255,0,
581 /* bits */
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;
589 HRESULT hr;
590 HGLOBAL hbmpdata;
591 char *bmpdata;
592 IStream *bmpstream;
593 DWORD capability=0;
594 GUID guidresult;
595 UINT count=0, width=0, height=0;
596 double dpiX, dpiY;
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};
612 WICRect rc;
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 (!SUCCEEDED(hr)) return;
619 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle8));
620 ok(hbmpdata != 0, "GlobalAlloc failed\n");
621 if (hbmpdata)
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);
629 if (SUCCEEDED(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);
644 if (SUCCEEDED(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);
666 if (SUCCEEDED(hr))
668 hr = IWICImagingFactory_CreatePalette(factory, &palette);
669 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
670 if (SUCCEEDED(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);
693 rc.X = 0;
694 rc.Y = 0;
695 rc.Width = 8;
696 rc.Height = 8;
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);
707 if (SUCCEEDED(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 */
726 66,77, /* "BM" */
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 */
732 8,0,0,0, /* width */
733 8,0,0,0, /* height */
734 1,0, /* planes */
735 4,0, /* bit count */
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 */
742 /* color table */
743 0,0,0,0,
744 255,0,0,0,
745 0,0,255,0,
746 255,0,255,0,
747 0,255,0,0,
748 255,255,255,0,
749 /* bits */
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;
757 HRESULT hr;
758 HGLOBAL hbmpdata;
759 char *bmpdata;
760 IStream *bmpstream;
761 DWORD capability=0;
762 GUID guidresult;
763 UINT count=0, width=0, height=0;
764 double dpiX, dpiY;
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};
778 WICRect rc;
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 (!SUCCEEDED(hr)) return;
785 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_rle4));
786 ok(hbmpdata != 0, "GlobalAlloc failed\n");
787 if (hbmpdata)
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);
795 if (SUCCEEDED(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);
810 if (SUCCEEDED(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);
832 if (SUCCEEDED(hr))
834 hr = IWICImagingFactory_CreatePalette(factory, &palette);
835 ok(SUCCEEDED(hr), "CreatePalette failed, hr=%x\n", hr);
836 if (SUCCEEDED(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);
859 rc.X = 0;
860 rc.Y = 0;
861 rc.Width = 8;
862 rc.Height = 8;
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);
873 if (SUCCEEDED(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 START_TEST(bmpformat)
892 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
894 test_decode_24bpp();
895 test_decode_1bpp();
896 test_decode_4bpp();
897 test_decode_rle8();
898 test_decode_rle4();
900 CoUninitialize();