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;
195 WICColor *wiccolors=NULL;
196 RGBTRIPLE *bgrcolors=NULL;
198 TRACE("(%p,%p)\n", iface, pIPalette);
200 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
202 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
203 if (bch->bcBitCount <= 8)
205 /* 2**n colors in BGR format after the header */
206 ULONG tablesize, bytesread;
207 LARGE_INTEGER offset;
210 count = 1 << bch->bcBitCount;
211 wiccolors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count);
212 tablesize = sizeof(RGBTRIPLE) * count;
213 bgrcolors = HeapAlloc(GetProcessHeap(), 0, tablesize);
214 if (!wiccolors || !bgrcolors)
220 offset.QuadPart = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPCOREHEADER);
221 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
222 if (FAILED(hr)) goto end;
224 hr = IStream_Read(This->stream, bgrcolors, tablesize, &bytesread);
225 if (FAILED(hr)) goto end;
226 if (bytesread != tablesize) {
231 for (i=0; i<count; i++)
233 wiccolors[i] = 0xff000000|
234 (bgrcolors[i].rgbtRed<<16)|
235 (bgrcolors[i].rgbtGreen<<8)|
236 bgrcolors[i].rgbtBlue;
241 return WINCODEC_ERR_PALETTEUNAVAILABLE;
246 if (This->bih.bV5BitCount <= 8)
248 ULONG tablesize, bytesread;
249 LARGE_INTEGER offset;
252 if (This->bih.bV5ClrUsed == 0)
253 count = 1 << This->bih.bV5BitCount;
255 count = This->bih.bV5ClrUsed;
257 tablesize = sizeof(WICColor) * count;
258 wiccolors = HeapAlloc(GetProcessHeap(), 0, tablesize);
259 if (!wiccolors) return E_OUTOFMEMORY;
261 offset.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
262 hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL);
263 if (FAILED(hr)) goto end;
265 hr = IStream_Read(This->stream, wiccolors, tablesize, &bytesread);
266 if (FAILED(hr)) goto end;
267 if (bytesread != tablesize) {
272 /* convert from BGR to BGRA by setting alpha to 100% */
273 for (i=0; i<count; i++)
274 wiccolors[i] |= 0xff000000;
278 return WINCODEC_ERR_PALETTEUNAVAILABLE;
282 hr = IWICPalette_InitializeCustom(pIPalette, wiccolors, count);
285 HeapFree(GetProcessHeap(), 0, wiccolors);
286 HeapFree(GetProcessHeap(), 0, bgrcolors);
290 static HRESULT WINAPI BmpFrameDecode_CopyPixels(IWICBitmapFrameDecode *iface,
291 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
293 BmpFrameDecode *This = (BmpFrameDecode*)iface;
296 TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
298 if (!This->imagedata)
300 hr = This->read_data_func(This);
301 if (FAILED(hr)) return hr;
304 hr = BmpFrameDecode_GetSize(iface, &width, &height);
305 if (FAILED(hr)) return hr;
307 return copy_pixels(This->bitsperpixel, This->imagedatastart,
308 width, height, This->stride,
309 prc, cbStride, cbBufferSize, pbBuffer);
312 static HRESULT WINAPI BmpFrameDecode_GetMetadataQueryReader(IWICBitmapFrameDecode *iface,
313 IWICMetadataQueryReader **ppIMetadataQueryReader)
315 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
316 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
319 static HRESULT WINAPI BmpFrameDecode_GetColorContexts(IWICBitmapFrameDecode *iface,
320 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
322 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
323 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
326 static HRESULT WINAPI BmpFrameDecode_GetThumbnail(IWICBitmapFrameDecode *iface,
327 IWICBitmapSource **ppIThumbnail)
329 TRACE("(%p,%p)\n", iface, ppIThumbnail);
330 return WINCODEC_ERR_CODECNOTHUMBNAIL;
333 static HRESULT BmpFrameDecode_ReadUncompressed(BmpFrameDecode* This)
340 LARGE_INTEGER offbits;
343 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
345 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
346 width = bch->bcWidth;
347 height = bch->bcHeight;
352 width = This->bih.bV5Width;
353 height = abs(This->bih.bV5Height);
354 bottomup = (This->bih.bV5Height > 0);
357 /* row sizes in BMP files must be divisible by 4 bytes */
358 bytesperrow = (((width * This->bitsperpixel)+31)/32)*4;
359 datasize = bytesperrow * height;
361 This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize);
362 if (!This->imagedata) return E_OUTOFMEMORY;
364 offbits.QuadPart = This->bfh.bfOffBits;
365 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
366 if (FAILED(hr)) goto fail;
368 hr = IStream_Read(This->stream, This->imagedata, datasize, &bytesread);
369 if (FAILED(hr) || bytesread != datasize) goto fail;
373 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
374 This->stride = -bytesperrow;
378 This->imagedatastart = This->imagedata;
379 This->stride = bytesperrow;
384 HeapFree(GetProcessHeap(), 0, This->imagedata);
385 This->imagedata = NULL;
386 if (SUCCEEDED(hr)) hr = E_FAIL;
390 static HRESULT BmpFrameDecode_ReadRLE8(BmpFrameDecode* This)
394 BYTE *rledata, *cursor, *rledataend;
395 UINT rlesize, datasize, palettesize;
400 LARGE_INTEGER offbits;
403 width = This->bih.bV5Width;
404 height = abs(This->bih.bV5Height);
405 bytesperrow = width * 4;
406 datasize = bytesperrow * height;
407 rlesize = This->bih.bV5SizeImage;
408 if (This->bih.bV5ClrUsed && This->bih.bV5ClrUsed < 256)
409 palettesize = 4 * This->bih.bV5ClrUsed;
411 palettesize = 4 * 256;
413 rledata = HeapAlloc(GetProcessHeap(), 0, rlesize);
414 This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize);
415 if (!This->imagedata || !rledata)
422 offbits.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
423 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
424 if (FAILED(hr)) goto fail;
426 hr = IStream_Read(This->stream, palette, palettesize, &bytesread);
427 if (FAILED(hr) || bytesread != palettesize) goto fail;
430 offbits.QuadPart = This->bfh.bfOffBits;
431 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
432 if (FAILED(hr)) goto fail;
434 hr = IStream_Read(This->stream, rledata, rlesize, &bytesread);
435 if (FAILED(hr) || bytesread != rlesize) goto fail;
438 bgrdata = (DWORD*)This->imagedata;
441 rledataend = rledata + rlesize;
443 while (cursor < rledataend && y < height)
445 BYTE length = *cursor++;
449 BYTE escape = *cursor++;
452 case 0: /* end of line */
456 case 1: /* end of bitmap */
459 if (cursor < rledataend)
465 default: /* absolute mode */
467 while (cursor < rledataend && length-- && x < width)
468 bgrdata[y*width + x++] = palette[*cursor++];
469 if (escape & 1) cursor++; /* skip pad byte */
474 DWORD color = palette[*cursor++];
475 while (length-- && x < width)
476 bgrdata[y*width + x++] = color;
481 HeapFree(GetProcessHeap(), 0, rledata);
483 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
484 This->stride = -bytesperrow;
489 HeapFree(GetProcessHeap(), 0, rledata);
490 HeapFree(GetProcessHeap(), 0, This->imagedata);
491 This->imagedata = NULL;
492 if (SUCCEEDED(hr)) hr = E_FAIL;
496 static HRESULT BmpFrameDecode_ReadRLE4(BmpFrameDecode* This)
500 BYTE *rledata, *cursor, *rledataend;
501 UINT rlesize, datasize, palettesize;
506 LARGE_INTEGER offbits;
509 width = This->bih.bV5Width;
510 height = abs(This->bih.bV5Height);
511 bytesperrow = width * 4;
512 datasize = bytesperrow * height;
513 rlesize = This->bih.bV5SizeImage;
514 if (This->bih.bV5ClrUsed && This->bih.bV5ClrUsed < 16)
515 palettesize = 4 * This->bih.bV5ClrUsed;
517 palettesize = 4 * 16;
519 rledata = HeapAlloc(GetProcessHeap(), 0, rlesize);
520 This->imagedata = HeapAlloc(GetProcessHeap(), 0, datasize);
521 if (!This->imagedata || !rledata)
528 offbits.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size;
529 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
530 if (FAILED(hr)) goto fail;
532 hr = IStream_Read(This->stream, palette, palettesize, &bytesread);
533 if (FAILED(hr) || bytesread != palettesize) goto fail;
536 offbits.QuadPart = This->bfh.bfOffBits;
537 hr = IStream_Seek(This->stream, offbits, STREAM_SEEK_SET, NULL);
538 if (FAILED(hr)) goto fail;
540 hr = IStream_Read(This->stream, rledata, rlesize, &bytesread);
541 if (FAILED(hr) || bytesread != rlesize) goto fail;
544 bgrdata = (DWORD*)This->imagedata;
547 rledataend = rledata + rlesize;
549 while (cursor < rledataend && y < height)
551 BYTE length = *cursor++;
555 BYTE escape = *cursor++;
558 case 0: /* end of line */
562 case 1: /* end of bitmap */
565 if (cursor < rledataend)
571 default: /* absolute mode */
573 while (cursor < rledataend && length-- && x < width)
575 BYTE colors = *cursor++;
576 bgrdata[y*width + x++] = palette[colors>>4];
577 if (length-- && x < width)
578 bgrdata[y*width + x++] = palette[colors&0xf];
582 if ((cursor - rledata) & 1) cursor++; /* skip pad byte */
587 BYTE colors = *cursor++;
588 DWORD color1 = palette[colors>>4];
589 DWORD color2 = palette[colors&0xf];
590 while (length-- && x < width)
592 bgrdata[y*width + x++] = color1;
593 if (length-- && x < width)
594 bgrdata[y*width + x++] = color2;
602 HeapFree(GetProcessHeap(), 0, rledata);
604 This->imagedatastart = This->imagedata + (height-1) * bytesperrow;
605 This->stride = -bytesperrow;
610 HeapFree(GetProcessHeap(), 0, rledata);
611 HeapFree(GetProcessHeap(), 0, This->imagedata);
612 This->imagedata = NULL;
613 if (SUCCEEDED(hr)) hr = E_FAIL;
617 static HRESULT BmpFrameDecode_ReadUnsupported(BmpFrameDecode* This)
622 static const IWICBitmapFrameDecodeVtbl BmpFrameDecode_Vtbl = {
623 BmpFrameDecode_QueryInterface,
624 BmpFrameDecode_AddRef,
625 BmpFrameDecode_Release,
626 BmpFrameDecode_GetSize,
627 BmpFrameDecode_GetPixelFormat,
628 BmpFrameDecode_GetResolution,
629 BmpFrameDecode_CopyPalette,
630 BmpFrameDecode_CopyPixels,
631 BmpFrameDecode_GetMetadataQueryReader,
632 BmpFrameDecode_GetColorContexts,
633 BmpFrameDecode_GetThumbnail
637 const IWICBitmapDecoderVtbl *lpVtbl;
641 BITMAPFILEHEADER bfh;
643 BmpFrameDecode *framedecode;
644 const WICPixelFormatGUID *pixelformat;
646 ReadDataFunc read_data_func;
649 static HRESULT BmpDecoder_ReadHeaders(BmpDecoder* This, IStream *stream)
652 ULONG bytestoread, bytesread;
655 if (This->initialized) return WINCODEC_ERR_WRONGSTATE;
658 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
659 if (FAILED(hr)) return hr;
661 hr = IStream_Read(stream, &This->bfh, sizeof(BITMAPFILEHEADER), &bytesread);
662 if (FAILED(hr)) return hr;
663 if (bytesread != sizeof(BITMAPFILEHEADER) ||
664 This->bfh.bfType != 0x4d42 /* "BM" */) return E_FAIL;
666 hr = IStream_Read(stream, &This->bih.bV5Size, sizeof(DWORD), &bytesread);
667 if (FAILED(hr)) return hr;
668 if (bytesread != sizeof(DWORD) ||
669 (This->bih.bV5Size != sizeof(BITMAPCOREHEADER) &&
670 This->bih.bV5Size != sizeof(BITMAPCOREHEADER2) &&
671 This->bih.bV5Size != sizeof(BITMAPINFOHEADER) &&
672 This->bih.bV5Size != sizeof(BITMAPV4HEADER) &&
673 This->bih.bV5Size != sizeof(BITMAPV5HEADER))) return E_FAIL;
675 bytestoread = This->bih.bV5Size-sizeof(DWORD);
676 hr = IStream_Read(stream, &This->bih.bV5Width, bytestoread, &bytesread);
677 if (FAILED(hr)) return hr;
678 if (bytestoread != bytesread) return E_FAIL;
680 /* decide what kind of bitmap this is and how/if we can read it */
681 if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER))
683 BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih;
684 TRACE("BITMAPCOREHEADER with depth=%i\n", bch->bcBitCount);
685 This->bitsperpixel = bch->bcBitCount;
686 This->read_data_func = BmpFrameDecode_ReadUncompressed;
687 switch(bch->bcBitCount)
690 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
693 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
696 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
699 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
702 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
705 This->pixelformat = &GUID_WICPixelFormatUndefined;
706 WARN("unsupported bit depth %i for BITMAPCOREHEADER\n", bch->bcBitCount);
710 else /* struct is compatible with BITMAPINFOHEADER */
712 TRACE("bitmap header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
713 switch(This->bih.bV5Compression)
716 This->bitsperpixel = This->bih.bV5BitCount;
717 This->read_data_func = BmpFrameDecode_ReadUncompressed;
718 switch(This->bih.bV5BitCount)
721 This->pixelformat = &GUID_WICPixelFormat1bppIndexed;
724 This->pixelformat = &GUID_WICPixelFormat2bppIndexed;
727 This->pixelformat = &GUID_WICPixelFormat4bppIndexed;
730 This->pixelformat = &GUID_WICPixelFormat8bppIndexed;
733 This->pixelformat = &GUID_WICPixelFormat16bppBGR555;
736 This->pixelformat = &GUID_WICPixelFormat24bppBGR;
739 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
742 This->pixelformat = &GUID_WICPixelFormatUndefined;
743 FIXME("unsupported bit depth %i for uncompressed RGB\n", This->bih.bV5BitCount);
747 This->bitsperpixel = 32;
748 This->read_data_func = BmpFrameDecode_ReadRLE8;
749 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
752 This->bitsperpixel = 32;
753 This->read_data_func = BmpFrameDecode_ReadRLE4;
754 This->pixelformat = &GUID_WICPixelFormat32bppBGR;
757 This->bitsperpixel = 0;
758 This->read_data_func = BmpFrameDecode_ReadUnsupported;
759 This->pixelformat = &GUID_WICPixelFormatUndefined;
760 FIXME("unsupported bitmap type header=%i compression=%i depth=%i\n", This->bih.bV5Size, This->bih.bV5Compression, This->bih.bV5BitCount);
765 This->initialized = TRUE;
770 static HRESULT WINAPI BmpDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID iid,
773 BmpDecoder *This = (BmpDecoder*)iface;
774 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
776 if (!ppv) return E_INVALIDARG;
778 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICBitmapDecoder, iid))
785 return E_NOINTERFACE;
788 IUnknown_AddRef((IUnknown*)*ppv);
792 static ULONG WINAPI BmpDecoder_AddRef(IWICBitmapDecoder *iface)
794 BmpDecoder *This = (BmpDecoder*)iface;
795 ULONG ref = InterlockedIncrement(&This->ref);
797 TRACE("(%p) refcount=%u\n", iface, ref);
802 static ULONG WINAPI BmpDecoder_Release(IWICBitmapDecoder *iface)
804 BmpDecoder *This = (BmpDecoder*)iface;
805 ULONG ref = InterlockedDecrement(&This->ref);
807 TRACE("(%p) refcount=%u\n", iface, ref);
811 if (This->stream) IStream_Release(This->stream);
812 if (This->framedecode) IUnknown_Release((IUnknown*)This->framedecode);
813 HeapFree(GetProcessHeap(), 0, This);
819 static HRESULT WINAPI BmpDecoder_QueryCapability(IWICBitmapDecoder *iface, IStream *pIStream,
820 DWORD *pdwCapability)
823 BmpDecoder *This = (BmpDecoder*)iface;
825 hr = BmpDecoder_ReadHeaders(This, pIStream);
826 if (FAILED(hr)) return hr;
828 if (This->read_data_func == BmpFrameDecode_ReadUnsupported)
831 *pdwCapability = WICBitmapDecoderCapabilityCanDecodeAllImages;
836 static HRESULT WINAPI BmpDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream,
837 WICDecodeOptions cacheOptions)
840 BmpDecoder *This = (BmpDecoder*)iface;
842 hr = BmpDecoder_ReadHeaders(This, pIStream);
846 This->stream = pIStream;
847 IStream_AddRef(pIStream);
853 static HRESULT WINAPI BmpDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
854 GUID *pguidContainerFormat)
856 memcpy(pguidContainerFormat, &GUID_ContainerFormatBmp, sizeof(GUID));
860 static HRESULT WINAPI BmpDecoder_GetDecoderInfo(IWICBitmapDecoder *iface,
861 IWICBitmapDecoderInfo **ppIDecoderInfo)
863 FIXME("(%p,%p): stub\n", iface, ppIDecoderInfo);
867 static HRESULT WINAPI BmpDecoder_CopyPalette(IWICBitmapDecoder *iface,
868 IWICPalette *pIPalette)
870 TRACE("(%p,%p)\n", iface, pIPalette);
872 return WINCODEC_ERR_PALETTEUNAVAILABLE;
875 static HRESULT WINAPI BmpDecoder_GetMetadataQueryReader(IWICBitmapDecoder *iface,
876 IWICMetadataQueryReader **ppIMetadataQueryReader)
878 TRACE("(%p,%p)\n", iface, ppIMetadataQueryReader);
879 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
882 static HRESULT WINAPI BmpDecoder_GetPreview(IWICBitmapDecoder *iface,
883 IWICBitmapSource **ppIBitmapSource)
885 TRACE("(%p,%p)\n", iface, ppIBitmapSource);
886 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
889 static HRESULT WINAPI BmpDecoder_GetColorContexts(IWICBitmapDecoder *iface,
890 UINT cCount, IWICColorContext **ppIColorContexts, UINT *pcActualCount)
892 TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
893 return WINCODEC_ERR_UNSUPPORTEDOPERATION;
896 static HRESULT WINAPI BmpDecoder_GetThumbnail(IWICBitmapDecoder *iface,
897 IWICBitmapSource **ppIThumbnail)
899 TRACE("(%p,%p)\n", iface, ppIThumbnail);
900 return WINCODEC_ERR_CODECNOTHUMBNAIL;
903 static HRESULT WINAPI BmpDecoder_GetFrameCount(IWICBitmapDecoder *iface,
910 static HRESULT WINAPI BmpDecoder_GetFrame(IWICBitmapDecoder *iface,
911 UINT index, IWICBitmapFrameDecode **ppIBitmapFrame)
913 BmpDecoder *This = (BmpDecoder*)iface;
915 if (index != 0) return E_INVALIDARG;
917 if (!This->stream) return WINCODEC_ERR_WRONGSTATE;
919 if (!This->framedecode)
921 This->framedecode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameDecode));
922 if (!This->framedecode) return E_OUTOFMEMORY;
924 This->framedecode->lpVtbl = &BmpFrameDecode_Vtbl;
925 This->framedecode->ref = 1;
926 This->framedecode->stream = This->stream;
927 IStream_AddRef(This->stream);
928 This->framedecode->bfh = This->bfh;
929 This->framedecode->bih = This->bih;
930 This->framedecode->pixelformat = This->pixelformat;
931 This->framedecode->bitsperpixel = This->bitsperpixel;
932 This->framedecode->read_data_func = This->read_data_func;
933 This->framedecode->imagedata = NULL;
936 *ppIBitmapFrame = (IWICBitmapFrameDecode*)This->framedecode;
937 IWICBitmapFrameDecode_AddRef((IWICBitmapFrameDecode*)This->framedecode);
942 static const IWICBitmapDecoderVtbl BmpDecoder_Vtbl = {
943 BmpDecoder_QueryInterface,
946 BmpDecoder_QueryCapability,
947 BmpDecoder_Initialize,
948 BmpDecoder_GetContainerFormat,
949 BmpDecoder_GetDecoderInfo,
950 BmpDecoder_CopyPalette,
951 BmpDecoder_GetMetadataQueryReader,
952 BmpDecoder_GetPreview,
953 BmpDecoder_GetColorContexts,
954 BmpDecoder_GetThumbnail,
955 BmpDecoder_GetFrameCount,
959 HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv)
964 TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppv);
968 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
970 This = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpDecoder));
971 if (!This) return E_OUTOFMEMORY;
973 This->lpVtbl = &BmpDecoder_Vtbl;
975 This->initialized = FALSE;
977 This->framedecode = NULL;
979 ret = IUnknown_QueryInterface((IUnknown*)This, iid, ppv);
980 IUnknown_Release((IUnknown*)This);