| 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 |
68 |
| 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 |
68 |
| dIMCTXim(im); |
| 24 |
|
| |
| 25 |
68 |
| im_log((aIMCTX,1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len)); |
| 26 |
68 |
| im_clear_error(aIMCTX); |
| 27 |
|
| |
| 28 |
68 |
▶ | if (len < 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 1) { |
2 |
66 |
68 |
|
| 29 |
2 |
| im_push_error(aIMCTX, 0, "there must be at least one coefficient"); |
| 30 |
2 |
| return 0; |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
66 |
| center=(len-1)/2; |
| 34 |
|
| |
| 35 |
66 |
| pc = 0; |
| 36 |
386 |
▶ | for (c = 0; c < len; ++c) |
Branch: 1 branch
| Branch | True | False | Total |
| for (c = 0; c < len; ++c) |
320 |
66 |
386 |
|
| 37 |
320 |
| pc += coeff[c]; |
| 38 |
|
| |
| 39 |
66 |
▶ | if (pc == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pc == 0) { |
1 |
65 |
66 |
|
| 40 |
1 |
| i_push_error(0, "sum of coefficients is zero"); |
| 41 |
1 |
| return 0; |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
65 |
| timg = i_sametype(im, im->xsize, im->ysize); |
| 45 |
65 |
▶ | if (!timg) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!timg) |
0 |
65 |
65 |
|
| 46 |
0 |
| return 0; |
| 47 |
|
| |
| 48 |
65 |
▶ | #code im->bits <= 8 |
Branch: 1 branch
| Branch | True | False | Total |
| #code im->bits <= 8 |
48 |
17 |
65 |
|
| 49 |
|
| IM_COLOR rcolor; |
| 50 |
|
| /* don't move the calculation of pc up here, it depends on which pixels |
| 51 |
|
| are readable */ |
| 52 |
9815 |
▶ | for(yo = 0; yo < im->ysize; yo++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(yo = 0; yo < im->ysize; yo++) { |
7200 |
48 |
7248 |
| for(yo = 0; yo < im->ysize; yo++) { |
2550 |
17 |
2567 |
|
| 53 |
1472250 |
▶ | for(xo = 0; xo < im->xsize; xo++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(xo = 0; xo < im->xsize; xo++) { |
1080000 |
7200 |
1087200 |
| for(xo = 0; xo < im->xsize; xo++) { |
382500 |
2550 |
385050 |
|
| 54 |
5535000 |
▶ | for(ch = 0;ch < im->channels; ch++) |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0;ch < im->channels; ch++) |
3105000 |
1080000 |
4185000 |
| for(ch = 0;ch < im->channels; ch++) |
967500 |
382500 |
1350000 |
|
| 55 |
4072500 |
| res[ch] = 0; |
| 56 |
8595000 |
▶ | for(c = 0;c < len; c++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(c = 0;c < len; c++) { |
5265000 |
1080000 |
6345000 |
| for(c = 0;c < len; c++) { |
1867500 |
382500 |
2250000 |
|
| 57 |
7132500 |
| i_img_dim xi = xo + c - center; |
| 58 |
7132500 |
▶ | if (xi < 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (xi < 0) |
20700 |
5244300 |
5265000 |
| if (xi < 0) |
7350 |
1860150 |
1867500 |
|
| 59 |
28050 |
| xi = 0; |
| 60 |
7104450 |
▶ | else if (xi >= im->xsize) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (xi >= im->xsize) |
20700 |
5223600 |
5244300 |
| else if (xi >= im->xsize) |
7350 |
1852800 |
1860150 |
|
| 61 |
28050 |
| xi = im->xsize - 1; |
| 62 |
|
| |
| 63 |
7132500 |
▶ | if (IM_GPIX(im, xi, yo, &rcolor)!=-1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (IM_GPIX(im, xi, yo, &rcolor)!=-1) { |
5265000 |
0 |
5265000 |
| if (IM_GPIX(im, xi, yo, &rcolor)!=-1) { |
1867500 |
0 |
1867500 |
|
| 64 |
26955000 |
▶ | for(ch = 0; ch < im->channels; ch++) |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0; ch < im->channels; ch++) |
15120000 |
5265000 |
20385000 |
| for(ch = 0; ch < im->channels; ch++) |
4702500 |
1867500 |
6570000 |
|
| 65 |
19822500 |
| res[ch] += (rcolor.channel[ch]) *coeff[c]; |
| 66 |
|
| } |
| 67 |
|
| } |
| 68 |
1462500 |
▶ | im_assert(pc != 0); |
Branch: 2 branches
| Branch | True | False | Total |
| im_assert(pc != 0); |
0 |
1080000 |
1080000 |
| im_assert(pc != 0); |
0 |
382500 |
382500 |
|
| 69 |
5535000 |
▶ | for(ch = 0; ch < im->channels; ch++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0; ch < im->channels; ch++) { |
3105000 |
1080000 |
4185000 |
| for(ch = 0; ch < im->channels; ch++) { |
967500 |
382500 |
1350000 |
|
| 70 |
4072500 |
| double temp = res[ch] / pc; |
| 71 |
4072500 |
▶ | rcolor.channel[ch] = |
Branch: 2 branches
| Branch | True | False | Total |
| rcolor.channel[ch] = |
1882 |
3103118 |
3105000 |
| rcolor.channel[ch] = |
1032 |
3102086 |
3103118 |
|
| 72 |
967500 |
▶ | temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
Branch: 2 branches
| Branch | True | False | Total |
| temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
678 |
966822 |
967500 |
| temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
408 |
966414 |
966822 |
|
| 73 |
|
| } |
| 74 |
1462500 |
| IM_PPIX(timg, xo, yo, &rcolor); |
| 75 |
|
| } |
| 76 |
|
| } |
| 77 |
|
| |
| 78 |
9815 |
▶ | for(xo = 0; xo < im->xsize; xo++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(xo = 0; xo < im->xsize; xo++) { |
7200 |
48 |
7248 |
| for(xo = 0; xo < im->xsize; xo++) { |
2550 |
17 |
2567 |
|
| 79 |
1472250 |
▶ | for(yo = 0;yo < im->ysize; yo++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(yo = 0;yo < im->ysize; yo++) { |
1080000 |
7200 |
1087200 |
| for(yo = 0;yo < im->ysize; yo++) { |
382500 |
2550 |
385050 |
|
| 80 |
5535000 |
▶ | for(ch = 0; ch < im->channels; ch++) |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0; ch < im->channels; ch++) |
3105000 |
1080000 |
4185000 |
| for(ch = 0; ch < im->channels; ch++) |
967500 |
382500 |
1350000 |
|
| 81 |
4072500 |
| res[ch] = 0; |
| 82 |
8595000 |
▶ | for(c = 0; c < len; c++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(c = 0; c < len; c++) { |
5265000 |
1080000 |
6345000 |
| for(c = 0; c < len; c++) { |
1867500 |
382500 |
2250000 |
|
| 83 |
7132500 |
| i_img_dim yi = yo + c - center; |
| 84 |
7132500 |
▶ | if (yi < 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (yi < 0) |
20700 |
5244300 |
5265000 |
| if (yi < 0) |
7350 |
1860150 |
1867500 |
|
| 85 |
28050 |
| yi = 0; |
| 86 |
7104450 |
▶ | else if (yi >= im->ysize) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (yi >= im->ysize) |
20700 |
5223600 |
5244300 |
| else if (yi >= im->ysize) |
7350 |
1852800 |
1860150 |
|
| 87 |
28050 |
| yi = im->ysize - 1; |
| 88 |
7132500 |
▶ | if (IM_GPIX(timg, xo, yi, &rcolor) != -1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (IM_GPIX(timg, xo, yi, &rcolor) != -1) { |
5265000 |
0 |
5265000 |
| if (IM_GPIX(timg, xo, yi, &rcolor) != -1) { |
1867500 |
0 |
1867500 |
|
| 89 |
26955000 |
▶ | for(ch = 0;ch < im->channels; ch++) |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0;ch < im->channels; ch++) |
15120000 |
5265000 |
20385000 |
| for(ch = 0;ch < im->channels; ch++) |
4702500 |
1867500 |
6570000 |
|
| 90 |
19822500 |
| res[ch] += (rcolor.channel[ch]) * coeff[c]; |
| 91 |
|
| } |
| 92 |
|
| } |
| 93 |
1462500 |
▶ | im_assert(pc != 0); |
Branch: 2 branches
| Branch | True | False | Total |
| im_assert(pc != 0); |
0 |
1080000 |
1080000 |
| im_assert(pc != 0); |
0 |
382500 |
382500 |
|
| 94 |
5535000 |
▶ | for(ch = 0;ch < im->channels; ch++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for(ch = 0;ch < im->channels; ch++) { |
3105000 |
1080000 |
4185000 |
| for(ch = 0;ch < im->channels; ch++) { |
967500 |
382500 |
1350000 |
|
| 95 |
4072500 |
| double temp = res[ch] / pc; |
| 96 |
4072500 |
▶ | rcolor.channel[ch] = |
Branch: 2 branches
| Branch | True | False | Total |
| rcolor.channel[ch] = |
1578 |
3103422 |
3105000 |
| rcolor.channel[ch] = |
1242 |
3102180 |
3103422 |
|
| 97 |
967500 |
▶ | temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
Branch: 2 branches
| Branch | True | False | Total |
| temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
652 |
966848 |
967500 |
| temp < 0 ? 0 : temp > IM_SAMPLE_MAX ? IM_SAMPLE_MAX : (IM_SAMPLE_T)temp; |
558 |
966290 |
966848 |
|
| 98 |
|
| } |
| 99 |
1462500 |
| IM_PPIX(im, xo, yo,&rcolor); |
| 100 |
|
| } |
| 101 |
|
| } |
| 102 |
|
| #/code |
| 103 |
|
| |
| 104 |
65 |
| i_img_destroy(timg); |
| 105 |
|
| |
| 106 |
65 |
| return 1; |
| 107 |
|
| } |