comctl32/monthcal: Remove unused variable (Clang).
[wine/multimedia.git] / dlls / windowscodecs / icoformat.c
blobb4abac5f3357d53a70eee9ab8a6a002c030a750e
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "objbase.h"
29 #include "wincodec.h"
31 #include "wincodecs_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
37 #include "pshpack1.h"
39 typedef struct {
40 BYTE bWidth;
41 BYTE bHeight;
42 BYTE bColorCount;
43 BYTE bReserved;
44 WORD wPlanes;
45 WORD wBitCount;
46 DWORD dwDIBSize;
47 DWORD dwDIBOffset;
48 } ICONDIRENTRY;
50 typedef struct
52 WORD idReserved;
53 WORD idType;
54 WORD idCount;
55 } ICONHEADER;
57 #include "poppack.h"
59 typedef struct {
60 IWICBitmapDecoder IWICBitmapDecoder_iface;
61 LONG ref;
62 BOOL initialized;
63 IStream *stream;
64 ICONHEADER header;
65 CRITICAL_SECTION lock; /* must be held when accessing stream */
66 } IcoDecoder;
68 typedef struct {
69 IWICBitmapFrameDecode IWICBitmapFrameDecode_iface;
70 LONG ref;
71 UINT width, height;
72 BYTE *bits;
73 } IcoFrameDecode;
75 static inline IcoDecoder *impl_from_IWICBitmapDecoder(IWICBitmapDecoder *iface)
77 return CONTAINING_RECORD(iface, IcoDecoder, IWICBitmapDecoder_iface);
80 static inline IcoFrameDecode *impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface)
82 return CONTAINING_RECORD(iface, IcoFrameDecode, IWICBitmapFrameDecode_iface);
85 static HRESULT WINAPI IcoFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
86 void **ppv)
88 IcoFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
89 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
91 if (!ppv) return E_INVALIDARG;
93 if (IsEqualIID(&IID_IUnknown, iid) ||
94 IsEqualIID(&IID_IWICBitmapSource, iid) ||
95 IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
97 *ppv = This;
99 else
101 *ppv = NULL;
102 return E_NOINTERFACE;
105 IUnknown_AddRef((IUnknown*)*ppv);
106 return S_OK;
109 static ULONG WINAPI IcoFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
111 IcoFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
112 ULONG ref = InterlockedIncrement(&This->ref);
114 TRACE("(%p) refcount=%u\n", iface, ref);
116 return ref;
119 static ULONG WINAPI IcoFrameDecode_Release(IWICBitmapFrameDecode *iface)
121 IcoFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
122 ULONG ref = InterlockedDecrement(&This->ref);
124 TRACE("(%p) refcount=%u\n", iface, ref);
126 if (ref == 0)
128 HeapFree(GetProcessHeap(), 0, This->bits);
129 HeapFree(GetProcessHeap(), 0, This);
132 return ref;
135 static HRESULT WINAPI IcoFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
136 UINT *puiWidth, UINT *puiHeight)
138 IcoFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
140 *puiWidth = This->width;
141 *puiHeight = This->height;
143 TRACE("(%p) -> (%i,%i)\n", iface, *puiWidth, *puiHeight);
145 return S_OK;
148 static HRESULT WINAPI IcoFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface,
149 WICPixelFormatGUID *pPixelFormat)
151 memcpy(pPixelFormat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
152 return S_OK;
155 static HRESULT WINAPI IcoFrameDecode_GetResolution(IWICBitmapFrameDecode *iface,
156 double *pDpiX, double *pDpiY)
158 FIXME("(%p,%p,%p): stub\n", iface, pDpiX, pDpiY);
159 return E_NOTIMPL;
162 static HRESULT WINAPI IcoFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface,
163 IWICPalette *pIPalette)
165 TRACE("(%p,%p)\n", iface, pIPalette);
166 return WINCODEC_ERR_PALETTEUNAVAILABLE;
169 static HRESULT WINAPI IcoFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
170 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
172 IcoFrameDecode *This = impl_from_IWICBitmapFrameDecode(iface);
173 TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
175 return copy_pixels(32, This->bits, This->width, This->height, This->width * 4,
176 prc, cbStride, cbBufferSize, pbBuffer);
179 static HRESULT WINAPI IcoFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
180 IWICMetadataQueryReader **ppIMetadataQueryReader)
182 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
183 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
186 static HRESULT WINAPI IcoFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface,
187 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
189 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
190 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
193 static HRESULT WINAPI IcoFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
194 IWICBitmapSource **ppIThumbnail)
196 TRACE("(%p,%p)\n", iface, ppIThumbnail);
197 return WINCODEC_ERR_CODECNOTHUMBNAIL;
200 static const IWICBitmapFrameDecodeVtbl IcoFrameDecode_Vtbl = {
201 IcoFrameDecode_QueryInterface,
202 IcoFrameDecode_AddRef,
203 IcoFrameDecode_Release,
204 IcoFrameDecode_GetSize,
205 IcoFrameDecode_GetPixelFormat,
206 IcoFrameDecode_GetResolution,
207 IcoFrameDecode_CopyPalette,
208 IcoFrameDecode_CopyPixels,
209 IcoFrameDecode_GetMetadataQueryReader,
210 IcoFrameDecode_GetColorContexts,
211 IcoFrameDecode_GetThumbnail
214 static inline void pixel_set_trans(DWORD* pixel, BOOL transparent)
216 if (transparent) *pixel = 0;
217 else *pixel |= 0xff000000;
220 static HRESULT ReadIcoDib(IStream *stream, IcoFrameDecode *result)
222 HRESULT hr;
223 BmpDecoder *bmp_decoder;
224 IWICBitmapDecoder *decoder;
225 IWICBitmapFrameDecode *framedecode;
226 WICPixelFormatGUID pixelformat;
227 IWICBitmapSource *source;
228 int has_alpha=FALSE; /* if TRUE, alpha data might be in the image data */
229 WICRect rc;
231 hr = IcoDibDecoder_CreateInstance(&bmp_decoder);
232 if (SUCCEEDED(hr))
234 BmpDecoder_GetWICDecoder(bmp_decoder, &decoder);
235 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
237 if (SUCCEEDED(hr))
238 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
240 if (SUCCEEDED(hr))
242 hr = IWICBitmapFrameDecode_GetSize(framedecode, &result->width, &result->height);
244 if (SUCCEEDED(hr))
246 result->bits = HeapAlloc(GetProcessHeap(), 0, result->width * result->height * 4);
247 if (!result->bits) hr = E_OUTOFMEMORY;
250 if (SUCCEEDED(hr))
251 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &pixelformat);
253 if (IsEqualGUID(&pixelformat, &GUID_WICPixelFormat32bppBGR) ||
254 IsEqualGUID(&pixelformat, &GUID_WICPixelFormat32bppBGRA))
256 source = (IWICBitmapSource*)framedecode;
257 IWICBitmapSource_AddRef(source);
258 has_alpha = TRUE;
260 else
262 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA,
263 (IWICBitmapSource*)framedecode, &source);
264 has_alpha = FALSE;
267 if (SUCCEEDED(hr))
269 rc.X = 0;
270 rc.Y = 0;
271 rc.Width = result->width;
272 rc.Height = result->height;
273 hr = IWICBitmapSource_CopyPixels(source, &rc, result->width * 4,
274 result->width * result->height * 4, result->bits);
276 IWICBitmapSource_Release(source);
279 IWICBitmapFrameDecode_Release(framedecode);
282 if (SUCCEEDED(hr) && has_alpha)
284 /* If the alpha channel is fully transparent, we should ignore it. */
285 int nonzero_alpha = 0;
286 int i;
288 for (i=0; i<(result->height*result->width); i++)
290 if (result->bits[i*4+3] != 0)
292 nonzero_alpha = 1;
293 break;
297 if (!nonzero_alpha)
299 for (i=0; i<(result->height*result->width); i++)
300 result->bits[i*4+3] = 0xff;
302 has_alpha = FALSE;
306 if (SUCCEEDED(hr) && !has_alpha)
308 /* set alpha data based on the AND mask */
309 UINT andBytesPerRow = (result->width+31)/32*4;
310 UINT andBytes = andBytesPerRow * result->height;
311 INT andStride;
312 BYTE *tempdata=NULL;
313 BYTE *andRow;
314 BYTE *bitsRow;
315 UINT bitsStride = result->width * 4;
316 UINT x, y;
317 ULONG offset;
318 ULONG bytesread;
319 LARGE_INTEGER seek;
320 int topdown;
322 BmpDecoder_FindIconMask(bmp_decoder, &offset, &topdown);
324 if (offset)
326 seek.QuadPart = offset;
328 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, 0);
330 if (SUCCEEDED(hr))
332 tempdata = HeapAlloc(GetProcessHeap(), 0, andBytes);
333 if (!tempdata) hr = E_OUTOFMEMORY;
336 if (SUCCEEDED(hr))
337 hr = IStream_Read(stream, tempdata, andBytes, &bytesread);
339 if (SUCCEEDED(hr) && bytesread == andBytes)
341 if (topdown)
343 andStride = andBytesPerRow;
344 andRow = tempdata;
346 else
348 andStride = -andBytesPerRow;
349 andRow = tempdata + (result->height-1)*andBytesPerRow;
352 bitsRow = result->bits;
353 for (y=0; y<result->height; y++) {
354 BYTE *andByte=andRow;
355 DWORD *bitsPixel=(DWORD*)bitsRow;
356 for (x=0; x<result->width; x+=8) {
357 BYTE andVal=*andByte++;
358 pixel_set_trans(bitsPixel++, andVal>>7&1);
359 if (x+1 < result->width) pixel_set_trans(bitsPixel++, andVal>>6&1);
360 if (x+2 < result->width) pixel_set_trans(bitsPixel++, andVal>>5&1);
361 if (x+3 < result->width) pixel_set_trans(bitsPixel++, andVal>>4&1);
362 if (x+4 < result->width) pixel_set_trans(bitsPixel++, andVal>>3&1);
363 if (x+5 < result->width) pixel_set_trans(bitsPixel++, andVal>>2&1);
364 if (x+6 < result->width) pixel_set_trans(bitsPixel++, andVal>>1&1);
365 if (x+7 < result->width) pixel_set_trans(bitsPixel++, andVal&1);
367 andRow += andStride;
368 bitsRow += bitsStride;
372 HeapFree(GetProcessHeap(), 0, tempdata);
376 IWICBitmapDecoder_Release(decoder);
379 return hr;
382 static HRESULT ReadIcoPng(IStream *stream, IcoFrameDecode *result)
384 IWICBitmapDecoder *decoder = NULL;
385 IWICBitmapFrameDecode *sourceFrame = NULL;
386 IWICBitmapSource *sourceBitmap = NULL;
387 WICRect rect;
388 HRESULT hr;
390 hr = PngDecoder_CreateInstance(NULL, &IID_IWICBitmapDecoder, (void**)&decoder);
391 if (FAILED(hr))
392 goto end;
393 hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnLoad);
394 if (FAILED(hr))
395 goto end;
396 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &sourceFrame);
397 if (FAILED(hr))
398 goto end;
399 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)sourceFrame, &sourceBitmap);
400 if (FAILED(hr))
401 goto end;
402 hr = IWICBitmapFrameDecode_GetSize(sourceFrame, &result->width, &result->height);
403 if (FAILED(hr))
404 goto end;
405 result->bits = HeapAlloc(GetProcessHeap(), 0, 4 * result->width * result->height);
406 if (result->bits == NULL)
408 hr = E_OUTOFMEMORY;
409 goto end;
411 rect.X = 0;
412 rect.Y = 0;
413 rect.Width = result->width;
414 rect.Height = result->height;
415 hr = IWICBitmapSource_CopyPixels(sourceBitmap, &rect, 4*result->width,
416 4*result->width*result->height, result->bits);
418 end:
419 if (decoder != NULL)
420 IWICBitmapDecoder_Release(decoder);
421 if (sourceFrame != NULL)
422 IWICBitmapFrameDecode_Release(sourceFrame);
423 if (sourceBitmap != NULL)
424 IWICBitmapSource_Release(sourceBitmap);
425 return hr;
428 static HRESULT WINAPI IcoDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
429 void **ppv)
431 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
432 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
434 if (!ppv) return E_INVALIDARG;
436 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
438 *ppv = This;
440 else
442 *ppv = NULL;
443 return E_NOINTERFACE;
446 IUnknown_AddRef((IUnknown*)*ppv);
447 return S_OK;
450 static ULONG WINAPI IcoDecoder_AddRef(IWICBitmapDecoder *iface)
452 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
453 ULONG ref = InterlockedIncrement(&This->ref);
455 TRACE("(%p) refcount=%u\n", iface, ref);
457 return ref;
460 static ULONG WINAPI IcoDecoder_Release(IWICBitmapDecoder *iface)
462 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
463 ULONG ref = InterlockedDecrement(&This->ref);
465 TRACE("(%p) refcount=%u\n", iface, ref);
467 if (ref == 0)
469 This->lock.DebugInfo->Spare[0] = 0;
470 DeleteCriticalSection(&This->lock);
471 if (This->stream) IStream_Release(This->stream);
472 HeapFree(GetProcessHeap(), 0, This);
475 return ref;
478 static HRESULT WINAPI IcoDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
479 DWORD *pdwCapability)
481 FIXME("(%p,%p,%p): stub\n", iface, pIStream, pdwCapability);
482 return E_NOTIMPL;
485 static HRESULT WINAPI IcoDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
486 WICDecodeOptions cacheOptions)
488 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
489 LARGE_INTEGER seek;
490 HRESULT hr;
491 ULONG bytesread;
492 TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
494 EnterCriticalSection(&This->lock);
496 if (This->initialized)
498 hr = WINCODEC_ERR_WRONGSTATE;
499 goto end;
502 seek.QuadPart = 0;
503 hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, NULL);
504 if (FAILED(hr)) goto end;
506 hr = IStream_Read(pIStream, &This->header, sizeof(ICONHEADER), &bytesread);
507 if (FAILED(hr)) goto end;
508 if (bytesread != sizeof(ICONHEADER) ||
509 This->header.idReserved != 0 ||
510 This->header.idType != 1)
512 hr = E_FAIL;
513 goto end;
516 This->initialized = TRUE;
517 This->stream = pIStream;
518 IStream_AddRef(pIStream);
520 end:
522 LeaveCriticalSection(&This->lock);
524 return hr;
527 static HRESULT WINAPI IcoDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
528 GUID *pguidContainerFormat)
530 FIXME("(%p,%p): stub\n", iface, pguidContainerFormat);
531 return E_NOTIMPL;
534 static HRESULT WINAPI IcoDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
535 IWICBitmapDecoderInfo **ppIDecoderInfo)
537 FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
538 return E_NOTIMPL;
541 static HRESULT WINAPI IcoDecoder_CopyPalette(IWICBitmapDecoder *iface,
542 IWICPalette *pIPalette)
544 TRACE("(%p,%p)\n", iface, pIPalette);
545 return WINCODEC_ERR_PALETTEUNAVAILABLE;
548 static HRESULT WINAPI IcoDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
549 IWICMetadataQueryReader **ppIMetadataQueryReader)
551 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
552 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
555 static HRESULT WINAPI IcoDecoder_GetPreview(IWICBitmapDecoder *iface,
556 IWICBitmapSource **ppIBitmapSource)
558 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
559 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
562 static HRESULT WINAPI IcoDecoder_GetColorContexts(IWICBitmapDecoder *iface,
563 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
565 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
566 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
569 static HRESULT WINAPI IcoDecoder_GetThumbnail(IWICBitmapDecoder *iface,
570 IWICBitmapSource **ppIThumbnail)
572 TRACE("(%p,%p)\n", iface, ppIThumbnail);
573 return WINCODEC_ERR_CODECNOTHUMBNAIL;
576 static HRESULT WINAPI IcoDecoder_GetFrameCount(IWICBitmapDecoder *iface,
577 UINT *pCount)
579 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
580 TRACE("(%p,%p)\n", iface, pCount);
582 if (!This->initialized) return WINCODEC_ERR_NOTINITIALIZED;
584 *pCount = This->header.idCount;
585 TRACE("<-- %u\n", *pCount);
587 return S_OK;
590 static HRESULT WINAPI IcoDecoder_GetFrame(IWICBitmapDecoder *iface,
591 UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
593 IcoDecoder *This = impl_from_IWICBitmapDecoder(iface);
594 IcoFrameDecode *result=NULL;
595 LARGE_INTEGER seek;
596 ULARGE_INTEGER offset, length;
597 HRESULT hr;
598 ULONG bytesread;
599 ICONDIRENTRY entry;
600 IWICStream *substream=NULL;
601 DWORD magic;
602 TRACE("(%p,%u,%p)\n", iface, index, ppIBitmapFrame);
604 EnterCriticalSection(&This->lock);
606 if (!This->initialized)
608 hr = WINCODEC_ERR_NOTINITIALIZED;
609 goto fail;
612 if (This->header.idCount < index)
614 hr = E_INVALIDARG;
615 goto fail;
618 result = HeapAlloc(GetProcessHeap(), 0, sizeof(IcoFrameDecode));
619 if (!result)
621 hr = E_OUTOFMEMORY;
622 goto fail;
625 result->IWICBitmapFrameDecode_iface.lpVtbl = &IcoFrameDecode_Vtbl;
626 result->ref = 1;
627 result->bits = NULL;
629 /* read the icon entry */
630 seek.QuadPart = sizeof(ICONHEADER) + sizeof(ICONDIRENTRY) * index;
631 hr = IStream_Seek(This->stream, seek, STREAM_SEEK_SET, 0);
632 if (FAILED(hr)) goto fail;
634 hr = IStream_Read(This->stream, &entry, sizeof(ICONDIRENTRY), &bytesread);
635 if (FAILED(hr) || bytesread != sizeof(ICONDIRENTRY)) goto fail;
637 /* create a stream object for this icon */
638 hr = StreamImpl_Create(&substream);
639 if (FAILED(hr)) goto fail;
641 offset.QuadPart = entry.dwDIBOffset;
642 length.QuadPart = entry.dwDIBSize;
643 hr = IWICStream_InitializeFromIStreamRegion(substream, This->stream, offset, length);
644 if (FAILED(hr)) goto fail;
646 /* read the bitmapinfo size or magic number */
647 hr = IWICStream_Read(substream, &magic, sizeof(magic), &bytesread);
648 if (FAILED(hr) || bytesread != sizeof(magic)) goto fail;
650 /* forward to the appropriate decoding function based on the magic number */
651 switch (magic)
653 case sizeof(BITMAPCOREHEADER):
654 case 64: /* sizeof(BITMAPCOREHEADER2) */
655 case sizeof(BITMAPINFOHEADER):
656 case sizeof(BITMAPV4HEADER):
657 case sizeof(BITMAPV5HEADER):
658 hr = ReadIcoDib((IStream*)substream, result);
659 break;
660 case 0x474e5089:
661 hr = ReadIcoPng((IStream*)substream, result);
662 break;
663 default:
664 FIXME("Unrecognized ICO frame magic: %x\n", magic);
665 hr = E_FAIL;
666 break;
668 if (FAILED(hr)) goto fail;
670 *ppIBitmapFrame = (IWICBitmapFrameDecode*)result;
672 LeaveCriticalSection(&This->lock);
674 IStream_Release(substream);
676 return S_OK;
678 fail:
679 LeaveCriticalSection(&This->lock);
680 HeapFree(GetProcessHeap(), 0, result);
681 if (substream) IStream_Release(substream);
682 if (SUCCEEDED(hr)) hr = E_FAIL;
683 TRACE("<-- %x\n", hr);
684 return hr;
687 static const IWICBitmapDecoderVtbl IcoDecoder_Vtbl = {
688 IcoDecoder_QueryInterface,
689 IcoDecoder_AddRef,
690 IcoDecoder_Release,
691 IcoDecoder_QueryCapability,
692 IcoDecoder_Initialize,
693 IcoDecoder_GetContainerFormat,
694 IcoDecoder_GetDecoderInfo,
695 IcoDecoder_CopyPalette,
696 IcoDecoder_GetMetadataQueryReader,
697 IcoDecoder_GetPreview,
698 IcoDecoder_GetColorContexts,
699 IcoDecoder_GetThumbnail,
700 IcoDecoder_GetFrameCount,
701 IcoDecoder_GetFrame
704 HRESULT IcoDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
706 IcoDecoder *This;
707 HRESULT ret;
709 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
711 *ppv = NULL;
713 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
715 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IcoDecoder));
716 if (!This) return E_OUTOFMEMORY;
718 This->IWICBitmapDecoder_iface.lpVtbl = &IcoDecoder_Vtbl;
719 This->ref = 1;
720 This->stream = NULL;
721 This->initialized = FALSE;
722 InitializeCriticalSection(&This->lock);
723 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IcoDecoder.lock");
725 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
726 IUnknown_Release((IUnknown*)This);
728 return ret;