ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

imgfactory.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 Vincent Povirk for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 
00021 #include <stdarg.h>
00022 
00023 #define COBJMACROS
00024 
00025 #include "windef.h"
00026 #include "winbase.h"
00027 #include "winreg.h"
00028 #include "objbase.h"
00029 #include "shellapi.h"
00030 #include "wincodec.h"
00031 
00032 #include "wincodecs_private.h"
00033 
00034 #include "wine/debug.h"
00035 
00036 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
00037 
00038 typedef struct {
00039     const IWICImagingFactoryVtbl    *lpIWICImagingFactoryVtbl;
00040     LONG ref;
00041 } ImagingFactory;
00042 
00043 static HRESULT WINAPI ImagingFactory_QueryInterface(IWICImagingFactory *iface, REFIID iid,
00044     void **ppv)
00045 {
00046     ImagingFactory *This = (ImagingFactory*)iface;
00047     TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
00048 
00049     if (!ppv) return E_INVALIDARG;
00050 
00051     if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICImagingFactory, iid))
00052     {
00053         *ppv = This;
00054     }
00055     else
00056     {
00057         *ppv = NULL;
00058         return E_NOINTERFACE;
00059     }
00060 
00061     IUnknown_AddRef((IUnknown*)*ppv);
00062     return S_OK;
00063 }
00064 
00065 static ULONG WINAPI ImagingFactory_AddRef(IWICImagingFactory *iface)
00066 {
00067     ImagingFactory *This = (ImagingFactory*)iface;
00068     ULONG ref = InterlockedIncrement(&This->ref);
00069 
00070     TRACE("(%p) refcount=%u\n", iface, ref);
00071 
00072     return ref;
00073 }
00074 
00075 static ULONG WINAPI ImagingFactory_Release(IWICImagingFactory *iface)
00076 {
00077     ImagingFactory *This = (ImagingFactory*)iface;
00078     ULONG ref = InterlockedDecrement(&This->ref);
00079 
00080     TRACE("(%p) refcount=%u\n", iface, ref);
00081 
00082     if (ref == 0)
00083         HeapFree(GetProcessHeap(), 0, This);
00084 
00085     return ref;
00086 }
00087 
00088 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFilename(
00089     IWICImagingFactory *iface, LPCWSTR wzFilename, const GUID *pguidVendor,
00090     DWORD dwDesiredAccess, WICDecodeOptions metadataOptions,
00091     IWICBitmapDecoder **ppIDecoder)
00092 {
00093     IWICStream *stream;
00094     HRESULT hr;
00095 
00096     TRACE("(%p,%s,%s,%u,%u,%p)\n", iface, debugstr_w(wzFilename),
00097         debugstr_guid(pguidVendor), dwDesiredAccess, metadataOptions, ppIDecoder);
00098 
00099     hr = StreamImpl_Create(&stream);
00100     if (SUCCEEDED(hr))
00101     {
00102         hr = IWICStream_InitializeFromFilename(stream, wzFilename, dwDesiredAccess);
00103 
00104         if (SUCCEEDED(hr))
00105         {
00106             hr = IWICImagingFactory_CreateDecoderFromStream(iface, (IStream*)stream,
00107                 pguidVendor, metadataOptions, ppIDecoder);
00108         }
00109 
00110         IWICStream_Release(stream);
00111     }
00112 
00113     return hr;
00114 }
00115 
00116 static HRESULT WINAPI ImagingFactory_CreateDecoderFromStream(
00117     IWICImagingFactory *iface, IStream *pIStream, const GUID *pguidVendor,
00118     WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
00119 {
00120     static int fixme=0;
00121     IEnumUnknown *enumdecoders;
00122     IUnknown *unkdecoderinfo;
00123     IWICBitmapDecoderInfo *decoderinfo;
00124     IWICBitmapDecoder *decoder=NULL;
00125     HRESULT res=S_OK;
00126     ULONG num_fetched;
00127     BOOL matches;
00128 
00129     TRACE("(%p,%p,%s,%u,%p)\n", iface, pIStream, debugstr_guid(pguidVendor),
00130         metadataOptions, ppIDecoder);
00131 
00132     if (pguidVendor && !fixme++)
00133         FIXME("ignoring vendor GUID\n");
00134 
00135     res = CreateComponentEnumerator(WICDecoder, WICComponentEnumerateDefault, &enumdecoders);
00136     if (FAILED(res)) return res;
00137 
00138     while (!decoder)
00139     {
00140         res = IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched);
00141 
00142         if (res == S_OK)
00143         {
00144             res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo);
00145 
00146             if (SUCCEEDED(res))
00147             {
00148                 res = IWICBitmapDecoderInfo_MatchesPattern(decoderinfo, pIStream, &matches);
00149 
00150                 if (SUCCEEDED(res) && matches)
00151                 {
00152                     res = IWICBitmapDecoderInfo_CreateInstance(decoderinfo, &decoder);
00153 
00154                     /* FIXME: should use QueryCapability to choose a decoder */
00155 
00156                     if (SUCCEEDED(res))
00157                     {
00158                         res = IWICBitmapDecoder_Initialize(decoder, pIStream, metadataOptions);
00159 
00160                         if (FAILED(res))
00161                         {
00162                             IWICBitmapDecoder_Release(decoder);
00163                             decoder = NULL;
00164                         }
00165                     }
00166                 }
00167 
00168                 IWICBitmapDecoderInfo_Release(decoderinfo);
00169             }
00170 
00171             IUnknown_Release(unkdecoderinfo);
00172         }
00173         else
00174             break;
00175     }
00176 
00177     IEnumUnknown_Release(enumdecoders);
00178 
00179     if (decoder)
00180     {
00181         *ppIDecoder = decoder;
00182         return S_OK;
00183     }
00184     else
00185     {
00186         if (WARN_ON(wincodecs))
00187         {
00188             LARGE_INTEGER seek;
00189             BYTE data[4];
00190             ULONG bytesread;
00191 
00192             WARN("failed to load from a stream\n");
00193 
00194             seek.QuadPart = 0;
00195             res = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
00196             if (SUCCEEDED(res))
00197                 res = IStream_Read(pIStream, data, 4, &bytesread);
00198             if (SUCCEEDED(res))
00199                 WARN("first %i bytes of stream=%x %x %x %x\n", bytesread, data[0], data[1], data[2], data[3]);
00200         }
00201         *ppIDecoder = NULL;
00202         return WINCODEC_ERR_COMPONENTNOTFOUND;
00203     }
00204 }
00205 
00206 static HRESULT WINAPI ImagingFactory_CreateDecoderFromFileHandle(
00207     IWICImagingFactory *iface, ULONG_PTR hFile, const GUID *pguidVendor,
00208     WICDecodeOptions metadataOptions, IWICBitmapDecoder **ppIDecoder)
00209 {
00210     FIXME("(%p,%lx,%s,%u,%p): stub\n", iface, hFile, debugstr_guid(pguidVendor),
00211         metadataOptions, ppIDecoder);
00212     return E_NOTIMPL;
00213 }
00214 
00215 static HRESULT WINAPI ImagingFactory_CreateComponentInfo(IWICImagingFactory *iface,
00216     REFCLSID clsidComponent, IWICComponentInfo **ppIInfo)
00217 {
00218     TRACE("(%p,%s,%p)\n", iface, debugstr_guid(clsidComponent), ppIInfo);
00219     return CreateComponentInfo(clsidComponent, ppIInfo);
00220 }
00221 
00222 static HRESULT WINAPI ImagingFactory_CreateDecoder(IWICImagingFactory *iface,
00223     REFGUID guidContainerFormat, const GUID *pguidVendor,
00224     IWICBitmapDecoder **ppIDecoder)
00225 {
00226     FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
00227         debugstr_guid(pguidVendor), ppIDecoder);
00228     return E_NOTIMPL;
00229 }
00230 
00231 static HRESULT WINAPI ImagingFactory_CreateEncoder(IWICImagingFactory *iface,
00232     REFGUID guidContainerFormat, const GUID *pguidVendor,
00233     IWICBitmapEncoder **ppIEncoder)
00234 {
00235     FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidContainerFormat),
00236         debugstr_guid(pguidVendor), ppIEncoder);
00237     return E_NOTIMPL;
00238 }
00239 
00240 static HRESULT WINAPI ImagingFactory_CreatePalette(IWICImagingFactory *iface,
00241     IWICPalette **ppIPalette)
00242 {
00243     TRACE("(%p,%p)\n", iface, ppIPalette);
00244     return PaletteImpl_Create(ppIPalette);
00245 }
00246 
00247 static HRESULT WINAPI ImagingFactory_CreateFormatConverter(IWICImagingFactory *iface,
00248     IWICFormatConverter **ppIFormatConverter)
00249 {
00250     return FormatConverter_CreateInstance(NULL, &IID_IWICFormatConverter, (void**)ppIFormatConverter);
00251 }
00252 
00253 static HRESULT WINAPI ImagingFactory_CreateBitmapScaler(IWICImagingFactory *iface,
00254     IWICBitmapScaler **ppIBitmapScaler)
00255 {
00256     FIXME("(%p,%p): stub\n", iface, ppIBitmapScaler);
00257     return E_NOTIMPL;
00258 }
00259 
00260 static HRESULT WINAPI ImagingFactory_CreateBitmapClipper(IWICImagingFactory *iface,
00261     IWICBitmapClipper **ppIBitmapClipper)
00262 {
00263     FIXME("(%p,%p): stub\n", iface, ppIBitmapClipper);
00264     return E_NOTIMPL;
00265 }
00266 
00267 static HRESULT WINAPI ImagingFactory_CreateBitmapFlipRotator(IWICImagingFactory *iface,
00268     IWICBitmapFlipRotator **ppIBitmapFlipRotator)
00269 {
00270     TRACE("(%p,%p)\n", iface, ppIBitmapFlipRotator);
00271     return FlipRotator_Create(ppIBitmapFlipRotator);
00272 }
00273 
00274 static HRESULT WINAPI ImagingFactory_CreateStream(IWICImagingFactory *iface,
00275     IWICStream **ppIWICStream)
00276 {
00277     TRACE("(%p,%p)\n", iface, ppIWICStream);
00278     return StreamImpl_Create(ppIWICStream);
00279 }
00280 
00281 static HRESULT WINAPI ImagingFactory_CreateColorContext(IWICImagingFactory *iface,
00282     IWICColorContext **ppIColorContext)
00283 {
00284     FIXME("(%p,%p): stub\n", iface, ppIColorContext);
00285     return E_NOTIMPL;
00286 }
00287 
00288 static HRESULT WINAPI ImagingFactory_CreateColorTransformer(IWICImagingFactory *iface,
00289     IWICColorTransform **ppIColorTransform)
00290 {
00291     FIXME("(%p,%p): stub\n", iface, ppIColorTransform);
00292     return E_NOTIMPL;
00293 }
00294 
00295 static HRESULT WINAPI ImagingFactory_CreateBitmap(IWICImagingFactory *iface,
00296     UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat,
00297     WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap)
00298 {
00299     FIXME("(%p,%u,%u,%s,%u,%p): stub\n", iface, uiWidth, uiHeight,
00300         debugstr_guid(pixelFormat), option, ppIBitmap);
00301     return E_NOTIMPL;
00302 }
00303 
00304 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSource(IWICImagingFactory *iface,
00305     IWICBitmapSource *piBitmapSource, WICBitmapCreateCacheOption option,
00306     IWICBitmap **ppIBitmap)
00307 {
00308     FIXME("(%p,%p,%u,%p): stub\n", iface, piBitmapSource, option, ppIBitmap);
00309     return E_NOTIMPL;
00310 }
00311 
00312 static HRESULT WINAPI ImagingFactory_CreateBitmapFromSourceRect(IWICImagingFactory *iface,
00313     IWICBitmapSource *piBitmapSource, UINT x, UINT y, UINT width, UINT height,
00314     IWICBitmap **ppIBitmap)
00315 {
00316     FIXME("(%p,%p,%u,%u,%u,%u,%p): stub\n", iface, piBitmapSource, x, y, width,
00317         height, ppIBitmap);
00318     return E_NOTIMPL;
00319 }
00320 
00321 static HRESULT WINAPI ImagingFactory_CreateBitmapFromMemory(IWICImagingFactory *iface,
00322     UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat, UINT cbStride,
00323     UINT cbBufferSize, BYTE *pbBuffer, IWICBitmap **ppIBitmap)
00324 {
00325     FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface, uiWidth, uiHeight,
00326         debugstr_guid(pixelFormat), cbStride, cbBufferSize, pbBuffer, ppIBitmap);
00327     return E_NOTIMPL;
00328 }
00329 
00330 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory *iface,
00331     HBITMAP hBitmap, HPALETTE hPalette, WICBitmapAlphaChannelOption options,
00332     IWICBitmap **ppIBitmap)
00333 {
00334     FIXME("(%p,%p,%p,%u,%p): stub\n", iface, hBitmap, hPalette, options, ppIBitmap);
00335     return E_NOTIMPL;
00336 }
00337 
00338 static HRESULT WINAPI ImagingFactory_CreateBitmapFromHICON(IWICImagingFactory *iface,
00339     HICON hIcon, IWICBitmap **ppIBitmap)
00340 {
00341     FIXME("(%p,%p,%p): stub\n", iface, hIcon, ppIBitmap);
00342     return E_NOTIMPL;
00343 }
00344 
00345 static HRESULT WINAPI ImagingFactory_CreateComponentEnumerator(IWICImagingFactory *iface,
00346     DWORD componentTypes, DWORD options, IEnumUnknown **ppIEnumUnknown)
00347 {
00348     TRACE("(%p,%u,%u,%p)\n", iface, componentTypes, options, ppIEnumUnknown);
00349     return CreateComponentEnumerator(componentTypes, options, ppIEnumUnknown);
00350 }
00351 
00352 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromDecoder(
00353     IWICImagingFactory *iface, IWICBitmapDecoder *pIDecoder,
00354     IWICFastMetadataEncoder **ppIFastEncoder)
00355 {
00356     FIXME("(%p,%p,%p): stub\n", iface, pIDecoder, ppIFastEncoder);
00357     return E_NOTIMPL;
00358 }
00359 
00360 static HRESULT WINAPI ImagingFactory_CreateFastMetadataEncoderFromFrameDecode(
00361     IWICImagingFactory *iface, IWICBitmapFrameDecode *pIFrameDecoder,
00362     IWICFastMetadataEncoder **ppIFastEncoder)
00363 {
00364     FIXME("(%p,%p,%p): stub\n", iface, pIFrameDecoder, ppIFastEncoder);
00365     return E_NOTIMPL;
00366 }
00367 
00368 static HRESULT WINAPI ImagingFactory_CreateQueryWriter(IWICImagingFactory *iface,
00369     REFGUID guidMetadataFormat, const GUID *pguidVendor,
00370     IWICMetadataQueryWriter **ppIQueryWriter)
00371 {
00372     FIXME("(%p,%s,%s,%p): stub\n", iface, debugstr_guid(guidMetadataFormat),
00373         debugstr_guid(pguidVendor), ppIQueryWriter);
00374     return E_NOTIMPL;
00375 }
00376 
00377 static HRESULT WINAPI ImagingFactory_CreateQueryWriterFromReader(IWICImagingFactory *iface,
00378     IWICMetadataQueryReader *pIQueryReader, const GUID *pguidVendor,
00379     IWICMetadataQueryWriter **ppIQueryWriter)
00380 {
00381     FIXME("(%p,%p,%s,%p): stub\n", iface, pIQueryReader, debugstr_guid(pguidVendor),
00382         ppIQueryWriter);
00383     return E_NOTIMPL;
00384 }
00385 
00386 static const IWICImagingFactoryVtbl ImagingFactory_Vtbl = {
00387     ImagingFactory_QueryInterface,
00388     ImagingFactory_AddRef,
00389     ImagingFactory_Release,
00390     ImagingFactory_CreateDecoderFromFilename,
00391     ImagingFactory_CreateDecoderFromStream,
00392     ImagingFactory_CreateDecoderFromFileHandle,
00393     ImagingFactory_CreateComponentInfo,
00394     ImagingFactory_CreateDecoder,
00395     ImagingFactory_CreateEncoder,
00396     ImagingFactory_CreatePalette,
00397     ImagingFactory_CreateFormatConverter,
00398     ImagingFactory_CreateBitmapScaler,
00399     ImagingFactory_CreateBitmapClipper,
00400     ImagingFactory_CreateBitmapFlipRotator,
00401     ImagingFactory_CreateStream,
00402     ImagingFactory_CreateColorContext,
00403     ImagingFactory_CreateColorTransformer,
00404     ImagingFactory_CreateBitmap,
00405     ImagingFactory_CreateBitmapFromSource,
00406     ImagingFactory_CreateBitmapFromSourceRect,
00407     ImagingFactory_CreateBitmapFromMemory,
00408     ImagingFactory_CreateBitmapFromHBITMAP,
00409     ImagingFactory_CreateBitmapFromHICON,
00410     ImagingFactory_CreateComponentEnumerator,
00411     ImagingFactory_CreateFastMetadataEncoderFromDecoder,
00412     ImagingFactory_CreateFastMetadataEncoderFromFrameDecode,
00413     ImagingFactory_CreateQueryWriter,
00414     ImagingFactory_CreateQueryWriterFromReader
00415 };
00416 
00417 HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
00418 {
00419     ImagingFactory *This;
00420     HRESULT ret;
00421 
00422     TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
00423 
00424     *ppv = NULL;
00425 
00426     if (pUnkOuter) return CLASS_E_NOAGGREGATION;
00427 
00428     This = HeapAlloc(GetProcessHeap(), 0, sizeof(ImagingFactory));
00429     if (!This) return E_OUTOFMEMORY;
00430 
00431     This->lpIWICImagingFactoryVtbl = &ImagingFactory_Vtbl;
00432     This->ref = 1;
00433 
00434     ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
00435     IUnknown_Release((IUnknown*)This);
00436 
00437     return ret;
00438 }

Generated on Sat May 26 2012 04:25:24 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.