File Coverage

combine.im
Criterion Covered Total %
statement 40 43 93.0
branch 29 32 90.6
condition n/a
subroutine n/a
pod n/a
total 69 75 92.0


line stmt bran cond sub pod time code
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           int 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 100         if (in_count <= 0) {
32 1           i_push_error(0, "At least one image must be supplied");
33 1           return NULL;
34             }
35 10 100         if (in_count > MAXCHANNELS) {
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 100         for (i = 0; i < in_count; ++i) {
44 14 100         if (imgs[i]->bits > maxbits) {
45 10           maximg = imgs[i];
46 10           maxbits = maximg->bits;
47             }
48 14 50         if (imgs[i]->xsize < width)
49 0           width = imgs[i]->xsize;
50 14 50         if (imgs[i]->ysize < height)
51 0           height = imgs[i]->ysize;
52 14 100         if (channels[i] < 0) {
53 1           i_push_error(0, "Channel numbers must be zero or positive");
54 1           return NULL;
55             }
56 13 100         if (channels[i] >= imgs[i]->channels) {
57 1           i_push_errorf(0, "Channel %d for image %d is too high (%d channels)",
58 2           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 50         if (!out)
65 0           return NULL;
66 7 100         #code maxbits <= i_8_bits
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 100         for (y = 0; y < height; ++y) {
    100          
71 2850 100         for (i = 0; i < in_count; ++i) {
    100          
72 1800           IM_GSAMP(imgs[i], 0, width, y, in_row, channels + i, 1);
73 271800 100         for (x = 0; x < width; ++x)
    100          
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             }