conv.im

filter: Statementstmt 98.2% 57 / 58 Branchbran 91.5% 97 / 106 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.9% 154 / 164 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« regops.perl ↑ Summary ICO/t/t10icon.t »
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 ▶ if (len < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (len < 1) { 2 63 65
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 ▶ for (c = 0; c < len; ++c)
Branch: 1 branch
BranchTrueFalseTotal
for (c = 0; c < len; ++c) 305 63 368
37 305 pc += coeff[c];
38  
39 63 ▶ if (pc == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (pc == 0) { 1 62 63
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 62 ▶ if (!timg)
Branch: 1 branch
BranchTrueFalseTotal
if (!timg) 0 62 62
46 0 return 0;
47  
48 62 ▶#code im->bits <= 8
Branch: 1 branch
BranchTrueFalseTotal
#code im->bits <= 8 47 15 62
49 IM_COLOR rcolor;
50 /* don't move the calculation of pc up here, it depends on which pixels
51 are readable */
52 9362 ▶ for(yo = 0; yo < im->ysize; yo++) {
Branch: 2 branches
BranchTrueFalseTotal
for(yo = 0; yo < im->ysize; yo++) { 7050 47 7097
for(yo = 0; yo < im->ysize; yo++) { 2250 15 2265
53 1404300 ▶ for(xo = 0; xo < im->xsize; xo++) {
Branch: 2 branches
BranchTrueFalseTotal
for(xo = 0; xo < im->xsize; xo++) { 1057500 7050 1064550
for(xo = 0; xo < im->xsize; xo++) { 337500 2250 339750
54 5310000 ▶ for(ch = 0;ch < im->channels; ch++)
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0;ch < im->channels; ch++) 3037500 1057500 4095000
for(ch = 0;ch < im->channels; ch++) 877500 337500 1215000
55 3915000 res[ch] = 0;
56 8190000 ▶ for(c = 0;c < len; c++) {
Branch: 2 branches
BranchTrueFalseTotal
for(c = 0;c < len; c++) { 5152500 1057500 6210000
for(c = 0;c < len; c++) { 1642500 337500 1980000
57 6795000 i_img_dim xi = xo + c - center;
58 6795000 ▶ if (xi < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (xi < 0) 20250 5132250 5152500
if (xi < 0) 6450 1636050 1642500
59 26700 xi = 0;
60 6768300 ▶ else if (xi >= im->xsize)
Branch: 2 branches
BranchTrueFalseTotal
else if (xi >= im->xsize) 20250 5112000 5132250
else if (xi >= im->xsize) 6450 1629600 1636050
61 26700 xi = im->xsize - 1;
62  
63 6795000 ▶ if (IM_GPIX(im, xi, yo, &rcolor)!=-1) {
Branch: 2 branches
BranchTrueFalseTotal
if (IM_GPIX(im, xi, yo, &rcolor)!=-1) { 5152500 0 5152500
if (IM_GPIX(im, xi, yo, &rcolor)!=-1) { 1642500 0 1642500
64 25830000 ▶ for(ch = 0; ch < im->channels; ch++)
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0; ch < im->channels; ch++) 14782500 5152500 19935000
for(ch = 0; ch < im->channels; ch++) 4252500 1642500 5895000
65 19035000 res[ch] += (rcolor.channel[ch]) *coeff[c];
66 }
67 }
68 1395000 ▶ im_assert(pc != 0);
Branch: 2 branches
BranchTrueFalseTotal
im_assert(pc != 0); 0 1057500 1057500
im_assert(pc != 0); 0 337500 337500
69 5310000 ▶ for(ch = 0; ch < im->channels; ch++) {
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0; ch < im->channels; ch++) { 3037500 1057500 4095000
for(ch = 0; ch < im->channels; ch++) { 877500 337500 1215000
70 3915000 double temp = res[ch] / pc;
71 3915000 ▶ rcolor.channel[ch] =
Branch: 2 branches
BranchTrueFalseTotal
rcolor.channel[ch] = 1882 3035618 3037500
rcolor.channel[ch] = 1032 3034586 3035618
72 877500 ▶ temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
Branch: 2 branches
BranchTrueFalseTotal
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; 678 876822 877500
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; 408 876414 876822
73 }
74 1395000 IM_PPIX(timg, xo, yo, &rcolor);
75 }
76 }
77  
78 9362 ▶ for(xo = 0; xo < im->xsize; xo++) {
Branch: 2 branches
BranchTrueFalseTotal
for(xo = 0; xo < im->xsize; xo++) { 7050 47 7097
for(xo = 0; xo < im->xsize; xo++) { 2250 15 2265
79 1404300 ▶ for(yo = 0;yo < im->ysize; yo++) {
Branch: 2 branches
BranchTrueFalseTotal
for(yo = 0;yo < im->ysize; yo++) { 1057500 7050 1064550
for(yo = 0;yo < im->ysize; yo++) { 337500 2250 339750
80 5310000 ▶ for(ch = 0; ch < im->channels; ch++)
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0; ch < im->channels; ch++) 3037500 1057500 4095000
for(ch = 0; ch < im->channels; ch++) 877500 337500 1215000
81 3915000 res[ch] = 0;
82 8190000 ▶ for(c = 0; c < len; c++) {
Branch: 2 branches
BranchTrueFalseTotal
for(c = 0; c < len; c++) { 5152500 1057500 6210000
for(c = 0; c < len; c++) { 1642500 337500 1980000
83 6795000 i_img_dim yi = yo + c - center;
84 6795000 ▶ if (yi < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (yi < 0) 20250 5132250 5152500
if (yi < 0) 6450 1636050 1642500
85 26700 yi = 0;
86 6768300 ▶ else if (yi >= im->ysize)
Branch: 2 branches
BranchTrueFalseTotal
else if (yi >= im->ysize) 20250 5112000 5132250
else if (yi >= im->ysize) 6450 1629600 1636050
87 26700 yi = im->ysize - 1;
88 6795000 ▶ if (IM_GPIX(timg, xo, yi, &rcolor) != -1) {
Branch: 2 branches
BranchTrueFalseTotal
if (IM_GPIX(timg, xo, yi, &rcolor) != -1) { 5152500 0 5152500
if (IM_GPIX(timg, xo, yi, &rcolor) != -1) { 1642500 0 1642500
89 25830000 ▶ for(ch = 0;ch < im->channels; ch++)
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0;ch < im->channels; ch++) 14782500 5152500 19935000
for(ch = 0;ch < im->channels; ch++) 4252500 1642500 5895000
90 19035000 res[ch] += (rcolor.channel[ch]) * coeff[c];
91 }
92 }
93 1395000 ▶ im_assert(pc != 0);
Branch: 2 branches
BranchTrueFalseTotal
im_assert(pc != 0); 0 1057500 1057500
im_assert(pc != 0); 0 337500 337500
94 5310000 ▶ for(ch = 0;ch < im->channels; ch++) {
Branch: 2 branches
BranchTrueFalseTotal
for(ch = 0;ch < im->channels; ch++) { 3037500 1057500 4095000
for(ch = 0;ch < im->channels; ch++) { 877500 337500 1215000
95 3915000 double temp = res[ch] / pc;
96 3915000 ▶ rcolor.channel[ch] =
Branch: 2 branches
BranchTrueFalseTotal
rcolor.channel[ch] = 1578 3035922 3037500
rcolor.channel[ch] = 1242 3034680 3035922
97 877500 ▶ temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp;
Branch: 2 branches
BranchTrueFalseTotal
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; 652 876848 877500
temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; 558 876290 876848
98 }
99 1395000 IM_PPIX(im, xo, yo,&rcolor);
100 }
101 }
102 #/code
103  
104 62 i_img_destroy(timg);
105  
106 62 return 1;
107 }
« regops.perl ↑ Summary ICO/t/t10icon.t »