maskimg.c

filter: Statementstmt 98.5% 275 / 279 Branchbran 85.5% 224 / 262 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.2% 499 / 541 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« combine.im ↑ Summary flip.im »
1 /*
2 =head1 NAME
3  
4 maskimg.c - implements masked images/image subsets
5  
6 =head1 SYNOPSIS
7  
8 =head1 DESCRIPTION
9  
10 =over
11 =cut
12 */
13  
14 #define IMAGER_NO_CONTEXT
15  
16 #include "imager.h"
17 #include "imageri.h"
18  
19 #include <stdio.h>
20 /*
21 =item i_img_mask_ext
22  
23 A pointer to this type of object is kept in the ext_data of a masked
24 image.
25  
26 =cut
27 */
28  
29 typedef struct {
30 i_img *targ;
31 i_img *mask;
32 i_img_dim xbase, ybase;
33 i_sample_t *samps; /* temp space */
34 } i_img_mask_ext;
35  
36 #define MASKEXT(im) ((i_img_mask_ext *)((im)->ext_data))
37  
38 static void i_destroy_masked(i_img *im);
39 static int i_ppix_masked(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix);
40 static int i_ppixf_masked(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix);
41 static i_img_dim i_plin_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals);
42 static i_img_dim i_plinf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals);
43 static int i_gpix_masked(i_img *im, i_img_dim x, i_img_dim y, i_color *pix);
44 static int i_gpixf_masked(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix);
45 static i_img_dim i_glin_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals);
46 static i_img_dim i_glinf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals);
47 static i_img_dim i_gsamp_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
48 int const *chans, int chan_count);
49 static i_img_dim i_gsampf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
50 int const *chans, int chan_count);
51 static i_img_dim i_gpal_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_palidx *vals);
52 static i_img_dim i_ppal_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_palidx *vals);
53 static i_img_dim
54 psamp_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
55 const i_sample_t *samples, const int *chans, int chan_count);
56 static i_img_dim
57 psampf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
58 const i_fsample_t *samples, const int *chans, int chan_count);
59  
60 /*
61 =item IIM_base_masked
62  
63 The basic data we copy into a masked image.
64  
65 =cut
66 */
67 static i_img IIM_base_masked =
68 {
69 0, /* channels set */
70 0, 0, 0, /* xsize, ysize, bytes */
71 ~0U, /* ch_mask */
72 i_8_bits, /* bits */
73 i_palette_type, /* type */
74 1, /* virtual */
75 NULL, /* idata */
76 { 0, 0, NULL }, /* tags */
77 NULL, /* ext_data */
78  
79 i_ppix_masked, /* i_f_ppix */
80 i_ppixf_masked, /* i_f_ppixf */
81 i_plin_masked, /* i_f_plin */
82 i_plinf_masked, /* i_f_plinf */
83 i_gpix_masked, /* i_f_gpix */
84 i_gpixf_masked, /* i_f_gpixf */
85 i_glin_masked, /* i_f_glin */
86 i_glinf_masked, /* i_f_glinf */
87 i_gsamp_masked, /* i_f_gsamp */
88 i_gsampf_masked, /* i_f_gsampf */
89  
90 i_gpal_masked, /* i_f_gpal */
91 i_ppal_masked, /* i_f_ppal */
92 i_addcolors_forward, /* i_f_addcolors */
93 i_getcolors_forward, /* i_f_getcolors */
94 i_colorcount_forward, /* i_f_colorcount */
95 i_maxcolors_forward, /* i_f_maxcolors */
96 i_findcolor_forward, /* i_f_findcolor */
97 i_setcolors_forward, /* i_f_setcolors */
98  
99 i_destroy_masked, /* i_f_destroy */
100  
101 NULL, /* i_f_gsamp_bits */
102 NULL, /* i_f_psamp_bits */
103  
104 psamp_masked, /* i_f_psamp */
105 psampf_masked, /* i_f_psampf */
106  
107 NULL,
108 NULL
109 };
110  
111 /*
112 =item i_img_masked_new(i_img *targ, i_img *mask, i_img_dim xbase, i_img_dim ybase, i_img_dim w, i_img_dim h)
113  
114 Create a new masked image.
115  
116 The image mask is optional, in which case the image is just a view of
117 a rectangular portion of the image.
118  
119 The mask only has an effect of writing to the image, the entire view
120 of the underlying image is readable.
121  
122 pixel access to mimg(x,y) is translated to targ(x+xbase, y+ybase), as long
123 as (0 <= x < w) and (0 <= y < h).
124  
125 For a pixel to be writable, the pixel mask(x,y) must have non-zero in
126 it's first channel. No scaling of the pixel is done, the channel
127 sample is treated as boolean.
128  
129 =cut
130 */
131  
132 i_img *
133 24 i_img_masked_new(i_img *targ, i_img *mask, i_img_dim x, i_img_dim y, i_img_dim w, i_img_dim h) {
134 i_img *im;
135 i_img_mask_ext *ext;
136 24 dIMCTXim(targ);
137  
138 24 im_clear_error(aIMCTX);
139 24 ▶ if (x < 0 || x >= targ->xsize || y < 0 || y >= targ->ysize) {
Branch: 4 branches
BranchTrueFalseTotal
if (x < 0 || x >= targ->xsize || y < 0 || y >= targ->ysize) { 23 1 24
if (x < 0 || x >= targ->xsize || y < 0 || y >= targ->ysize) { 22 1 23
if (x < 0 || x >= targ->xsize || y < 0 || y >= targ->ysize) { 21 1 22
if (x < 0 || x >= targ->xsize || y < 0 || y >= targ->ysize) { 0 21 21
140 3 im_push_error(aIMCTX, 0, "subset outside of target image");
141 3 return NULL;
142 }
143 21 ▶ if (mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask) { 7 14 21
144 7 ▶ if (w > mask->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (w > mask->xsize) 3 4 7
145 3 w = mask->xsize;
146 7 ▶ if (h > mask->ysize)
Branch: 1 branch
BranchTrueFalseTotal
if (h > mask->ysize) 3 4 7
147 3 h = mask->ysize;
148 }
149 21 ▶ if (x+w > targ->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (x+w > targ->xsize) 1 20 21
150 1 w = targ->xsize - x;
151 21 ▶ if (y+h > targ->ysize)
Branch: 1 branch
BranchTrueFalseTotal
if (y+h > targ->ysize) 1 20 21
152 1 h = targ->ysize - y;
153  
154 21 ▶ if (w < 1 || h < 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (w < 1 || h < 1) { 19 2 21
if (w < 1 || h < 1) { 2 17 19
155 4 im_push_error(aIMCTX, 0, "width and height must be greater than or equal to 1");
156 4 return NULL;
157 }
158  
159 17 im = im_img_alloc(aIMCTX);
160  
161 17 memcpy(im, &IIM_base_masked, sizeof(i_img));
162 17 i_tags_new(&im->tags);
163 17 im->xsize = w;
164 17 im->ysize = h;
165 17 im->channels = targ->channels;
166 17 im->bits = targ->bits;
167 17 im->type = targ->type;
168 17 ext = mymalloc(sizeof(*ext));
169 17 ext->targ = targ;
170 17 ext->mask = mask;
171 17 ext->xbase = x;
172 17 ext->ybase = y;
173 17 ext->samps = mymalloc(sizeof(i_sample_t) * im->xsize);
174 17 im->ext_data = ext;
175  
176 17 im_img_init(aIMCTX, im);
177  
178 17 return im;
179 }
180  
181 /*
182 =item i_destroy_masked(i_img *im)
183  
184 The destruction handler for masked images.
185  
186 Releases the ext_data.
187  
188 Internal function.
189  
190 =cut
191 */
192  
193 17 static void i_destroy_masked(i_img *im) {
194 17 myfree(MASKEXT(im)->samps);
195 17 myfree(im->ext_data);
196 17 }
197  
198 /*
199 =item i_ppix_masked(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix)
200  
201 Write a pixel to a masked image.
202  
203 Internal function.
204  
205 =cut
206 */
207 3 static int i_ppix_masked(i_img *im, i_img_dim x, i_img_dim y, const i_color *pix) {
208 3 i_img_mask_ext *ext = MASKEXT(im);
209 int result;
210  
211 3 ▶ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
Branch: 4 branches
BranchTrueFalseTotal
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 3 0 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 2 1 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 2 0 2
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 0 2 2
212 1 return -1;
213 2 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 2 0 2
214 i_sample_t samp;
215
216 2 ▶ if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp)
Branch: 2 branches
BranchTrueFalseTotal
if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp) 2 0 2
if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp) 1 1 2
217 1 return 0; /* pretend it was good */
218 }
219 1 result = i_ppix(ext->targ, x + ext->xbase, y + ext->ybase, pix);
220 1 im->type = ext->targ->type;
221 1 return result;
222 }
223  
224 /*
225 =item i_ppixf_masked(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix)
226  
227 Write a pixel to a masked image.
228  
229 Internal function.
230  
231 =cut
232 */
233 3 static int i_ppixf_masked(i_img *im, i_img_dim x, i_img_dim y, const i_fcolor *pix) {
234 3 i_img_mask_ext *ext = MASKEXT(im);
235 int result;
236  
237 3 ▶ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
Branch: 4 branches
BranchTrueFalseTotal
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 3 0 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 3 0 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 3 0 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 1 2 3
238 1 return -1;
239 2 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 2 0 2
240 i_sample_t samp;
241
242 2 ▶ if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp)
Branch: 2 branches
BranchTrueFalseTotal
if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp) 2 0 2
if (i_gsamp(ext->mask, x, x+1, y, &samp, NULL, 1) && !samp) 1 1 2
243 1 return 0; /* pretend it was good */
244 }
245 1 result = i_ppixf(ext->targ, x + ext->xbase, y + ext->ybase, pix);
246 1 im->type = ext->targ->type;
247 1 return result;
248 }
249  
250 /*
251 =item i_plin_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals)
252  
253 Write a row of data to a masked image.
254  
255 Internal function.
256  
257 =cut
258 */
259 265 static i_img_dim i_plin_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals) {
260 265 i_img_mask_ext *ext = MASKEXT(im);
261  
262 265 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 265 0 265
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 265 0 265
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 264 1 265
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 264 0 264
263 264 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 263 264
264 1 r = im->xsize;
265 264 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 213 51 264
266 i_img_dim i;
267 213 int simple = 0;
268 213 i_sample_t *samps = ext->samps;
269 213 i_img_dim w = r - l;
270  
271 213 i_gsamp(ext->mask, l, r, y, samps, NULL, 1);
272 213 ▶ if (w < 10)
Branch: 1 branch
BranchTrueFalseTotal
if (w < 10) 1 212 213
273 1 simple = 1;
274 else {
275 /* the idea is to make a fast scan to see how often the state
276 changes */
277 212 i_img_dim changes = 0;
278 15392 ▶ for (i = 0; i < w-1; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < w-1; ++i) 15180 212 15392
279 15180 ▶ if (!samps[i] != !samps[i+1])
Branch: 1 branch
BranchTrueFalseTotal
if (!samps[i] != !samps[i+1]) 404 14776 15180
280 404 ++changes;
281 212 ▶ if (changes > w/3) /* just rough */
Branch: 1 branch
BranchTrueFalseTotal
if (changes > w/3) /* just rough */ 1 211 212
282 1 simple = 1;
283 }
284 213 ▶ if (simple) {
Branch: 1 branch
BranchTrueFalseTotal
if (simple) { 2 211 213
285 /* we'd be calling a usually more complicated i_plin function
286 almost as often as the usually simple i_ppix(), so just
287 do a simple scan
288 */
289 26 ▶ for (i = 0; i < w; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < w; ++i) { 24 2 26
290 24 ▶ if (samps[i])
Branch: 1 branch
BranchTrueFalseTotal
if (samps[i]) 10 14 24
291 10 i_ppix(ext->targ, l + i + ext->xbase, y + ext->ybase, vals + i);
292 }
293 2 im->type = ext->targ->type;
294 2 return r-l;
295 }
296 else {
297 /* the scan above indicates there should be some contiguous
298 regions, look for them and render
299 */
300 i_img_dim start;
301 211 i = 0;
302 615 ▶ while (i < w) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < w) { 404 211 615
303 4714 ▶ while (i < w && !samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && !samps[i]) 4503 211 4714
while (i < w && !samps[i]) 4310 193 4503
304 4310 ++i;
305 404 start = i;
306 11466 ▶ while (i < w && samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && samps[i]) 11255 211 11466
while (i < w && samps[i]) 11062 193 11255
307 11062 ++i;
308 404 ▶ if (i != start)
Branch: 1 branch
BranchTrueFalseTotal
if (i != start) 193 211 404
309 193 i_plin(ext->targ, l + start + ext->xbase, l + i + ext->xbase,
310 y + ext->ybase, vals + start);
311 }
312 211 im->type = ext->targ->type;
313 211 return w;
314 }
315 }
316 else {
317 51 i_img_dim result = i_plin(ext->targ, l + ext->xbase, r + ext->xbase,
318 y + ext->ybase, vals);
319 51 im->type = ext->targ->type;
320 51 return result;
321 }
322 }
323 else {
324 1 return 0;
325 }
326 }
327  
328 /*
329 =item i_plinf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals)
330  
331 Write a row of data to a masked image.
332  
333 Internal function.
334  
335 =cut
336 */
337 5 static i_img_dim i_plinf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals) {
338 5 i_img_mask_ext *ext = MASKEXT(im);
339 5 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 5 0 5
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 5 0 5
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 1 5
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 0 4
340 4 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 3 4
341 1 r = im->xsize;
342 4 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 3 1 4
343 i_img_dim i;
344 3 int simple = 0;
345 3 i_sample_t *samps = ext->samps;
346 3 i_img_dim w = r - l;
347  
348 3 i_gsamp(ext->mask, l, r, y, samps, NULL, 1);
349 3 ▶ if (w < 10)
Branch: 1 branch
BranchTrueFalseTotal
if (w < 10) 1 2 3
350 1 simple = 1;
351 else {
352 /* the idea is to make a fast scan to see how often the state
353 changes */
354 2 i_img_dim changes = 0;
355 92 ▶ for (i = 0; i < w-1; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < w-1; ++i) 90 2 92
356 90 ▶ if (!samps[i] != !samps[i+1])
Branch: 1 branch
BranchTrueFalseTotal
if (!samps[i] != !samps[i+1]) 20 70 90
357 20 ++changes;
358 2 ▶ if (changes > w/3) /* just rough */
Branch: 1 branch
BranchTrueFalseTotal
if (changes > w/3) /* just rough */ 1 1 2
359 1 simple = 1;
360 }
361 3 ▶ if (simple) {
Branch: 1 branch
BranchTrueFalseTotal
if (simple) { 2 1 3
362 /* we'd be calling a usually more complicated i_plin function
363 almost as often as the usually simple i_ppix(), so just
364 do a simple scan
365 */
366 26 ▶ for (i = 0; i < w; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < w; ++i) { 24 2 26
367 24 ▶ if (samps[i])
Branch: 1 branch
BranchTrueFalseTotal
if (samps[i]) 10 14 24
368 10 i_ppixf(ext->targ, l + i + ext->xbase, y + ext->ybase, vals+i);
369 }
370 2 im->type = ext->targ->type;
371 2 return r-l;
372 }
373 else {
374 /* the scan above indicates there should be some contiguous
375 regions, look for them and render
376 */
377 i_img_dim start;
378 1 i = 0;
379 3 ▶ while (i < w) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < w) { 2 1 3
380 38 ▶ while (i < w && !samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && !samps[i]) 37 1 38
while (i < w && !samps[i]) 36 1 37
381 36 ++i;
382 2 start = i;
383 38 ▶ while (i < w && samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && samps[i]) 37 1 38
while (i < w && samps[i]) 36 1 37
384 36 ++i;
385 2 ▶ if (i != start)
Branch: 1 branch
BranchTrueFalseTotal
if (i != start) 1 1 2
386 1 i_plinf(ext->targ, l + start + ext->xbase, l + i + ext->xbase,
387 y + ext->ybase, vals + start);
388 }
389 1 im->type = ext->targ->type;
390 1 return w;
391 }
392 }
393 else {
394 1 i_img_dim result = i_plinf(ext->targ, l + ext->xbase, r + ext->xbase,
395 y + ext->ybase, vals);
396 1 im->type = ext->targ->type;
397 1 return result;
398 }
399 }
400 else {
401 1 return 0;
402 }
403 }
404  
405 /*
406 =item i_gpix_masked(i_img *im, i_img_dim x, i_img_dim y, i_color *pix)
407  
408 Read a pixel from a masked image.
409  
410 Internal.
411  
412 =cut
413 */
414 23079 static int i_gpix_masked(i_img *im, i_img_dim x, i_img_dim y, i_color *pix) {
415 23079 i_img_mask_ext *ext = MASKEXT(im);
416  
417 23079 ▶ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
Branch: 4 branches
BranchTrueFalseTotal
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 23078 1 23079
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 23077 1 23078
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 23076 1 23077
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 1 23075 23076
418 4 return -1;
419  
420 23075 return i_gpix(ext->targ, x + ext->xbase, y + ext->ybase, pix);
421 }
422  
423 /*
424 =item i_gpixf_masked(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix)
425  
426 Read a pixel from a masked image.
427  
428 Internal.
429  
430 =cut
431 */
432 5 static int i_gpixf_masked(i_img *im, i_img_dim x, i_img_dim y, i_fcolor *pix) {
433 5 i_img_mask_ext *ext = MASKEXT(im);
434  
435 5 ▶ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
Branch: 4 branches
BranchTrueFalseTotal
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 4 1 5
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 3 1 4
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 2 1 3
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) 1 1 2
436 4 return -1;
437  
438 1 return i_gpixf(ext->targ, x + ext->xbase, y + ext->ybase, pix);
439 }
440  
441 6 static i_img_dim i_glin_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals) {
442 6 i_img_mask_ext *ext = MASKEXT(im);
443 6 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 5 1 6
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 1 5
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 3 1 4
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 1 3
444 2 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 1 2
445 1 r = im->xsize;
446 2 return i_glin(ext->targ, l + ext->xbase, r + ext->xbase,
447 y + ext->ybase, vals);
448 }
449 else {
450 4 return 0;
451 }
452 }
453  
454 6 static i_img_dim i_glinf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals) {
455 6 i_img_mask_ext *ext = MASKEXT(im);
456 6 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 5 1 6
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 1 5
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 3 1 4
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 1 3
457 2 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 1 2
458 1 r = im->xsize;
459 2 return i_glinf(ext->targ, l + ext->xbase, r + ext->xbase,
460 y + ext->ybase, vals);
461 }
462 else {
463 4 return 0;
464 }
465 }
466  
467 306 static i_img_dim i_gsamp_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp,
468 int const *chans, int chan_count) {
469 306 i_img_mask_ext *ext = MASKEXT(im);
470 306 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 306 0 306
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 306 0 306
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 306 0 306
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 306 0 306
471 306 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 0 306 306
472 0 r = im->xsize;
473 306 return i_gsamp(ext->targ, l + ext->xbase, r + ext->xbase,
474 y + ext->ybase, samp, chans, chan_count);
475 }
476 else {
477 0 return 0;
478 }
479 }
480  
481 2 static i_img_dim i_gsampf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
482 int const *chans, int chan_count) {
483 2 i_img_mask_ext *ext = MASKEXT(im);
484 2 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
485 2 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 0 2 2
486 0 r = im->xsize;
487 2 return i_gsampf(ext->targ, l + ext->xbase, r + ext->xbase,
488 y + ext->ybase, samp, chans, chan_count);
489 }
490 else {
491 0 return 0;
492 }
493 }
494  
495 2 static i_img_dim i_gpal_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_palidx *vals) {
496 2 i_img_mask_ext *ext = MASKEXT(im);
497 2 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 2 0 2
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 1 1 2
498 1 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 0 1
499 1 r = im->xsize;
500 1 ▶ return i_gpal(ext->targ, l + ext->xbase, r + ext->xbase,
Branch: 1 branch
BranchTrueFalseTotal
return i_gpal(ext->targ, l + ext->xbase, r + ext->xbase, 1 0 1
501 y + ext->ybase, vals);
502 }
503 else {
504 1 return 0;
505 }
506 }
507  
508 4 static i_img_dim i_ppal_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_palidx *vals) {
509 4 i_img_mask_ext *ext = MASKEXT(im);
510 4 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 0 4
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 0 4
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 4 0 4
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 3 1 4
511 3 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 1 2 3
512 1 r = im->xsize;
513 3 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 2 1 3
514 i_img_dim i;
515 2 i_sample_t *samps = ext->samps;
516 2 i_img_dim w = r - l;
517 i_img_dim start;
518
519 2 i_gsamp(ext->mask, l, r, y, samps, NULL, 1);
520 2 i = 0;
521 5 ▶ while (i < w) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < w) { 3 2 5
522 14 ▶ while (i < w && !samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && !samps[i]) 12 2 14
while (i < w && !samps[i]) 11 1 12
523 11 ++i;
524 3 start = i;
525 42 ▶ while (i < w && samps[i])
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && samps[i]) 40 2 42
while (i < w && samps[i]) 39 1 40
526 39 ++i;
527 3 ▶ if (i != start)
Branch: 1 branch
BranchTrueFalseTotal
if (i != start) 1 2 3
528 1 ▶ i_ppal(ext->targ, l+start+ext->xbase, l+i+ext->xbase,
Branch: 1 branch
BranchTrueFalseTotal
i_ppal(ext->targ, l+start+ext->xbase, l+i+ext->xbase, 1 0 1
529 y+ext->ybase, vals+start);
530 }
531 2 return w;
532 }
533 else {
534 1 ▶ return i_ppal(ext->targ, l + ext->xbase, r + ext->xbase,
Branch: 1 branch
BranchTrueFalseTotal
return i_ppal(ext->targ, l + ext->xbase, r + ext->xbase, 1 0 1
535 y + ext->ybase, vals);
536 }
537 }
538 else {
539 1 return 0;
540 }
541 }
542  
543 /*
544 =item psamp_masked()
545  
546 i_psamp() implementation for masked images.
547  
548 =cut
549 */
550  
551 static i_img_dim
552 23 psamp_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
553 const i_sample_t *samples, const int *chans, int chan_count) {
554 23 i_img_mask_ext *ext = MASKEXT(im);
555  
556 23 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 21 2 23
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 19 2 21
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 19 0 19
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 17 2 19
557 17 unsigned old_ch_mask = ext->targ->ch_mask;
558 17 i_img_dim result = 0;
559 17 ext->targ->ch_mask = im->ch_mask;
560 17 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 2 15 17
561 2 r = im->xsize;
562 17 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 9 8 17
563 9 i_img_dim w = r - l;
564 9 i_img_dim i = 0;
565 9 i_img_dim x = ext->xbase + l;
566 9 i_img_dim work_y = y + ext->ybase;
567 9 i_sample_t *mask_samps = ext->samps;
568
569 9 i_gsamp(ext->mask, l, r, y, mask_samps, NULL, 1);
570 /* not optimizing this yet */
571 22 ▶ while (i < w) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < w) { 13 9 22
572 13 ▶ if (mask_samps[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask_samps[i]) { 10 3 13
573 /* found a set mask value, try to do a run */
574 10 i_img_dim run_left = x;
575 10 const i_sample_t *run_samps = samples;
576 10 ++i;
577 10 ++x;
578 10 samples += chan_count;
579
580 26 ▶ while (i < w && mask_samps[i]) {
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && mask_samps[i]) { 17 9 26
while (i < w && mask_samps[i]) { 16 1 17
581 16 ++i;
582 16 ++x;
583 16 samples += chan_count;
584 }
585 10 result += i_psamp(ext->targ, run_left, x, work_y, run_samps, chans, chan_count);
586 }
587 else {
588 3 ++i;
589 3 ++x;
590 3 samples += chan_count;
591 3 result += chan_count; /* pretend we wrote masked off pixels */
592 }
593 }
594 }
595 else {
596 8 result = i_psamp(ext->targ, l + ext->xbase, r + ext->xbase,
597 y + ext->ybase, samples, chans, chan_count);
598 8 im->type = ext->targ->type;
599 }
600 17 ext->targ->ch_mask = old_ch_mask;
601 17 return result;
602 }
603 else {
604 6 dIMCTXim(im);
605 6 i_push_error(0, "Image position outside of image");
606 6 return -1;
607 }
608 }
609  
610 /*
611 =item psampf_masked()
612  
613 i_psampf() implementation for masked images.
614  
615 =cut
616 */
617  
618 static i_img_dim
619 25 psampf_masked(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
620 const i_fsample_t *samples, const int *chans, int chan_count) {
621 25 i_img_mask_ext *ext = MASKEXT(im);
622  
623 25 ▶ if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 23 2 25
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 21 2 23
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 19 2 21
if (y >= 0 && y < im->ysize && l < im->xsize && l >= 0) { 17 2 19
624 17 i_img_dim result = 0;
625 17 unsigned old_ch_mask = ext->targ->ch_mask;
626 17 ext->targ->ch_mask = im->ch_mask;
627 17 ▶ if (r > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (r > im->xsize) 2 15 17
628 2 r = im->xsize;
629 17 ▶ if (ext->mask) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext->mask) { 9 8 17
630 9 i_img_dim w = r - l;
631 9 i_img_dim i = 0;
632 9 i_img_dim x = ext->xbase + l;
633 9 i_img_dim work_y = y + ext->ybase;
634 9 i_sample_t *mask_samps = ext->samps;
635
636 9 i_gsamp(ext->mask, l, r, y, mask_samps, NULL, 1);
637 /* not optimizing this yet */
638 22 ▶ while (i < w) {
Branch: 1 branch
BranchTrueFalseTotal
while (i < w) { 13 9 22
639 13 ▶ if (mask_samps[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask_samps[i]) { 10 3 13
640 /* found a set mask value, try to do a run */
641 10 i_img_dim run_left = x;
642 10 const i_fsample_t *run_samps = samples;
643 10 ++i;
644 10 ++x;
645 10 samples += chan_count;
646
647 26 ▶ while (i < w && mask_samps[i]) {
Branch: 2 branches
BranchTrueFalseTotal
while (i < w && mask_samps[i]) { 17 9 26
while (i < w && mask_samps[i]) { 16 1 17
648 16 ++i;
649 16 ++x;
650 16 samples += chan_count;
651 }
652 10 result += i_psampf(ext->targ, run_left, x, work_y, run_samps, chans, chan_count);
653 }
654 else {
655 3 ++i;
656 3 ++x;
657 3 samples += chan_count;
658 3 result += chan_count; /* pretend we wrote masked off pixels */
659 }
660 }
661 }
662 else {
663 8 result = i_psampf(ext->targ, l + ext->xbase, r + ext->xbase,
664 y + ext->ybase, samples,
665 chans, chan_count);
666 8 im->type = ext->targ->type;
667 }
668 17 ext->targ->ch_mask = old_ch_mask;
669 17 return result;
670 }
671 else {
672 8 dIMCTXim(im);
673 8 i_push_error(0, "Image position outside of image");
674 8 return -1;
675 }
676 }
677  
678  
679 /*
680 =back
681  
682 =head1 AUTHOR
683  
684 Tony Cook <tony@develop-help.com>
685  
686 =head1 SEE ALSO
687  
688 Imager(3)
689  
690 =cut
691 */
« combine.im ↑ Summary flip.im »