Fix broken opto-electronic transfer functions
Bug: 29940137
Test: colorspace_test
Change-Id: I08e558bd842df5cc6d06919279e70328d71f4710
diff --git a/libs/ui/ColorSpace.cpp b/libs/ui/ColorSpace.cpp
index 4ea3b96..a8fe4e3 100644
--- a/libs/ui/ColorSpace.cpp
+++ b/libs/ui/ColorSpace.cpp
@@ -97,7 +97,7 @@
}
static constexpr float rcpResponse(float x, float g,float a, float b, float c, float d) {
- return x >= d * c ? std::pow(x / a, 1.0f / g) - b / a : x / c;
+ return x >= d * c ? (std::pow(x, 1.0f / g) - b) / a : x / c;
}
static constexpr float response(float x, float g, float a, float b, float c, float d) {
@@ -216,7 +216,7 @@
return {
"SMPTE RP 431-2-2007 DCI (P3)",
{{float2{0.680f, 0.320f}, {0.265f, 0.690f}, {0.150f, 0.060f}}},
- {0.3127f, 0.3290f},
+ {0.314f, 0.351f},
std::bind(powf, _1, 1.0f / 2.6f),
std::bind(powf, _1, 2.6f)
};
diff --git a/libs/ui/tests/colorspace_test.cpp b/libs/ui/tests/colorspace_test.cpp
index b5a06e6..e5c2633 100644
--- a/libs/ui/tests/colorspace_test.cpp
+++ b/libs/ui/tests/colorspace_test.cpp
@@ -106,6 +106,11 @@
TEST_F(ColorSpaceTest, TransferFunctions) {
ColorSpace sRGB = ColorSpace::sRGB();
+ EXPECT_NEAR(0.0f, sRGB.getEOTF()(0.0f), 1e-6f);
+ EXPECT_NEAR(0.0f, sRGB.getOETF()(0.0f), 1e-6f);
+ EXPECT_NEAR(1.0f, sRGB.getEOTF()(1.0f), 1e-6f);
+ EXPECT_NEAR(1.0f, sRGB.getOETF()(1.0f), 1e-6f);
+
for (float v = 0.0f; v <= 0.5f; v += 1e-3f) {
ASSERT_TRUE(v >= sRGB.getEOTF()(v));
ASSERT_TRUE(v <= sRGB.getOETF()(v));