Imager.xs

filter: Statementstmt 80.9% 1201 / 1484 Branchbran 58.2% 650 / 1116 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 71.1% 1851 / 2600 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« image.c ↑ Summary regmach.c »
1 #define PERL_NO_GET_CONTEXT
2 #ifdef __cplusplus
3 extern "C" {
4 #endif
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8 #define NEED_newRV_noinc
9 #define NEED_sv_2pv_nolen
10 #define NEED_sv_2pvbyte
11 #include "ppport.h"
12 #ifdef __cplusplus
13 }
14 #endif
15  
16 #define i_int_hlines_testing() 1
17  
18 #include "imager.h"
19 #include "feat.h"
20 #include "dynaload.h"
21 #include "regmach.h"
22 #include "imextdef.h"
23 #include "imextpltypes.h"
24 #include "imperlio.h"
25 #include <float.h>
26  
27 #if i_int_hlines_testing()
28 #include "imageri.h"
29 #endif
30  
31 #include "imperl.h"
32  
33 #define ARRAY_COUNT(array) (sizeof(array)/sizeof(*array))
34  
35 #ifndef SSize_t_MAX
36 #define SSize_t_MAX (SSize_t)(~(Size_t)0 >> 1)
37 #endif
38  
39 /*
40  
41 Context object management
42  
43 */
44  
45 #ifdef PERL_IMPLICIT_CONTEXT
46  
47 #define MY_CXT_KEY "Imager::_context" XS_VERSION
48  
49 typedef struct {
50 im_context_t ctx;
51 } my_cxt_t;
52  
53 START_MY_CXT
54  
55 static void
56 start_context(pTHX) {
57 dMY_CXT;
58 MY_CXT.ctx = im_context_new();
59 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
60 }
61  
62 static im_context_t
63 perl_get_context(void) {
64 dTHX;
65 dMY_CXT;
66
67 return MY_CXT.ctx;
68 }
69  
70 #else
71  
72 static im_context_t perl_context;
73  
74 static void
75 79 start_context(pTHX) {
76 79 perl_context = im_context_new();
77  
78 /* just so it gets destroyed */
79 79 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", perl_context);
80 79 }
81  
82 static im_context_t
83 67722 perl_get_context(void) {
84 67722 return perl_context;
85 }
86  
87 #endif
88  
89 typedef im_context_t Imager__Context;
90  
91 static void
92 79 S_im_context_DESTROY(pTHX_ im_context_t ctx) {
93 #ifdef PERL_IMPLICIT_CONTEXT
94 dMY_CXT;
95  
96 if (ctx == MY_CXT.ctx)
97 MY_CXT.ctx = NULL;
98 #else
99 79 perl_context = NULL;
100 #endif
101  
102 79 im_context_refdec(ctx, "DESTROY");
103 79 }
104  
105 #define im_context_DESTROY(ctx) S_im_context_DESTROY(aTHX_ (ctx))
106  
107 /* used to represent channel lists parameters */
108 typedef struct i_channel_list_tag {
109 int *channels;
110 int count;
111 } i_channel_list;
112  
113 typedef struct {
114 size_t count;
115 const i_sample_t *samples;
116 } i_sample_list;
117  
118 typedef struct {
119 size_t count;
120 const i_fsample_t *samples;
121 } i_fsample_list;
122  
123 typedef struct {
124 size_t count;
125 const i_polygon_t *polygons;
126 } i_polygon_list;
127  
128 typedef struct {
129 SV *sv;
130 SV *rsv;
131 size_t count;
132 i_trim_colors_t *colors;
133 } i_trim_color_list;
134  
135 /*
136  
137 Allocate memory that will be discarded when mortals are discarded.
138  
139 */
140  
141 static void *
142 979 malloc_temp(pTHX_ size_t size) {
143 void *result;
144 979 Newx(result, size, char);
145 979 SAVEFREEPV(result);
146  
147 979 return result;
148 }
149  
150 static void *
151 137 calloc_temp(pTHX_ size_t size) {
152 void *result;
153 137 Newxz(result, size, char);
154 137 SAVEFREEPV(result);
155  
156 137 return result;
157 }
158  
159 /* for use with the T_AVARRAY typemap */
160 #define doublePtr(size) ((double *)calloc_temp(aTHX_ sizeof(double) * (size)))
161 #define SvDouble(sv, pname) (SvNV(sv))
162  
163 #define intPtr(size) ((int *)calloc_temp(aTHX_ sizeof(int) * (size)))
164 #define SvInt(sv, pname) (SvIV(sv))
165  
166 #define i_img_dimPtr(size) ((i_img_dim *)calloc_temp(aTHX_ sizeof(i_img_dim) * (size)))
167 #define SvI_img_dim(sv, pname) (SvIV(sv))
168  
169 #define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color) * (size)))
170  
171 #define SvI_color(sv, pname) S_sv_to_i_color(aTHX_ sv, pname)
172  
173 static i_color
174 3 S_sv_to_i_color(pTHX_ SV *sv, const char *pname) {
175 3 ▶ if (!sv_derived_from(sv, "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_derived_from(sv, "Imager::Color")) { 0 3 3
176 0 croak("%s: not a color object", pname);
177 }
178 3 return *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
179 }
180  
181 /* These functions are all shared - then comes platform dependant code */
182 0 static int getstr(void *hv_t,char *key,char **store) {
183 dTHX;
184 SV** svpp;
185 0 HV* hv=(HV*)hv_t;
186  
187 0 mm_log((1,"getstr(hv_t %p, key %s, store %p)\n",hv_t,key,store));
188  
189 0 ▶ if ( !hv_exists(hv,key,strlen(key)) ) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ( !hv_exists(hv,key,strlen(key)) ) return 0; 0 0 0
190  
191 0 svpp=hv_fetch(hv, key, strlen(key), 0);
192 0 *store=SvPV(*svpp, PL_na );
193  
194 0 return 1;
195 }
196  
197 0 static int getint(void *hv_t,char *key,int *store) {
198 dTHX;
199 SV** svpp;
200 0 HV* hv=(HV*)hv_t;
201  
202 0 mm_log((1,"getint(hv_t %p, key %s, store %p)\n",hv_t,key,store));
203  
204 0 ▶ if ( !hv_exists(hv,key,strlen(key)) ) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ( !hv_exists(hv,key,strlen(key)) ) return 0; 0 0 0
205  
206 0 svpp=hv_fetch(hv, key, strlen(key), 0);
207 0 *store=(int)SvIV(*svpp);
208 0 return 1;
209 }
210  
211 0 static int getdouble(void *hv_t,char* key,double *store) {
212 dTHX;
213 SV** svpp;
214 0 HV* hv=(HV*)hv_t;
215  
216 0 mm_log((1,"getdouble(hv_t %p, key %s, store %p)\n",hv_t,key,store));
217  
218 0 ▶ if ( !hv_exists(hv,key,strlen(key)) ) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ( !hv_exists(hv,key,strlen(key)) ) return 0; 0 0 0
219 0 svpp=hv_fetch(hv, key, strlen(key), 0);
220 0 *store=(double)SvNV(*svpp);
221 0 return 1;
222 }
223  
224 0 static int getvoid(void *hv_t,char* key,void **store) {
225 dTHX;
226 SV** svpp;
227 0 HV* hv=(HV*)hv_t;
228  
229 0 mm_log((1,"getvoid(hv_t %p, key %s, store %p)\n",hv_t,key,store));
230  
231 0 ▶ if ( !hv_exists(hv,key,strlen(key)) ) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ( !hv_exists(hv,key,strlen(key)) ) return 0; 0 0 0
232  
233 0 svpp=hv_fetch(hv, key, strlen(key), 0);
234 0 *store = INT2PTR(void*, SvIV(*svpp));
235  
236 0 return 1;
237 }
238  
239 0 static int getobj(void *hv_t,char *key,char *type,void **store) {
240 dTHX;
241 SV** svpp;
242 0 HV* hv=(HV*)hv_t;
243  
244 0 mm_log((1,"getobj(hv_t %p, key %s,type %s, store %p)\n",hv_t,key,type,store));
245  
246 0 ▶ if ( !hv_exists(hv,key,strlen(key)) ) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ( !hv_exists(hv,key,strlen(key)) ) return 0; 0 0 0
247  
248 0 svpp=hv_fetch(hv, key, strlen(key), 0);
249  
250 0 ▶ if (sv_derived_from(*svpp,type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(*svpp,type)) { 0 0 0
251 0 IV tmp = SvIV((SV*)SvRV(*svpp));
252 0 *store = INT2PTR(void*, tmp);
253 } else {
254 0 mm_log((1,"getobj: key exists in hash but is not of correct type"));
255 0 return 0;
256 }
257  
258 0 return 1;
259 }
260  
261 UTIL_table_t i_UTIL_table={getstr,getint,getdouble,getvoid,getobj};
262  
263 static void
264 204 free_buffer(void *p) {
265 204 myfree(p);
266 204 }
267  
268  
269 static void
270 38 i_log_entry(char *string, int level) {
271 38 mm_log((level, "%s", string));
272 38 }
273  
274 static SV *
275 594 make_i_color_sv(pTHX_ const i_color *c) {
276 SV *sv;
277 594 i_color *col = mymalloc(sizeof(i_color));
278 594 *col = *c;
279 594 sv = newSV(0);
280 594 sv_setref_pv(sv, "Imager::Color", (void *)col);
281  
282 594 return sv;
283 }
284  
285 static SV *
286 582 make_i_color_sv_mortal(pTHX_ const i_color *c) {
287 582 return sv_2mortal(make_i_color_sv(aTHX_ c));
288 }
289  
290 static SV *
291 674 make_i_fcolor_sv(pTHX_ const i_fcolor *c) {
292 SV *sv;
293 674 i_fcolor *col = mymalloc(sizeof(i_fcolor));
294 674 *col = *c;
295 674 sv = newSV(0);
296 674 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
297  
298 674 return sv;
299 }
300  
301 static SV *
302 666 make_i_fcolor_sv_mortal(pTHX_ const i_fcolor *c) {
303 666 return sv_2mortal(make_i_fcolor_sv(aTHX_ c));
304 }
305  
306 #define CBDATA_BUFSIZE 8192
307  
308 struct cbdata {
309 /* the SVs we use to call back to Perl */
310 SV *writecb;
311 SV *readcb;
312 SV *seekcb;
313 SV *closecb;
314 off_t size;
315 SV *sizecb;
316 };
317  
318 static ssize_t
319 109 call_reader(struct cbdata *cbd, void *buf, size_t size,
320 size_t maxread) {
321 dTHX;
322 int count;
323 int result;
324 SV *data;
325 109 dSP;
326  
327 109 ▶ if (!SvOK(cbd->readcb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(cbd->readcb)) { 4 105 109
328 4 mm_log((1, "read callback called but no readcb supplied\n"));
329 4 i_push_error(0, "read callback called but no readcb supplied");
330 4 return -1;
331 }
332  
333 105 ENTER;
334 105 SAVETMPS;
335 105 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 105 105
336 105 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 105 105
337 105 PUSHs(sv_2mortal(newSViv(size)));
338 105 PUSHs(sv_2mortal(newSViv(maxread)));
339 105 PUTBACK;
340  
341 105 count = perl_call_sv(cbd->readcb, G_SCALAR);
342  
343 105 SPAGAIN;
344  
345 105 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 105 105
346 0 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
347  
348 105 data = POPs;
349  
350 105 ▶ if (SvOK(data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(data)) { 93 12 105
351 STRLEN len;
352 93 char *ptr = SvPVbyte(data, len);
353 93 ▶ if (len > maxread)
Branch: 1 branch
BranchTrueFalseTotal
if (len > maxread) 0 93 93
354 0 croak("Too much data returned in reader callback (wanted %d, got %d, expected %d)",
355 (int)size, (int)len, (int)maxread);
356
357 93 memcpy(buf, ptr, len);
358 93 result = len;
359 }
360 else {
361 12 result = -1;
362 }
363  
364 105 PUTBACK;
365 105 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 105 0 105
366 105 LEAVE;
367  
368 105 return result;
369 }
370  
371 static off_t
372 11 io_seeker(void *p, off_t offset, int whence) {
373 dTHX;
374 11 struct cbdata *cbd = p;
375 int count;
376 off_t result;
377 11 dSP;
378  
379 11 ▶ if (!SvOK(cbd->seekcb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(cbd->seekcb)) { 3 8 11
380 3 mm_log((1, "seek callback called but no seekcb supplied\n"));
381 3 i_push_error(0, "seek callback called but no seekcb supplied");
382 3 return -1;
383 }
384  
385 8 ENTER;
386 8 SAVETMPS;
387 8 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 8 8
388 8 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 8 8
389 8 PUSHs(sv_2mortal(newSViv(offset)));
390 8 PUSHs(sv_2mortal(newSViv(whence)));
391 8 PUTBACK;
392  
393 8 count = perl_call_sv(cbd->seekcb, G_SCALAR);
394  
395 8 SPAGAIN;
396  
397 8 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 8 8
398 0 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
399  
400 #if IVSIZE < 8
401 /* please -Duse64bitint */
402 result = POPn;
403 #else
404 8 result = POPi;
405 #endif
406  
407 8 PUTBACK;
408 8 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 8 0 8
409 8 LEAVE;
410  
411 8 return result;
412 }
413  
414 static ssize_t
415 2056 io_writer(void *p, void const *data, size_t size) {
416 dTHX;
417 2056 struct cbdata *cbd = p;
418 I32 count;
419 SV *sv;
420 2056 dSP;
421 bool success;
422  
423 2056 ▶ if (!SvOK(cbd->writecb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(cbd->writecb)) { 9 2047 2056
424 9 mm_log((1, "write callback called but no writecb supplied\n"));
425 9 i_push_error(0, "write callback called but no writecb supplied");
426 9 return -1;
427 }
428  
429 2047 ENTER;
430 2047 SAVETMPS;
431 2047 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2047 2047
432 2047 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2047 2047
433 2047 PUSHs(newSVpvn_flags((char *)data, size, SVs_TEMP));
434 2047 PUTBACK;
435  
436 2047 count = perl_call_sv(cbd->writecb, G_SCALAR);
437  
438 2047 SPAGAIN;
439 2047 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 2047 2047
440 0 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
441  
442 2047 sv = POPs;
443 2047 success = SvTRUE(sv);
444  
445  
446 2047 PUTBACK;
447 2047 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2047 0 2047
448 2047 LEAVE;
449  
450 2047 ▶ return success ? (ssize_t)size : -1;
Branch: 1 branch
BranchTrueFalseTotal
return success ? (ssize_t)size : -1; 2001 46 2047
451 }
452  
453 static ssize_t
454 109 io_reader(void *p, void *data, size_t size) {
455 109 struct cbdata *cbd = p;
456  
457 109 return call_reader(cbd, data, size, size);
458 }
459  
460 32 static int io_closer(void *p) {
461 dTHX;
462 32 struct cbdata *cbd = p;
463 32 int success = 1;
464  
465 32 ▶ if (SvOK(cbd->closecb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(cbd->closecb)) { 20 12 32
466 20 dSP;
467 I32 count;
468  
469 20 ENTER;
470 20 SAVETMPS;
471 20 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 20 20
472 20 PUTBACK;
473  
474 20 count = perl_call_sv(cbd->closecb, G_SCALAR);
475  
476 20 SPAGAIN;
477
478 20 ▶ if (count) {
Branch: 1 branch
BranchTrueFalseTotal
if (count) { 20 0 20
479 20 SV *sv = POPs;
480 20 success = SvTRUE(sv);
481 }
482 else
483 0 success = 0;
484  
485 20 PUTBACK;
486 20 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 20 0 20
487 20 LEAVE;
488 }
489  
490 32 ▶ return success ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
return success ? 0 : -1; 19 13 32
491 }
492  
493 static const char *
494 describe_sv(SV *sv);
495  
496 static off_t
497 3 io_size(void *p) {
498 dTHX;
499 3 struct cbdata *cbd = p;
500 int count;
501 off_t result;
502 3 dSP;
503  
504 3 ▶ if (cbd->size != (off_t)-1)
Branch: 1 branch
BranchTrueFalseTotal
if (cbd->size != (off_t)-1) 1 2 3
505 1 return cbd->size;
506  
507 2 ▶ if (!cbd->sizecb) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cbd->sizecb) { 1 1 2
508 1 return (off_t)-1;
509 }
510  
511 1 ENTER;
512 1 SAVETMPS;
513 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
514 1 PUTBACK;
515  
516 1 count = perl_call_sv(cbd->sizecb, G_SCALAR);
517  
518 1 SPAGAIN;
519  
520 1 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 1 1
521 0 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
522  
523 #if IVSIZE < 8
524 /* please -Duse64bitint */
525 result = POPn;
526 #else
527 1 result = POPi;
528 #endif
529  
530 1 PUTBACK;
531 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
532 1 LEAVE;
533  
534 1 return result;
535 }
536  
537 113 static void io_destroyer(void *p) {
538 dTHX;
539 113 struct cbdata *cbd = p;
540  
541 113 SvREFCNT_dec(cbd->writecb);
542 113 SvREFCNT_dec(cbd->readcb);
543 113 SvREFCNT_dec(cbd->seekcb);
544 113 SvREFCNT_dec(cbd->closecb);
545 113 SvREFCNT_dec(cbd->sizecb);
546 113 myfree(cbd);
547 113 }
548  
549 static bool
550 20 im_SvREFSCALAR(SV *sv) {
551 20 svtype type = SvTYPE(sv);
552  
553 20 ▶ switch (type) {
Branch: 1 branch
BranchTrueFalseTotal
switch (type) { 20 0 20
554 20 case SVt_PV:
555 case SVt_PVIV:
556 case SVt_PVNV:
557 case SVt_PVMG:
558 case SVt_IV:
559 case SVt_NV:
560 case SVt_PVLV:
561 #if PERL_VERSION > 10
562 case SVt_REGEXP:
563 #endif
564 20 return 1;
565  
566 0 default:
567 0 return 0;
568 }
569 }
570  
571 static const char *
572 452 describe_sv(SV *sv) {
573 452 ▶ if (SvOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv)) { 170 282 452
574 170 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 169 1 170
575 169 svtype type = SvTYPE(SvRV(sv));
576 169 switch (type) {
577 169 case SVt_PVCV: return "CV";
578 0 case SVt_PVGV: return "GV";
579 0 case SVt_PVLV: return "LV";
580 0 default: return "some reference";
581 }
582 }
583 else {
584 1 return "non-reference scalar";
585 }
586 }
587 else {
588 282 return "undef";
589 }
590 }
591  
592 static i_io_glue_t *
593 204 do_io_new_buffer(pTHX_ SV *data_sv) {
594 const char *data;
595 char *data_copy;
596 STRLEN length;
597 SV *sv;
598  
599 204 ▶ SvGETMAGIC(data_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(data_sv); 0 204 204
SvGETMAGIC(data_sv); 0 0 0
600 204 ▶ if (SvROK(data_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(data_sv)) { 20 184 204
601 20 ▶ if (im_SvREFSCALAR(SvRV(data_sv))) {
Branch: 1 branch
BranchTrueFalseTotal
if (im_SvREFSCALAR(SvRV(data_sv))) { 20 0 20
602 20 sv = SvRV(data_sv);
603 }
604 else {
605 0 i_push_errorf(0, "data is not a scalar or a reference to scalar");
606 0 return NULL;
607 }
608 }
609 else {
610 184 sv = data_sv;
611 }
612  
613 /* previously this would keep the SV around, but this is unsafe in
614 many ways, so always copy the bytes */
615 204 data = SvPVbyte(sv, length);
616 204 data_copy = mymalloc(length);
617 204 memcpy(data_copy, data, length);
618 204 return io_new_buffer(data_copy, length, free_buffer, data_copy);
619 }
620  
621 static i_io_glue_t *
622 113 do_io_new_cb(pTHX_ SV *writecb, SV *readcb, SV *seekcb, SV *closecb, SV *size_or_cb) {
623 struct cbdata *cbd;
624  
625 113 i_clear_error();
626 113 cbd = mymalloc(sizeof(struct cbdata));
627 113 cbd->writecb = newSVsv(writecb);
628 113 cbd->readcb = newSVsv(readcb);
629 113 cbd->seekcb = newSVsv(seekcb);
630 113 cbd->closecb = newSVsv(closecb);
631  
632 113 cbd->sizecb = NULL;
633 113 cbd->size = -1;
634  
635 113 ▶ if (size_or_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (size_or_cb) { 53 60 113
636 53 ▶ SvGETMAGIC(size_or_cb);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(size_or_cb); 0 53 53
SvGETMAGIC(size_or_cb); 0 0 0
637 53 ▶ if (SvROK(size_or_cb) && SvTYPE(SvRV(size_or_cb)) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(size_or_cb) && SvTYPE(SvRV(size_or_cb)) == SVt_PVCV) { 1 52 53
if (SvROK(size_or_cb) && SvTYPE(SvRV(size_or_cb)) == SVt_PVCV) { 1 0 1
638 1 cbd->sizecb = newSVsv(size_or_cb);
639 }
640 52 ▶ else if (size_or_cb && SvOK(size_or_cb)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (size_or_cb && SvOK(size_or_cb)) { 52 0 52
else if (size_or_cb && SvOK(size_or_cb)) { 44 8 52
641 #if IVSIZE < 8
642 cbd->size = SvNV(size_or_cb);
643 #else
644 44 cbd->size = SvIV(size_or_cb);
645 #endif
646 }
647 }
648 113 mm_log((1, "do_io_new_cb(writecb %p (%s), readcb %p (%s), seekcb %p (%s), closecb %p (%s))\n", writecb, describe_sv(writecb), readcb, describe_sv(readcb), seekcb, describe_sv(seekcb), closecb, describe_sv(closecb)));
649  
650 113 return im_io_new_cb8(aIMCTX, cbd, io_reader, io_writer, io_seeker,
651 io_closer, io_destroyer, io_size);
652 }
653  
654 struct value_name {
655 const char *name;
656 int value;
657 };
658 static int
659 36 lookup_name(const struct value_name *names, int count, char *name, int def_value, int push_errors, const char *id, int *failed)
660 {
661 int i;
662  
663 36 ▶ if (push_errors)
Branch: 1 branch
BranchTrueFalseTotal
if (push_errors) 30 6 36
664 30 *failed = 0;
665  
666 113 ▶ for (i = 0; i < count; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) 112 1 113
667 112 ▶ if (strEQ(names[i].name, name))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(names[i].name, name)) 35 77 112
668 35 return names[i].value;
669  
670 1 ▶ if (push_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (push_errors) { 1 0 1
671 1 i_push_errorf(0, "unknown value '%s' for %s", name, id);
672 1 *failed = 1;
673 }
674  
675 1 return def_value;
676 }
677  
678 static struct value_name transp_names[] =
679 {
680 { "none", tr_none },
681 { "threshold", tr_threshold },
682 { "errdiff", tr_errdiff },
683 { "ordered", tr_ordered, },
684 };
685  
686 static struct value_name make_color_names[] =
687 {
688 { "none", mc_none, },
689 { "webmap", mc_web_map, },
690 { "addi", mc_addi, },
691 { "mediancut", mc_median_cut, },
692 { "mono", mc_mono, },
693 { "monochrome", mc_mono, },
694 { "gray", mc_gray, },
695 { "gray4", mc_gray4, },
696 { "gray16", mc_gray16, },
697 };
698  
699 static struct value_name translate_names[] =
700 {
701 { "giflib", pt_giflib, },
702 { "closest", pt_closest, },
703 { "perturb", pt_perturb, },
704 { "errdiff", pt_errdiff, },
705 };
706  
707 static struct value_name errdiff_names[] =
708 {
709 { "floyd", ed_floyd, },
710 { "jarvis", ed_jarvis, },
711 { "stucki", ed_stucki, },
712 { "custom", ed_custom, },
713 };
714  
715 static struct value_name orddith_names[] =
716 {
717 { "random", od_random, },
718 { "dot8", od_dot8, },
719 { "dot4", od_dot4, },
720 { "hline", od_hline, },
721 { "vline", od_vline, },
722 { "/line", od_slashline, },
723 { "slashline", od_slashline, },
724 { "\\line", od_backline, },
725 { "backline", od_backline, },
726 { "tiny", od_tiny, },
727 { "custom", od_custom, },
728 };
729  
730 /* look through the hash for quantization options */
731 static int
732 24 ip_handle_quant_opts_low(pTHX_ i_quantize *quant, HV *hv, int push_errors)
733 {
734 SV **sv;
735 int i;
736 STRLEN len;
737 char *str;
738 24 int failed = 0;
739  
740 24 quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color));
741  
742 24 sv = hv_fetchs(hv, "transp", 0);
743 24 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 0 24 24
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
744 0 quant->transp =
745 0 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
746 str, tr_none, push_errors, "transp", &failed);
747 0 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 0 0 0
748 0 return 0;
749 0 ▶ if (quant->transp != tr_none) {
Branch: 1 branch
BranchTrueFalseTotal
if (quant->transp != tr_none) { 0 0 0
750 0 quant->tr_threshold = 127;
751 0 sv = hv_fetchs(hv, "tr_threshold", 0);
752 0 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 0 0 0
if (sv && *sv) 0 0 0
753 0 quant->tr_threshold = SvIV(*sv);
754 }
755 0 ▶ if (quant->transp == tr_errdiff) {
Branch: 1 branch
BranchTrueFalseTotal
if (quant->transp == tr_errdiff) { 0 0 0
756 0 sv = hv_fetchs(hv, "tr_errdiff", 0);
757 0 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
758 0 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "tr_errdiff", &failed);
759 0 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 0 0 0
760 0 return 0;
761 }
762 }
763 0 ▶ if (quant->transp == tr_ordered) {
Branch: 1 branch
BranchTrueFalseTotal
if (quant->transp == tr_ordered) { 0 0 0
764 0 quant->tr_orddith = od_tiny;
765 0 sv = hv_fetchs(hv, "tr_orddith", 0);
766 0 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
if (sv && *sv && (str = SvPV(*sv, len))) { 0 0 0
767 0 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random, push_errors, "tr_orddith", &failed);
768 0 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 0 0 0
769 0 return 0;
770 }
771  
772 0 ▶ if (quant->tr_orddith == od_custom) {
Branch: 1 branch
BranchTrueFalseTotal
if (quant->tr_orddith == od_custom) { 0 0 0
773 0 sv = hv_fetchs(hv, "tr_map", 0);
774 0 ▶ if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 0 0 0
if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 0 0 0
if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 0 0 0
775 0 AV *av = (AV*)SvRV(*sv);
776 unsigned index;
777 0 len = av_len(av) + 1;
778 0 ▶ if (len > sizeof(quant->tr_custom))
Branch: 1 branch
BranchTrueFalseTotal
if (len > sizeof(quant->tr_custom)) 0 0 0
779 0 len = sizeof(quant->tr_custom);
780 0 ▶ for (index = 0; index < len; ++index) {
Branch: 1 branch
BranchTrueFalseTotal
for (index = 0; index < len; ++index) { 0 0 0
781 0 SV **sv2 = av_fetch(av, index, 0);
782 0 ▶ if (sv2 && *sv2) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv2 && *sv2) { 0 0 0
if (sv2 && *sv2) { 0 0 0
783 0 quant->tr_custom[index] = SvIV(*sv2);
784 }
785 }
786 0 ▶ while (index < sizeof(quant->tr_custom))
Branch: 1 branch
BranchTrueFalseTotal
while (index < sizeof(quant->tr_custom)) 0 0 0
787 0 quant->tr_custom[index++] = 0;
788 }
789 }
790 }
791 }
792 24 quant->make_colors = mc_median_cut;
793 24 sv = hv_fetchs(hv, "make_colors", 0);
794 44 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 20 4 24
if (sv && *sv && (str = SvPV(*sv, len))) { 20 0 20
if (sv && *sv && (str = SvPV(*sv, len))) { 20 0 20
795 20 quant->make_colors =
796 20 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_median_cut, push_errors, "make_colors", &failed);
797 20 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 1 19 20
798 1 return 0;
799 }
800 23 sv = hv_fetchs(hv, "colors", 0);
801 23 ▶ if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 8 15 23
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 8 0 8
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 8 0 8
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 8 0 8
802 /* needs to be an array of Imager::Color
803 note that the caller allocates the mc_color array and sets mc_size
804 to it's size */
805 8 AV *av = (AV *)SvRV(*sv);
806 8 quant->mc_count = av_len(av)+1;
807 8 ▶ if (quant->mc_count > quant->mc_size)
Branch: 1 branch
BranchTrueFalseTotal
if (quant->mc_count > quant->mc_size) 0 8 8
808 0 quant->mc_count = quant->mc_size;
809 43 ▶ for (i = 0; i < quant->mc_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < quant->mc_count; ++i) { 35 8 43
810 35 SV **sv1 = av_fetch(av, i, 0);
811 35 ▶ if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
Branch: 4 branches
BranchTrueFalseTotal
if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { 35 0 35
if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { 35 0 35
if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { 35 0 35
if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) { 35 0 35
812 35 i_color *col = INT2PTR(i_color *, SvIV((SV*)SvRV(*sv1)));
813 35 quant->mc_colors[i] = *col;
814 }
815 0 ▶ else if (push_errors) {
Branch: 1 branch
BranchTrueFalseTotal
else if (push_errors) { 0 0 0
816 0 i_push_errorf(0, "colors[%d] isn't an Imager::Color object", i);
817 0 return 0;
818 }
819 }
820 }
821 23 sv = hv_fetchs(hv, "max_colors", 0);
822 23 ▶ if (sv && *sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) { 0 23 23
if (sv && *sv) { 0 0 0
823 0 IV iv = SvIV(*sv);
824 0 ▶ if (iv <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (iv <= 0) { 0 0 0
825 0 i_push_errorf(0, "max_colors of %ld is invalid", (long)iv);
826 0 return 0;
827 }
828 0 ▶ if (iv <= quant->mc_size && iv >= quant->mc_count)
Branch: 2 branches
BranchTrueFalseTotal
if (iv <= quant->mc_size && iv >= quant->mc_count) 0 0 0
if (iv <= quant->mc_size && iv >= quant->mc_count) 0 0 0
829 0 quant->mc_size = iv;
830 }
831  
832 23 quant->translate = pt_closest;
833 23 sv = hv_fetchs(hv, "translate", 0);
834 32 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 9 14 23
if (sv && *sv && (str = SvPV(*sv, len))) { 9 0 9
if (sv && *sv && (str = SvPV(*sv, len))) { 9 0 9
835 9 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest, push_errors, "translate", &failed);
836 9 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 0 9 9
837 0 return 0;
838 }
839 23 sv = hv_fetchs(hv, "errdiff", 0);
840 24 ▶ if (sv && *sv && (str = SvPV(*sv, len))) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && *sv && (str = SvPV(*sv, len))) { 1 22 23
if (sv && *sv && (str = SvPV(*sv, len))) { 1 0 1
if (sv && *sv && (str = SvPV(*sv, len))) { 1 0 1
841 1 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "errdiff", &failed);
842 1 ▶ if (failed)
Branch: 1 branch
BranchTrueFalseTotal
if (failed) 0 1 1
843 0 return 0;
844 }
845 23 ▶ if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
Branch: 2 branches
BranchTrueFalseTotal
if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) { 6 17 23
if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) { 1 5 6
846 /* get the error diffusion map */
847 1 sv = hv_fetchs(hv, "errdiff_width", 0);
848 1 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 1 0 1
if (sv && *sv) 1 0 1
849 1 quant->ed_width = SvIV(*sv);
850 1 sv = hv_fetchs(hv, "errdiff_height", 0);
851 1 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 1 0 1
if (sv && *sv) 1 0 1
852 1 quant->ed_height = SvIV(*sv);
853 1 sv = hv_fetchs(hv, "errdiff_orig", 0);
854 1 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 0 1 1
if (sv && *sv) 0 0 0
855 0 quant->ed_orig = SvIV(*sv);
856 1 ▶ if (quant->ed_width > 0 && quant->ed_height > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (quant->ed_width > 0 && quant->ed_height > 0) { 1 0 1
if (quant->ed_width > 0 && quant->ed_height > 0) { 1 0 1
857 1 int sum = 0;
858 1 quant->ed_map = mymalloc(sizeof(int) * quant->ed_width * quant->ed_height);
859 1 sv = hv_fetchs(hv, "errdiff_map", 0);
860 1 ▶ if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 1 0 1
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 1 0 1
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 1 0 1
if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) { 1 0 1
861 1 AV *av = (AV*)SvRV(*sv);
862 size_t avi;
863 1 len = av_len(av) + 1;
864 1 ▶ if (len > (size_t)quant->ed_width * quant->ed_height)
Branch: 1 branch
BranchTrueFalseTotal
if (len > (size_t)quant->ed_width * quant->ed_height) 0 1 1
865 0 len = (size_t)quant->ed_width * quant->ed_height;
866 5 ▶ for (avi = 0; avi < len; ++avi) {
Branch: 1 branch
BranchTrueFalseTotal
for (avi = 0; avi < len; ++avi) { 4 1 5
867 4 SV **sv2 = av_fetch(av, avi, 0);
868 4 ▶ if (sv2 && *sv2) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv2 && *sv2) { 4 0 4
if (sv2 && *sv2) { 4 0 4
869 4 IV iv = SvIV(*sv2);
870 4 ▶ if (push_errors && iv < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (push_errors && iv < 0) { 4 0 4
if (push_errors && iv < 0) { 0 4 4
871 0 i_push_errorf(0, "errdiff_map values must be non-negative, errdiff[%lu] is negative",
872 (unsigned long)avi);
873 0 return 0;
874 }
875 4 quant->ed_map[avi] = iv;
876 4 sum += quant->ed_map[avi];
877 }
878 }
879 }
880 1 ▶ if (!sum) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sum) { 1 0 1
881 /* broken map */
882 1 myfree(quant->ed_map);
883 1 quant->ed_map = 0;
884 1 quant->errdiff = ed_floyd;
885 1 ▶ if (push_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (push_errors) { 1 0 1
886 1 i_push_error(0, "error diffusion map must contain some non-zero values");
887 1 return 0;
888 }
889 }
890 }
891 }
892 22 sv = hv_fetchs(hv, "perturb", 0);
893 22 ▶ if (sv && *sv)
Branch: 2 branches
BranchTrueFalseTotal
if (sv && *sv) 0 22 22
if (sv && *sv) 0 0 0
894 0 quant->perturb = SvIV(*sv);
895  
896 22 return 1;
897 }
898  
899 static void
900 24 ip_cleanup_quant_opts(pTHX_ i_quantize *quant) {
901 24 myfree(quant->mc_colors);
902 24 ▶ if (quant->ed_map)
Branch: 1 branch
BranchTrueFalseTotal
if (quant->ed_map) 0 24 24
903 0 myfree(quant->ed_map);
904 24 }
905  
906 static int
907 24 ip_handle_quant_opts2(pTHX_ i_quantize *quant, HV *hv) {
908 24 int result = ip_handle_quant_opts_low(aTHX_ quant, hv, 1);
909 24 ▶ if (!result) {
Branch: 1 branch
BranchTrueFalseTotal
if (!result) { 2 22 24
910 2 ip_cleanup_quant_opts(aTHX_ quant);
911 }
912 24 return result;
913 }
914  
915 static void
916 0 ip_handle_quant_opts(pTHX_ i_quantize *quant, HV *hv) {
917 0 (void)ip_handle_quant_opts_low(aTHX_ quant, hv, 0);
918 0 }
919  
920 /* copies the color map from the hv into the colors member of the HV */
921 static void
922 17 ip_copy_colors_back(pTHX_ HV *hv, i_quantize *quant) {
923 SV **sv;
924 AV *av;
925 int i;
926 SV *work;
927  
928 17 sv = hv_fetchs(hv, "colors", 0);
929 17 ▶ if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { 7 10 17
if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { 7 0 7
if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { 7 0 7
if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) { 0 7 7
930 /* nothing to do */
931 10 return;
932 }
933  
934 7 av = (AV *)SvRV(*sv);
935 7 av_clear(av);
936 7 av_extend(av, quant->mc_count+1);
937 258 ▶ for (i = 0; i < quant->mc_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < quant->mc_count; ++i) { 251 7 258
938 251 i_color *in = quant->mc_colors+i;
939 251 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
940 251 work = sv_newmortal();
941 251 sv_setref_pv(work, "Imager::Color", (void *)c);
942 251 SvREFCNT_inc(work);
943 251 av_push(av, work);
944 }
945 }
946  
947 static struct value_name
948 poly_fill_mode_names[] =
949 {
950 { "evenodd", i_pfm_evenodd },
951 { "nonzero", i_pfm_nonzero }
952 };
953  
954 static i_poly_fill_mode_t
955 73 S_get_poly_fill_mode(pTHX_ SV *sv) {
956 73 ▶ if (looks_like_number(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (looks_like_number(sv)) { 67 6 73
957 67 IV work = SvIV(sv);
958 67 ▶ if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero)
Branch: 2 branches
BranchTrueFalseTotal
if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero) 67 0 67
if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero) 0 67 67
959 0 work = (IV)i_pfm_evenodd;
960 67 return (i_poly_fill_mode_t)work;
961 }
962 else {
963 6 return (i_poly_fill_mode_t)lookup_name
964 (poly_fill_mode_names, ARRAY_COUNT(poly_fill_mode_names),
965 SvPV_nolen(sv), i_pfm_evenodd, 0, NULL, NULL);
966 }
967 }
968  
969 static void
970 6 S_get_polygon_list(pTHX_ i_polygon_list *polys, SV *sv) {
971 AV *av;
972 size_t poly_index;
973 i_polygon_t *s;
974  
975 6 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 6 6
SvGETMAGIC(sv); 0 0 0
976 6 ▶ if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) 6 0 6
if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) 6 0 6
if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) 0 6 6
977 0 croak("polys must be an arrayref");
978  
979 6 av = (AV*)SvRV(sv);
980 6 polys->count = av_len(av) + 1;
981 6 ▶ if (polys->count < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (polys->count < 1) 0 6 6
982 0 croak("polypolygon: no polygons provided");
983 6 s = malloc_temp(aTHX_ sizeof(i_polygon_t) * polys->count);
984 20 ▶ for (poly_index = 0; poly_index < polys->count; ++poly_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (poly_index = 0; poly_index < polys->count; ++poly_index) { 14 6 20
985 14 SV **poly_sv = av_fetch(av, poly_index, 0);
986 AV *poly_av;
987 SV **x_sv, **y_sv;
988 AV *x_av, *y_av;
989 double *x_data, *y_data;
990 ssize_t j;
991 ssize_t point_count;
992  
993 14 ▶ if (!poly_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!poly_sv) 0 14 14
994 0 croak("poly_polygon: nothing found for polygon %zu", poly_index);
995 /* needs to be another av */
996 14 ▶ SvGETMAGIC(*poly_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(*poly_sv); 0 14 14
SvGETMAGIC(*poly_sv); 0 0 0
997 14 ▶ if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV) 14 0 14
if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV) 14 0 14
if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV) 0 14 14
998 0 croak("poly_polygon: polygon %zu isn't an arrayref", poly_index);
999 14 poly_av = (AV*)SvRV(*poly_sv);
1000 /* with two elements */
1001 14 ▶ if (av_len(poly_av) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(poly_av) != 1) 0 14 14
1002 0 croak("poly_polygon: polygon %zu should contain two arrays", poly_index);
1003 14 x_sv = av_fetch(poly_av, 0, 0);
1004 14 y_sv = av_fetch(poly_av, 1, 0);
1005 14 ▶ if (!x_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!x_sv) 0 14 14
1006 0 croak("poly_polygon: polygon %zu has no x elements", poly_index);
1007 14 ▶ if (!y_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!y_sv) 0 14 14
1008 0 croak("poly_polygon: polygon %zu has no y elements", poly_index);
1009 14 ▶ SvGETMAGIC(*x_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(*x_sv); 0 14 14
SvGETMAGIC(*x_sv); 0 0 0
1010 14 ▶ SvGETMAGIC(*y_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(*y_sv); 0 14 14
SvGETMAGIC(*y_sv); 0 0 0
1011 14 ▶ if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV) { 14 0 14
if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV) { 14 0 14
if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV) { 0 14 14
1012 0 croak("poly_polygon: polygon %zu x elements isn't an array",
1013 poly_index);
1014 }
1015 14 ▶ if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV) { 14 0 14
if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV) { 14 0 14
if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV) { 0 14 14
1016 0 croak("poly_polygon: polygon %zu y elements isn't an array",
1017 poly_index);
1018 }
1019 14 x_av = (AV*)SvRV(*x_sv);
1020 14 y_av = (AV*)SvRV(*y_sv);
1021 14 ▶ if (av_len(x_av) != av_len(y_av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(x_av) != av_len(y_av)) { 0 14 14
1022 0 croak("poly_polygon: polygon %zu x and y arrays different lengths",
1023 poly_index+1);
1024 }
1025 14 point_count = av_len(x_av)+1;
1026 14 x_data = malloc_temp(aTHX_ sizeof(double) * point_count * 2);
1027 14 y_data = x_data + point_count;
1028  
1029 70 ▶ for (j = 0; j < point_count; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < point_count; ++j) { 56 14 70
1030 56 SV **x_item_sv = av_fetch(x_av, j, 0);
1031 56 SV **y_item_sv = av_fetch(y_av, j, 0);
1032 56 ▶ x_data[j] = x_item_sv ? SvNV(*x_item_sv) : 0;
Branch: 1 branch
BranchTrueFalseTotal
x_data[j] = x_item_sv ? SvNV(*x_item_sv) : 0; 56 0 56
1033 56 ▶ y_data[j] = y_item_sv ? SvNV(*y_item_sv) : 0;
Branch: 1 branch
BranchTrueFalseTotal
y_data[j] = y_item_sv ? SvNV(*y_item_sv) : 0; 56 0 56
1034 }
1035 14 s[poly_index].x = x_data;
1036 14 s[poly_index].y = y_data;
1037 14 s[poly_index].count = point_count;
1038 }
1039 6 polys->polygons = s;
1040 6 }
1041  
1042 /* loads the segments of a fountain fill into an array */
1043 static i_fountain_seg *
1044 14 load_fount_segs(pTHX_ AV *asegs, int *count) {
1045 /* Each element of segs must contain:
1046 [ start, middle, end, c0, c1, segtype, colortrans ]
1047 start, middle, end are doubles from 0 to 1
1048 c0, c1 are Imager::Color::Float or Imager::Color objects
1049 segtype, colortrans are ints
1050 */
1051 int i, j;
1052 AV *aseg;
1053 i_fountain_seg *segs;
1054 double work[3];
1055 int worki[2];
1056  
1057 14 *count = av_len(asegs)+1;
1058 14 ▶ if (*count < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (*count < 1) 0 14 14
1059 0 croak("i_fountain must have at least one segment");
1060 14 segs = mymalloc(sizeof(i_fountain_seg) * *count);
1061 31 ▶ for(i = 0; i < *count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < *count; i++) { 17 14 31
1062 17 SV **sv1 = av_fetch(asegs, i, 0);
1063 17 ▶ if (!sv1 || !*sv1 || !SvROK(*sv1)
Branch: 3 branches
BranchTrueFalseTotal
if (!sv1 || !*sv1 || !SvROK(*sv1) 17 0 17
if (!sv1 || !*sv1 || !SvROK(*sv1) 17 0 17
if (!sv1 || !*sv1 || !SvROK(*sv1) 17 0 17
1064 17 ▶ || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*sv1)) != SVt_PVAV) { 0 17 17
1065 0 myfree(segs);
1066 0 croak("i_fountain: segs must be an arrayref of arrayrefs");
1067 }
1068 17 aseg = (AV *)SvRV(*sv1);
1069 17 ▶ if (av_len(aseg) != 7-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(aseg) != 7-1) { 0 17 17
1070 0 myfree(segs);
1071 0 croak("i_fountain: a segment must have 7 members");
1072 }
1073 68 ▶ for (j = 0; j < 3; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < 3; ++j) { 51 17 68
1074 51 SV **sv2 = av_fetch(aseg, j, 0);
1075 51 ▶ if (!sv2 || !*sv2) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv2 || !*sv2) { 51 0 51
if (!sv2 || !*sv2) { 0 51 51
1076 0 myfree(segs);
1077 0 croak("i_fountain: XS error");
1078 }
1079 51 work[j] = SvNV(*sv2);
1080 }
1081 17 segs[i].start = work[0];
1082 17 segs[i].middle = work[1];
1083 17 segs[i].end = work[2];
1084 51 ▶ for (j = 0; j < 2; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < 2; ++j) { 34 17 51
1085 34 SV **sv3 = av_fetch(aseg, 3+j, 0);
1086 34 ▶ if (!sv3 || !*sv3 || !SvROK(*sv3) ||
Branch: 3 branches
BranchTrueFalseTotal
if (!sv3 || !*sv3 || !SvROK(*sv3) || 34 0 34
if (!sv3 || !*sv3 || !SvROK(*sv3) || 34 0 34
if (!sv3 || !*sv3 || !SvROK(*sv3) || 34 0 34
1087 34 ▶ (!sv_derived_from(*sv3, "Imager::Color")
Branch: 1 branch
BranchTrueFalseTotal
(!sv_derived_from(*sv3, "Imager::Color") 5 29 34
1088 5 ▶ && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
Branch: 1 branch
BranchTrueFalseTotal
&& !sv_derived_from(*sv3, "Imager::Color::Float"))) { 0 5 5
1089 0 myfree(segs);
1090 0 croak("i_fountain: segs must contain colors in elements 3 and 4");
1091 }
1092 34 ▶ if (sv_derived_from(*sv3, "Imager::Color::Float")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(*sv3, "Imager::Color::Float")) { 5 29 34
1093 5 segs[i].c[j] = *INT2PTR(i_fcolor *, SvIV((SV *)SvRV(*sv3)));
1094 }
1095 else {
1096 29 i_color c = *INT2PTR(i_color *, SvIV((SV *)SvRV(*sv3)));
1097 int ch;
1098 145 ▶ for (ch = 0; ch < MAXCHANNELS; ++ch) {
Branch: 1 branch
BranchTrueFalseTotal
for (ch = 0; ch < MAXCHANNELS; ++ch) { 116 29 145
1099 116 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
1100 }
1101 }
1102 }
1103 51 ▶ for (j = 0; j < 2; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < 2; ++j) { 34 17 51
1104 34 SV **sv2 = av_fetch(aseg, j+5, 0);
1105 34 ▶ if (!sv2 || !*sv2) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv2 || !*sv2) { 34 0 34
if (!sv2 || !*sv2) { 0 34 34
1106 0 myfree(segs);
1107 0 croak("i_fountain: XS error");
1108 }
1109 34 worki[j] = SvIV(*sv2);
1110 }
1111 17 segs[i].type = worki[0];
1112 17 segs[i].color = worki[1];
1113 }
1114  
1115 14 return segs;
1116 }
1117  
1118 /* validates the indexes supplied to i_ppal
1119  
1120 i_ppal() doesn't do that for speed, but I'm not comfortable doing that
1121 for calls from perl.
1122  
1123 */
1124 static void
1125 335 validate_i_ppal(i_img *im, i_palidx const *indexes, int count) {
1126 335 ▶ int color_count = i_colorcount(im);
Branch: 1 branch
BranchTrueFalseTotal
int color_count = i_colorcount(im); 335 0 335
1127 int i;
1128  
1129 335 ▶ if (color_count == -1)
Branch: 1 branch
BranchTrueFalseTotal
if (color_count == -1) 0 335 335
1130 0 croak("i_plin() called on direct color image");
1131
1132 61061 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 60730 331 61061
1133 60730 ▶ if (indexes[i] >= color_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (indexes[i] >= color_count) { 4 60726 60730
1134 4 croak("i_plin() called with out of range color index %d (max %d)",
1135 indexes[i], color_count-1);
1136 }
1137 }
1138 331 }
1139  
1140 /* I don't think ICLF_* names belong at the C interface
1141 this makes the XS code think we have them, to let us avoid
1142 putting function bodies in the XS code
1143 */
1144 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
1145 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
1146  
1147 #ifdef IMAGER_LOG
1148 #define i_log_enabled() 1
1149 #else
1150 #define i_log_enabled() 0
1151 #endif
1152  
1153 #if i_int_hlines_testing()
1154  
1155 typedef i_int_hlines *Imager__Internal__Hlines;
1156  
1157 static i_int_hlines *
1158 2 i_int_hlines_new(i_img_dim start_y, i_img_dim count_y, i_img_dim start_x, i_img_dim count_x) {
1159 2 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
1160 2 i_int_init_hlines(result, start_y, count_y, start_x, count_x);
1161  
1162 2 return result;
1163 }
1164  
1165 static i_int_hlines *
1166 1 i_int_hlines_new_img(i_img *im) {
1167 1 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
1168 1 i_int_init_hlines_img(result, im);
1169  
1170 1 return result;
1171 }
1172  
1173 static void
1174 3 i_int_hlines_DESTROY(i_int_hlines *hlines) {
1175 3 i_int_hlines_destroy(hlines);
1176 3 myfree(hlines);
1177 3 }
1178  
1179 #define i_int_hlines_CLONE_SKIP(cls) 1
1180  
1181 45 static int seg_compare(const void *vleft, const void *vright) {
1182 45 const i_int_hline_seg *left = vleft;
1183 45 const i_int_hline_seg *right = vright;
1184  
1185 45 return left->minx - right->minx;
1186 }
1187  
1188 static SV *
1189 15 i_int_hlines_dump(i_int_hlines *hlines) {
1190 dTHX;
1191 15 SV *dump = newSVpvf("start_y: %" i_DF " limit_y: %" i_DF " start_x: %" i_DF " limit_x: %" i_DF"\n",
1192 i_DFc(hlines->start_y), i_DFc(hlines->limit_y), i_DFc(hlines->start_x), i_DFc(hlines->limit_x));
1193 i_img_dim y;
1194
1195 1375 ▶ for (y = hlines->start_y; y < hlines->limit_y; ++y) {
Branch: 1 branch
BranchTrueFalseTotal
for (y = hlines->start_y; y < hlines->limit_y; ++y) { 1360 15 1375
1196 1360 i_int_hline_entry *entry = hlines->entries[y-hlines->start_y];
1197 1360 ▶ if (entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry) { 19 1341 1360
1198 int i;
1199 /* sort the segments, if any */
1200 19 ▶ if (entry->count)
Branch: 1 branch
BranchTrueFalseTotal
if (entry->count) 19 0 19
1201 19 qsort(entry->segs, entry->count, sizeof(i_int_hline_seg), seg_compare);
1202  
1203 19 sv_catpvf(dump, " %" i_DF " (%" i_DF "):", i_DFc(y), i_DFc(entry->count));
1204 61 ▶ for (i = 0; i < entry->count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < entry->count; ++i) { 42 19 61
1205 42 sv_catpvf(dump, " [%" i_DF ", %" i_DF ")", i_DFc(entry->segs[i].minx),
1206 i_DFc(entry->segs[i].x_limit));
1207 }
1208 19 sv_catpv(dump, "\n");
1209 }
1210 }
1211  
1212 15 return dump;
1213 }
1214  
1215 #endif
1216  
1217 static off_t
1218 20 i_sv_off_t(pTHX_ SV *sv) {
1219 #if LSEEKSIZE > IVSIZE
1220 return (off_t)SvNV(sv);
1221 #else
1222 20 return (off_t)SvIV(sv);
1223 #endif
1224 }
1225  
1226 static SV *
1227 17 i_new_sv_off_t(pTHX_ off_t off) {
1228 #if LSEEKSIZE > IVSIZE
1229 return newSVnv(off);
1230 #else
1231 17 return newSViv(off);
1232 #endif
1233 }
1234  
1235 static im_pl_ext_funcs im_perl_funcs =
1236 {
1237 IMAGER_PL_API_VERSION,
1238 IMAGER_PL_API_LEVEL,
1239 ip_handle_quant_opts,
1240 ip_cleanup_quant_opts,
1241 ip_copy_colors_back,
1242 ip_handle_quant_opts2
1243 };
1244  
1245 #define trim_color_list__new() S_trim_color_list__new(aTHX)
1246 static i_trim_color_list
1247 101 S_trim_color_list__new(pTHX) {
1248 i_trim_color_list r;
1249  
1250 101 r.count = 0;
1251 101 r.rsv = newSV(0);
1252 101 sv_setref_pvn(r.rsv, "Imager::TrimColorList", "", 0);
1253 101 r.sv = SvRV(r.rsv);
1254 101 r.colors = (i_trim_colors_t *)SvPVX(r.sv);
1255  
1256 101 return r;
1257 }
1258  
1259 static int
1260 40 trim_color_list_grow(pTHX_ i_trim_color_list *t) {
1261 40 STRLEN old_cur = SvCUR(t->sv);
1262 char *p;
1263 40 ▶ SvGROW(t->sv, SvCUR(t->sv)+sizeof(i_trim_colors_t)+1);
Branch: 2 branches
BranchTrueFalseTotal
SvGROW(t->sv, SvCUR(t->sv)+sizeof(i_trim_colors_t)+1); 40 0 40
SvGROW(t->sv, SvCUR(t->sv)+sizeof(i_trim_colors_t)+1); 40 0 40
1264 40 p = SvPVX(t->sv);
1265 40 memset(p+old_cur, 0, sizeof(i_trim_colors_t));
1266 40 t->colors = (i_trim_colors_t *)p;
1267  
1268 40 return 1;
1269 }
1270  
1271 #define trim_color_list_add_color(t, c1, c2) S_trim_color_list_add_color(aTHX_ (t), (c1), (c2))
1272 static int
1273 36 S_trim_color_list_add_color(pTHX_ i_trim_color_list t, const i_color *c1, const i_color *c2) {
1274 i_trim_colors_t *e;
1275 36 ▶ if (!trim_color_list_grow(aTHX_ &t))
Branch: 1 branch
BranchTrueFalseTotal
if (!trim_color_list_grow(aTHX_ &t)) 0 36 36
1276 0 return 0;
1277  
1278 36 e = t.colors + t.count;
1279  
1280 36 e->is_float = 0;
1281 36 e->c1 = *c1;
1282 36 e->c2 = *c2;
1283  
1284 36 ++t.count;
1285 36 SvCUR_set(t.sv, t.count * sizeof(i_trim_colors_t));
1286 36 *SvEND(t.sv) = '\0';
1287  
1288 36 return 1;
1289 }
1290  
1291 #define trim_color_list_add_fcolor(t, c1, c2) S_trim_color_list_add_fcolor(aTHX_ (t), (c1), (c2))
1292 static int
1293 4 S_trim_color_list_add_fcolor(pTHX_ i_trim_color_list t, const i_fcolor *c1, const i_fcolor *c2) {
1294 i_trim_colors_t *e;
1295 4 ▶ if (!trim_color_list_grow(aTHX_ &t))
Branch: 1 branch
BranchTrueFalseTotal
if (!trim_color_list_grow(aTHX_ &t)) 0 4 4
1296 0 return 0;
1297  
1298 4 e = t.colors + t.count;
1299  
1300 4 e->is_float = 1;
1301 4 e->cf1 = *c1;
1302 4 e->cf2 = *c2;
1303  
1304 4 ++t.count;
1305 4 SvCUR_set(t.sv, t.count * sizeof(i_trim_colors_t));
1306 4 *SvEND(t.sv) = '\0';
1307  
1308 4 return 1;
1309 }
1310  
1311 #define trim_color_list_get(t, i) S_trim_color_list_get(aTHX_ (t), (i))
1312 static SV *
1313 11 S_trim_color_list_get(pTHX_ i_trim_color_list t, IV i) {
1314 SV *r;
1315 AV *av;
1316 const i_trim_colors_t *e;
1317  
1318 11 ▶ if (i < 0 || (size_t)i >= t.count) {
Branch: 2 branches
BranchTrueFalseTotal
if (i < 0 || (size_t)i >= t.count) { 11 0 11
if (i < 0 || (size_t)i >= t.count) { 1 10 11
1319 1 return &PL_sv_undef;
1320 }
1321  
1322 10 av = newAV();
1323 10 r = newRV_noinc((SV*)av);
1324 10 e = t.colors+i;
1325  
1326 10 ▶ if (e->is_float) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->is_float) { 4 6 10
1327 4 av_push(av, make_i_fcolor_sv(aTHX_ &e->cf1));
1328 4 av_push(av, make_i_fcolor_sv(aTHX_ &e->cf2));
1329 }
1330 else {
1331 6 av_push(av, make_i_color_sv(aTHX_ &e->c1));
1332 6 av_push(av, make_i_color_sv(aTHX_ &e->c2));
1333 }
1334  
1335 10 return r;
1336 }
1337  
1338 /* given a ref to an Imager::TrimColorList fill in an i_trim_color_list structure */
1339 static bool
1340 78 S_get_trim_color_list(pTHX_ SV *sv, i_trim_color_list *t) {
1341 STRLEN len;
1342 78 t->rsv = sv;
1343 78 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 78 78
SvGETMAGIC(sv); 0 0 0
1344 78 ▶ if (!SvROK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv)) 0 78 78
1345 0 return FALSE;
1346 78 t->sv = SvRV(sv);
1347 78 ▶ if (!SvPOK(t->sv) || SvMAGIC(t->sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(t->sv) || SvMAGIC(t->sv)) 78 0 78
if (!SvPOK(t->sv) || SvMAGIC(t->sv)) 0 78 78
1348 0 return FALSE;
1349 78 len = SvCUR(t->sv);
1350 78 ▶ if (len % sizeof(i_trim_colors_t) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (len % sizeof(i_trim_colors_t) != 0) 0 78 78
1351 0 return FALSE;
1352 78 t->colors = (i_trim_colors_t *)SvPVX(t->sv);
1353 78 t->count = len / sizeof(i_trim_colors_t);
1354  
1355 78 return TRUE;
1356 }
1357  
1358 static void
1359 0 my_out_of_memory(pIMCTX, void *userdata, const char *func, size_t size) {
1360 dTHX;
1361 0 dSP;
1362 0 SV *callme = get_sv("Imager::_out_of_memory", 0);
1363  
1364 (void)my_im_ctx;
1365 (void)userdata;
1366  
1367 0 ▶ if (!SvOK(callme))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(callme)) 0 0 0
1368 0 Perl_croak(aTHX_ "out of memory %s size %zu", func, size);
1369  
1370 0 PUSHSTACK;
1371 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
1372 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
1373 0 PUSHs(sv_2mortal(newSVpv(func, 0)));
1374 0 PUSHs(sv_2mortal(newSVuv(size)));
1375 0 PUTBACK;
1376 0 (void)call_sv(callme, G_VOID);
1377 /* we shouldn't get here */
1378 0 Perl_croak(aTHX_ "out of memory handler returned");
1379 }
1380  
1381 /* test the numeric parameters of i_[pg]sampf?(?:_bits)?
1382 for validity.
1383 Pushes errors.
1384 Returns the size of the buffer in *buf_size.
1385  
1386 Returns non-zero if valid.
1387 */
1388  
1389 static int
1390 513 is_valid_sample_params(
1391 i_img *im, i_img_dim l, i_img_dim *pr, i_img_dim y,
1392 i_channel_list *channels, size_t sample_size, size_t *buf_size) {
1393 513 ▶ if (l < 0 || l > im->xsize) {
Branch: 2 branches
BranchTrueFalseTotal
if (l < 0 || l > im->xsize) { 487 26 513
if (l < 0 || l > im->xsize) { 24 463 487
1394 50 i_push_error(0, "getsamples: left outside of image");
1395 50 return 0;
1396 }
1397 463 ▶ if (*pr > im->xsize)
Branch: 1 branch
BranchTrueFalseTotal
if (*pr > im->xsize) 4 459 463
1398 4 *pr = im->xsize;
1399 463 ▶ if (l >= *pr) {
Branch: 1 branch
BranchTrueFalseTotal
if (l >= *pr) { 26 437 463
1400 26 i_push_errorf(0, "left not left of right");
1401 26 return 0;
1402 }
1403 437 ▶ if (y < 0 || y >= im->ysize) {
Branch: 2 branches
BranchTrueFalseTotal
if (y < 0 || y >= im->ysize) { 411 26 437
if (y < 0 || y >= im->ysize) { 26 385 411
1404 52 i_push_error(0, "y outside of image");
1405 52 return 0;
1406 }
1407 385 ▶ if (channels->count < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (channels->count < 1) { 0 385 385
1408 /* caught in the type handler */
1409 0 i_push_error(0, "must be at least one channel");
1410 0 return 0;
1411 }
1412 385 ▶ if (channels->channels) {
Branch: 1 branch
BranchTrueFalseTotal
if (channels->channels) { 355 30 385
1413 int i;
1414 1313 ▶ for (i = 0; i < channels->count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < channels->count; ++i) { 1007 306 1313
1415 1007 int ch = channels->channels[i];
1416 1007 ▶ if (ch < 0 || ch >= im->channels) {
Branch: 2 branches
BranchTrueFalseTotal
if (ch < 0 || ch >= im->channels) { 983 24 1007
if (ch < 0 || ch >= im->channels) { 25 958 983
1417 49 i_push_errorf(0, "channel %d out of range for %d channel image",
1418 ch, im->channels);
1419 49 return 0;
1420 }
1421 }
1422 }
1423 else {
1424 /* the type handler doesn't do this (yet) */
1425 30 ▶ if (channels->count > im->channels) {
Branch: 1 branch
BranchTrueFalseTotal
if (channels->count > im->channels) { 0 30 30
1426 0 i_push_errorf(0, "channel count %d out of range for %d channel image",
1427 channels->count, im->channels);
1428 0 return 0;
1429 }
1430 }
1431  
1432 336 ▶ if (im_mult_overflow3(buf_size, *pr - l, channels->count, sample_size)) {
Branch: 1 branch
BranchTrueFalseTotal
if (im_mult_overflow3(buf_size, *pr - l, channels->count, sample_size)) { 0 336 336
1433 0 i_push_error(0, "integer overflow calculating buffer size");
1434 0 return 0;
1435 }
1436  
1437 336 return 1;
1438 }
1439  
1440 static void
1441 176 save_error_sv(pTHX_ SV *err_sv) {
1442 176 i_errmsg *errors = i_errors();
1443 176 int i = 0;
1444 176 SvPVCLEAR(err_sv);
1445  
1446 528 ▶ while (errors[i].msg) {
Branch: 1 branch
BranchTrueFalseTotal
while (errors[i].msg) { 352 176 528
1447 352 ▶ if (i)
Branch: 1 branch
BranchTrueFalseTotal
if (i) 176 176 352
1448 176 sv_catpvs(err_sv, ": ");
1449 352 sv_catpv(err_sv, errors[i].msg);
1450 352 ++i;
1451 }
1452 176 ▶ SvSETMAGIC(err_sv);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(err_sv); 0 176 176
1453 176 }
1454  
1455 typedef i_trim_color_list Imager__TrimColorList;
1456 #define trim_color_list_count(t) ((t).count)
1457  
1458 #define PERL_PL_SET_GLOBAL_CALLBACKS \
1459 sv_setiv(get_sv(PERL_PL_FUNCTION_TABLE_NAME, 1), PTR2IV(&im_perl_funcs));
1460  
1461 #define IIM_new i_img_8_new
1462 #define IIM_DESTROY i_img_destroy
1463 typedef int ImSysRet;
1464  
1465 #ifdef IMEXIF_ENABLE
1466 #define i_exif_enabled() 1
1467 #else
1468 #define i_exif_enabled() 0
1469 #endif
1470  
1471 /* trying to use more C style names, map them here */
1472 #define i_io_DESTROY(ig) io_glue_destroy(ig)
1473  
1474 #define i_img_get_width(im) ((im)->xsize)
1475 #define i_img_get_height(im) ((im)->ysize)
1476  
1477 #define i_img_epsilonf() (DBL_EPSILON * 4)
1478  
1479 /* avoid some xsubpp strangeness */
1480 #define NEWLINE '\n'
1481  
1482 #define ICL_red(c) ((c)->rgba.r)
1483 #define ICL_green(c) ((c)->rgba.g)
1484 #define ICL_blue(c) ((c)->rgba.b)
1485 #define ICL_alpha(c) ((c)->rgba.a)
1486  
1487 #define ICLF_red(c) ((c)->rgba.r)
1488 #define ICLF_green(c) ((c)->rgba.g)
1489 #define ICLF_blue(c) ((c)->rgba.b)
1490 #define ICLF_alpha(c) ((c)->rgba.a)
1491  
1492 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
1493  
1494 Imager::Color
1495 ICL_new_internal(r,g,b,a)
1496 unsigned char r
1497 unsigned char g
1498 unsigned char b
1499 unsigned char a
1500  
1501 void
1502 ICL_DESTROY(cl)
1503 Imager::Color cl
1504  
1505  
1506 void
1507 ICL_set_internal(cl,r,g,b,a)
1508 Imager::Color cl
1509 unsigned char r
1510 unsigned char g
1511 unsigned char b
1512 unsigned char a
1513 PPCODE:
1514 2000 cl->rgba.r = r;
1515 2000 cl->rgba.g = g;
1516 2000 cl->rgba.b = b;
1517 2000 cl->rgba.a = a;
1518 2000 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2000 2000
1519 2000 PUSHs(ST(0));
1520  
1521 void
1522 ICL_info(cl)
1523 Imager::Color cl
1524  
1525  
1526 void
1527 ICL_rgba(cl)
1528 Imager::Color cl
1529 PPCODE:
1530 1924 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 1924 1924
1531 1924 PUSHs(sv_2mortal(newSViv(cl->rgba.r)));
1532 1924 PUSHs(sv_2mortal(newSViv(cl->rgba.g)));
1533 1924 PUSHs(sv_2mortal(newSViv(cl->rgba.b)));
1534 1924 PUSHs(sv_2mortal(newSViv(cl->rgba.a)));
1535  
1536 Imager::Color
1537 i_hsv_to_rgb(c)
1538 Imager::Color c
1539 CODE:
1540 5 RETVAL = mymalloc(sizeof(i_color));
1541 5 *RETVAL = *c;
1542 5 i_hsv_to_rgb(RETVAL);
1543 OUTPUT:
1544 RETVAL
1545
1546 Imager::Color
1547 i_rgb_to_hsv(c)
1548 Imager::Color c
1549 CODE:
1550 5 RETVAL = mymalloc(sizeof(i_color));
1551 5 *RETVAL = *c;
1552 5 i_rgb_to_hsv(RETVAL);
1553 OUTPUT:
1554 RETVAL
1555
1556 int
1557 ICL_red(c)
1558 Imager::Color c
1559  
1560 int
1561 ICL_green(c)
1562 Imager::Color c
1563  
1564 int
1565 ICL_blue(c)
1566 Imager::Color c
1567  
1568 int
1569 ICL_alpha(c)
1570 Imager::Color c
1571  
1572 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
1573  
1574 Imager::Color::Float
1575 ICLF_new_internal(r, g, b, a)
1576 im_double r
1577 im_double g
1578 im_double b
1579 im_double a
1580  
1581 void
1582 ICLF_DESTROY(cl)
1583 Imager::Color::Float cl
1584  
1585 void
1586 ICLF_rgba(cl)
1587 Imager::Color::Float cl
1588 PREINIT:
1589 int ch;
1590 PPCODE:
1591 1448 ▶ EXTEND(SP, MAXCHANNELS);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, MAXCHANNELS); 0 1448 1448
1592 7240 ▶ for (ch = 0; ch < MAXCHANNELS; ++ch) {
Branch: 1 branch
BranchTrueFalseTotal
for (ch = 0; ch < MAXCHANNELS; ++ch) { 5792 1448 7240
1593 /* printf("%d: %g\n", ch, cl->channel[ch]); */
1594 5792 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
1595 }
1596  
1597 void
1598 ICLF_set_internal(cl,r,g,b,a)
1599 Imager::Color::Float cl
1600 im_double r
1601 im_double g
1602 im_double b
1603 im_double a
1604 PPCODE:
1605 1 cl->rgba.r = r;
1606 1 cl->rgba.g = g;
1607 1 cl->rgba.b = b;
1608 1 cl->rgba.a = a;
1609 1 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 1 1
1610 1 PUSHs(ST(0));
1611  
1612 Imager::Color::Float
1613 i_hsv_to_rgb(c)
1614 Imager::Color::Float c
1615 CODE:
1616 5 RETVAL = mymalloc(sizeof(i_fcolor));
1617 5 *RETVAL = *c;
1618 5 i_hsv_to_rgbf(RETVAL);
1619 OUTPUT:
1620 RETVAL
1621
1622 Imager::Color::Float
1623 i_rgb_to_hsv(c)
1624 Imager::Color::Float c
1625 CODE:
1626 5 RETVAL = mymalloc(sizeof(i_fcolor));
1627 5 *RETVAL = *c;
1628 5 i_rgb_to_hsvf(RETVAL);
1629 OUTPUT:
1630 RETVAL
1631  
1632 double
1633 ICLF_red(c)
1634 Imager::Color::Float c
1635  
1636 double
1637 ICLF_green(c)
1638 Imager::Color::Float c
1639  
1640 double
1641 ICLF_blue(c)
1642 Imager::Color::Float c
1643  
1644 double
1645 ICLF_alpha(c)
1646 Imager::Color::Float c
1647  
1648 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
1649  
1650 Imager::ImgRaw
1651 IIM_new(xsize,ysize,ch)
1652 i_img_dim xsize
1653 i_img_dim ysize
1654 int ch
1655  
1656 void
1657 IIM_DESTROY(im)
1658 Imager::ImgRaw im
1659  
1660  
1661  
1662 MODULE = Imager PACKAGE = Imager
1663  
1664 PROTOTYPES: ENABLE
1665  
1666  
1667 Imager::IO
1668 io_new_fd(fd)
1669 int fd
1670  
1671 Imager::IO
1672 io_new_bufchain()
1673  
1674  
1675 Imager::IO
1676 io_new_buffer(data_sv)
1677 SV *data_sv
1678 CODE:
1679 196 i_clear_error();
1680 196 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1681 196 ▶ if (!RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) 0 196 196
1682 0 XSRETURN(0);
1683 OUTPUT:
1684 RETVAL
1685  
1686 Imager::IO
1687 io_new_cb(SV *writecb, SV *readcb, SV *seekcb, SV *closecb, SV *size_or_cb = NULL)
1688 CODE:
1689 108 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb, size_or_cb);
1690 OUTPUT:
1691 RETVAL
1692  
1693 SV *
1694 io_slurp(ig)
1695 Imager::IO ig
1696 PREINIT:
1697 unsigned char* data;
1698 size_t tlength;
1699 CODE:
1700 47 data = NULL;
1701 47 tlength = io_slurp(ig, &data);
1702 47 RETVAL = newSVpvn((char *)data, tlength);
1703 47 myfree(data);
1704 OUTPUT:
1705 RETVAL
1706  
1707  
1708 undef_int
1709 i_set_image_file_limits(width, height, bytes)
1710 i_img_dim width
1711 i_img_dim height
1712 size_t bytes
1713  
1714 void
1715 i_get_image_file_limits()
1716 PREINIT:
1717 i_img_dim width, height;
1718 size_t bytes;
1719 PPCODE:
1720 7 ▶ if (i_get_image_file_limits(&width, &height, &bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_get_image_file_limits(&width, &height, &bytes)) { 7 0 7
1721 7 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 7 7
1722 7 PUSHs(sv_2mortal(newSViv(width)));
1723 7 PUSHs(sv_2mortal(newSViv(height)));
1724 7 PUSHs(sv_2mortal(newSVuv(bytes)));
1725 }
1726  
1727 bool
1728 i_int_check_image_file_limits(width, height, channels, sample_size)
1729 i_img_dim width
1730 i_img_dim height
1731 int channels
1732 size_t sample_size
1733 PROTOTYPE: DISABLE
1734  
1735 void
1736 i_set_out_of_memory(bool use_perl)
1737 PPCODE:
1738 0 ▶ i_set_out_of_memory(use_perl ? my_out_of_memory : NULL, NULL);
Branch: 1 branch
BranchTrueFalseTotal
i_set_out_of_memory(use_perl ? my_out_of_memory : NULL, NULL); 0 0 0
1739  
1740 void
1741 i_trim_rect(Imager::ImgRaw im, double transp_threshold, Imager::TrimColorList cls)
1742 PREINIT:
1743 i_img_dim left, top, right, bottom;
1744 PPCODE:
1745 15 ▶ if (!i_trim_rect(im, transp_threshold, cls.count, cls.colors, &left, &top, &right, &bottom))
Branch: 1 branch
BranchTrueFalseTotal
if (!i_trim_rect(im, transp_threshold, cls.count, cls.colors, &left, &top, &right, &bottom)) 0 15 15
1746 0 XSRETURN(0);
1747 15 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 15 15
1748 15 PUSHs(newSViv(left));
1749 15 PUSHs(newSViv(top));
1750 15 PUSHs(newSViv(right));
1751 15 PUSHs(newSViv(bottom));
1752  
1753 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_
1754  
1755 PROTOTYPES: DISABLE
1756  
1757 Imager::IO
1758 io_new_fd(class, fd)
1759 int fd
1760 CODE:
1761 1 RETVAL = io_new_fd(fd);
1762 OUTPUT:
1763 RETVAL
1764  
1765 Imager::IO
1766 io_new_buffer(class, data_sv)
1767 SV *data_sv
1768 CODE:
1769 8 i_clear_error();
1770 8 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1771 8 ▶ if (!RETVAL)
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) 0 8 8
1772 0 XSRETURN(0);
1773 OUTPUT:
1774 RETVAL
1775  
1776 Imager::IO
1777 io_new_cb(class, SV *writecb, SV *readcb, SV *seekcb, SV *closecb, SV *size_or_cb = NULL)
1778 CODE:
1779 5 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb, size_or_cb);
1780 OUTPUT:
1781 RETVAL
1782  
1783 Imager::IO
1784 io_new_bufchain(class)
1785 CODE:
1786 1 RETVAL = io_new_bufchain();
1787 OUTPUT:
1788 RETVAL
1789  
1790 Imager::IO
1791 io__new_perlio(class, io)
1792 PerlIO *io
1793 CODE:
1794 19 RETVAL = im_io_new_perlio(aTHX_ io);
1795 OUTPUT:
1796 RETVAL
1797  
1798 SV *
1799 io_slurp(class, ig)
1800 Imager::IO ig
1801 PREINIT:
1802 unsigned char* data;
1803 size_t tlength;
1804 CODE:
1805 0 data = NULL;
1806 0 tlength = io_slurp(ig, &data);
1807 0 RETVAL = newSVpvn((char *)data, tlength);
1808 0 myfree(data);
1809 OUTPUT:
1810 RETVAL
1811  
1812 MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_
1813  
1814 IV
1815 i_io_raw_write(ig, data_sv)
1816 Imager::IO ig
1817 SV *data_sv
1818 PREINIT:
1819 void *data;
1820 STRLEN size;
1821 CODE:
1822 7 data = SvPVbyte(data_sv, size);
1823 7 RETVAL = i_io_raw_write(ig, data, size);
1824 OUTPUT:
1825 RETVAL
1826  
1827 void
1828 i_io_raw_read(ig, buffer_sv, size)
1829 Imager::IO ig
1830 SV *buffer_sv
1831 IV size
1832 PREINIT:
1833 void *buffer;
1834 ssize_t result;
1835 PPCODE:
1836 16 ▶ if (size <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size <= 0) 0 16 16
1837 0 croak("size %" IVdf " non-positive in call to i_io_raw_read()", size);
1838 16 ▶ if (size >= SSize_t_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if (size >= SSize_t_MAX) 0 16 16
1839 0 croak("size %" IVdf " too large in call to i_io_raw_read()", size);
1840 /* prevent an undefined value warning if they supplied an
1841 undef buffer.
1842 Orginally conditional on !SvOK(), but this will prevent the
1843 downgrade from croaking */
1844 16 SvPVCLEAR(buffer_sv);
1845 #ifdef SvUTF8
1846 16 ▶ if (SvUTF8(buffer_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(buffer_sv)) 0 16 16
1847 0 sv_utf8_downgrade(buffer_sv, FALSE);
1848 #endif
1849 16 ▶ buffer = SvGROW(buffer_sv, (STRLEN)size+1);
Branch: 2 branches
BranchTrueFalseTotal
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 16 0 16
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 0 16 16
1850 16 result = i_io_raw_read(ig, buffer, size);
1851 16 ▶ if (result >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result >= 0) { 12 4 16
1852 12 SvCUR_set(buffer_sv, result);
1853 12 *SvEND(buffer_sv) = '\0';
1854 12 SvPOK_only(buffer_sv);
1855 12 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 12 12
1856 12 PUSHs(sv_2mortal(newSViv(result)));
1857 }
1858 16 ST(1) = buffer_sv;
1859 16 ▶ SvSETMAGIC(ST(1));
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(ST(1)); 0 16 16
1860  
1861 void
1862 i_io_raw_read2(ig, size)
1863 Imager::IO ig
1864 IV size
1865 PREINIT:
1866 SV *buffer_sv;
1867 void *buffer;
1868 ssize_t result;
1869 PPCODE:
1870 4 ▶ if (size <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size <= 0) 0 4 4
1871 0 croak("size %" IVdf " negative in call to i_io_read2()", size);
1872 4 ▶ if (size >= SSize_t_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if (size >= SSize_t_MAX) 0 4 4
1873 0 croak("size %" IVdf " too large in i_io_read2()", size);
1874 4 buffer_sv = newSV(size+1);
1875 4 ▶ buffer = SvGROW(buffer_sv, (STRLEN)size+1);
Branch: 2 branches
BranchTrueFalseTotal
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 4 0 4
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 0 4 4
1876 4 result = i_io_raw_read(ig, buffer, size);
1877 4 ▶ if (result >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result >= 0) { 2 2 4
1878 2 SvCUR_set(buffer_sv, result);
1879 2 *SvEND(buffer_sv) = '\0';
1880 2 SvPOK_only(buffer_sv);
1881 2 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2 2
1882 2 PUSHs(sv_2mortal(buffer_sv));
1883 }
1884 else {
1885 /* discard it */
1886 2 SvREFCNT_dec(buffer_sv);
1887 }
1888  
1889 off_t
1890 i_io_raw_seek(ig, position, whence)
1891 Imager::IO ig
1892 off_t position
1893 int whence
1894  
1895 int
1896 i_io_raw_close(ig)
1897 Imager::IO ig
1898  
1899 void
1900 i_io_DESTROY(ig)
1901 Imager::IO ig
1902  
1903 int
1904 i_io_CLONE_SKIP(...)
1905 CODE:
1906 (void)items; /* avoid unused warning for XS variable */
1907 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
1908 OUTPUT:
1909 RETVAL
1910  
1911 int
1912 i_io_getc(ig)
1913 Imager::IO ig
1914  
1915 void
1916 i_io_nextc(ig)
1917 Imager::IO ig
1918  
1919 int
1920 i_io_putc(ig, c)
1921 Imager::IO ig
1922 int c
1923  
1924 int
1925 i_io_close(ig)
1926 Imager::IO ig
1927  
1928 int
1929 i_io_flush(ig)
1930 Imager::IO ig
1931  
1932 int
1933 i_io_peekc(ig)
1934 Imager::IO ig
1935  
1936 int
1937 i_io_seek(ig, off, whence)
1938 Imager::IO ig
1939 off_t off
1940 int whence
1941  
1942 void
1943 i_io_peekn(ig, size)
1944 Imager::IO ig
1945 STRLEN size
1946 PREINIT:
1947 SV *buffer_sv;
1948 void *buffer;
1949 ssize_t result;
1950 PPCODE:
1951 21 buffer_sv = newSV(size+1);
1952 21 ▶ buffer = SvGROW(buffer_sv, size+1);
Branch: 2 branches
BranchTrueFalseTotal
buffer = SvGROW(buffer_sv, size+1); 21 0 21
buffer = SvGROW(buffer_sv, size+1); 0 21 21
1953 21 result = i_io_peekn(ig, buffer, size);
1954 21 ▶ if (result >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result >= 0) { 16 5 21
1955 16 SvCUR_set(buffer_sv, result);
1956 16 *SvEND(buffer_sv) = '\0';
1957 16 SvPOK_only(buffer_sv);
1958 16 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 16 16
1959 16 PUSHs(sv_2mortal(buffer_sv));
1960 }
1961 else {
1962 /* discard it */
1963 5 SvREFCNT_dec(buffer_sv);
1964 }
1965  
1966 void
1967 i_io_read(ig, buffer_sv, size)
1968 Imager::IO ig
1969 SV *buffer_sv
1970 IV size
1971 PREINIT:
1972 void *buffer;
1973 ssize_t result;
1974 PPCODE:
1975 7 ▶ if (size <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size <= 0) 0 7 7
1976 0 croak("size negative in call to i_io_read()");
1977 7 ▶ if (size >= SSize_t_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if (size >= SSize_t_MAX) 0 7 7
1978 0 croak("size too large in call to i_io_read()");
1979 /* prevent an undefined value warning if they supplied an
1980 undef buffer.
1981 Orginally conditional on !SvOK(), but this will prevent the
1982 downgrade from croaking */
1983 7 SvPVCLEAR(buffer_sv);
1984 #ifdef SvUTF8
1985 7 ▶ if (SvUTF8(buffer_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(buffer_sv)) 0 7 7
1986 0 sv_utf8_downgrade(buffer_sv, FALSE);
1987 #endif
1988 7 ▶ buffer = SvGROW(buffer_sv, (STRLEN)size+1);
Branch: 2 branches
BranchTrueFalseTotal
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 7 0 7
buffer = SvGROW(buffer_sv, (STRLEN)size+1); 3 4 7
1989 7 result = i_io_read(ig, buffer, size);
1990 7 ▶ if (result >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result >= 0) { 6 1 7
1991 6 SvCUR_set(buffer_sv, result);
1992 6 *SvEND(buffer_sv) = '\0';
1993 6 SvPOK_only(buffer_sv);
1994 6 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 6 6
1995 6 PUSHs(sv_2mortal(newSViv(result)));
1996 }
1997 7 ST(1) = buffer_sv;
1998 7 ▶ SvSETMAGIC(ST(1));
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(ST(1)); 0 7 7
1999  
2000 void
2001 i_io_read2(ig, size)
2002 Imager::IO ig
2003 STRLEN size
2004 PREINIT:
2005 SV *buffer_sv;
2006 void *buffer;
2007 ssize_t result;
2008 PPCODE:
2009 13 ▶ if (size == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size == 0) 0 13 13
2010 0 croak("size zero in call to read2()");
2011 13 buffer_sv = newSV(size);
2012 13 ▶ buffer = SvGROW(buffer_sv, size+1);
Branch: 2 branches
BranchTrueFalseTotal
buffer = SvGROW(buffer_sv, size+1); 13 0 13
buffer = SvGROW(buffer_sv, size+1); 0 13 13
2013 13 result = i_io_read(ig, buffer, size);
2014 13 ▶ if (result > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result > 0) { 10 3 13
2015 10 SvCUR_set(buffer_sv, result);
2016 10 *SvEND(buffer_sv) = '\0';
2017 10 SvPOK_only(buffer_sv);
2018 10 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 10 10
2019 10 PUSHs(sv_2mortal(buffer_sv));
2020 }
2021 else {
2022 /* discard it */
2023 3 SvREFCNT_dec(buffer_sv);
2024 }
2025  
2026 void
2027 i_io_gets(ig, size = 8192, eol = NEWLINE)
2028 Imager::IO ig
2029 STRLEN size
2030 int eol
2031 PREINIT:
2032 SV *buffer_sv;
2033 void *buffer;
2034 ssize_t result;
2035 PPCODE:
2036 7 ▶ if (size < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (size < 2) 0 7 7
2037 0 croak("size too small in call to gets()");
2038 7 buffer_sv = sv_2mortal(newSV(size+1));
2039 7 buffer = SvPVX(buffer_sv);
2040 7 result = i_io_gets(ig, buffer, size+1, eol);
2041 7 ▶ if (result > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result > 0) { 7 0 7
2042 7 SvCUR_set(buffer_sv, result);
2043 7 *SvEND(buffer_sv) = '\0';
2044 7 SvPOK_only(buffer_sv);
2045 7 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 7 7
2046 7 PUSHs(buffer_sv);
2047 }
2048  
2049 IV
2050 i_io_write(ig, data_sv)
2051 Imager::IO ig
2052 SV *data_sv
2053 PREINIT:
2054 void *data;
2055 STRLEN size;
2056 CODE:
2057 8208 data = SvPVbyte(data_sv, size);
2058 8208 RETVAL = i_io_write(ig, data, size);
2059 OUTPUT:
2060 RETVAL
2061  
2062 void
2063 i_io_dump(ig, flags = I_IO_DUMP_DEFAULT)
2064 Imager::IO ig
2065 int flags
2066  
2067 bool
2068 i_io_set_buffered(ig, flag = 1)
2069 Imager::IO ig
2070 int flag
2071  
2072 bool
2073 i_io_is_buffered(ig)
2074 Imager::IO ig
2075  
2076 bool
2077 i_io_eof(ig)
2078 Imager::IO ig
2079  
2080 bool
2081 i_io_error(ig)
2082 Imager::IO ig
2083  
2084 off_t
2085 i_io_size(Imager::IO ig)
2086  
2087 size_t
2088 i_io_get_max_mmap_size(cls)
2089 C_ARGS:
2090  
2091 size_t
2092 i_io_set_max_mmap_size(cls, size_t new_size)
2093 C_ARGS: new_size
2094  
2095 MODULE = Imager PACKAGE = Imager
2096  
2097 PROTOTYPES: ENABLE
2098  
2099 void
2100 i_list_formats()
2101 PREINIT:
2102 char* item;
2103 int i;
2104 PPCODE:
2105 79 i=0;
2106 474 ▶ while( (item=i_format_list[i++]) != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while( (item=i_format_list[i++]) != NULL ) { 395 79 474
2107 395 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 395 395
2108 395 PUSHs(sv_2mortal(newSVpv(item,0)));
2109 }
2110  
2111 Imager::ImgRaw
2112 i_sametype(im, x, y)
2113 Imager::ImgRaw im
2114 i_img_dim x
2115 i_img_dim y
2116  
2117 Imager::ImgRaw
2118 i_sametype_chans(im, x, y, channels)
2119 Imager::ImgRaw im
2120 i_img_dim x
2121 i_img_dim y
2122 int channels
2123  
2124 int
2125 i_init_log(name_sv,level)
2126 SV* name_sv
2127 int level
2128 PREINIT:
2129 93 ▶ const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL; 37 19 56
const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL; 56 0 56
2130 CODE:
2131 56 RETVAL = i_init_log(name, level);
2132 OUTPUT:
2133 RETVAL
2134  
2135 void
2136 i_log_entry(string,level)
2137 char* string
2138 int level
2139  
2140 int
2141 i_log_enabled()
2142  
2143 void
2144 i_img_info(im)
2145 Imager::ImgRaw im
2146 PREINIT:
2147 i_img_dim info[4];
2148 PPCODE:
2149 39 i_img_info(im,info);
2150 39 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 39 39
2151 39 PUSHs(sv_2mortal(newSViv(info[0])));
2152 39 PUSHs(sv_2mortal(newSViv(info[1])));
2153 39 PUSHs(sv_2mortal(newSViv(info[2])));
2154 39 PUSHs(sv_2mortal(newSViv(info[3])));
2155  
2156  
2157  
2158  
2159 void
2160 i_img_setmask(im,ch_mask)
2161 Imager::ImgRaw im
2162 int ch_mask
2163  
2164 int
2165 i_img_getmask(im)
2166 Imager::ImgRaw im
2167  
2168 int
2169 i_img_getchannels(im)
2170 Imager::ImgRaw im
2171  
2172 void
2173 i_img_getdata(im)
2174 Imager::ImgRaw im
2175 PPCODE:
2176 0 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 0 0
2177 0 ▶ PUSHs(im->idata ?
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(im->idata ? 0 0 0
2178 newSVpvn_flags((char *)im->idata, im->bytes, SVs_TEMP)
2179 : &PL_sv_undef);
2180  
2181 IV
2182 i_img_get_width(im)
2183 Imager::ImgRaw im
2184  
2185 IV
2186 i_img_get_height(im)
2187 Imager::ImgRaw im
2188  
2189 int
2190 i_img_color_model(im)
2191 Imager::ImgRaw im
2192  
2193 int
2194 i_img_color_channels(im)
2195 Imager::ImgRaw im
2196  
2197 int
2198 i_img_alpha_channel(im)
2199 Imager::ImgRaw im
2200 CODE:
2201 9 ▶ if (!i_img_alpha_channel(im, &RETVAL))
Branch: 1 branch
BranchTrueFalseTotal
if (!i_img_alpha_channel(im, &RETVAL)) 5 4 9
2202 5 XSRETURN(0);
2203 OUTPUT:
2204 RETVAL
2205  
2206 void
2207 i_img_is_monochrome(im)
2208 Imager::ImgRaw im
2209 PREINIT:
2210 int zero_is_white;
2211 int result;
2212 PPCODE:
2213 24 result = i_img_is_monochrome(im, &zero_is_white);
2214 24 ▶ if (result) {
Branch: 1 branch
BranchTrueFalseTotal
if (result) { 11 13 24
2215 11 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 5 6 11
2216 5 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 5 5
2217 5 PUSHs(&PL_sv_yes);
2218 5 PUSHs(sv_2mortal(newSViv(zero_is_white)));
2219 }
2220 else {
2221 6 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 6 6
2222 6 PUSHs(&PL_sv_yes);
2223 }
2224 }
2225  
2226 void
2227 i_line(im,x1,y1,x2,y2,val,endp)
2228 Imager::ImgRaw im
2229 i_img_dim x1
2230 i_img_dim y1
2231 i_img_dim x2
2232 i_img_dim y2
2233 Imager::Color val
2234 int endp
2235  
2236 void
2237 i_line_aa(im,x1,y1,x2,y2,val,endp)
2238 Imager::ImgRaw im
2239 i_img_dim x1
2240 i_img_dim y1
2241 i_img_dim x2
2242 i_img_dim y2
2243 Imager::Color val
2244 int endp
2245  
2246 void
2247 i_box(im,x1,y1,x2,y2,val)
2248 Imager::ImgRaw im
2249 i_img_dim x1
2250 i_img_dim y1
2251 i_img_dim x2
2252 i_img_dim y2
2253 Imager::Color val
2254  
2255 void
2256 i_box_filled(im,x1,y1,x2,y2,val)
2257 Imager::ImgRaw im
2258 i_img_dim x1
2259 i_img_dim y1
2260 i_img_dim x2
2261 i_img_dim y2
2262 Imager::Color val
2263  
2264 int
2265 i_box_filledf(im,x1,y1,x2,y2,val)
2266 Imager::ImgRaw im
2267 i_img_dim x1
2268 i_img_dim y1
2269 i_img_dim x2
2270 i_img_dim y2
2271 Imager::Color::Float val
2272  
2273 void
2274 i_box_cfill(im,x1,y1,x2,y2,fill)
2275 Imager::ImgRaw im
2276 i_img_dim x1
2277 i_img_dim y1
2278 i_img_dim x2
2279 i_img_dim y2
2280 Imager::FillHandle fill
2281  
2282 void
2283 i_arc(im,x,y,rad,d1,d2,val)
2284 Imager::ImgRaw im
2285 i_img_dim x
2286 i_img_dim y
2287 im_double rad
2288 im_double d1
2289 im_double d2
2290 Imager::Color val
2291  
2292 void
2293 i_arc_aa(im,x,y,rad,d1,d2,val)
2294 Imager::ImgRaw im
2295 im_double x
2296 im_double y
2297 im_double rad
2298 im_double d1
2299 im_double d2
2300 Imager::Color val
2301  
2302 void
2303 i_arc_cfill(im,x,y,rad,d1,d2,fill)
2304 Imager::ImgRaw im
2305 i_img_dim x
2306 i_img_dim y
2307 im_double rad
2308 im_double d1
2309 im_double d2
2310 Imager::FillHandle fill
2311  
2312 void
2313 i_arc_aa_cfill(im,x,y,rad,d1,d2,fill)
2314 Imager::ImgRaw im
2315 im_double x
2316 im_double y
2317 im_double rad
2318 im_double d1
2319 im_double d2
2320 Imager::FillHandle fill
2321  
2322  
2323 void
2324 i_circle_aa(im,x,y,rad,val)
2325 Imager::ImgRaw im
2326 im_double x
2327 im_double y
2328 im_double rad
2329 Imager::Color val
2330  
2331 void
2332 i_circle_aa_fill(im,x,y,rad,fill)
2333 Imager::ImgRaw im
2334 im_double x
2335 im_double y
2336 im_double rad
2337 Imager::FillHandle fill
2338  
2339 int
2340 i_circle_out(im,x,y,rad,val)
2341 Imager::ImgRaw im
2342 i_img_dim x
2343 i_img_dim y
2344 i_img_dim rad
2345 Imager::Color val
2346  
2347 int
2348 i_circle_out_aa(im,x,y,rad,val)
2349 Imager::ImgRaw im
2350 i_img_dim x
2351 i_img_dim y
2352 i_img_dim rad
2353 Imager::Color val
2354  
2355 int
2356 i_arc_out(im,x,y,rad,d1,d2,val)
2357 Imager::ImgRaw im
2358 i_img_dim x
2359 i_img_dim y
2360 i_img_dim rad
2361 im_double d1
2362 im_double d2
2363 Imager::Color val
2364  
2365 int
2366 i_arc_out_aa(im,x,y,rad,d1,d2,val)
2367 Imager::ImgRaw im
2368 i_img_dim x
2369 i_img_dim y
2370 i_img_dim rad
2371 im_double d1
2372 im_double d2
2373 Imager::Color val
2374  
2375  
2376 void
2377 i_bezier_multi(im,x,y,val)
2378 Imager::ImgRaw im
2379 double *x
2380 double *y
2381 Imager::Color val
2382 PREINIT:
2383 STRLEN size_x;
2384 STRLEN size_y;
2385 PPCODE:
2386 0 ▶ if (size_x != size_y)
Branch: 1 branch
BranchTrueFalseTotal
if (size_x != size_y) 0 0 0
2387 0 croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
2388 0 i_bezier_multi(im,size_x,x,y,val);
2389  
2390 int
2391 i_poly_aa_m(im,x,y,mode,val)
2392 Imager::ImgRaw im
2393 double *x
2394 double *y
2395 i_poly_fill_mode_t mode
2396 Imager::Color val
2397 PREINIT:
2398 STRLEN size_x;
2399 STRLEN size_y;
2400 CODE:
2401 63 ▶ if (size_x != size_y)
Branch: 1 branch
BranchTrueFalseTotal
if (size_x != size_y) 0 63 63
2402 0 croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
2403 63 RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val);
2404 OUTPUT:
2405 RETVAL
2406  
2407 int
2408 i_poly_aa_cfill_m(im, x, y, mode, fill)
2409 Imager::ImgRaw im
2410 double *x
2411 double *y
2412 i_poly_fill_mode_t mode
2413 Imager::FillHandle fill
2414 PREINIT:
2415 STRLEN size_x;
2416 STRLEN size_y;
2417 CODE:
2418 4 ▶ if (size_x != size_y)
Branch: 1 branch
BranchTrueFalseTotal
if (size_x != size_y) 0 4 4
2419 0 croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
2420 4 RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill);
2421 OUTPUT:
2422 RETVAL
2423  
2424 int
2425 i_poly_poly_aa(im, polys, mode, color)
2426 Imager::ImgRaw im
2427 i_polygon_list polys
2428 i_poly_fill_mode_t mode
2429 Imager::Color color
2430 CODE:
2431 6 RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color);
2432 OUTPUT:
2433 RETVAL
2434  
2435 int
2436 i_poly_poly_aa_cfill(im, polys, mode, fill)
2437 Imager::ImgRaw im
2438 i_polygon_list polys
2439 i_poly_fill_mode_t mode
2440 Imager::FillHandle fill
2441 CODE:
2442 0 RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill);
2443 OUTPUT:
2444 RETVAL
2445  
2446 undef_int
2447 i_flood_fill(im,seedx,seedy,dcol)
2448 Imager::ImgRaw im
2449 i_img_dim seedx
2450 i_img_dim seedy
2451 Imager::Color dcol
2452  
2453 undef_int
2454 i_flood_cfill(im,seedx,seedy,fill)
2455 Imager::ImgRaw im
2456 i_img_dim seedx
2457 i_img_dim seedy
2458 Imager::FillHandle fill
2459  
2460 undef_int
2461 i_flood_fill_border(im,seedx,seedy,dcol, border)
2462 Imager::ImgRaw im
2463 i_img_dim seedx
2464 i_img_dim seedy
2465 Imager::Color dcol
2466 Imager::Color border
2467  
2468 undef_int
2469 i_flood_cfill_border(im,seedx,seedy,fill, border)
2470 Imager::ImgRaw im
2471 i_img_dim seedx
2472 i_img_dim seedy
2473 Imager::FillHandle fill
2474 Imager::Color border
2475  
2476  
2477 void
2478 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
2479 Imager::ImgRaw im
2480 Imager::ImgRaw src
2481 i_img_dim x1
2482 i_img_dim y1
2483 i_img_dim x2
2484 i_img_dim y2
2485 i_img_dim tx
2486 i_img_dim ty
2487  
2488  
2489 void
2490 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
2491 Imager::ImgRaw im
2492 Imager::ImgRaw src
2493 i_img_dim x1
2494 i_img_dim y1
2495 i_img_dim x2
2496 i_img_dim y2
2497 i_img_dim tx
2498 i_img_dim ty
2499 Imager::Color trans
2500  
2501 Imager::ImgRaw
2502 i_copy(src)
2503 Imager::ImgRaw src
2504  
2505  
2506 undef_int
2507 i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy)
2508 Imager::ImgRaw im
2509 Imager::ImgRaw src
2510 i_img_dim tx
2511 i_img_dim ty
2512 i_img_dim src_minx
2513 i_img_dim src_miny
2514 i_img_dim src_maxx
2515 i_img_dim src_maxy
2516  
2517 undef_int
2518 i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0)
2519 Imager::ImgRaw out
2520 Imager::ImgRaw src
2521 i_img_dim out_left
2522 i_img_dim out_top
2523 i_img_dim src_left
2524 i_img_dim src_top
2525 i_img_dim width
2526 i_img_dim height
2527 int combine
2528 im_double opacity
2529  
2530 undef_int
2531 i_compose_mask(out, src, mask, out_left, out_top, src_left, src_top, mask_left, mask_top, width, height, combine = ic_normal, opacity = 0.0)
2532 Imager::ImgRaw out
2533 Imager::ImgRaw src
2534 Imager::ImgRaw mask
2535 i_img_dim out_left
2536 i_img_dim out_top
2537 i_img_dim src_left
2538 i_img_dim src_top
2539 i_img_dim mask_left
2540 i_img_dim mask_top
2541 i_img_dim width
2542 i_img_dim height
2543 int combine
2544 im_double opacity
2545  
2546 Imager::ImgRaw
2547 i_combine(src_av, channels_av = NULL)
2548 AV *src_av
2549 AV *channels_av
2550 PREINIT:
2551 11 i_img **imgs = NULL;
2552 STRLEN in_count;
2553 11 ▶ int *channels = NULL;
Branch: 1 branch
BranchTrueFalseTotal
int *channels = NULL; 0 11 11
2554 IV tmp;
2555 CODE:
2556 11 in_count = av_len(src_av) + 1;
2557 11 ▶ if (in_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_count > 0) { 10 1 11
2558 unsigned i;
2559 10 imgs = mymalloc(sizeof(i_img*) * in_count);
2560 10 channels = mymalloc(sizeof(int) * in_count);
2561 29 ▶ for (i = 0; i < in_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < in_count; ++i) { 19 10 29
2562 19 SV **psv = av_fetch(src_av, i, 0);
2563 19 ▶ if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) { 19 0 19
if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) { 19 0 19
if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) { 0 19 19
2564 0 myfree(imgs);
2565 0 myfree(channels);
2566 0 croak("imgs must contain only images");
2567 }
2568 19 tmp = SvIV((SV*)SvRV(*psv));
2569 19 imgs[i] = INT2PTR(i_img*, tmp);
2570 23 if (channels_av &&
2571 4 (psv = av_fetch(channels_av, i, 0)) != NULL &&
2572 4 ▶ *psv) {
Branch: 1 branch
BranchTrueFalseTotal
*psv) { 4 0 4
2573 4 channels[i] = SvIV(*psv);
2574 }
2575 else {
2576 15 channels[i] = 0;
2577 }
2578 }
2579 }
2580 11 RETVAL = i_combine(imgs, channels, in_count);
2581 11 myfree(imgs);
2582 11 myfree(channels);
2583 OUTPUT:
2584 RETVAL
2585  
2586 undef_int
2587 i_flipxy(im, direction)
2588 Imager::ImgRaw im
2589 int direction
2590  
2591 Imager::ImgRaw
2592 i_rotate90(im, degrees)
2593 Imager::ImgRaw im
2594 int degrees
2595  
2596 Imager::ImgRaw
2597 i_rotate_exact(im, amount, ...)
2598 Imager::ImgRaw im
2599 im_double amount
2600 PREINIT:
2601 10 i_color *backp = NULL;
2602 10 i_fcolor *fbackp = NULL;
2603 int i;
2604 SV * sv1;
2605 CODE:
2606 /* extract the bg colors if any */
2607 /* yes, this is kind of strange */
2608 15 ▶ for (i = 2; i < items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; ++i) { 5 10 15
2609 5 sv1 = ST(i);
2610 5 ▶ if (sv_derived_from(sv1, "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(sv1, "Imager::Color")) { 5 0 5
2611 5 IV tmp = SvIV((SV*)SvRV(sv1));
2612 5 backp = INT2PTR(i_color *, tmp);
2613 }
2614 0 ▶ else if (sv_derived_from(sv1, "Imager::Color::Float")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_derived_from(sv1, "Imager::Color::Float")) { 0 0 0
2615 0 IV tmp = SvIV((SV*)SvRV(sv1));
2616 0 fbackp = INT2PTR(i_fcolor *, tmp);
2617 }
2618 }
2619 10 RETVAL = i_rotate_exact_bg(im, amount, backp, fbackp);
2620 OUTPUT:
2621 RETVAL
2622  
2623 Imager::ImgRaw
2624 i_matrix_transform(im, xsize, ysize, matrix_av, ...)
2625 Imager::ImgRaw im
2626 i_img_dim xsize
2627 i_img_dim ysize
2628 AV *matrix_av
2629 PREINIT:
2630 double matrix[9];
2631 STRLEN len;
2632 SV *sv1;
2633 int item_index;
2634 unsigned coeff_index;
2635 3 i_color *backp = NULL;
2636 3 i_fcolor *fbackp = NULL;
2637 CODE:
2638 3 len=av_len(matrix_av)+1;
2639 3 ▶ if (len > 9)
Branch: 1 branch
BranchTrueFalseTotal
if (len > 9) 0 3 3
2640 0 len = 9;
2641 30 ▶ for (coeff_index = 0; coeff_index < len; ++coeff_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (coeff_index = 0; coeff_index < len; ++coeff_index) { 27 3 30
2642 27 sv1=(*(av_fetch(matrix_av, coeff_index, 0)));
2643 27 matrix[coeff_index] = SvNV(sv1);
2644 }
2645 3 ▶ for (; coeff_index < 9; ++coeff_index)
Branch: 1 branch
BranchTrueFalseTotal
for (; coeff_index < 9; ++coeff_index) 0 3 3
2646 0 matrix[coeff_index] = 0;
2647 /* extract the bg colors if any */
2648 /* yes, this is kind of strange */
2649 4 ▶ for (item_index = 4; item_index < items; ++item_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (item_index = 4; item_index < items; ++item_index) { 1 3 4
2650 1 sv1 = ST(item_index);
2651 1 ▶ if (sv_derived_from(sv1, "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_derived_from(sv1, "Imager::Color")) { 1 0 1
2652 1 IV tmp = SvIV((SV*)SvRV(sv1));
2653 1 backp = INT2PTR(i_color *, tmp);
2654 }
2655 0 ▶ else if (sv_derived_from(sv1, "Imager::Color::Float")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_derived_from(sv1, "Imager::Color::Float")) { 0 0 0
2656 0 IV tmp = SvIV((SV*)SvRV(sv1));
2657 0 fbackp = INT2PTR(i_fcolor *, tmp);
2658 }
2659 }
2660 3 RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
2661 OUTPUT:
2662 RETVAL
2663  
2664 undef_int
2665 i_gaussian(im,stddev)
2666 Imager::ImgRaw im
2667 im_double stddev
2668  
2669 undef_int
2670 i_gaussian2(im,stddevX,stddevY)
2671 Imager::ImgRaw im
2672 im_double stddevX
2673 im_double stddevY
2674  
2675 void
2676 i_unsharp_mask(im,stdev,scale)
2677 Imager::ImgRaw im
2678 im_double stdev
2679 im_double scale
2680  
2681 int
2682 i_conv(im,coef)
2683 Imager::ImgRaw im
2684 AV *coef
2685 PREINIT:
2686 double* c_coef;
2687 int len;
2688 SV* sv1;
2689 int i;
2690 CODE:
2691 68 len = av_len(coef) + 1;
2692 68 c_coef=mymalloc( len * sizeof(double) );
2693 388 ▶ for(i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < len; i++) { 320 68 388
2694 320 sv1 = (*(av_fetch(coef, i, 0)));
2695 320 c_coef[i] = (double)SvNV(sv1);
2696 }
2697 68 RETVAL = i_conv(im, c_coef, len);
2698 68 myfree(c_coef);
2699 OUTPUT:
2700 RETVAL
2701  
2702 Imager::ImgRaw
2703 i_convert(src, avmain)
2704 Imager::ImgRaw src
2705 AV *avmain
2706 PREINIT:
2707 double *coeff;
2708 int outchan;
2709 int inchan;
2710 SV **temp;
2711 AV *avsub;
2712 int len;
2713 int i, j;
2714 CODE:
2715 29 outchan = av_len(avmain)+1;
2716 /* find the biggest */
2717 29 inchan = 0;
2718 96 ▶ for (j=0; j < outchan; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j < outchan; ++j) { 68 28 96
2719 68 temp = av_fetch(avmain, j, 0);
2720 68 ▶ if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { 68 0 68
if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { 67 1 68
if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) { 67 0 67
2721 67 avsub = (AV*)SvRV(*temp);
2722 67 len = av_len(avsub)+1;
2723 67 ▶ if (len > inchan)
Branch: 1 branch
BranchTrueFalseTotal
if (len > inchan) 28 39 67
2724 28 inchan = len;
2725 }
2726 else {
2727 1 i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
2728 1 XSRETURN(0);
2729 }
2730 }
2731 28 coeff = mymalloc(sizeof(double) * outchan * inchan);
2732 95 ▶ for (j = 0; j < outchan; ++j) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < outchan; ++j) { 67 28 95
2733 67 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
2734 67 len = av_len(avsub)+1;
2735 246 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 179 67 246
2736 179 temp = av_fetch(avsub, i, 0);
2737 179 ▶ if (temp)
Branch: 1 branch
BranchTrueFalseTotal
if (temp) 179 0 179
2738 179 coeff[i+j*inchan] = SvNV(*temp);
2739 else
2740 0 coeff[i+j*inchan] = 0;
2741 }
2742 67 ▶ while (i < inchan)
Branch: 1 branch
BranchTrueFalseTotal
while (i < inchan) 0 67 67
2743 0 coeff[i++ + j*inchan] = 0;
2744 }
2745 28 RETVAL = i_convert(src, coeff, outchan, inchan);
2746 28 myfree(coeff);
2747 OUTPUT:
2748 RETVAL
2749  
2750  
2751 undef_int
2752 i_map(im, pmaps_av)
2753 Imager::ImgRaw im
2754 AV *pmaps_av
2755 PREINIT:
2756 9 unsigned int mask = 0;
2757 AV *avsub;
2758 SV **temp;
2759 int len;
2760 int i, j;
2761 unsigned char (*maps)[256];
2762 CODE:
2763 9 len = av_len(pmaps_av)+1;
2764 9 ▶ if (im->channels < len)
Branch: 1 branch
BranchTrueFalseTotal
if (im->channels < len) 0 9 9
2765 0 len = im->channels;
2766 9 maps = mymalloc( len * sizeof(unsigned char [256]) );
2767 36 ▶ for (j=0; j<len ; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j=0; j<len ; j++) { 27 9 36
2768 27 temp = av_fetch(pmaps_av, j, 0);
2769 27 ▶ if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { 27 0 27
if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { 23 4 27
if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) { 23 0 23
2770 23 avsub = (AV*)SvRV(*temp);
2771 23 ▶ if(av_len(avsub) != 255)
Branch: 1 branch
BranchTrueFalseTotal
if(av_len(avsub) != 255) 5 18 23
2772 5 continue;
2773 18 mask |= 1<<j;
2774 4626 ▶ for (i=0; i<256 ; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<256 ; i++) { 4608 18 4626
2775 int val;
2776 4608 temp = av_fetch(avsub, i, 0);
2777 4608 ▶ val = temp ? SvIV(*temp) : 0;
Branch: 1 branch
BranchTrueFalseTotal
val = temp ? SvIV(*temp) : 0; 4608 0 4608
2778 4608 ▶ if (val<0) val = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (val<0) val = 0; 0 4608 4608
2779 4608 ▶ if (val>255) val = 255;
Branch: 1 branch
BranchTrueFalseTotal
if (val>255) val = 255; 0 4608 4608
2780 4608 maps[j][i] = val;
2781 }
2782 }
2783 }
2784 9 i_map(im, maps, mask);
2785 9 myfree(maps);
2786 9 RETVAL = 1;
2787 OUTPUT:
2788 RETVAL
2789  
2790 float
2791 i_img_diff(im1,im2)
2792 Imager::ImgRaw im1
2793 Imager::ImgRaw im2
2794  
2795 double
2796 i_img_diffd(im1,im2)
2797 Imager::ImgRaw im1
2798 Imager::ImgRaw im2
2799  
2800 int
2801 i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL)
2802 Imager::ImgRaw im1
2803 Imager::ImgRaw im2
2804 im_double epsilon
2805 const char *what
2806  
2807 double
2808 i_img_epsilonf()
2809  
2810 bool
2811 _is_color_object(sv)
2812 SV* sv
2813 CODE:
2814 924 ▶ SvGETMAGIC(sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(sv); 0 924 924
SvGETMAGIC(sv); 0 0 0
2815 1856 ▶ RETVAL = SvOK(sv) && SvROK(sv) &&
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = SvOK(sv) && SvROK(sv) && 924 0 924
RETVAL = SvOK(sv) && SvROK(sv) && 761 163 924
2816 828 (sv_derived_from(sv, "Imager::Color")
2817 104 ▶ || sv_derived_from(sv, "Imager::Color::Float"));
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(sv, "Imager::Color::Float")); 37 67 104
2818 OUTPUT:
2819 RETVAL
2820  
2821 #ifdef HAVE_LIBTT
2822  
2823  
2824 Imager::Font::TT
2825 i_tt_new(fontname)
2826 char* fontname
2827  
2828  
2829 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
2830  
2831 #define TT_DESTROY(handle) i_tt_destroy(handle)
2832  
2833 void
2834 TT_DESTROY(handle)
2835 Imager::Font::TT handle
2836  
2837 int
2838 TT_CLONE_SKIP(...)
2839 CODE:
2840 (void)items; /* avoid unused warning */
2841 RETVAL = 1;
2842 OUTPUT:
2843 RETVAL
2844  
2845  
2846 MODULE = Imager PACKAGE = Imager
2847  
2848  
2849 undef_int
2850 i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1)
2851 Imager::Font::TT handle
2852 Imager::ImgRaw im
2853 i_img_dim xb
2854 i_img_dim yb
2855 Imager::Color cl
2856 im_double points
2857 SV * str_sv
2858 int smooth
2859 int utf8
2860 int align
2861 PREINIT:
2862 char *str;
2863 STRLEN len;
2864 CODE:
2865 str = SvPV(str_sv, len);
2866 #ifdef SvUTF8
2867 if (SvUTF8(str_sv))
2868 utf8 = 1;
2869 #endif
2870 RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
2871 len, smooth, utf8, align);
2872 OUTPUT:
2873 RETVAL
2874  
2875  
2876 undef_int
2877 i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1)
2878 Imager::Font::TT handle
2879 Imager::ImgRaw im
2880 i_img_dim xb
2881 i_img_dim yb
2882 int channel
2883 im_double points
2884 SV * str_sv
2885 int smooth
2886 int utf8
2887 int align
2888 PREINIT:
2889 char *str;
2890 STRLEN len;
2891 CODE:
2892 str = SvPV(str_sv, len);
2893 #ifdef SvUTF8
2894 if (SvUTF8(str_sv))
2895 utf8 = 1;
2896 #endif
2897 RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
2898 smooth, utf8, align);
2899 OUTPUT:
2900 RETVAL
2901  
2902  
2903 void
2904 i_tt_bbox(handle,point,str_sv,utf8)
2905 Imager::Font::TT handle
2906 im_double point
2907 SV* str_sv
2908 int utf8
2909 PREINIT:
2910 i_img_dim cords[BOUNDING_BOX_COUNT];
2911 int rc;
2912 char * str;
2913 STRLEN len;
2914 int i;
2915 PPCODE:
2916 str = SvPV(str_sv, len);
2917 #ifdef SvUTF8
2918 if (SvUTF8(ST(2)))
2919 utf8 = 1;
2920 #endif
2921 if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
2922 EXTEND(SP, rc);
2923 for (i = 0; i < rc; ++i) {
2924 PUSHs(sv_2mortal(newSViv(cords[i])));
2925 }
2926 }
2927  
2928 void
2929 i_tt_has_chars(handle, text_sv, utf8)
2930 Imager::Font::TT handle
2931 SV *text_sv
2932 int utf8
2933 PREINIT:
2934 char const *text;
2935 STRLEN len;
2936 char *work;
2937 size_t count;
2938 size_t i;
2939 PPCODE:
2940 i_clear_error();
2941 text = SvPV(text_sv, len);
2942 #ifdef SvUTF8
2943 if (SvUTF8(text_sv))
2944 utf8 = 1;
2945 #endif
2946 work = mymalloc(len);
2947 count = i_tt_has_chars(handle, text, len, utf8, work);
2948 if (GIMME_V == G_ARRAY) {
2949 if (count) {
2950 EXTEND(SP, count);
2951 for (i = 0; i < count; ++i) {
2952 PUSHs(boolSV(work[i]));
2953 }
2954 }
2955 }
2956 else if (count) {
2957 EXTEND(SP, 1);
2958 PUSHs(sv_2mortal(newSVpv(work, count)));
2959 }
2960 myfree(work);
2961  
2962 void
2963 i_tt_dump_names(handle)
2964 Imager::Font::TT handle
2965  
2966 void
2967 i_tt_face_name(handle)
2968 Imager::Font::TT handle
2969 PREINIT:
2970 char name[255];
2971 size_t len;
2972 PPCODE:
2973 len = i_tt_face_name(handle, name, sizeof(name));
2974 if (len) {
2975 EXTEND(SP, 1);
2976 PUSHs(sv_2mortal(newSVpv(name, len-1)));
2977 }
2978  
2979 void
2980 i_tt_glyph_name(handle, text_sv, utf8 = 0)
2981 Imager::Font::TT handle
2982 SV *text_sv
2983 int utf8
2984 PREINIT:
2985 char const *text;
2986 STRLEN work_len;
2987 size_t len;
2988 size_t outsize;
2989 char name[255];
2990 PPCODE:
2991 i_clear_error();
2992 text = SvPV(text_sv, work_len);
2993 #ifdef SvUTF8
2994 if (SvUTF8(text_sv))
2995 utf8 = 1;
2996 #endif
2997 len = work_len;
2998 while (len) {
2999 unsigned long ch;
3000 if (utf8) {
3001 ch = i_utf8_advance(&text, &len);
3002 if (ch == ~0UL) {
3003 i_push_error(0, "invalid UTF8 character");
3004 XSRETURN_EMPTY;
3005 }
3006 }
3007 else {
3008 ch = *text++;
3009 --len;
3010 }
3011 EXTEND(SP, 1);
3012 if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
3013 PUSHs(sv_2mortal(newSVpv(name, 0)));
3014 }
3015 else {
3016 PUSHs(&PL_sv_undef);
3017 }
3018 }
3019  
3020 #endif
3021  
3022 const char *
3023 i_test_format_probe(ig, length)
3024 Imager::IO ig
3025 int length
3026  
3027 int
3028 i_add_file_magic(name, bits_sv, mask_sv)
3029 const char *name
3030 SV *bits_sv
3031 SV *mask_sv
3032 PREINIT:
3033 const unsigned char *bits;
3034 const unsigned char *mask;
3035 size_t bits_size;
3036 size_t mask_size;
3037 CODE:
3038 1 i_clear_error();
3039 1 ▶ bits = (const unsigned char *)SvPV(bits_sv, bits_size);
Branch: 1 branch
BranchTrueFalseTotal
bits = (const unsigned char *)SvPV(bits_sv, bits_size); 1 0 1
3040 1 mask = (const unsigned char *)SvPV(mask_sv, mask_size);
3041 1 ▶ if (bits_size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (bits_size == 0) { 0 1 1
3042 0 i_push_error(0, "bits must be non-empty");
3043 0 XSRETURN_EMPTY;
3044 }
3045 1 ▶ if (mask_size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask_size == 0) { 0 1 1
3046 0 i_push_error(0, "mask must be non-empty");
3047 0 XSRETURN_EMPTY;
3048 }
3049 1 ▶ if (bits_size != mask_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (bits_size != mask_size) { 0 1 1
3050 0 i_push_error(0, "bits and mask must be the same length");
3051 0 XSRETURN_EMPTY;
3052 }
3053 1 ▶ if (!*name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!*name) { 0 1 1
3054 0 i_push_error(0, "name must be non-empty");
3055 0 XSRETURN_EMPTY;
3056 }
3057 1 RETVAL = i_add_file_magic(name, bits, mask, bits_size);
3058 OUTPUT:
3059 RETVAL
3060  
3061 Imager::ImgRaw
3062 i_readpnm_wiol(ig, allow_incomplete)
3063 Imager::IO ig
3064 int allow_incomplete
3065  
3066  
3067 void
3068 i_readpnm_multi_wiol(ig, allow_incomplete)
3069 Imager::IO ig
3070 int allow_incomplete
3071 PREINIT:
3072 i_img **imgs;
3073 1 ▶ int count=0;
Branch: 1 branch
BranchTrueFalseTotal
int count=0; 1 0 1
3074 int i;
3075 PPCODE:
3076 1 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
3077 1 ▶ if (imgs) {
Branch: 1 branch
BranchTrueFalseTotal
if (imgs) { 1 0 1
3078 1 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 1 0 1
EXTEND(SP, count); 0 1 1
3079 4 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 3 1 4
3080 3 SV *sv = sv_newmortal();
3081 3 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
3082 3 PUSHs(sv);
3083 }
3084 1 myfree(imgs);
3085 }
3086  
3087 undef_int
3088 i_writeppm_wiol(im, ig)
3089 Imager::ImgRaw im
3090 Imager::IO ig
3091  
3092  
3093  
3094  
3095  
3096 Imager::ImgRaw
3097 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
3098 Imager::IO ig
3099 i_img_dim x
3100 i_img_dim y
3101 int datachannels
3102 int storechannels
3103 int intrl
3104  
3105 undef_int
3106 i_writeraw_wiol(im,ig)
3107 Imager::ImgRaw im
3108 Imager::IO ig
3109  
3110 undef_int
3111 i_writebmp_wiol(im,ig)
3112 Imager::ImgRaw im
3113 Imager::IO ig
3114  
3115 Imager::ImgRaw
3116 i_readbmp_wiol(ig, allow_incomplete=0)
3117 Imager::IO ig
3118 int allow_incomplete
3119  
3120  
3121 undef_int
3122 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
3123 Imager::ImgRaw im
3124 Imager::IO ig
3125 int wierdpack
3126 int compress
3127 char* idstring
3128 PREINIT:
3129 int idlen;
3130 CODE:
3131 27 idlen = SvCUR(ST(4));
3132 27 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
3133 OUTPUT:
3134 RETVAL
3135  
3136  
3137 Imager::ImgRaw
3138 i_readtga_wiol(ig, length)
3139 Imager::IO ig
3140 int length
3141  
3142  
3143  
3144  
3145 Imager::ImgRaw
3146 i_scaleaxis(im,Value,Axis)
3147 Imager::ImgRaw im
3148 im_double Value
3149 int Axis
3150  
3151 Imager::ImgRaw
3152 i_scale_nn(im,scx,scy)
3153 Imager::ImgRaw im
3154 im_double scx
3155 im_double scy
3156  
3157 Imager::ImgRaw
3158 i_scale_mixing(im, width, height)
3159 Imager::ImgRaw im
3160 i_img_dim width
3161 i_img_dim height
3162  
3163 Imager::ImgRaw
3164 i_haar(im)
3165 Imager::ImgRaw im
3166  
3167 int
3168 i_count_colors(im,maxc)
3169 Imager::ImgRaw im
3170 int maxc
3171  
3172 void
3173 i_get_anonymous_color_histo(im, maxc = 0x40000000)
3174 Imager::ImgRaw im
3175 int maxc
3176 PREINIT:
3177 int i;
3178 5 unsigned int * col_usage = NULL;
3179 int col_cnt;
3180 PPCODE:
3181 5 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
3182 5 ▶ if (col_cnt <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (col_cnt <= 0) { 1 4 5
3183 1 XSRETURN_EMPTY;
3184 }
3185 4 ▶ EXTEND(SP, col_cnt);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, col_cnt); 4 0 4
EXTEND(SP, col_cnt); 0 4 4
3186 13 ▶ for (i = 0; i < col_cnt; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < col_cnt; i++) { 9 4 13
3187 9 PUSHs(sv_2mortal(newSViv( col_usage[i])));
3188 }
3189 4 myfree(col_usage);
3190  
3191  
3192 void
3193 i_transform(im, opx, opy, parm)
3194 Imager::ImgRaw im
3195 int *opx
3196 int *opy
3197 double *parm
3198 PREINIT:
3199 STRLEN size_opx, size_opy, size_parm;
3200 i_img *result;
3201 PPCODE:
3202 0 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
3203 0 ▶ if (result) {
Branch: 1 branch
BranchTrueFalseTotal
if (result) { 0 0 0
3204 0 SV *result_sv = sv_newmortal();
3205 0 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 0 0
3206 0 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
3207 0 PUSHs(result_sv);
3208 }
3209  
3210 void
3211 i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
3212 SV *sv_width
3213 SV *sv_height
3214 SV *sv_ops
3215 AV *av_n_regs
3216 AV *av_c_regs
3217 AV *av_in_imgs
3218 int channels
3219 PREINIT:
3220 i_img_dim width;
3221 i_img_dim height;
3222 struct rm_op *ops;
3223 STRLEN ops_len;
3224 int ops_count;
3225 double *n_regs;
3226 int n_regs_count;
3227 i_color *c_regs;
3228 int c_regs_count;
3229 int in_imgs_count;
3230 i_img **in_imgs;
3231 SV *sv1;
3232 IV tmp;
3233 int i;
3234 i_img *result;
3235 PPCODE:
3236  
3237 28 in_imgs_count = av_len(av_in_imgs)+1;
3238 54 ▶ for (i = 0; i < in_imgs_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < in_imgs_count; ++i) { 26 28 54
3239 26 sv1 = *av_fetch(av_in_imgs, i, 0);
3240 26 ▶ if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_derived_from(sv1, "Imager::ImgRaw")) { 0 26 26
3241 0 croak("sv_in_img must contain only images");
3242 }
3243 }
3244 28 ▶ if (in_imgs_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_imgs_count > 0) { 25 3 28
3245 25 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
3246 51 ▶ for (i = 0; i < in_imgs_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < in_imgs_count; ++i) { 26 25 51
3247 26 sv1 = *av_fetch(av_in_imgs,i,0);
3248 26 ▶ if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_derived_from(sv1, "Imager::ImgRaw")) { 0 26 26
3249 0 croak("Parameter 5 must contain only images");
3250 }
3251 26 tmp = SvIV((SV*)SvRV(sv1));
3252 26 in_imgs[i] = INT2PTR(i_img*, tmp);
3253 }
3254 }
3255 else {
3256 /* no input images */
3257 3 in_imgs = NULL;
3258 }
3259 /* default the output size from the first input if possible */
3260 28 ▶ if (SvOK(sv_width))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv_width)) 3 25 28
3261 3 width = SvIV(sv_width);
3262 25 ▶ else if (in_imgs_count)
Branch: 1 branch
BranchTrueFalseTotal
else if (in_imgs_count) 25 0 25
3263 25 width = in_imgs[0]->xsize;
3264 else
3265 0 croak("No output image width supplied");
3266  
3267 28 ▶ if (SvOK(sv_height))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv_height)) 3 25 28
3268 3 height = SvIV(sv_height);
3269 25 ▶ else if (in_imgs_count)
Branch: 1 branch
BranchTrueFalseTotal
else if (in_imgs_count) 25 0 25
3270 25 height = in_imgs[0]->ysize;
3271 else
3272 0 croak("No output image height supplied");
3273  
3274 28 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
3275 28 ▶ if (ops_len % sizeof(struct rm_op))
Branch: 1 branch
BranchTrueFalseTotal
if (ops_len % sizeof(struct rm_op)) 0 28 28
3276 0 croak("Imager: Parameter 3 must be a bitmap of regops\n");
3277 28 ops_count = ops_len / sizeof(struct rm_op);
3278  
3279 28 n_regs_count = av_len(av_n_regs)+1;
3280 28 n_regs = mymalloc(n_regs_count * sizeof(double));
3281 276 ▶ for (i = 0; i < n_regs_count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n_regs_count; ++i) { 248 28 276
3282 248 sv1 = *av_fetch(av_n_regs,i,0);
3283 248 ▶ if (SvOK(sv1))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv1)) 146 102 248
3284 146 n_regs[i] = SvNV(sv1);
3285 }
3286 28 c_regs_count = av_len(av_c_regs)+1;
3287 28 c_regs = mymalloc(c_regs_count * sizeof(i_color));
3288 /* I don't bother initializing the colou?r registers */
3289  
3290 28 result=i_transform2(width, height, channels, ops, ops_count,
3291 n_regs, n_regs_count,
3292 c_regs, c_regs_count, in_imgs, in_imgs_count);
3293 28 ▶ if (in_imgs)
Branch: 1 branch
BranchTrueFalseTotal
if (in_imgs) 25 3 28
3294 25 myfree(in_imgs);
3295 28 myfree(n_regs);
3296 28 myfree(c_regs);
3297 28 ▶ if (result) {
Branch: 1 branch
BranchTrueFalseTotal
if (result) { 27 1 28
3298 27 SV *result_sv = sv_newmortal();
3299 27 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 27 27
3300 27 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
3301 27 PUSHs(result_sv);
3302 }
3303  
3304  
3305 void
3306 i_contrast(im,intensity)
3307 Imager::ImgRaw im
3308 im_float intensity
3309  
3310 void
3311 i_hardinvert(im)
3312 Imager::ImgRaw im
3313  
3314 void
3315 i_hardinvertall(im)
3316 Imager::ImgRaw im
3317  
3318 void
3319 i_noise(im,amount,type)
3320 Imager::ImgRaw im
3321 im_float amount
3322 unsigned char type
3323  
3324 void
3325 i_bumpmap(im,bump,channel,light_x,light_y,strength)
3326 Imager::ImgRaw im
3327 Imager::ImgRaw bump
3328 int channel
3329 i_img_dim light_x
3330 i_img_dim light_y
3331 i_img_dim strength
3332  
3333  
3334 void
3335 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
3336 Imager::ImgRaw im
3337 Imager::ImgRaw bump
3338 int channel
3339 i_img_dim tx
3340 i_img_dim ty
3341 im_double Lx
3342 im_double Ly
3343 im_double Lz
3344 im_float cd
3345 im_float cs
3346 im_float n
3347 Imager::Color Ia
3348 Imager::Color Il
3349 Imager::Color Is
3350  
3351  
3352  
3353 void
3354 i_postlevels(im,levels)
3355 Imager::ImgRaw im
3356 int levels
3357  
3358 void
3359 i_mosaic(im,size)
3360 Imager::ImgRaw im
3361 i_img_dim size
3362  
3363 void
3364 i_watermark(im,wmark,tx,ty,pixdiff)
3365 Imager::ImgRaw im
3366 Imager::ImgRaw wmark
3367 i_img_dim tx
3368 i_img_dim ty
3369 int pixdiff
3370  
3371  
3372 void
3373 i_autolevels(im,lsat,usat,skew)
3374 Imager::ImgRaw im
3375 im_float lsat
3376 im_float usat
3377 im_float skew
3378  
3379 void
3380 i_autolevels_mono(im,lsat,usat)
3381 Imager::ImgRaw im
3382 im_float lsat
3383 im_float usat
3384  
3385 void
3386 i_radnoise(im,xo,yo,rscale,ascale)
3387 Imager::ImgRaw im
3388 im_float xo
3389 im_float yo
3390 im_float rscale
3391 im_float ascale
3392  
3393 void
3394 i_turbnoise(im, xo, yo, scale)
3395 Imager::ImgRaw im
3396 im_float xo
3397 im_float yo
3398 im_float scale
3399  
3400  
3401 void
3402 i_gradgen(im, xo, yo, ac, dmeasure)
3403 Imager::ImgRaw im
3404 i_img_dim *xo
3405 i_img_dim *yo
3406 i_color *ac
3407 int dmeasure
3408 PREINIT:
3409 STRLEN size_xo;
3410 STRLEN size_yo;
3411 STRLEN size_ac;
3412 CODE:
3413 1 ▶ if (size_xo != size_yo || size_xo != size_ac)
Branch: 2 branches
BranchTrueFalseTotal
if (size_xo != size_yo || size_xo != size_ac) 1 0 1
if (size_xo != size_yo || size_xo != size_ac) 0 1 1
3414 0 croak("i_gradgen: x, y and color arrays must be the same size");
3415 1 ▶ if (size_xo < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (size_xo < 2) 0 1 1
3416 0 croak("Usage: i_gradgen array refs must have more than 1 entry each");
3417 1 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
3418  
3419 Imager::ImgRaw
3420 i_diff_image(im, im2, mindist=0)
3421 Imager::ImgRaw im
3422 Imager::ImgRaw im2
3423 im_double mindist
3424  
3425 Imager::ImgRaw
3426 i_rgbdiff_image(im, im2)
3427 Imager::ImgRaw im
3428 Imager::ImgRaw im2
3429  
3430 undef_int
3431 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3432 Imager::ImgRaw im
3433 im_double xa
3434 im_double ya
3435 im_double xb
3436 im_double yb
3437 int type
3438 int repeat
3439 int combine
3440 int super_sample
3441 im_double ssample_param
3442 PREINIT:
3443 AV *asegs;
3444 int count;
3445 i_fountain_seg *segs;
3446 CODE:
3447 9 ▶ if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10)))) 9 0 9
if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10)))) 0 9 9
3448 0 croak("i_fountain: argument 11 must be an array ref");
3449
3450 9 asegs = (AV *)SvRV(ST(10));
3451 9 segs = load_fount_segs(aTHX_ asegs, &count);
3452 9 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
3453 super_sample, ssample_param, count, segs);
3454 9 myfree(segs);
3455 OUTPUT:
3456 RETVAL
3457  
3458 Imager::FillHandle
3459 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3460 im_double xa
3461 im_double ya
3462 im_double xb
3463 im_double yb
3464 int type
3465 int repeat
3466 int combine
3467 int super_sample
3468 im_double ssample_param
3469 PREINIT:
3470 AV *asegs;
3471 int count;
3472 i_fountain_seg *segs;
3473 CODE:
3474 5 ▶ if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9)))) 5 0 5
if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9)))) 0 5 5
3475 0 croak("i_fountain: argument 11 must be an array ref");
3476
3477 5 asegs = (AV *)SvRV(ST(9));
3478 5 segs = load_fount_segs(aTHX_ asegs, &count);
3479 5 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
3480 super_sample, ssample_param, count, segs);
3481 5 myfree(segs);
3482 OUTPUT:
3483 RETVAL
3484  
3485 Imager::FillHandle
3486 i_new_fill_opacity(other_fill, alpha_mult)
3487 Imager::FillHandle other_fill
3488 im_double alpha_mult
3489  
3490 void
3491 i_errors()
3492 PREINIT:
3493 i_errmsg *errors;
3494 int i;
3495 AV *av;
3496 SV *sv;
3497 PPCODE:
3498 393 errors = i_errors();
3499 393 i = 0;
3500 891 ▶ while (errors[i].msg) {
Branch: 1 branch
BranchTrueFalseTotal
while (errors[i].msg) { 498 393 891
3501 498 av = newAV();
3502 498 sv = newSVpv(errors[i].msg, 0);
3503 498 ▶ if (!av_store(av, 0, sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store(av, 0, sv)) { 0 498 498
3504 0 SvREFCNT_dec(sv);
3505 }
3506 498 sv = newSViv(errors[i].code);
3507 498 ▶ if (!av_store(av, 1, sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store(av, 1, sv)) { 0 498 498
3508 0 SvREFCNT_dec(sv);
3509 }
3510 498 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV*)av))); 0 498 498
3511 498 ++i;
3512 }
3513  
3514 void
3515 i_clear_error()
3516  
3517 void
3518 i_push_error(code, msg)
3519 int code
3520 const char *msg
3521  
3522 undef_int
3523 i_nearest_color(im, ...)
3524 Imager::ImgRaw im
3525 PREINIT:
3526 int num;
3527 i_img_dim *xo;
3528 i_img_dim *yo;
3529 i_color *ival;
3530 int dmeasure;
3531 int i;
3532 SV *sv;
3533 AV *axx;
3534 AV *ayy;
3535 AV *ac;
3536 CODE:
3537 1 ▶ if (items != 5)
Branch: 1 branch
BranchTrueFalseTotal
if (items != 5) 0 1 1
3538 0 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3539 1 ▶ if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) 1 0 1
if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1)))) 0 1 1
3540 0 croak("i_nearest_color: Second argument must be an array ref");
3541 1 ▶ if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) 1 0 1
if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2)))) 0 1 1
3542 0 croak("i_nearest_color: Third argument must be an array ref");
3543 1 ▶ if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) 1 0 1
if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3)))) 0 1 1
3544 0 croak("i_nearest_color: Fourth argument must be an array ref");
3545 1 axx = (AV *)SvRV(ST(1));
3546 1 ayy = (AV *)SvRV(ST(2));
3547 1 ac = (AV *)SvRV(ST(3));
3548 1 dmeasure = (int)SvIV(ST(4));
3549
3550 1 ▶ num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
Branch: 1 branch
BranchTrueFalseTotal
num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy); 0 1 1
3551 1 ▶ num = num <= av_len(ac) ? num : av_len(ac);
Branch: 1 branch
BranchTrueFalseTotal
num = num <= av_len(ac) ? num : av_len(ac); 0 1 1
3552 1 num++;
3553 1 ▶ if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
Branch: 1 branch
BranchTrueFalseTotal
if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each"); 0 1 1
3554 1 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3555 1 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3556 1 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
3557 4 ▶ for(i = 0; i<num; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i<num; i++) { 3 1 4
3558 3 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3559 3 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
3560 3 sv = *av_fetch(ac, i, 0);
3561 3 ▶ if ( !sv_derived_from(sv, "Imager::Color") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !sv_derived_from(sv, "Imager::Color") ) { 0 3 3
3562 0 free(axx); free(ayy); free(ac);
3563 0 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3564 }
3565 3 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
3566 }
3567 1 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3568 OUTPUT:
3569 RETVAL
3570  
3571 void
3572 DSO_open(filename)
3573 char* filename
3574 PREINIT:
3575 void *rc;
3576 char *evstr;
3577 PPCODE:
3578 0 rc=DSO_open(filename,&evstr);
3579 0 ▶ if (rc!=NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc!=NULL) { 0 0 0
3580 0 ▶ if (evstr!=NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (evstr!=NULL) { 0 0 0
3581 0 ▶ EXTEND(SP,2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,2); 0 0 0
3582 0 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3583 0 PUSHs(sv_2mortal(newSVpv(evstr, 0)));
3584 } else {
3585 0 ▶ EXTEND(SP,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,1); 0 0 0
3586 0 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3587 }
3588 }
3589  
3590  
3591 undef_int
3592 DSO_close(dso_handle)
3593 void* dso_handle
3594  
3595 void
3596 DSO_funclist(dso_handle_v)
3597 void* dso_handle_v
3598 PREINIT:
3599 int i;
3600 DSO_handle *dso_handle;
3601 func_ptr *functions;
3602 PPCODE:
3603 0 dso_handle=(DSO_handle*)dso_handle_v;
3604 0 functions = DSO_funclist(dso_handle);
3605 0 i=0;
3606 0 ▶ while( functions[i].name != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while( functions[i].name != NULL) { 0 0 0
3607 0 ▶ EXTEND(SP,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,1); 0 0 0
3608 0 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
3609 0 ▶ EXTEND(SP,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP,1); 0 0 0
3610 0 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
3611 }
3612  
3613 void
3614 DSO_call(handle,func_index,hv)
3615 void* handle
3616 int func_index
3617 HV *hv
3618 PPCODE:
3619 0 DSO_call( (DSO_handle *)handle,func_index,hv);
3620  
3621 Imager::Color
3622 i_get_pixel(im, x, y)
3623 Imager::ImgRaw im
3624 i_img_dim x
3625 i_img_dim y;
3626 CODE:
3627 412 RETVAL = (i_color *)mymalloc(sizeof(i_color));
3628 412 memset(RETVAL, 0, sizeof(*RETVAL));
3629 412 ▶ if (i_gpix(im, x, y, RETVAL) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_gpix(im, x, y, RETVAL) != 0) { 38 374 412
3630 38 myfree(RETVAL);
3631 38 XSRETURN_UNDEF;
3632 }
3633 OUTPUT:
3634 RETVAL
3635
3636  
3637 int
3638 i_ppix(im, x, y, cl)
3639 Imager::ImgRaw im
3640 i_img_dim x
3641 i_img_dim y
3642 Imager::Color cl
3643  
3644 Imager::ImgRaw
3645 i_img_pal_new(x, y, channels, maxpal)
3646 i_img_dim x
3647 i_img_dim y
3648 int channels
3649 int maxpal
3650  
3651 Imager::ImgRaw
3652 i_img_to_pal(src, quant_hv)
3653 Imager::ImgRaw src
3654 HV *quant_hv
3655 PREINIT:
3656 i_quantize quant;
3657 CODE:
3658 19 memset(&quant, 0, sizeof(quant));
3659 19 quant.version = 1;
3660 19 quant.mc_size = 256;
3661 19 i_clear_error();
3662 19 ▶ if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { 1 18 19
3663 1 XSRETURN_EMPTY;
3664 }
3665 18 RETVAL = i_img_to_pal(src, &quant);
3666 18 ▶ if (RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL) { 17 1 18
3667 17 ip_copy_colors_back(aTHX_ quant_hv, &quant);
3668 }
3669 18 ip_cleanup_quant_opts(aTHX_ &quant);
3670 OUTPUT:
3671 RETVAL
3672  
3673 Imager::ImgRaw
3674 i_img_to_rgb(src)
3675 Imager::ImgRaw src
3676  
3677 void
3678 i_img_make_palette(HV *quant_hv, ...)
3679 PREINIT:
3680 5 ssize_t count = items - 1;
3681 i_quantize quant;
3682 5 ▶ i_img **imgs = NULL;
Branch: 1 branch
BranchTrueFalseTotal
i_img **imgs = NULL; 0 5 5
3683 ssize_t color_index;
3684 PPCODE:
3685 5 ▶ if (count <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (count <= 0) 0 5 5
3686 0 croak("Please supply at least one image (%zd)", count);
3687 5 imgs = malloc_temp(aTHX_ count * sizeof(i_img *));
3688 10 ▶ for (color_index = 0; color_index < count; ++color_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (color_index = 0; color_index < count; ++color_index) { 5 5 10
3689 5 SV *img_sv = ST(color_index + 1);
3690 5 ▶ if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) { 5 0 5
if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) { 5 0 5
3691 5 imgs[color_index] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3692 }
3693 else {
3694 0 croak("Image %zd is not an image object", color_index+1);
3695 }
3696 }
3697 5 memset(&quant, 0, sizeof(quant));
3698 5 quant.version = 1;
3699 5 quant.mc_size = 256;
3700 5 ▶ if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) { 1 4 5
3701 1 XSRETURN_EMPTY;
3702 }
3703 4 i_quant_makemap(&quant, imgs, count);
3704 4 ▶ EXTEND(SP, quant.mc_count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, quant.mc_count); 4 0 4
EXTEND(SP, quant.mc_count); 0 4 4
3705 282 ▶ for (color_index = 0; color_index < quant.mc_count; ++color_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (color_index = 0; color_index < quant.mc_count; ++color_index) { 278 4 282
3706 278 SV *sv_c = make_i_color_sv_mortal(aTHX_ quant.mc_colors + color_index);
3707 278 PUSHs(sv_c);
3708 }
3709 4 ip_cleanup_quant_opts(aTHX_ &quant);
3710
3711  
3712 void
3713 i_gpal(im, l, r, y)
3714 Imager::ImgRaw im
3715 i_img_dim l
3716 i_img_dim r
3717 i_img_dim y
3718 PREINIT:
3719 i_palidx *work;
3720 int count, i;
3721 PPCODE:
3722 10 ▶ if (l < r) {
Branch: 1 branch
BranchTrueFalseTotal
if (l < r) { 10 0 10
3723 10 work = mymalloc((r-l) * sizeof(i_palidx));
3724 10 ▶ count = i_gpal(im, l, r, y, work);
Branch: 1 branch
BranchTrueFalseTotal
count = i_gpal(im, l, r, y, work); 10 0 10
3725 10 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 8 2 10
3726 8 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 8 0 8
EXTEND(SP, count); 0 8 8
3727 320 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 312 8 320
3728 312 PUSHs(sv_2mortal(newSViv(work[i])));
3729 }
3730 }
3731 2 ▶ else if (count) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count) { 2 0 2
3732 2 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2 2
3733 2 PUSHs(newSVpvn_flags((char *)work, count * sizeof(i_palidx), SVs_TEMP));
3734 }
3735 10 myfree(work);
3736 }
3737 else {
3738 0 ▶ if (GIMME_V != G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_ARRAY) { 0 0 0
3739 0 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 0 0
3740 0 PUSHs(&PL_sv_undef);
3741 }
3742 }
3743  
3744 int
3745 i_ppal(im, l, y, ...)
3746 Imager::ImgRaw im
3747 i_img_dim l
3748 i_img_dim y
3749 PREINIT:
3750 i_palidx *work;
3751 i_img_dim i;
3752 CODE:
3753 331 ▶ if (items > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) { 331 0 331
3754 331 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
3755 61053 ▶ for (i=0; i < items-3; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < items-3; ++i) { 60722 331 61053
3756 60722 work[i] = SvIV(ST(i+3));
3757 }
3758 331 validate_i_ppal(im, work, items - 3);
3759 329 ▶ RETVAL = i_ppal(im, l, l+items-3, y, work);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = i_ppal(im, l, l+items-3, y, work); 329 0 329
3760 }
3761 else {
3762 0 RETVAL = 0;
3763 }
3764 OUTPUT:
3765 RETVAL
3766  
3767 int
3768 i_ppal_p(im, l, y, data)
3769 Imager::ImgRaw im
3770 i_img_dim l
3771 i_img_dim y
3772 SV *data
3773 PREINIT:
3774 i_palidx const *work;
3775 STRLEN len;
3776 CODE:
3777 4 work = (i_palidx const *)SvPV(data, len);
3778 4 len /= sizeof(i_palidx);
3779 4 ▶ if (len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > 0) { 4 0 4
3780 4 validate_i_ppal(im, work, len);
3781 2 ▶ RETVAL = i_ppal(im, l, l+len, y, work);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = i_ppal(im, l, l+len, y, work); 2 0 2
3782 }
3783 else {
3784 0 RETVAL = 0;
3785 }
3786 OUTPUT:
3787 RETVAL
3788  
3789 ImSysRet
3790 i_addcolors(im, ...)
3791 Imager::ImgRaw im
3792 PREINIT:
3793 i_color *colors;
3794 int i;
3795 CODE:
3796 35 ▶ if (items < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 2) 0 35 35
3797 0 croak("i_addcolors: no colors to add");
3798 35 colors = mymalloc((items-1) * sizeof(i_color));
3799 148 ▶ for (i=0; i < items-1; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < items-1; ++i) { 113 35 148
3800 113 ▶ if (sv_isobject(ST(i+1))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(ST(i+1)) 113 0 113
3801 113 ▶ && sv_derived_from(ST(i+1), "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(ST(i+1), "Imager::Color")) { 113 0 113
3802 113 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
3803 113 colors[i] = *INT2PTR(i_color *, tmp);
3804 }
3805 else {
3806 0 myfree(colors);
3807 0 croak("i_addcolor: pixels must be Imager::Color objects");
3808 }
3809 }
3810 35 ▶ RETVAL = i_addcolors(im, colors, items-1);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = i_addcolors(im, colors, items-1); 35 0 35
3811 35 myfree(colors);
3812 OUTPUT:
3813 RETVAL
3814  
3815 undef_int
3816 i_setcolors(im, index, ...)
3817 Imager::ImgRaw im
3818 int index
3819 PREINIT:
3820 i_color *colors;
3821 int i;
3822 CODE:
3823 9 ▶ if (items < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 3) 0 9 9
3824 0 croak("i_setcolors: no colors to add");
3825 9 colors = mymalloc((items-2) * sizeof(i_color));
3826 22 ▶ for (i=0; i < items-2; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < items-2; ++i) { 13 9 22
3827 13 ▶ if (sv_isobject(ST(i+2))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(ST(i+2)) 13 0 13
3828 13 ▶ && sv_derived_from(ST(i+2), "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(ST(i+2), "Imager::Color")) { 13 0 13
3829 13 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
3830 13 colors[i] = *INT2PTR(i_color *, tmp);
3831 }
3832 else {
3833 0 myfree(colors);
3834 0 croak("i_setcolors: pixels must be Imager::Color objects");
3835 }
3836 }
3837 9 ▶ RETVAL = i_setcolors(im, index, colors, items-2);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = i_setcolors(im, index, colors, items-2); 9 0 9
3838 9 myfree(colors);
3839 OUTPUT:
3840 RETVAL
3841  
3842 void
3843 i_getcolors(im, index, count=1)
3844 Imager::ImgRaw im
3845 int index
3846 int count
3847 PREINIT:
3848 i_color *colors;
3849 int i;
3850 PPCODE:
3851 20 ▶ if (count < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count < 1) 0 20 20
3852 0 croak("i_getcolors: count must be positive");
3853 20 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
3854 20 ▶ if (i_getcolors(im, index, colors, count)) {
Branch: 2 branches
BranchTrueFalseTotal
if (i_getcolors(im, index, colors, count)) { 20 0 20
if (i_getcolors(im, index, colors, count)) { 20 0 20
3855 20 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 20 0 20
EXTEND(SP, count); 0 20 20
3856 213 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 193 20 213
3857 193 SV *sv = make_i_color_sv_mortal(aTHX_ colors+i);
3858 193 PUSHs(sv);
3859 }
3860 }
3861  
3862 undef_neg_int
3863 i_colorcount(im)
3864 Imager::ImgRaw im
3865  
3866 undef_neg_int
3867 i_maxcolors(im)
3868 Imager::ImgRaw im
3869  
3870 i_palidx
3871 i_findcolor(im, color)
3872 Imager::ImgRaw im
3873 Imager::Color color
3874 CODE:
3875 9 ▶ if (!i_findcolor(im, color, &RETVAL)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!i_findcolor(im, color, &RETVAL)) { 9 0 9
if (!i_findcolor(im, color, &RETVAL)) { 2 7 9
3876 2 XSRETURN_UNDEF;
3877 }
3878 OUTPUT:
3879 RETVAL
3880  
3881 int
3882 i_img_bits(im)
3883 Imager::ImgRaw im
3884  
3885 int
3886 i_img_type(im)
3887 Imager::ImgRaw im
3888  
3889 int
3890 i_img_virtual(im)
3891 Imager::ImgRaw im
3892  
3893 void
3894 i_gsamp(Imager::ImgRaw im, i_img_dim l, i_img_dim r, i_img_dim y, \
3895 i_channel_list channels, SV *err_sv = NULL)
3896 PREINIT:
3897 i_sample_t *data;
3898 i_img_dim count, i;
3899 size_t buf_size;
3900 SV *result_sv;
3901 PPCODE:
3902 378 i_clear_error();
3903 378 ▶ if (is_valid_sample_params(im, l, &r, y, &channels,
Branch: 1 branch
BranchTrueFalseTotal
if (is_valid_sample_params(im, l, &r, y, &channels, 318 60 378
3904 sizeof(i_sample_t), &buf_size)) {
3905 318 result_sv = sv_2mortal(newSV(buf_size));
3906 318 data = (i_sample_t *)SvPVX(result_sv);
3907 318 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
3908 318 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 38 280 318
3909 38 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 38 0 38
EXTEND(SP, count); 0 38 38
3910 2055 ▶ for (i = 0; i < count; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) 2017 38 2055
3911 2017 PUSHs(sv_2mortal(newSViv(data[i])));
3912 }
3913 280 ▶ else if (count) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count) { 280 0 280
3914 280 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 280 280
3915 280 SvCUR_set(result_sv, count * sizeof(i_sample_t));
3916 280 *SvEND(result_sv) = '\0';
3917 280 SvPOK_only(result_sv);
3918 280 PUSHs(result_sv);
3919 }
3920 else {
3921 0 i_push_error(0, "getsamples");
3922 0 ▶ if (err_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (err_sv) 0 0 0
3923 0 save_error_sv(aTHX_ err_sv);
3924 }
3925 }
3926 else {
3927 60 i_push_error(0, "getsamples");
3928 60 ▶ if (err_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (err_sv) 60 0 60
3929 60 save_error_sv(aTHX_ err_sv);
3930 60 ▶ if (GIMME_V == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR) { 28 32 60
3931 28 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 28 28
3932 28 PUSHs(&PL_sv_undef);
3933 }
3934 }
3935  
3936 undef_neg_int
3937 i_gsamp_bits(Imager::ImgRaw im, i_img_dim l, i_img_dim r, i_img_dim y, \
3938 int bits, AV *target, STRLEN offset, i_channel_list channels, \
3939 SV *err_sv = NULL)
3940 PREINIT:
3941 unsigned *data;
3942 i_img_dim count, i;
3943 size_t buf_size;
3944 CODE:
3945 62 i_clear_error();
3946 62 ▶ if (is_valid_sample_params(im, l, &r, y, &channels,
Branch: 1 branch
BranchTrueFalseTotal
if (is_valid_sample_params(im, l, &r, y, &channels, 5 57 62
3947 sizeof(unsigned), &buf_size)) {
3948 5 data = mymalloc(buf_size);
3949 5 ▶ count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
Branch: 1 branch
BranchTrueFalseTotal
count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits); 5 0 5
3950 5 ▶ if (count >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count >= 0) { 5 0 5
3951 75 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 70 5 75
3952 70 av_store(target, i+offset, newSVuv(data[i]));
3953 }
3954 }
3955 else {
3956 0 i_push_error(0, "getsamples");
3957 0 ▶ if (err_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (err_sv) 0 0 0
3958 0 save_error_sv(aTHX_ err_sv);
3959 }
3960 5 myfree(data);
3961 5 RETVAL = count;
3962 }
3963 else {
3964 57 i_push_error(0, "getsamples");
3965 57 ▶ if (err_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (err_sv) 56 1 57
3966 56 save_error_sv(aTHX_ err_sv);
3967 57 RETVAL = -1;
3968 }
3969 OUTPUT:
3970 RETVAL
3971  
3972 undef_neg_int
3973 i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
3974 Imager::ImgRaw im
3975 i_img_dim l
3976 i_img_dim y
3977 int bits
3978 i_channel_list channels
3979 AV *data_av
3980 i_img_dim data_offset
3981 i_img_dim pixel_count
3982 PREINIT:
3983 STRLEN data_count;
3984 size_t data_used;
3985 unsigned *data;
3986 size_t data_index;
3987 CODE:
3988 2 i_clear_error();
3989  
3990 2 data_count = av_len(data_av) + 1;
3991 2 ▶ if (data_offset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (data_offset < 0) { 0 2 2
3992 0 croak("data_offset must be non-negative");
3993 }
3994 2 ▶ if ((size_t)data_offset > data_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)data_offset > data_count) { 0 2 2
3995 0 croak("data_offset greater than number of samples supplied");
3996 }
3997 2 ▶ if (pixel_count == -1 ||
Branch: 1 branch
BranchTrueFalseTotal
if (pixel_count == -1 || 1 1 2
3998 1 ▶ (size_t)data_offset + pixel_count * channels.count > data_count) {
Branch: 1 branch
BranchTrueFalseTotal
(size_t)data_offset + pixel_count * channels.count > data_count) { 0 1 1
3999 1 pixel_count = (data_count - data_offset) / channels.count;
4000 }
4001  
4002 2 data_used = pixel_count * channels.count;
4003 2 data = mymalloc(sizeof(unsigned) * data_count);
4004 44 ▶ for (data_index = 0; data_index < data_used; ++data_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (data_index = 0; data_index < data_used; ++data_index) { 42 2 44
4005 42 data[data_index] =
4006 42 SvUV(*av_fetch(data_av, data_offset + data_index, 0));
4007 }
4008  
4009 2 ▶ RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels, 2 0 2
4010 channels.count, bits);
4011  
4012 2 ▶ if (data)
Branch: 1 branch
BranchTrueFalseTotal
if (data) 2 0 2
4013 2 myfree(data);
4014 OUTPUT:
4015 RETVAL
4016  
4017 undef_neg_int
4018 i_psamp(im, x, y, channels, data, offset = 0, width = -1)
4019 Imager::ImgRaw im
4020 i_img_dim x
4021 i_img_dim y
4022 i_channel_list channels
4023 i_sample_list data
4024 i_img_dim offset
4025 i_img_dim width
4026 PREINIT:
4027 i_img_dim r;
4028 CODE:
4029 82 i_clear_error();
4030 82 ▶ if (offset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset < 0) { 1 81 82
4031 1 i_push_error(0, "offset must be non-negative");
4032 9 XSRETURN_UNDEF;
4033 }
4034 81 ▶ if (offset > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset > 0) { 4 77 81
4035 4 ▶ if ((size_t)offset > data.count) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)offset > data.count) { 1 3 4
4036 1 i_push_error(0, "offset greater than number of samples supplied");
4037 1 XSRETURN_UNDEF;
4038 }
4039 3 data.samples += offset;
4040 3 data.count -= offset;
4041 }
4042 80 ▶ if (width == -1 ||
Branch: 1 branch
BranchTrueFalseTotal
if (width == -1 || 6 74 80
4043 6 ▶ (size_t)width * channels.count > data.count) {
Branch: 1 branch
BranchTrueFalseTotal
(size_t)width * channels.count > data.count) { 4 2 6
4044 78 width = data.count / channels.count;
4045 }
4046 80 ▶ if (x >= im->xsize) {
Branch: 1 branch
BranchTrueFalseTotal
if (x >= im->xsize) { 7 73 80
4047 7 i_push_error(0, "Image position outside of image");
4048 7 XSRETURN_UNDEF;
4049 }
4050 73 ▶ if (width <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (width <= 0) { 0 73 73
4051 0 i_push_errorf(0, "i_psamp: width %zd negative or zero", width);
4052 0 XSRETURN_UNDEF;
4053 }
4054 73 r = x + width;
4055 73 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
4056 OUTPUT:
4057 RETVAL
4058  
4059 undef_neg_int
4060 i_psampf(im, x, y, channels, data, offset = 0, width = -1)
4061 Imager::ImgRaw im
4062 i_img_dim x
4063 i_img_dim y
4064 i_channel_list channels
4065 i_fsample_list data
4066 i_img_dim offset
4067 i_img_dim width
4068 PREINIT:
4069 i_img_dim r;
4070 CODE:
4071 82 i_clear_error();
4072 82 ▶ if (offset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset < 0) { 1 81 82
4073 1 i_push_error(0, "offset must be non-negative");
4074 2 XSRETURN_UNDEF;
4075 }
4076 81 ▶ if (offset > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset > 0) { 4 77 81
4077 4 ▶ if ((size_t)offset > data.count) {
Branch: 1 branch
BranchTrueFalseTotal
if ((size_t)offset > data.count) { 1 3 4
4078 1 i_push_error(0, "offset greater than number of samples supplied");
4079 1 XSRETURN_UNDEF;
4080 }
4081 3 data.samples += offset;
4082 3 data.count -= offset;
4083 }
4084 80 ▶ if (width == -1 ||
Branch: 1 branch
BranchTrueFalseTotal
if (width == -1 || 6 74 80
4085 6 ▶ (size_t)width * channels.count > data.count) {
Branch: 1 branch
BranchTrueFalseTotal
(size_t)width * channels.count > data.count) { 4 2 6
4086 78 width = data.count / channels.count;
4087 }
4088 80 r = x + width;
4089 80 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
4090 OUTPUT:
4091 RETVAL
4092  
4093 Imager::ImgRaw
4094 i_img_masked_new(targ, mask, x, y, w, h)
4095 Imager::ImgRaw targ
4096 i_img_dim x
4097 i_img_dim y
4098 i_img_dim w
4099 i_img_dim h
4100 PREINIT:
4101 i_img *mask;
4102 CODE:
4103 24 ▶ if (SvOK(ST(1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(ST(1))) { 7 17 24
4104 7 ▶ if (!sv_isobject(ST(1))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(ST(1)) 7 0 7
4105 7 ▶ || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(ST(1), "Imager::ImgRaw")) { 0 7 7
4106 0 croak("i_img_masked_new: parameter 2 must undef or an image");
4107 }
4108 7 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
4109 }
4110 else
4111 17 mask = NULL;
4112 24 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
4113 OUTPUT:
4114 RETVAL
4115  
4116 int
4117 i_plin(im, l, y, ...)
4118 Imager::ImgRaw im
4119 i_img_dim l
4120 i_img_dim y
4121 PREINIT:
4122 i_color *work;
4123 STRLEN len;
4124 size_t count;
4125 CODE:
4126 552 ▶ if (items > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) { 552 0 552
4127 552 ▶ if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
Branch: 3 branches
BranchTrueFalseTotal
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 158 394 552
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 158 0 158
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 152 6 158
4128 /* supplied as a byte string */
4129 152 work = (i_color *)SvPV(ST(3), len);
4130 152 count = len / sizeof(i_color);
4131 152 ▶ if (count * sizeof(i_color) != len) {
Branch: 1 branch
BranchTrueFalseTotal
if (count * sizeof(i_color) != len) { 0 152 152
4132 0 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
4133 }
4134 152 RETVAL = i_plin(im, l, l+count, y, work);
4135 }
4136 else {
4137 I32 item_index;
4138 400 work = mymalloc(sizeof(i_color) * (items-3));
4139 26876 ▶ for (item_index = 0; item_index < items-3; ++item_index) {
Branch: 1 branch
BranchTrueFalseTotal
for (item_index = 0; item_index < items-3; ++item_index) { 26476 400 26876
4140 26476 ▶ if (sv_isobject(ST(item_index+3))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(ST(item_index+3)) 26476 0 26476
4141 26476 ▶ && sv_derived_from(ST(item_index+3), "Imager::Color")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(ST(item_index+3), "Imager::Color")) { 26476 0 26476
4142 26476 IV tmp = SvIV((SV *)SvRV(ST(item_index+3)));
4143 26476 work[item_index] = *INT2PTR(i_color *, tmp);
4144 }
4145 else {
4146 0 myfree(work);
4147 0 croak("i_plin: pixels must be Imager::Color objects");
4148 }
4149 }
4150 400 RETVAL = i_plin(im, l, l+items-3, y, work);
4151 400 myfree(work);
4152 }
4153 }
4154 else {
4155 0 RETVAL = 0;
4156 }
4157 OUTPUT:
4158 RETVAL
4159  
4160 int
4161 i_ppixf(im, x, y, cl)
4162 Imager::ImgRaw im
4163 i_img_dim x
4164 i_img_dim y
4165 Imager::Color::Float cl
4166  
4167 void
4168 i_gsampf(Imager::ImgRaw im, i_img_dim l, i_img_dim r, i_img_dim y, \
4169 i_channel_list channels, SV *err_sv = NULL)
4170 PREINIT:
4171 i_fsample_t *data;
4172 i_img_dim count, i;
4173 size_t buf_size;
4174 SV *result_sv;
4175 PPCODE:
4176 73 i_clear_error();
4177 73 ▶ if (is_valid_sample_params(im, l, &r, y, &channels,
Branch: 1 branch
BranchTrueFalseTotal
if (is_valid_sample_params(im, l, &r, y, &channels, 13 60 73
4178 sizeof(i_fsample_t), &buf_size)) {
4179 13 result_sv = sv_2mortal(newSV(buf_size));
4180 13 data = (i_fsample_t *)SvPVX(result_sv);
4181 13 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
4182 13 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 10 3 13
4183 10 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 10 0 10
EXTEND(SP, count); 0 10 10
4184 1224 ▶ for (i = 0; i < count; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) 1214 10 1224
4185 1214 PUSHs(sv_2mortal(newSVnv(data[i])));
4186 }
4187 3 ▶ else if (count) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count) { 3 0 3
4188 3 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 3 3
4189 3 SvCUR_set(result_sv, count * sizeof(i_fsample_t));
4190 3 *SvEND(result_sv) = '\0';
4191 3 SvPOK_only(result_sv);
4192 3 PUSHs(result_sv);
4193 }
4194 }
4195 else {
4196 60 i_push_error(0, "getsamples");
4197 60 ▶ if (err_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (err_sv) 60 0 60
4198 60 save_error_sv(aTHX_ err_sv);
4199 60 ▶ if (GIMME_V == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR) { 28 32 60
4200 28 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 28 28
4201 28 PUSHs(&PL_sv_undef);
4202 }
4203 }
4204  
4205 int
4206 i_plinf(im, l, y, ...)
4207 Imager::ImgRaw im
4208 i_img_dim l
4209 i_img_dim y
4210 PREINIT:
4211 i_fcolor *work;
4212 i_img_dim i;
4213 STRLEN len;
4214 size_t count;
4215 CODE:
4216 226 ▶ if (items > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) { 226 0 226
4217 226 ▶ if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
Branch: 3 branches
BranchTrueFalseTotal
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 8 218 226
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 8 0 8
if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) { 2 6 8
4218 /* supplied as a byte string */
4219 2 work = (i_fcolor *)SvPV(ST(3), len);
4220 2 count = len / sizeof(i_fcolor);
4221 2 ▶ if (count * sizeof(i_fcolor) != len) {
Branch: 1 branch
BranchTrueFalseTotal
if (count * sizeof(i_fcolor) != len) { 0 2 2
4222 0 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
4223 }
4224 2 RETVAL = i_plinf(im, l, l+count, y, work);
4225 }
4226 else {
4227 224 work = mymalloc(sizeof(i_fcolor) * (items-3));
4228 20993 ▶ for (i=0; i < items-3; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < items-3; ++i) { 20769 224 20993
4229 20769 ▶ if (sv_isobject(ST(i+3))
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(ST(i+3)) 20769 0 20769
4230 20769 ▶ && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(ST(i+3), "Imager::Color::Float")) { 20769 0 20769
4231 20769 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
4232 20769 work[i] = *INT2PTR(i_fcolor *, tmp);
4233 }
4234 else {
4235 0 myfree(work);
4236 0 croak("i_plinf: pixels must be Imager::Color::Float objects");
4237 }
4238 }
4239 /**(char *)0 = 1;*/
4240 224 RETVAL = i_plinf(im, l, l+items-3, y, work);
4241 224 myfree(work);
4242 }
4243 }
4244 else {
4245 0 RETVAL = 0;
4246 }
4247 OUTPUT:
4248 RETVAL
4249  
4250 Imager::Color::Float
4251 i_gpixf(im, x, y)
4252 Imager::ImgRaw im
4253 i_img_dim x
4254 i_img_dim y;
4255 CODE:
4256 52 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
4257 52 memset(RETVAL, 0, sizeof(*RETVAL));
4258 52 ▶ if (i_gpixf(im, x, y, RETVAL) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_gpixf(im, x, y, RETVAL) != 0) { 6 46 52
4259 6 myfree(RETVAL);
4260 6 XSRETURN_UNDEF;
4261 }
4262 OUTPUT:
4263 RETVAL
4264  
4265 void
4266 i_glin(im, l, r, y)
4267 Imager::ImgRaw im
4268 i_img_dim l
4269 i_img_dim r
4270 i_img_dim y
4271 PREINIT:
4272 i_color *vals;
4273 i_img_dim count, i;
4274 PPCODE:
4275 21 ▶ if (l < r) {
Branch: 1 branch
BranchTrueFalseTotal
if (l < r) { 21 0 21
4276 21 vals = mymalloc((r-l) * sizeof(i_color));
4277 21 memset(vals, 0, (r-l) * sizeof(i_color));
4278 21 count = i_glin(im, l, r, y, vals);
4279 21 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 17 4 21
4280 17 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 17 0 17
EXTEND(SP, count); 0 17 17
4281 128 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 111 17 128
4282 111 SV *sv = make_i_color_sv_mortal(aTHX_ vals+i);
4283 111 PUSHs(sv);
4284 }
4285 }
4286 4 ▶ else if (count) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count) { 4 0 4
4287 4 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 4 4
4288 4 PUSHs(newSVpvn_flags((void *)vals, count * sizeof(i_color), SVs_TEMP));
4289 }
4290 21 myfree(vals);
4291 }
4292  
4293 void
4294 i_glinf(im, l, r, y)
4295 Imager::ImgRaw im
4296 i_img_dim l
4297 i_img_dim r
4298 i_img_dim y
4299 PREINIT:
4300 i_fcolor *vals;
4301 i_img_dim count, i;
4302 i_fcolor zero;
4303 PPCODE:
4304 110 ▶ for (i = 0; i < MAXCHANNELS; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < MAXCHANNELS; ++i) 88 22 110
4305 88 zero.channel[i] = 0;
4306 22 ▶ if (l < r) {
Branch: 1 branch
BranchTrueFalseTotal
if (l < r) { 22 0 22
4307 22 vals = mymalloc((r-l) * sizeof(i_fcolor));
4308 716 ▶ for (i = 0; i < r-l; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r-l; ++i) 694 22 716
4309 694 vals[i] = zero;
4310 22 count = i_glinf(im, l, r, y, vals);
4311 22 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 19 3 22
4312 19 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 19 0 19
EXTEND(SP, count); 0 19 19
4313 685 ▶ for (i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; ++i) { 666 19 685
4314 666 SV *sv = make_i_fcolor_sv_mortal(aTHX_ vals+i);
4315 666 PUSHs(sv);
4316 }
4317 }
4318 3 ▶ else if (count) {
Branch: 1 branch
BranchTrueFalseTotal
else if (count) { 3 0 3
4319 3 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 3 3
4320 3 PUSHs(newSVpvn_flags((void *)vals, count * sizeof(i_fcolor), SVs_TEMP));
4321 }
4322 22 myfree(vals);
4323 }
4324  
4325 Imager::ImgRaw
4326 i_img_8_new(xsize, ysize, channels)
4327 i_img_dim xsize
4328 i_img_dim ysize
4329 int channels
4330  
4331 Imager::ImgRaw
4332 i_img_16_new(xsize, ysize, channels)
4333 i_img_dim xsize
4334 i_img_dim ysize
4335 int channels
4336  
4337 Imager::ImgRaw
4338 i_img_to_rgb16(im)
4339 Imager::ImgRaw im
4340  
4341 Imager::ImgRaw
4342 i_img_double_new(xsize, ysize, channels)
4343 i_img_dim xsize
4344 i_img_dim ysize
4345 int channels
4346  
4347 Imager::ImgRaw
4348 i_img_to_drgb(im)
4349 Imager::ImgRaw im
4350  
4351 undef_int
4352 i_tags_addn(im, name_sv, code, idata)
4353 Imager::ImgRaw im
4354 SV *name_sv
4355 int code
4356 int idata
4357 PREINIT:
4358 char *name;
4359 STRLEN len;
4360 CODE:
4361 39 ▶ SvGETMAGIC(name_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(name_sv); 0 39 39
SvGETMAGIC(name_sv); 0 0 0
4362 39 ▶ if (SvOK(name_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(name_sv)) 37 2 39
4363 37 name = SvPV_nomg(name_sv, len);
4364 else
4365 2 name = NULL;
4366 39 RETVAL = i_tags_addn(&im->tags, name, code, idata);
4367 OUTPUT:
4368 RETVAL
4369  
4370 undef_int
4371 i_tags_add(im, name_sv, code, data_sv, idata)
4372 Imager::ImgRaw im
4373 SV *name_sv
4374 int code
4375 SV *data_sv
4376 int idata
4377 PREINIT:
4378 char *name;
4379 char *data;
4380 STRLEN len;
4381 CODE:
4382 25 ▶ SvGETMAGIC(name_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(name_sv); 0 25 25
SvGETMAGIC(name_sv); 0 0 0
4383 25 ▶ if (SvOK(name_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(name_sv)) 24 1 25
4384 24 name = SvPV_nomg(name_sv, len);
4385 else
4386 1 name = NULL;
4387 25 ▶ SvGETMAGIC(data_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(data_sv); 0 25 25
SvGETMAGIC(data_sv); 0 0 0
4388 25 ▶ if (SvOK(data_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(data_sv)) 24 1 25
4389 24 data = SvPV(data_sv, len);
4390 else {
4391 1 data = NULL;
4392 1 len = 0;
4393 }
4394 25 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
4395 OUTPUT:
4396 RETVAL
4397  
4398 ImSysRet
4399 i_tags_find(im, name, start)
4400 Imager::ImgRaw im
4401 char *name
4402 int start
4403 PREINIT:
4404 int entry;
4405 CODE:
4406 327 ▶ if (i_tags_find(&im->tags, name, start, &entry)) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_tags_find(&im->tags, name, start, &entry)) { 173 154 327
4407 173 RETVAL = entry;
4408 } else {
4409 154 XSRETURN_UNDEF;
4410 }
4411 OUTPUT:
4412 RETVAL
4413  
4414 ImSysRet
4415 i_tags_findn(im, code, start)
4416 Imager::ImgRaw im
4417 int code
4418 int start
4419 PREINIT:
4420 int entry;
4421 CODE:
4422 4 ▶ if (i_tags_findn(&im->tags, code, start, &entry)) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_tags_findn(&im->tags, code, start, &entry)) { 3 1 4
4423 3 RETVAL = entry;
4424 }
4425 else {
4426 1 XSRETURN_UNDEF;
4427 }
4428 OUTPUT:
4429 RETVAL
4430  
4431 int
4432 i_tags_delete(im, entry)
4433 Imager::ImgRaw im
4434 int entry
4435 CODE:
4436 1 RETVAL = i_tags_delete(&im->tags, entry);
4437 OUTPUT:
4438 RETVAL
4439  
4440 int
4441 i_tags_delbyname(im, name)
4442 Imager::ImgRaw im
4443 char * name
4444 CODE:
4445 41 RETVAL = i_tags_delbyname(&im->tags, name);
4446 OUTPUT:
4447 RETVAL
4448  
4449 int
4450 i_tags_delbycode(im, code)
4451 Imager::ImgRaw im
4452 int code
4453 CODE:
4454 3 RETVAL = i_tags_delbycode(&im->tags, code);
4455 OUTPUT:
4456 RETVAL
4457  
4458 void
4459 i_tags_get(im, index)
4460 Imager::ImgRaw im
4461 int index
4462 PPCODE:
4463 172 ▶ if (index >= 0 && index < im->tags.count) {
Branch: 2 branches
BranchTrueFalseTotal
if (index >= 0 && index < im->tags.count) { 172 0 172
if (index >= 0 && index < im->tags.count) { 172 0 172
4464 172 i_img_tag *entry = im->tags.tags + index;
4465 172 ▶ EXTEND(SP, 5);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 5); 0 172 172
4466
4467 172 ▶ if (entry->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->name) { 170 2 172
4468 170 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
4469 }
4470 else {
4471 2 PUSHs(sv_2mortal(newSViv(entry->code)));
4472 }
4473 172 ▶ if (entry->data) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->data) { 51 121 172
4474 51 PUSHs(newSVpvn_flags(entry->data, entry->size, SVs_TEMP));
4475 }
4476 else {
4477 121 PUSHs(sv_2mortal(newSViv(entry->idata)));
4478 }
4479 }
4480  
4481 void
4482 i_tags_get_string(im, what_sv)
4483 Imager::ImgRaw im
4484 SV *what_sv
4485 PREINIT:
4486 2 char const *name = NULL;
4487 int code;
4488 char buffer[200];
4489 PPCODE:
4490 2 ▶ if (SvIOK(what_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(what_sv)) { 1 1 2
4491 1 code = SvIV(what_sv);
4492 1 name = NULL;
4493 }
4494 else {
4495 1 name = SvPV_nolen(what_sv);
4496 1 code = 0;
4497 }
4498 2 ▶ if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
Branch: 1 branch
BranchTrueFalseTotal
if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) { 2 0 2
4499 2 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2 2
4500 2 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
4501 }
4502  
4503 int
4504 i_tags_count(im)
4505 Imager::ImgRaw im
4506 CODE:
4507 3 ▶ RETVAL = im->tags.count;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = im->tags.count; 0 3 3
4508 OUTPUT:
4509 RETVAL
4510  
4511  
4512  
4513 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
4514  
4515 void
4516 IFILL_DESTROY(fill)
4517 Imager::FillHandle fill
4518  
4519 int
4520 IFILL_CLONE_SKIP(...)
4521 CODE:
4522 (void)items; /* avoid unused warning for XS variable */
4523 0 ▶ RETVAL = 1;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = 1; 0 0 0
4524 OUTPUT:
4525 RETVAL
4526  
4527 MODULE = Imager PACKAGE = Imager
4528  
4529 Imager::FillHandle
4530 i_new_fill_solid(cl, combine)
4531 Imager::Color cl
4532 int combine
4533  
4534 Imager::FillHandle
4535 i_new_fill_solidf(cl, combine)
4536 Imager::Color::Float cl
4537 int combine
4538  
4539 Imager::FillHandle
4540 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4541 Imager::Color fg
4542 Imager::Color bg
4543 int combine
4544 int hatch
4545 SV *cust_hatch_sv
4546 i_img_dim dx
4547 i_img_dim dy
4548 PREINIT:
4549 unsigned char *cust_hatch;
4550 STRLEN len;
4551 CODE:
4552 29 ▶ SvGETMAGIC(cust_hatch_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(cust_hatch_sv); 23 6 29
SvGETMAGIC(cust_hatch_sv); 0 23 23
4553 29 ▶ if (SvOK(cust_hatch_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(cust_hatch_sv)) { 1 28 29
4554 1 cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
4555 }
4556 else
4557 28 cust_hatch = NULL;
4558 29 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
4559 OUTPUT:
4560 RETVAL
4561  
4562 Imager::FillHandle
4563 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4564 Imager::Color::Float fg
4565 Imager::Color::Float bg
4566 int combine
4567 int hatch
4568 SV *cust_hatch_sv
4569 i_img_dim dx
4570 i_img_dim dy
4571 PREINIT:
4572 unsigned char *cust_hatch;
4573 STRLEN len;
4574 CODE:
4575 2 ▶ SvGETMAGIC(cust_hatch_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(cust_hatch_sv); 0 2 2
SvGETMAGIC(cust_hatch_sv); 0 0 0
4576 2 ▶ if (SvOK(cust_hatch_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(cust_hatch_sv)) { 0 2 2
4577 0 cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
4578 }
4579 else
4580 2 cust_hatch = NULL;
4581 2 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
4582 OUTPUT:
4583 RETVAL
4584  
4585 Imager::FillHandle
4586 i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
4587 Imager::ImgRaw src
4588 SV *matrix_sv
4589 i_img_dim xoff
4590 i_img_dim yoff
4591 int combine
4592 PREINIT:
4593 double matrix[9];
4594 double *matrixp;
4595 AV *av;
4596 IV len;
4597 SV *sv1;
4598 int i;
4599 CODE:
4600 9 ▶ SvGETMAGIC(matrix_sv);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(matrix_sv); 8 1 9
SvGETMAGIC(matrix_sv); 0 8 8
4601 9 ▶ if (!SvOK(matrix_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(matrix_sv)) { 8 1 9
4602 8 matrixp = NULL;
4603 }
4604 else {
4605 1 ▶ if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV) 1 0 1
if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV) 0 1 1
4606 0 croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
4607 1 av=(AV*)SvRV(matrix_sv);
4608 1 len=av_len(av)+1;
4609 1 ▶ if (len > 9)
Branch: 1 branch
BranchTrueFalseTotal
if (len > 9) 0 1 1
4610 0 len = 9;
4611 10 ▶ for (i = 0; i < len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; ++i) { 9 1 10
4612 9 sv1=(*(av_fetch(av,i,0)));
4613 9 matrix[i] = SvNV(sv1);
4614 }
4615 1 ▶ for (; i < 9; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (; i < 9; ++i) 0 1 1
4616 0 matrix[i] = 0;
4617 1 matrixp = matrix;
4618 }
4619 9 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
4620 OUTPUT:
4621 RETVAL
4622  
4623 MODULE = Imager PACKAGE = Imager::Internal::Hlines PREFIX=i_int_hlines_
4624  
4625 # this class is only exposed for testing
4626  
4627 int
4628 i_int_hlines_testing()
4629  
4630 #if i_int_hlines_testing()
4631  
4632 Imager::Internal::Hlines
4633 i_int_hlines_new(start_y, count_y, start_x, count_x)
4634 i_img_dim start_y
4635 int count_y
4636 i_img_dim start_x
4637 int count_x
4638  
4639 Imager::Internal::Hlines
4640 i_int_hlines_new_img(im)
4641 Imager::ImgRaw im
4642  
4643 void
4644 i_int_hlines_add(hlines, y, minx, width)
4645 Imager::Internal::Hlines hlines
4646 i_img_dim y
4647 i_img_dim minx
4648 i_img_dim width
4649  
4650 void
4651 i_int_hlines_DESTROY(hlines)
4652 Imager::Internal::Hlines hlines
4653  
4654 SV *
4655 i_int_hlines_dump(hlines)
4656 Imager::Internal::Hlines hlines
4657  
4658 int
4659 i_int_hlines_CLONE_SKIP(cls)
4660  
4661 #endif
4662  
4663 MODULE = Imager PACKAGE = Imager::TrimColorList PREFIX=trim_color_list_
4664  
4665 Imager::TrimColorList
4666 trim_color_list__new(cls)
4667 C_ARGS:
4668  
4669 int
4670 trim_color_list_add_color(Imager::TrimColorList t, Imager::Color c1, Imager::Color c2)
4671  
4672 int
4673 trim_color_list_add_fcolor(Imager::TrimColorList t, Imager::Color::Float c1, Imager::Color::Float c2)
4674  
4675 SV *
4676 trim_color_list_get(Imager::TrimColorList t, IV i)
4677  
4678 IV
4679 trim_color_list_count(Imager::TrimColorList t)
4680  
4681 MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
4682  
4683 void
4684 im_context_DESTROY(ctx)
4685 Imager::Context ctx
4686  
4687 #ifdef PERL_IMPLICIT_CONTEXT
4688  
4689 void
4690 im_context_CLONE(...)
4691 CODE:
4692 MY_CXT_CLONE;
4693 (void)items;
4694 /* the following sv_setref_pv() will free this inc */
4695 im_context_refinc(MY_CXT.ctx, "CLONE");
4696 MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
4697 if (MY_CXT.ctx == NULL) {
4698 croak("Failed to clone Imager context");
4699 }
4700 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
4701  
4702 #endif
4703  
4704 BOOT:
4705 79 PERL_SET_GLOBAL_CALLBACKS;
4706 79 PERL_PL_SET_GLOBAL_CALLBACKS;
4707 #ifdef PERL_IMPLICIT_CONTEXT
4708 {
4709 MY_CXT_INIT;
4710 (void)MY_CXT;
4711 }
4712 #endif
4713 79 start_context(aTHX);
4714 79 im_get_context = perl_get_context;
4715 #ifdef HAVE_LIBTT
4716 i_tt_start();
4717 #endif
4718  
« image.c ↑ Summary regmach.c »