ScummVM API documentation
Filters.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_QDCORE_UTIL_FILTERS_H
23#define QDENGINE_QDCORE_UTIL_FILTERS_H
24
25
26
27namespace QDEngine {
28
29namespace scl {
30
32public:
33 CGenericFilter(double dWidth) : _dWidth(dWidth) {}
34 virtual ~CGenericFilter() {}
35
36 double getWidth() const {
37 return _dWidth;
38 }
39 void setWidth(double dWidth) {
40 _dWidth = dWidth;
41 }
42
43 virtual double filter(double dVal) = 0;
44
45protected:
46
47#define FILTER_PI double (3.1415926535897932384626433832795)
48#define FILTER_2PI double (2.0 * 3.1415926535897932384626433832795)
49#define FILTER_4PI double (4.0 * 3.1415926535897932384626433832795)
50
51 double _dWidth;
52};
53
54class CBoxFilter : public CGenericFilter {
55public:
56 CBoxFilter(double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
57 ~CBoxFilter() {}
58
59 double filter(double dVal) {
60 return (fabs(dVal) <= _dWidth ? 1.0 : 0.0);
61 }
62};
63
65public:
66 CBilinearFilter(double dWidth = double(1.0)) : CGenericFilter(dWidth) {}
68
69 double filter(double dVal) {
70 dVal = fabs(dVal);
71 return (dVal < _dWidth ? _dWidth - dVal : 0.0);
72 }
73};
74
76public:
77 CGaussianFilter(double dWidth = double(3.0)) : CGenericFilter(dWidth) {}
79
80 double filter(double dVal) {
81 if (fabs(dVal) > _dWidth) {
82 return 0.0;
83 }
84 return exp(-dVal * dVal / 2.0) / sqrt(FILTER_2PI);
85 }
86};
87
89public:
90 CHammingFilter(double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
92
93 double filter(double dVal) {
94 if (fabs(dVal) > _dWidth)
95 return 0.0;
96
97 double dWindow = 0.54 + 0.46 * cos(FILTER_2PI * dVal);
98 double dSinc = (dVal == 0) ? 1.0 : sin(FILTER_PI * dVal) / (FILTER_PI * dVal);
99 return dWindow * dSinc;
100 }
101};
102
104public:
105 CBlackmanFilter(double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
107
108 double filter(double dVal) {
109 if (fabs(dVal) > _dWidth)
110 return 0.0;
111
112 double dN = 2.0 * _dWidth + 1.0;
113 return 0.42 + 0.5 * cos(FILTER_2PI * dVal / (dN - 1.0)) + 0.08 * cos(FILTER_4PI * dVal / (dN - 1.0));
114 }
115};
116
117} // namespace scl
118
119} // namespace QDEngine
120
121#endif // QDENGINE_QDCORE_UTIL_FILTERS_H
Definition: Filters.h:64
Definition: Filters.h:103
Definition: Filters.h:54
Definition: Filters.h:75
Definition: Filters.h:31
Definition: Filters.h:88
Базовый класс для игровых ресурсов.
Definition: console.h:28