5 General convolution for 2d decoupled filters
6 end effects are acounted for by increasing
7 scaling the result with the sum of used coefficients
9 coeff: (double array) coefficients for filter
10 len: length of filter.. number of coefficients
11 note that this has to be an odd number
12 (since the filter is even);
16 i_conv(i_img *im, const double *coeff,int len) {
17 i_img_dim xo, yo; /* output pixel co-ordinate */
20 double res[MAXCHANNELS];
23 mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
27 i_push_error(0, "there must be at least one coefficient");
34 for (c = 0; c < len; ++c)
38 i_push_error(0, "sum of coefficients is zero");
42 timg = i_sametype(im, im->xsize, im->ysize);
46 /* don't move the calculation of pc up here, it depends on which pixels
48 for(yo = 0; yo < im->ysize; yo++) {
49 for(xo = 0; xo < im->xsize; xo++) {
50 for(ch = 0;ch < im->channels; ch++)
52 for(c = 0;c < len; c++) {
53 i_img_dim xi = xo + c - center;
56 else if (xi >= im->xsize)
59 if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
60 for(ch = 0; ch < im->channels; ch++)
61 res[ch] += (rcolor.channel[ch]) *coeff[c];
65 for(ch = 0; ch < im->channels; ch++) {
66 double temp = res[ch] / pc;
68 temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
70 IM_PPIX(timg, xo, yo, &rcolor);
74 for(xo = 0; xo < im->xsize; xo++) {
75 for(yo = 0;yo < im->ysize; yo++) {
76 for(ch = 0; ch < im->channels; ch++)
78 for(c = 0; c < len; c++) {
79 i_img_dim yi = yo + c - center;
82 else if (yi >= im->ysize)
84 if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
85 for(ch = 0;ch < im->channels; ch++)
86 res[ch] += (rcolor.channel[ch]) * coeff[c];
90 for(ch = 0;ch < im->channels; ch++) {
91 double temp = res[ch] / pc;
93 temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
95 IM_PPIX(im, xo, yo,&rcolor);