2 * Copyright 2010 Damjan Jovanovic
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
20 #include "wine/port.h"
35 #include "wincodecs_private.h"
37 #include "wine/debug.h"
38 #include "wine/library.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
44 static void *libicns_handle;
45 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
46 MAKE_FUNCPTR(icns_create_family);
47 MAKE_FUNCPTR(icns_export_family_data);
48 MAKE_FUNCPTR(icns_free_image);
49 MAKE_FUNCPTR(icns_get_mask_type_for_icon_type);
50 MAKE_FUNCPTR(icns_get_type_from_image_info);
51 MAKE_FUNCPTR(icns_init_image_for_type);
52 MAKE_FUNCPTR(icns_new_element_from_image);
53 MAKE_FUNCPTR(icns_set_element_in_family);
56 static void *load_libicns(void)
58 if((libicns_handle = wine_dlopen(SONAME_LIBICNS, RTLD_NOW, NULL, 0)) != NULL) {
60 #define LOAD_FUNCPTR(f) \
61 if((p##f = wine_dlsym(libicns_handle, #f, NULL, 0)) == NULL) { \
62 libicns_handle = NULL; \
65 LOAD_FUNCPTR(icns_create_family);
66 LOAD_FUNCPTR(icns_export_family_data);
67 LOAD_FUNCPTR(icns_free_image);
68 LOAD_FUNCPTR(icns_get_mask_type_for_icon_type);
69 LOAD_FUNCPTR(icns_get_type_from_image_info);
70 LOAD_FUNCPTR(icns_init_image_for_type);
71 LOAD_FUNCPTR(icns_new_element_from_image);
72 LOAD_FUNCPTR(icns_set_element_in_family);
75 return libicns_handle;
78 typedef struct IcnsEncoder {
79 const IWICBitmapEncoderVtbl *lpVtbl;
82 CRITICAL_SECTION lock;
85 static HRESULT WINAPI IcnsEncoder_QueryInterface(IWICBitmapEncoder *iface, REFIID iid,
88 IcnsEncoder *This = (IcnsEncoder*)iface;
89 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
91 if (!ppv) return E_INVALIDARG;
93 if (IsEqualIID(&IID_IUnknown, iid) ||
94 IsEqualIID(&IID_IWICBitmapEncoder, iid))
101 return E_NOINTERFACE;
104 IUnknown_AddRef((IUnknown*)*ppv);
108 static ULONG WINAPI IcnsEncoder_AddRef(IWICBitmapEncoder *iface)
110 IcnsEncoder *This = (IcnsEncoder*)iface;
111 ULONG ref = InterlockedIncrement(&This->ref);
113 TRACE("(%p) refcount=%u\n", iface, ref);
118 static ULONG WINAPI IcnsEncoder_Release(IWICBitmapEncoder *iface)
120 IcnsEncoder *This = (IcnsEncoder*)iface;
121 ULONG ref = InterlockedDecrement(&This->ref);
123 TRACE("(%p) refcount=%u\n", iface, ref);
127 This->lock.DebugInfo->Spare[0] = 0;
128 DeleteCriticalSection(&This->lock);
130 IStream_Release(This->stream);
131 HeapFree(GetProcessHeap(), 0, This);
137 static HRESULT WINAPI IcnsEncoder_Initialize(IWICBitmapEncoder *iface,
138 IStream *pIStream, WICBitmapEncoderCacheOption cacheOption)
140 IcnsEncoder *This = (IcnsEncoder*)iface;
142 TRACE("(%p,%p,%u)\n", iface, pIStream, cacheOption);
144 EnterCriticalSection(&This->lock);
146 IStream_AddRef(pIStream);
147 This->stream = pIStream;
149 LeaveCriticalSection(&This->lock);
154 static HRESULT WINAPI IcnsEncoder_GetContainerFormat(IWICBitmapEncoder *iface,
155 GUID *pguidContainerFormat)
157 FIXME("(%p,%s): stub\n", iface, debugstr_guid(pguidContainerFormat));
161 static HRESULT WINAPI IcnsEncoder_GetEncoderInfo(IWICBitmapEncoder *iface,
162 IWICBitmapEncoderInfo **ppIEncoderInfo)
164 FIXME("(%p,%p): stub\n", iface, ppIEncoderInfo);
168 static HRESULT WINAPI IcnsEncoder_SetColorContexts(IWICBitmapEncoder *iface,
169 UINT cCount, IWICColorContext **ppIColorContext)
171 FIXME("(%p,%u,%p): stub\n", iface, cCount, ppIColorContext);
175 static HRESULT WINAPI IcnsEncoder_SetPalette(IWICBitmapEncoder *iface, IWICPalette *pIPalette)
177 TRACE("(%p,%p)\n", iface, pIPalette);
178 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
181 static HRESULT WINAPI IcnsEncoder_SetThumbnail(IWICBitmapEncoder *iface, IWICBitmapSource *pIThumbnail)
183 TRACE("(%p,%p)\n", iface, pIThumbnail);
184 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
187 static HRESULT WINAPI IcnsEncoder_SetPreview(IWICBitmapEncoder *iface, IWICBitmapSource *pIPreview)
189 TRACE("(%p,%p)\n", iface, pIPreview);
190 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
193 static HRESULT WINAPI IcnsEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
194 IWICBitmapFrameEncode **ppIFrameEncode, IPropertyBag2 **ppIEncoderOptions)
196 FIXME("(%p,%p,%p): stub\n", iface, ppIFrameEncode, ppIEncoderOptions);
201 static HRESULT WINAPI IcnsEncoder_Commit(IWICBitmapEncoder *iface)
203 FIXME("(%p): stub\n", iface);
208 static HRESULT WINAPI IcnsEncoder_GetMetadataQueryWriter(IWICBitmapEncoder *iface,
209 IWICMetadataQueryWriter **ppIMetadataQueryWriter)
211 FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryWriter);
215 static const IWICBitmapEncoderVtbl IcnsEncoder_Vtbl = {
216 IcnsEncoder_QueryInterface,
219 IcnsEncoder_Initialize,
220 IcnsEncoder_GetContainerFormat,
221 IcnsEncoder_GetEncoderInfo,
222 IcnsEncoder_SetColorContexts,
223 IcnsEncoder_SetPalette,
224 IcnsEncoder_SetThumbnail,
225 IcnsEncoder_SetPreview,
226 IcnsEncoder_CreateNewFrame,
228 IcnsEncoder_GetMetadataQueryWriter
231 HRESULT IcnsEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
236 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
240 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
242 if (!libicns_handle && !load_libicns())
244 ERR("Failed writing ICNS because unable to find %s\n",SONAME_LIBICNS);
248 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IcnsEncoder));
249 if (!This) return E_OUTOFMEMORY;
251 This->lpVtbl = &IcnsEncoder_Vtbl;
254 InitializeCriticalSection(&This->lock);
255 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IcnsEncoder.lock");
257 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
258 IUnknown_Release((IUnknown*)This);
263 #else /* !HAVE_ICNS_H */
265 HRESULT IcnsEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
267 ERR("Trying to save ICNS picture, but ICNS support is not compiled in.\n");