-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilter.h
145 lines (111 loc) · 2.3 KB
/
Filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This code is in the public domain -- [email protected]
#ifndef NV_IMAGE_FILTER_H
#define NV_IMAGE_FILTER_H
#define uint unsigned int
/// Base filter class.
class Filter
{
public:
Filter(float width);
virtual ~Filter();
float width() const { return m_width; }
float sampleDelta(float x, float scale) const;
float sampleBox(float x, float scale, int samples) const;
float sampleTriangle(float x, float scale, int samples) const;
virtual float evaluate(float x) const = 0;
protected:
const float m_width;
};
// Box filter.
class BoxFilter : public Filter
{
public:
BoxFilter();
BoxFilter(float width);
virtual float evaluate(float x) const;
};
// Triangle (bilinear/tent) filter.
class TriangleFilter : public Filter
{
public:
TriangleFilter();
TriangleFilter(float width);
virtual float evaluate(float x) const;
};
// Kaiser filter.
class KaiserFilter : public Filter
{
public:
KaiserFilter(float w);
virtual float evaluate(float x) const;
void setParameters(float a, float stretch);
private:
float alpha;
float stretch;
};
/// A 1D kernel. Used to precompute filter weights.
class Kernel1
{
public:
Kernel1(const Filter & f, int iscale, int samples = 32);
~Kernel1();
float valueAt(uint x) const {
return m_data[x];
}
int windowSize() const {
return m_windowSize;
}
float width() const {
return m_width;
}
void debugPrint();
private:
int m_windowSize;
float m_width;
float * m_data;
};
/// A 2D kernel.
class Kernel2
{
public:
Kernel2(uint width);
Kernel2(const Kernel2 & k);
~Kernel2();
void normalize();
void transpose();
float valueAt(uint x, uint y) const {
return m_data[y * m_windowSize + x];
}
uint windowSize() const {
return m_windowSize;
}
private:
const uint m_windowSize;
float * m_data;
};
/// A 1D polyphase kernel
class PolyphaseKernel
{
public:
PolyphaseKernel(const Filter & f, uint srcLength, uint dstLength, int samples = 32);
~PolyphaseKernel();
int windowSize() const {
return m_windowSize;
}
uint length() const {
return m_length;
}
float width() const {
return m_width;
}
float valueAt(uint column, uint x) const {
return m_data[column * m_windowSize + x];
}
void debugPrint() const;
private:
int m_windowSize;
uint m_length;
float m_width;
float * m_data;
};
#endif // NV_IMAGE_FILTER_H