xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/Effects/Daltonizer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2013 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef SF_EFFECTS_DALTONIZER_H_
18*38e8c45fSAndroid Build Coastguard Worker #define SF_EFFECTS_DALTONIZER_H_
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <math/mat4.h>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker namespace android {
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker // Forward declare test class
25*38e8c45fSAndroid Build Coastguard Worker class DaltonizerTest;
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker enum class ColorBlindnessType {
28*38e8c45fSAndroid Build Coastguard Worker     None,               // Disables the Daltonizer
29*38e8c45fSAndroid Build Coastguard Worker     Protanomaly,        // L (red) cone deficient
30*38e8c45fSAndroid Build Coastguard Worker     Deuteranomaly,      // M (green) cone deficient (most common)
31*38e8c45fSAndroid Build Coastguard Worker     Tritanomaly         // S (blue) cone deficient
32*38e8c45fSAndroid Build Coastguard Worker };
33*38e8c45fSAndroid Build Coastguard Worker 
34*38e8c45fSAndroid Build Coastguard Worker enum class ColorBlindnessMode {
35*38e8c45fSAndroid Build Coastguard Worker     Simulation,
36*38e8c45fSAndroid Build Coastguard Worker     Correction
37*38e8c45fSAndroid Build Coastguard Worker };
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker class Daltonizer {
40*38e8c45fSAndroid Build Coastguard Worker public:
41*38e8c45fSAndroid Build Coastguard Worker     void setType(ColorBlindnessType type);
42*38e8c45fSAndroid Build Coastguard Worker     void setMode(ColorBlindnessMode mode);
43*38e8c45fSAndroid Build Coastguard Worker     // sets level for correction saturation, [0-10].
44*38e8c45fSAndroid Build Coastguard Worker     void setLevel(int32_t level);
45*38e8c45fSAndroid Build Coastguard Worker 
46*38e8c45fSAndroid Build Coastguard Worker     // returns the color transform to apply in the shader
47*38e8c45fSAndroid Build Coastguard Worker     const mat4& operator()();
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker     // For testing.
50*38e8c45fSAndroid Build Coastguard Worker     friend class DaltonizerTest;
51*38e8c45fSAndroid Build Coastguard Worker 
52*38e8c45fSAndroid Build Coastguard Worker private:
53*38e8c45fSAndroid Build Coastguard Worker     void update();
54*38e8c45fSAndroid Build Coastguard Worker 
55*38e8c45fSAndroid Build Coastguard Worker     ColorBlindnessType mType = ColorBlindnessType::None;
56*38e8c45fSAndroid Build Coastguard Worker     ColorBlindnessMode mMode = ColorBlindnessMode::Simulation;
57*38e8c45fSAndroid Build Coastguard Worker     bool mDirty = true;
58*38e8c45fSAndroid Build Coastguard Worker     mat4 mColorTransform;
59*38e8c45fSAndroid Build Coastguard Worker     // level of error spreading, [0.0-1.0].
60*38e8c45fSAndroid Build Coastguard Worker     float mLevel = 0.7f;
61*38e8c45fSAndroid Build Coastguard Worker };
62*38e8c45fSAndroid Build Coastguard Worker 
63*38e8c45fSAndroid Build Coastguard Worker } /* namespace android */
64*38e8c45fSAndroid Build Coastguard Worker #endif /* SF_EFFECTS_DALTONIZER_H_ */
65