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