| 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 |
1119 |
| im_img_8_new(pIMCTX, i_img_dim x,i_img_dim y,int ch) { |
| 102 |
|
| i_img *im; |
| 103 |
|
| size_t bytes; |
| 104 |
|
| size_t line_bytes; |
| 105 |
|
| |
| 106 |
1119 |
| im_log((aIMCTX, 1,"im_img_8_new(x %" i_DF ", y %" i_DF ", ch %d)\n", |
| 107 |
|
| i_DFc(x), i_DFc(y), ch)); |
| 108 |
|
| |
| 109 |
1119 |
▶ | if (x < 1 || y < 1) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (x < 1 || y < 1) { |
1116 |
3 |
1119 |
| if (x < 1 || y < 1) { |
2 |
1114 |
1116 |
|
| 110 |
5 |
| im_push_error(aIMCTX, 0, "Image sizes must be positive"); |
| 111 |
5 |
| return NULL; |
| 112 |
|
| } |
| 113 |
1114 |
▶ | if (ch < 1 || ch > MAXCHANNELS) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ch < 1 || ch > MAXCHANNELS) { |
1113 |
1 |
1114 |
| if (ch < 1 || ch > MAXCHANNELS) { |
1 |
1112 |
1113 |
|
| 114 |
2 |
| im_push_errorf(aIMCTX, 0, "channels must be between 1 and %d", MAXCHANNELS); |
| 115 |
2 |
| return NULL; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
1112 |
▶ | if (im_mult_overflow3(&bytes, x, y, ch)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (im_mult_overflow3(&bytes, x, y, ch)) { |
0 |
1112 |
1112 |
|
| 119 |
0 |
| im_push_error(aIMCTX, 0, "integer overflow calculating image allocation"); |
| 120 |
0 |
| return NULL; |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
|
| /* basic assumption: we can always allocate a buffer representing a |
| 124 |
|
| line from the image, otherwise we're going to have trouble |
| 125 |
|
| working with the image */ |
| 126 |
1112 |
▶ | 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 |
1112 |
1112 |
|
| 127 |
0 |
| im_push_error(aIMCTX, 0, "integer overflow calculating scanline allocation"); |
| 128 |
0 |
| return NULL; |
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
1112 |
| im = im_img_alloc(aIMCTX); |
| 132 |
|
| |
| 133 |
1112 |
| memcpy(im, &IIM_base_8bit_direct, sizeof(i_img)); |
| 134 |
|
| |
| 135 |
1112 |
▶ | if ( (im->idata = i_malloc_fail(bytes)) == NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (im->idata = i_malloc_fail(bytes)) == NULL) { |
0 |
1112 |
1112 |
|
| 136 |
0 |
| im_log((aIMCTX, 1, "i_img_8_new(): out of memory\n")); |
| 137 |
0 |
| i_push_error(0, "Out of memory allocating image surface"); |
| 138 |
0 |
| return NULL; |
| 139 |
|
| } |
| 140 |
|
| |
| 141 |
1112 |
| memset(im->idata, 0, bytes); |
| 142 |
|
| |
| 143 |
1112 |
| i_tags_new(&im->tags); |
| 144 |
1112 |
| im->xsize = x; |
| 145 |
1112 |
| im->ysize = y; |
| 146 |
1112 |
| im->channels = ch; |
| 147 |
1112 |
| im->ch_mask = ~0U; |
| 148 |
1112 |
| im->bytes = bytes; |
| 149 |
|
| |
| 150 |
1112 |
| im->ext_data = NULL; |
| 151 |
|
| |
| 152 |
1112 |
| im_img_init(aIMCTX, im); |
| 153 |
|
| |
| 154 |
1112 |
| im_log((aIMCTX, 1,"(%p) <- i_img_8_new\n",im)); |
| 155 |
1112 |
| return im; |
| 156 |
|
| } |
| 157 |
|
| |
| 158 |
|
| /* |
| 159 |
|
| =head2 8-bit per sample image internal functions |
| 160 |
|
| |
| 161 |
|
| These are the functions installed in an 8-bit per sample image. |
| 162 |
|
| |
| 163 |
|
| =over |
| 164 |
|
| |
| 165 |
|
| =item i_ppix_d(im, x, y, col) |
| 166 |
|
| |
| 167 |
|
| Internal function. |
| 168 |
|
| |
| 169 |
|
| This is the function kept in the i_f_ppix member of an i_img object. |
| 170 |
|
| It does a normal store of a pixel into the image with range checking. |
| 171 |
|
| |
| 172 |
|
| Returns 0 if the pixel could be set, -1 otherwise. |
| 173 |
|
| |
| 174 |
|
| =cut |
| 175 |
|
| */ |
| 176 |
|
| static |
| 177 |
|
| int |
| 178 |
5710222 |
| i_ppix_d(i_img *im, i_img_dim x, i_img_dim y, const i_color *val) { |
| 179 |
|
| int ch; |
| 180 |
|
| |
| 181 |
5710222 |
▶ | 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 ) { |
5710219 |
3 |
5710222 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5683194 |
27025 |
5710219 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5683034 |
160 |
5683194 |
| if ( x>-1 && x<im->xsize && y>-1 && y<im->ysize ) { |
5682462 |
572 |
5683034 |
|
| 182 |
22522095 |
▶ | for(ch=0;ch<im->channels;ch++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) |
16839633 |
5682462 |
22522095 |
|
| 183 |
16839633 |
▶ | if (im->ch_mask&(1<<ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask&(1<<ch)) |
16839632 |
1 |
16839633 |
|
| 184 |
16839632 |
| im->idata[(x+y*im->xsize)*im->channels+ch]=val->channel[ch]; |
| 185 |
5682462 |
| return 0; |
| 186 |
|
| } |
| 187 |
27760 |
| return -1; /* error was clipped */ |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
|
| /* |
| 191 |
|
| =item i_gpix_d(im, x, y, &col) |
| 192 |
|
| |
| 193 |
|
| Internal function. |
| 194 |
|
| |
| 195 |
|
| This is the function kept in the i_f_gpix member of an i_img object. |
| 196 |
|
| It does normal retrieval of a pixel from the image with range checking. |
| 197 |
|
| |
| 198 |
|
| Returns 0 if the pixel could be retrieved, -1 otherwise. |
| 199 |
|
| |
| 200 |
|
| =cut |
| 201 |
|
| */ |
| 202 |
|
| static |
| 203 |
|
| int |
| 204 |
24665016 |
| i_gpix_d(i_img *im, i_img_dim x, i_img_dim y, i_color *val) { |
| 205 |
|
| int ch; |
| 206 |
24665016 |
▶ | 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) { |
24637685 |
27331 |
24665016 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24585005 |
52680 |
24637685 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24557255 |
27750 |
24585005 |
| if (x>-1 && x<im->xsize && y>-1 && y<im->ysize) { |
24525262 |
31993 |
24557255 |
|
| 207 |
96468578 |
▶ | for(ch=0;ch<im->channels;ch++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(ch=0;ch<im->channels;ch++) |
71943316 |
24525262 |
96468578 |
|
| 208 |
71943316 |
| val->channel[ch]=im->idata[(x+y*im->xsize)*im->channels+ch]; |
| 209 |
24525262 |
| return 0; |
| 210 |
|
| } |
| 211 |
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 |
|
| 212 |
139754 |
| return -1; /* error was cliped */ |
| 213 |
|
| } |
| 214 |
|
| |
| 215 |
|
| /* |
| 216 |
|
| =item i_glin_d(im, l, r, y, vals) |
| 217 |
|
| |
| 218 |
|
| Reads a line of data from the image, storing the pixels at vals. |
| 219 |
|
| |
| 220 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 221 |
|
| |
| 222 |
|
| vals should point at space for (r-l) pixels. |
| 223 |
|
| |
| 224 |
|
| l should never be less than zero (to avoid confusion about where to |
| 225 |
|
| put the pixels in vals). |
| 226 |
|
| |
| 227 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 228 |
|
| |
| 229 |
|
| =cut |
| 230 |
|
| */ |
| 231 |
|
| static |
| 232 |
|
| i_img_dim |
| 233 |
158228 |
| i_glin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) { |
| 234 |
|
| int ch; |
| 235 |
|
| i_img_dim count, i; |
| 236 |
|
| unsigned char *data; |
| 237 |
158228 |
▶ | 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) { |
158228 |
0 |
158228 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158228 |
0 |
158228 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158228 |
0 |
158228 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
158228 |
0 |
158228 |
|
| 238 |
158228 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
158228 |
158228 |
|
| 239 |
0 |
| r = im->xsize; |
| 240 |
158228 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 241 |
158228 |
| count = r - l; |
| 242 |
4844808 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
4686580 |
158228 |
4844808 |
|
| 243 |
18574978 |
▶ | for (ch = 0; ch < im->channels; ++ch) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) |
13888398 |
4686580 |
18574978 |
|
| 244 |
13888398 |
| vals[i].channel[ch] = *data++; |
| 245 |
|
| } |
| 246 |
158228 |
| return count; |
| 247 |
|
| } |
| 248 |
|
| else { |
| 249 |
0 |
| return 0; |
| 250 |
|
| } |
| 251 |
|
| } |
| 252 |
|
| |
| 253 |
|
| /* |
| 254 |
|
| =item i_plin_d(im, l, r, y, vals) |
| 255 |
|
| |
| 256 |
|
| Writes a line of data into the image, using the pixels at vals. |
| 257 |
|
| |
| 258 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 259 |
|
| |
| 260 |
|
| vals should point at (r-l) pixels. |
| 261 |
|
| |
| 262 |
|
| l should never be less than zero (to avoid confusion about where to |
| 263 |
|
| get the pixels in vals). |
| 264 |
|
| |
| 265 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 266 |
|
| |
| 267 |
|
| =cut |
| 268 |
|
| */ |
| 269 |
|
| static |
| 270 |
|
| i_img_dim |
| 271 |
509028 |
| i_plin_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) { |
| 272 |
|
| int ch; |
| 273 |
|
| i_img_dim count, i; |
| 274 |
|
| unsigned char *data; |
| 275 |
509028 |
▶ | 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) { |
509028 |
0 |
509028 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508968 |
60 |
509028 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508968 |
0 |
508968 |
| if (y >=0 && y < im->ysize && l < im->xsize && l >= 0) { |
508968 |
0 |
508968 |
|
| 276 |
508968 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
300 |
508668 |
508968 |
|
| 277 |
300 |
| r = im->xsize; |
| 278 |
508968 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 279 |
508968 |
| count = r - l; |
| 280 |
8092258 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
7583290 |
508968 |
8092258 |
|
| 281 |
29632574 |
▶ | for (ch = 0; ch < im->channels; ++ch) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ch = 0; ch < im->channels; ++ch) { |
22049284 |
7583290 |
29632574 |
|
| 282 |
22049284 |
▶ | if (im->ch_mask & (1 << ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << ch)) |
21123063 |
926221 |
22049284 |
|
| 283 |
21123063 |
| *data = vals[i].channel[ch]; |
| 284 |
22049284 |
| ++data; |
| 285 |
|
| } |
| 286 |
|
| } |
| 287 |
508968 |
| return count; |
| 288 |
|
| } |
| 289 |
|
| else { |
| 290 |
60 |
| return 0; |
| 291 |
|
| } |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
|
| /* |
| 295 |
|
| =item i_ppixf_d(im, x, y, val) |
| 296 |
|
| |
| 297 |
|
| =cut |
| 298 |
|
| */ |
| 299 |
|
| static |
| 300 |
|
| int |
| 301 |
17 |
| i_ppixf_d(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *val) { |
| 302 |
|
| int ch; |
| 303 |
|
| |
| 304 |
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 |
|
| 305 |
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 |
|
| 306 |
30 |
▶ | if (im->ch_mask&(1<<ch)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask&(1<<ch)) { |
29 |
1 |
30 |
|
| 307 |
29 |
| im->idata[(x+y*im->xsize)*im->channels+ch] = |
| 308 |
29 |
| SampleFTo8(val->channel[ch]); |
| 309 |
|
| } |
| 310 |
10 |
| return 0; |
| 311 |
|
| } |
| 312 |
7 |
| return -1; /* error was clipped */ |
| 313 |
|
| } |
| 314 |
|
| |
| 315 |
|
| /* |
| 316 |
|
| =item i_gpixf_d(im, x, y, val) |
| 317 |
|
| |
| 318 |
|
| =cut |
| 319 |
|
| */ |
| 320 |
|
| static |
| 321 |
|
| int |
| 322 |
18 |
| i_gpixf_d(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *val) { |
| 323 |
|
| int ch; |
| 324 |
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 |
|
| 325 |
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 |
|
| 326 |
48 |
| val->channel[ch] = |
| 327 |
48 |
| Sample8ToF(im->idata[(x+y*im->xsize)*im->channels+ch]); |
| 328 |
|
| } |
| 329 |
16 |
| return 0; |
| 330 |
|
| } |
| 331 |
2 |
| return -1; /* error was cliped */ |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
|
| /* |
| 335 |
|
| =item i_glinf_d(im, l, r, y, vals) |
| 336 |
|
| |
| 337 |
|
| Reads a line of data from the image, storing the pixels at vals. |
| 338 |
|
| |
| 339 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 340 |
|
| |
| 341 |
|
| vals should point at space for (r-l) pixels. |
| 342 |
|
| |
| 343 |
|
| l should never be less than zero (to avoid confusion about where to |
| 344 |
|
| put the pixels in vals). |
| 345 |
|
| |
| 346 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 347 |
|
| |
| 348 |
|
| =cut |
| 349 |
|
| */ |
| 350 |
|
| static |
| 351 |
|
| i_img_dim |
| 352 |
2793 |
| i_glinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) { |
| 353 |
|
| int ch; |
| 354 |
|
| i_img_dim count, i; |
| 355 |
|
| unsigned char *data; |
| 356 |
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 |
|
| 357 |
2793 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
2793 |
2793 |
|
| 358 |
0 |
| r = im->xsize; |
| 359 |
2793 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 360 |
2793 |
| count = r - l; |
| 361 |
393512 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
390719 |
2793 |
393512 |
|
| 362 |
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 |
|
| 363 |
1260450 |
| vals[i].channel[ch] = Sample8ToF(*data++); |
| 364 |
|
| } |
| 365 |
2793 |
| return count; |
| 366 |
|
| } |
| 367 |
|
| else { |
| 368 |
0 |
| return 0; |
| 369 |
|
| } |
| 370 |
|
| } |
| 371 |
|
| |
| 372 |
|
| /* |
| 373 |
|
| =item i_plinf_d(im, l, r, y, vals) |
| 374 |
|
| |
| 375 |
|
| Writes a line of data into the image, using the pixels at vals. |
| 376 |
|
| |
| 377 |
|
| The line runs from (l,y) inclusive to (r,y) non-inclusive |
| 378 |
|
| |
| 379 |
|
| vals should point at (r-l) pixels. |
| 380 |
|
| |
| 381 |
|
| l should never be less than zero (to avoid confusion about where to |
| 382 |
|
| get the pixels in vals). |
| 383 |
|
| |
| 384 |
|
| Returns the number of pixels copied (eg. if r, l or y is out of range) |
| 385 |
|
| |
| 386 |
|
| =cut |
| 387 |
|
| */ |
| 388 |
|
| static |
| 389 |
|
| i_img_dim |
| 390 |
1438 |
| i_plinf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) { |
| 391 |
|
| int ch; |
| 392 |
|
| i_img_dim count, i; |
| 393 |
|
| unsigned char *data; |
| 394 |
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 |
|
| 395 |
1438 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
1438 |
1438 |
|
| 396 |
0 |
| r = im->xsize; |
| 397 |
1438 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 398 |
1438 |
| count = r - l; |
| 399 |
165981 |
▶ | for (i = 0; i < count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; ++i) { |
164543 |
1438 |
165981 |
|
| 400 |
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 |
|
| 401 |
493653 |
▶ | if (im->ch_mask & (1 << ch)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & (1 << ch)) |
493652 |
1 |
493653 |
|
| 402 |
493652 |
| *data = SampleFTo8(vals[i].channel[ch]); |
| 403 |
493653 |
| ++data; |
| 404 |
|
| } |
| 405 |
|
| } |
| 406 |
1438 |
| return count; |
| 407 |
|
| } |
| 408 |
|
| else { |
| 409 |
0 |
| return 0; |
| 410 |
|
| } |
| 411 |
|
| } |
| 412 |
|
| |
| 413 |
|
| /* |
| 414 |
|
| =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) |
| 415 |
|
| |
| 416 |
|
| Reads sample values from im for the horizontal line (l, y) to (r-1,y) |
| 417 |
|
| for the channels specified by chans, an array of int with chan_count |
| 418 |
|
| elements. |
| 419 |
|
| |
| 420 |
|
| Returns the number of samples read (which should be (r-l) * bits_set(chan_mask) |
| 421 |
|
| |
| 422 |
|
| =cut |
| 423 |
|
| */ |
| 424 |
|
| static |
| 425 |
|
| i_img_dim |
| 426 |
207066 |
| i_gsamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samps, |
| 427 |
|
| const int *chans, int chan_count) { |
| 428 |
|
| int ch; |
| 429 |
|
| i_img_dim count, i, w; |
| 430 |
|
| unsigned char *data; |
| 431 |
|
| |
| 432 |
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 |
|
| 433 |
207066 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
207066 |
207066 |
|
| 434 |
0 |
| r = im->xsize; |
| 435 |
207066 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 436 |
207066 |
| w = r - l; |
| 437 |
207066 |
| count = 0; |
| 438 |
|
| |
| 439 |
207066 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
202129 |
4937 |
207066 |
|
| 440 |
|
| /* make sure we have good channel numbers */ |
| 441 |
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 |
|
| 442 |
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 |
|
| 443 |
0 |
| dIMCTXim(im); |
| 444 |
0 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 445 |
0 |
| return 0; |
| 446 |
|
| } |
| 447 |
|
| } |
| 448 |
1348591 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
1146462 |
202129 |
1348591 |
|
| 449 |
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 |
|
| 450 |
1927436 |
| *samps++ = data[chans[ch]]; |
| 451 |
1927436 |
| ++count; |
| 452 |
|
| } |
| 453 |
1146462 |
| data += im->channels; |
| 454 |
|
| } |
| 455 |
|
| } |
| 456 |
|
| else { |
| 457 |
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 |
|
| 458 |
0 |
| dIMCTXim(im); |
| 459 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 460 |
|
| chan_count); |
| 461 |
0 |
| return 0; |
| 462 |
|
| } |
| 463 |
786058 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
781121 |
4937 |
786058 |
|
| 464 |
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 |
|
| 465 |
2477735 |
| *samps++ = data[ch]; |
| 466 |
2477735 |
| ++count; |
| 467 |
|
| } |
| 468 |
781121 |
| data += im->channels; |
| 469 |
|
| } |
| 470 |
|
| } |
| 471 |
|
| |
| 472 |
207066 |
| return count; |
| 473 |
|
| } |
| 474 |
|
| else { |
| 475 |
0 |
| return 0; |
| 476 |
|
| } |
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
|
| /* |
| 480 |
|
| =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) |
| 481 |
|
| |
| 482 |
|
| Reads sample values from im for the horizontal line (l, y) to (r-1,y) |
| 483 |
|
| for the channels specified by chan_mask, where bit 0 is the first |
| 484 |
|
| channel. |
| 485 |
|
| |
| 486 |
|
| Returns the number of samples read (which should be (r-l) * bits_set(chan_mask) |
| 487 |
|
| |
| 488 |
|
| =cut |
| 489 |
|
| */ |
| 490 |
|
| static |
| 491 |
|
| i_img_dim |
| 492 |
155 |
| i_gsampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samps, |
| 493 |
|
| const int *chans, int chan_count) { |
| 494 |
|
| int ch; |
| 495 |
|
| i_img_dim count, i, w; |
| 496 |
|
| unsigned char *data; |
| 497 |
|
| |
| 498 |
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 |
|
| 499 |
155 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
0 |
155 |
155 |
|
| 500 |
0 |
| r = im->xsize; |
| 501 |
155 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 502 |
155 |
| w = r - l; |
| 503 |
155 |
| count = 0; |
| 504 |
|
| |
| 505 |
155 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
154 |
1 |
155 |
|
| 506 |
|
| /* make sure we have good channel numbers */ |
| 507 |
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 |
|
| 508 |
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 |
|
| 509 |
0 |
| dIMCTXim(im); |
| 510 |
0 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 511 |
0 |
| return 0; |
| 512 |
|
| } |
| 513 |
|
| } |
| 514 |
22676 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
22522 |
154 |
22676 |
|
| 515 |
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 |
|
| 516 |
22566 |
| *samps++ = Sample8ToF(data[chans[ch]]); |
| 517 |
22566 |
| ++count; |
| 518 |
|
| } |
| 519 |
22522 |
| data += im->channels; |
| 520 |
|
| } |
| 521 |
|
| } |
| 522 |
|
| else { |
| 523 |
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 |
|
| 524 |
0 |
| dIMCTXim(im); |
| 525 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 526 |
|
| chan_count); |
| 527 |
0 |
| return 0; |
| 528 |
|
| } |
| 529 |
5 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
4 |
1 |
5 |
|
| 530 |
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 |
|
| 531 |
16 |
| *samps++ = Sample8ToF(data[ch]); |
| 532 |
16 |
| ++count; |
| 533 |
|
| } |
| 534 |
4 |
| data += im->channels; |
| 535 |
|
| } |
| 536 |
|
| } |
| 537 |
155 |
| return count; |
| 538 |
|
| } |
| 539 |
|
| else { |
| 540 |
0 |
| return 0; |
| 541 |
|
| } |
| 542 |
|
| } |
| 543 |
|
| |
| 544 |
|
| /* |
| 545 |
|
| =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) |
| 546 |
|
| |
| 547 |
|
| Writes sample values to im for the horizontal line (l, y) to (r-1,y) |
| 548 |
|
| for the channels specified by chans, an array of int with chan_count |
| 549 |
|
| elements. |
| 550 |
|
| |
| 551 |
|
| Returns the number of samples written (which should be (r-l) * |
| 552 |
|
| bits_set(chan_mask) |
| 553 |
|
| |
| 554 |
|
| =cut |
| 555 |
|
| */ |
| 556 |
|
| |
| 557 |
|
| static |
| 558 |
|
| i_img_dim |
| 559 |
195 |
| i_psamp_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, |
| 560 |
|
| const i_sample_t *samps, const int *chans, int chan_count) { |
| 561 |
|
| int ch; |
| 562 |
|
| i_img_dim count, i, w; |
| 563 |
|
| unsigned char *data; |
| 564 |
|
| |
| 565 |
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 |
|
| 566 |
192 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
1 |
191 |
192 |
|
| 567 |
1 |
| r = im->xsize; |
| 568 |
192 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 569 |
192 |
| w = r - l; |
| 570 |
192 |
| count = 0; |
| 571 |
|
| |
| 572 |
192 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
19 |
173 |
192 |
|
| 573 |
|
| /* make sure we have good channel numbers */ |
| 574 |
|
| /* and test if all channels specified are in the mask */ |
| 575 |
19 |
| int all_in_mask = 1; |
| 576 |
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 |
|
| 577 |
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 |
|
| 578 |
7 |
| dIMCTXim(im); |
| 579 |
7 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 580 |
7 |
| return -1; |
| 581 |
|
| } |
| 582 |
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 |
|
| 583 |
3 |
| all_in_mask = 0; |
| 584 |
|
| } |
| 585 |
12 |
▶ | if (all_in_mask) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (all_in_mask) { |
9 |
3 |
12 |
|
| 586 |
51 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
42 |
9 |
51 |
|
| 587 |
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 |
|
| 588 |
120 |
| data[chans[ch]] = *samps++; |
| 589 |
120 |
| ++count; |
| 590 |
|
| } |
| 591 |
42 |
| data += im->channels; |
| 592 |
|
| } |
| 593 |
|
| } |
| 594 |
|
| else { |
| 595 |
6 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
3 |
3 |
6 |
|
| 596 |
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 |
|
| 597 |
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 |
|
| 598 |
6 |
| data[chans[ch]] = *samps; |
| 599 |
9 |
| ++samps; |
| 600 |
9 |
| ++count; |
| 601 |
|
| } |
| 602 |
3 |
| data += im->channels; |
| 603 |
|
| } |
| 604 |
|
| } |
| 605 |
|
| } |
| 606 |
|
| else { |
| 607 |
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 |
|
| 608 |
0 |
| dIMCTXim(im); |
| 609 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 610 |
|
| chan_count); |
| 611 |
0 |
| return -1; |
| 612 |
|
| } |
| 613 |
22806 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
22633 |
173 |
22806 |
|
| 614 |
22633 |
| unsigned mask = 1; |
| 615 |
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 |
|
| 616 |
67899 |
▶ | if (im->ch_mask & mask) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & mask) |
67896 |
3 |
67899 |
|
| 617 |
67896 |
| data[ch] = *samps; |
| 618 |
67899 |
| ++samps; |
| 619 |
67899 |
| ++count; |
| 620 |
67899 |
| mask <<= 1; |
| 621 |
|
| } |
| 622 |
22633 |
| data += im->channels; |
| 623 |
|
| } |
| 624 |
|
| } |
| 625 |
|
| |
| 626 |
185 |
| return count; |
| 627 |
|
| } |
| 628 |
|
| else { |
| 629 |
3 |
| dIMCTXim(im); |
| 630 |
3 |
| i_push_error(0, "Image position outside of image"); |
| 631 |
3 |
| return -1; |
| 632 |
|
| } |
| 633 |
|
| } |
| 634 |
|
| |
| 635 |
|
| /* |
| 636 |
|
| =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) |
| 637 |
|
| |
| 638 |
|
| Writes sample values to im for the horizontal line (l, y) to (r-1,y) |
| 639 |
|
| for the channels specified by chans, an array of int with chan_count |
| 640 |
|
| elements. |
| 641 |
|
| |
| 642 |
|
| Returns the number of samples written (which should be (r-l) * |
| 643 |
|
| bits_set(chan_mask) |
| 644 |
|
| |
| 645 |
|
| =cut |
| 646 |
|
| */ |
| 647 |
|
| |
| 648 |
|
| static |
| 649 |
|
| i_img_dim |
| 650 |
37 |
| i_psampf_d(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, |
| 651 |
|
| const i_fsample_t *samps, const int *chans, int chan_count) { |
| 652 |
|
| int ch; |
| 653 |
|
| i_img_dim count, i, w; |
| 654 |
|
| unsigned char *data; |
| 655 |
|
| |
| 656 |
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 |
|
| 657 |
32 |
▶ | if (r > im->xsize) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > im->xsize) |
1 |
31 |
32 |
|
| 658 |
1 |
| r = im->xsize; |
| 659 |
32 |
| data = im->idata + (l+y*im->xsize) * im->channels; |
| 660 |
32 |
| w = r - l; |
| 661 |
32 |
| count = 0; |
| 662 |
|
| |
| 663 |
32 |
▶ | if (chans) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chans) { |
19 |
13 |
32 |
|
| 664 |
|
| /* make sure we have good channel numbers */ |
| 665 |
|
| /* and test if all channels specified are in the mask */ |
| 666 |
19 |
| int all_in_mask = 1; |
| 667 |
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 |
|
| 668 |
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 |
|
| 669 |
7 |
| dIMCTXim(im); |
| 670 |
7 |
| im_push_errorf(aIMCTX, 0, "No channel %d in this image", chans[ch]); |
| 671 |
7 |
| return -1; |
| 672 |
|
| } |
| 673 |
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 |
|
| 674 |
3 |
| all_in_mask = 0; |
| 675 |
|
| } |
| 676 |
12 |
▶ | if (all_in_mask) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (all_in_mask) { |
9 |
3 |
12 |
|
| 677 |
51 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
42 |
9 |
51 |
|
| 678 |
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 |
|
| 679 |
120 |
| data[chans[ch]] = SampleFTo8(*samps); |
| 680 |
120 |
| ++samps; |
| 681 |
120 |
| ++count; |
| 682 |
|
| } |
| 683 |
42 |
| data += im->channels; |
| 684 |
|
| } |
| 685 |
|
| } |
| 686 |
|
| else { |
| 687 |
6 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
3 |
3 |
6 |
|
| 688 |
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 |
|
| 689 |
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 |
|
| 690 |
6 |
| data[chans[ch]] = SampleFTo8(*samps); |
| 691 |
9 |
| ++samps; |
| 692 |
9 |
| ++count; |
| 693 |
|
| } |
| 694 |
3 |
| data += im->channels; |
| 695 |
|
| } |
| 696 |
|
| } |
| 697 |
|
| } |
| 698 |
|
| else { |
| 699 |
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 |
|
| 700 |
0 |
| dIMCTXim(im); |
| 701 |
0 |
| im_push_errorf(aIMCTX, 0, "chan_count %d out of range, must be >0, <= channels", |
| 702 |
|
| chan_count); |
| 703 |
0 |
| return -1; |
| 704 |
|
| } |
| 705 |
45 |
▶ | for (i = 0; i < w; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < w; ++i) { |
32 |
13 |
45 |
|
| 706 |
32 |
| unsigned mask = 1; |
| 707 |
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 |
|
| 708 |
96 |
▶ | if (im->ch_mask & mask) |
Branch: 1 branch
| Branch | True | False | Total |
| if (im->ch_mask & mask) |
93 |
3 |
96 |
|
| 709 |
93 |
| data[ch] = SampleFTo8(*samps); |
| 710 |
96 |
| ++samps; |
| 711 |
96 |
| ++count; |
| 712 |
96 |
| mask <<= 1; |
| 713 |
|
| } |
| 714 |
32 |
| data += im->channels; |
| 715 |
|
| } |
| 716 |
|
| } |
| 717 |
|
| |
| 718 |
25 |
| return count; |
| 719 |
|
| } |
| 720 |
|
| else { |
| 721 |
5 |
| dIMCTXim(im); |
| 722 |
5 |
| i_push_error(0, "Image position outside of image"); |
| 723 |
5 |
| return -1; |
| 724 |
|
| } |
| 725 |
|
| } |
| 726 |
|
| |
| 727 |
|
| /* |
| 728 |
|
| =back |
| 729 |
|
| |
| 730 |
|
| =head1 AUTHOR |
| 731 |
|
| |
| 732 |
|
| Arnar M. Hrafnkelsson <addi@umich.edu> |
| 733 |
|
| |
| 734 |
|
| Tony Cook <tony@develop-help.com> |
| 735 |
|
| |
| 736 |
|
| =head1 SEE ALSO |
| 737 |
|
| |
| 738 |
|
| L<Imager> |
| 739 |
|
| |
| 740 |
|
| =cut |
| 741 |
|
| */ |