1 /*
2 * Copyright (c) 2021 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 SAMPLING_OPTIONS_H
17 #define SAMPLING_OPTIONS_H
18
19 namespace OHOS {
20 namespace Rosen {
21 namespace Drawing {
22 enum class FilterMode {
23 NEAREST,
24 LINEAR,
25 };
26
27 enum class MipmapMode {
28 NONE,
29 NEAREST,
30 LINEAR,
31 };
32
33 struct CubicResampler {
34 float cubicCoffB = 0;
35 float cubicCoffC = 0;
MitchellCubicResampler36 static constexpr CubicResampler Mitchell()
37 {
38 return { 1 / 3.0f, 1 / 3.0f };
39 }
CatmullRomCubicResampler40 static constexpr CubicResampler CatmullRom()
41 {
42 return { 0.0f, 1 / 2.0f };
43 }
44 };
45
46 class SamplingOptions {
47 public:
48 inline SamplingOptions() noexcept;
49 inline SamplingOptions(FilterMode fm) noexcept;
50 inline SamplingOptions(FilterMode fm, MipmapMode mm) noexcept;
51 inline SamplingOptions(const CubicResampler& c) noexcept;
52
~SamplingOptions()53 inline ~SamplingOptions() {}
54
55 inline bool GetUseCubic() const;
56 inline FilterMode GetFilterMode() const;
57 inline MipmapMode GetMipmapMode() const;
58 inline float GetCubicCoffB() const;
59 inline float GetCubicCoffC() const;
60
61 friend inline bool operator==(const SamplingOptions& a, const SamplingOptions& b);
62 friend inline bool operator!=(const SamplingOptions& a, const SamplingOptions& b);
63
64 private:
65 bool useCubic;
66 CubicResampler cubic;
67 FilterMode filter;
68 MipmapMode mipmap;
69 };
70
SamplingOptions()71 inline SamplingOptions::SamplingOptions() noexcept
72 : useCubic(false), filter(FilterMode::NEAREST), mipmap(MipmapMode::NONE)
73 {}
74
SamplingOptions(FilterMode fm)75 inline SamplingOptions::SamplingOptions(FilterMode fm) noexcept : useCubic(false), filter(fm), mipmap(MipmapMode::NONE)
76 {}
77
SamplingOptions(FilterMode fm,MipmapMode mm)78 inline SamplingOptions::SamplingOptions(FilterMode fm, MipmapMode mm) noexcept : useCubic(false), filter(fm), mipmap(mm)
79 {}
80
SamplingOptions(const CubicResampler & c)81 inline SamplingOptions::SamplingOptions(const CubicResampler& c) noexcept : useCubic(true), cubic(c) {}
82
GetUseCubic()83 inline bool SamplingOptions::GetUseCubic() const
84 {
85 return useCubic;
86 }
87
GetFilterMode()88 inline FilterMode SamplingOptions::GetFilterMode() const
89 {
90 return filter;
91 }
92
GetMipmapMode()93 inline MipmapMode SamplingOptions::GetMipmapMode() const
94 {
95 return mipmap;
96 }
97
GetCubicCoffB()98 inline float SamplingOptions::GetCubicCoffB() const
99 {
100 return cubic.cubicCoffB;
101 }
102
GetCubicCoffC()103 inline float SamplingOptions::GetCubicCoffC() const
104 {
105 return cubic.cubicCoffC;
106 }
107
108 inline bool operator==(const SamplingOptions& a, const SamplingOptions& b)
109 {
110 return a.useCubic == b.useCubic && a.cubic.cubicCoffB == b.cubic.cubicCoffB &&
111 a.cubic.cubicCoffC == b.cubic.cubicCoffC && a.filter == b.filter && a.mipmap == b.mipmap;
112 }
113
114 inline bool operator!=(const SamplingOptions& a, const SamplingOptions& b)
115 {
116 return !(a == b);
117 }
118 } // namespace Drawing
119 } // namespace Rosen
120 } // namespace OHOS
121 #endif