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 "effect/image_filter.h"
17
18 #include "impl_factory.h"
19
20 #include "impl_interface/image_filter_impl.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
ImageFilter(FilterType t,scalar x,scalar y,std::shared_ptr<ImageFilter> input)25 ImageFilter::ImageFilter(FilterType t, scalar x, scalar y, std::shared_ptr<ImageFilter> input) noexcept : ImageFilter()
26 {
27 type_ = t;
28 impl_->InitWithOffset(x, y, input);
29 }
30
ImageFilter(FilterType t,scalar x,scalar y,TileMode mode,std::shared_ptr<ImageFilter> input)31 ImageFilter::ImageFilter(FilterType t, scalar x, scalar y, TileMode mode, std::shared_ptr<ImageFilter> input) noexcept
32 : ImageFilter()
33 {
34 type_ = t;
35 impl_->InitWithBlur(x, y, mode, input);
36 }
37
ImageFilter(FilterType t,const ColorFilter & cf,std::shared_ptr<ImageFilter> input)38 ImageFilter::ImageFilter(FilterType t, const ColorFilter& cf, std::shared_ptr<ImageFilter> input) noexcept
39 : ImageFilter()
40 {
41 type_ = t;
42 impl_->InitWithColor(cf, input);
43 }
44
ImageFilter(FilterType t,const ColorFilter & cf,scalar x,scalar y)45 ImageFilter::ImageFilter(FilterType t, const ColorFilter& cf, scalar x, scalar y) noexcept
46 : ImageFilter()
47 {
48 type_ = t;
49 impl_->InitWithColorBlur(cf, x, y);
50 }
51
InitWithColorBlur(const ColorFilter & cf,scalar x,scalar y)52 void ImageFilter::InitWithColorBlur(const ColorFilter& cf, scalar x, scalar y)
53 {
54 type_ = ImageFilter::FilterType::COLOR_FILTER;
55 impl_->InitWithColorBlur(cf, x, y);
56 }
57
ImageFilter(FilterType t,const std::vector<scalar> & coefficients,bool enforcePMColor,std::shared_ptr<ImageFilter> background,std::shared_ptr<ImageFilter> foreground)58 ImageFilter::ImageFilter(FilterType t, const std::vector<scalar>& coefficients, bool enforcePMColor,
59 std::shared_ptr<ImageFilter> background, std::shared_ptr<ImageFilter> foreground) noexcept
60 :ImageFilter()
61 {
62 type_ = t;
63 impl_->InitWithArithmetic(coefficients, enforcePMColor, background, foreground);
64 }
65
ImageFilter(FilterType t,std::shared_ptr<ImageFilter> f1,std::shared_ptr<ImageFilter> f2)66 ImageFilter::ImageFilter(FilterType t, std::shared_ptr<ImageFilter> f1, std::shared_ptr<ImageFilter> f2) noexcept
67 : ImageFilter()
68 {
69 type_ = t;
70 impl_->InitWithCompose(f1, f2);
71 }
72
ImageFilter(FilterType t)73 ImageFilter::ImageFilter(FilterType t) noexcept
74 : type_(t), impl_(ImplFactory::CreateImageFilterImpl())
75 {}
76
ImageFilter()77 ImageFilter::ImageFilter() noexcept
78 : type_(ImageFilter::FilterType::NO_TYPE), impl_(ImplFactory::CreateImageFilterImpl())
79 {}
80
GetType() const81 ImageFilter::FilterType ImageFilter::GetType() const
82 {
83 return type_;
84 }
85
CreateBlurImageFilter(scalar sigmaX,scalar sigmaY,TileMode mode,std::shared_ptr<ImageFilter> input)86 std::shared_ptr<ImageFilter> ImageFilter::CreateBlurImageFilter(scalar sigmaX, scalar sigmaY, TileMode mode,
87 std::shared_ptr<ImageFilter> input)
88 {
89 return std::make_shared<ImageFilter>(ImageFilter::FilterType::BLUR, sigmaX, sigmaY, mode, input);
90 }
91
CreateColorFilterImageFilter(const ColorFilter & cf,std::shared_ptr<ImageFilter> input)92 std::shared_ptr<ImageFilter> ImageFilter::CreateColorFilterImageFilter(
93 const ColorFilter& cf, std::shared_ptr<ImageFilter> input)
94 {
95 return std::make_shared<ImageFilter>(ImageFilter::FilterType::COLOR_FILTER, cf, input);
96 }
97
CreateColorBlurImageFilter(const ColorFilter & cf,scalar sigmaX,scalar sigmaY)98 std::shared_ptr<ImageFilter> ImageFilter::CreateColorBlurImageFilter(const ColorFilter& cf,
99 scalar sigmaX, scalar sigmaY)
100 {
101 return std::make_shared<ImageFilter>(ImageFilter::FilterType::COLOR_FILTER, cf, sigmaX, sigmaY);
102 }
103
CreateOffsetImageFilter(scalar dx,scalar dy,std::shared_ptr<ImageFilter> input)104 std::shared_ptr<ImageFilter> ImageFilter::CreateOffsetImageFilter(
105 scalar dx, scalar dy, std::shared_ptr<ImageFilter> input)
106 {
107 return std::make_shared<ImageFilter>(ImageFilter::FilterType::OFFSET, dx, dy, input);
108 }
109
CreateArithmeticImageFilter(const std::vector<scalar> & coefficients,bool enforcePMColor,std::shared_ptr<ImageFilter> background,std::shared_ptr<ImageFilter> foreground)110 std::shared_ptr<ImageFilter> ImageFilter::CreateArithmeticImageFilter(const std::vector<scalar>& coefficients,
111 bool enforcePMColor, std::shared_ptr<ImageFilter> background, std::shared_ptr<ImageFilter> foreground)
112 {
113 return std::make_shared<ImageFilter>(
114 ImageFilter::FilterType::ARITHMETIC, coefficients, enforcePMColor, background, foreground);
115 }
116
CreateComposeImageFilter(std::shared_ptr<ImageFilter> f1,std::shared_ptr<ImageFilter> f2)117 std::shared_ptr<ImageFilter> ImageFilter::CreateComposeImageFilter(
118 std::shared_ptr<ImageFilter> f1, std::shared_ptr<ImageFilter> f2)
119 {
120 return std::make_shared<ImageFilter>(ImageFilter::FilterType::COMPOSE, f1, f2);
121 }
122
Serialize() const123 std::shared_ptr<Data> ImageFilter::Serialize() const
124 {
125 return impl_->Serialize();
126 }
127
Deserialize(std::shared_ptr<Data> data)128 bool ImageFilter::Deserialize(std::shared_ptr<Data> data)
129 {
130 return impl_->Deserialize(data);
131 }
132
133 } // namespace Drawing
134 } // namespace Rosen
135 } // namespace OHOS