1 #define IMAGER_NO_CONTEXT
6 General convolution for 2d decoupled filters
7 end effects are acounted for by increasing
8 scaling the result with the sum of used coefficients
10 coeff: (double array) coefficients for filter
11 len: length of filter.. number of coefficients
12 note that this has to be an odd number
13 (since the filter is even);
17 i_conv(i_img *im, const double *coeff,int len) {
18 i_img_dim xo, yo; /* output pixel co-ordinate */
21 double res[MAXCHANNELS];
25 im_log((aIMCTX,1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
26 im_clear_error(aIMCTX);
29 im_push_error(aIMCTX, 0, "there must be at least one coefficient");
36 for (c = 0; c < len; ++c)
40 i_push_error(0, "sum of coefficients is zero");
44 timg = i_sametype(im, im->xsize, im->ysize);
48 /* don't move the calculation of pc up here, it depends on which pixels
50 for(yo = 0; yo < im->ysize; yo++) {
51 for(xo = 0; xo < im->xsize; xo++) {
52 for(ch = 0;ch < im->channels; ch++)
54 for(c = 0;c < len; c++) {
55 i_img_dim xi = xo + c - center;
58 else if (xi >= im->xsize)
61 if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
62 for(ch = 0; ch < im->channels; ch++)
63 res[ch] += (rcolor.channel[ch]) *coeff[c];
67 for(ch = 0; ch < im->channels; ch++) {
68 double temp = res[ch] / pc;
70 temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
72 IM_PPIX(timg, xo, yo, &rcolor);
76 for(xo = 0; xo < im->xsize; xo++) {
77 for(yo = 0;yo < im->ysize; yo++) {
78 for(ch = 0; ch < im->channels; ch++)
80 for(c = 0; c < len; c++) {
81 i_img_dim yi = yo + c - center;
84 else if (yi >= im->ysize)
86 if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
87 for(ch = 0;ch < im->channels; ch++)
88 res[ch] += (rcolor.channel[ch]) * coeff[c];
92 for(ch = 0;ch < im->channels; ch++) {
93 double temp = res[ch] / pc;
95 temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
97 IM_PPIX(im, xo, yo,&rcolor);