From 8bae21302f88bd6b3360334355d9d7a5c6a1ad38 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 14 Aug 2017 14:58:59 -0500 Subject: [PATCH] windowscodecs: Fix 32bppGrayFloat to 8bppGray conversion. Based on Dmitry Timoshkov's patch. Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/windowscodecs/converter.c | 37 ++++++++++++++++++++++++++++ dlls/windowscodecs/tests/converter.c | 1 + 2 files changed, 38 insertions(+) diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c index e5d61e19913..42ba2602239 100644 --- a/dlls/windowscodecs/converter.c +++ b/dlls/windowscodecs/converter.c @@ -1149,6 +1149,43 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec return S_OK; } + if (source_format == format_32bppGrayFloat) + { + hr = S_OK; + + if (prc) + { + srcstride = 4 * prc->Width; + srcdatasize = srcstride * prc->Height; + + srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize); + if (!srcdata) return E_OUTOFMEMORY; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata); + if (SUCCEEDED(hr)) + { + INT x, y; + BYTE *src = srcdata, *dst = pbBuffer; + + for (y=0; y < prc->Height; y++) + { + float *srcpixel = (float*)src; + BYTE *dstpixel = dst; + + for (x=0; x < prc->Width; x++) + *dstpixel++ = (BYTE)floorf(to_sRGB_component(*srcpixel++) * 255.0f + 0.51f); + + src += srcstride; + dst += cbStride; + } + } + + HeapFree(GetProcessHeap(), 0, srcdata); + } + + return hr; + } + srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index 041ca96c8ec..13aa3c11ca8 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -880,6 +880,7 @@ START_TEST(converter) test_conversion(&testdata_24bppBGR, &testdata_8bppGray, "24bppBGR -> 8bppGray", FALSE); test_conversion(&testdata_32bppBGR, &testdata_8bppGray, "32bppBGR -> 8bppGray", FALSE); test_conversion(&testdata_32bppGrayFloat, &testdata_24bppBGR_gray, "32bppGrayFloat -> 24bppBGR gray", FALSE); + test_conversion(&testdata_32bppGrayFloat, &testdata_8bppGray, "32bppGrayFloat -> 8bppGray", FALSE); test_invalid_conversion(); test_default_converter();