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)
286 n = (
unsigned long)nn << 1;
288 for (i=1 ; i<n ; i+=2) {
290 KERNEL_SW(data[j-1],data[i-1]);
291 KERNEL_SW(data[j],data[i]);
294 while (m>=2 && j>m) {
303 theta = 2 * PI_NUMB / mmax;
304 wtemp = sin(0.5 * theta);
305 wpr = -2.0 * wtemp * wtemp;
309 for (m=1 ; m<mmax ; m+=2) {
310 for (i=m ; i<=n ; i+=istep) {
312 tempr = wr * data[j-1] - wi * data[j];
313 tempi = wr * data[j] + wi * data[j-1];
314 data[j-1] = data[i-1] - tempr;
315 data[j] = data[i] - tempi;
319 wr = (wtemp = wr) * wpr - wi * wpi + wr;
320 wi = wi * wpr + wtemp * wpi + wi;
365 sinfo_invert_linear_transform(
double *trans)
370 if (trans==NULL)
return NULL ;
371 det = (trans[0] * trans[4]) - (trans[1] * trans[3]) ;
372 if (fabs(det) < 1e-6) {
377 i_trans = cpl_calloc(6,
sizeof(
double)) ;
379 i_trans[0] = trans[4] / det ;
380 i_trans[1] = -trans[1] / det ;
381 i_trans[2] = ((trans[1] * trans[5]) - (trans[2] * trans[4])) / det ;
382 i_trans[3] = -trans[3] / det ;
383 i_trans[4] = trans[0] / det ;
384 i_trans[5] = ((trans[2] * trans[3]) - (trans[0] * trans[5])) / det ;