From fcb79b285ec57562fcf61814b9d6ae3aa88d3a47 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Thu, 27 Aug 2009 13:17:15 -0500 Subject: [PATCH] windowscodecs: implement conversion from 2bppIndexed to 32bppBGRA --- dlls/windowscodecs/converter.c | 61 ++++++++++++++++++++++++++++++++++++++++ dlls/windowscodecs/regsvr.c | 1 + 2 files changed, 62 insertions(+), 0 deletions(-) diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index af6827c..3ea0b2e 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -37,6 +37,7 @@ struct FormatConverter; enum pixelformat { format_1bppIndexed, + format_2bppIndexed, format_4bppIndexed, format_8bppIndexed, format_BlackWhite, @@ -144,6 +145,65 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe return res; } return S_OK; + case format_2bppIndexed: + if (prc) + { + HRESULT res; + UINT x, y; + BYTE *srcdata; + UINT srcstride, srcdatasize; + const BYTE *srcrow; + const BYTE *srcbyte; + BYTE *dstrow; + DWORD *dstpixel; + WICColor colors[4]; + IWICPalette *palette; + UINT actualcolors; + + res = PaletteImpl_Create(&palette); + if (FAILED(res)) return res; + + res = IWICBitmapSource_CopyPalette(This->source, palette); + if (SUCCEEDED(res)) + res = IWICPalette_GetColors(palette, 4, colors, &actualcolors); + + IWICPalette_Release(palette); + + if (FAILED(res)) return res; + + srcstride = (prc->Width+3)/4; + srcdatasize = srcstride * prc->Height; + + srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + + if (SUCCEEDED(res)) + { + srcrow = srcdata; + dstrow = pbBuffer; + for (y=0; yHeight; y++) { + srcbyte=(const BYTE*)srcrow; + dstpixel=(DWORD*)dstrow; + for (x=0; xWidth; x+=4) { + BYTE srcval; + srcval=*srcbyte++; + *dstpixel++ = colors[srcval>>6]; + if (x+1 < prc->Width) *dstpixel++ = colors[srcval>>4&0x3]; + if (x+2 < prc->Width) *dstpixel++ = colors[srcval>>2&0x3]; + if (x+1 < prc->Width) *dstpixel++ = colors[srcval&0x3]; + } + srcrow += srcstride; + dstrow += cbStride; + } + } + + HeapFree(GetProcessHeap(), 0, srcdata); + + return res; + } + return S_OK; case format_4bppIndexed: if (prc) { @@ -476,6 +536,7 @@ static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRec static const struct pixelformatinfo supported_formats[] = { {format_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL}, + {format_2bppIndexed, &GUID_WICPixelFormat2bppIndexed, NULL}, {format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL}, {format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, NULL}, {format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL}, diff --git a/dlls/windowscodecs/regsvr.c b/dlls/windowscodecs/regsvr.c index 7218c07..4a38849 100644 --- a/dlls/windowscodecs/regsvr.c +++ b/dlls/windowscodecs/regsvr.c @@ -918,6 +918,7 @@ static struct regsvr_decoder const decoder_list[] = { static GUID const * const converter_formats[] = { &GUID_WICPixelFormat1bppIndexed, + &GUID_WICPixelFormat2bppIndexed, &GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormatBlackWhite, -- 1.5.4.3