1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef UIEFFECT_EFFECT_BRIGHTNESS_BLENDER_H 16 #define UIEFFECT_EFFECT_BRIGHTNESS_BLENDER_H 17 18 #include "blender.h" 19 #include "common/rs_vector3.h" 20 #include "ui_effect/utils.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 constexpr std::pair<float, float> BRIGHTNESS_BLENDER_LIMITS {-20.f, 20.f}; // limits for brightness blender pamameters 25 26 class BrightnessBlender : public Blender { 27 public: BrightnessBlender()28 BrightnessBlender() 29 { 30 this->blenderType_ = Blender::BRIGHTNESS_BLENDER; 31 } 32 ~BrightnessBlender() override = default; 33 SetCubicRate(float cubicRate)34 void SetCubicRate(float cubicRate) 35 { 36 cubicRate_ = UIEffect::GetLimitedPara(cubicRate, BRIGHTNESS_BLENDER_LIMITS); 37 } 38 GetCubicRate()39 float GetCubicRate() const 40 { 41 return cubicRate_; 42 } 43 SetQuadRate(float quadRate)44 void SetQuadRate(float quadRate) 45 { 46 quadRate_ = UIEffect::GetLimitedPara(quadRate, BRIGHTNESS_BLENDER_LIMITS); 47 } 48 GetQuadRate()49 float GetQuadRate() const 50 { 51 return quadRate_; 52 } 53 SetLinearRate(float linearRate)54 void SetLinearRate(float linearRate) 55 { 56 linearRate_ = UIEffect::GetLimitedPara(linearRate, BRIGHTNESS_BLENDER_LIMITS); 57 } 58 GetLinearRate()59 float GetLinearRate() const 60 { 61 return linearRate_; 62 } 63 SetDegree(float degree)64 void SetDegree(float degree) 65 { 66 degree_ = UIEffect::GetLimitedPara(degree, BRIGHTNESS_BLENDER_LIMITS); 67 } 68 GetDegree()69 float GetDegree() const 70 { 71 return degree_; 72 } 73 SetSaturation(float saturation)74 void SetSaturation(float saturation) 75 { 76 saturation_ = UIEffect::GetLimitedPara(saturation, {0.0f, BRIGHTNESS_BLENDER_LIMITS.second}); 77 } 78 GetSaturation()79 float GetSaturation() const 80 { 81 return saturation_; 82 } 83 SetPositiveCoeff(const Vector3f & positiveCoeff)84 void SetPositiveCoeff(const Vector3f& positiveCoeff) 85 { 86 positiveCoeff_ = UIEffect::GetLimitedPara(positiveCoeff, BRIGHTNESS_BLENDER_LIMITS); 87 } 88 GetPositiveCoeff()89 const Vector3f& GetPositiveCoeff() const 90 { 91 return positiveCoeff_; 92 } 93 SetNegativeCoeff(const Vector3f & negativeCoeff)94 void SetNegativeCoeff(const Vector3f& negativeCoeff) 95 { 96 negativeCoeff_ = UIEffect::GetLimitedPara(negativeCoeff, BRIGHTNESS_BLENDER_LIMITS); 97 } 98 GetNegativeCoeff()99 const Vector3f& GetNegativeCoeff() const 100 { 101 return negativeCoeff_; 102 } 103 SetFraction(float fraction)104 void SetFraction(float fraction) 105 { 106 fraction_ = UIEffect::GetLimitedPara(fraction, {0.f, 1.f}); 107 } 108 GetFraction()109 float GetFraction() const 110 { 111 return fraction_; 112 } 113 114 private: 115 float cubicRate_ = 0.0f; 116 float quadRate_ = 0.0f; 117 float linearRate_ = 1.0f; 118 float degree_ = 0.0f; 119 float saturation_ = 1.0f; 120 Vector3f positiveCoeff_; 121 Vector3f negativeCoeff_; 122 float fraction_ = 1.0f; 123 }; 124 } // namespace Rosen 125 } // namespace OHOS 126 #endif // UIEFFECT_EFFECT_BRIGHTNESS_BLENDER_H 127