From 5c4ed986c0933945295dc45e56876cdb81168d6e Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 2 Jul 2012 13:48:05 -0500 Subject: [PATCH] windowscodecs: Implement IWICBitmapCodecInfo::GetPixelFormats. --- dlls/windowscodecs/info.c | 73 ++++++++++++++++++++++++++++++++++++++--- dlls/windowscodecs/tests/info.c | 54 ++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 4 deletions(-) diff --git a/dlls/windowscodecs/info.c b/dlls/windowscodecs/info.c index 9921efceb64..f1eaf4cf4dd 100644 --- a/dlls/windowscodecs/info.c +++ b/dlls/windowscodecs/info.c @@ -42,6 +42,7 @@ static const WCHAR mimetypes_valuename[] = {'M','i','m','e','T','y','p','e','s', static const WCHAR author_valuename[] = {'A','u','t','h','o','r',0}; static const WCHAR friendlyname_valuename[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0}; static const WCHAR pixelformats_keyname[] = {'P','i','x','e','l','F','o','r','m','a','t','s',0}; +static const WCHAR formats_keyname[] = {'F','o','r','m','a','t','s',0}; static const WCHAR containerformat_valuename[] = {'C','o','n','t','a','i','n','e','r','F','o','r','m','a','t',0}; static const WCHAR metadataformat_valuename[] = {'M','e','t','a','d','a','t','a','F','o','r','m','a','t',0}; static const WCHAR vendor_valuename[] = {'V','e','n','d','o','r',0}; @@ -135,6 +136,68 @@ static HRESULT ComponentInfo_GetDWORDValue(HKEY classkey, LPCWSTR value, return HRESULT_FROM_WIN32(ret); } +static HRESULT ComponentInfo_GetGuidList(HKEY classkey, LPCWSTR subkeyname, + UINT buffersize, GUID *buffer, UINT *actual_size) +{ + LONG ret; + HKEY subkey; + UINT items_returned; + WCHAR guid_string[39]; + DWORD guid_string_size; + HRESULT hr=S_OK; + + if (!actual_size) + return E_INVALIDARG; + + ret = RegOpenKeyExW(classkey, subkeyname, 0, KEY_READ, &subkey); + if (ret != ERROR_SUCCESS) return HRESULT_FROM_WIN32(ret); + + if (buffer) + { + items_returned = 0; + guid_string_size = 39; + while (items_returned < buffersize) + { + ret = RegEnumKeyExW(subkey, items_returned, guid_string, + &guid_string_size, NULL, NULL, NULL, NULL); + + if (ret != ERROR_SUCCESS) + { + hr = HRESULT_FROM_WIN32(ret); + break; + } + + if (guid_string_size != 38) + { + hr = E_FAIL; + break; + } + + hr = CLSIDFromString(guid_string, &buffer[items_returned]); + if (FAILED(hr)) + break; + + items_returned++; + guid_string_size = 39; + } + + if (ret == ERROR_NO_MORE_ITEMS) + hr = S_OK; + + *actual_size = items_returned; + } + else + { + ret = RegQueryInfoKeyW(subkey, NULL, NULL, NULL, actual_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + if (ret != ERROR_SUCCESS) + hr = HRESULT_FROM_WIN32(ret); + } + + RegCloseKey(subkey); + + return hr; +} + typedef struct { IWICBitmapDecoderInfo IWICBitmapDecoderInfo_iface; LONG ref; @@ -290,8 +353,9 @@ static HRESULT WINAPI BitmapDecoderInfo_GetContainerFormat(IWICBitmapDecoderInfo static HRESULT WINAPI BitmapDecoderInfo_GetPixelFormats(IWICBitmapDecoderInfo *iface, UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual) { - FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual); - return E_NOTIMPL; + BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface); + TRACE("(%p,%u,%p,%p)\n", iface, cFormats, pguidPixelFormats, pcActual); + return ComponentInfo_GetGuidList(This->classkey, formats_keyname, cFormats, pguidPixelFormats, pcActual); } static HRESULT WINAPI BitmapDecoderInfo_GetColorManagementVersion(IWICBitmapDecoderInfo *iface, @@ -755,8 +819,9 @@ static HRESULT WINAPI BitmapEncoderInfo_GetContainerFormat(IWICBitmapEncoderInfo static HRESULT WINAPI BitmapEncoderInfo_GetPixelFormats(IWICBitmapEncoderInfo *iface, UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual) { - FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual); - return E_NOTIMPL; + BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface); + TRACE("(%p,%u,%p,%p)\n", iface, cFormats, pguidPixelFormats, pcActual); + return ComponentInfo_GetGuidList(This->classkey, formats_keyname, cFormats, pguidPixelFormats, pcActual); } static HRESULT WINAPI BitmapEncoderInfo_GetColorManagementVersion(IWICBitmapEncoderInfo *iface, diff --git a/dlls/windowscodecs/tests/info.c b/dlls/windowscodecs/tests/info.c index cae64ff639f..6eb20cb903d 100644 --- a/dlls/windowscodecs/tests/info.c +++ b/dlls/windowscodecs/tests/info.c @@ -63,6 +63,23 @@ static HRESULT get_component_info(const GUID *clsid, IWICComponentInfo **result) return hr; } +static int is_pixelformat(GUID *format) +{ + IWICComponentInfo *info; + HRESULT hr; + WICComponentType componenttype; + + hr = get_component_info(format, &info); + if (FAILED(hr)) + return FALSE; + + hr = IWICComponentInfo_GetComponentType(info, &componenttype); + + IWICComponentInfo_Release(info); + + return SUCCEEDED(hr) && componenttype == WICPixelFormat; +} + static void test_decoder_info(void) { IWICComponentInfo *info; @@ -72,6 +89,9 @@ static void test_decoder_info(void) WCHAR value[256]; const WCHAR expected_mimetype[] = {'i','m','a','g','e','/','b','m','p',0}; CLSID clsid; + GUID pixelformats[20]; + UINT num_formats, count; + int i; hr = get_component_info(&CLSID_WICBmpDecoder, &info); @@ -114,6 +134,40 @@ static void test_decoder_info(void) ok(lstrcmpW(value, expected_mimetype) == 0, "GetMimeType returned wrong value %s\n", wine_dbgstr_w(value)); ok(len == lstrlenW(expected_mimetype)+1, "GetMimeType returned wrong len %i\n", len); + num_formats = 0xdeadbeef; + hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, &num_formats); + ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr); + ok(num_formats < 20 && num_formats > 1, "got %d formats\n", num_formats); + + hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, NULL, NULL); + ok(hr == E_INVALIDARG, "GetPixelFormats failed, hr=%x\n", hr); + + count = 0xdeadbeef; + hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 0, pixelformats, &count); + ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr); + ok(count == 0, "got %d formats\n", count); + + count = 0xdeadbeef; + hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, 1, pixelformats, &count); + ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr); + ok(count == 1, "got %d formats\n", count); + ok(is_pixelformat(&pixelformats[0]), "got invalid pixel format\n"); + + count = 0xdeadbeef; + hr = IWICBitmapDecoderInfo_GetPixelFormats(decoder_info, num_formats, pixelformats, &count); + ok(hr == S_OK, "GetPixelFormats failed, hr=%x\n", hr); + ok(count == num_formats, "got %d formats, expected %d\n", count, num_formats); + for (i=0; i