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
32 #include "wincodecs_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs
);
39 const IWICBitmapDecoderVtbl
*lpVtbl
;
45 static HRESULT WINAPI
GifDecoder_QueryInterface(IWICBitmapDecoder
*iface
, REFIID iid
,
48 GifDecoder
*This
= (GifDecoder
*)iface
;
49 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(iid
), ppv
);
51 if (!ppv
) return E_INVALIDARG
;
53 if (IsEqualIID(&IID_IUnknown
, iid
) || IsEqualIID(&IID_IWICBitmapDecoder
, iid
))
63 IUnknown_AddRef((IUnknown
*)*ppv
);
67 static ULONG WINAPI
GifDecoder_AddRef(IWICBitmapDecoder
*iface
)
69 GifDecoder
*This
= (GifDecoder
*)iface
;
70 ULONG ref
= InterlockedIncrement(&This
->ref
);
72 TRACE("(%p) refcount=%u\n", iface
, ref
);
77 static ULONG WINAPI
GifDecoder_Release(IWICBitmapDecoder
*iface
)
79 GifDecoder
*This
= (GifDecoder
*)iface
;
80 ULONG ref
= InterlockedDecrement(&This
->ref
);
82 TRACE("(%p) refcount=%u\n", iface
, ref
);
86 DGifCloseFile(This
->gif
);
87 HeapFree(GetProcessHeap(), 0, This
);
93 static HRESULT WINAPI
GifDecoder_QueryCapability(IWICBitmapDecoder
*iface
, IStream
*pIStream
,
96 FIXME("(%p,%p,%p): stub\n", iface
, pIStream
, pdwCapability
);
100 static int _gif_inputfunc(GifFileType
*gif
, GifByteType
*data
, int len
) {
101 IStream
*stream
= gif
->UserData
;
107 ERR("attempting to read file after initialization\n");
111 hr
= IStream_Read(stream
, data
, len
, &bytesread
);
112 if (hr
!= S_OK
) bytesread
= 0;
116 static HRESULT WINAPI
GifDecoder_Initialize(IWICBitmapDecoder
*iface
, IStream
*pIStream
,
117 WICDecodeOptions cacheOptions
)
119 GifDecoder
*This
= (GifDecoder
*)iface
;
123 TRACE("(%p,%p,%x)\n", iface
, pIStream
, cacheOptions
);
125 if (This
->initialized
|| This
->gif
)
127 WARN("already initialized\n");
128 return WINCODEC_ERR_WRONGSTATE
;
131 /* seek to start of stream */
133 IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, NULL
);
135 /* read all data from the stream */
136 This
->gif
= DGifOpen((void*)pIStream
, _gif_inputfunc
);
137 if (!This
->gif
) return E_FAIL
;
139 ret
= DGifSlurp(This
->gif
);
140 if (ret
== GIF_ERROR
) return E_FAIL
;
142 /* make sure we don't use the stream after this method returns */
143 This
->gif
->UserData
= NULL
;
145 This
->initialized
= TRUE
;
150 static HRESULT WINAPI
GifDecoder_GetContainerFormat(IWICBitmapDecoder
*iface
,
151 GUID
*pguidContainerFormat
)
153 FIXME("(%p,%s): stub\n", iface
, debugstr_guid(pguidContainerFormat
));
157 static HRESULT WINAPI
GifDecoder_GetDecoderInfo(IWICBitmapDecoder
*iface
,
158 IWICBitmapDecoderInfo
**ppIDecoderInfo
)
160 FIXME("(%p,%p): stub\n", iface
, ppIDecoderInfo
);
164 static HRESULT WINAPI
GifDecoder_CopyPalette(IWICBitmapDecoder
*iface
,
165 IWICPalette
*pIPalette
)
167 TRACE("(%p,%p)\n", iface
, pIPalette
);
168 return WINCODEC_ERR_PALETTEUNAVAILABLE
;
171 static HRESULT WINAPI
GifDecoder_GetMetadataQueryReader(IWICBitmapDecoder
*iface
,
172 IWICMetadataQueryReader
**ppIMetadataQueryReader
)
174 TRACE("(%p,%p)\n", iface
, ppIMetadataQueryReader
);
175 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
178 static HRESULT WINAPI
GifDecoder_GetPreview(IWICBitmapDecoder
*iface
,
179 IWICBitmapSource
**ppIBitmapSource
)
181 TRACE("(%p,%p)\n", iface
, ppIBitmapSource
);
182 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
185 static HRESULT WINAPI
GifDecoder_GetColorContexts(IWICBitmapDecoder
*iface
,
186 UINT cCount
, IWICColorContext
**ppIColorContexts
, UINT
*pcActualCount
)
188 TRACE("(%p,%u,%p,%p)\n", iface
, cCount
, ppIColorContexts
, pcActualCount
);
189 return WINCODEC_ERR_UNSUPPORTEDOPERATION
;
192 static HRESULT WINAPI
GifDecoder_GetThumbnail(IWICBitmapDecoder
*iface
,
193 IWICBitmapSource
**ppIThumbnail
)
195 TRACE("(%p,%p)\n", iface
, ppIThumbnail
);
196 return WINCODEC_ERR_CODECNOTHUMBNAIL
;
199 static HRESULT WINAPI
GifDecoder_GetFrameCount(IWICBitmapDecoder
*iface
,
202 FIXME("(%p,%p): stub\n", iface
, pCount
);
206 static HRESULT WINAPI
GifDecoder_GetFrame(IWICBitmapDecoder
*iface
,
207 UINT index
, IWICBitmapFrameDecode
**ppIBitmapFrame
)
209 FIXME("(%p,%u,%p): stub\n", iface
, index
, ppIBitmapFrame
);
213 static const IWICBitmapDecoderVtbl GifDecoder_Vtbl
= {
214 GifDecoder_QueryInterface
,
217 GifDecoder_QueryCapability
,
218 GifDecoder_Initialize
,
219 GifDecoder_GetContainerFormat
,
220 GifDecoder_GetDecoderInfo
,
221 GifDecoder_CopyPalette
,
222 GifDecoder_GetMetadataQueryReader
,
223 GifDecoder_GetPreview
,
224 GifDecoder_GetColorContexts
,
225 GifDecoder_GetThumbnail
,
226 GifDecoder_GetFrameCount
,
230 HRESULT
GifDecoder_CreateInstance(IUnknown
*pUnkOuter
, REFIID iid
, void** ppv
)
235 TRACE("(%p,%s,%p)\n", pUnkOuter
, debugstr_guid(iid
), ppv
);
239 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
241 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(GifDecoder
));
242 if (!This
) return E_OUTOFMEMORY
;
244 This
->lpVtbl
= &GifDecoder_Vtbl
;
246 This
->initialized
= FALSE
;
249 ret
= IUnknown_QueryInterface((IUnknown
*)This
, iid
, ppv
);
250 IUnknown_Release((IUnknown
*)This
);