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
27 #include "wine/test.h"
29 static const char testbmp_24bpp[] = {
30 /* BITMAPFILEHEADER */
32 50,0,0,0, /* file size */
33 0,0,0,0, /* reserved */
34 26,0,0,0, /* offset to bits */
35 /* BITMAPCOREHEADER */
36 12,0,0,0, /* header size */
43 255,0,0, 255,255,0, 0,0,
44 255,0,255, 255,255,255, 0,0
47 static void test_decode_24bpp(void)
49 IWICBitmapDecoder *decoder, *decoder2;
50 IWICBitmapFrameDecode *framedecode;
57 UINT count=0, width=0, height=0;
60 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
61 &IID_IWICBitmapDecoder, (void**)&decoder);
62 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
63 if (!SUCCEEDED(hr)) return;
65 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
66 ok(hbmpdata != 0, "GlobalAlloc failed\n");
69 bmpdata = GlobalLock(hbmpdata);
70 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
71 GlobalUnlock(hbmpdata);
73 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
74 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
77 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
78 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
80 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
81 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
82 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
84 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
85 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
86 ok(count == 1, "unexpected count %u\n", count);
88 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
89 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
91 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
92 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
95 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
96 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
97 ok(width == 2, "expected width=2, got %u\n", width);
98 ok(height == 3, "expected height=2, got %u\n", height);
100 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
101 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
102 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
103 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
105 IWICBitmapFrameDecode_Release(framedecode);
108 /* cannot initialize twice */
109 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
110 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
112 /* cannot querycapability after initialize */
113 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
114 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
116 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
117 &IID_IWICBitmapDecoder, (void**)&decoder2);
118 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
121 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
122 todo_wine ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
123 todo_wine ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
124 "unexpected capabilities: %x\n", capability);
126 /* cannot initialize after querycapability */
127 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
128 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
130 /* cannot querycapability twice */
131 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
132 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
135 IStream_Release(bmpstream);
138 GlobalFree(hbmpdata);
141 IWICBitmapDecoder_Release(decoder);
144 START_TEST(bmpformat)
146 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);