- eliminate unused variables and static functions
[imager.git] / conv.c
CommitLineData
02d1d628
AMH
1#include "image.h"
2
3/*
4 General convolution for 2d decoupled filters
5 end effects are acounted for by increasing
6 scaling the result with the sum of used coefficients
7
8 coeff: (float array) coefficients for filter
9 len: length of filter.. number of coefficients
10 note that this has to be an odd number
11 (since the filter is even);
12*/
13
14void
15i_conv(i_img *im,float *coeff,int len) {
16 int i,l,c,ch,center;
17 float pc;
18 i_color rcolor;
19 float res[11];
20 i_img timg;
21
a73aeb5f 22 mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
02d1d628
AMH
23
24 i_img_empty_ch(&timg,im->xsize,im->ysize,im->channels);
25
26 center=(len-1)/2;
27
54e78067
TC
28 pc = 0.0;
29 for (c = 0; c < len; ++c) {
30 pc += coeff[c];
31 }
02d1d628
AMH
32
33 for(l=0;l<im->ysize;l++) {
34 for(i=0;i<im->xsize;i++) {
02d1d628
AMH
35 for(ch=0;ch<im->channels;ch++) res[ch]=0;
36 for(c=0;c<len;c++)
37 if (i_gpix(im,i+c-center,l,&rcolor)!=-1) {
0b76fec8
TC
38 for(ch=0;ch<im->channels;ch++)
39 res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
02d1d628 40 }
0b76fec8
TC
41 for(ch=0;ch<im->channels;ch++) {
42 double temp = res[ch]/pc;
43 rcolor.channel[ch] =
44 temp < 0 ? 0 : temp > 255 ? 255 : (unsigned char)temp;
45 }
02d1d628
AMH
46 i_ppix(&timg,i,l,&rcolor);
47 }
48 }
49
50 for(l=0;l<im->xsize;l++)
51 {
52 for(i=0;i<im->ysize;i++)
53 {
02d1d628
AMH
54 for(ch=0;ch<im->channels;ch++) res[ch]=0;
55 for(c=0;c<len;c++)
56 if (i_gpix(&timg,l,i+c-center,&rcolor)!=-1)
57 {
0b76fec8
TC
58 for(ch=0;ch<im->channels;ch++)
59 res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
02d1d628 60 }
0b76fec8
TC
61 for(ch=0;ch<im->channels;ch++) {
62 double temp = res[ch]/pc;
63 rcolor.channel[ch]=
64 temp < 0 ? 0 : temp > 255 ? 255 : (unsigned char)temp;
65 }
02d1d628
AMH
66 i_ppix(im,l,i,&rcolor);
67 }
68 }
a73aeb5f 69 i_img_exorcise(&timg);
02d1d628
AMH
70}
71
72
73
74
75
76
77
78
79