windowscodecs: Fix 32bppGrayFloat to 8bppGray conversion.
Vincent Povirk
vincent at codeweavers.com
Mon Aug 14 14:58:59 CDT 2017
Based on Dmitry Timoshkov's patch in Staging.
This adds a separate conversion path because I don't like having code in
one conversion function that depends the inconsistencies of another one.
Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
---
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 e5d61e1..42ba260 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 041ca96..13aa3c1 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();
--
2.7.4
More information about the wine-patches
mailing list