NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
resampler.h
Go to the documentation of this file.
1// resampler.h, Separable filtering image rescaler v2.21, Rich Geldreich - richgel99@gmail.com
2// See unlicense.org text at the bottom of this file.
3#ifndef __RESAMPLER_H__
4#define __RESAMPLER_H__
5
6#define RESAMPLER_DEBUG_OPS 0
7#define RESAMPLER_DEFAULT_FILTER "lanczos4"
8
9#define RESAMPLER_MAX_DIMENSION 16384
10
11// float or double
12typedef double Resample_Real;
13
15{
16 public:
18
19 struct Contrib
20 {
22 unsigned short pixel;
23 };
24
26 {
27 unsigned short n;
29 };
30
32 {
36 };
37
38 enum Status
39 {
44 };
45
46 // src_x/src_y - Input dimensions
47 // dst_x/dst_y - Output dimensions
48 // boundary_op - How to sample pixels near the image boundaries
49 // sample_low/sample_high - Clamp output samples to specified range, or disable clamping if sample_low >= sample_high
50 // Pclist_x/Pclist_y - Optional pointers to contributor lists from another instance of a Resampler
51 // src_x_ofs/src_y_ofs - Offset input image by specified amount (fractional values okay)
53 int src_x, int src_y,
54 int dst_x, int dst_y,
55 Boundary_Op boundary_op = BOUNDARY_CLAMP,
56 Resample_Real sample_low = 0.0f, Resample_Real sample_high = 0.0f,
57 const char* Pfilter_name = RESAMPLER_DEFAULT_FILTER,
58 Contrib_List* Pclist_x = NULL,
59 Contrib_List* Pclist_y = NULL,
60 Resample_Real filter_x_scale = 1.0f,
61 Resample_Real filter_y_scale = 1.0f,
62 Resample_Real src_x_ofs = 0.0f,
63 Resample_Real src_y_ofs = 0.0f);
64
65 ~Resampler();
66
67 // Reinits resampler so it can handle another frame.
68 void restart();
69
70 // false on out of memory.
71 bool put_line(const Sample* Psrc);
72
73 // NULL if no scanlines are currently available (give the resampler more scanlines!)
74 const Sample* get_line();
75
76 Status status() const
77 {
78 return m_status;
79 }
80
81 // Returned contributor lists can be shared with another Resampler.
82 void get_clists(Contrib_List** ptr_clist_x, Contrib_List** ptr_clist_y);
84 {
85 return m_Pclist_x;
86 }
88 {
89 return m_Pclist_y;
90 }
91
92 // Filter accessors.
93 static int get_filter_num();
94 static char* get_filter_name(int filter_num);
95
96 private:
100
101#ifdef RESAMPLER_DEBUG_OPS
103#endif
104
106
111
113
116
119
122
124
126 unsigned char* m_Psrc_y_flag;
127
128 // The maximum number of scanlines that can be buffered at one time.
130
131 struct Scan_Buf
132 {
135 };
136
138
141
143
144 void resample_x(Sample* Pdst, const Sample* Psrc);
145 void scale_y_mov(Sample* Ptmp, const Sample* Psrc, Resample_Real weight, int dst_x);
146 void scale_y_add(Sample* Ptmp, const Sample* Psrc, Resample_Real weight, int dst_x);
147 void clamp(Sample* Pdst, int n);
148 void resample_y(Sample* Pdst);
149
150 int reflect(const int j, const int src_x, const Boundary_Op boundary_op);
151
153 int src_x, int dst_x, Boundary_Op boundary_op,
154 Resample_Real (*Pfilter)(Resample_Real),
155 Resample_Real filter_support,
156 Resample_Real filter_scale,
157 Resample_Real src_ofs);
158
159 inline int count_ops(Contrib_List* Pclist, int k)
160 {
161 int i, t = 0;
162 for (i = 0; i < k; i++)
163 t += Pclist[i].n;
164 return (t);
165 }
166
169
171 {
172 if (f < m_lo)
173 f = m_lo;
174 else if (f > m_hi)
175 f = m_hi;
176 return f;
177 }
178};
179
180#endif // __RESAMPLER_H__
181
182// This is free and unencumbered software released into the public domain.
183//
184// Anyone is free to copy, modify, publish, use, compile, sell, or
185// distribute this software, either in source code form or as a compiled
186// binary, for any purpose, commercial or non-commercial, and by any
187// means.
188//
189// In jurisdictions that recognize copyright laws, the author or authors
190// of this software dedicate any and all copyright interest in the
191// software to the public domain. We make this dedication for the benefit
192// of the public at large and to the detriment of our heirs and
193// successors. We intend this dedication to be an overt act of
194// relinquishment in perpetuity of all present and future rights to this
195// software under copyright law.
196//
197// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
198// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
199// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
200// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
201// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
202// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
203// OTHER DEALINGS IN THE SOFTWARE.
204//
205// For more information, please refer to <http://unlicense.org/>
Contrib_List * m_Pclist_x
Definition: resampler.h:117
void restart()
Definition: resampler.cpp:1002
void get_clists(Contrib_List **ptr_clist_x, Contrib_List **ptr_clist_y)
Definition: resampler.cpp:1219
Resample_Real Sample
Definition: resampler.h:17
Sample * m_Pdst_buf
Definition: resampler.h:114
static int get_filter_num()
Definition: resampler.cpp:1228
bool m_clist_x_forced
Definition: resampler.h:120
const Sample * get_line()
Definition: resampler.cpp:924
Resample_Real clamp_sample(Resample_Real f) const
Definition: resampler.h:170
Contrib_List * get_clist_x() const
Definition: resampler.h:83
int m_resample_src_x
Definition: resampler.h:107
bool m_clist_y_forced
Definition: resampler.h:121
@ BOUNDARY_WRAP
Definition: resampler.h:33
@ BOUNDARY_REFLECT
Definition: resampler.h:34
@ BOUNDARY_CLAMP
Definition: resampler.h:35
Boundary_Op m_boundary_op
Definition: resampler.h:112
int count_ops(Contrib_List *Pclist, int k)
Definition: resampler.h:159
Scan_Buf * m_Pscan_buf
Definition: resampler.h:137
int m_resample_dst_x
Definition: resampler.h:109
Contrib_List * make_clist(int src_x, int dst_x, Boundary_Op boundary_op, Resample_Real(*Pfilter)(Resample_Real), Resample_Real filter_support, Resample_Real filter_scale, Resample_Real src_ofs)
Definition: resampler.cpp:439
bool m_delay_x_resample
Definition: resampler.h:123
Resample_Real m_lo
Definition: resampler.h:167
Contrib_List * m_Pclist_y
Definition: resampler.h:118
int m_cur_src_y
Definition: resampler.h:139
static char * get_filter_name(int filter_num)
Definition: resampler.cpp:1233
void scale_y_add(Sample *Ptmp, const Sample *Psrc, Resample_Real weight, int dst_x)
Definition: resampler.cpp:768
bool put_line(const Sample *Psrc)
Definition: resampler.cpp:848
void scale_y_mov(Sample *Ptmp, const Sample *Psrc, Resample_Real weight, int dst_x)
Definition: resampler.cpp:755
int m_intermediate_x
Definition: resampler.h:105
Status status() const
Definition: resampler.h:76
unsigned char * m_Psrc_y_flag
Definition: resampler.h:126
int m_resample_src_y
Definition: resampler.h:108
int m_resample_dst_y
Definition: resampler.h:110
@ MAX_SCAN_BUF_SIZE
Definition: resampler.h:129
Status m_status
Definition: resampler.h:142
int reflect(const int j, const int src_x, const Boundary_Op boundary_op)
Definition: resampler.cpp:399
Resample_Real m_hi
Definition: resampler.h:168
void clamp(Sample *Pdst, int n)
Definition: resampler.cpp:778
int m_cur_dst_y
Definition: resampler.h:140
Resampler(const Resampler &o)
Resampler & operator=(const Resampler &o)
void resample_x(Sample *Pdst, const Sample *Psrc)
Definition: resampler.cpp:728
@ STATUS_OKAY
Definition: resampler.h:40
@ STATUS_BAD_FILTER_NAME
Definition: resampler.h:42
@ STATUS_SCAN_BUFFER_FULL
Definition: resampler.h:43
@ STATUS_OUT_OF_MEMORY
Definition: resampler.h:41
void resample_y(Sample *Pdst)
Definition: resampler.cpp:788
Contrib_List * get_clist_y() const
Definition: resampler.h:87
int total_ops
Definition: resampler.h:102
int * m_Psrc_y_count
Definition: resampler.h:125
Sample * m_Ptmp_buf
Definition: resampler.h:115
double Resample_Real
Definition: resampler.h:12
#define RESAMPLER_DEFAULT_FILTER
Definition: resampler.h:7
#define RESAMPLER_MAX_DIMENSION
Definition: resampler.h:9
unsigned short n
Definition: resampler.h:27
Resample_Real weight
Definition: resampler.h:21
unsigned short pixel
Definition: resampler.h:22
int scan_buf_y[MAX_SCAN_BUF_SIZE]
Definition: resampler.h:133
Sample * scan_buf_l[MAX_SCAN_BUF_SIZE]
Definition: resampler.h:134