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;
59 BYTE imagedata[36] = {1};
60 const BYTE expected_imagedata[36] = {
61 255,0,255, 255,255,255,
66 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
67 &IID_IWICBitmapDecoder, (void**)&decoder);
68 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
69 if (!SUCCEEDED(hr)) return;
71 hbmpdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(testbmp_24bpp));
72 ok(hbmpdata != 0, "GlobalAlloc failed\n");
75 bmpdata = GlobalLock(hbmpdata);
76 memcpy(bmpdata, testbmp_24bpp, sizeof(testbmp_24bpp));
77 GlobalUnlock(hbmpdata);
79 hr = CreateStreamOnHGlobal(hbmpdata, FALSE, &bmpstream);
80 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
83 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
84 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
86 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
87 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
88 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatBmp), "unexpected container format\n");
90 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
91 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
92 ok(count == 1, "unexpected count %u\n", count);
94 hr = IWICBitmapDecoder_GetFrame(decoder, 1, &framedecode);
95 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
97 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
98 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
101 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
102 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
103 ok(width == 2, "expected width=2, got %u\n", width);
104 ok(height == 3, "expected height=2, got %u\n", height);
106 hr = IWICBitmapFrameDecode_GetResolution(framedecode, &dpiX, &dpiY);
107 ok(SUCCEEDED(hr), "GetResolution failed, hr=%x\n", hr);
108 ok(dpiX == 96.0, "expected dpiX=96.0, got %f\n", dpiX);
109 ok(dpiY == 96.0, "expected dpiY=96.0, got %f\n", dpiY);
111 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
112 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
113 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR), "unexpected pixel format\n");
119 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
120 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
126 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
127 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
133 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, sizeof(imagedata), imagedata);
134 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
140 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 4, 5, imagedata);
141 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %x\n", hr);
147 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, &rc, 6, sizeof(imagedata), imagedata);
148 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
149 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)), "unexpected image data\n");
151 IWICBitmapFrameDecode_Release(framedecode);
154 /* cannot initialize twice */
155 hr = IWICBitmapDecoder_Initialize(decoder, bmpstream, WICDecodeMetadataCacheOnLoad);
156 ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
158 /* cannot querycapability after initialize */
159 hr = IWICBitmapDecoder_QueryCapability(decoder, bmpstream, &capability);
160 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
162 hr = CoCreateInstance(&CLSID_WICBmpDecoder, NULL, CLSCTX_INPROC_SERVER,
163 &IID_IWICBitmapDecoder, (void**)&decoder2);
164 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
167 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
168 todo_wine ok(hr == S_OK, "QueryCapability failed, hr=%x\n", hr);
169 todo_wine ok(capability == (WICBitmapDecoderCapabilityCanDecodeAllImages),
170 "unexpected capabilities: %x\n", capability);
172 /* cannot initialize after querycapability */
173 hr = IWICBitmapDecoder_Initialize(decoder2, bmpstream, WICDecodeMetadataCacheOnLoad);
174 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
176 /* cannot querycapability twice */
177 hr = IWICBitmapDecoder_QueryCapability(decoder2, bmpstream, &capability);
178 todo_wine ok(hr == WINCODEC_ERR_WRONGSTATE, "expected WINCODEC_ERR_WRONGSTATE, hr=%x\n", hr);
181 IStream_Release(bmpstream);
184 GlobalFree(hbmpdata);
187 IWICBitmapDecoder_Release(decoder);
190 START_TEST(bmpformat)
192 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);