| 1 |
|
| /* |
| 2 |
|
| =head1 NAME |
| 3 |
|
| |
| 4 |
|
| combine.im - combining channels into an image |
| 5 |
|
| |
| 6 |
|
| =head1 SYNOPSIS |
| 7 |
|
| |
| 8 |
|
| out = i_combine(imgs, channels, count); |
| 9 |
|
| |
| 10 |
|
| =head1 DESCRIPTION |
| 11 |
|
| |
| 12 |
|
| Combines channels from the input images into an output image. |
| 13 |
|
| |
| 14 |
|
| =over |
| 15 |
|
| |
| 16 |
|
| =cut |
| 17 |
|
| */ |
| 18 |
|
| |
| 19 |
|
| #include "imager.h" |
| 20 |
|
| |
| 21 |
|
| i_img * |
| 22 |
11 |
| i_combine(i_img **imgs, const int *channels, int in_count) { |
| 23 |
11 |
| i_img *out = NULL; |
| 24 |
11 |
| i_img_bits_t maxbits = 0; |
| 25 |
11 |
| i_img *maximg = NULL; |
| 26 |
|
| int i; |
| 27 |
|
| i_img_dim width, height; |
| 28 |
|
| i_img_dim x, y; |
| 29 |
|
| |
| 30 |
11 |
| i_clear_error(); |
| 31 |
11 |
▶ | if (in_count <= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_count <= 0) { |
1 |
10 |
11 |
|
| 32 |
1 |
| i_push_error(0, "At least one image must be supplied"); |
| 33 |
1 |
| return NULL; |
| 34 |
|
| } |
| 35 |
10 |
▶ | if (in_count > MAXCHANNELS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (in_count > MAXCHANNELS) { |
1 |
9 |
10 |
|
| 36 |
1 |
| i_push_errorf(0, "Maximum of %d channels, you supplied %d", |
| 37 |
|
| MAXCHANNELS, in_count); |
| 38 |
1 |
| return NULL; |
| 39 |
|
| } |
| 40 |
|
| |
| 41 |
9 |
| width = imgs[0]->xsize; |
| 42 |
9 |
| height = imgs[0]->ysize; |
| 43 |
21 |
▶ | for (i = 0; i < in_count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < in_count; ++i) { |
14 |
7 |
21 |
|
| 44 |
14 |
▶ | if (imgs[i]->bits > maxbits) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (imgs[i]->bits > maxbits) { |
10 |
4 |
14 |
|
| 45 |
10 |
| maximg = imgs[i]; |
| 46 |
10 |
| maxbits = maximg->bits; |
| 47 |
|
| } |
| 48 |
14 |
▶ | if (imgs[i]->xsize < width) |
Branch: 1 branch
| Branch | True | False | Total |
| if (imgs[i]->xsize < width) |
0 |
14 |
14 |
|
| 49 |
0 |
| width = imgs[i]->xsize; |
| 50 |
14 |
▶ | if (imgs[i]->ysize < height) |
Branch: 1 branch
| Branch | True | False | Total |
| if (imgs[i]->ysize < height) |
0 |
14 |
14 |
|
| 51 |
0 |
| height = imgs[i]->ysize; |
| 52 |
14 |
▶ | if (channels[i] < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (channels[i] < 0) { |
1 |
13 |
14 |
|
| 53 |
1 |
| i_push_error(0, "Channel numbers must be zero or positive"); |
| 54 |
1 |
| return NULL; |
| 55 |
|
| } |
| 56 |
13 |
▶ | if (channels[i] >= imgs[i]->channels) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (channels[i] >= imgs[i]->channels) { |
1 |
12 |
13 |
|
| 57 |
1 |
| i_push_errorf(0, "Channel %d for image %d is too high (%d channels)", |
| 58 |
1 |
| channels[i], i, imgs[i]->channels); |
| 59 |
1 |
| return NULL; |
| 60 |
|
| } |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
7 |
| out = i_sametype_chans(maximg, width, height, in_count); |
| 64 |
7 |
▶ | if (!out) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!out) |
0 |
7 |
7 |
|
| 65 |
0 |
| return NULL; |
| 66 |
7 |
▶ | #code maxbits <= i_8_bits |
Branch: 1 branch
| Branch | True | False | Total |
| #code maxbits <= i_8_bits |
3 |
4 |
7 |
|
| 67 |
7 |
| IM_SAMPLE_T *in_row = mymalloc(sizeof(IM_SAMPLE_T) * width); |
| 68 |
7 |
| IM_COLOR *out_row = mymalloc(sizeof(IM_COLOR) * width); |
| 69 |
|
| |
| 70 |
1057 |
▶ | for (y = 0; y < height; ++y) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (y = 0; y < height; ++y) { |
450 |
3 |
453 |
| for (y = 0; y < height; ++y) { |
600 |
4 |
604 |
|
| 71 |
2850 |
▶ | for (i = 0; i < in_count; ++i) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; i < in_count; ++i) { |
750 |
450 |
1200 |
| for (i = 0; i < in_count; ++i) { |
1050 |
600 |
1650 |
|
| 72 |
1800 |
| IM_GSAMP(imgs[i], 0, width, y, in_row, channels + i, 1); |
| 73 |
271800 |
▶ | for (x = 0; x < width; ++x) |
Branch: 2 branches
| Branch | True | False | Total |
| for (x = 0; x < width; ++x) |
112500 |
750 |
113250 |
| for (x = 0; x < width; ++x) |
157500 |
1050 |
158550 |
|
| 74 |
270000 |
| out_row[x].channel[i] = in_row[x]; |
| 75 |
|
| } |
| 76 |
1050 |
| IM_PLIN(out, 0, width, y, out_row); |
| 77 |
|
| } |
| 78 |
7 |
| myfree(out_row); |
| 79 |
7 |
| myfree(in_row); |
| 80 |
|
| #/code |
| 81 |
|
| |
| 82 |
7 |
| return out; |
| 83 |
|
| } |