windowscodecs: Implement conversion from 2bppGray to 32bppBGRA.

This commit is contained in:
Vincent Povirk 2009-08-27 13:23:18 -05:00 committed by Alexandre Julliard
parent b952c5726d
commit 4b99c98720
2 changed files with 26 additions and 7 deletions

View File

@ -41,6 +41,7 @@ enum pixelformat {
format_4bppIndexed, format_4bppIndexed,
format_8bppIndexed, format_8bppIndexed,
format_BlackWhite, format_BlackWhite,
format_2bppGray,
format_8bppGray, format_8bppGray,
format_16bppBGR555, format_16bppBGR555,
format_16bppBGR565, format_16bppBGR565,
@ -68,6 +69,16 @@ typedef struct FormatConverter {
WICBitmapPaletteType palette_type; WICBitmapPaletteType palette_type;
} FormatConverter; } FormatConverter;
static void make_grayscale_palette(WICColor *colors, UINT num_colors)
{
int i, v;
for (i=0; i<num_colors; i++)
{
v = i * 255 / (num_colors-1);
colors[i] = 0xff000000 | v<<16 | v<<8 | v;
}
}
static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRect *prc, static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRect *prc,
UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format) UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer, enum pixelformat source_format)
{ {
@ -146,6 +157,7 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
} }
return S_OK; return S_OK;
case format_2bppIndexed: case format_2bppIndexed:
case format_2bppGray:
if (prc) if (prc)
{ {
HRESULT res; HRESULT res;
@ -160,16 +172,21 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
IWICPalette *palette; IWICPalette *palette;
UINT actualcolors; UINT actualcolors;
res = PaletteImpl_Create(&palette); if (source_format == format_2bppIndexed)
if (FAILED(res)) return res; {
res = PaletteImpl_Create(&palette);
if (FAILED(res)) return res;
res = IWICBitmapSource_CopyPalette(This->source, palette); res = IWICBitmapSource_CopyPalette(This->source, palette);
if (SUCCEEDED(res)) if (SUCCEEDED(res))
res = IWICPalette_GetColors(palette, 4, colors, &actualcolors); res = IWICPalette_GetColors(palette, 4, colors, &actualcolors);
IWICPalette_Release(palette); IWICPalette_Release(palette);
if (FAILED(res)) return res; if (FAILED(res)) return res;
}
else
make_grayscale_palette(colors, 4);
srcstride = (prc->Width+3)/4; srcstride = (prc->Width+3)/4;
srcdatasize = srcstride * prc->Height; srcdatasize = srcstride * prc->Height;
@ -540,6 +557,7 @@ static const struct pixelformatinfo supported_formats[] = {
{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},
{format_2bppGray, &GUID_WICPixelFormat2bppGray, NULL},
{format_8bppGray, &GUID_WICPixelFormat8bppGray, NULL}, {format_8bppGray, &GUID_WICPixelFormat8bppGray, NULL},
{format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL}, {format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL},
{format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL}, {format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL},

View File

@ -922,6 +922,7 @@ static GUID const * const converter_formats[] = {
&GUID_WICPixelFormat4bppIndexed, &GUID_WICPixelFormat4bppIndexed,
&GUID_WICPixelFormat8bppIndexed, &GUID_WICPixelFormat8bppIndexed,
&GUID_WICPixelFormatBlackWhite, &GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat2bppGray,
&GUID_WICPixelFormat8bppGray, &GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat16bppBGR555, &GUID_WICPixelFormat16bppBGR555,
&GUID_WICPixelFormat16bppBGR565, &GUID_WICPixelFormat16bppBGR565,