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 #ifndef IMAGE_FILTER_IMPL_H
17 #define IMAGE_FILTER_IMPL_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "base_impl.h"
23 
24 #include "effect/shader_effect.h"
25 #include "utils/scalar.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class Data;
31 class ImageFilter;
32 class ColorFilter;
33 enum class GradientDir : uint8_t {
34     LEFT = 0,
35     TOP,
36     RIGHT,
37     BOTTOM,
38     LEFT_TOP,
39     LEFT_BOTTOM,
40     RIGHT_TOP,
41     RIGHT_BOTTOM,
42 };
43 
44 enum class GradientBlurType : uint8_t {
45     ALPHA_BLEND = 0,
46     RADIUS_GRADIENT,
47 };
48 
49 enum class ImageBlurType : uint8_t {
50     KAWASE = 0,
51     GAUSS,
52 };
53 
54 class ImageFilterImpl : public BaseImpl {
55 public:
ImageFilterImpl()56     ImageFilterImpl() noexcept {}
~ImageFilterImpl()57     ~ImageFilterImpl() override {}
58 
59     virtual void InitWithBlur(scalar sigmaX, scalar sigmaY, TileMode mode, const std::shared_ptr<ImageFilter> f,
60         ImageBlurType blurType, const Rect& cropRect) = 0;
61     virtual void InitWithColor(const ColorFilter& colorFilter,
62         const std::shared_ptr<ImageFilter> f, const Rect& cropRect) = 0;
63     virtual void InitWithColorBlur(const ColorFilter& colorFilter, scalar sigmaX, scalar sigmaY,
64         ImageBlurType blurType, const Rect& cropRect) = 0;
65     virtual void InitWithOffset(scalar dx, scalar dy, const std::shared_ptr<ImageFilter> f, const Rect& cropRect) = 0;
66     virtual void InitWithArithmetic(const std::vector<scalar>& coefficients, bool enforcePMColor,
67         const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2, const Rect& cropRect) = 0;
68     virtual void InitWithCompose(const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2) = 0;
69     virtual void InitWithGradientBlur(float radius, const std::vector<std::pair<float, float>>& fractionStops,
70         GradientDir direction, GradientBlurType blurType,
71         const std::shared_ptr<ImageFilter> f) = 0;
72     virtual std::shared_ptr<Data> Serialize() const = 0;
73     virtual bool Deserialize(std::shared_ptr<Data> data) = 0;
74     virtual void InitWithBlend(BlendMode mode, const Rect& cropRect, std::shared_ptr<ImageFilter> background,
75         std::shared_ptr<ImageFilter> foreground = nullptr) = 0;
76     virtual void InitWithShader(std::shared_ptr<ShaderEffect> shader, const Rect& cropRect) = 0;
77 };
78 } // namespace Drawing
79 } // namespace Rosen
80 } // namespace OHOS
81 #endif