#include "imager.h" /* General convolution for 2d decoupled filters end effects are acounted for by increasing scaling the result with the sum of used coefficients coeff: (float array) coefficients for filter len: length of filter.. number of coefficients note that this has to be an odd number (since the filter is even); */ void i_conv(i_img *im,const float *coeff,int len) { int i,l,c,ch,center; double pc; double res[11]; i_img *timg; mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len)); timg = i_sametype(im, im->xsize, im->ysize); center=(len-1)/2; #code im->bits <= 8 IM_COLOR rcolor; /* don't move the calculation of pc up here, it depends on which pixels are readable */ for(l=0;lysize;l++) { for(i=0;ixsize;i++) { pc=0.0; for(ch=0;chchannels;ch++) res[ch]=0; for(c=0;cchannels;ch++) res[ch] += (rcolor.channel[ch])*coeff[c]; pc+=coeff[c]; } for(ch=0;chchannels;ch++) { double temp = res[ch]/pc; rcolor.channel[ch] = temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; } IM_PPIX(timg,i,l,&rcolor); } } for(l=0;lxsize;l++) { for(i=0;iysize;i++) { pc=0.0; for(ch=0;chchannels;ch++) res[ch]=0; for(c=0;cchannels;ch++) res[ch] += (rcolor.channel[ch])*coeff[c]; pc+=coeff[c]; } } for(ch=0;chchannels;ch++) { double temp = res[ch]/pc; rcolor.channel[ch]= temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; } IM_PPIX(im,l,i,&rcolor); } } #/code i_img_destroy(timg); }