OSDN Git Service

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