File Coverage

conv.im
Criterion Covered Total %
statement 56 56 100.0
branch 96 104 92.3
condition n/a
subroutine n/a
pod n/a
total 152 160 95.0


line stmt bran cond sub pod time code
1             #define IMAGER_NO_CONTEXT
2             #include "imager.h"
3             #include "imageri.h"
4              
5             /*
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
9              
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);
14             */
15              
16             int
17 64           i_conv(i_img *im, const double *coeff,int len) {
18             i_img_dim xo, yo; /* output pixel co-ordinate */
19             int c, ch, center;
20             double pc;
21             double res[MAXCHANNELS];
22             i_img *timg;
23 64           dIMCTXim(im);
24              
25 64           im_log((aIMCTX,1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
26 64           im_clear_error(aIMCTX);
27              
28 64 100         if (len < 1) {
29 2           im_push_error(aIMCTX, 0, "there must be at least one coefficient");
30 2           return 0;
31             }
32            
33 62           center=(len-1)/2;
34              
35 62           pc = 0;
36 362 100         for (c = 0; c < len; ++c)
37 300           pc += coeff[c];
38              
39 62 100         if (pc == 0) {
40 1           i_push_error(0, "sum of coefficients is zero");
41 1           return 0;
42             }
43              
44 61           timg = i_sametype(im, im->xsize, im->ysize);
45              
46 61 100         #code im->bits <= 8
47             IM_COLOR rcolor;
48             /* don't move the calculation of pc up here, it depends on which pixels
49             are readable */
50 9211 100         for(yo = 0; yo < im->ysize; yo++) {
    100          
51 1381650 100         for(xo = 0; xo < im->xsize; xo++) {
    100          
52 5220000 100         for(ch = 0;ch < im->channels; ch++)
    100          
53 3847500           res[ch] = 0;
54 8055000 100         for(c = 0;c < len; c++) {
    100          
55 6682500           i_img_dim xi = xo + c - center;
56 6682500 100         if (xi < 0)
    100          
57 26250           xi = 0;
58 6656250 100         else if (xi >= im->xsize)
    100          
59 26250           xi = im->xsize - 1;
60              
61 6682500 50         if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
    50          
62 25380000 100         for(ch = 0; ch < im->channels; ch++)
    100          
63 18697500           res[ch] += (rcolor.channel[ch]) *coeff[c];
64             }
65             }
66 1372500 50         im_assert(pc != 0);
    50          
67 5220000 100         for(ch = 0; ch < im->channels; ch++) {
    100          
68 3847500           double temp = res[ch] / pc;
69 2970000 100         rcolor.channel[ch] =
    100          
70 877500 100         temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
    100          
71             }
72 1372500           IM_PPIX(timg, xo, yo, &rcolor);
73             }
74             }
75              
76 9211 100         for(xo = 0; xo < im->xsize; xo++) {
    100          
77 1381650 100         for(yo = 0;yo < im->ysize; yo++) {
    100          
78 5220000 100         for(ch = 0; ch < im->channels; ch++)
    100          
79 3847500           res[ch] = 0;
80 8055000 100         for(c = 0; c < len; c++) {
    100          
81 6682500           i_img_dim yi = yo + c - center;
82 6682500 100         if (yi < 0)
    100          
83 26250           yi = 0;
84 6656250 100         else if (yi >= im->ysize)
    100          
85 26250           yi = im->ysize - 1;
86 6682500 50         if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
    50          
87 25380000 100         for(ch = 0;ch < im->channels; ch++)
    100          
88 18697500           res[ch] += (rcolor.channel[ch]) * coeff[c];
89             }
90             }
91 1372500 50         im_assert(pc != 0);
    50          
92 5220000 100         for(ch = 0;ch < im->channels; ch++) {
    100          
93 3847500           double temp = res[ch] / pc;
94 2970000 100         rcolor.channel[ch] =
    100          
95 877500 100         temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
    100          
96             }
97 1372500           IM_PPIX(im, xo, yo,&rcolor);
98             }
99             }
100             #/code
101              
102 61           i_img_destroy(timg);
103              
104 64           return 1;
105             }