[6/9] windowscodecs: implement GetFrame for BMP decoder

Vincent Povirk madewokherd+8cd9 at gmail.com
Sat Jun 27 20:50:16 CDT 2009


Vincent Povirk
-------------- next part --------------
From 7758edee9bee2988de66263c09bbfa0cc4dc084a Mon Sep 17 00:00:00 2001
From: Vincent Povirk <madewokherd at gmail.com>
Date: Sat, 13 Jun 2009 17:32:16 -0500
Subject: [PATCH 6/9] windowscodecs: implement GetFrame for BMP decoder

---
 dlls/windowscodecs/bmpdecode.c |  156 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 154 insertions(+), 2 deletions(-)

diff --git a/dlls/windowscodecs/bmpdecode.c b/dlls/windowscodecs/bmpdecode.c
index fc4ea92..1c96261 100644
--- a/dlls/windowscodecs/bmpdecode.c
+++ b/dlls/windowscodecs/bmpdecode.c
@@ -59,12 +59,141 @@ typedef struct {
 } BITMAPCOREHEADER2;
 
 typedef struct {
+    const IWICBitmapFrameDecodeVtbl *lpIWICBitmapFrameDecodeVtbl;
+    LONG ref;
+    IStream *stream;
+    BITMAPFILEHEADER bfh;
+    BITMAPV5HEADER bih;
+} BmpFrameDecode;
+
+HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
+    void **ppv)
+{
+    BmpFrameDecode *This = (BmpFrameDecode*)iface;
+    TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
+
+    if (!ppv) return E_INVALIDARG;
+
+    if (IsEqualIID(&IID_IUnknown, iid) ||
+        IsEqualIID(&IID_IWICBitmapSource, iid) ||
+        IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
+    {
+        *ppv = This;
+    }
+    else
+    {
+        *ppv = NULL;
+        return E_NOINTERFACE;
+    }
+
+    IUnknown_AddRef((IUnknown*)*ppv);
+    return S_OK;
+}
+
+static ULONG WINAPI BmpFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
+{
+    BmpFrameDecode *This = (BmpFrameDecode*)iface;
+    ULONG ref = InterlockedIncrement(&This->ref);
+
+    TRACE("(%p) refcount=%u\n", iface, ref);
+
+    return ref;
+}
+
+static ULONG WINAPI BmpFrameDecode_Release(IWICBitmapFrameDecode *iface)
+{
+    BmpFrameDecode *This = (BmpFrameDecode*)iface;
+    ULONG ref = InterlockedDecrement(&This->ref);
+
+    TRACE("(%p) refcount=%u\n", iface, ref);
+
+    if (ref == 0)
+    {
+        IStream_Release(This->stream);
+        HeapFree(GetProcessHeap(), 0, This);
+    }
+
+    return ref;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
+    UINT *puiWidth, UINT *puiHeight)
+{
+    FIXME("(%p,%p,%p): stub\n", iface, puiWidth, puiHeight);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface,
+    WICPixelFormatGUID *pPixelFormat)
+{
+    FIXME("(%p,%p): stub\n", iface, pPixelFormat);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface,
+    double *pDpiX, double *pDpiY)
+{
+    FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface,
+    IWICPalette *pIPalette)
+{
+    FIXME("(%p,%p): stub\n", iface, pIPalette);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
+    const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
+{
+    FIXME("(%p,%p,%u,%u,%p): stub\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
+    IWICMetadataQueryReader **ppIMetadataQueryReader)
+{
+    FIXME("(%p,%p): stub\n", iface, ppIMetadataQueryReader);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface,
+    UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
+{
+    FIXME("(%p,%u,%p,%p): stub\n", iface, cCount, ppIColorContexts, pcActualCount);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BmpFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
+    IWICBitmapSource **ppIThumbnail)
+{
+    FIXME("(%p,%p): stub\n", iface, ppIThumbnail);
+    return E_NOTIMPL;
+}
+
+static const IWICBitmapFrameDecodeVtbl BmpFrameDecode_Vtbl = {
+    BmpFrameDecode_QueryInterface,
+    BmpFrameDecode_AddRef,
+    BmpFrameDecode_Release,
+    BmpFrameDecode_GetSize,
+    BmpFrameDecode_GetPixelFormat,
+    BmpFrameDecode_GetResolution,
+    BmpFrameDecode_CopyPalette,
+    BmpFrameDecode_CopyPixels,
+    BmpFrameDecode_GetMetadataQueryReader,
+    BmpFrameDecode_GetColorContexts,
+    BmpFrameDecode_GetThumbnail
+};
+
+typedef struct {
     const IWICBitmapDecoderVtbl *lpIWICBitmapDecoderVtbl;
     LONG ref;
     BOOL initialized;
     IStream *stream;
     BITMAPFILEHEADER bfh;
     BITMAPV5HEADER bih;
+    BmpFrameDecode *framedecode;
 } BmpDecoder;
 
 static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream)
@@ -140,6 +269,7 @@ static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface)
     if (ref == 0)
     {
         if (This->stream) IStream_Release(This->stream);
+        if (This->framedecode) IUnknown_Release((IUnknown*)This->framedecode);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -229,8 +359,29 @@ static HRESULT WINAPI BmpDecoder_GetFrameCount(IWICBitmapDecoder *iface,
 static HRESULT WINAPI BmpDecoder_GetFrame(IWICBitmapDecoder *iface,
     UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
 {
-    FIXME("(%p,%u,%p): stub\n", iface, index, ppIBitmapFrame);
-    return E_NOTIMPL;
+    BmpDecoder *This = (BmpDecoder*)iface;
+
+    if (index != 0) return E_INVALIDARG;
+
+    if (!This->stream) return WINCODEC_ERR_WRONGSTATE;
+
+    if (!This->framedecode)
+    {
+        This->framedecode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameDecode));
+        if (!This->framedecode) return E_OUTOFMEMORY;
+
+        This->framedecode->lpIWICBitmapFrameDecodeVtbl = &BmpFrameDecode_Vtbl;
+        This->framedecode->ref = 1;
+        This->framedecode->stream = This->stream;
+        IStream_AddRef(This->stream);
+        This->framedecode->bfh = This->bfh;
+        This->framedecode->bih = This->bih;
+    }
+
+    *ppIBitmapFrame = (IWICBitmapFrameDecode*)This->framedecode;
+    IWICBitmapFrameDecode_AddRef((IWICBitmapFrameDecode*)This->framedecode);
+
+    return S_OK;
 }
 
 static const IWICBitmapDecoderVtbl BmpDecoder_Vtbl = {
@@ -268,6 +419,7 @@ HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
     This->ref = 1;
     This->initialized = FALSE;
     This->stream = NULL;
+    This->framedecode = NULL;
 
     ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
     IUnknown_Release((IUnknown*)This);
-- 
1.6.3.1


More information about the wine-patches mailing list