Add color correction level API to native
Test: Locally tested with other cls of the same topic, and also added unit tests and ran 'atest SurfaceFlinger_test'
Bug: 322829049
Change-Id: I494ce39608ddf84fb74b60291511477672ca4e36
diff --git a/services/surfaceflinger/Effects/Daltonizer.cpp b/services/surfaceflinger/Effects/Daltonizer.cpp
index a7090c5..65f2605 100644
--- a/services/surfaceflinger/Effects/Daltonizer.cpp
+++ b/services/surfaceflinger/Effects/Daltonizer.cpp
@@ -37,6 +37,18 @@
}
}
+void Daltonizer::setLevel(int32_t level) {
+ if (level < 0 || level > 10) {
+ return;
+ }
+
+ float newLevel = level / 10.0f;
+ if (std::fabs(mLevel - newLevel) > 0.09f) {
+ mDirty = true;
+ }
+ mLevel = newLevel;
+}
+
const mat4& Daltonizer::operator()() {
if (mDirty) {
mDirty = false;
@@ -117,25 +129,24 @@
// a color blind user and "spread" this error onto the healthy cones.
// The matrices below perform this last step and have been chosen arbitrarily.
- // The amount of correction can be adjusted here.
-
+ // Scale 0 represents no change (mColorTransform is identical matrix).
// error spread for protanopia
- const mat4 errp( 1.0, 0.7, 0.7, 0,
- 0.0, 1.0, 0.0, 0,
- 0.0, 0.0, 1.0, 0,
- 0, 0, 0, 1);
+ const mat4 errp(1.0, mLevel, mLevel, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
// error spread for deuteranopia
- const mat4 errd( 1.0, 0.0, 0.0, 0,
- 0.7, 1.0, 0.7, 0,
- 0.0, 0.0, 1.0, 0,
- 0, 0, 0, 1);
+ const mat4 errd( 1.0, 0.0, 0.0, 0.0,
+ mLevel, 1.0, mLevel, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
// error spread for tritanopia
- const mat4 errt( 1.0, 0.0, 0.0, 0,
- 0.0, 1.0, 0.0, 0,
- 0.7, 0.7, 1.0, 0,
- 0, 0, 0, 1);
+ const mat4 errt( 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ mLevel, mLevel, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
// And the magic happens here...
// We construct the matrix that will perform the whole correction.
diff --git a/services/surfaceflinger/Effects/Daltonizer.h b/services/surfaceflinger/Effects/Daltonizer.h
index 2fb60e9..f5eaae7 100644
--- a/services/surfaceflinger/Effects/Daltonizer.h
+++ b/services/surfaceflinger/Effects/Daltonizer.h
@@ -21,6 +21,9 @@
namespace android {
+// Forward declare test class
+class DaltonizerTest;
+
enum class ColorBlindnessType {
None, // Disables the Daltonizer
Protanomaly, // L (red) cone deficient
@@ -37,10 +40,15 @@
public:
void setType(ColorBlindnessType type);
void setMode(ColorBlindnessMode mode);
+ // sets level for correction saturation, [0-10].
+ void setLevel(int32_t level);
// returns the color transform to apply in the shader
const mat4& operator()();
+ // For testing.
+ friend class DaltonizerTest;
+
private:
void update();
@@ -48,6 +56,8 @@
ColorBlindnessMode mMode = ColorBlindnessMode::Simulation;
bool mDirty = true;
mat4 mColorTransform;
+ // level of error spreading, [0.0-1.0].
+ float mLevel = 0.7f;
};
} /* namespace android */