kernel32: Add more tracing to GetDiskFreeSpaceW.
[wine/multimedia.git] / dlls / windowscodecs / info.c
blobb67eddded2242b10f68773e4580ef72ce565873d
1 /*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
3 * Copyright 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "objbase.h"
30 #include "wincodec.h"
31 #include "wincodecsdk.h"
33 #include "wincodecs_private.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
41 static const WCHAR mimetypes_valuename[] = {'M','i','m','e','T','y','p','e','s',0};
42 static const WCHAR author_valuename[] = {'A','u','t','h','o','r',0};
43 static const WCHAR friendlyname_valuename[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
44 static const WCHAR pixelformats_keyname[] = {'P','i','x','e','l','F','o','r','m','a','t','s',0};
45 static const WCHAR containerformat_valuename[] = {'C','o','n','t','a','i','n','e','r','F','o','r','m','a','t',0};
46 static const WCHAR metadataformat_valuename[] = {'M','e','t','a','d','a','t','a','F','o','r','m','a','t',0};
47 static const WCHAR vendor_valuename[] = {'V','e','n','d','o','r',0};
48 static const WCHAR version_valuename[] = {'V','e','r','s','i','o','n',0};
50 static HRESULT ComponentInfo_GetStringValue(HKEY classkey, LPCWSTR value,
51 UINT buffer_size, WCHAR *buffer, UINT *actual_size)
53 LONG ret;
54 DWORD cbdata=buffer_size * sizeof(WCHAR);
56 if (!actual_size)
57 return E_INVALIDARG;
59 ret = RegGetValueW(classkey, NULL, value, RRF_RT_REG_SZ|RRF_NOEXPAND, NULL,
60 buffer, &cbdata);
62 if (ret == ERROR_FILE_NOT_FOUND)
64 *actual_size = 0;
65 return S_OK;
68 if (ret == 0 || ret == ERROR_MORE_DATA)
69 *actual_size = cbdata/sizeof(WCHAR);
71 if (!buffer && buffer_size != 0)
72 /* Yes, native returns the correct size in this case. */
73 return E_INVALIDARG;
75 if (ret == ERROR_MORE_DATA)
76 return WINCODEC_ERR_INSUFFICIENTBUFFER;
78 return HRESULT_FROM_WIN32(ret);
81 static HRESULT ComponentInfo_GetGUIDValue(HKEY classkey, LPCWSTR value,
82 GUID *result)
84 LONG ret;
85 WCHAR guid_string[39];
86 DWORD cbdata = sizeof(guid_string);
87 HRESULT hr;
89 if (!result)
90 return E_INVALIDARG;
92 ret = RegGetValueW(classkey, NULL, value, RRF_RT_REG_SZ|RRF_NOEXPAND, NULL,
93 guid_string, &cbdata);
95 if (ret != ERROR_SUCCESS)
96 return HRESULT_FROM_WIN32(ret);
98 if (cbdata < sizeof(guid_string))
100 ERR("incomplete GUID value\n");
101 return E_FAIL;
104 hr = CLSIDFromString(guid_string, result);
106 return hr;
109 typedef struct {
110 IWICBitmapDecoderInfo IWICBitmapDecoderInfo_iface;
111 LONG ref;
112 HKEY classkey;
113 CLSID clsid;
114 } BitmapDecoderInfo;
116 static inline BitmapDecoderInfo *impl_from_IWICBitmapDecoderInfo(IWICBitmapDecoderInfo *iface)
118 return CONTAINING_RECORD(iface, BitmapDecoderInfo, IWICBitmapDecoderInfo_iface);
121 static HRESULT WINAPI BitmapDecoderInfo_QueryInterface(IWICBitmapDecoderInfo *iface, REFIID iid,
122 void **ppv)
124 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
125 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
127 if (!ppv) return E_INVALIDARG;
129 if (IsEqualIID(&IID_IUnknown, iid) ||
130 IsEqualIID(&IID_IWICComponentInfo, iid) ||
131 IsEqualIID(&IID_IWICBitmapCodecInfo, iid) ||
132 IsEqualIID(&IID_IWICBitmapDecoderInfo ,iid))
134 *ppv = This;
136 else
138 *ppv = NULL;
139 return E_NOINTERFACE;
142 IUnknown_AddRef((IUnknown*)*ppv);
143 return S_OK;
146 static ULONG WINAPI BitmapDecoderInfo_AddRef(IWICBitmapDecoderInfo *iface)
148 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
149 ULONG ref = InterlockedIncrement(&This->ref);
151 TRACE("(%p) refcount=%u\n", iface, ref);
153 return ref;
156 static ULONG WINAPI BitmapDecoderInfo_Release(IWICBitmapDecoderInfo *iface)
158 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
159 ULONG ref = InterlockedDecrement(&This->ref);
161 TRACE("(%p) refcount=%u\n", iface, ref);
163 if (ref == 0)
165 RegCloseKey(This->classkey);
166 HeapFree(GetProcessHeap(), 0, This);
169 return ref;
172 static HRESULT WINAPI BitmapDecoderInfo_GetComponentType(IWICBitmapDecoderInfo *iface,
173 WICComponentType *pType)
175 TRACE("(%p,%p)\n", iface, pType);
176 if (!pType) return E_INVALIDARG;
177 *pType = WICDecoder;
178 return S_OK;
181 static HRESULT WINAPI BitmapDecoderInfo_GetCLSID(IWICBitmapDecoderInfo *iface, CLSID *pclsid)
183 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
184 TRACE("(%p,%p)\n", iface, pclsid);
186 if (!pclsid)
187 return E_INVALIDARG;
189 memcpy(pclsid, &This->clsid, sizeof(CLSID));
191 return S_OK;
194 static HRESULT WINAPI BitmapDecoderInfo_GetSigningStatus(IWICBitmapDecoderInfo *iface, DWORD *pStatus)
196 FIXME("(%p,%p): stub\n", iface, pStatus);
197 return E_NOTIMPL;
200 static HRESULT WINAPI BitmapDecoderInfo_GetAuthor(IWICBitmapDecoderInfo *iface, UINT cchAuthor,
201 WCHAR *wzAuthor, UINT *pcchActual)
203 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
205 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
207 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
208 cchAuthor, wzAuthor, pcchActual);
211 static HRESULT WINAPI BitmapDecoderInfo_GetVendorGUID(IWICBitmapDecoderInfo *iface, GUID *pguidVendor)
213 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
215 TRACE("(%p,%p)\n", iface, pguidVendor);
217 return ComponentInfo_GetGUIDValue(This->classkey, vendor_valuename, pguidVendor);
220 static HRESULT WINAPI BitmapDecoderInfo_GetVersion(IWICBitmapDecoderInfo *iface, UINT cchVersion,
221 WCHAR *wzVersion, UINT *pcchActual)
223 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
225 TRACE("(%p,%u,%p,%p)\n", iface, cchVersion, wzVersion, pcchActual);
227 return ComponentInfo_GetStringValue(This->classkey, version_valuename,
228 cchVersion, wzVersion, pcchActual);
231 static HRESULT WINAPI BitmapDecoderInfo_GetSpecVersion(IWICBitmapDecoderInfo *iface, UINT cchSpecVersion,
232 WCHAR *wzSpecVersion, UINT *pcchActual)
234 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
235 return E_NOTIMPL;
238 static HRESULT WINAPI BitmapDecoderInfo_GetFriendlyName(IWICBitmapDecoderInfo *iface, UINT cchFriendlyName,
239 WCHAR *wzFriendlyName, UINT *pcchActual)
241 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
243 TRACE("(%p,%u,%p,%p)\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
245 return ComponentInfo_GetStringValue(This->classkey, friendlyname_valuename,
246 cchFriendlyName, wzFriendlyName, pcchActual);
249 static HRESULT WINAPI BitmapDecoderInfo_GetContainerFormat(IWICBitmapDecoderInfo *iface,
250 GUID *pguidContainerFormat)
252 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
253 TRACE("(%p,%p)\n", iface, pguidContainerFormat);
254 return ComponentInfo_GetGUIDValue(This->classkey, containerformat_valuename, pguidContainerFormat);
257 static HRESULT WINAPI BitmapDecoderInfo_GetPixelFormats(IWICBitmapDecoderInfo *iface,
258 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
260 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
261 return E_NOTIMPL;
264 static HRESULT WINAPI BitmapDecoderInfo_GetColorManagementVersion(IWICBitmapDecoderInfo *iface,
265 UINT cchColorManagementVersion, WCHAR *wzColorManagementVersion, UINT *pcchActual)
267 FIXME("(%p,%u,%p,%p): stub\n", iface, cchColorManagementVersion, wzColorManagementVersion, pcchActual);
268 return E_NOTIMPL;
271 static HRESULT WINAPI BitmapDecoderInfo_GetDeviceManufacturer(IWICBitmapDecoderInfo *iface,
272 UINT cchDeviceManufacturer, WCHAR *wzDeviceManufacturer, UINT *pcchActual)
274 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceManufacturer, wzDeviceManufacturer, pcchActual);
275 return E_NOTIMPL;
278 static HRESULT WINAPI BitmapDecoderInfo_GetDeviceModels(IWICBitmapDecoderInfo *iface,
279 UINT cchDeviceModels, WCHAR *wzDeviceModels, UINT *pcchActual)
281 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceModels, wzDeviceModels, pcchActual);
282 return E_NOTIMPL;
285 static HRESULT WINAPI BitmapDecoderInfo_GetMimeTypes(IWICBitmapDecoderInfo *iface,
286 UINT cchMimeTypes, WCHAR *wzMimeTypes, UINT *pcchActual)
288 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
290 TRACE("(%p,%u,%p,%p)\n", iface, cchMimeTypes, wzMimeTypes, pcchActual);
292 return ComponentInfo_GetStringValue(This->classkey, mimetypes_valuename,
293 cchMimeTypes, wzMimeTypes, pcchActual);
296 static HRESULT WINAPI BitmapDecoderInfo_GetFileExtensions(IWICBitmapDecoderInfo *iface,
297 UINT cchFileExtensions, WCHAR *wzFileExtensions, UINT *pcchActual)
299 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFileExtensions, wzFileExtensions, pcchActual);
300 return E_NOTIMPL;
303 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportAnimation(IWICBitmapDecoderInfo *iface,
304 BOOL *pfSupportAnimation)
306 FIXME("(%p,%p): stub\n", iface, pfSupportAnimation);
307 return E_NOTIMPL;
310 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportChromaKey(IWICBitmapDecoderInfo *iface,
311 BOOL *pfSupportChromaKey)
313 FIXME("(%p,%p): stub\n", iface, pfSupportChromaKey);
314 return E_NOTIMPL;
317 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportLossless(IWICBitmapDecoderInfo *iface,
318 BOOL *pfSupportLossless)
320 FIXME("(%p,%p): stub\n", iface, pfSupportLossless);
321 return E_NOTIMPL;
324 static HRESULT WINAPI BitmapDecoderInfo_DoesSupportMultiframe(IWICBitmapDecoderInfo *iface,
325 BOOL *pfSupportMultiframe)
327 FIXME("(%p,%p): stub\n", iface, pfSupportMultiframe);
328 return E_NOTIMPL;
331 static HRESULT WINAPI BitmapDecoderInfo_MatchesMimeType(IWICBitmapDecoderInfo *iface,
332 LPCWSTR wzMimeType, BOOL *pfMatches)
334 FIXME("(%p,%s,%p): stub\n", iface, debugstr_w(wzMimeType), pfMatches);
335 return E_NOTIMPL;
338 static HRESULT WINAPI BitmapDecoderInfo_GetPatterns(IWICBitmapDecoderInfo *iface,
339 UINT cbSizePatterns, WICBitmapPattern *pPatterns, UINT *pcPatterns, UINT *pcbPatternsActual)
341 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
342 UINT pattern_count=0, patterns_size=0;
343 WCHAR subkeyname[11];
344 LONG res;
345 HKEY patternskey, patternkey;
346 static const WCHAR uintformatW[] = {'%','u',0};
347 static const WCHAR patternsW[] = {'P','a','t','t','e','r','n','s',0};
348 static const WCHAR positionW[] = {'P','o','s','i','t','i','o','n',0};
349 static const WCHAR lengthW[] = {'L','e','n','g','t','h',0};
350 static const WCHAR patternW[] = {'P','a','t','t','e','r','n',0};
351 static const WCHAR maskW[] = {'M','a','s','k',0};
352 static const WCHAR endofstreamW[] = {'E','n','d','O','f','S','t','r','e','a','m',0};
353 HRESULT hr=S_OK;
354 UINT i;
355 BYTE *bPatterns=(BYTE*)pPatterns;
356 DWORD length, valuesize;
358 TRACE("(%p,%i,%p,%p,%p)\n", iface, cbSizePatterns, pPatterns, pcPatterns, pcbPatternsActual);
360 res = RegOpenKeyExW(This->classkey, patternsW, 0, KEY_READ, &patternskey);
361 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
363 res = RegQueryInfoKeyW(patternskey, NULL, NULL, NULL, &pattern_count, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
364 if (res == ERROR_SUCCESS)
366 patterns_size = pattern_count * sizeof(WICBitmapPattern);
368 for (i=0; i<pattern_count; i++)
370 snprintfW(subkeyname, 11, uintformatW, i);
371 res = RegOpenKeyExW(patternskey, subkeyname, 0, KEY_READ, &patternkey);
372 if (res == ERROR_SUCCESS)
374 valuesize = sizeof(ULONG);
375 res = RegGetValueW(patternkey, NULL, lengthW, RRF_RT_DWORD, NULL,
376 &length, &valuesize);
377 patterns_size += length*2;
379 if ((cbSizePatterns >= patterns_size) && (res == ERROR_SUCCESS))
381 pPatterns[i].Length = length;
383 pPatterns[i].EndOfStream = 0;
384 valuesize = sizeof(BOOL);
385 RegGetValueW(patternkey, NULL, endofstreamW, RRF_RT_DWORD, NULL,
386 &pPatterns[i].EndOfStream, &valuesize);
388 pPatterns[i].Position.QuadPart = 0;
389 valuesize = sizeof(ULARGE_INTEGER);
390 res = RegGetValueW(patternkey, NULL, positionW, RRF_RT_DWORD|RRF_RT_QWORD, NULL,
391 &pPatterns[i].Position, &valuesize);
393 if (res == ERROR_SUCCESS)
395 pPatterns[i].Pattern = bPatterns+patterns_size-length*2;
396 valuesize = length;
397 res = RegGetValueW(patternkey, NULL, patternW, RRF_RT_REG_BINARY, NULL,
398 pPatterns[i].Pattern, &valuesize);
401 if (res == ERROR_SUCCESS)
403 pPatterns[i].Mask = bPatterns+patterns_size-length;
404 valuesize = length;
405 res = RegGetValueW(patternkey, NULL, maskW, RRF_RT_REG_BINARY, NULL,
406 pPatterns[i].Mask, &valuesize);
410 RegCloseKey(patternkey);
412 if (res != ERROR_SUCCESS)
414 hr = HRESULT_FROM_WIN32(res);
415 break;
419 else hr = HRESULT_FROM_WIN32(res);
421 RegCloseKey(patternskey);
423 if (hr == S_OK)
425 *pcPatterns = pattern_count;
426 *pcbPatternsActual = patterns_size;
427 if (pPatterns && cbSizePatterns < patterns_size)
428 hr = WINCODEC_ERR_INSUFFICIENTBUFFER;
431 return hr;
434 static HRESULT WINAPI BitmapDecoderInfo_MatchesPattern(IWICBitmapDecoderInfo *iface,
435 IStream *pIStream, BOOL *pfMatches)
437 WICBitmapPattern *patterns;
438 UINT pattern_count=0, patterns_size=0;
439 HRESULT hr;
440 int i, pos;
441 BYTE *data=NULL;
442 ULONG datasize=0;
443 ULONG bytesread;
444 LARGE_INTEGER seekpos;
446 TRACE("(%p,%p,%p)\n", iface, pIStream, pfMatches);
448 hr = BitmapDecoderInfo_GetPatterns(iface, 0, NULL, &pattern_count, &patterns_size);
449 if (FAILED(hr)) return hr;
451 patterns = HeapAlloc(GetProcessHeap(), 0, patterns_size);
452 if (!patterns) return E_OUTOFMEMORY;
454 hr = BitmapDecoderInfo_GetPatterns(iface, patterns_size, patterns, &pattern_count, &patterns_size);
455 if (FAILED(hr)) goto end;
457 for (i=0; i<pattern_count; i++)
459 if (datasize < patterns[i].Length)
461 HeapFree(GetProcessHeap(), 0, data);
462 datasize = patterns[i].Length;
463 data = HeapAlloc(GetProcessHeap(), 0, patterns[i].Length);
464 if (!data)
466 hr = E_OUTOFMEMORY;
467 break;
471 if (patterns[i].EndOfStream)
472 seekpos.QuadPart = -patterns[i].Position.QuadPart;
473 else
474 seekpos.QuadPart = patterns[i].Position.QuadPart;
475 hr = IStream_Seek(pIStream, seekpos, patterns[i].EndOfStream ? STREAM_SEEK_END : STREAM_SEEK_SET, NULL);
476 if (hr == STG_E_INVALIDFUNCTION) continue; /* before start of stream */
477 if (FAILED(hr)) break;
479 hr = IStream_Read(pIStream, data, patterns[i].Length, &bytesread);
480 if (hr == S_FALSE || (hr == S_OK && bytesread != patterns[i].Length)) /* past end of stream */
481 continue;
482 if (FAILED(hr)) break;
484 for (pos=0; pos<patterns[i].Length; pos++)
486 if ((data[pos] & patterns[i].Mask[pos]) != patterns[i].Pattern[pos])
487 break;
489 if (pos == patterns[i].Length) /* matches pattern */
491 hr = S_OK;
492 *pfMatches = TRUE;
493 break;
497 if (i == pattern_count) /* does not match any pattern */
499 hr = S_OK;
500 *pfMatches = FALSE;
503 end:
504 HeapFree(GetProcessHeap(), 0, patterns);
505 HeapFree(GetProcessHeap(), 0, data);
507 return hr;
510 static HRESULT WINAPI BitmapDecoderInfo_CreateInstance(IWICBitmapDecoderInfo *iface,
511 IWICBitmapDecoder **ppIBitmapDecoder)
513 BitmapDecoderInfo *This = impl_from_IWICBitmapDecoderInfo(iface);
515 TRACE("(%p,%p)\n", iface, ppIBitmapDecoder);
517 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
518 &IID_IWICBitmapDecoder, (void**)ppIBitmapDecoder);
521 static const IWICBitmapDecoderInfoVtbl BitmapDecoderInfo_Vtbl = {
522 BitmapDecoderInfo_QueryInterface,
523 BitmapDecoderInfo_AddRef,
524 BitmapDecoderInfo_Release,
525 BitmapDecoderInfo_GetComponentType,
526 BitmapDecoderInfo_GetCLSID,
527 BitmapDecoderInfo_GetSigningStatus,
528 BitmapDecoderInfo_GetAuthor,
529 BitmapDecoderInfo_GetVendorGUID,
530 BitmapDecoderInfo_GetVersion,
531 BitmapDecoderInfo_GetSpecVersion,
532 BitmapDecoderInfo_GetFriendlyName,
533 BitmapDecoderInfo_GetContainerFormat,
534 BitmapDecoderInfo_GetPixelFormats,
535 BitmapDecoderInfo_GetColorManagementVersion,
536 BitmapDecoderInfo_GetDeviceManufacturer,
537 BitmapDecoderInfo_GetDeviceModels,
538 BitmapDecoderInfo_GetMimeTypes,
539 BitmapDecoderInfo_GetFileExtensions,
540 BitmapDecoderInfo_DoesSupportAnimation,
541 BitmapDecoderInfo_DoesSupportChromaKey,
542 BitmapDecoderInfo_DoesSupportLossless,
543 BitmapDecoderInfo_DoesSupportMultiframe,
544 BitmapDecoderInfo_MatchesMimeType,
545 BitmapDecoderInfo_GetPatterns,
546 BitmapDecoderInfo_MatchesPattern,
547 BitmapDecoderInfo_CreateInstance
550 static HRESULT BitmapDecoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
552 BitmapDecoderInfo *This;
554 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapDecoderInfo));
555 if (!This)
557 RegCloseKey(classkey);
558 return E_OUTOFMEMORY;
561 This->IWICBitmapDecoderInfo_iface.lpVtbl = &BitmapDecoderInfo_Vtbl;
562 This->ref = 1;
563 This->classkey = classkey;
564 memcpy(&This->clsid, clsid, sizeof(CLSID));
566 *ppIInfo = (IWICComponentInfo*)This;
567 return S_OK;
570 typedef struct {
571 IWICBitmapEncoderInfo IWICBitmapEncoderInfo_iface;
572 LONG ref;
573 HKEY classkey;
574 CLSID clsid;
575 } BitmapEncoderInfo;
577 static inline BitmapEncoderInfo *impl_from_IWICBitmapEncoderInfo(IWICBitmapEncoderInfo *iface)
579 return CONTAINING_RECORD(iface, BitmapEncoderInfo, IWICBitmapEncoderInfo_iface);
582 static HRESULT WINAPI BitmapEncoderInfo_QueryInterface(IWICBitmapEncoderInfo *iface, REFIID iid,
583 void **ppv)
585 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
586 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
588 if (!ppv) return E_INVALIDARG;
590 if (IsEqualIID(&IID_IUnknown, iid) ||
591 IsEqualIID(&IID_IWICComponentInfo, iid) ||
592 IsEqualIID(&IID_IWICBitmapCodecInfo, iid) ||
593 IsEqualIID(&IID_IWICBitmapEncoderInfo ,iid))
595 *ppv = This;
597 else
599 *ppv = NULL;
600 return E_NOINTERFACE;
603 IUnknown_AddRef((IUnknown*)*ppv);
604 return S_OK;
607 static ULONG WINAPI BitmapEncoderInfo_AddRef(IWICBitmapEncoderInfo *iface)
609 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
610 ULONG ref = InterlockedIncrement(&This->ref);
612 TRACE("(%p) refcount=%u\n", iface, ref);
614 return ref;
617 static ULONG WINAPI BitmapEncoderInfo_Release(IWICBitmapEncoderInfo *iface)
619 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
620 ULONG ref = InterlockedDecrement(&This->ref);
622 TRACE("(%p) refcount=%u\n", iface, ref);
624 if (ref == 0)
626 RegCloseKey(This->classkey);
627 HeapFree(GetProcessHeap(), 0, This);
630 return ref;
633 static HRESULT WINAPI BitmapEncoderInfo_GetComponentType(IWICBitmapEncoderInfo *iface,
634 WICComponentType *pType)
636 TRACE("(%p,%p)\n", iface, pType);
637 if (!pType) return E_INVALIDARG;
638 *pType = WICEncoder;
639 return S_OK;
642 static HRESULT WINAPI BitmapEncoderInfo_GetCLSID(IWICBitmapEncoderInfo *iface, CLSID *pclsid)
644 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
645 TRACE("(%p,%p)\n", iface, pclsid);
647 if (!pclsid)
648 return E_INVALIDARG;
650 memcpy(pclsid, &This->clsid, sizeof(CLSID));
652 return S_OK;
655 static HRESULT WINAPI BitmapEncoderInfo_GetSigningStatus(IWICBitmapEncoderInfo *iface, DWORD *pStatus)
657 FIXME("(%p,%p): stub\n", iface, pStatus);
658 return E_NOTIMPL;
661 static HRESULT WINAPI BitmapEncoderInfo_GetAuthor(IWICBitmapEncoderInfo *iface, UINT cchAuthor,
662 WCHAR *wzAuthor, UINT *pcchActual)
664 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
666 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
668 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
669 cchAuthor, wzAuthor, pcchActual);
672 static HRESULT WINAPI BitmapEncoderInfo_GetVendorGUID(IWICBitmapEncoderInfo *iface, GUID *pguidVendor)
674 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
676 TRACE("(%p,%p)\n", iface, pguidVendor);
678 return ComponentInfo_GetGUIDValue(This->classkey, vendor_valuename, pguidVendor);
681 static HRESULT WINAPI BitmapEncoderInfo_GetVersion(IWICBitmapEncoderInfo *iface, UINT cchVersion,
682 WCHAR *wzVersion, UINT *pcchActual)
684 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
686 TRACE("(%p,%u,%p,%p)\n", iface, cchVersion, wzVersion, pcchActual);
688 return ComponentInfo_GetStringValue(This->classkey, version_valuename,
689 cchVersion, wzVersion, pcchActual);
692 static HRESULT WINAPI BitmapEncoderInfo_GetSpecVersion(IWICBitmapEncoderInfo *iface, UINT cchSpecVersion,
693 WCHAR *wzSpecVersion, UINT *pcchActual)
695 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
696 return E_NOTIMPL;
699 static HRESULT WINAPI BitmapEncoderInfo_GetFriendlyName(IWICBitmapEncoderInfo *iface, UINT cchFriendlyName,
700 WCHAR *wzFriendlyName, UINT *pcchActual)
702 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
704 TRACE("(%p,%u,%p,%p)\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
706 return ComponentInfo_GetStringValue(This->classkey, friendlyname_valuename,
707 cchFriendlyName, wzFriendlyName, pcchActual);
710 static HRESULT WINAPI BitmapEncoderInfo_GetContainerFormat(IWICBitmapEncoderInfo *iface,
711 GUID *pguidContainerFormat)
713 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
714 TRACE("(%p,%p)\n", iface, pguidContainerFormat);
715 return ComponentInfo_GetGUIDValue(This->classkey, containerformat_valuename, pguidContainerFormat);
718 static HRESULT WINAPI BitmapEncoderInfo_GetPixelFormats(IWICBitmapEncoderInfo *iface,
719 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
721 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
722 return E_NOTIMPL;
725 static HRESULT WINAPI BitmapEncoderInfo_GetColorManagementVersion(IWICBitmapEncoderInfo *iface,
726 UINT cchColorManagementVersion, WCHAR *wzColorManagementVersion, UINT *pcchActual)
728 FIXME("(%p,%u,%p,%p): stub\n", iface, cchColorManagementVersion, wzColorManagementVersion, pcchActual);
729 return E_NOTIMPL;
732 static HRESULT WINAPI BitmapEncoderInfo_GetDeviceManufacturer(IWICBitmapEncoderInfo *iface,
733 UINT cchDeviceManufacturer, WCHAR *wzDeviceManufacturer, UINT *pcchActual)
735 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceManufacturer, wzDeviceManufacturer, pcchActual);
736 return E_NOTIMPL;
739 static HRESULT WINAPI BitmapEncoderInfo_GetDeviceModels(IWICBitmapEncoderInfo *iface,
740 UINT cchDeviceModels, WCHAR *wzDeviceModels, UINT *pcchActual)
742 FIXME("(%p,%u,%p,%p): stub\n", iface, cchDeviceModels, wzDeviceModels, pcchActual);
743 return E_NOTIMPL;
746 static HRESULT WINAPI BitmapEncoderInfo_GetMimeTypes(IWICBitmapEncoderInfo *iface,
747 UINT cchMimeTypes, WCHAR *wzMimeTypes, UINT *pcchActual)
749 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
751 TRACE("(%p,%u,%p,%p)\n", iface, cchMimeTypes, wzMimeTypes, pcchActual);
753 return ComponentInfo_GetStringValue(This->classkey, mimetypes_valuename,
754 cchMimeTypes, wzMimeTypes, pcchActual);
757 static HRESULT WINAPI BitmapEncoderInfo_GetFileExtensions(IWICBitmapEncoderInfo *iface,
758 UINT cchFileExtensions, WCHAR *wzFileExtensions, UINT *pcchActual)
760 FIXME("(%p,%u,%p,%p): stub\n", iface, cchFileExtensions, wzFileExtensions, pcchActual);
761 return E_NOTIMPL;
764 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportAnimation(IWICBitmapEncoderInfo *iface,
765 BOOL *pfSupportAnimation)
767 FIXME("(%p,%p): stub\n", iface, pfSupportAnimation);
768 return E_NOTIMPL;
771 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportChromaKey(IWICBitmapEncoderInfo *iface,
772 BOOL *pfSupportChromaKey)
774 FIXME("(%p,%p): stub\n", iface, pfSupportChromaKey);
775 return E_NOTIMPL;
778 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportLossless(IWICBitmapEncoderInfo *iface,
779 BOOL *pfSupportLossless)
781 FIXME("(%p,%p): stub\n", iface, pfSupportLossless);
782 return E_NOTIMPL;
785 static HRESULT WINAPI BitmapEncoderInfo_DoesSupportMultiframe(IWICBitmapEncoderInfo *iface,
786 BOOL *pfSupportMultiframe)
788 FIXME("(%p,%p): stub\n", iface, pfSupportMultiframe);
789 return E_NOTIMPL;
792 static HRESULT WINAPI BitmapEncoderInfo_MatchesMimeType(IWICBitmapEncoderInfo *iface,
793 LPCWSTR wzMimeType, BOOL *pfMatches)
795 FIXME("(%p,%s,%p): stub\n", iface, debugstr_w(wzMimeType), pfMatches);
796 return E_NOTIMPL;
799 static HRESULT WINAPI BitmapEncoderInfo_CreateInstance(IWICBitmapEncoderInfo *iface,
800 IWICBitmapEncoder **ppIBitmapEncoder)
802 BitmapEncoderInfo *This = impl_from_IWICBitmapEncoderInfo(iface);
804 TRACE("(%p,%p)\n", iface, ppIBitmapEncoder);
806 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
807 &IID_IWICBitmapEncoder, (void**)ppIBitmapEncoder);
810 static const IWICBitmapEncoderInfoVtbl BitmapEncoderInfo_Vtbl = {
811 BitmapEncoderInfo_QueryInterface,
812 BitmapEncoderInfo_AddRef,
813 BitmapEncoderInfo_Release,
814 BitmapEncoderInfo_GetComponentType,
815 BitmapEncoderInfo_GetCLSID,
816 BitmapEncoderInfo_GetSigningStatus,
817 BitmapEncoderInfo_GetAuthor,
818 BitmapEncoderInfo_GetVendorGUID,
819 BitmapEncoderInfo_GetVersion,
820 BitmapEncoderInfo_GetSpecVersion,
821 BitmapEncoderInfo_GetFriendlyName,
822 BitmapEncoderInfo_GetContainerFormat,
823 BitmapEncoderInfo_GetPixelFormats,
824 BitmapEncoderInfo_GetColorManagementVersion,
825 BitmapEncoderInfo_GetDeviceManufacturer,
826 BitmapEncoderInfo_GetDeviceModels,
827 BitmapEncoderInfo_GetMimeTypes,
828 BitmapEncoderInfo_GetFileExtensions,
829 BitmapEncoderInfo_DoesSupportAnimation,
830 BitmapEncoderInfo_DoesSupportChromaKey,
831 BitmapEncoderInfo_DoesSupportLossless,
832 BitmapEncoderInfo_DoesSupportMultiframe,
833 BitmapEncoderInfo_MatchesMimeType,
834 BitmapEncoderInfo_CreateInstance
837 static HRESULT BitmapEncoderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
839 BitmapEncoderInfo *This;
841 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapEncoderInfo));
842 if (!This)
844 RegCloseKey(classkey);
845 return E_OUTOFMEMORY;
848 This->IWICBitmapEncoderInfo_iface.lpVtbl = &BitmapEncoderInfo_Vtbl;
849 This->ref = 1;
850 This->classkey = classkey;
851 memcpy(&This->clsid, clsid, sizeof(CLSID));
853 *ppIInfo = (IWICComponentInfo*)This;
854 return S_OK;
857 typedef struct {
858 IWICFormatConverterInfo IWICFormatConverterInfo_iface;
859 LONG ref;
860 HKEY classkey;
861 CLSID clsid;
862 } FormatConverterInfo;
864 static inline FormatConverterInfo *impl_from_IWICFormatConverterInfo(IWICFormatConverterInfo *iface)
866 return CONTAINING_RECORD(iface, FormatConverterInfo, IWICFormatConverterInfo_iface);
869 static HRESULT WINAPI FormatConverterInfo_QueryInterface(IWICFormatConverterInfo *iface, REFIID iid,
870 void **ppv)
872 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
873 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
875 if (!ppv) return E_INVALIDARG;
877 if (IsEqualIID(&IID_IUnknown, iid) ||
878 IsEqualIID(&IID_IWICComponentInfo, iid) ||
879 IsEqualIID(&IID_IWICFormatConverterInfo ,iid))
881 *ppv = This;
883 else
885 *ppv = NULL;
886 return E_NOINTERFACE;
889 IUnknown_AddRef((IUnknown*)*ppv);
890 return S_OK;
893 static ULONG WINAPI FormatConverterInfo_AddRef(IWICFormatConverterInfo *iface)
895 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
896 ULONG ref = InterlockedIncrement(&This->ref);
898 TRACE("(%p) refcount=%u\n", iface, ref);
900 return ref;
903 static ULONG WINAPI FormatConverterInfo_Release(IWICFormatConverterInfo *iface)
905 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
906 ULONG ref = InterlockedDecrement(&This->ref);
908 TRACE("(%p) refcount=%u\n", iface, ref);
910 if (ref == 0)
912 RegCloseKey(This->classkey);
913 HeapFree(GetProcessHeap(), 0, This);
916 return ref;
919 static HRESULT WINAPI FormatConverterInfo_GetComponentType(IWICFormatConverterInfo *iface,
920 WICComponentType *pType)
922 TRACE("(%p,%p)\n", iface, pType);
923 if (!pType) return E_INVALIDARG;
924 *pType = WICPixelFormatConverter;
925 return S_OK;
928 static HRESULT WINAPI FormatConverterInfo_GetCLSID(IWICFormatConverterInfo *iface, CLSID *pclsid)
930 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
931 TRACE("(%p,%p)\n", iface, pclsid);
933 if (!pclsid)
934 return E_INVALIDARG;
936 memcpy(pclsid, &This->clsid, sizeof(CLSID));
938 return S_OK;
941 static HRESULT WINAPI FormatConverterInfo_GetSigningStatus(IWICFormatConverterInfo *iface, DWORD *pStatus)
943 FIXME("(%p,%p): stub\n", iface, pStatus);
944 return E_NOTIMPL;
947 static HRESULT WINAPI FormatConverterInfo_GetAuthor(IWICFormatConverterInfo *iface, UINT cchAuthor,
948 WCHAR *wzAuthor, UINT *pcchActual)
950 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
952 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
954 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
955 cchAuthor, wzAuthor, pcchActual);
958 static HRESULT WINAPI FormatConverterInfo_GetVendorGUID(IWICFormatConverterInfo *iface, GUID *pguidVendor)
960 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
962 TRACE("(%p,%p)\n", iface, pguidVendor);
964 return ComponentInfo_GetGUIDValue(This->classkey, vendor_valuename, pguidVendor);
967 static HRESULT WINAPI FormatConverterInfo_GetVersion(IWICFormatConverterInfo *iface, UINT cchVersion,
968 WCHAR *wzVersion, UINT *pcchActual)
970 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
972 TRACE("(%p,%u,%p,%p)\n", iface, cchVersion, wzVersion, pcchActual);
974 return ComponentInfo_GetStringValue(This->classkey, version_valuename,
975 cchVersion, wzVersion, pcchActual);
978 static HRESULT WINAPI FormatConverterInfo_GetSpecVersion(IWICFormatConverterInfo *iface, UINT cchSpecVersion,
979 WCHAR *wzSpecVersion, UINT *pcchActual)
981 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
982 return E_NOTIMPL;
985 static HRESULT WINAPI FormatConverterInfo_GetFriendlyName(IWICFormatConverterInfo *iface, UINT cchFriendlyName,
986 WCHAR *wzFriendlyName, UINT *pcchActual)
988 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
990 TRACE("(%p,%u,%p,%p)\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
992 return ComponentInfo_GetStringValue(This->classkey, friendlyname_valuename,
993 cchFriendlyName, wzFriendlyName, pcchActual);
996 static HRESULT WINAPI FormatConverterInfo_GetPixelFormats(IWICFormatConverterInfo *iface,
997 UINT cFormats, GUID *pguidPixelFormats, UINT *pcActual)
999 FIXME("(%p,%u,%p,%p): stub\n", iface, cFormats, pguidPixelFormats, pcActual);
1000 return E_NOTIMPL;
1003 static HRESULT WINAPI FormatConverterInfo_CreateInstance(IWICFormatConverterInfo *iface,
1004 IWICFormatConverter **ppIFormatConverter)
1006 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
1008 TRACE("(%p,%p)\n", iface, ppIFormatConverter);
1010 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
1011 &IID_IWICFormatConverter, (void**)ppIFormatConverter);
1014 static BOOL ConverterSupportsFormat(IWICFormatConverterInfo *iface, const WCHAR *formatguid)
1016 LONG res;
1017 FormatConverterInfo *This = impl_from_IWICFormatConverterInfo(iface);
1018 HKEY formats_key, guid_key;
1020 /* Avoid testing using IWICFormatConverter_GetPixelFormats because that
1021 would be O(n). A registry test should do better. */
1023 res = RegOpenKeyExW(This->classkey, pixelformats_keyname, 0, KEY_READ, &formats_key);
1024 if (res != ERROR_SUCCESS) return FALSE;
1026 res = RegOpenKeyExW(formats_key, formatguid, 0, KEY_READ, &guid_key);
1027 if (res == ERROR_SUCCESS) RegCloseKey(guid_key);
1029 RegCloseKey(formats_key);
1031 return (res == ERROR_SUCCESS);
1034 static const IWICFormatConverterInfoVtbl FormatConverterInfo_Vtbl = {
1035 FormatConverterInfo_QueryInterface,
1036 FormatConverterInfo_AddRef,
1037 FormatConverterInfo_Release,
1038 FormatConverterInfo_GetComponentType,
1039 FormatConverterInfo_GetCLSID,
1040 FormatConverterInfo_GetSigningStatus,
1041 FormatConverterInfo_GetAuthor,
1042 FormatConverterInfo_GetVendorGUID,
1043 FormatConverterInfo_GetVersion,
1044 FormatConverterInfo_GetSpecVersion,
1045 FormatConverterInfo_GetFriendlyName,
1046 FormatConverterInfo_GetPixelFormats,
1047 FormatConverterInfo_CreateInstance
1050 static HRESULT FormatConverterInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
1052 FormatConverterInfo *This;
1054 This = HeapAlloc(GetProcessHeap(), 0, sizeof(FormatConverterInfo));
1055 if (!This)
1057 RegCloseKey(classkey);
1058 return E_OUTOFMEMORY;
1061 This->IWICFormatConverterInfo_iface.lpVtbl = &FormatConverterInfo_Vtbl;
1062 This->ref = 1;
1063 This->classkey = classkey;
1064 memcpy(&This->clsid, clsid, sizeof(CLSID));
1066 *ppIInfo = (IWICComponentInfo*)This;
1067 return S_OK;
1070 typedef struct {
1071 IWICPixelFormatInfo2 IWICPixelFormatInfo2_iface;
1072 LONG ref;
1073 HKEY classkey;
1074 CLSID clsid;
1075 } PixelFormatInfo;
1077 static inline PixelFormatInfo *impl_from_IWICPixelFormatInfo2(IWICPixelFormatInfo2 *iface)
1079 return CONTAINING_RECORD(iface, PixelFormatInfo, IWICPixelFormatInfo2_iface);
1082 static HRESULT WINAPI PixelFormatInfo_QueryInterface(IWICPixelFormatInfo2 *iface, REFIID iid,
1083 void **ppv)
1085 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1086 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
1088 if (!ppv) return E_INVALIDARG;
1090 if (IsEqualIID(&IID_IUnknown, iid) ||
1091 IsEqualIID(&IID_IWICComponentInfo, iid) ||
1092 IsEqualIID(&IID_IWICPixelFormatInfo, iid) ||
1093 IsEqualIID(&IID_IWICPixelFormatInfo2 ,iid))
1095 *ppv = This;
1097 else
1099 *ppv = NULL;
1100 return E_NOINTERFACE;
1103 IUnknown_AddRef((IUnknown*)*ppv);
1104 return S_OK;
1107 static ULONG WINAPI PixelFormatInfo_AddRef(IWICPixelFormatInfo2 *iface)
1109 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1110 ULONG ref = InterlockedIncrement(&This->ref);
1112 TRACE("(%p) refcount=%u\n", iface, ref);
1114 return ref;
1117 static ULONG WINAPI PixelFormatInfo_Release(IWICPixelFormatInfo2 *iface)
1119 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1120 ULONG ref = InterlockedDecrement(&This->ref);
1122 TRACE("(%p) refcount=%u\n", iface, ref);
1124 if (ref == 0)
1126 RegCloseKey(This->classkey);
1127 HeapFree(GetProcessHeap(), 0, This);
1130 return ref;
1133 static HRESULT WINAPI PixelFormatInfo_GetComponentType(IWICPixelFormatInfo2 *iface,
1134 WICComponentType *pType)
1136 TRACE("(%p,%p)\n", iface, pType);
1137 if (!pType) return E_INVALIDARG;
1138 *pType = WICPixelFormat;
1139 return S_OK;
1142 static HRESULT WINAPI PixelFormatInfo_GetCLSID(IWICPixelFormatInfo2 *iface, CLSID *pclsid)
1144 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1145 TRACE("(%p,%p)\n", iface, pclsid);
1147 if (!pclsid)
1148 return E_INVALIDARG;
1150 memcpy(pclsid, &This->clsid, sizeof(CLSID));
1152 return S_OK;
1155 static HRESULT WINAPI PixelFormatInfo_GetSigningStatus(IWICPixelFormatInfo2 *iface, DWORD *pStatus)
1157 TRACE("(%p,%p)\n", iface, pStatus);
1159 if (!pStatus)
1160 return E_INVALIDARG;
1162 /* Pixel formats don't require code, so they are considered signed. */
1163 *pStatus = WICComponentSigned;
1165 return S_OK;
1168 static HRESULT WINAPI PixelFormatInfo_GetAuthor(IWICPixelFormatInfo2 *iface, UINT cchAuthor,
1169 WCHAR *wzAuthor, UINT *pcchActual)
1171 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1173 TRACE("(%p,%u,%p,%p)\n", iface, cchAuthor, wzAuthor, pcchActual);
1175 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
1176 cchAuthor, wzAuthor, pcchActual);
1179 static HRESULT WINAPI PixelFormatInfo_GetVendorGUID(IWICPixelFormatInfo2 *iface, GUID *pguidVendor)
1181 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1183 TRACE("(%p,%p)\n", iface, pguidVendor);
1185 return ComponentInfo_GetGUIDValue(This->classkey, vendor_valuename, pguidVendor);
1188 static HRESULT WINAPI PixelFormatInfo_GetVersion(IWICPixelFormatInfo2 *iface, UINT cchVersion,
1189 WCHAR *wzVersion, UINT *pcchActual)
1191 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1193 TRACE("(%p,%u,%p,%p)\n", iface, cchVersion, wzVersion, pcchActual);
1195 return ComponentInfo_GetStringValue(This->classkey, version_valuename,
1196 cchVersion, wzVersion, pcchActual);
1199 static HRESULT WINAPI PixelFormatInfo_GetSpecVersion(IWICPixelFormatInfo2 *iface, UINT cchSpecVersion,
1200 WCHAR *wzSpecVersion, UINT *pcchActual)
1202 FIXME("(%p,%u,%p,%p): stub\n", iface, cchSpecVersion, wzSpecVersion, pcchActual);
1203 return E_NOTIMPL;
1206 static HRESULT WINAPI PixelFormatInfo_GetFriendlyName(IWICPixelFormatInfo2 *iface, UINT cchFriendlyName,
1207 WCHAR *wzFriendlyName, UINT *pcchActual)
1209 PixelFormatInfo *This = impl_from_IWICPixelFormatInfo2(iface);
1211 TRACE("(%p,%u,%p,%p)\n", iface, cchFriendlyName, wzFriendlyName, pcchActual);
1213 return ComponentInfo_GetStringValue(This->classkey, friendlyname_valuename,
1214 cchFriendlyName, wzFriendlyName, pcchActual);
1217 static HRESULT WINAPI PixelFormatInfo_GetFormatGUID(IWICPixelFormatInfo2 *iface,
1218 GUID *pFormat)
1220 FIXME("(%p,%p): stub\n", iface, pFormat);
1221 return E_NOTIMPL;
1224 static HRESULT WINAPI PixelFormatInfo_GetColorContext(IWICPixelFormatInfo2 *iface,
1225 IWICColorContext **ppIColorContext)
1227 FIXME("(%p,%p): stub\n", iface, ppIColorContext);
1228 return E_NOTIMPL;
1231 static HRESULT WINAPI PixelFormatInfo_GetBitsPerPixel(IWICPixelFormatInfo2 *iface,
1232 UINT *puiBitsPerPixel)
1234 FIXME("(%p,%p): stub\n", iface, puiBitsPerPixel);
1235 return E_NOTIMPL;
1238 static HRESULT WINAPI PixelFormatInfo_GetChannelCount(IWICPixelFormatInfo2 *iface,
1239 UINT *puiChannelCount)
1241 FIXME("(%p,%p): stub\n", iface, puiChannelCount);
1242 return E_NOTIMPL;
1245 static HRESULT WINAPI PixelFormatInfo_GetChannelMask(IWICPixelFormatInfo2 *iface,
1246 UINT uiChannelIndex, UINT cbMaskBuffer, BYTE *pbMaskBuffer, UINT *pcbActual)
1248 FIXME("(%p,%u,%u,%p,%p): stub\n", iface, uiChannelIndex, cbMaskBuffer, pbMaskBuffer, pcbActual);
1249 return E_NOTIMPL;
1252 static HRESULT WINAPI PixelFormatInfo_SupportsTransparency(IWICPixelFormatInfo2 *iface,
1253 BOOL *pfSupportsTransparency)
1255 FIXME("(%p,%p): stub\n", iface, pfSupportsTransparency);
1256 return E_NOTIMPL;
1259 static HRESULT WINAPI PixelFormatInfo_GetNumericRepresentation(IWICPixelFormatInfo2 *iface,
1260 WICPixelFormatNumericRepresentation *pNumericRepresentation)
1262 FIXME("(%p,%p): stub\n", iface, pNumericRepresentation);
1263 return E_NOTIMPL;
1266 static const IWICPixelFormatInfo2Vtbl PixelFormatInfo_Vtbl = {
1267 PixelFormatInfo_QueryInterface,
1268 PixelFormatInfo_AddRef,
1269 PixelFormatInfo_Release,
1270 PixelFormatInfo_GetComponentType,
1271 PixelFormatInfo_GetCLSID,
1272 PixelFormatInfo_GetSigningStatus,
1273 PixelFormatInfo_GetAuthor,
1274 PixelFormatInfo_GetVendorGUID,
1275 PixelFormatInfo_GetVersion,
1276 PixelFormatInfo_GetSpecVersion,
1277 PixelFormatInfo_GetFriendlyName,
1278 PixelFormatInfo_GetFormatGUID,
1279 PixelFormatInfo_GetColorContext,
1280 PixelFormatInfo_GetBitsPerPixel,
1281 PixelFormatInfo_GetChannelCount,
1282 PixelFormatInfo_GetChannelMask,
1283 PixelFormatInfo_SupportsTransparency,
1284 PixelFormatInfo_GetNumericRepresentation
1287 static HRESULT PixelFormatInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **ppIInfo)
1289 PixelFormatInfo *This;
1291 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PixelFormatInfo));
1292 if (!This)
1294 RegCloseKey(classkey);
1295 return E_OUTOFMEMORY;
1298 This->IWICPixelFormatInfo2_iface.lpVtbl = &PixelFormatInfo_Vtbl;
1299 This->ref = 1;
1300 This->classkey = classkey;
1301 memcpy(&This->clsid, clsid, sizeof(CLSID));
1303 *ppIInfo = (IWICComponentInfo*)This;
1304 return S_OK;
1307 typedef struct
1309 IWICMetadataReaderInfo IWICMetadataReaderInfo_iface;
1310 LONG ref;
1311 HKEY classkey;
1312 CLSID clsid;
1313 } MetadataReaderInfo;
1315 static inline MetadataReaderInfo *impl_from_IWICMetadataReaderInfo(IWICMetadataReaderInfo *iface)
1317 return CONTAINING_RECORD(iface, MetadataReaderInfo, IWICMetadataReaderInfo_iface);
1320 static HRESULT WINAPI MetadataReaderInfo_QueryInterface(IWICMetadataReaderInfo *iface,
1321 REFIID riid, void **ppv)
1323 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1325 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppv);
1327 if (!ppv) return E_INVALIDARG;
1329 if (IsEqualIID(&IID_IUnknown, riid) ||
1330 IsEqualIID(&IID_IWICComponentInfo, riid) ||
1331 IsEqualIID(&IID_IWICMetadataHandlerInfo, riid) ||
1332 IsEqualIID(&IID_IWICMetadataReaderInfo, riid))
1334 *ppv = This;
1336 else
1338 *ppv = NULL;
1339 return E_NOINTERFACE;
1342 IUnknown_AddRef((IUnknown *)*ppv);
1343 return S_OK;
1346 static ULONG WINAPI MetadataReaderInfo_AddRef(IWICMetadataReaderInfo *iface)
1348 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1349 ULONG ref = InterlockedIncrement(&This->ref);
1351 TRACE("(%p) refcount=%u\n", iface, ref);
1352 return ref;
1355 static ULONG WINAPI MetadataReaderInfo_Release(IWICMetadataReaderInfo *iface)
1357 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1358 ULONG ref = InterlockedDecrement(&This->ref);
1360 TRACE("(%p) refcount=%u\n", iface, ref);
1362 if (!ref)
1364 RegCloseKey(This->classkey);
1365 HeapFree(GetProcessHeap(), 0, This);
1367 return ref;
1370 static HRESULT WINAPI MetadataReaderInfo_GetComponentType(IWICMetadataReaderInfo *iface,
1371 WICComponentType *type)
1373 TRACE("(%p,%p)\n", iface, type);
1375 if (!type) return E_INVALIDARG;
1376 *type = WICMetadataReader;
1377 return S_OK;
1380 static HRESULT WINAPI MetadataReaderInfo_GetCLSID(IWICMetadataReaderInfo *iface,
1381 CLSID *clsid)
1383 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1385 TRACE("(%p,%p)\n", iface, clsid);
1387 if (!clsid) return E_INVALIDARG;
1388 *clsid = This->clsid;
1389 return S_OK;
1392 static HRESULT WINAPI MetadataReaderInfo_GetSigningStatus(IWICMetadataReaderInfo *iface,
1393 DWORD *status)
1395 FIXME("(%p,%p): stub\n", iface, status);
1396 return E_NOTIMPL;
1399 static HRESULT WINAPI MetadataReaderInfo_GetAuthor(IWICMetadataReaderInfo *iface,
1400 UINT length, WCHAR *author, UINT *actual_length)
1402 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1404 TRACE("(%p,%u,%p,%p)\n", iface, length, author, actual_length);
1406 return ComponentInfo_GetStringValue(This->classkey, author_valuename,
1407 length, author, actual_length);
1410 static HRESULT WINAPI MetadataReaderInfo_GetVendorGUID(IWICMetadataReaderInfo *iface,
1411 GUID *vendor)
1413 FIXME("(%p,%p): stub\n", iface, vendor);
1414 return E_NOTIMPL;
1417 static HRESULT WINAPI MetadataReaderInfo_GetVersion(IWICMetadataReaderInfo *iface,
1418 UINT length, WCHAR *version, UINT *actual_length)
1420 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1422 TRACE("(%p,%u,%p,%p)\n", iface, length, version, actual_length);
1424 return ComponentInfo_GetStringValue(This->classkey, version_valuename,
1425 length, version, actual_length);
1428 static HRESULT WINAPI MetadataReaderInfo_GetSpecVersion(IWICMetadataReaderInfo *iface,
1429 UINT length, WCHAR *version, UINT *actual_length)
1431 FIXME("(%p,%u,%p,%p): stub\n", iface, length, version, actual_length);
1432 return E_NOTIMPL;
1435 static HRESULT WINAPI MetadataReaderInfo_GetFriendlyName(IWICMetadataReaderInfo *iface,
1436 UINT length, WCHAR *name, UINT *actual_length)
1438 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1440 TRACE("(%p,%u,%p,%p)\n", iface, length, name, actual_length);
1442 return ComponentInfo_GetStringValue(This->classkey, friendlyname_valuename,
1443 length, name, actual_length);
1446 static HRESULT WINAPI MetadataReaderInfo_GetMetadataFormat(IWICMetadataReaderInfo *iface,
1447 GUID *format)
1449 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1450 TRACE("(%p,%p)\n", iface, format);
1451 return ComponentInfo_GetGUIDValue(This->classkey, metadataformat_valuename, format);
1454 static HRESULT WINAPI MetadataReaderInfo_GetContainerFormats(IWICMetadataReaderInfo *iface,
1455 UINT length, GUID *formats, UINT *actual_length)
1457 if (!actual_length) return E_INVALIDARG;
1459 FIXME("(%p,%u,%p,%p): stub\n", iface, length, formats, actual_length);
1460 return E_NOTIMPL;
1463 static HRESULT WINAPI MetadataReaderInfo_GetDeviceManufacturer(IWICMetadataReaderInfo *iface,
1464 UINT length, WCHAR *manufacturer, UINT *actual_length)
1466 FIXME("(%p,%u,%p,%p): stub\n", iface, length, manufacturer, actual_length);
1467 return E_NOTIMPL;
1470 static HRESULT WINAPI MetadataReaderInfo_GetDeviceModels(IWICMetadataReaderInfo *iface,
1471 UINT length, WCHAR *models, UINT *actual_length)
1473 FIXME("(%p,%u,%p,%p): stub\n", iface, length, models, actual_length);
1474 return E_NOTIMPL;
1477 static HRESULT WINAPI MetadataReaderInfo_DoesRequireFullStream(IWICMetadataReaderInfo *iface,
1478 BOOL *param)
1480 FIXME("(%p,%p): stub\n", iface, param);
1481 return E_NOTIMPL;
1484 static HRESULT WINAPI MetadataReaderInfo_DoesSupportPadding(IWICMetadataReaderInfo *iface,
1485 BOOL *param)
1487 FIXME("(%p,%p): stub\n", iface, param);
1488 return E_NOTIMPL;
1491 static HRESULT WINAPI MetadataReaderInfo_DoesRequireFixedSize(IWICMetadataReaderInfo *iface,
1492 BOOL *param)
1494 FIXME("(%p,%p): stub\n", iface, param);
1495 return E_NOTIMPL;
1498 static HRESULT WINAPI MetadataReaderInfo_GetPatterns(IWICMetadataReaderInfo *iface,
1499 REFGUID container, UINT length, WICMetadataPattern *pattern, UINT *count, UINT *actual_length)
1501 if (!actual_length) return E_INVALIDARG;
1503 FIXME("(%p,%s,%u,%p,%p,%p): stub\n", iface, debugstr_guid(container), length, pattern, count, actual_length);
1504 return E_NOTIMPL;
1507 static HRESULT WINAPI MetadataReaderInfo_MatchesPattern(IWICMetadataReaderInfo *iface,
1508 REFGUID container, IStream *stream, BOOL *matches)
1510 FIXME("(%p,%s,%p,%p): stub\n", iface, debugstr_guid(container), stream, matches);
1511 return E_NOTIMPL;
1514 static HRESULT WINAPI MetadataReaderInfo_CreateInstance(IWICMetadataReaderInfo *iface,
1515 IWICMetadataReader **reader)
1517 MetadataReaderInfo *This = impl_from_IWICMetadataReaderInfo(iface);
1519 TRACE("(%p,%p)\n", iface, reader);
1521 return CoCreateInstance(&This->clsid, NULL, CLSCTX_INPROC_SERVER,
1522 &IID_IWICMetadataReader, (void **)reader);
1525 static const IWICMetadataReaderInfoVtbl MetadataReaderInfo_Vtbl = {
1526 MetadataReaderInfo_QueryInterface,
1527 MetadataReaderInfo_AddRef,
1528 MetadataReaderInfo_Release,
1529 MetadataReaderInfo_GetComponentType,
1530 MetadataReaderInfo_GetCLSID,
1531 MetadataReaderInfo_GetSigningStatus,
1532 MetadataReaderInfo_GetAuthor,
1533 MetadataReaderInfo_GetVendorGUID,
1534 MetadataReaderInfo_GetVersion,
1535 MetadataReaderInfo_GetSpecVersion,
1536 MetadataReaderInfo_GetFriendlyName,
1537 MetadataReaderInfo_GetMetadataFormat,
1538 MetadataReaderInfo_GetContainerFormats,
1539 MetadataReaderInfo_GetDeviceManufacturer,
1540 MetadataReaderInfo_GetDeviceModels,
1541 MetadataReaderInfo_DoesRequireFullStream,
1542 MetadataReaderInfo_DoesSupportPadding,
1543 MetadataReaderInfo_DoesRequireFixedSize,
1544 MetadataReaderInfo_GetPatterns,
1545 MetadataReaderInfo_MatchesPattern,
1546 MetadataReaderInfo_CreateInstance
1549 static HRESULT MetadataReaderInfo_Constructor(HKEY classkey, REFCLSID clsid, IWICComponentInfo **info)
1551 MetadataReaderInfo *This;
1553 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1554 if (!This)
1556 RegCloseKey(classkey);
1557 return E_OUTOFMEMORY;
1560 This->IWICMetadataReaderInfo_iface.lpVtbl = &MetadataReaderInfo_Vtbl;
1561 This->ref = 1;
1562 This->classkey = classkey;
1563 This->clsid = *clsid;
1565 *info = (IWICComponentInfo *)This;
1566 return S_OK;
1569 static const WCHAR clsid_keyname[] = {'C','L','S','I','D',0};
1570 static const WCHAR instance_keyname[] = {'I','n','s','t','a','n','c','e',0};
1572 struct category {
1573 WICComponentType type;
1574 const GUID *catid;
1575 HRESULT (*constructor)(HKEY,REFCLSID,IWICComponentInfo**);
1578 static const struct category categories[] = {
1579 {WICDecoder, &CATID_WICBitmapDecoders, BitmapDecoderInfo_Constructor},
1580 {WICEncoder, &CATID_WICBitmapEncoders, BitmapEncoderInfo_Constructor},
1581 {WICPixelFormatConverter, &CATID_WICFormatConverters, FormatConverterInfo_Constructor},
1582 {WICPixelFormat, &CATID_WICPixelFormats, PixelFormatInfo_Constructor},
1583 {WICMetadataReader, &CATID_WICMetadataReader, MetadataReaderInfo_Constructor},
1587 HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo)
1589 HKEY clsidkey;
1590 HKEY classkey;
1591 HKEY catidkey;
1592 HKEY instancekey;
1593 WCHAR guidstring[39];
1594 LONG res;
1595 const struct category *category;
1596 int found=0;
1597 HRESULT hr;
1599 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, KEY_READ, &clsidkey);
1600 if (res != ERROR_SUCCESS)
1601 return HRESULT_FROM_WIN32(res);
1603 for (category=categories; category->type; category++)
1605 StringFromGUID2(category->catid, guidstring, 39);
1606 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &catidkey);
1607 if (res == ERROR_SUCCESS)
1609 res = RegOpenKeyExW(catidkey, instance_keyname, 0, KEY_READ, &instancekey);
1610 if (res == ERROR_SUCCESS)
1612 StringFromGUID2(clsid, guidstring, 39);
1613 res = RegOpenKeyExW(instancekey, guidstring, 0, KEY_READ, &classkey);
1614 if (res == ERROR_SUCCESS)
1616 RegCloseKey(classkey);
1617 found = 1;
1619 RegCloseKey(instancekey);
1621 RegCloseKey(catidkey);
1623 if (found) break;
1626 if (found)
1628 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &classkey);
1629 if (res == ERROR_SUCCESS)
1630 hr = category->constructor(classkey, clsid, ppIInfo);
1631 else
1632 hr = HRESULT_FROM_WIN32(res);
1634 else
1636 FIXME("%s is not supported\n", wine_dbgstr_guid(clsid));
1637 hr = E_FAIL;
1640 RegCloseKey(clsidkey);
1642 return hr;
1645 typedef struct {
1646 IEnumUnknown IEnumUnknown_iface;
1647 LONG ref;
1648 struct list objects;
1649 struct list *cursor;
1650 CRITICAL_SECTION lock; /* Must be held when reading or writing cursor */
1651 } ComponentEnum;
1653 static inline ComponentEnum *impl_from_IEnumUnknown(IEnumUnknown *iface)
1655 return CONTAINING_RECORD(iface, ComponentEnum, IEnumUnknown_iface);
1658 typedef struct {
1659 struct list entry;
1660 IUnknown *unk;
1661 } ComponentEnumItem;
1663 static const IEnumUnknownVtbl ComponentEnumVtbl;
1665 static HRESULT WINAPI ComponentEnum_QueryInterface(IEnumUnknown *iface, REFIID iid,
1666 void **ppv)
1668 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1669 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
1671 if (!ppv) return E_INVALIDARG;
1673 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IEnumUnknown, iid))
1675 *ppv = This;
1677 else
1679 *ppv = NULL;
1680 return E_NOINTERFACE;
1683 IUnknown_AddRef((IUnknown*)*ppv);
1684 return S_OK;
1687 static ULONG WINAPI ComponentEnum_AddRef(IEnumUnknown *iface)
1689 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1690 ULONG ref = InterlockedIncrement(&This->ref);
1692 TRACE("(%p) refcount=%u\n", iface, ref);
1694 return ref;
1697 static ULONG WINAPI ComponentEnum_Release(IEnumUnknown *iface)
1699 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1700 ULONG ref = InterlockedDecrement(&This->ref);
1701 ComponentEnumItem *cursor, *cursor2;
1703 TRACE("(%p) refcount=%u\n", iface, ref);
1705 if (ref == 0)
1707 LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->objects, ComponentEnumItem, entry)
1709 IUnknown_Release(cursor->unk);
1710 list_remove(&cursor->entry);
1711 HeapFree(GetProcessHeap(), 0, cursor);
1713 This->lock.DebugInfo->Spare[0] = 0;
1714 DeleteCriticalSection(&This->lock);
1715 HeapFree(GetProcessHeap(), 0, This);
1718 return ref;
1721 static HRESULT WINAPI ComponentEnum_Next(IEnumUnknown *iface, ULONG celt,
1722 IUnknown **rgelt, ULONG *pceltFetched)
1724 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1725 int num_fetched=0;
1726 ComponentEnumItem *item;
1727 HRESULT hr=S_OK;
1729 TRACE("(%p,%u,%p,%p)\n", iface, celt, rgelt, pceltFetched);
1731 EnterCriticalSection(&This->lock);
1732 while (num_fetched<celt)
1734 if (!This->cursor)
1736 hr = S_FALSE;
1737 break;
1739 item = LIST_ENTRY(This->cursor, ComponentEnumItem, entry);
1740 IUnknown_AddRef(item->unk);
1741 rgelt[num_fetched] = item->unk;
1742 num_fetched++;
1743 This->cursor = list_next(&This->objects, This->cursor);
1745 LeaveCriticalSection(&This->lock);
1746 if (pceltFetched)
1747 *pceltFetched = num_fetched;
1748 return hr;
1751 static HRESULT WINAPI ComponentEnum_Skip(IEnumUnknown *iface, ULONG celt)
1753 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1754 int i;
1755 HRESULT hr=S_OK;
1757 TRACE("(%p,%u)\n", iface, celt);
1759 EnterCriticalSection(&This->lock);
1760 for (i=0; i<celt; i++)
1762 if (!This->cursor)
1764 hr = S_FALSE;
1765 break;
1767 This->cursor = list_next(&This->objects, This->cursor);
1769 LeaveCriticalSection(&This->lock);
1770 return hr;
1773 static HRESULT WINAPI ComponentEnum_Reset(IEnumUnknown *iface)
1775 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1777 TRACE("(%p)\n", iface);
1779 EnterCriticalSection(&This->lock);
1780 This->cursor = list_head(&This->objects);
1781 LeaveCriticalSection(&This->lock);
1782 return S_OK;
1785 static HRESULT WINAPI ComponentEnum_Clone(IEnumUnknown *iface, IEnumUnknown **ppenum)
1787 ComponentEnum *This = impl_from_IEnumUnknown(iface);
1788 ComponentEnum *new_enum;
1789 ComponentEnumItem *old_item, *new_item;
1790 HRESULT ret=S_OK;
1791 struct list *old_cursor;
1793 new_enum = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnum));
1794 if (!new_enum)
1796 *ppenum = NULL;
1797 return E_OUTOFMEMORY;
1800 new_enum->IEnumUnknown_iface.lpVtbl = &ComponentEnumVtbl;
1801 new_enum->ref = 1;
1802 new_enum->cursor = NULL;
1803 list_init(&new_enum->objects);
1804 InitializeCriticalSection(&new_enum->lock);
1805 new_enum->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ComponentEnum.lock");
1807 EnterCriticalSection(&This->lock);
1808 old_cursor = This->cursor;
1809 LeaveCriticalSection(&This->lock);
1811 LIST_FOR_EACH_ENTRY(old_item, &This->objects, ComponentEnumItem, entry)
1813 new_item = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnumItem));
1814 if (!new_item)
1816 ret = E_OUTOFMEMORY;
1817 break;
1819 new_item->unk = old_item->unk;
1820 list_add_tail(&new_enum->objects, &new_item->entry);
1821 IUnknown_AddRef(new_item->unk);
1822 if (&old_item->entry == old_cursor) new_enum->cursor = &new_item->entry;
1825 if (FAILED(ret))
1827 IUnknown_Release((IUnknown*)new_enum);
1828 *ppenum = NULL;
1830 else
1831 *ppenum = (IEnumUnknown*)new_enum;
1833 return ret;
1836 static const IEnumUnknownVtbl ComponentEnumVtbl = {
1837 ComponentEnum_QueryInterface,
1838 ComponentEnum_AddRef,
1839 ComponentEnum_Release,
1840 ComponentEnum_Next,
1841 ComponentEnum_Skip,
1842 ComponentEnum_Reset,
1843 ComponentEnum_Clone
1846 HRESULT CreateComponentEnumerator(DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
1848 ComponentEnum *This;
1849 ComponentEnumItem *item;
1850 const struct category *category;
1851 HKEY clsidkey, catidkey, instancekey;
1852 WCHAR guidstring[39];
1853 LONG res;
1854 int i;
1855 HRESULT hr=S_OK;
1856 CLSID clsid;
1858 if (options) FIXME("ignoring flags %x\n", options);
1860 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, KEY_READ, &clsidkey);
1861 if (res != ERROR_SUCCESS)
1862 return HRESULT_FROM_WIN32(res);
1864 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnum));
1865 if (!This)
1867 RegCloseKey(clsidkey);
1868 return E_OUTOFMEMORY;
1871 This->IEnumUnknown_iface.lpVtbl = &ComponentEnumVtbl;
1872 This->ref = 1;
1873 list_init(&This->objects);
1874 InitializeCriticalSection(&This->lock);
1875 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ComponentEnum.lock");
1877 for (category=categories; category->type && hr == S_OK; category++)
1879 if ((category->type & componentTypes) == 0) continue;
1880 StringFromGUID2(category->catid, guidstring, 39);
1881 res = RegOpenKeyExW(clsidkey, guidstring, 0, KEY_READ, &catidkey);
1882 if (res == ERROR_SUCCESS)
1884 res = RegOpenKeyExW(catidkey, instance_keyname, 0, KEY_READ, &instancekey);
1885 if (res == ERROR_SUCCESS)
1887 i=0;
1888 for (;;i++)
1890 DWORD guidstring_size = 39;
1891 res = RegEnumKeyExW(instancekey, i, guidstring, &guidstring_size, NULL, NULL, NULL, NULL);
1892 if (res != ERROR_SUCCESS) break;
1894 item = HeapAlloc(GetProcessHeap(), 0, sizeof(ComponentEnumItem));
1895 if (!item) { hr = E_OUTOFMEMORY; break; }
1897 hr = CLSIDFromString(guidstring, &clsid);
1898 if (SUCCEEDED(hr))
1900 hr = CreateComponentInfo(&clsid, (IWICComponentInfo**)&item->unk);
1901 if (SUCCEEDED(hr))
1902 list_add_tail(&This->objects, &item->entry);
1905 if (FAILED(hr))
1907 HeapFree(GetProcessHeap(), 0, item);
1908 hr = S_OK;
1911 RegCloseKey(instancekey);
1913 RegCloseKey(catidkey);
1915 if (res != ERROR_SUCCESS && res != ERROR_NO_MORE_ITEMS)
1916 hr = HRESULT_FROM_WIN32(res);
1918 RegCloseKey(clsidkey);
1920 if (SUCCEEDED(hr))
1922 IEnumUnknown_Reset((IEnumUnknown*)This);
1923 *ppIEnumUnknown = (IEnumUnknown*)This;
1925 else
1927 *ppIEnumUnknown = NULL;
1928 IUnknown_Release((IUnknown*)This);
1931 return hr;
1934 HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
1936 HRESULT res;
1937 IEnumUnknown *enumconverters;
1938 IUnknown *unkconverterinfo;
1939 IWICFormatConverterInfo *converterinfo=NULL;
1940 IWICFormatConverter *converter=NULL;
1941 GUID srcFormat;
1942 WCHAR srcformatstr[39], dstformatstr[39];
1943 BOOL canconvert;
1944 ULONG num_fetched;
1946 res = IWICBitmapSource_GetPixelFormat(pISrc, &srcFormat);
1947 if (FAILED(res)) return res;
1949 if (IsEqualGUID(&srcFormat, dstFormat))
1951 IWICBitmapSource_AddRef(pISrc);
1952 *ppIDst = pISrc;
1953 return S_OK;
1956 StringFromGUID2(&srcFormat, srcformatstr, 39);
1957 StringFromGUID2(dstFormat, dstformatstr, 39);
1959 res = CreateComponentEnumerator(WICPixelFormatConverter, 0, &enumconverters);
1960 if (FAILED(res)) return res;
1962 while (!converter)
1964 res = IEnumUnknown_Next(enumconverters, 1, &unkconverterinfo, &num_fetched);
1966 if (res == S_OK)
1968 res = IUnknown_QueryInterface(unkconverterinfo, &IID_IWICFormatConverterInfo, (void**)&converterinfo);
1970 if (SUCCEEDED(res))
1972 canconvert = ConverterSupportsFormat(converterinfo, srcformatstr);
1974 if (canconvert)
1975 canconvert = ConverterSupportsFormat(converterinfo, dstformatstr);
1977 if (canconvert)
1979 res = IWICFormatConverterInfo_CreateInstance(converterinfo, &converter);
1981 if (SUCCEEDED(res))
1982 res = IWICFormatConverter_CanConvert(converter, &srcFormat, dstFormat, &canconvert);
1984 if (SUCCEEDED(res) && canconvert)
1985 res = IWICFormatConverter_Initialize(converter, pISrc, dstFormat, WICBitmapDitherTypeNone,
1986 NULL, 0.0, WICBitmapPaletteTypeCustom);
1988 if (FAILED(res) || !canconvert)
1990 if (converter)
1992 IWICFormatConverter_Release(converter);
1993 converter = NULL;
1995 res = S_OK;
1999 IWICFormatConverterInfo_Release(converterinfo);
2002 IUnknown_Release(unkconverterinfo);
2004 else
2005 break;
2008 IEnumUnknown_Release(enumconverters);
2010 if (converter)
2012 *ppIDst = (IWICBitmapSource*)converter;
2013 return S_OK;
2015 else
2017 FIXME("cannot convert %s to %s\n", debugstr_guid(&srcFormat), debugstr_guid(dstFormat));
2018 *ppIDst = NULL;
2019 return WINCODEC_ERR_COMPONENTNOTFOUND;