Signed-off-by: Vincent Povirk vincent@codeweavers.com --- dlls/windowscodecs/bmpencode.c | 3 ++- dlls/windowscodecs/jpegformat.c | 3 ++- dlls/windowscodecs/main.c | 24 +++++++++++++++++++++++- dlls/windowscodecs/pngformat.c | 4 +++- dlls/windowscodecs/tests/bmpformat.c | 2 +- dlls/windowscodecs/tiffformat.c | 4 +++- dlls/windowscodecs/wincodecs_private.h | 2 +- 7 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/dlls/windowscodecs/bmpencode.c b/dlls/windowscodecs/bmpencode.c index 3b77517a8d9..2f0c05a5df3 100644 --- a/dlls/windowscodecs/bmpencode.c +++ b/dlls/windowscodecs/bmpencode.c @@ -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; diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c index 0ecbbf48fce..9460e6913fd 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c @@ -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; diff --git a/dlls/windowscodecs/main.c b/dlls/windowscodecs/main.c index 78281519b81..94d66407820 100644 --- a/dlls/windowscodecs/main.c +++ b/dlls/windowscodecs/main.c @@ -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); diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c index a79df632ef1..207a81d4d27 100644 --- a/dlls/windowscodecs/pngformat.c +++ b/dlls/windowscodecs/pngformat.c @@ -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; diff --git a/dlls/windowscodecs/tests/bmpformat.c b/dlls/windowscodecs/tests/bmpformat.c index 9de138130e5..183fc461001 100644 --- a/dlls/windowscodecs/tests/bmpformat.c +++ b/dlls/windowscodecs/tests/bmpformat.c @@ -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); diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c index 295330aea2c..60592e0cb8a 100644 --- a/dlls/windowscodecs/tiffformat.c +++ b/dlls/windowscodecs/tiffformat.c @@ -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; diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index 2b3b10b7ee8..7686e80715f 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -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;