Commit cdc8e59b authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

windowscodecs: Implement ImagingFactory_CreateDecoder.

parent 40185b6c
...@@ -252,9 +252,83 @@ static HRESULT WINAPI ComponentFactory_CreateDecoder(IWICComponentFactory *iface ...@@ -252,9 +252,83 @@ static HRESULT WINAPI ComponentFactory_CreateDecoder(IWICComponentFactory *iface
REFGUID guidContainerFormat, const GUID *pguidVendor, REFGUID guidContainerFormat, const GUID *pguidVendor,
IWICBitmapDecoder **ppIDecoder) IWICBitmapDecoder **ppIDecoder)
{ {
FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat), IEnumUnknown *enumdecoders;
IUnknown *unkdecoderinfo;
IWICBitmapDecoderInfo *decoderinfo;
IWICBitmapDecoder *decoder = NULL, *preferred_decoder = NULL;
GUID vendor;
HRESULT res;
ULONG num_fetched;
TRACE("(%p,%s,%s,%p)\n", iface, debugstr_guid(guidContainerFormat),
debugstr_guid(pguidVendor), ppIDecoder); debugstr_guid(pguidVendor), ppIDecoder);
return E_NOTIMPL;
if (!guidContainerFormat || !ppIDecoder) return E_INVALIDARG;
res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders);
if (FAILED(res)) return res;
while (!preferred_decoder)
{
res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
if (res != S_OK) break;
res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void **)&decoderinfo);
if (SUCCEEDED(res))
{
GUID container_guid;
res = IWICBitmapDecoderInfo_GetContainerFormat(decoderinfo, &container_guid);
if (SUCCEEDED(res) && IsEqualIID(&container_guid, guidContainerFormat))
{
IWICBitmapDecoder *new_decoder;
res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &new_decoder);
if (SUCCEEDED(res))
{
if (pguidVendor)
{
res = IWICBitmapDecoderInfo_GetVendorGUID(decoderinfo, &vendor);
if (SUCCEEDED(res) && IsEqualIID(&vendor, pguidVendor))
{
preferred_decoder = new_decoder;
new_decoder = NULL;
}
}
if (new_decoder && !decoder)
{
decoder = new_decoder;
new_decoder = NULL;
}
if (new_decoder) IWICBitmapDecoder_Release(new_decoder);
}
}
IWICBitmapDecoderInfo_Release(decoderinfo);
}
IUnknown_Release(unkdecoderinfo);
}
IEnumUnknown_Release(enumdecoders);
if (preferred_decoder)
{
*ppIDecoder = preferred_decoder;
if (decoder) IWICBitmapDecoder_Release(decoder);
return S_OK;
}
if (decoder)
{
*ppIDecoder = decoder;
return S_OK;
}
*ppIDecoder = NULL;
return WINCODEC_ERR_COMPONENTNOTFOUND;
} }
static HRESULT WINAPI ComponentFactory_CreateEncoder(IWICComponentFactory *iface, static HRESULT WINAPI ComponentFactory_CreateEncoder(IWICComponentFactory *iface,
......
...@@ -1119,6 +1119,33 @@ static void test_gif_notrailer(void) ...@@ -1119,6 +1119,33 @@ static void test_gif_notrailer(void)
IWICImagingFactory_Release(factory); IWICImagingFactory_Release(factory);
} }
static void test_create_decoder(void)
{
IWICBitmapDecoder *decoder;
IWICImagingFactory *factory;
HRESULT hr;
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
&IID_IWICImagingFactory, (void **)&factory);
ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
hr = IWICImagingFactory_CreateDecoder(factory, NULL, NULL, NULL);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICImagingFactory_CreateDecoder(factory, NULL, NULL, &decoder);
ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICImagingFactory_CreateDecoder(factory, &GUID_ContainerFormatBmp, NULL, &decoder);
ok(hr == S_OK, "CreateDecoder error %#x\n", hr);
IWICBitmapDecoder_Release(decoder);
hr = IWICImagingFactory_CreateDecoder(factory, &GUID_ContainerFormatBmp, &GUID_VendorMicrosoft, &decoder);
ok(hr == S_OK, "CreateDecoder error %#x\n", hr);
IWICBitmapDecoder_Release(decoder);
IWICImagingFactory_Release(factory);
}
START_TEST(bmpformat) START_TEST(bmpformat)
{ {
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
...@@ -1131,6 +1158,7 @@ START_TEST(bmpformat) ...@@ -1131,6 +1158,7 @@ START_TEST(bmpformat)
test_componentinfo(); test_componentinfo();
test_createfromstream(); test_createfromstream();
test_gif_notrailer(); test_gif_notrailer();
test_create_decoder();
CoUninitialize(); CoUninitialize();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment