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
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
35 #include "wine/list.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
39 static const WCHAR mimetypes_valuename[] = {'M','i','m','e','T','y','p','e','s',0};
40 static const WCHAR author_valuename[] = {'A','u','t','h','o','r',0};
41 static const WCHAR pixelformats_keyname[] = {'P','i','x','e','l','F','o','r','m','a','t','s',0};
42 static const WCHAR containerformat_valuename[] = {'C','o','n','t','a','i','n','e','r','F','o','r','m','a','t',0};
44 static HRESULT ComponentInfo_GetStringValue(HKEY classkey, LPCWSTR value,
45 UINT buffer_size, WCHAR *buffer, UINT *actual_size)
48 DWORD cbdata=buffer_size * sizeof(WCHAR);
53 ret = RegGetValueW(classkey, NULL, value, RRF_RT_REG_SZ|RRF_NOEXPAND, NULL,
56 if (ret == 0 || ret == ERROR_MORE_DATA)
57 *actual_size = cbdata/sizeof(WCHAR);
59 if (!buffer && buffer_size != 0)
60 /* Yes, native returns the correct size in this case. */
63 if (ret == ERROR_MORE_DATA)
64 return WINCODEC_ERR_INSUFFICIENTBUFFER;
66 return HRESULT_FROM_WIN32(ret);
69 static HRESULT ComponentInfo_GetGUIDValue(HKEY classkey, LPCWSTR value,
73 WCHAR guid_string[39];
74 DWORD cbdata = sizeof(guid_string);
80 ret = RegGetValueW(classkey, NULL, value, RRF_RT_REG_SZ|RRF_NOEXPAND, NULL,
81 guid_string, &cbdata);
83 if (ret != ERROR_SUCCESS)
84 return HRESULT_FROM_WIN32(ret);
86 if (cbdata < sizeof(guid_string))
88 ERR("incomplete GUID value\n");
92 hr = CLSIDFromString(guid_string, result);
98 IWICBitmapDecoderInfo IWICBitmapDecoderInfo_iface;
104 static inline BitmapDecoderInfo *impl_from_IWICBitmapDecoderInfo(IWICBitmapDecoderInfo *iface)
106 return CONTAINING_RECORD(iface, BitmapDecoderInfo, IWICBitmapDecoderInfo_iface);
109 static HRESULT WINAPI BitmapDecoderInfo_QueryInterface(IWICBitmapDecoderInfo *iface, REFIID iid,
112 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
113 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
115 if (!ppv) return E_INVALIDARG;
117 if (IsEqualIID(&IID_IUnknown, iid) ||
118 IsEqualIID(&IID_IWICComponentInfo, iid) ||
119 IsEqualIID(&IID_IWICBitmapCodecInfo, iid) ||
120 IsEqualIID(&IID_IWICBitmapDecoderInfo ,iid))
127 return E_NOINTERFACE;
130 IUnknown_AddRef((IUnknown*)*ppv);
134 static ULONG WINAPI BitmapDecoderInfo_AddRef(IWICBitmapDecoderInfo *iface)
136 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
137 ULONG ref = InterlockedIncrement(&This->ref);
139 TRACE("(%p) refcount=%u\n", iface, ref);
144 static ULONG WINAPI BitmapDecoderInfo_Release(IWICBitmapDecoderInfo *iface)
146 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
147 ULONG ref = InterlockedDecrement(&This->ref);
149 TRACE("(%p) refcount=%u\n", iface, ref);
153 RegCloseKey(This->classkey);
154 HeapFree(GetProcessHeap(), 0, This);
160 static HRESULT WINAPI BitmapDecoderInfo_GetComponentType(IWICBitmapDecoderInfo *iface,
161 WICComponentType *pType)
163 TRACE("(%p,%p)\n", iface, pType);
168 static HRESULT WINAPI BitmapDecoderInfo_GetCLSID(IWICBitmapDecoderInfo *iface, CLSID *pclsid)
170 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
171 TRACE("(%p,%p)\n", iface, pclsid);
176 memcpy(pclsid, &This->clsid, sizeof(CLSID));
181 static HRESULT WINAPI BitmapDecoderInfo_GetSigningStatus(IWICBitmapDecoderInfo *iface, DWORD *pStatus)
183 FIXME("(%p,%p): stub\n", iface, pStatus);
187 static HRESULT WINAPI BitmapDecoderInfo_GetAuthor(IWICBitmapDecoderInfo *iface, UINT cchAuthor,
188 WCHAR *wzAuthor, UINT *pcchActual)
190 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
192 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
194 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
195 cchAuthor, wzAuthor, pcchActual);
198 static HRESULT WINAPI BitmapDecoderInfo_GetVendorGUID(IWICBitmapDecoderInfo *iface, GUID *pguidVendor)
200 FIXME("(%p,%p): stub\n", iface, pguidVendor);
204 static HRESULT WINAPI BitmapDecoderInfo_GetVersion(IWICBitmapDecoderInfo *iface, UINT cchVersion,
205 WCHAR *wzVersion, UINT *pcchActual)
207 FIXME("(%p,%u,%p,%p): stub\n", iface, cchVersion, wzVersion, pcchActual);
211 static HRESULT WINAPI BitmapDecoderInfo_GetSpecVersion(IWICBitmapDecoderInfo *iface, UINT cchSpecVersion,
212 WCHAR *wzSpecVersion, UINT *pcchActual)
214 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
218 static HRESULT WINAPI BitmapDecoderInfo_GetFriendlyName(IWICBitmapDecoderInfo *iface, UINT cchFriendlyName,
219 WCHAR *wzFriendlyName, UINT *pcchActual)
221 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
225 static HRESULT WINAPI BitmapDecoderInfo_GetContainerFormat(IWICBitmapDecoderInfo *iface,
226 GUID *pguidContainerFormat)
228 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
229 TRACE("(%p,%p)\n", iface, pguidContainerFormat);
230 return ComponentInfo_GetGUIDValue(This->classkey, containerformat_valuename, pguidContainerFormat);
233 static HRESULT WINAPI BitmapDecoderInfo_GetPixelFormats(IWICBitmapDecoderInfo *iface,
234 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
236 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
240 static HRESULT WINAPI BitmapDecoderInfo_GetColorManagementVersion(IWICBitmapDecoderInfo *iface,
241 UINT cchColorManagementVersion, WCHAR *wzColorManagementVersion, UINT *pcchActual)
243 FIXME("(%p,%u,%p,%p): stub\n", iface, cchColorManagementVersion, wzColorManagementVersion, pcchActual);
247 static HRESULT WINAPI BitmapDecoderInfo_GetDeviceManufacturer(IWICBitmapDecoderInfo *iface,
248 UINT cchDeviceManufacturer, WCHAR *wzDeviceManufacturer, UINT *pcchActual)
250 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceManufacturer, wzDeviceManufacturer, pcchActual);
254 static HRESULT WINAPI BitmapDecoderInfo_GetDeviceModels(IWICBitmapDecoderInfo *iface,
255 UINT cchDeviceModels, WCHAR *wzDeviceModels, UINT *pcchActual)
257 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceModels, wzDeviceModels, pcchActual);
261 static HRESULT WINAPI BitmapDecoderInfo_GetMimeTypes(IWICBitmapDecoderInfo *iface,
262 UINT cchMimeTypes, WCHAR *wzMimeTypes, UINT *pcchActual)
264 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
266 TRACE("(%p,%u,%p,%p)\n", iface, cchMimeTypes, wzMimeTypes, pcchActual);
268 return ComponentInfo_GetStringValue(This->classkey, mimetypes_valuename,
269 cchMimeTypes, wzMimeTypes, pcchActual);
272 static HRESULT WINAPI BitmapDecoderInfo_GetFileExtensions(IWICBitmapDecoderInfo *iface,
273 UINT cchFileExtensions, WCHAR *wzFileExtensions, UINT *pcchActual)
275 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFileExtensions, wzFileExtensions, pcchActual);
279 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportAnimation(IWICBitmapDecoderInfo *iface,
280 BOOL *pfSupportAnimation)
282 FIXME("(%p,%p): stub\n", iface, pfSupportAnimation);
286 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportChromaKey(IWICBitmapDecoderInfo *iface,
287 BOOL *pfSupportChromaKey)
289 FIXME("(%p,%p): stub\n", iface, pfSupportChromaKey);
293 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportLossless(IWICBitmapDecoderInfo *iface,
294 BOOL *pfSupportLossless)
296 FIXME("(%p,%p): stub\n", iface, pfSupportLossless);
300 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportMultiframe(IWICBitmapDecoderInfo *iface,
301 BOOL *pfSupportMultiframe)
303 FIXME("(%p,%p): stub\n", iface, pfSupportMultiframe);
307 static HRESULT WINAPI BitmapDecoderInfo_MatchesMimeType(IWICBitmapDecoderInfo *iface,
308 LPCWSTR wzMimeType, BOOL *pfMatches)
310 FIXME("(%p,%s,%p): stub\n", iface, debugstr_w(wzMimeType), pfMatches);
314 static HRESULT WINAPI BitmapDecoderInfo_GetPatterns(IWICBitmapDecoderInfo *iface,
315 UINT cbSizePatterns, WICBitmapPattern *pPatterns, UINT *pcPatterns, UINT *pcbPatternsActual)
317 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
318 UINT pattern_count=0, patterns_size=0;
319 WCHAR subkeyname[11];
321 HKEY patternskey, patternkey;
322 static const WCHAR uintformatW[] = {'%','u',0};
323 static const WCHAR patternsW[] = {'P','a','t','t','e','r','n','s',0};
324 static const WCHAR positionW[] = {'P','o','s','i','t','i','o','n',0};
325 static const WCHAR lengthW[] = {'L','e','n','g','t','h',0};
326 static const WCHAR patternW[] = {'P','a','t','t','e','r','n',0};
327 static const WCHAR maskW[] = {'M','a','s','k',0};
328 static const WCHAR endofstreamW[] = {'E','n','d','O','f','S','t','r','e','a','m',0};
331 BYTE *bPatterns=(BYTE*)pPatterns;
332 DWORD length, valuesize;
334 TRACE("(%p,%i,%p,%p,%p)\n", iface, cbSizePatterns, pPatterns, pcPatterns, pcbPatternsActual);
336 res = RegOpenKeyExW(This->classkey, patternsW, 0, KEY_READ, &patternskey);
337 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
339 res = RegQueryInfoKeyW(patternskey, NULL, NULL, NULL, &pattern_count, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
340 if (res == ERROR_SUCCESS)
342 patterns_size = pattern_count * sizeof(WICBitmapPattern);
344 for (i=0; i<pattern_count; i++)
346 snprintfW(subkeyname, 11, uintformatW, i);
347 res = RegOpenKeyExW(patternskey, subkeyname, 0, KEY_READ, &patternkey);
348 if (res == ERROR_SUCCESS)
350 valuesize = sizeof(ULONG);
351 res = RegGetValueW(patternkey, NULL, lengthW, RRF_RT_DWORD, NULL,
352 &length, &valuesize);
353 patterns_size += length*2;
355 if ((cbSizePatterns >= patterns_size) && (res == ERROR_SUCCESS))
357 pPatterns[i].Length = length;
359 pPatterns[i].EndOfStream = 0;
360 valuesize = sizeof(BOOL);
361 RegGetValueW(patternkey, NULL, endofstreamW, RRF_RT_DWORD, NULL,
362 &pPatterns[i].EndOfStream, &valuesize);
364 pPatterns[i].Position.QuadPart = 0;
365 valuesize = sizeof(ULARGE_INTEGER);
366 res = RegGetValueW(patternkey, NULL, positionW, RRF_RT_DWORD|RRF_RT_QWORD, NULL,
367 &pPatterns[i].Position, &valuesize);
369 if (res == ERROR_SUCCESS)
371 pPatterns[i].Pattern = bPatterns+patterns_size-length*2;
373 res = RegGetValueW(patternkey, NULL, patternW, RRF_RT_REG_BINARY, NULL,
374 pPatterns[i].Pattern, &valuesize);
377 if (res == ERROR_SUCCESS)
379 pPatterns[i].Mask = bPatterns+patterns_size-length;
381 res = RegGetValueW(patternkey, NULL, maskW, RRF_RT_REG_BINARY, NULL,
382 pPatterns[i].Mask, &valuesize);
386 RegCloseKey(patternkey);
388 if (res != ERROR_SUCCESS)
390 hr = HRESULT_FROM_WIN32(res);
395 else hr = HRESULT_FROM_WIN32(res);
397 RegCloseKey(patternskey);
401 *pcPatterns = pattern_count;
402 *pcbPatternsActual = patterns_size;
403 if (pPatterns && cbSizePatterns < patterns_size)
404 hr = WINCODEC_ERR_INSUFFICIENTBUFFER;
410 static HRESULT WINAPI BitmapDecoderInfo_MatchesPattern(IWICBitmapDecoderInfo *iface,
411 IStream *pIStream, BOOL *pfMatches)
413 WICBitmapPattern *patterns;
414 UINT pattern_count=0, patterns_size=0;
420 LARGE_INTEGER seekpos;
422 TRACE("(%p,%p,%p)\n", iface, pIStream, pfMatches);
424 hr = BitmapDecoderInfo_GetPatterns(iface, 0, NULL, &pattern_count, &patterns_size);
425 if (FAILED(hr)) return hr;
427 patterns = HeapAlloc(GetProcessHeap(), 0, patterns_size);
428 if (!patterns) return E_OUTOFMEMORY;
430 hr = BitmapDecoderInfo_GetPatterns(iface, patterns_size, patterns, &pattern_count, &patterns_size);
431 if (FAILED(hr)) goto end;
433 for (i=0; i<pattern_count; i++)
435 if (datasize < patterns[i].Length)
437 HeapFree(GetProcessHeap(), 0, data);
438 datasize = patterns[i].Length;
439 data = HeapAlloc(GetProcessHeap(), 0, patterns[i].Length);
447 if (patterns[i].EndOfStream)
448 seekpos.QuadPart = -patterns[i].Position.QuadPart;
450 seekpos.QuadPart = patterns[i].Position.QuadPart;
451 hr = IStream_Seek(pIStream, seekpos, patterns[i].EndOfStream ? STREAM_SEEK_END : STREAM_SEEK_SET, NULL);
452 if (hr == STG_E_INVALIDFUNCTION) continue; /* before start of stream */
453 if (FAILED(hr)) break;
455 hr = IStream_Read(pIStream, data, patterns[i].Length, &bytesread);
456 if (hr == S_FALSE || (hr == S_OK && bytesread != patterns[i].Length)) /* past end of stream */
458 if (FAILED(hr)) break;
460 for (pos=0; pos<patterns[i].Length; pos++)
462 if ((data[pos] & patterns[i].Mask[pos]) != patterns[i].Pattern[pos])
465 if (pos == patterns[i].Length) /* matches pattern */
473 if (i == pattern_count) /* does not match any pattern */
480 HeapFree(GetProcessHeap(), 0, patterns);
481 HeapFree(GetProcessHeap(), 0, data);
486 static HRESULT WINAPI BitmapDecoderInfo_CreateInstance(IWICBitmapDecoderInfo *iface,
487 IWICBitmapDecoder **ppIBitmapDecoder)
489 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
491 TRACE("(%p,%p)\n", iface, ppIBitmapDecoder);
493 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
494 &IID_IWICBitmapDecoder, (void**)ppIBitmapDecoder);
497 static const IWICBitmapDecoderInfoVtbl BitmapDecoderInfo_Vtbl = {
498 BitmapDecoderInfo_QueryInterface,
499 BitmapDecoderInfo_AddRef,
500 BitmapDecoderInfo_Release,
501 BitmapDecoderInfo_GetComponentType,
502 BitmapDecoderInfo_GetCLSID,
503 BitmapDecoderInfo_GetSigningStatus,
504 BitmapDecoderInfo_GetAuthor,
505 BitmapDecoderInfo_GetVendorGUID,
506 BitmapDecoderInfo_GetVersion,
507 BitmapDecoderInfo_GetSpecVersion,
508 BitmapDecoderInfo_GetFriendlyName,
509 BitmapDecoderInfo_GetContainerFormat,
510 BitmapDecoderInfo_GetPixelFormats,
511 BitmapDecoderInfo_GetColorManagementVersion,
512 BitmapDecoderInfo_GetDeviceManufacturer,
513 BitmapDecoderInfo_GetDeviceModels,
514 BitmapDecoderInfo_GetMimeTypes,
515 BitmapDecoderInfo_GetFileExtensions,
516 BitmapDecoderInfo_DoesSupportAnimation,
517 BitmapDecoderInfo_DoesSupportChromaKey,
518 BitmapDecoderInfo_DoesSupportLossless,
519 BitmapDecoderInfo_DoesSupportMultiframe,
520 BitmapDecoderInfo_MatchesMimeType,
521 BitmapDecoderInfo_GetPatterns,
522 BitmapDecoderInfo_MatchesPattern,
523 BitmapDecoderInfo_CreateInstance
526 static HRESULT BitmapDecoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
528 BitmapDecoderInfo *This;
530 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapDecoderInfo));
533 RegCloseKey(classkey);
534 return E_OUTOFMEMORY;
537 This->IWICBitmapDecoderInfo_iface.lpVtbl = &BitmapDecoderInfo_Vtbl;
539 This->classkey = classkey;
540 memcpy(&This->clsid, clsid, sizeof(CLSID));
542 *ppIInfo = (IWICComponentInfo*)This;
547 IWICBitmapEncoderInfo IWICBitmapEncoderInfo_iface;
553 static inline BitmapEncoderInfo *impl_from_IWICBitmapEncoderInfo(IWICBitmapEncoderInfo *iface)
555 return CONTAINING_RECORD(iface, BitmapEncoderInfo, IWICBitmapEncoderInfo_iface);
558 static HRESULT WINAPI BitmapEncoderInfo_QueryInterface(IWICBitmapEncoderInfo *iface, REFIID iid,
561 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
562 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
564 if (!ppv) return E_INVALIDARG;
566 if (IsEqualIID(&IID_IUnknown, iid) ||
567 IsEqualIID(&IID_IWICComponentInfo, iid) ||
568 IsEqualIID(&IID_IWICBitmapCodecInfo, iid) ||
569 IsEqualIID(&IID_IWICBitmapEncoderInfo ,iid))
576 return E_NOINTERFACE;
579 IUnknown_AddRef((IUnknown*)*ppv);
583 static ULONG WINAPI BitmapEncoderInfo_AddRef(IWICBitmapEncoderInfo *iface)
585 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
586 ULONG ref = InterlockedIncrement(&This->ref);
588 TRACE("(%p) refcount=%u\n", iface, ref);
593 static ULONG WINAPI BitmapEncoderInfo_Release(IWICBitmapEncoderInfo *iface)
595 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
596 ULONG ref = InterlockedDecrement(&This->ref);
598 TRACE("(%p) refcount=%u\n", iface, ref);
602 RegCloseKey(This->classkey);
603 HeapFree(GetProcessHeap(), 0, This);
609 static HRESULT WINAPI BitmapEncoderInfo_GetComponentType(IWICBitmapEncoderInfo *iface,
610 WICComponentType *pType)
612 TRACE("(%p,%p)\n", iface, pType);
617 static HRESULT WINAPI BitmapEncoderInfo_GetCLSID(IWICBitmapEncoderInfo *iface, CLSID *pclsid)
619 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
620 TRACE("(%p,%p)\n", iface, pclsid);
625 memcpy(pclsid, &This->clsid, sizeof(CLSID));
630 static HRESULT WINAPI BitmapEncoderInfo_GetSigningStatus(IWICBitmapEncoderInfo *iface, DWORD *pStatus)
632 FIXME("(%p,%p): stub\n", iface, pStatus);
636 static HRESULT WINAPI BitmapEncoderInfo_GetAuthor(IWICBitmapEncoderInfo *iface, UINT cchAuthor,
637 WCHAR *wzAuthor, UINT *pcchActual)
639 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
641 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
643 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
644 cchAuthor, wzAuthor, pcchActual);
647 static HRESULT WINAPI BitmapEncoderInfo_GetVendorGUID(IWICBitmapEncoderInfo *iface, GUID *pguidVendor)
649 FIXME("(%p,%p): stub\n", iface, pguidVendor);
653 static HRESULT WINAPI BitmapEncoderInfo_GetVersion(IWICBitmapEncoderInfo *iface, UINT cchVersion,
654 WCHAR *wzVersion, UINT *pcchActual)
656 FIXME("(%p,%u,%p,%p): stub\n", iface, cchVersion, wzVersion, pcchActual);
660 static HRESULT WINAPI BitmapEncoderInfo_GetSpecVersion(IWICBitmapEncoderInfo *iface, UINT cchSpecVersion,
661 WCHAR *wzSpecVersion, UINT *pcchActual)
663 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
667 static HRESULT WINAPI BitmapEncoderInfo_GetFriendlyName(IWICBitmapEncoderInfo *iface, UINT cchFriendlyName,
668 WCHAR *wzFriendlyName, UINT *pcchActual)
670 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
674 static HRESULT WINAPI BitmapEncoderInfo_GetContainerFormat(IWICBitmapEncoderInfo *iface,
675 GUID *pguidContainerFormat)
677 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
678 TRACE("(%p,%p)\n", iface, pguidContainerFormat);
679 return ComponentInfo_GetGUIDValue(This->classkey, containerformat_valuename, pguidContainerFormat);
682 static HRESULT WINAPI BitmapEncoderInfo_GetPixelFormats(IWICBitmapEncoderInfo *iface,
683 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
685 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
689 static HRESULT WINAPI BitmapEncoderInfo_GetColorManagementVersion(IWICBitmapEncoderInfo *iface,
690 UINT cchColorManagementVersion, WCHAR *wzColorManagementVersion, UINT *pcchActual)
692 FIXME("(%p,%u,%p,%p): stub\n", iface, cchColorManagementVersion, wzColorManagementVersion, pcchActual);
696 static HRESULT WINAPI BitmapEncoderInfo_GetDeviceManufacturer(IWICBitmapEncoderInfo *iface,
697 UINT cchDeviceManufacturer, WCHAR *wzDeviceManufacturer, UINT *pcchActual)
699 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceManufacturer, wzDeviceManufacturer, pcchActual);
703 static HRESULT WINAPI BitmapEncoderInfo_GetDeviceModels(IWICBitmapEncoderInfo *iface,
704 UINT cchDeviceModels, WCHAR *wzDeviceModels, UINT *pcchActual)
706 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceModels, wzDeviceModels, pcchActual);
710 static HRESULT WINAPI BitmapEncoderInfo_GetMimeTypes(IWICBitmapEncoderInfo *iface,
711 UINT cchMimeTypes, WCHAR *wzMimeTypes, UINT *pcchActual)
713 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
715 TRACE("(%p,%u,%p,%p)\n", iface, cchMimeTypes, wzMimeTypes, pcchActual);
717 return ComponentInfo_GetStringValue(This->classkey, mimetypes_valuename,
718 cchMimeTypes, wzMimeTypes, pcchActual);
721 static HRESULT WINAPI BitmapEncoderInfo_GetFileExtensions(IWICBitmapEncoderInfo *iface,
722 UINT cchFileExtensions, WCHAR *wzFileExtensions, UINT *pcchActual)
724 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFileExtensions, wzFileExtensions, pcchActual);
728 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportAnimation(IWICBitmapEncoderInfo *iface,
729 BOOL *pfSupportAnimation)
731 FIXME("(%p,%p): stub\n", iface, pfSupportAnimation);
735 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportChromaKey(IWICBitmapEncoderInfo *iface,
736 BOOL *pfSupportChromaKey)
738 FIXME("(%p,%p): stub\n", iface, pfSupportChromaKey);
742 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportLossless(IWICBitmapEncoderInfo *iface,
743 BOOL *pfSupportLossless)
745 FIXME("(%p,%p): stub\n", iface, pfSupportLossless);
749 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportMultiframe(IWICBitmapEncoderInfo *iface,
750 BOOL *pfSupportMultiframe)
752 FIXME("(%p,%p): stub\n", iface, pfSupportMultiframe);
756 static HRESULT WINAPI BitmapEncoderInfo_MatchesMimeType(IWICBitmapEncoderInfo *iface,
757 LPCWSTR wzMimeType, BOOL *pfMatches)
759 FIXME("(%p,%s,%p): stub\n", iface, debugstr_w(wzMimeType), pfMatches);
763 static HRESULT WINAPI BitmapEncoderInfo_CreateInstance(IWICBitmapEncoderInfo *iface,
764 IWICBitmapEncoder **ppIBitmapEncoder)
766 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
768 TRACE("(%p,%p)\n", iface, ppIBitmapEncoder);
770 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
771 &IID_IWICBitmapEncoder, (void**)ppIBitmapEncoder);
774 static const IWICBitmapEncoderInfoVtbl BitmapEncoderInfo_Vtbl = {
775 BitmapEncoderInfo_QueryInterface,
776 BitmapEncoderInfo_AddRef,
777 BitmapEncoderInfo_Release,
778 BitmapEncoderInfo_GetComponentType,
779 BitmapEncoderInfo_GetCLSID,
780 BitmapEncoderInfo_GetSigningStatus,
781 BitmapEncoderInfo_GetAuthor,
782 BitmapEncoderInfo_GetVendorGUID,
783 BitmapEncoderInfo_GetVersion,
784 BitmapEncoderInfo_GetSpecVersion,
785 BitmapEncoderInfo_GetFriendlyName,
786 BitmapEncoderInfo_GetContainerFormat,
787 BitmapEncoderInfo_GetPixelFormats,
788 BitmapEncoderInfo_GetColorManagementVersion,
789 BitmapEncoderInfo_GetDeviceManufacturer,
790 BitmapEncoderInfo_GetDeviceModels,
791 BitmapEncoderInfo_GetMimeTypes,
792 BitmapEncoderInfo_GetFileExtensions,
793 BitmapEncoderInfo_DoesSupportAnimation,
794 BitmapEncoderInfo_DoesSupportChromaKey,
795 BitmapEncoderInfo_DoesSupportLossless,
796 BitmapEncoderInfo_DoesSupportMultiframe,
797 BitmapEncoderInfo_MatchesMimeType,
798 BitmapEncoderInfo_CreateInstance
801 static HRESULT BitmapEncoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
803 BitmapEncoderInfo *This;
805 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapEncoderInfo));
808 RegCloseKey(classkey);
809 return E_OUTOFMEMORY;
812 This->IWICBitmapEncoderInfo_iface.lpVtbl = &BitmapEncoderInfo_Vtbl;
814 This->classkey = classkey;
815 memcpy(&This->clsid, clsid, sizeof(CLSID));
817 *ppIInfo = (IWICComponentInfo*)This;
822 IWICFormatConverterInfo IWICFormatConverterInfo_iface;
826 } FormatConverterInfo;
828 static inline FormatConverterInfo *impl_from_IWICFormatConverterInfo(IWICFormatConverterInfo *iface)
830 return CONTAINING_RECORD(iface, FormatConverterInfo, IWICFormatConverterInfo_iface);
833 static HRESULT WINAPI FormatConverterInfo_QueryInterface(IWICFormatConverterInfo *iface, REFIID iid,
836 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
837 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
839 if (!ppv) return E_INVALIDARG;
841 if (IsEqualIID(&IID_IUnknown, iid) ||
842 IsEqualIID(&IID_IWICComponentInfo, iid) ||
843 IsEqualIID(&IID_IWICFormatConverterInfo ,iid))
850 return E_NOINTERFACE;
853 IUnknown_AddRef((IUnknown*)*ppv);
857 static ULONG WINAPI FormatConverterInfo_AddRef(IWICFormatConverterInfo *iface)
859 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
860 ULONG ref = InterlockedIncrement(&This->ref);
862 TRACE("(%p) refcount=%u\n", iface, ref);
867 static ULONG WINAPI FormatConverterInfo_Release(IWICFormatConverterInfo *iface)
869 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
870 ULONG ref = InterlockedDecrement(&This->ref);
872 TRACE("(%p) refcount=%u\n", iface, ref);
876 RegCloseKey(This->classkey);
877 HeapFree(GetProcessHeap(), 0, This);
883 static HRESULT WINAPI FormatConverterInfo_GetComponentType(IWICFormatConverterInfo *iface,
884 WICComponentType *pType)
886 TRACE("(%p,%p)\n", iface, pType);
887 *pType = WICPixelFormatConverter;
891 static HRESULT WINAPI FormatConverterInfo_GetCLSID(IWICFormatConverterInfo *iface, CLSID *pclsid)
893 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
894 TRACE("(%p,%p)\n", iface, pclsid);
899 memcpy(pclsid, &This->clsid, sizeof(CLSID));
904 static HRESULT WINAPI FormatConverterInfo_GetSigningStatus(IWICFormatConverterInfo *iface, DWORD *pStatus)
906 FIXME("(%p,%p): stub\n", iface, pStatus);
910 static HRESULT WINAPI FormatConverterInfo_GetAuthor(IWICFormatConverterInfo *iface, UINT cchAuthor,
911 WCHAR *wzAuthor, UINT *pcchActual)
913 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
915 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
917 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
918 cchAuthor, wzAuthor, pcchActual);
921 static HRESULT WINAPI FormatConverterInfo_GetVendorGUID(IWICFormatConverterInfo *iface, GUID *pguidVendor)
923 FIXME("(%p,%p): stub\n", iface, pguidVendor);
927 static HRESULT WINAPI FormatConverterInfo_GetVersion(IWICFormatConverterInfo *iface, UINT cchVersion,
928 WCHAR *wzVersion, UINT *pcchActual)
930 FIXME("(%p,%u,%p,%p): stub\n", iface, cchVersion, wzVersion, pcchActual);
934 static HRESULT WINAPI FormatConverterInfo_GetSpecVersion(IWICFormatConverterInfo *iface, UINT cchSpecVersion,
935 WCHAR *wzSpecVersion, UINT *pcchActual)
937 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
941 static HRESULT WINAPI FormatConverterInfo_GetFriendlyName(IWICFormatConverterInfo *iface, UINT cchFriendlyName,
942 WCHAR *wzFriendlyName, UINT *pcchActual)
944 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
948 static HRESULT WINAPI FormatConverterInfo_GetPixelFormats(IWICFormatConverterInfo *iface,
949 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
951 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
955 static HRESULT WINAPI FormatConverterInfo_CreateInstance(IWICFormatConverterInfo *iface,
956 IWICFormatConverter **ppIFormatConverter)
958 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
960 TRACE("(%p,%p)\n", iface, ppIFormatConverter);
962 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
963 &IID_IWICFormatConverter, (void**)ppIFormatConverter);
966 static BOOL ConverterSupportsFormat(IWICFormatConverterInfo *iface, const WCHAR *formatguid)
969 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
970 HKEY formats_key, guid_key;
972 /* Avoid testing using IWICFormatConverter_GetPixelFormats because that
973 would be O(n). A registry test should do better. */
975 res = RegOpenKeyExW(This->classkey, pixelformats_keyname, 0, KEY_READ, &formats_key);
976 if (res != ERROR_SUCCESS) return FALSE;
978 res = RegOpenKeyExW(formats_key, formatguid, 0, KEY_READ, &guid_key);
979 if (res == ERROR_SUCCESS) RegCloseKey(guid_key);
981 RegCloseKey(formats_key);
983 return (res == ERROR_SUCCESS);
986 static const IWICFormatConverterInfoVtbl FormatConverterInfo_Vtbl = {
987 FormatConverterInfo_QueryInterface,
988 FormatConverterInfo_AddRef,
989 FormatConverterInfo_Release,
990 FormatConverterInfo_GetComponentType,
991 FormatConverterInfo_GetCLSID,
992 FormatConverterInfo_GetSigningStatus,
993 FormatConverterInfo_GetAuthor,
994 FormatConverterInfo_GetVendorGUID,
995 FormatConverterInfo_GetVersion,
996 FormatConverterInfo_GetSpecVersion,
997 FormatConverterInfo_GetFriendlyName,
998 FormatConverterInfo_GetPixelFormats,
999 FormatConverterInfo_CreateInstance
1002 static HRESULT FormatConverterInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
1004 FormatConverterInfo *This;
1006 This = HeapAlloc(GetProcessHeap(), 0, sizeof(FormatConverterInfo));
1009 RegCloseKey(classkey);
1010 return E_OUTOFMEMORY;
1013 This->IWICFormatConverterInfo_iface.lpVtbl = &FormatConverterInfo_Vtbl;
1015 This->classkey = classkey;
1016 memcpy(&This->clsid, clsid, sizeof(CLSID));
1018 *ppIInfo = (IWICComponentInfo*)This;
1023 IWICPixelFormatInfo2 IWICPixelFormatInfo2_iface;
1029 static inline PixelFormatInfo *impl_from_IWICPixelFormatInfo2(IWICPixelFormatInfo2 *iface)
1031 return CONTAINING_RECORD(iface, PixelFormatInfo, IWICPixelFormatInfo2_iface);
1034 static HRESULT WINAPI PixelFormatInfo_QueryInterface(IWICPixelFormatInfo2 *iface, REFIID iid,
1037 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1038 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
1040 if (!ppv) return E_INVALIDARG;
1042 if (IsEqualIID(&IID_IUnknown, iid) ||
1043 IsEqualIID(&IID_IWICComponentInfo, iid) ||
1044 IsEqualIID(&IID_IWICPixelFormatInfo, iid) ||
1045 IsEqualIID(&IID_IWICPixelFormatInfo2 ,iid))
1052 return E_NOINTERFACE;
1055 IUnknown_AddRef((IUnknown*)*ppv);
1059 static ULONG WINAPI PixelFormatInfo_AddRef(IWICPixelFormatInfo2 *iface)
1061 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1062 ULONG ref = InterlockedIncrement(&This->ref);
1064 TRACE("(%p) refcount=%u\n", iface, ref);
1069 static ULONG WINAPI PixelFormatInfo_Release(IWICPixelFormatInfo2 *iface)
1071 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1072 ULONG ref = InterlockedDecrement(&This->ref);
1074 TRACE("(%p) refcount=%u\n", iface, ref);
1078 RegCloseKey(This->classkey);
1079 HeapFree(GetProcessHeap(), 0, This);
1085 static HRESULT WINAPI PixelFormatInfo_GetComponentType(IWICPixelFormatInfo2 *iface,
1086 WICComponentType *pType)
1088 TRACE("(%p,%p)\n", iface, pType);
1089 if (!pType) return E_INVALIDARG;
1090 *pType = WICPixelFormat;
1094 static HRESULT WINAPI PixelFormatInfo_GetCLSID(IWICPixelFormatInfo2 *iface, CLSID *pclsid)
1096 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1097 TRACE("(%p,%p)\n", iface, pclsid);
1100 return E_INVALIDARG;
1102 memcpy(pclsid, &This->clsid, sizeof(CLSID));
1107 static HRESULT WINAPI PixelFormatInfo_GetSigningStatus(IWICPixelFormatInfo2 *iface, DWORD *pStatus)
1109 FIXME("(%p,%p): stub\n", iface, pStatus);
1113 static HRESULT WINAPI PixelFormatInfo_GetAuthor(IWICPixelFormatInfo2 *iface, UINT cchAuthor,
1114 WCHAR *wzAuthor, UINT *pcchActual)
1116 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1118 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
1120 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
1121 cchAuthor, wzAuthor, pcchActual);
1124 static HRESULT WINAPI PixelFormatInfo_GetVendorGUID(IWICPixelFormatInfo2 *iface, GUID *pguidVendor)
1126 FIXME("(%p,%p): stub\n", iface, pguidVendor);
1130 static HRESULT WINAPI PixelFormatInfo_GetVersion(IWICPixelFormatInfo2 *iface, UINT cchVersion,
1131 WCHAR *wzVersion, UINT *pcchActual)
1133 FIXME("(%p,%u,%p,%p): stub\n", iface, cchVersion, wzVersion, pcchActual);
1137 static HRESULT WINAPI PixelFormatInfo_GetSpecVersion(IWICPixelFormatInfo2 *iface, UINT cchSpecVersion,
1138 WCHAR *wzSpecVersion, UINT *pcchActual)
1140 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
1144 static HRESULT WINAPI PixelFormatInfo_GetFriendlyName(IWICPixelFormatInfo2 *iface, UINT cchFriendlyName,
1145 WCHAR *wzFriendlyName, UINT *pcchActual)
1147 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
1151 static HRESULT WINAPI PixelFormatInfo_GetFormatGUID(IWICPixelFormatInfo2 *iface,
1154 FIXME("(%p,%p): stub\n", iface, pFormat);
1158 static HRESULT WINAPI PixelFormatInfo_GetColorContext(IWICPixelFormatInfo2 *iface,
1159 IWICColorContext **ppIColorContext)
1161 FIXME("(%p,%p): stub\n", iface, ppIColorContext);
1165 static HRESULT WINAPI PixelFormatInfo_GetBitsPerPixel(IWICPixelFormatInfo2 *iface,
1166 UINT *puiBitsPerPixel)
1168 FIXME("(%p,%p): stub\n", iface, puiBitsPerPixel);
1172 static HRESULT WINAPI PixelFormatInfo_GetChannelCount(IWICPixelFormatInfo2 *iface,
1173 UINT *puiChannelCount)
1175 FIXME("(%p,%p): stub\n", iface, puiChannelCount);
1179 static HRESULT WINAPI PixelFormatInfo_GetChannelMask(IWICPixelFormatInfo2 *iface,
1180 UINT uiChannelIndex, UINT cbMaskBuffer, BYTE *pbMaskBuffer, UINT *pcbActual)
1182 FIXME("(%p,%u,%u,%p,%p): stub\n", iface, uiChannelIndex, cbMaskBuffer, pbMaskBuffer, pcbActual);
1186 static HRESULT WINAPI PixelFormatInfo_SupportsTransparency(IWICPixelFormatInfo2 *iface,
1187 BOOL *pfSupportsTransparency)
1189 FIXME("(%p,%p): stub\n", iface, pfSupportsTransparency);
1193 static HRESULT WINAPI PixelFormatInfo_GetNumericRepresentation(IWICPixelFormatInfo2 *iface,
1194 WICPixelFormatNumericRepresentation *pNumericRepresentation)
1196 FIXME("(%p,%p): stub\n", iface, pNumericRepresentation);
1200 static const IWICPixelFormatInfo2Vtbl PixelFormatInfo_Vtbl = {
1201 PixelFormatInfo_QueryInterface,
1202 PixelFormatInfo_AddRef,
1203 PixelFormatInfo_Release,
1204 PixelFormatInfo_GetComponentType,
1205 PixelFormatInfo_GetCLSID,
1206 PixelFormatInfo_GetSigningStatus,
1207 PixelFormatInfo_GetAuthor,
1208 PixelFormatInfo_GetVendorGUID,
1209 PixelFormatInfo_GetVersion,
1210 PixelFormatInfo_GetSpecVersion,
1211 PixelFormatInfo_GetFriendlyName,
1212 PixelFormatInfo_GetFormatGUID,
1213 PixelFormatInfo_GetColorContext,
1214 PixelFormatInfo_GetBitsPerPixel,
1215 PixelFormatInfo_GetChannelCount,
1216 PixelFormatInfo_GetChannelMask,
1217 PixelFormatInfo_SupportsTransparency,
1218 PixelFormatInfo_GetNumericRepresentation
1221 static HRESULT PixelFormatInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
1223 PixelFormatInfo *This;
1225 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PixelFormatInfo));
1228 RegCloseKey(classkey);
1229 return E_OUTOFMEMORY;
1232 This->IWICPixelFormatInfo2_iface.lpVtbl = &PixelFormatInfo_Vtbl;
1234 This->classkey = classkey;
1235 memcpy(&This->clsid, clsid, sizeof(CLSID));
1237 *ppIInfo = (IWICComponentInfo*)This;
1241 static const WCHAR clsid_keyname[] = {'C','L','S','I','D',0};
1242 static const WCHAR instance_keyname[] = {'I','n','s','t','a','n','c','e',0};
1245 WICComponentType type;
1247 HRESULT (*constructor)(HKEY,REFCLSID,IWICComponentInfo**);
1250 static const struct category categories[] = {
1251 {WICDecoder, &CATID_WICBitmapDecoders, BitmapDecoderInfo_Constructor},
1252 {WICEncoder, &CATID_WICBitmapEncoders, BitmapEncoderInfo_Constructor},
1253 {WICPixelFormatConverter, &CATID_WICFormatConverters, FormatConverterInfo_Constructor},
1254 {WICPixelFormat, &CATID_WICPixelFormats, PixelFormatInfo_Constructor},
1258 HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo)
1264 WCHAR guidstring[39];
1266 const struct category *category;
1270 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, KEY_READ, &clsidkey);
1271 if (res != ERROR_SUCCESS)
1272 return HRESULT_FROM_WIN32(res);
1274 for (category=categories; category->type; category++)
1276 StringFromGUID2(category->catid, guidstring, 39);
1277 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &catidkey);
1278 if (res == ERROR_SUCCESS)
1280 res = RegOpenKeyExW(catidkey, instance_keyname, 0, KEY_READ, &instancekey);
1281 if (res == ERROR_SUCCESS)
1283 StringFromGUID2(clsid, guidstring, 39);
1284 res = RegOpenKeyExW(instancekey, guidstring, 0, KEY_READ, &classkey);
1285 if (res == ERROR_SUCCESS)
1287 RegCloseKey(classkey);
1290 RegCloseKey(instancekey);
1292 RegCloseKey(catidkey);
1299 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &classkey);
1300 if (res == ERROR_SUCCESS)
1301 hr = category->constructor(classkey, clsid, ppIInfo);
1303 hr = HRESULT_FROM_WIN32(res);
1308 RegCloseKey(clsidkey);
1314 IEnumUnknown IEnumUnknown_iface;
1316 struct list objects;
1317 struct list *cursor;
1318 CRITICAL_SECTION lock; /* Must be held when reading or writing cursor */
1321 static inline ComponentEnum *impl_from_IEnumUnknown(IEnumUnknown *iface)
1323 return CONTAINING_RECORD(iface, ComponentEnum, IEnumUnknown_iface);
1329 } ComponentEnumItem;
1331 static const IEnumUnknownVtbl ComponentEnumVtbl;
1333 static HRESULT WINAPI ComponentEnum_QueryInterface(IEnumUnknown *iface, REFIID iid,
1336 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1337 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
1339 if (!ppv) return E_INVALIDARG;
1341 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IEnumUnknown, iid))
1348 return E_NOINTERFACE;
1351 IUnknown_AddRef((IUnknown*)*ppv);
1355 static ULONG WINAPI ComponentEnum_AddRef(IEnumUnknown *iface)
1357 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1358 ULONG ref = InterlockedIncrement(&This->ref);
1360 TRACE("(%p) refcount=%u\n", iface, ref);
1365 static ULONG WINAPI ComponentEnum_Release(IEnumUnknown *iface)
1367 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1368 ULONG ref = InterlockedDecrement(&This->ref);
1369 ComponentEnumItem *cursor, *cursor2;
1371 TRACE("(%p) refcount=%u\n", iface, ref);
1375 LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->objects, ComponentEnumItem, entry)
1377 IUnknown_Release(cursor->unk);
1378 list_remove(&cursor->entry);
1379 HeapFree(GetProcessHeap(), 0, cursor);
1381 This->lock.DebugInfo->Spare[0] = 0;
1382 DeleteCriticalSection(&This->lock);
1383 HeapFree(GetProcessHeap(), 0, This);
1389 static HRESULT WINAPI ComponentEnum_Next(IEnumUnknown *iface, ULONG celt,
1390 IUnknown **rgelt, ULONG *pceltFetched)
1392 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1394 ComponentEnumItem *item;
1397 TRACE("(%p,%u,%p,%p)\n", iface, celt, rgelt, pceltFetched);
1399 EnterCriticalSection(&This->lock);
1400 while (num_fetched<celt)
1407 item = LIST_ENTRY(This->cursor, ComponentEnumItem, entry);
1408 IUnknown_AddRef(item->unk);
1409 rgelt[num_fetched] = item->unk;
1411 This->cursor = list_next(&This->objects, This->cursor);
1413 LeaveCriticalSection(&This->lock);
1415 *pceltFetched = num_fetched;
1419 static HRESULT WINAPI ComponentEnum_Skip(IEnumUnknown *iface, ULONG celt)
1421 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1425 TRACE("(%p,%u)\n", iface, celt);
1427 EnterCriticalSection(&This->lock);
1428 for (i=0; i<celt; i++)
1435 This->cursor = list_next(&This->objects, This->cursor);
1437 LeaveCriticalSection(&This->lock);
1441 static HRESULT WINAPI ComponentEnum_Reset(IEnumUnknown *iface)
1443 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1445 TRACE("(%p)\n", iface);
1447 EnterCriticalSection(&This->lock);
1448 This->cursor = list_head(&This->objects);
1449 LeaveCriticalSection(&This->lock);
1453 static HRESULT WINAPI ComponentEnum_Clone(IEnumUnknown *iface, IEnumUnknown **ppenum)
1455 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1456 ComponentEnum *new_enum;
1457 ComponentEnumItem *old_item, *new_item;
1459 struct list *old_cursor;
1461 new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnum));
1465 return E_OUTOFMEMORY;
1468 new_enum->IEnumUnknown_iface.lpVtbl = &ComponentEnumVtbl;
1470 new_enum->cursor = NULL;
1471 list_init(&new_enum->objects);
1472 InitializeCriticalSection(&new_enum->lock);
1473 new_enum->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ComponentEnum.lock");
1475 EnterCriticalSection(&This->lock);
1476 old_cursor = This->cursor;
1477 LeaveCriticalSection(&This->lock);
1479 LIST_FOR_EACH_ENTRY(old_item, &This->objects, ComponentEnumItem, entry)
1481 new_item = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnumItem));
1484 ret = E_OUTOFMEMORY;
1487 new_item->unk = old_item->unk;
1488 list_add_tail(&new_enum->objects, &new_item->entry);
1489 IUnknown_AddRef(new_item->unk);
1490 if (&old_item->entry == old_cursor) new_enum->cursor = &new_item->entry;
1495 IUnknown_Release((IUnknown*)new_enum);
1499 *ppenum = (IEnumUnknown*)new_enum;
1504 static const IEnumUnknownVtbl ComponentEnumVtbl = {
1505 ComponentEnum_QueryInterface,
1506 ComponentEnum_AddRef,
1507 ComponentEnum_Release,
1510 ComponentEnum_Reset,
1514 HRESULT CreateComponentEnumerator(DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
1516 ComponentEnum *This;
1517 ComponentEnumItem *item;
1518 const struct category *category;
1519 HKEY clsidkey, catidkey, instancekey;
1520 WCHAR guidstring[39];
1526 if (options) FIXME("ignoring flags %x\n", options);
1528 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, KEY_READ, &clsidkey);
1529 if (res != ERROR_SUCCESS)
1530 return HRESULT_FROM_WIN32(res);
1532 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnum));
1535 RegCloseKey(clsidkey);
1536 return E_OUTOFMEMORY;
1539 This->IEnumUnknown_iface.lpVtbl = &ComponentEnumVtbl;
1541 list_init(&This->objects);
1542 InitializeCriticalSection(&This->lock);
1543 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ComponentEnum.lock");
1545 for (category=categories; category->type && hr == S_OK; category++)
1547 if ((category->type & componentTypes) == 0) continue;
1548 StringFromGUID2(category->catid, guidstring, 39);
1549 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &catidkey);
1550 if (res == ERROR_SUCCESS)
1552 res = RegOpenKeyExW(catidkey, instance_keyname, 0, KEY_READ, &instancekey);
1553 if (res == ERROR_SUCCESS)
1558 DWORD guidstring_size = 39;
1559 res = RegEnumKeyExW(instancekey, i, guidstring, &guidstring_size, NULL, NULL, NULL, NULL);
1560 if (res != ERROR_SUCCESS) break;
1562 item = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnumItem));
1563 if (!item) { hr = E_OUTOFMEMORY; break; }
1565 hr = CLSIDFromString(guidstring, &clsid);
1568 hr = CreateComponentInfo(&clsid, (IWICComponentInfo**)&item->unk);
1570 list_add_tail(&This->objects, &item->entry);
1575 HeapFree(GetProcessHeap(), 0, item);
1579 RegCloseKey(instancekey);
1581 RegCloseKey(catidkey);
1583 if (res != ERROR_SUCCESS && res != ERROR_NO_MORE_ITEMS)
1584 hr = HRESULT_FROM_WIN32(res);
1586 RegCloseKey(clsidkey);
1590 IEnumUnknown_Reset((IEnumUnknown*)This);
1591 *ppIEnumUnknown = (IEnumUnknown*)This;
1595 *ppIEnumUnknown = NULL;
1596 IUnknown_Release((IUnknown*)This);
1602 HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
1605 IEnumUnknown *enumconverters;
1606 IUnknown *unkconverterinfo;
1607 IWICFormatConverterInfo *converterinfo=NULL;
1608 IWICFormatConverter *converter=NULL;
1610 WCHAR srcformatstr[39], dstformatstr[39];
1614 res = IWICBitmapSource_GetPixelFormat(pISrc, &srcFormat);
1615 if (FAILED(res)) return res;
1617 if (IsEqualGUID(&srcFormat, dstFormat))
1619 IWICBitmapSource_AddRef(pISrc);
1624 StringFromGUID2(&srcFormat, srcformatstr, 39);
1625 StringFromGUID2(dstFormat, dstformatstr, 39);
1627 res = CreateComponentEnumerator(WICPixelFormatConverter, 0, &enumconverters);
1628 if (FAILED(res)) return res;
1632 res = IEnumUnknown_Next(enumconverters, 1, &unkconverterinfo, &num_fetched);
1636 res = IUnknown_QueryInterface(unkconverterinfo, &IID_IWICFormatConverterInfo, (void**)&converterinfo);
1640 canconvert = ConverterSupportsFormat(converterinfo, srcformatstr);
1643 canconvert = ConverterSupportsFormat(converterinfo, dstformatstr);
1647 res = IWICFormatConverterInfo_CreateInstance(converterinfo, &converter);
1650 res = IWICFormatConverter_CanConvert(converter, &srcFormat, dstFormat, &canconvert);
1652 if (SUCCEEDED(res) && canconvert)
1653 res = IWICFormatConverter_Initialize(converter, pISrc, dstFormat, WICBitmapDitherTypeNone,
1654 NULL, 0.0, WICBitmapPaletteTypeCustom);
1656 if (FAILED(res) || !canconvert)
1660 IWICFormatConverter_Release(converter);
1667 IWICFormatConverterInfo_Release(converterinfo);
1670 IUnknown_Release(unkconverterinfo);
1676 IEnumUnknown_Release(enumconverters);
1680 *ppIDst = (IWICBitmapSource*)converter;
1685 FIXME("cannot convert %s to %s\n", debugstr_guid(&srcFormat), debugstr_guid(dstFormat));
1687 return WINCODEC_ERR_COMPONENTNOTFOUND;