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
CreateBlurFilter(float blurRadiusX,float blurRadiusY)36 std::shared_ptr<RSFilter> RSFilter::CreateBlurFilter(float blurRadiusX, float blurRadiusY)
37 {
38 return std::make_shared<RSBlurFilter>(blurRadiusX, blurRadiusY);
39 }
40
CreateMaterialFilter(int style,float dipScale,BLUR_COLOR_MODE mode,float ratio)41 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode, float ratio)
42 {
43 return std::make_shared<RSMaterialFilter>(style, dipScale, mode, ratio);
44 }
45
CreateMaterialFilter(float radius,float saturation,float brightness,uint32_t colorValue)46 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(float radius, float saturation,
47 float brightness, uint32_t colorValue)
48 {
49 MaterialParam materialParam = {radius, saturation, brightness, Color::FromArgbInt(colorValue)};
50 return std::make_shared<RSMaterialFilter>(materialParam, BLUR_COLOR_MODE::DEFAULT);
51 }
52
CreateLightUpEffectFilter(float lightUpDegree)53 std::shared_ptr<RSFilter> RSFilter::CreateLightUpEffectFilter(float lightUpDegree)
54 {
55 return std::make_shared<RSLightUpEffectFilter>(lightUpDegree);
56 }
57
operator +(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)58 std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
59 {
60 if (lhs == nullptr) {
61 return rhs;
62 }
63 if (rhs == nullptr) {
64 return lhs;
65 }
66 return lhs->Add(rhs);
67 }
68
operator -(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)69 std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
70 {
71 if (rhs == nullptr) {
72 return lhs;
73 }
74 if (lhs == nullptr) {
75 return rhs->Negate();
76 }
77 return lhs->Sub(rhs);
78 }
79
operator *(const std::shared_ptr<RSFilter> & lhs,float rhs)80 std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs)
81 {
82 if (lhs == nullptr) {
83 return nullptr;
84 }
85 return lhs->Multiply(rhs);
86 }
87 } // namespace Rosen
88 } // namespace OHOS
89