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);
49 DWORD bc2ClrImportant;
50 /* same as BITMAPINFOHEADER until this point */
55 DWORD bc2HalftoneSize1;
56 DWORD bc2HalftoneSize2;
61 struct BmpFrameDecode;
62 typedef HRESULT (*ReadDataFunc)(struct BmpFrameDecode* This);
64 typedef struct BmpFrameDecode {
65 const IWICBitmapFrameDecodeVtbl *lpVtbl;
70 const WICPixelFormatGUID *pixelformat;
72 ReadDataFunc read_data_func;
78 static HRESULT WINAPI BmpFrameDecode_QueryInterface(IWICBitmapFrameDecode *iface, REFIID iid,
81 BmpFrameDecode *This = (BmpFrameDecode*)iface;
82 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
84 if (!ppv) return E_INVALIDARG;
86 if (IsEqualIID(&IID_IUnknown, iid) ||
87 IsEqualIID(&IID_IWICBitmapSource, iid) ||
88 IsEqualIID(&IID_IWICBitmapFrameDecode, iid))
98 IUnknown_AddRef((IUnknown*)*ppv);
102 static ULONG WINAPI BmpFrameDecode_AddRef(IWICBitmapFrameDecode *iface)
104 BmpFrameDecode *This = (BmpFrameDecode*)iface;
105 ULONG ref = InterlockedIncrement(&This->ref);
107 TRACE("(%p) refcount=%u\n", iface, ref);
112 static ULONG WINAPI BmpFrameDecode_Release(IWICBitmapFrameDecode *iface)
114 BmpFrameDecode *This = (BmpFrameDecode*)iface;
115 ULONG ref = InterlockedDecrement(&This->ref);
117 TRACE("(%p) refcount=%u\n", iface, ref);
121 IStream_Release(This->stream);
122 HeapFree(GetProcessHeap(), 0, This->imagedata);
123 HeapFree(GetProcessHeap(), 0, This);
129 static HRESULT WINAPI BmpFrameDecode_GetSize(IWICBitmapFrameDecode *iface,
130 UINT *puiWidth, UINT *puiHeight)
132 BmpFrameDecode *This = (BmpFrameDecode*)iface;
133 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
135 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
137 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
138 *puiWidth = bch->bcWidth;
139 *puiHeight = bch->bcHeight;
143 *puiWidth = This->bih.bV5Width;
144 *puiHeight = abs(This->bih.bV5Height);
149 static HRESULT WINAPI BmpFrameDecode_GetPixelFormat(IWICBitmapFrameDecode *iface,
150 WICPixelFormatGUID *pPixelFormat)
152 BmpFrameDecode *This = (BmpFrameDecode*)iface;
153 TRACE("(%p,%p)\n", iface, pPixelFormat);
155 memcpy(pPixelFormat, This->pixelformat, sizeof(GUID));
160 static HRESULT BmpHeader_GetResolution(BITMAPV5HEADER *bih, double *pDpiX, double *pDpiY)
162 switch (bih->bV5Size)
164 case sizeof(BITMAPCOREHEADER):
168 case sizeof(BITMAPCOREHEADER2):
169 case sizeof(BITMAPINFOHEADER):
170 case sizeof(BITMAPV4HEADER):
171 case sizeof(BITMAPV5HEADER):
172 *pDpiX = bih->bV5XPelsPerMeter * 0.0254;
173 *pDpiY = bih->bV5YPelsPerMeter * 0.0254;
180 static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface,
181 double *pDpiX, double *pDpiY)
183 BmpFrameDecode *This = (BmpFrameDecode*)iface;
184 TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
186 return BmpHeader_GetResolution(&This->bih, pDpiX, pDpiY);
189 static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface,
190 IWICPalette *pIPalette)
193 BmpFrameDecode *This = (BmpFrameDecode*)iface;
194 TRACE("(%p,%p)\n", iface, pIPalette);
196 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
198 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
199 if (bch->bcBitCount <= 8)
201 /* 2**n colors in BGR format after the header */
202 int count = 1 << bch->bcBitCount;
204 ULONG tablesize, bytesread;
205 RGBTRIPLE *bgrcolors;
206 LARGE_INTEGER offset;
209 wiccolors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count);
210 tablesize = sizeof(RGBTRIPLE) * count;
211 bgrcolors = HeapAlloc(GetProcessHeap(), 0, tablesize);
212 if (!wiccolors || !bgrcolors)
214 HeapFree(GetProcessHeap(), 0, wiccolors);
215 HeapFree(GetProcessHeap(), 0, bgrcolors);
216 return E_OUTOFMEMORY;
219 offset.QuadPart = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPCOREHEADER);
220 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
221 if (FAILED(hr)) return hr;
223 hr = IStream_Read(This->stream, bgrcolors, tablesize, &bytesread);
224 if (FAILED(hr)) return hr;
225 if (bytesread != tablesize) return E_FAIL;
227 for (i=0; i<count; i++)
229 wiccolors[i] = 0xff000000|
230 (bgrcolors[i].rgbtRed<<16)|
231 (bgrcolors[i].rgbtGreen<<8)|
232 bgrcolors[i].rgbtBlue;
235 hr = IWICPalette_InitializeCustom(pIPalette, wiccolors, count);
237 HeapFree(GetProcessHeap(), 0, wiccolors);
238 HeapFree(GetProcessHeap(), 0, bgrcolors);
243 return WINCODEC_ERR_PALETTEUNAVAILABLE;
248 if (This->bih.bV5BitCount <= 8)
252 ULONG tablesize, bytesread;
253 LARGE_INTEGER offset;
256 if (This->bih.bV5ClrUsed == 0)
257 count = 1 << This->bih.bV5BitCount;
259 count = This->bih.bV5ClrUsed;
261 tablesize = sizeof(WICColor) * count;
262 wiccolors = HeapAlloc(GetProcessHeap(), 0, tablesize);
263 if (!wiccolors) return E_OUTOFMEMORY;
265 offset.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
266 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
267 if (FAILED(hr)) return hr;
269 hr = IStream_Read(This->stream, wiccolors, tablesize, &bytesread);
270 if (FAILED(hr)) return hr;
271 if (bytesread != tablesize) return E_FAIL;
273 /* convert from BGR to BGRA by setting alpha to 100% */
274 for (i=0; i<count; i++)
275 wiccolors[i] |= 0xff000000;
277 hr = IWICPalette_InitializeCustom(pIPalette, wiccolors, count);
279 HeapFree(GetProcessHeap(), 0, wiccolors);
284 return WINCODEC_ERR_PALETTEUNAVAILABLE;
289 static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
290 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
292 BmpFrameDecode *This = (BmpFrameDecode*)iface;
295 TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
297 if (!This->imagedata)
299 hr = This->read_data_func(This);
300 if (FAILED(hr)) return hr;
303 hr = BmpFrameDecode_GetSize(iface, &width, &height);
304 if (FAILED(hr)) return hr;
306 return copy_pixels(This->bitsperpixel, This->imagedatastart,
307 width, height, This->stride,
308 prc, cbStride, cbBufferSize, pbBuffer);
311 static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
312 IWICMetadataQueryReader **ppIMetadataQueryReader)
314 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
315 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
318 static HRESULT WINAPI BmpFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface,
319 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
321 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
322 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
325 static HRESULT WINAPI BmpFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
326 IWICBitmapSource **ppIThumbnail)
328 TRACE("(%p,%p)\n", iface, ppIThumbnail);
329 return WINCODEC_ERR_CODECNOTHUMBNAIL;
332 static HRESULT BmpFrameDecode_ReadUncompressed(BmpFrameDecode* This)
339 LARGE_INTEGER offbits;
342 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
344 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
345 width = bch->bcWidth;
346 height = bch->bcHeight;
351 width = This->bih.bV5Width;
352 height = abs(This->bih.bV5Height);
353 bottomup = (This->bih.bV5Height > 0);
356 /* row sizes in BMP files must be divisible by 4 bytes */
357 bytesperrow = (((width * This->bitsperpixel)+31)/32)*4;
358 datasize = bytesperrow * height;
360 This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize);
361 if (!This->imagedata) return E_OUTOFMEMORY;
363 offbits.QuadPart = This->bfh.bfOffBits;
364 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
365 if (FAILED(hr)) goto fail;
367 hr = IStream_Read(This->stream, This->imagedata, datasize, &bytesread);
368 if (FAILED(hr) || bytesread != datasize) goto fail;
372 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
373 This->stride = -bytesperrow;
377 This->imagedatastart = This->imagedata;
378 This->stride = bytesperrow;
383 HeapFree(GetProcessHeap(), 0, This->imagedata);
384 This->imagedata = NULL;
385 if (SUCCEEDED(hr)) hr = E_FAIL;
389 static HRESULT BmpFrameDecode_ReadRLE8(BmpFrameDecode* This)
393 BYTE *rledata, *cursor, *rledataend;
394 UINT rlesize, datasize, palettesize;
399 LARGE_INTEGER offbits;
402 width = This->bih.bV5Width;
403 height = abs(This->bih.bV5Height);
404 bytesperrow = width * 4;
405 datasize = bytesperrow * height;
406 rlesize = This->bih.bV5SizeImage;
407 if (This->bih.bV5ClrUsed && This->bih.bV5ClrUsed < 256)
408 palettesize = 4 * This->bih.bV5ClrUsed;
410 palettesize = 4 * 256;
412 rledata = HeapAlloc(GetProcessHeap(), 0, rlesize);
413 This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize);
414 if (!This->imagedata || !rledata)
421 offbits.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
422 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
423 if (FAILED(hr)) goto fail;
425 hr = IStream_Read(This->stream, palette, palettesize, &bytesread);
426 if (FAILED(hr) || bytesread != palettesize) goto fail;
429 offbits.QuadPart = This->bfh.bfOffBits;
430 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
431 if (FAILED(hr)) goto fail;
433 hr = IStream_Read(This->stream, rledata, rlesize, &bytesread);
434 if (FAILED(hr) || bytesread != rlesize) goto fail;
437 bgrdata = (DWORD*)This->imagedata;
440 rledataend = rledata + rlesize;
442 while (cursor < rledataend && y < height)
444 BYTE length = *cursor++;
448 BYTE escape = *cursor++;
451 case 0: /* end of line */
455 case 1: /* end of bitmap */
458 if (cursor < rledataend)
464 default: /* absolute mode */
466 while (cursor < rledataend && length-- && x < width)
467 bgrdata[y*width + x++] = palette[*cursor++];
468 if (escape & 1) cursor++; /* skip pad byte */
473 DWORD color = palette[*cursor++];
474 while (length-- && x < width)
475 bgrdata[y*width + x++] = color;
480 HeapFree(GetProcessHeap(), 0, rledata);
482 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
483 This->stride = -bytesperrow;
488 HeapFree(GetProcessHeap(), 0, rledata);
489 HeapFree(GetProcessHeap(), 0, This->imagedata);
490 This->imagedata = NULL;
491 if (SUCCEEDED(hr)) hr = E_FAIL;
495 static HRESULT BmpFrameDecode_ReadUnsupported(BmpFrameDecode* This)
500 static const IWICBitmapFrameDecodeVtbl BmpFrameDecode_Vtbl = {
501 BmpFrameDecode_QueryInterface,
502 BmpFrameDecode_AddRef,
503 BmpFrameDecode_Release,
504 BmpFrameDecode_GetSize,
505 BmpFrameDecode_GetPixelFormat,
506 BmpFrameDecode_GetResolution,
507 BmpFrameDecode_CopyPalette,
508 BmpFrameDecode_CopyPixels,
509 BmpFrameDecode_GetMetadataQueryReader,
510 BmpFrameDecode_GetColorContexts,
511 BmpFrameDecode_GetThumbnail
515 const IWICBitmapDecoderVtbl *lpVtbl;
519 BITMAPFILEHEADER bfh;
521 BmpFrameDecode *framedecode;
522 const WICPixelFormatGUID *pixelformat;
524 ReadDataFunc read_data_func;
527 static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream)
530 ULONG bytestoread, bytesread;
533 if (This->initialized) return WINCODEC_ERR_WRONGSTATE;
536 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
537 if (FAILED(hr)) return hr;
539 hr = IStream_Read(stream, &This->bfh, sizeof(BITMAPFILEHEADER), &bytesread);
540 if (FAILED(hr)) return hr;
541 if (bytesread != sizeof(BITMAPFILEHEADER) ||
542 This->bfh.bfType != 0x4d42 /* "BM" */) return E_FAIL;
544 hr = IStream_Read(stream, &This->bih.bV5Size, sizeof(DWORD), &bytesread);
545 if (FAILED(hr)) return hr;
546 if (bytesread != sizeof(DWORD) ||
547 (This->bih.bV5Size != sizeof(BITMAPCOREHEADER) &&
548 This->bih.bV5Size != sizeof(BITMAPCOREHEADER2) &&
549 This->bih.bV5Size != sizeof(BITMAPINFOHEADER) &&
550 This->bih.bV5Size != sizeof(BITMAPV4HEADER) &&
551 This->bih.bV5Size != sizeof(BITMAPV5HEADER))) return E_FAIL;
553 bytestoread = This->bih.bV5Size-sizeof(DWORD);
554 hr = IStream_Read(stream, &This->bih.bV5Width, bytestoread, &bytesread);
555 if (FAILED(hr)) return hr;
556 if (bytestoread != bytesread) return E_FAIL;
558 /* decide what kind of bitmap this is and how/if we can read it */
559 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
561 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
562 TRACE("BITMAPCOREHEADER with depth=%i\n", bch->bcBitCount);
563 This->bitsperpixel = bch->bcBitCount;
564 This->read_data_func = BmpFrameDecode_ReadUncompressed;
565 switch(bch->bcBitCount)
568 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
571 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
574 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
577 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
580 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
583 This->pixelformat = &GUID_WICPixelFormatUndefined;
584 WARN("unsupported bit depth %i for BITMAPCOREHEADER\n", bch->bcBitCount);
588 else /* struct is compatible with BITMAPINFOHEADER */
590 TRACE("bitmap header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
591 switch(This->bih.bV5Compression)
594 This->bitsperpixel = This->bih.bV5BitCount;
595 This->read_data_func = BmpFrameDecode_ReadUncompressed;
596 switch(This->bih.bV5BitCount)
599 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
602 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
605 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
608 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
611 This->pixelformat = &GUID_WICPixelFormat16bppBGR555;
614 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
617 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
620 This->pixelformat = &GUID_WICPixelFormatUndefined;
621 FIXME("unsupported bit depth %i for uncompressed RGB\n", This->bih.bV5BitCount);
625 This->bitsperpixel = 32;
626 This->read_data_func = BmpFrameDecode_ReadRLE8;
627 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
630 This->bitsperpixel = 0;
631 This->read_data_func = BmpFrameDecode_ReadUnsupported;
632 This->pixelformat = &GUID_WICPixelFormatUndefined;
633 FIXME("unsupported bitmap type header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
638 This->initialized = TRUE;
643 static HRESULT WINAPI BmpDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
646 BmpDecoder *This = (BmpDecoder*)iface;
647 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
649 if (!ppv) return E_INVALIDARG;
651 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
658 return E_NOINTERFACE;
661 IUnknown_AddRef((IUnknown*)*ppv);
665 static ULONG WINAPI BmpDecoder_AddRef(IWICBitmapDecoder *iface)
667 BmpDecoder *This = (BmpDecoder*)iface;
668 ULONG ref = InterlockedIncrement(&This->ref);
670 TRACE("(%p) refcount=%u\n", iface, ref);
675 static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface)
677 BmpDecoder *This = (BmpDecoder*)iface;
678 ULONG ref = InterlockedDecrement(&This->ref);
680 TRACE("(%p) refcount=%u\n", iface, ref);
684 if (This->stream) IStream_Release(This->stream);
685 if (This->framedecode) IUnknown_Release((IUnknown*)This->framedecode);
686 HeapFree(GetProcessHeap(), 0, This);
692 static HRESULT WINAPI BmpDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
693 DWORD *pdwCapability)
696 BmpDecoder *This = (BmpDecoder*)iface;
698 hr = BmpDecoder_ReadHeaders(This, pIStream);
699 if (FAILED(hr)) return hr;
701 if (This->read_data_func == BmpFrameDecode_ReadUnsupported)
704 *pdwCapability = WICBitmapDecoderCapabilityCanDecodeAllImages;
709 static HRESULT WINAPI BmpDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
710 WICDecodeOptions cacheOptions)
713 BmpDecoder *This = (BmpDecoder*)iface;
715 hr = BmpDecoder_ReadHeaders(This, pIStream);
719 This->stream = pIStream;
720 IStream_AddRef(pIStream);
726 static HRESULT WINAPI BmpDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
727 GUID *pguidContainerFormat)
729 memcpy(pguidContainerFormat, &GUID_ContainerFormatBmp, sizeof(GUID));
733 static HRESULT WINAPI BmpDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
734 IWICBitmapDecoderInfo **ppIDecoderInfo)
736 FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
740 static HRESULT WINAPI BmpDecoder_CopyPalette(IWICBitmapDecoder *iface,
741 IWICPalette *pIPalette)
743 TRACE("(%p,%p)\n", iface, pIPalette);
745 return WINCODEC_ERR_PALETTEUNAVAILABLE;
748 static HRESULT WINAPI BmpDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
749 IWICMetadataQueryReader **ppIMetadataQueryReader)
751 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
752 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
755 static HRESULT WINAPI BmpDecoder_GetPreview(IWICBitmapDecoder *iface,
756 IWICBitmapSource **ppIBitmapSource)
758 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
759 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
762 static HRESULT WINAPI BmpDecoder_GetColorContexts(IWICBitmapDecoder *iface,
763 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
765 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
766 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
769 static HRESULT WINAPI BmpDecoder_GetThumbnail(IWICBitmapDecoder *iface,
770 IWICBitmapSource **ppIThumbnail)
772 TRACE("(%p,%p)\n", iface, ppIThumbnail);
773 return WINCODEC_ERR_CODECNOTHUMBNAIL;
776 static HRESULT WINAPI BmpDecoder_GetFrameCount(IWICBitmapDecoder *iface,
783 static HRESULT WINAPI BmpDecoder_GetFrame(IWICBitmapDecoder *iface,
784 UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
786 BmpDecoder *This = (BmpDecoder*)iface;
788 if (index != 0) return E_INVALIDARG;
790 if (!This->stream) return WINCODEC_ERR_WRONGSTATE;
792 if (!This->framedecode)
794 This->framedecode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameDecode));
795 if (!This->framedecode) return E_OUTOFMEMORY;
797 This->framedecode->lpVtbl = &BmpFrameDecode_Vtbl;
798 This->framedecode->ref = 1;
799 This->framedecode->stream = This->stream;
800 IStream_AddRef(This->stream);
801 This->framedecode->bfh = This->bfh;
802 This->framedecode->bih = This->bih;
803 This->framedecode->pixelformat = This->pixelformat;
804 This->framedecode->bitsperpixel = This->bitsperpixel;
805 This->framedecode->read_data_func = This->read_data_func;
806 This->framedecode->imagedata = NULL;
809 *ppIBitmapFrame = (IWICBitmapFrameDecode*)This->framedecode;
810 IWICBitmapFrameDecode_AddRef((IWICBitmapFrameDecode*)This->framedecode);
815 static const IWICBitmapDecoderVtbl BmpDecoder_Vtbl = {
816 BmpDecoder_QueryInterface,
819 BmpDecoder_QueryCapability,
820 BmpDecoder_Initialize,
821 BmpDecoder_GetContainerFormat,
822 BmpDecoder_GetDecoderInfo,
823 BmpDecoder_CopyPalette,
824 BmpDecoder_GetMetadataQueryReader,
825 BmpDecoder_GetPreview,
826 BmpDecoder_GetColorContexts,
827 BmpDecoder_GetThumbnail,
828 BmpDecoder_GetFrameCount,
832 HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
837 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
841 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
843 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpDecoder));
844 if (!This) return E_OUTOFMEMORY;
846 This->lpVtbl = &BmpDecoder_Vtbl;
848 This->initialized = FALSE;
850 This->framedecode = NULL;
852 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
853 IUnknown_Release((IUnknown*)This);