1 /*
2 * Copyright (c) 2021-2023 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
16 #include "render/rs_filter.h"
17
18 #include "platform/common/rs_log.h"
19 #include "render/rs_blur_filter.h"
20 #include "render/rs_material_filter.h"
21 #include "render/rs_light_up_effect_filter.h"
22
23 namespace OHOS {
24 namespace Rosen {
RSFilter()25 RSFilter::RSFilter()
26 : type_(FilterType::NONE)
27 {}
28
~RSFilter()29 RSFilter::~RSFilter() {}
30
GetDescription()31 std::string RSFilter::GetDescription()
32 {
33 return "RSFilter " + std::to_string(type_);
34 }
35
GetDetailedDescription()36 std::string RSFilter::GetDetailedDescription()
37 {
38 return "RSFilter " + std::to_string(type_);
39 }
40
CreateBlurFilter(float blurRadiusX,float blurRadiusY,bool disableSystemAdaptation)41 std::shared_ptr<RSFilter> RSFilter::CreateBlurFilter(float blurRadiusX, float blurRadiusY,
42 bool disableSystemAdaptation)
43 {
44 return std::make_shared<RSBlurFilter>(blurRadiusX, blurRadiusY);
45 }
46
CreateMaterialFilter(int style,float dipScale,BLUR_COLOR_MODE mode,float ratio,bool disableSystemAdaptation)47 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode,
48 float ratio, bool disableSystemAdaptation)
49 {
50 return std::make_shared<RSMaterialFilter>(style, dipScale, mode, ratio);
51 }
52
CreateMaterialFilter(float radius,float saturation,float brightness,uint32_t colorValue,BLUR_COLOR_MODE mode,bool disableSystemAdaptation)53 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(float radius, float saturation,
54 float brightness, uint32_t colorValue, BLUR_COLOR_MODE mode, bool disableSystemAdaptation)
55 {
56 MaterialParam materialParam = {radius, saturation, brightness, Color::FromArgbInt(colorValue)};
57 return std::make_shared<RSMaterialFilter>(materialParam, mode);
58 }
59
CreateLightUpEffectFilter(float lightUpDegree)60 std::shared_ptr<RSFilter> RSFilter::CreateLightUpEffectFilter(float lightUpDegree)
61 {
62 return std::make_shared<RSLightUpEffectFilter>(lightUpDegree);
63 }
64
RadiusVp2Sigma(float radiusVp,float dipScale)65 float RSFilter::RadiusVp2Sigma(float radiusVp, float dipScale)
66 {
67 float radiusPx = radiusVp * dipScale;
68 return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f;
69 }
70
operator +(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)71 std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
72 {
73 if (lhs == nullptr) {
74 return rhs;
75 }
76 if (rhs == nullptr) {
77 return lhs;
78 }
79 return lhs->Add(rhs);
80 }
81
operator -(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)82 std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
83 {
84 if (rhs == nullptr) {
85 return lhs;
86 }
87 if (lhs == nullptr) {
88 return rhs->Negate();
89 }
90 return lhs->Sub(rhs);
91 }
92
operator *(const std::shared_ptr<RSFilter> & lhs,float rhs)93 std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs)
94 {
95 if (lhs == nullptr) {
96 return nullptr;
97 }
98 return lhs->Multiply(rhs);
99 }
100 } // namespace Rosen
101 } // namespace OHOS
102