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 65           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 65           dIMCTXim(im);
24              
25 65           im_log((aIMCTX,1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
26 65           im_clear_error(aIMCTX);
27              
28 65 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 63           center=(len-1)/2;
34              
35 63           pc = 0;
36 368 100         for (c = 0; c < len; ++c)
37 305           pc += coeff[c];
38              
39 63 100         if (pc == 0) {
40 1           i_push_error(0, "sum of coefficients is zero");
41 1           return 0;
42             }
43              
44 62           timg = i_sametype(im, im->xsize, im->ysize);
45              
46 62 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 9362 100         for(yo = 0; yo < im->ysize; yo++) {
    100          
51 1404300 100         for(xo = 0; xo < im->xsize; xo++) {
    100          
52 5310000 100         for(ch = 0;ch < im->channels; ch++)
    100          
53 3915000           res[ch] = 0;
54 8190000 100         for(c = 0;c < len; c++) {
    100          
55 6795000           i_img_dim xi = xo + c - center;
56 6795000 100         if (xi < 0)
    100          
57 26700           xi = 0;
58 6768300 100         else if (xi >= im->xsize)
    100          
59 26700           xi = im->xsize - 1;
60              
61 6795000 50         if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
    50          
62 25830000 100         for(ch = 0; ch < im->channels; ch++)
    100          
63 19035000           res[ch] += (rcolor.channel[ch]) *coeff[c];
64             }
65             }
66 1395000 50         im_assert(pc != 0);
    50          
67 5310000 100         for(ch = 0; ch < im->channels; ch++) {
    100          
68 3915000           double temp = res[ch] / pc;
69 3915000 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 1395000           IM_PPIX(timg, xo, yo, &rcolor);
73             }
74             }
75              
76 9362 100         for(xo = 0; xo < im->xsize; xo++) {
    100          
77 1404300 100         for(yo = 0;yo < im->ysize; yo++) {
    100          
78 5310000 100         for(ch = 0; ch < im->channels; ch++)
    100          
79 3915000           res[ch] = 0;
80 8190000 100         for(c = 0; c < len; c++) {
    100          
81 6795000           i_img_dim yi = yo + c - center;
82 6795000 100         if (yi < 0)
    100          
83 26700           yi = 0;
84 6768300 100         else if (yi >= im->ysize)
    100          
85 26700           yi = im->ysize - 1;
86 6795000 50         if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
    50          
87 25830000 100         for(ch = 0;ch < im->channels; ch++)
    100          
88 19035000           res[ch] += (rcolor.channel[ch]) * coeff[c];
89             }
90             }
91 1395000 50         im_assert(pc != 0);
    50          
92 5310000 100         for(ch = 0;ch < im->channels; ch++) {
    100          
93 3915000           double temp = res[ch] / pc;
94 3915000 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 1395000           IM_PPIX(im, xo, yo,&rcolor);
98             }
99             }
100             #/code
101              
102 62           i_img_destroy(timg);
103              
104 62           return 1;
105             }