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
20 #include "wine/port.h"
30 /* This is a hack, so jpeglib.h does not redefine INT32 and the like*/
32 #define UINT8 JPEG_UINT8
33 #define UINT16 JPEG_UINT16
34 #define boolean jpeg_boolean
38 #define HAVE_STDLIB_H 1
51 #include "wincodecs_private.h"
53 #include "wine/debug.h"
54 #include "wine/library.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
60 static void *libjpeg_handle;
62 #define MAKE_FUNCPTR(f) static typeof(f) * p##f
63 MAKE_FUNCPTR(jpeg_std_error);
66 static void *load_libjpeg(void)
68 if((libjpeg_handle = wine_dlopen(SONAME_LIBJPEG, RTLD_NOW, NULL, 0)) != NULL) {
70 #define LOAD_FUNCPTR(f) \
71 if((p##f = wine_dlsym(libjpeg_handle, #f, NULL, 0)) == NULL) { \
72 libjpeg_handle = NULL; \
76 LOAD_FUNCPTR(jpeg_std_error);
79 return libjpeg_handle;
83 const IWICBitmapDecoderVtbl *lpVtbl;
87 static HRESULT WINAPI JpegDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
90 JpegDecoder *This = (JpegDecoder*)iface;
91 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
93 if (!ppv) return E_INVALIDARG;
95 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
102 return E_NOINTERFACE;
105 IUnknown_AddRef((IUnknown*)*ppv);
109 static ULONG WINAPI JpegDecoder_AddRef(IWICBitmapDecoder *iface)
111 JpegDecoder *This = (JpegDecoder*)iface;
112 ULONG ref = InterlockedIncrement(&This->ref);
114 TRACE("(%p) refcount=%u\n", iface, ref);
119 static ULONG WINAPI JpegDecoder_Release(IWICBitmapDecoder *iface)
121 JpegDecoder *This = (JpegDecoder*)iface;
122 ULONG ref = InterlockedDecrement(&This->ref);
124 TRACE("(%p) refcount=%u\n", iface, ref);
128 HeapFree(GetProcessHeap(), 0, This);
134 static HRESULT WINAPI JpegDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
135 DWORD *pdwCapability)
137 FIXME("(%p,%p,%p): stub\n", iface, pIStream, pdwCapability);
141 static HRESULT WINAPI JpegDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
142 WICDecodeOptions cacheOptions)
144 FIXME("(%p,%p,%u): stub\n", iface, pIStream, cacheOptions);
148 static HRESULT WINAPI JpegDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
149 GUID *pguidContainerFormat)
151 memcpy(pguidContainerFormat, &GUID_ContainerFormatJpeg, sizeof(GUID));
155 static HRESULT WINAPI JpegDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
156 IWICBitmapDecoderInfo **ppIDecoderInfo)
158 FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
162 static HRESULT WINAPI JpegDecoder_CopyPalette(IWICBitmapDecoder *iface,
163 IWICPalette *pIPalette)
165 TRACE("(%p,%p)\n", iface, pIPalette);
167 return WINCODEC_ERR_PALETTEUNAVAILABLE;
170 static HRESULT WINAPI JpegDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
171 IWICMetadataQueryReader **ppIMetadataQueryReader)
173 FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
177 static HRESULT WINAPI JpegDecoder_GetPreview(IWICBitmapDecoder *iface,
178 IWICBitmapSource **ppIBitmapSource)
180 FIXME("(%p,%p): stub\n", iface, ppIBitmapSource);
181 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
184 static HRESULT WINAPI JpegDecoder_GetColorContexts(IWICBitmapDecoder *iface,
185 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
187 FIXME("(%p,%u,%p,%p): stub\n", iface, cCount, ppIColorContexts, pcActualCount);
188 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
191 static HRESULT WINAPI JpegDecoder_GetThumbnail(IWICBitmapDecoder *iface,
192 IWICBitmapSource **ppIThumbnail)
194 FIXME("(%p,%p): stub\n", iface, ppIThumbnail);
195 return WINCODEC_ERR_CODECNOTHUMBNAIL;
198 static HRESULT WINAPI JpegDecoder_GetFrameCount(IWICBitmapDecoder *iface,
205 static HRESULT WINAPI JpegDecoder_GetFrame(IWICBitmapDecoder *iface,
206 UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
208 FIXME("(%p,%u,%p): stub\n", iface, index, ppIBitmapFrame);
212 static const IWICBitmapDecoderVtbl JpegDecoder_Vtbl = {
213 JpegDecoder_QueryInterface,
216 JpegDecoder_QueryCapability,
217 JpegDecoder_Initialize,
218 JpegDecoder_GetContainerFormat,
219 JpegDecoder_GetDecoderInfo,
220 JpegDecoder_CopyPalette,
221 JpegDecoder_GetMetadataQueryReader,
222 JpegDecoder_GetPreview,
223 JpegDecoder_GetColorContexts,
224 JpegDecoder_GetThumbnail,
225 JpegDecoder_GetFrameCount,
229 HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
234 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
236 if (!libjpeg_handle && !load_libjpeg())
238 ERR("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
244 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
246 This = HeapAlloc(GetProcessHeap(), 0, sizeof(JpegDecoder));
247 if (!This) return E_OUTOFMEMORY;
249 This->lpVtbl = &JpegDecoder_Vtbl;
252 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
253 IUnknown_Release((IUnknown*)This);
258 #else /* !defined(SONAME_LIBJPEG) */
260 HRESULT JpegDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
262 ERR("Trying to load JPEG picture, but JPEG supported not compiled in.\n");