windowscodecs: Implement conversion from 2bppIndexed to 32bppBGRA.

This commit is contained in:
Vincent Povirk 2009-08-27 13:17:15 -05:00 committed by Alexandre Julliard
parent 3b1fde1668
commit b952c5726d
2 changed files with 62 additions and 0 deletions

View File

@ -37,6 +37,7 @@ struct FormatConverter;
enum pixelformat { enum pixelformat {
format_1bppIndexed, format_1bppIndexed,
format_2bppIndexed,
format_4bppIndexed, format_4bppIndexed,
format_8bppIndexed, format_8bppIndexed,
format_BlackWhite, format_BlackWhite,
@ -144,6 +145,65 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
return res; return res;
} }
return S_OK; 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; y<prc->Height; y++) {
srcbyte=(const BYTE*)srcrow;
dstpixel=(DWORD*)dstrow;
for (x=0; x<prc->Width; 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: case format_4bppIndexed:
if (prc) if (prc)
{ {
@ -476,6 +536,7 @@ static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRec
static const struct pixelformatinfo supported_formats[] = { static const struct pixelformatinfo supported_formats[] = {
{format_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL}, {format_1bppIndexed, &GUID_WICPixelFormat1bppIndexed, NULL},
{format_2bppIndexed, &GUID_WICPixelFormat2bppIndexed, NULL},
{format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL}, {format_4bppIndexed, &GUID_WICPixelFormat4bppIndexed, NULL},
{format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, NULL}, {format_8bppIndexed, &GUID_WICPixelFormat8bppIndexed, NULL},
{format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL}, {format_BlackWhite, &GUID_WICPixelFormatBlackWhite, NULL},

View File

@ -918,6 +918,7 @@ static struct regsvr_decoder const decoder_list[] = {
static GUID const * const converter_formats[] = { static GUID const * const converter_formats[] = {
&GUID_WICPixelFormat1bppIndexed, &GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat2bppIndexed,
&GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite,