Commit 4f53be1a authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

windowscodecs: Set palette in WriteSource when necessary.

parent 9891afcb
......@@ -316,7 +316,8 @@ static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
if (SUCCEEDED(hr))
{
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
This->format->guid, This->format->bpp, !This->colors && This->format->colors,
This->width, This->height);
}
return hr;
......
......@@ -1181,7 +1181,8 @@ static HRESULT WINAPI JpegEncoder_Frame_WriteSource(IWICBitmapFrameEncode *iface
if (SUCCEEDED(hr))
{
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
This->format->guid, This->format->bpp, FALSE,
This->width, This->height);
}
return hr;
......
......@@ -154,7 +154,7 @@ HRESULT configure_write_source(IWICBitmapFrameEncode *iface,
HRESULT write_source(IWICBitmapFrameEncode *iface,
IWICBitmapSource *source, const WICRect *prc,
const WICPixelFormatGUID *format, UINT bpp,
const WICPixelFormatGUID *format, UINT bpp, BOOL need_palette,
INT width, INT height)
{
IWICBitmapSource *converted_source;
......@@ -185,6 +185,28 @@ HRESULT write_source(IWICBitmapFrameEncode *iface,
return E_NOTIMPL;
}
if (need_palette)
{
IWICPalette *palette;
hr = PaletteImpl_Create(&palette);
if (SUCCEEDED(hr))
{
hr = IWICBitmapSource_CopyPalette(converted_source, palette);
if (SUCCEEDED(hr))
hr = IWICBitmapFrameEncode_SetPalette(iface, palette);
IWICPalette_Release(palette);
}
if (FAILED(hr))
{
IWICBitmapSource_Release(converted_source);
return hr;
}
}
stride = (bpp * width + 7)/8;
pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
......
......@@ -1772,7 +1772,9 @@ static HRESULT WINAPI PngFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
if (SUCCEEDED(hr))
{
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
This->format->guid, This->format->bpp,
!This->colors && This->format->color_type == PNG_COLOR_TYPE_PALETTE,
This->width, This->height);
}
return hr;
......
......@@ -1247,7 +1247,7 @@ static void test_writesource_palette(void)
ok(hr == S_OK, "GetFrame error %#x\n", hr);
hr = IWICBitmapFrameDecode_CopyPalette(frame_decode, palette);
todo_wine ok(hr == S_OK, "CopyPalette error %#x\n", hr);
ok(hr == S_OK, "CopyPalette error %#x\n", hr);
hr = IWICPalette_GetColors(palette, 2, result_palette, &result_colors);
ok(hr == S_OK, "GetColors error %#x\n", hr);
......
......@@ -1769,7 +1769,9 @@ static HRESULT WINAPI TiffFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
if (SUCCEEDED(hr))
{
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
This->format->guid, This->format->bpp,
!This->colors && This->format->bpp <= 8 && !IsEqualGUID(This->format->guid, &GUID_WICPixelFormatBlackWhite),
This->width, This->height);
}
return hr;
......
......@@ -174,7 +174,7 @@ extern HRESULT configure_write_source(IWICBitmapFrameEncode *iface,
extern HRESULT write_source(IWICBitmapFrameEncode *iface,
IWICBitmapSource *source, const WICRect *prc,
const WICPixelFormatGUID *format, UINT bpp,
const WICPixelFormatGUID *format, UINT bpp, BOOL need_palette,
INT width, INT height) DECLSPEC_HIDDEN;
extern void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment