42 #include "sinfo_resampling.h"
44 #include "sinfo_globals.h"
48 static void reverse_tanh_kernel(
double * data,
int nn) ;
49 static double * sinfo_generate_tanh_kernel(
double steep);
89 sinfo_generate_interpolation_kernel(
const char * kernel_type)
96 int samples = KERNEL_SAMPLES ;
98 if (kernel_type==NULL) {
99 tab = sinfo_generate_interpolation_kernel(
"tanh") ;
100 }
else if (!strcmp(kernel_type,
"default")) {
101 tab = sinfo_generate_interpolation_kernel(
"tanh") ;
102 }
else if (!strcmp(kernel_type,
"sinc")) {
103 tab = cpl_malloc(samples *
sizeof(
double)) ;
105 tab[samples-1] = 0.0 ;
106 for (i=1 ; i<samples ; i++) {
107 x = (double)KERNEL_WIDTH * (
double)i/(double)(samples-1) ;
108 tab[i] = sinfo_sinc(x) ;
110 }
else if (!strcmp(kernel_type,
"sinc2")) {
111 tab = cpl_malloc(samples *
sizeof(
double)) ;
113 tab[samples-1] = 0.0 ;
114 for (i=1 ; i<samples ; i++) {
115 x = 2.0 * (double)i/(
double)(samples-1) ;
116 tab[i] = sinfo_sinc(x) ;
119 }
else if (!strcmp(kernel_type,
"lanczos")) {
120 tab = cpl_malloc(samples *
sizeof(
double)) ;
121 for (i=0 ; i<samples ; i++) {
122 x = (double)KERNEL_WIDTH * (
double)i/(double)(samples-1) ;
124 tab[i] = sinfo_sinc(x) * sinfo_sinc(x/2) ;
129 }
else if (!strcmp(kernel_type,
"hamming")) {
130 tab = cpl_malloc(samples *
sizeof(
double)) ;
132 inv_norm = 1.00 / (double)(samples - 1) ;
133 for (i=0 ; i<samples ; i++) {
135 if (i<(samples-1)/2) {
136 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
141 }
else if (!strcmp(kernel_type,
"hann")) {
142 tab = cpl_malloc(samples *
sizeof(
double)) ;
144 inv_norm = 1.00 / (double)(samples - 1) ;
145 for (i=0 ; i<samples ; i++) {
147 if (i<(samples-1)/2) {
148 tab[i] = alpha + (1-alpha) * cos(2.0*PI_NUMB*x*inv_norm) ;
153 }
else if (!strcmp(kernel_type,
"tanh")) {
154 tab = sinfo_generate_tanh_kernel(TANH_STEEPNESS) ;
179 return (
double)1.00 ;
181 return ((sin(x * (
double)PI_NUMB)) / (x * (
double)PI_NUMB)) ;
205 #define hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2))
208 sinfo_generate_tanh_kernel(
double steep)
219 width = (double)TABSPERPIX / 2.0 ;
220 samples = KERNEL_SAMPLES ;
222 inv_np = 1.00 / (double)np ;
228 x = cpl_malloc((2*np+1)*
sizeof(
double)) ;
229 for (i=0 ; i<np/2 ; i++) {
230 ind = (double)i * 2.0 * width * inv_np ;
231 x[2*i] = hk_gen(ind, steep) ;
234 for (i=np/2 ; i<np ; i++) {
235 ind = (double)(i-np) * 2.0 * width * inv_np ;
236 x[2*i] = hk_gen(ind, steep) ;
243 reverse_tanh_kernel(x, np) ;
248 kernel = cpl_malloc(samples *
sizeof(
double)) ;
249 for (i=0 ; i<samples ; i++) {
250 kernel[i] = 2.0 * width * x[2*i] * inv_np ;
268 #define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr
270 reverse_tanh_kernel(
double * data,
int nn)
280 n = (
unsigned long)nn << 1;
282 for (i=1 ; i<n ; i+=2) {
284 KERNEL_SW(data[j-1],data[i-1]);
285 KERNEL_SW(data[j],data[i]);
288 while (m>=2 && j>m) {
296 unsigned long istep = mmax << 1;
297 double theta = 2 * PI_NUMB / mmax;
298 double wtemp = sin(0.5 * theta);
299 double wpr = -2.0 * wtemp * wtemp;
300 double wpi = sin(theta);
303 for (m=1 ; m<mmax ; m+=2) {
304 for (i=m ; i<=n ; i+=istep) {
306 tempr = wr * data[j-1] - wi * data[j];
307 tempi = wr * data[j] + wi * data[j-1];
308 data[j-1] = data[i-1] - tempr;
309 data[j] = data[i] - tempi;
313 wr = (wtemp = wr) * wpr - wi * wpi + wr;
314 wi = wi * wpr + wtemp * wpi + wi;
359 sinfo_invert_linear_transform(
double *trans)
364 if (trans==NULL)
return NULL ;
365 det = (trans[0] * trans[4]) - (trans[1] * trans[3]) ;
366 if (fabs(det) < 1e-6) {
371 i_trans = cpl_calloc(6,
sizeof(
double)) ;
373 i_trans[0] = trans[4] / det ;
374 i_trans[1] = -trans[1] / det ;
375 i_trans[2] = ((trans[1] * trans[5]) - (trans[2] * trans[4])) / det ;
376 i_trans[3] = -trans[3] / det ;
377 i_trans[4] = trans[0] / det ;
378 i_trans[5] = ((trans[2] * trans[3]) - (trans[0] * trans[5])) / det ;
#define sinfo_msg_error(...)
Print an error message.