wine-staging/patches/windowscodecs-32bppGrayFloat/0004-windowscodecs-Fix-32bppGrayFloat-to-8bppGray-convers.patch

45 lines
2.0 KiB
Diff

From 6d2db3592f0eccdef65691c51d16e3bb7558e8ae Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Mon, 7 Mar 2016 17:36:39 +0800
Subject: windowscodecs: Fix 32bppGrayFloat to 8bppGray conversion.
Intermediate conversion from 32bppGrayFloat to 24bppBGR applies sRGB gamma.
---
dlls/windowscodecs/converter.c | 7 ++++++-
dlls/windowscodecs/tests/converter.c | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c
index 322b2d1..bd5e978 100644
--- a/dlls/windowscodecs/converter.c
+++ b/dlls/windowscodecs/converter.c
@@ -1167,7 +1167,12 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec
{
float gray = (bgr[2] * 0.2126f + bgr[1] * 0.7152f + bgr[0] * 0.0722f) / 255.0f;
- gray = to_sRGB_component(gray) * 255.0f;
+ /* conversion from 32bppGrayFloat to 24bppBGR has already applied sRGB gamma */
+ if (source_format == format_32bppGrayFloat)
+ gray *= 255.0f;
+ else
+ gray = to_sRGB_component(gray) * 255.0f;
+
dst[x] = (BYTE)floorf(gray + 0.51f);
bgr += 3;
}
diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c
index 9dd77a5..80766ea 100644
--- a/dlls/windowscodecs/tests/converter.c
+++ b/dlls/windowscodecs/tests/converter.c
@@ -825,6 +825,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.1