From 3ed0164bb9a34b7cc1d0830992c348903d414624 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 6 Jul 2009 11:39:29 -0500 Subject: [PATCH] windowscodecs: implement CopyPalette for BMP decoder --- dlls/windowscodecs/bmpdecode.c | 102 ++++++++++++++++++++++++++++++++- dlls/windowscodecs/tests/bmpformat.c | 24 ++++++++ include/wincodec.idl | 1 + 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/dlls/windowscodecs/bmpdecode.c b/dlls/windowscodecs/bmpdecode.c index b81987c..61d68c1 100644 --- a/dlls/windowscodecs/bmpdecode.c +++ b/dlls/windowscodecs/bmpdecode.c @@ -189,8 +189,101 @@ static HRESULT WINAPI BmpFrameDecode_GetResolution(IWICBitmapFrameDecode *iface, static HRESULT WINAPI BmpFrameDecode_CopyPalette(IWICBitmapFrameDecode *iface, IWICPalette *pIPalette) { - FIXME("(%p,%p): stub\n", iface, pIPalette); - return E_NOTIMPL; + HRESULT hr; + BmpFrameDecode *This = (BmpFrameDecode*)iface; + TRACE("(%p,%p)\n", iface, pIPalette); + + if (This->bih.bV5Size == sizeof(BITMAPCOREHEADER)) + { + BITMAPCOREHEADER *bch = (BITMAPCOREHEADER*)&This->bih; + if (bch->bcBitCount <= 8) + { + /* 2**n colors in BGR format after the header */ + int count = 1 << bch->bcBitCount; + WICColor *wiccolors; + ULONG tablesize, bytesread; + RGBTRIPLE *bgrcolors; + LARGE_INTEGER offset; + int i; + + wiccolors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * count); + tablesize = sizeof(RGBTRIPLE) * count; + bgrcolors = HeapAlloc(GetProcessHeap(), 0, tablesize); + if (!wiccolors || !bgrcolors) + { + HeapFree(GetProcessHeap(), 0, wiccolors); + HeapFree(GetProcessHeap(), 0, bgrcolors); + return E_OUTOFMEMORY; + } + + offset.QuadPart = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPCOREHEADER); + hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL); + if (FAILED(hr)) return hr; + + hr = IStream_Read(This->stream, bgrcolors, tablesize, &bytesread); + if (FAILED(hr)) return hr; + if (bytesread != tablesize) return E_FAIL; + + for (i=0; ibih.bV5BitCount <= 8) + { + int count; + WICColor *wiccolors; + ULONG tablesize, bytesread; + LARGE_INTEGER offset; + int i; + + if (This->bih.bV5ClrUsed == 0) + count = 1 << This->bih.bV5BitCount; + else + count = This->bih.bV5ClrUsed; + + tablesize = sizeof(WICColor) * count; + wiccolors = HeapAlloc(GetProcessHeap(), 0, tablesize); + if (!wiccolors) return E_OUTOFMEMORY; + + offset.QuadPart = sizeof(BITMAPFILEHEADER) + This->bih.bV5Size; + hr = IStream_Seek(This->stream, offset, STREAM_SEEK_SET, NULL); + if (FAILED(hr)) return hr; + + hr = IStream_Read(This->stream, wiccolors, tablesize, &bytesread); + if (FAILED(hr)) return hr; + if (bytesread != tablesize) return E_FAIL; + + /* convert from BGR to BGRA by setting alpha to 100% */ + for (i=0; i