i need to implement the following formula in c-code: https://en.wikipedia.org/wiki/Lanczos_resampling Therefore i'm using the multidimensional interpolation approach:
where L(x-i) or L(y-i) is:
I'm using the ppm image format to get rgb values trough a small script. This is my actual lanczos approach now:
double _L(int param) {
/*
LANCZOS KERNEL
*/
int a = 2; // factor "a" from formula
if(param == 0) {
return 1;
}
if(abs(param) > 0 && abs(param) < a) {
return (a*sin(PI*param) * sin((PI*param)/a))/(PI*PI*param*param)
}
return 0;
}
void lanczos_interpolation(PPMImage *img) {
if(img) {
int start_i, start_j, limit_i, limit_j;
int a = 2; // factor "a" from formula
samples_ij = img->x*img->y; // "sij" from formula
for(x = 0;x < img->x;x++) {
for(y = 0;y = < img->y;y++) {
start_i = floor(x)-a+1:
limit_i = floor(x)+a;
for(i = start_i;i <= limit_i;i++) {
start_j = floor(y)-a+1:
limit_j = floor(y)+a;
for(i = start_i;i <= limit_i;i++) {
img->data[x+(W*y)].red = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].green = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].blue = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
}
}
}
}
}
}
This part of the code confused me a lot:
img->data[x+(W*y)].red = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].green = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].blue = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
Can someone help me to get along with this lanczos interpolation in c? Here is my complete C-File:
Thanks!