2009-06-01 20:32:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Vincent Povirk for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "ocidl.h"
|
|
|
|
#include "initguid.h"
|
|
|
|
#include "wincodec.h"
|
2012-01-11 23:03:24 +01:00
|
|
|
#include "wincodecsdk.h"
|
2009-06-01 20:32:41 +02:00
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
|
|
|
|
|
2010-10-22 15:14:40 +02:00
|
|
|
extern HRESULT WINAPI WIC_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
|
|
|
|
|
2009-06-01 20:32:41 +02:00
|
|
|
typedef struct {
|
|
|
|
REFCLSID classid;
|
|
|
|
HRESULT (*constructor)(IUnknown*,REFIID,void**);
|
|
|
|
} classinfo;
|
|
|
|
|
2012-07-24 08:04:20 +02:00
|
|
|
static const classinfo wic_classes[] = {
|
2012-05-28 11:41:38 +02:00
|
|
|
{&CLSID_WICImagingFactory, ComponentFactory_CreateInstance},
|
2009-06-10 22:40:27 +02:00
|
|
|
{&CLSID_WICBmpDecoder, BmpDecoder_CreateInstance},
|
2009-08-09 01:49:33 +02:00
|
|
|
{&CLSID_WICPngDecoder, PngDecoder_CreateInstance},
|
2009-09-23 20:54:39 +02:00
|
|
|
{&CLSID_WICPngEncoder, PngEncoder_CreateInstance},
|
2009-08-11 20:47:29 +02:00
|
|
|
{&CLSID_WICBmpEncoder, BmpEncoder_CreateInstance},
|
2009-08-17 16:45:28 +02:00
|
|
|
{&CLSID_WICGifDecoder, GifDecoder_CreateInstance},
|
2009-08-20 16:22:16 +02:00
|
|
|
{&CLSID_WICIcoDecoder, IcoDecoder_CreateInstance},
|
2009-08-24 17:19:37 +02:00
|
|
|
{&CLSID_WICJpegDecoder, JpegDecoder_CreateInstance},
|
2011-06-10 21:17:17 +02:00
|
|
|
{&CLSID_WICJpegEncoder, JpegEncoder_CreateInstance},
|
2010-03-09 00:07:29 +01:00
|
|
|
{&CLSID_WICTiffDecoder, TiffDecoder_CreateInstance},
|
2011-03-29 21:56:30 +02:00
|
|
|
{&CLSID_WICTiffEncoder, TiffEncoder_CreateInstance},
|
2010-08-24 09:43:54 +02:00
|
|
|
{&CLSID_WICIcnsEncoder, IcnsEncoder_CreateInstance},
|
2009-08-06 03:49:37 +02:00
|
|
|
{&CLSID_WICDefaultFormatConverter, FormatConverter_CreateInstance},
|
2010-06-07 21:36:35 +02:00
|
|
|
{&CLSID_WineTgaDecoder, TgaDecoder_CreateInstance},
|
2012-01-11 23:03:24 +01:00
|
|
|
{&CLSID_WICUnknownMetadataReader, UnknownMetadataReader_CreateInstance},
|
2012-06-08 07:08:52 +02:00
|
|
|
{&CLSID_WICIfdMetadataReader, IfdMetadataReader_CreateInstance},
|
2012-09-11 00:01:15 +02:00
|
|
|
{&CLSID_WICPngTextMetadataReader, PngTextReader_CreateInstance},
|
2012-09-11 09:48:37 +02:00
|
|
|
{&CLSID_WICLSDMetadataReader, LSDReader_CreateInstance},
|
2012-09-11 09:49:50 +02:00
|
|
|
{&CLSID_WICIMDMetadataReader, IMDReader_CreateInstance},
|
2012-09-11 09:50:42 +02:00
|
|
|
{&CLSID_WICGCEMetadataReader, GCEReader_CreateInstance},
|
2012-09-17 03:03:15 +02:00
|
|
|
{&CLSID_WICAPEMetadataReader, APEReader_CreateInstance},
|
2012-09-17 03:04:14 +02:00
|
|
|
{&CLSID_WICGifCommentMetadataReader, GifCommentReader_CreateInstance},
|
2009-06-01 20:32:41 +02:00
|
|
|
{0}};
|
|
|
|
|
|
|
|
typedef struct {
|
2010-11-29 00:57:27 +01:00
|
|
|
IClassFactory IClassFactory_iface;
|
2009-06-01 20:32:41 +02:00
|
|
|
LONG ref;
|
2012-07-24 08:04:20 +02:00
|
|
|
const classinfo *info;
|
2009-06-01 20:32:41 +02:00
|
|
|
} ClassFactoryImpl;
|
|
|
|
|
2010-11-29 00:57:27 +01:00
|
|
|
static inline ClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ClassFactoryImpl, IClassFactory_iface);
|
|
|
|
}
|
|
|
|
|
2009-06-01 20:32:41 +02:00
|
|
|
static HRESULT WINAPI ClassFactoryImpl_QueryInterface(IClassFactory *iface,
|
|
|
|
REFIID iid, void **ppv)
|
|
|
|
{
|
2010-11-29 00:57:27 +01:00
|
|
|
ClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-06-01 20:32:41 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
2012-07-24 08:03:20 +02:00
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IClassFactory, iid))
|
2009-06-01 20:32:41 +02:00
|
|
|
{
|
2012-07-24 08:03:20 +02:00
|
|
|
*ppv = &This->IClassFactory_iface;
|
2009-06-01 20:32:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ClassFactoryImpl_AddRef(IClassFactory *iface)
|
|
|
|
{
|
2010-11-29 00:57:27 +01:00
|
|
|
ClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-06-01 20:32:41 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface)
|
|
|
|
{
|
2010-11-29 00:57:27 +01:00
|
|
|
ClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-06-01 20:32:41 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) refcount=%u\n", iface, ref);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface,
|
|
|
|
IUnknown *pUnkOuter, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-11-29 00:57:27 +01:00
|
|
|
ClassFactoryImpl *This = impl_from_IClassFactory(iface);
|
2009-06-01 20:32:41 +02:00
|
|
|
|
|
|
|
return This->info->constructor(pUnkOuter, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %i): stub\n", iface, lock);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IClassFactoryVtbl ClassFactoryImpl_Vtbl = {
|
|
|
|
ClassFactoryImpl_QueryInterface,
|
|
|
|
ClassFactoryImpl_AddRef,
|
|
|
|
ClassFactoryImpl_Release,
|
|
|
|
ClassFactoryImpl_CreateInstance,
|
|
|
|
ClassFactoryImpl_LockServer
|
|
|
|
};
|
|
|
|
|
2012-07-24 08:04:20 +02:00
|
|
|
static HRESULT ClassFactoryImpl_Constructor(const classinfo *info, REFIID riid, LPVOID *ppv)
|
2009-06-01 20:32:41 +02:00
|
|
|
{
|
|
|
|
ClassFactoryImpl *This;
|
|
|
|
HRESULT ret;
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactoryImpl));
|
|
|
|
if (!This) return E_OUTOFMEMORY;
|
|
|
|
|
2010-11-29 00:57:27 +01:00
|
|
|
This->IClassFactory_iface.lpVtbl = &ClassFactoryImpl_Vtbl;
|
2009-06-01 20:32:41 +02:00
|
|
|
This->ref = 1;
|
|
|
|
This->info = info;
|
|
|
|
|
2012-07-24 08:03:20 +02:00
|
|
|
ret = IClassFactory_QueryInterface(&This->IClassFactory_iface, riid, ppv);
|
|
|
|
IClassFactory_Release(&This->IClassFactory_iface);
|
2009-06-01 20:32:41 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
HRESULT ret;
|
2012-07-24 08:04:20 +02:00
|
|
|
const classinfo *info=NULL;
|
2009-06-01 20:32:41 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
|
|
|
|
|
|
|
|
if (!rclsid || !iid || !ppv)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
for (i=0; wic_classes[i].classid; i++)
|
|
|
|
{
|
|
|
|
if (IsEqualCLSID(wic_classes[i].classid, rclsid))
|
|
|
|
{
|
|
|
|
info = &wic_classes[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
ret = ClassFactoryImpl_Constructor(info, iid, ppv);
|
|
|
|
else
|
2010-10-22 15:14:40 +02:00
|
|
|
ret = WIC_DllGetClassObject(rclsid, iid, ppv);
|
2009-06-01 20:32:41 +02:00
|
|
|
|
|
|
|
TRACE("<-- %08X\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|