| 1 |
|
| #define IMAGER_NO_CONTEXT |
| 2 |
|
| |
| 3 |
|
| #include "imager.h" |
| 4 |
|
| #include "imageri.h" |
| 5 |
|
| |
| 6 |
|
| static int i_ppix_d(i_img *im, i_img_dim x, i_img_dim y, const i_color *val); |
| 7 |
|
| static int i_gpix_d(i_img *im, i_img_dim x, i_img_dim y, i_color *val); |
| 8 |
|
| static i_img_dim i_glin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals); |
| 9 |
|
| static i_img_dim i_plin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals); |
| 10 |
|
| static int i_ppixf_d(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val); |
| 11 |
|
| static int i_gpixf_d(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *val); |
| 12 |
|
| static i_img_dim i_glinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals); |
| 13 |
|
| static i_img_dim i_plinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals); |
| 14 |
|
| static i_img_dim i_gsamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samps, const int *chans, int chan_count); |
| 15 |
|
| static i_img_dim i_gsampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samps, const int *chans, int chan_count); |
| 16 |
|
| static i_img_dim i_psamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_sample_t *samps, const int *chans, int chan_count); |
| 17 |
|
| static i_img_dim i_psampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fsample_t *samps, const int *chans, int chan_count); |
| 18 |
|
| |
| 19 |
|
| /* |
| 20 |
|
| =item IIM_base_8bit_direct (static) |
| 21 |
|
| |
| 22 |
|
| A static i_img object used to initialize direct 8-bit per sample images. |
| 23 |
|
| |
| 24 |
|
| =cut |
| 25 |
|
| */ |
| 26 |
|
| static i_img IIM_base_8bit_direct = |
| 27 |
|
| { |
| 28 |
|
| 0, /* channels set */ |
| 29 |
|
| 0, 0, 0, /* xsize, ysize, bytes */ |
| 30 |
|
| ~0U, /* ch_mask */ |
| 31 |
|
| i_8_bits, /* bits */ |
| 32 |
|
| i_direct_type, /* type */ |
| 33 |
|
| 0, /* virtual */ |
| 34 |
|
| NULL, /* idata */ |
| 35 |
|
| { 0, 0, NULL }, /* tags */ |
| 36 |
|
| NULL, /* ext_data */ |
| 37 |
|
| |
| 38 |
|
| i_ppix_d, /* i_f_ppix */ |
| 39 |
|
| i_ppixf_d, /* i_f_ppixf */ |
| 40 |
|
| i_plin_d, /* i_f_plin */ |
| 41 |
|
| i_plinf_d, /* i_f_plinf */ |
| 42 |
|
| i_gpix_d, /* i_f_gpix */ |
| 43 |
|
| i_gpixf_d, /* i_f_gpixf */ |
| 44 |
|
| i_glin_d, /* i_f_glin */ |
| 45 |
|
| i_glinf_d, /* i_f_glinf */ |
| 46 |
|
| i_gsamp_d, /* i_f_gsamp */ |
| 47 |
|
| i_gsampf_d, /* i_f_gsampf */ |
| 48 |
|
| |
| 49 |
|
| NULL, /* i_f_gpal */ |
| 50 |
|
| NULL, /* i_f_ppal */ |
| 51 |
|
| NULL, /* i_f_addcolors */ |
| 52 |
|
| NULL, /* i_f_getcolors */ |
| 53 |
|
| NULL, /* i_f_colorcount */ |
| 54 |
|
| NULL, /* i_f_maxcolors */ |
| 55 |
|
| NULL, /* i_f_findcolor */ |
| 56 |
|
| NULL, /* i_f_setcolors */ |
| 57 |
|
| |
| 58 |
|
| NULL, /* i_f_destroy */ |
| 59 |
|
| |
| 60 |
|
| i_gsamp_bits_fb, |
| 61 |
|
| NULL, /* i_f_psamp_bits */ |
| 62 |
|
| |
| 63 |
|
| i_psamp_d, |
| 64 |
|
| i_psampf_d, |
| 65 |
|
| |
| 66 |
|
| NULL, |
| 67 |
|
| NULL |
| 68 |
|
| }; |
| 69 |
|
| |
| 70 |
|
| /*static void set_8bit_direct(i_img *im) { |
| 71 |
|
| im->i_f_ppix = i_ppix_d; |
| 72 |
|
| im->i_f_ppixf = i_ppixf_d; |
| 73 |
|
| im->i_f_plin = i_plin_d; |
| 74 |
|
| im->i_f_plinf = i_plinf_d; |
| 75 |
|
| im->i_f_gpix = i_gpix_d; |
| 76 |
|
| im->i_f_gpixf = i_gpixf_d; |
| 77 |
|
| im->i_f_glin = i_glin_d; |
| 78 |
|
| im->i_f_glinf = i_glinf_d; |
| 79 |
|
| im->i_f_gpal = NULL; |
| 80 |
|
| im->i_f_ppal = NULL; |
| 81 |
|
| im->i_f_addcolor = NULL; |
| 82 |
|
| im->i_f_getcolor = NULL; |
| 83 |
|
| im->i_f_colorcount = NULL; |
| 84 |
|
| im->i_f_findcolor = NULL; |
| 85 |
|
| }*/ |
| 86 |
|
| |
| 87 |
|
| /* |
| 88 |
|
| =item im_img_8_new(ctx, x, y, ch) |
| 89 |
|
| X<im_img_8_new API>X<i_img_8_new API> |
| 90 |
|
| =category Image creation/destruction |
| 91 |
|
| =synopsis i_img *img = im_img_8_new(aIMCTX, width, height, channels); |
| 92 |
|
| =synopsis i_img *img = i_img_8_new(width, height, channels); |
| 93 |
|
| |
| 94 |
|
| Creates a new image object I<x> pixels wide, and I<y> pixels high with |
| 95 |
|
| I<ch> channels. |
| 96 |
|
| |
| 97 |
|
| =cut |
| 98 |
|
| */ |
| 99 |
|
| |
| 100 |
|
| i_img * |
| 101 |
692 |
| im_img_8_new(pIMCTX, i_img_dim x,i_img_dim y,int ch) { |
| 102 |
|
| i_img *im; |
| 103 |
|
| |
| 104 |
692 |
| im_log((aIMCTX, 1,"im_img_8_new(x %" i_DF ", y %" i_DF ", ch %d)\n", |
| 105 |
|
| i_DFc(x), i_DFc(y), ch)); |
| 106 |
|
| |
| 107 |
692 |
| im = im_img_empty_ch(aIMCTX, NULL,x,y,ch); |
| 108 |
|
| |
| 109 |
692 |
| im_log((aIMCTX, 1,"(%p) <- IIM_new\n",im)); |
| 110 |
692 |
| return im; |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
|
| /* |
| 114 |
|
| =item i_img_empty(im, x, y) |
| 115 |
|
| |
| 116 |
|
| Re-new image reference (assumes 3 channels) |
| 117 |
|
| |
| 118 |
|
| im - Image pointer |
| 119 |
|
| x - xsize of destination image |
| 120 |
|
| y - ysize of destination image |
| 121 |
|
| |
| 122 |
|
| **FIXME** what happens if a live image is passed in here? |
| 123 |
|
| |
| 124 |
|
| Should this just call i_img_empty_ch()? |
| 125 |
|
| |
| 126 |
|
| =cut |
| 127 |
|
| */ |
| 128 |
|
| |
| 129 |
|
| i_img * |
| 130 |
0 |
| im_img_empty(pIMCTX, i_img *im,i_img_dim x,i_img_dim y) { |
| 131 |
0 |
| im_log((aIMCTX, 1,"i_img_empty(*im %p, x %" i_DF ", y %" i_DF ")\n", |
| 132 |
|
| im, i_DFc(x), i_DFc(y))); |
| 133 |
0 |
| return im_img_empty_ch(aIMCTX, im, x, y, 3); |
| 134 |
|
| } |
| 135 |
|
| |
| 136 |
|
| /* |
| 137 |
|
| =item i_img_empty_ch(im, x, y, ch) |
| 138 |
|
| |
| 139 |
|
| Re-new image reference |
| 140 |
|
| |
| 141 |
|
| im - Image pointer |
| 142 |
|
| x - xsize of destination image |
| 143 |
|
| y - ysize of destination image |
| 144 |
|
| ch - number of channels |
| 145 |
|
| |
| 146 |
|
| =cut |
| 147 |
|
| */ |
| 148 |
|
| |
| 149 |
|
| i_img * |
| 150 |
1117 |
| im_img_empty_ch(pIMCTX, i_img *im,i_img_dim x,i_img_dim y,int ch) { |
| 151 |
|
| size_t bytes; |
| 152 |
1117 |
| i_img *const orig_im = im; |
| 153 |
|
| size_t line_bytes; |
| 154 |
|
| |
| 155 |
1117 |
| im_log((aIMCTX, 1,"i_img_empty_ch(*im %p, x %" i_DF ", y %" i_DF ", ch %d)\n", |
| 156 |
|
| im, i_DFc(x), i_DFc(y), ch)); |
| 157 |
1117 |
| i_clear_error(); |
| 158 |
|
| |
| 159 |
1117 |
▶ | if (x < 1 || y < 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (x < 1 || y < 1) { |
1114 |
3 |
1117 |
| if (x < 1 || y < 1) { |
2 |
1112 |
1114 |
|
| 160 |
5 |
| im_push_error(aIMCTX, 0, "Image sizes must be positive"); |
| 161 |
5 |
| return NULL; |
| 162 |
|
| } |
| 163 |
1112 |
▶ | if (ch < 1 || ch > MAXCHANNELS) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ch < 1 || ch > MAXCHANNELS) { |
1111 |
1 |
1112 |
| if (ch < 1 || ch > MAXCHANNELS) { |
1 |
1110 |
1111 |
|
| 164 |
2 |
| im_push_errorf(aIMCTX, 0, "channels must be between 1 and %d", MAXCHANNELS); |
| 165 |
2 |
| return NULL; |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
1110 |
▶ | if (im_mult_overflow3(&bytes, x, y, ch)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (im_mult_overflow3(&bytes, x, y, ch)) { |
0 |
1110 |
1110 |
|
| 169 |
0 |
| im_push_error(aIMCTX, 0, "integer overflow calculating image allocation"); |
| 170 |
0 |
| return NULL; |
| 171 |
|
| } |
| 172 |
|
| |
| 173 |
|
| /* basic assumption: we can always allocate a buffer representing a |
| 174 |
|
| line from the image, otherwise we're going to have trouble |
| 175 |
|
| working with the image */ |
| 176 |
1110 |
▶ | if (im_mult_overflow2(&line_bytes, x, sizeof(i_fcolor))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (im_mult_overflow2(&line_bytes, x, sizeof(i_fcolor))) { |
0 |
1110 |
1110 |
|
| 177 |
0 |
| im_push_error(aIMCTX, 0, "integer overflow calculating scanline allocation"); |
| 178 |
0 |
| return NULL; |
| 179 |
|
| } |
| 180 |
|
| |
| 181 |
1110 |
▶ | if (im == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im == NULL) |
1101 |
9 |
1110 |
|
| 182 |
1101 |
| im = im_img_alloc(aIMCTX); |
| 183 |
|
| |
| 184 |
1110 |
| memcpy(im, &IIM_base_8bit_direct, sizeof(i_img)); |
| 185 |
|
| |
| 186 |
1110 |
▶ | if ( (im->idata = i_malloc_fail(bytes)) == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (im->idata = i_malloc_fail(bytes)) == NULL) { |
0 |
1110 |
1110 |
|
| 187 |
0 |
▶ | if (!orig_im) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!orig_im) |
0 |
0 |
0 |
|
| 188 |
|
| /* can't i_img_destroy() until we've done i_img_init() */ |
| 189 |
0 |
| i_free(im); |
| 190 |
0 |
| im_log((aIMCTX, 1, "i_img_empty_ch(): out of memory\n")); |
| 191 |
0 |
| i_push_error(0, "Out of memory allocating image surface"); |
| 192 |
0 |
| return NULL; |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
1110 |
| memset(im->idata, 0, bytes); |
| 196 |
|
| |
| 197 |
1110 |
| i_tags_new(&im->tags); |
| 198 |
1110 |
| im->xsize = x; |
| 199 |
1110 |
| im->ysize = y; |
| 200 |
1110 |
| im->channels = ch; |
| 201 |
1110 |
| im->ch_mask = ~0U; |
| 202 |
1110 |
| im->bytes = bytes; |
| 203 |
|
| |
| 204 |
1110 |
| im->ext_data = NULL; |
| 205 |
|
| |
| 206 |
1110 |
| im_img_init(aIMCTX, im); |
| 207 |
|
| |
| 208 |
1110 |
| im_log((aIMCTX, 1,"(%p) <- i_img_empty_ch\n",im)); |
| 209 |
1110 |
| return im; |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
|
| /* |
| 213 |
|
| =head2 8-bit per sample image internal functions |
| 214 |
|
| |
| 215 |
|
| These are the functions installed in an 8-bit per sample image. |
| 216 |
|
| |
| 217 |
|
| =over |
| 218 |
|
| |
| 219 |
|
| =item i_ppix_d(im, x, y, col) |
| 220 |
|
| |
| 221 |
|
| Internal function. |
| 222 |
|
| |
| 223 |
|
| This is the function kept in the i_f_ppix member of an i_img object. |
| 224 |
|
| It does a normal store of a pixel into the image with range checking. |
| 225 |
|
| |
| 226 |
|
| Returns 0 if the pixel could be set, -1 otherwise. |
| 227 |
|
| |
| 228 |
|
| =cut |
| 229 |
|
| */ |
| 230 |
|
| static |
| 231 |
|
| int |
| 232 |
5662273 |
| i_ppix_d(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) { |
| 233 |
|
| int ch; |
| 234 |
|
| |
| 235 |
5662273 |
▶ | if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
Branch: 4 branches
| Branch | True | False | Total |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5662270 |
3 |
5662273 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5635245 |
27025 |
5662270 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5635085 |
160 |
5635245 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5634513 |
572 |
5635085 |
|
| 236 |
22330299 |
▶ | for(ch=0;ch<im->channels;ch++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) |
16695786 |
5634513 |
22330299 |
|
| 237 |
16695786 |
▶ | if (im->ch_mask&(1<<ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask&(1<<ch)) |
16695785 |
1 |
16695786 |
|
| 238 |
16695785 |
| im->idata[(x+y*im->xsize)*im->channels+ch]=val->channel[ch]; |
| 239 |
5634513 |
| return 0; |
| 240 |
|
| } |
| 241 |
27760 |
| return -1; /* error was clipped */ |
| 242 |
|
| } |
| 243 |
|
| |
| 244 |
|
| /* |
| 245 |
|
| =item i_gpix_d(im, x, y, &col) |
| 246 |
|
| |
| 247 |
|
| Internal function. |
| 248 |
|
| |
| 249 |
|
| This is the function kept in the i_f_gpix member of an i_img object. |
| 250 |
|
| It does normal retrieval of a pixel from the image with range checking. |
| 251 |
|
| |
| 252 |
|
| Returns 0 if the pixel could be retrieved, -1 otherwise. |
| 253 |
|
| |
| 254 |
|
| =cut |
| 255 |
|
| */ |
| 256 |
|
| static |
| 257 |
|
| int |
| 258 |
24440016 |
| i_gpix_d(i_img *im, i_img_dim x, i_img_dim y, i_color *val) { |
| 259 |
|
| int ch; |
| 260 |
24440016 |
▶ | if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24412685 |
27331 |
24440016 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24360005 |
52680 |
24412685 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24332255 |
27750 |
24360005 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24300262 |
31993 |
24332255 |
|
| 261 |
95568578 |
▶ | for(ch=0;ch<im->channels;ch++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) |
71268316 |
24300262 |
95568578 |
|
| 262 |
71268316 |
| val->channel[ch]=im->idata[(x+y*im->xsize)*im->channels+ch]; |
| 263 |
24300262 |
| return 0; |
| 264 |
|
| } |
| 265 |
559748 |
▶ | for(ch=0;ch<im->channels;ch++) val->channel[ch] = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) val->channel[ch] = 0; |
419994 |
139754 |
559748 |
|
| 266 |
139754 |
| return -1; /* error was cliped */ |
| 267 |
|
| } |
| 268 |
|
| |
| 269 |
|
| /* |
| 270 |
|
| =item i_glin_d(im, l, r, y, vals) |
| 271 |
|
| |
| 272 |
|
| Reads a line of data from the image, storing the pixels at vals. |
| 273 |
|
| |
| 274 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 275 |
|
| |
| 276 |
|
| vals should point at space for (r-l) pixels. |
| 277 |
|
| |
| 278 |
|
| l should never be less than zero (to avoid confusion about where to |
| 279 |
|
| put the pixels in vals). |
| 280 |
|
| |
| 281 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 282 |
|
| |
| 283 |
|
| =cut |
| 284 |
|
| */ |
| 285 |
|
| static |
| 286 |
|
| i_img_dim |
| 287 |
158078 |
| i_glin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) { |
| 288 |
|
| int ch; |
| 289 |
|
| i_img_dim count, i; |
| 290 |
|
| unsigned char *data; |
| 291 |
158078 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158078 |
0 |
158078 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158078 |
0 |
158078 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158078 |
0 |
158078 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158078 |
0 |
158078 |
|
| 292 |
158078 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
158078 |
158078 |
|
| 293 |
0 |
| r = im->xsize; |
| 294 |
158078 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 295 |
158078 |
| count = r - l; |
| 296 |
4822158 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
4664080 |
158078 |
4822158 |
|
| 297 |
18484978 |
▶ | for (ch = 0; ch < im->channels; ++ch) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) |
13820898 |
4664080 |
18484978 |
|
| 298 |
13820898 |
| vals[i].channel[ch] = *data++; |
| 299 |
|
| } |
| 300 |
158078 |
| return count; |
| 301 |
|
| } |
| 302 |
|
| else { |
| 303 |
0 |
| return 0; |
| 304 |
|
| } |
| 305 |
|
| } |
| 306 |
|
| |
| 307 |
|
| /* |
| 308 |
|
| =item i_plin_d(im, l, r, y, vals) |
| 309 |
|
| |
| 310 |
|
| Writes a line of data into the image, using the pixels at vals. |
| 311 |
|
| |
| 312 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 313 |
|
| |
| 314 |
|
| vals should point at (r-l) pixels. |
| 315 |
|
| |
| 316 |
|
| l should never be less than zero (to avoid confusion about where to |
| 317 |
|
| get the pixels in vals). |
| 318 |
|
| |
| 319 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 320 |
|
| |
| 321 |
|
| =cut |
| 322 |
|
| */ |
| 323 |
|
| static |
| 324 |
|
| i_img_dim |
| 325 |
508826 |
| i_plin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) { |
| 326 |
|
| int ch; |
| 327 |
|
| i_img_dim count, i; |
| 328 |
|
| unsigned char *data; |
| 329 |
508826 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508826 |
0 |
508826 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508766 |
60 |
508826 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508766 |
0 |
508766 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508766 |
0 |
508766 |
|
| 330 |
508766 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
300 |
508466 |
508766 |
|
| 331 |
300 |
| r = im->xsize; |
| 332 |
508766 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 333 |
508766 |
| count = r - l; |
| 334 |
8079734 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
7570968 |
508766 |
8079734 |
|
| 335 |
29583286 |
▶ | for (ch = 0; ch < im->channels; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) { |
22012318 |
7570968 |
29583286 |
|
| 336 |
22012318 |
▶ | if (im->ch_mask & (1 << ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << ch)) |
21086097 |
926221 |
22012318 |
|
| 337 |
21086097 |
| *data = vals[i].channel[ch]; |
| 338 |
22012318 |
| ++data; |
| 339 |
|
| } |
| 340 |
|
| } |
| 341 |
508766 |
| return count; |
| 342 |
|
| } |
| 343 |
|
| else { |
| 344 |
60 |
| return 0; |
| 345 |
|
| } |
| 346 |
|
| } |
| 347 |
|
| |
| 348 |
|
| /* |
| 349 |
|
| =item i_ppixf_d(im, x, y, val) |
| 350 |
|
| |
| 351 |
|
| =cut |
| 352 |
|
| */ |
| 353 |
|
| static |
| 354 |
|
| int |
| 355 |
17 |
| i_ppixf_d(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) { |
| 356 |
|
| int ch; |
| 357 |
|
| |
| 358 |
17 |
▶ | if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
Branch: 4 branches
| Branch | True | False | Total |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
15 |
2 |
17 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
13 |
2 |
15 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
11 |
2 |
13 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
10 |
1 |
11 |
|
| 359 |
40 |
▶ | for(ch=0;ch<im->channels;ch++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) |
30 |
10 |
40 |
|
| 360 |
30 |
▶ | if (im->ch_mask&(1<<ch)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask&(1<<ch)) { |
29 |
1 |
30 |
|
| 361 |
29 |
| im->idata[(x+y*im->xsize)*im->channels+ch] = |
| 362 |
29 |
| SampleFTo8(val->channel[ch]); |
| 363 |
|
| } |
| 364 |
10 |
| return 0; |
| 365 |
|
| } |
| 366 |
7 |
| return -1; /* error was clipped */ |
| 367 |
|
| } |
| 368 |
|
| |
| 369 |
|
| /* |
| 370 |
|
| =item i_gpixf_d(im, x, y, val) |
| 371 |
|
| |
| 372 |
|
| =cut |
| 373 |
|
| */ |
| 374 |
|
| static |
| 375 |
|
| int |
| 376 |
18 |
| i_gpixf_d(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *val) { |
| 377 |
|
| int ch; |
| 378 |
18 |
▶ | if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
17 |
1 |
18 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
16 |
1 |
17 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
16 |
0 |
16 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
16 |
0 |
16 |
|
| 379 |
64 |
▶ | for(ch=0;ch<im->channels;ch++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) { |
48 |
16 |
64 |
|
| 380 |
48 |
| val->channel[ch] = |
| 381 |
48 |
| Sample8ToF(im->idata[(x+y*im->xsize)*im->channels+ch]); |
| 382 |
|
| } |
| 383 |
16 |
| return 0; |
| 384 |
|
| } |
| 385 |
2 |
| return -1; /* error was cliped */ |
| 386 |
|
| } |
| 387 |
|
| |
| 388 |
|
| /* |
| 389 |
|
| =item i_glinf_d(im, l, r, y, vals) |
| 390 |
|
| |
| 391 |
|
| Reads a line of data from the image, storing the pixels at vals. |
| 392 |
|
| |
| 393 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 394 |
|
| |
| 395 |
|
| vals should point at space for (r-l) pixels. |
| 396 |
|
| |
| 397 |
|
| l should never be less than zero (to avoid confusion about where to |
| 398 |
|
| put the pixels in vals). |
| 399 |
|
| |
| 400 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 401 |
|
| |
| 402 |
|
| =cut |
| 403 |
|
| */ |
| 404 |
|
| static |
| 405 |
|
| i_img_dim |
| 406 |
2793 |
| i_glinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) { |
| 407 |
|
| int ch; |
| 408 |
|
| i_img_dim count, i; |
| 409 |
|
| unsigned char *data; |
| 410 |
2793 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
2793 |
0 |
2793 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
2793 |
0 |
2793 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
2793 |
0 |
2793 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
2793 |
0 |
2793 |
|
| 411 |
2793 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
2793 |
2793 |
|
| 412 |
0 |
| r = im->xsize; |
| 413 |
2793 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 414 |
2793 |
| count = r - l; |
| 415 |
393512 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
390719 |
2793 |
393512 |
|
| 416 |
1651169 |
▶ | for (ch = 0; ch < im->channels; ++ch) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) |
1260450 |
390719 |
1651169 |
|
| 417 |
1260450 |
| vals[i].channel[ch] = Sample8ToF(*data++); |
| 418 |
|
| } |
| 419 |
2793 |
| return count; |
| 420 |
|
| } |
| 421 |
|
| else { |
| 422 |
0 |
| return 0; |
| 423 |
|
| } |
| 424 |
|
| } |
| 425 |
|
| |
| 426 |
|
| /* |
| 427 |
|
| =item i_plinf_d(im, l, r, y, vals) |
| 428 |
|
| |
| 429 |
|
| Writes a line of data into the image, using the pixels at vals. |
| 430 |
|
| |
| 431 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 432 |
|
| |
| 433 |
|
| vals should point at (r-l) pixels. |
| 434 |
|
| |
| 435 |
|
| l should never be less than zero (to avoid confusion about where to |
| 436 |
|
| get the pixels in vals). |
| 437 |
|
| |
| 438 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 439 |
|
| |
| 440 |
|
| =cut |
| 441 |
|
| */ |
| 442 |
|
| static |
| 443 |
|
| i_img_dim |
| 444 |
1438 |
| i_plinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) { |
| 445 |
|
| int ch; |
| 446 |
|
| i_img_dim count, i; |
| 447 |
|
| unsigned char *data; |
| 448 |
1438 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
1438 |
0 |
1438 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
1438 |
0 |
1438 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
1438 |
0 |
1438 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
1438 |
0 |
1438 |
|
| 449 |
1438 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
1438 |
1438 |
|
| 450 |
0 |
| r = im->xsize; |
| 451 |
1438 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 452 |
1438 |
| count = r - l; |
| 453 |
165981 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
164543 |
1438 |
165981 |
|
| 454 |
658196 |
▶ | for (ch = 0; ch < im->channels; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) { |
493653 |
164543 |
658196 |
|
| 455 |
493653 |
▶ | if (im->ch_mask & (1 << ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << ch)) |
493652 |
1 |
493653 |
|
| 456 |
493652 |
| *data = SampleFTo8(vals[i].channel[ch]); |
| 457 |
493653 |
| ++data; |
| 458 |
|
| } |
| 459 |
|
| } |
| 460 |
1438 |
| return count; |
| 461 |
|
| } |
| 462 |
|
| else { |
| 463 |
0 |
| return 0; |
| 464 |
|
| } |
| 465 |
|
| } |
| 466 |
|
| |
| 467 |
|
| /* |
| 468 |
|
| =item i_gsamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samps, int *chans, int chan_count) |
| 469 |
|
| |
| 470 |
|
| Reads sample values from im for the horizontal line (l, y) to (r-1,y) |
| 471 |
|
| for the channels specified by chans, an array of int with chan_count |
| 472 |
|
| elements. |
| 473 |
|
| |
| 474 |
|
| Returns the number of samples read (which should be (r-l) * bits_set(chan_mask) |
| 475 |
|
| |
| 476 |
|
| =cut |
| 477 |
|
| */ |
| 478 |
|
| static |
| 479 |
|
| i_img_dim |
| 480 |
207066 |
| i_gsamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samps, |
| 481 |
|
| const int *chans, int chan_count) { |
| 482 |
|
| int ch; |
| 483 |
|
| i_img_dim count, i, w; |
| 484 |
|
| unsigned char *data; |
| 485 |
|
| |
| 486 |
207066 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
207066 |
0 |
207066 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
207066 |
0 |
207066 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
207066 |
0 |
207066 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
207066 |
0 |
207066 |
|
| 487 |
207066 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
207066 |
207066 |
|
| 488 |
0 |
| r = im->xsize; |
| 489 |
207066 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 490 |
207066 |
| w = r - l; |
| 491 |
207066 |
| count = 0; |
| 492 |
|
| |
| 493 |
207066 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
202129 |
4937 |
207066 |
|
| 494 |
|
| /* make sure we have good channel numbers */ |
| 495 |
410277 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
208148 |
202129 |
410277 |
|
| 496 |
208148 |
▶ | if (chans[ch] < 0 || chans[ch] >= im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
208148 |
0 |
208148 |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
0 |
208148 |
208148 |
|
| 497 |
0 |
| dIMCTXim(im); |
| 498 |
0 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 499 |
0 |
| return 0; |
| 500 |
|
| } |
| 501 |
|
| } |
| 502 |
1348591 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
1146462 |
202129 |
1348591 |
|
| 503 |
3073898 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
1927436 |
1146462 |
3073898 |
|
| 504 |
1927436 |
| *samps++ = data[chans[ch]]; |
| 505 |
1927436 |
| ++count; |
| 506 |
|
| } |
| 507 |
1146462 |
| data += im->channels; |
| 508 |
|
| } |
| 509 |
|
| } |
| 510 |
|
| else { |
| 511 |
4937 |
▶ | if (chan_count <= 0 || chan_count > im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chan_count <= 0 || chan_count > im->channels) { |
4937 |
0 |
4937 |
| if (chan_count <= 0 || chan_count > im->channels) { |
0 |
4937 |
4937 |
|
| 512 |
0 |
| dIMCTXim(im); |
| 513 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 514 |
|
| chan_count); |
| 515 |
0 |
| return 0; |
| 516 |
|
| } |
| 517 |
786058 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
781121 |
4937 |
786058 |
|
| 518 |
3258856 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
2477735 |
781121 |
3258856 |
|
| 519 |
2477735 |
| *samps++ = data[ch]; |
| 520 |
2477735 |
| ++count; |
| 521 |
|
| } |
| 522 |
781121 |
| data += im->channels; |
| 523 |
|
| } |
| 524 |
|
| } |
| 525 |
|
| |
| 526 |
207066 |
| return count; |
| 527 |
|
| } |
| 528 |
|
| else { |
| 529 |
0 |
| return 0; |
| 530 |
|
| } |
| 531 |
|
| } |
| 532 |
|
| |
| 533 |
|
| /* |
| 534 |
|
| =item i_gsampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samps, int *chans, int chan_count) |
| 535 |
|
| |
| 536 |
|
| Reads sample values from im for the horizontal line (l, y) to (r-1,y) |
| 537 |
|
| for the channels specified by chan_mask, where bit 0 is the first |
| 538 |
|
| channel. |
| 539 |
|
| |
| 540 |
|
| Returns the number of samples read (which should be (r-l) * bits_set(chan_mask) |
| 541 |
|
| |
| 542 |
|
| =cut |
| 543 |
|
| */ |
| 544 |
|
| static |
| 545 |
|
| i_img_dim |
| 546 |
155 |
| i_gsampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samps, |
| 547 |
|
| const int *chans, int chan_count) { |
| 548 |
|
| int ch; |
| 549 |
|
| i_img_dim count, i, w; |
| 550 |
|
| unsigned char *data; |
| 551 |
|
| |
| 552 |
155 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
155 |
0 |
155 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
155 |
0 |
155 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
155 |
0 |
155 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
155 |
0 |
155 |
|
| 553 |
155 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
155 |
155 |
|
| 554 |
0 |
| r = im->xsize; |
| 555 |
155 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 556 |
155 |
| w = r - l; |
| 557 |
155 |
| count = 0; |
| 558 |
|
| |
| 559 |
155 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
154 |
1 |
155 |
|
| 560 |
|
| /* make sure we have good channel numbers */ |
| 561 |
316 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
162 |
154 |
316 |
|
| 562 |
162 |
▶ | if (chans[ch] < 0 || chans[ch] >= im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
162 |
0 |
162 |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
0 |
162 |
162 |
|
| 563 |
0 |
| dIMCTXim(im); |
| 564 |
0 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 565 |
0 |
| return 0; |
| 566 |
|
| } |
| 567 |
|
| } |
| 568 |
22676 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
22522 |
154 |
22676 |
|
| 569 |
45088 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
22566 |
22522 |
45088 |
|
| 570 |
22566 |
| *samps++ = Sample8ToF(data[chans[ch]]); |
| 571 |
22566 |
| ++count; |
| 572 |
|
| } |
| 573 |
22522 |
| data += im->channels; |
| 574 |
|
| } |
| 575 |
|
| } |
| 576 |
|
| else { |
| 577 |
1 |
▶ | if (chan_count <= 0 || chan_count > im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chan_count <= 0 || chan_count > im->channels) { |
1 |
0 |
1 |
| if (chan_count <= 0 || chan_count > im->channels) { |
0 |
1 |
1 |
|
| 578 |
0 |
| dIMCTXim(im); |
| 579 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 580 |
|
| chan_count); |
| 581 |
0 |
| return 0; |
| 582 |
|
| } |
| 583 |
5 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
4 |
1 |
5 |
|
| 584 |
20 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
16 |
4 |
20 |
|
| 585 |
16 |
| *samps++ = Sample8ToF(data[ch]); |
| 586 |
16 |
| ++count; |
| 587 |
|
| } |
| 588 |
4 |
| data += im->channels; |
| 589 |
|
| } |
| 590 |
|
| } |
| 591 |
155 |
| return count; |
| 592 |
|
| } |
| 593 |
|
| else { |
| 594 |
0 |
| return 0; |
| 595 |
|
| } |
| 596 |
|
| } |
| 597 |
|
| |
| 598 |
|
| /* |
| 599 |
|
| =item i_psamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samps, int *chans, int chan_count) |
| 600 |
|
| |
| 601 |
|
| Writes sample values to im for the horizontal line (l, y) to (r-1,y) |
| 602 |
|
| for the channels specified by chans, an array of int with chan_count |
| 603 |
|
| elements. |
| 604 |
|
| |
| 605 |
|
| Returns the number of samples written (which should be (r-l) * |
| 606 |
|
| bits_set(chan_mask) |
| 607 |
|
| |
| 608 |
|
| =cut |
| 609 |
|
| */ |
| 610 |
|
| |
| 611 |
|
| static |
| 612 |
|
| i_img_dim |
| 613 |
195 |
| i_psamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, |
| 614 |
|
| const i_sample_t *samps, const int *chans, int chan_count) { |
| 615 |
|
| int ch; |
| 616 |
|
| i_img_dim count, i, w; |
| 617 |
|
| unsigned char *data; |
| 618 |
|
| |
| 619 |
195 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
194 |
1 |
195 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
193 |
1 |
194 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
193 |
0 |
193 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
192 |
1 |
193 |
|
| 620 |
192 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
1 |
191 |
192 |
|
| 621 |
1 |
| r = im->xsize; |
| 622 |
192 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 623 |
192 |
| w = r - l; |
| 624 |
192 |
| count = 0; |
| 625 |
|
| |
| 626 |
192 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
19 |
173 |
192 |
|
| 627 |
|
| /* make sure we have good channel numbers */ |
| 628 |
|
| /* and test if all channels specified are in the mask */ |
| 629 |
19 |
| int all_in_mask = 1; |
| 630 |
66 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
54 |
12 |
66 |
|
| 631 |
54 |
▶ | if (chans[ch] < 0 || chans[ch] >= im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
51 |
3 |
54 |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
4 |
47 |
51 |
|
| 632 |
7 |
| dIMCTXim(im); |
| 633 |
7 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 634 |
7 |
| return -1; |
| 635 |
|
| } |
| 636 |
47 |
▶ | if (!((1 << chans[ch]) & im->ch_mask)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!((1 << chans[ch]) & im->ch_mask)) |
3 |
44 |
47 |
|
| 637 |
3 |
| all_in_mask = 0; |
| 638 |
|
| } |
| 639 |
12 |
▶ | if (all_in_mask) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (all_in_mask) { |
9 |
3 |
12 |
|
| 640 |
51 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
42 |
9 |
51 |
|
| 641 |
162 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
120 |
42 |
162 |
|
| 642 |
120 |
| data[chans[ch]] = *samps++; |
| 643 |
120 |
| ++count; |
| 644 |
|
| } |
| 645 |
42 |
| data += im->channels; |
| 646 |
|
| } |
| 647 |
|
| } |
| 648 |
|
| else { |
| 649 |
6 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
3 |
3 |
6 |
|
| 650 |
12 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
9 |
3 |
12 |
|
| 651 |
9 |
▶ | if (im->ch_mask & (1 << (chans[ch]))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << (chans[ch]))) |
6 |
3 |
9 |
|
| 652 |
6 |
| data[chans[ch]] = *samps; |
| 653 |
9 |
| ++samps; |
| 654 |
9 |
| ++count; |
| 655 |
|
| } |
| 656 |
3 |
| data += im->channels; |
| 657 |
|
| } |
| 658 |
|
| } |
| 659 |
|
| } |
| 660 |
|
| else { |
| 661 |
173 |
▶ | if (chan_count <= 0 || chan_count > im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chan_count <= 0 || chan_count > im->channels) { |
173 |
0 |
173 |
| if (chan_count <= 0 || chan_count > im->channels) { |
0 |
173 |
173 |
|
| 662 |
0 |
| dIMCTXim(im); |
| 663 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 664 |
|
| chan_count); |
| 665 |
0 |
| return -1; |
| 666 |
|
| } |
| 667 |
22806 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
22633 |
173 |
22806 |
|
| 668 |
22633 |
| unsigned mask = 1; |
| 669 |
90532 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
67899 |
22633 |
90532 |
|
| 670 |
67899 |
▶ | if (im->ch_mask & mask) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & mask) |
67896 |
3 |
67899 |
|
| 671 |
67896 |
| data[ch] = *samps; |
| 672 |
67899 |
| ++samps; |
| 673 |
67899 |
| ++count; |
| 674 |
67899 |
| mask <<= 1; |
| 675 |
|
| } |
| 676 |
22633 |
| data += im->channels; |
| 677 |
|
| } |
| 678 |
|
| } |
| 679 |
|
| |
| 680 |
185 |
| return count; |
| 681 |
|
| } |
| 682 |
|
| else { |
| 683 |
3 |
| dIMCTXim(im); |
| 684 |
3 |
| i_push_error(0, "Image position outside of image"); |
| 685 |
3 |
| return -1; |
| 686 |
|
| } |
| 687 |
|
| } |
| 688 |
|
| |
| 689 |
|
| /* |
| 690 |
|
| =item i_psampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fsample_t *samps, int *chans, int chan_count) |
| 691 |
|
| |
| 692 |
|
| Writes sample values to im for the horizontal line (l, y) to (r-1,y) |
| 693 |
|
| for the channels specified by chans, an array of int with chan_count |
| 694 |
|
| elements. |
| 695 |
|
| |
| 696 |
|
| Returns the number of samples written (which should be (r-l) * |
| 697 |
|
| bits_set(chan_mask) |
| 698 |
|
| |
| 699 |
|
| =cut |
| 700 |
|
| */ |
| 701 |
|
| |
| 702 |
|
| static |
| 703 |
|
| i_img_dim |
| 704 |
37 |
| i_psampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, |
| 705 |
|
| const i_fsample_t *samps, const int *chans, int chan_count) { |
| 706 |
|
| int ch; |
| 707 |
|
| i_img_dim count, i, w; |
| 708 |
|
| unsigned char *data; |
| 709 |
|
| |
| 710 |
37 |
▶ | if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
36 |
1 |
37 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
35 |
1 |
36 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
33 |
2 |
35 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
32 |
1 |
33 |
|
| 711 |
32 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
1 |
31 |
32 |
|
| 712 |
1 |
| r = im->xsize; |
| 713 |
32 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 714 |
32 |
| w = r - l; |
| 715 |
32 |
| count = 0; |
| 716 |
|
| |
| 717 |
32 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
19 |
13 |
32 |
|
| 718 |
|
| /* make sure we have good channel numbers */ |
| 719 |
|
| /* and test if all channels specified are in the mask */ |
| 720 |
19 |
| int all_in_mask = 1; |
| 721 |
66 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
54 |
12 |
66 |
|
| 722 |
54 |
▶ | if (chans[ch] < 0 || chans[ch] >= im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
51 |
3 |
54 |
| if (chans[ch] < 0 || chans[ch] >= im->channels) { |
4 |
47 |
51 |
|
| 723 |
7 |
| dIMCTXim(im); |
| 724 |
7 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 725 |
7 |
| return -1; |
| 726 |
|
| } |
| 727 |
47 |
▶ | if (!((1 << chans[ch]) & im->ch_mask)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!((1 << chans[ch]) & im->ch_mask)) |
3 |
44 |
47 |
|
| 728 |
3 |
| all_in_mask = 0; |
| 729 |
|
| } |
| 730 |
12 |
▶ | if (all_in_mask) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (all_in_mask) { |
9 |
3 |
12 |
|
| 731 |
51 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
42 |
9 |
51 |
|
| 732 |
162 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
120 |
42 |
162 |
|
| 733 |
120 |
| data[chans[ch]] = SampleFTo8(*samps); |
| 734 |
120 |
| ++samps; |
| 735 |
120 |
| ++count; |
| 736 |
|
| } |
| 737 |
42 |
| data += im->channels; |
| 738 |
|
| } |
| 739 |
|
| } |
| 740 |
|
| else { |
| 741 |
6 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
3 |
3 |
6 |
|
| 742 |
12 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
9 |
3 |
12 |
|
| 743 |
9 |
▶ | if (im->ch_mask & (1 << (chans[ch]))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << (chans[ch]))) |
6 |
3 |
9 |
|
| 744 |
6 |
| data[chans[ch]] = SampleFTo8(*samps); |
| 745 |
9 |
| ++samps; |
| 746 |
9 |
| ++count; |
| 747 |
|
| } |
| 748 |
3 |
| data += im->channels; |
| 749 |
|
| } |
| 750 |
|
| } |
| 751 |
|
| } |
| 752 |
|
| else { |
| 753 |
13 |
▶ | if (chan_count <= 0 || chan_count > im->channels) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (chan_count <= 0 || chan_count > im->channels) { |
13 |
0 |
13 |
| if (chan_count <= 0 || chan_count > im->channels) { |
0 |
13 |
13 |
|
| 754 |
0 |
| dIMCTXim(im); |
| 755 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 756 |
|
| chan_count); |
| 757 |
0 |
| return -1; |
| 758 |
|
| } |
| 759 |
45 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
32 |
13 |
45 |
|
| 760 |
32 |
| unsigned mask = 1; |
| 761 |
128 |
▶ | for (ch = 0; ch < chan_count; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < chan_count; ++ch) { |
96 |
32 |
128 |
|
| 762 |
96 |
▶ | if (im->ch_mask & mask) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & mask) |
93 |
3 |
96 |
|
| 763 |
93 |
| data[ch] = SampleFTo8(*samps); |
| 764 |
96 |
| ++samps; |
| 765 |
96 |
| ++count; |
| 766 |
96 |
| mask <<= 1; |
| 767 |
|
| } |
| 768 |
32 |
| data += im->channels; |
| 769 |
|
| } |
| 770 |
|
| } |
| 771 |
|
| |
| 772 |
25 |
| return count; |
| 773 |
|
| } |
| 774 |
|
| else { |
| 775 |
5 |
| dIMCTXim(im); |
| 776 |
5 |
| i_push_error(0, "Image position outside of image"); |
| 777 |
5 |
| return -1; |
| 778 |
|
| } |
| 779 |
|
| } |
| 780 |
|
| |
| 781 |
|
| /* |
| 782 |
|
| =back |
| 783 |
|
| |
| 784 |
|
| =head1 AUTHOR |
| 785 |
|
| |
| 786 |
|
| Arnar M. Hrafnkelsson <addi@umich.edu> |
| 787 |
|
| |
| 788 |
|
| Tony Cook <tony@develop-help.com> |
| 789 |
|
| |
| 790 |
|
| =head1 SEE ALSO |
| 791 |
|
| |
| 792 |
|
| L<Imager> |
| 793 |
|
| |
| 794 |
|
| =cut |
| 795 |
|
| */ |