• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, disableSystemAdaptation);
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, disableSystemAdaptation);
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,
57         Color::FromArgbInt(colorValue), disableSystemAdaptation};
58     return std::make_shared<RSMaterialFilter>(materialParam, mode);
59 }
60 
CreateLightUpEffectFilter(float lightUpDegree)61 std::shared_ptr<RSFilter> RSFilter::CreateLightUpEffectFilter(float lightUpDegree)
62 {
63     return std::make_shared<RSLightUpEffectFilter>(lightUpDegree);
64 }
65 
RadiusVp2Sigma(float radiusVp,float dipScale)66 float RSFilter::RadiusVp2Sigma(float radiusVp, float dipScale)
67 {
68     float radiusPx = radiusVp * dipScale;
69     return radiusPx > 0.0f ? BLUR_SIGMA_SCALE * radiusPx + 0.5f : 0.0f;
70 }
71 
72 } // namespace Rosen
73 } // namespace OHOS
74