avoid dead code in i_tt_glyph_names()
[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
4615ad8d 144#define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color) * (size)))
0aaa8b4d
TC
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
TC
2514 char name[255];
2515 PPCODE:
7e3298ec
TC
2516 i_clear_error();
2517 text = SvPV(text_sv, work_len);
3799c4d1
TC
2518#ifdef SvUTF8
2519 if (SvUTF8(text_sv))
2520 utf8 = 1;
2521#endif
3799c4d1
TC
2522 len = work_len;
2523 while (len) {
17892255 2524 unsigned long ch;
3799c4d1
TC
2525 if (utf8) {
2526 ch = i_utf8_advance(&text, &len);
2527 if (ch == ~0UL) {
2528 i_push_error(0, "invalid UTF8 character");
7e3298ec 2529 XSRETURN_EMPTY;
3799c4d1
TC
2530 }
2531 }
2532 else {
2533 ch = *text++;
2534 --len;
2535 }
ea3099db 2536 EXTEND(SP, 1);
af070d99 2537 if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
ea3099db 2538 PUSHs(sv_2mortal(newSVpv(name, 0)));
3799c4d1
TC
2539 }
2540 else {
ea3099db 2541 PUSHs(&PL_sv_undef);
7e3298ec 2542 }
3799c4d1
TC
2543 }
2544
2545#endif
02d1d628 2546
53a6bbd4 2547const char *
e10bf46e
AMH
2548i_test_format_probe(ig, length)
2549 Imager::IO ig
2550 int length
2551
02d1d628 2552Imager::ImgRaw
d87dc9a4 2553i_readpnm_wiol(ig, allow_incomplete)
02d1d628 2554 Imager::IO ig
d87dc9a4 2555 int allow_incomplete
02d1d628
AMH
2556
2557
2086be61
TC
2558void
2559i_readpnm_multi_wiol(ig, allow_incomplete)
2560 Imager::IO ig
2561 int allow_incomplete
2562 PREINIT:
2563 i_img **imgs;
2564 int count=0;
2565 int i;
2566 PPCODE:
2567 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
2568 if (imgs) {
2569 EXTEND(SP, count);
2570 for (i = 0; i < count; ++i) {
2571 SV *sv = sv_newmortal();
2572 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
2573 PUSHs(sv);
2574 }
2575 myfree(imgs);
2576 }
2577
067d6bdc
AMH
2578undef_int
2579i_writeppm_wiol(im, ig)
2580 Imager::ImgRaw im
2581 Imager::IO ig
2582
2583
2086be61
TC
2584
2585
2586
02d1d628 2587Imager::ImgRaw
895dbd34
AMH
2588i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
2589 Imager::IO ig
8d14daab
TC
2590 i_img_dim x
2591 i_img_dim y
02d1d628
AMH
2592 int datachannels
2593 int storechannels
2594 int intrl
2595
2596undef_int
895dbd34 2597i_writeraw_wiol(im,ig)
02d1d628 2598 Imager::ImgRaw im
895dbd34
AMH
2599 Imager::IO ig
2600
261f91c5
TC
2601undef_int
2602i_writebmp_wiol(im,ig)
2603 Imager::ImgRaw im
2604 Imager::IO ig
02d1d628 2605
705fd961 2606Imager::ImgRaw
d87dc9a4 2607i_readbmp_wiol(ig, allow_incomplete=0)
705fd961 2608 Imager::IO ig
d87dc9a4 2609 int allow_incomplete
705fd961 2610
1ec86afa
AMH
2611
2612undef_int
febba01f 2613i_writetga_wiol(im,ig, wierdpack, compress, idstring)
1ec86afa
AMH
2614 Imager::ImgRaw im
2615 Imager::IO ig
febba01f
AMH
2616 int wierdpack
2617 int compress
2618 char* idstring
2619 PREINIT:
febba01f
AMH
2620 int idlen;
2621 CODE:
2622 idlen = SvCUR(ST(4));
2623 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
2624 OUTPUT:
2625 RETVAL
2626
1ec86afa
AMH
2627
2628Imager::ImgRaw
2629i_readtga_wiol(ig, length)
2630 Imager::IO ig
2631 int length
2632
2633
737a830c
AMH
2634
2635
02d1d628
AMH
2636Imager::ImgRaw
2637i_scaleaxis(im,Value,Axis)
2638 Imager::ImgRaw im
8d14daab 2639 double Value
02d1d628
AMH
2640 int Axis
2641
2642Imager::ImgRaw
2643i_scale_nn(im,scx,scy)
2644 Imager::ImgRaw im
8d14daab
TC
2645 double scx
2646 double scy
02d1d628 2647
658f724e
TC
2648Imager::ImgRaw
2649i_scale_mixing(im, width, height)
2650 Imager::ImgRaw im
8d14daab
TC
2651 i_img_dim width
2652 i_img_dim height
658f724e 2653
02d1d628
AMH
2654Imager::ImgRaw
2655i_haar(im)
2656 Imager::ImgRaw im
2657
2658int
2659i_count_colors(im,maxc)
2660 Imager::ImgRaw im
2661 int maxc
2662
fe622da1 2663void
a60905e4
TC
2664i_get_anonymous_color_histo(im, maxc = 0x40000000)
2665 Imager::ImgRaw im
2666 int maxc
4c99febf 2667 PREINIT:
fe622da1 2668 int i;
a60905e4 2669 unsigned int * col_usage = NULL;
4c99febf
TC
2670 int col_cnt;
2671 PPCODE:
2672 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
6ab89213
TC
2673 if (col_cnt > 0) {
2674 EXTEND(SP, col_cnt);
2675 for (i = 0; i < col_cnt; i++) {
2676 PUSHs(sv_2mortal(newSViv( col_usage[i])));
2677 }
2678 myfree(col_usage);
2679 XSRETURN(col_cnt);
2680 }
2681 else {
2682 XSRETURN_EMPTY;
fe622da1 2683 }
fe622da1 2684
02d1d628 2685
fb9cb3f9 2686void
19e9591b 2687i_transform(im, opx, opy, parm)
02d1d628 2688 Imager::ImgRaw im
19e9591b
TC
2689 int *opx
2690 int *opy
2691 double *parm
02d1d628 2692 PREINIT:
19e9591b 2693 STRLEN size_opx, size_opy, size_parm;
fb9cb3f9
TC
2694 i_img *result;
2695 PPCODE:
19e9591b 2696 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
fb9cb3f9
TC
2697 if (result) {
2698 SV *result_sv = sv_newmortal();
2699 EXTEND(SP, 1);
2700 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2701 PUSHs(result_sv);
2702 }
02d1d628 2703
fb9cb3f9 2704void
e5744e01
TC
2705i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
2706 SV *sv_width
2707 SV *sv_height
2708 SV *sv_ops
2709 AV *av_n_regs
2710 AV *av_c_regs
2711 AV *av_in_imgs
2712 int channels
02d1d628 2713 PREINIT:
8d14daab
TC
2714 i_img_dim width;
2715 i_img_dim height;
02d1d628 2716 struct rm_op *ops;
953209f8 2717 STRLEN ops_len;
02d1d628
AMH
2718 int ops_count;
2719 double *n_regs;
2720 int n_regs_count;
2721 i_color *c_regs;
2722 int c_regs_count;
2723 int in_imgs_count;
2724 i_img **in_imgs;
ea9e6c3f 2725 SV *sv1;
02d1d628
AMH
2726 IV tmp;
2727 int i;
fb9cb3f9
TC
2728 i_img *result;
2729 PPCODE:
e5744e01
TC
2730
2731 in_imgs_count = av_len(av_in_imgs)+1;
2732 for (i = 0; i < in_imgs_count; ++i) {
2733 sv1 = *av_fetch(av_in_imgs, i, 0);
2734 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2735 croak("sv_in_img must contain only images");
02d1d628
AMH
2736 }
2737 }
b8c2033e 2738 if (in_imgs_count > 0) {
02d1d628
AMH
2739 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2740 for (i = 0; i < in_imgs_count; ++i) {
e5744e01 2741 sv1 = *av_fetch(av_in_imgs,i,0);
02d1d628
AMH
2742 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2743 croak("Parameter 5 must contain only images");
2744 }
2745 tmp = SvIV((SV*)SvRV(sv1));
e375fbd8 2746 in_imgs[i] = INT2PTR(i_img*, tmp);
02d1d628
AMH
2747 }
2748 }
2749 else {
2750 /* no input images */
2751 in_imgs = NULL;
2752 }
2753 /* default the output size from the first input if possible */
e5744e01
TC
2754 if (SvOK(sv_width))
2755 width = SvIV(sv_width);
02d1d628
AMH
2756 else if (in_imgs_count)
2757 width = in_imgs[0]->xsize;
2758 else
2759 croak("No output image width supplied");
2760
e5744e01
TC
2761 if (SvOK(sv_height))
2762 height = SvIV(sv_height);
02d1d628
AMH
2763 else if (in_imgs_count)
2764 height = in_imgs[0]->ysize;
2765 else
2766 croak("No output image height supplied");
2767
e5744e01 2768 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
02d1d628
AMH
2769 if (ops_len % sizeof(struct rm_op))
2770 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2771 ops_count = ops_len / sizeof(struct rm_op);
e5744e01
TC
2772
2773 n_regs_count = av_len(av_n_regs)+1;
02d1d628
AMH
2774 n_regs = mymalloc(n_regs_count * sizeof(double));
2775 for (i = 0; i < n_regs_count; ++i) {
e5744e01 2776 sv1 = *av_fetch(av_n_regs,i,0);
02d1d628
AMH
2777 if (SvOK(sv1))
2778 n_regs[i] = SvNV(sv1);
2779 }
e5744e01 2780 c_regs_count = av_len(av_c_regs)+1;
02d1d628
AMH
2781 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2782 /* I don't bother initializing the colou?r registers */
2783
fb9cb3f9 2784 result=i_transform2(width, height, channels, ops, ops_count,
02d1d628
AMH
2785 n_regs, n_regs_count,
2786 c_regs, c_regs_count, in_imgs, in_imgs_count);
2787 if (in_imgs)
2788 myfree(in_imgs);
2789 myfree(n_regs);
2790 myfree(c_regs);
fb9cb3f9
TC
2791 if (result) {
2792 SV *result_sv = sv_newmortal();
2793 EXTEND(SP, 1);
2794 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2795 PUSHs(result_sv);
2796 }
02d1d628
AMH
2797
2798
2799void
2800i_contrast(im,intensity)
2801 Imager::ImgRaw im
2802 float intensity
2803
2804void
2805i_hardinvert(im)
2806 Imager::ImgRaw im
2807
5558f899
TC
2808void
2809i_hardinvertall(im)
2810 Imager::ImgRaw im
2811
02d1d628
AMH
2812void
2813i_noise(im,amount,type)
2814 Imager::ImgRaw im
2815 float amount
2816 unsigned char type
2817
2818void
2819i_bumpmap(im,bump,channel,light_x,light_y,strength)
2820 Imager::ImgRaw im
2821 Imager::ImgRaw bump
2822 int channel
8d14daab
TC
2823 i_img_dim light_x
2824 i_img_dim light_y
2825 i_img_dim strength
02d1d628 2826
b2778574
AMH
2827
2828void
2829i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2830 Imager::ImgRaw im
2831 Imager::ImgRaw bump
2832 int channel
8d14daab
TC
2833 i_img_dim tx
2834 i_img_dim ty
2835 double Lx
2836 double Ly
2837 double Lz
b2778574
AMH
2838 float cd
2839 float cs
2840 float n
2841 Imager::Color Ia
2842 Imager::Color Il
2843 Imager::Color Is
2844
2845
2846
02d1d628
AMH
2847void
2848i_postlevels(im,levels)
2849 Imager::ImgRaw im
2850 int levels
2851
2852void
2853i_mosaic(im,size)
2854 Imager::ImgRaw im
8d14daab 2855 i_img_dim size
02d1d628
AMH
2856
2857void
2858i_watermark(im,wmark,tx,ty,pixdiff)
2859 Imager::ImgRaw im
2860 Imager::ImgRaw wmark
8d14daab
TC
2861 i_img_dim tx
2862 i_img_dim ty
02d1d628
AMH
2863 int pixdiff
2864
2865
2866void
2867i_autolevels(im,lsat,usat,skew)
2868 Imager::ImgRaw im
2869 float lsat
2870 float usat
2871 float skew
2872
ac00f58d
TC
2873void
2874i_autolevels_mono(im,lsat,usat)
2875 Imager::ImgRaw im
2876 float lsat
2877 float usat
2878
02d1d628
AMH
2879void
2880i_radnoise(im,xo,yo,rscale,ascale)
2881 Imager::ImgRaw im
2882 float xo
2883 float yo
2884 float rscale
2885 float ascale
2886
2887void
2888i_turbnoise(im, xo, yo, scale)
2889 Imager::ImgRaw im
2890 float xo
2891 float yo
2892 float scale
2893
2894
2895void
0aaa8b4d 2896i_gradgen(im, xo, yo, ac, dmeasure)
02d1d628 2897 Imager::ImgRaw im
0aaa8b4d
TC
2898 i_img_dim *xo
2899 i_img_dim *yo
2900 i_color *ac
2901 int dmeasure
02d1d628 2902 PREINIT:
0aaa8b4d
TC
2903 STRLEN size_xo;
2904 STRLEN size_yo;
2905 STRLEN size_ac;
02d1d628 2906 CODE:
0aaa8b4d
TC
2907 if (size_xo != size_yo || size_xo != size_ac)
2908 croak("i_gradgen: x, y and color arrays must be the same size");
2909 if (size_xo < 2)
2910 croak("Usage: i_gradgen array refs must have more than 1 entry each");
2911 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
a73aeb5f 2912
dff75dee
TC
2913Imager::ImgRaw
2914i_diff_image(im, im2, mindist=0)
2915 Imager::ImgRaw im
2916 Imager::ImgRaw im2
01b84320 2917 double mindist
02d1d628 2918
e310e5f9 2919undef_int
6607600c
TC
2920i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2921 Imager::ImgRaw im
2922 double xa
2923 double ya
2924 double xb
2925 double yb
2926 int type
2927 int repeat
2928 int combine
2929 int super_sample
2930 double ssample_param
2931 PREINIT:
6607600c 2932 AV *asegs;
6607600c
TC
2933 int count;
2934 i_fountain_seg *segs;
6607600c 2935 CODE:
6607600c
TC
2936 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2937 croak("i_fountain: argument 11 must be an array ref");
2938
2939 asegs = (AV *)SvRV(ST(10));
b13a3ddb 2940 segs = load_fount_segs(aTHX_ asegs, &count);
e310e5f9
TC
2941 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
2942 super_sample, ssample_param, count, segs);
6607600c 2943 myfree(segs);
e310e5f9
TC
2944 OUTPUT:
2945 RETVAL
02d1d628 2946
f1ac5027
TC
2947Imager::FillHandle
2948i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2949 double xa
2950 double ya
2951 double xb
2952 double yb
2953 int type
2954 int repeat
2955 int combine
2956 int super_sample
2957 double ssample_param
2958 PREINIT:
2959 AV *asegs;
2960 int count;
2961 i_fountain_seg *segs;
2962 CODE:
2963 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2964 croak("i_fountain: argument 11 must be an array ref");
2965
2966 asegs = (AV *)SvRV(ST(9));
b13a3ddb 2967 segs = load_fount_segs(aTHX_ asegs, &count);
f1ac5027
TC
2968 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2969 super_sample, ssample_param, count, segs);
2970 myfree(segs);
2971 OUTPUT:
2972 RETVAL
2973
52f2b10a
TC
2974Imager::FillHandle
2975i_new_fill_opacity(other_fill, alpha_mult)
2976 Imager::FillHandle other_fill
2977 double alpha_mult
2978
4f4f776a
TC
2979void
2980i_errors()
2981 PREINIT:
2982 i_errmsg *errors;
2983 int i;
4f4f776a 2984 AV *av;
4f4f776a
TC
2985 SV *sv;
2986 PPCODE:
2987 errors = i_errors();
2988 i = 0;
2989 while (errors[i].msg) {
2990 av = newAV();
2991 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2992 if (!av_store(av, 0, sv)) {
2993 SvREFCNT_dec(sv);
2994 }
2995 sv = newSViv(errors[i].code);
2996 if (!av_store(av, 1, sv)) {
2997 SvREFCNT_dec(sv);
2998 }
57bbbbe7 2999 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
4f4f776a
TC
3000 ++i;
3001 }
02d1d628 3002
2b405c9e
TC
3003void
3004i_clear_error()
3005
3006void
3007i_push_error(code, msg)
3008 int code
3009 const char *msg
3010
e310e5f9 3011undef_int
02d1d628
AMH
3012i_nearest_color(im, ...)
3013 Imager::ImgRaw im
3014 PREINIT:
3015 int num;
8d14daab
TC
3016 i_img_dim *xo;
3017 i_img_dim *yo;
02d1d628
AMH
3018 i_color *ival;
3019 int dmeasure;
3020 int i;
3021 SV *sv;
3022 AV *axx;
3023 AV *ayy;
3024 AV *ac;
3025 CODE:
3026 if (items != 5)
3027 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3028 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3029 croak("i_nearest_color: Second argument must be an array ref");
3030 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
3031 croak("i_nearest_color: Third argument must be an array ref");
3032 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
3033 croak("i_nearest_color: Fourth argument must be an array ref");
3034 axx = (AV *)SvRV(ST(1));
3035 ayy = (AV *)SvRV(ST(2));
3036 ac = (AV *)SvRV(ST(3));
3037 dmeasure = (int)SvIV(ST(4));
3038
3039 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
3040 num = num <= av_len(ac) ? num : av_len(ac);
3041 num++;
3042 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
945dff7f
TC
3043 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3044 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3045 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
02d1d628 3046 for(i = 0; i<num; i++) {
8d14daab
TC
3047 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3048 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
02d1d628
AMH
3049 sv = *av_fetch(ac, i, 0);
3050 if ( !sv_derived_from(sv, "Imager::Color") ) {
3051 free(axx); free(ayy); free(ac);
3052 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3053 }
4c4c2ffd 3054 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
02d1d628 3055 }
e310e5f9
TC
3056 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3057 OUTPUT:
3058 RETVAL
02d1d628
AMH
3059
3060void
3061malloc_state()
3062
02d1d628
AMH
3063void
3064DSO_open(filename)
3065 char* filename
3066 PREINIT:
3067 void *rc;
3068 char *evstr;
3069 PPCODE:
3070 rc=DSO_open(filename,&evstr);
3071 if (rc!=NULL) {
3072 if (evstr!=NULL) {
3073 EXTEND(SP,2);
e375fbd8 3074 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
02d1d628
AMH
3075 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
3076 } else {
3077 EXTEND(SP,1);
e375fbd8 3078 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
02d1d628
AMH
3079 }
3080 }
3081
3082
3083undef_int
3084DSO_close(dso_handle)
3085 void* dso_handle
3086
3087void
3088DSO_funclist(dso_handle_v)
3089 void* dso_handle_v
3090 PREINIT:
3091 int i;
3092 DSO_handle *dso_handle;
d8e0c3ba 3093 func_ptr *functions;
02d1d628
AMH
3094 PPCODE:
3095 dso_handle=(DSO_handle*)dso_handle_v;
d8e0c3ba 3096 functions = DSO_funclist(dso_handle);
02d1d628 3097 i=0;
d8e0c3ba 3098 while( functions[i].name != NULL) {
02d1d628 3099 EXTEND(SP,1);
d8e0c3ba 3100 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
02d1d628 3101 EXTEND(SP,1);
d8e0c3ba 3102 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
02d1d628
AMH
3103 }
3104
02d1d628
AMH
3105void
3106DSO_call(handle,func_index,hv)
3107 void* handle
3108 int func_index
75cebca8 3109 HV *hv
02d1d628 3110 PPCODE:
02d1d628
AMH
3111 DSO_call( (DSO_handle *)handle,func_index,hv);
3112
befd4be1 3113Imager::Color
f5991c03
TC
3114i_get_pixel(im, x, y)
3115 Imager::ImgRaw im
8d14daab
TC
3116 i_img_dim x
3117 i_img_dim y;
faa9b3e7 3118 CODE:
befd4be1 3119 RETVAL = (i_color *)mymalloc(sizeof(i_color));
2ea4aa42 3120 memset(RETVAL, 0, sizeof(*RETVAL));
befd4be1
TC
3121 if (i_gpix(im, x, y, RETVAL) != 0) {
3122 myfree(RETVAL);
3123 XSRETURN_UNDEF;
faa9b3e7 3124 }
a659442a
TC
3125 OUTPUT:
3126 RETVAL
faa9b3e7
TC
3127
3128
3129int
3130i_ppix(im, x, y, cl)
3131 Imager::ImgRaw im
8d14daab
TC
3132 i_img_dim x
3133 i_img_dim y
faa9b3e7
TC
3134 Imager::Color cl
3135
3136Imager::ImgRaw
3137i_img_pal_new(x, y, channels, maxpal)
8d14daab
TC
3138 i_img_dim x
3139 i_img_dim y
faa9b3e7
TC
3140 int channels
3141 int maxpal
3142
3143Imager::ImgRaw
3144i_img_to_pal(src, quant)
3145 Imager::ImgRaw src
3146 PREINIT:
3147 HV *hv;
3148 i_quantize quant;
3149 CODE:
3150 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3151 croak("i_img_to_pal: second argument must be a hash ref");
3152 hv = (HV *)SvRV(ST(1));
3153 memset(&quant, 0, sizeof(quant));
ec6d8908 3154 quant.version = 1;
faa9b3e7 3155 quant.mc_size = 256;
ec6d8908 3156 ip_handle_quant_opts(aTHX_ &quant, hv);
faa9b3e7
TC
3157 RETVAL = i_img_to_pal(src, &quant);
3158 if (RETVAL) {
ec6d8908 3159 ip_copy_colors_back(aTHX_ hv, &quant);
faa9b3e7 3160 }
ec6d8908 3161 ip_cleanup_quant_opts(aTHX_ &quant);
faa9b3e7
TC
3162 OUTPUT:
3163 RETVAL
3164
3165Imager::ImgRaw
3166i_img_to_rgb(src)
3167 Imager::ImgRaw src
3168
5e9a7fbd
TC
3169void
3170i_img_make_palette(HV *quant_hv, ...)
3171 PREINIT:
3172 size_t count = items - 1;
3173 i_quantize quant;
3174 i_img **imgs = NULL;
3175 ssize_t i;
3176 PPCODE:
3177 if (count <= 0)
3178 croak("Please supply at least one image (%d)", (int)count);
3179 imgs = mymalloc(sizeof(i_img *) * count);
3180 for (i = 0; i < count; ++i) {
3181 SV *img_sv = ST(i + 1);
3182 if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
3183 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3184 }
3185 else {
3186 myfree(imgs);
ec2f6280 3187 croak("Image %d is not an image object", (int)i+1);
5e9a7fbd
TC
3188 }
3189 }
3190 memset(&quant, 0, sizeof(quant));
3191 quant.version = 1;
3192 quant.mc_size = 256;
3193 ip_handle_quant_opts(aTHX_ &quant, quant_hv);
3194 i_quant_makemap(&quant, imgs, count);
3195 EXTEND(SP, quant.mc_count);
3196 for (i = 0; i < quant.mc_count; ++i) {
3197 SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i);
3198 PUSHs(sv_c);
3199 }
3200 ip_cleanup_quant_opts(aTHX_ &quant);
e906e86a 3201 myfree(imgs);
5e9a7fbd
TC
3202
3203
faa9b3e7
TC
3204void
3205i_gpal(im, l, r, y)
3206 Imager::ImgRaw im
8d14daab
TC
3207 i_img_dim l
3208 i_img_dim r
3209 i_img_dim y
faa9b3e7
TC
3210 PREINIT:
3211 i_palidx *work;
3212 int count, i;
3213 PPCODE:
3214 if (l < r) {
3215 work = mymalloc((r-l) * sizeof(i_palidx));
3216 count = i_gpal(im, l, r, y, work);
3217 if (GIMME_V == G_ARRAY) {
3218 EXTEND(SP, count);
3219 for (i = 0; i < count; ++i) {
3220 PUSHs(sv_2mortal(newSViv(work[i])));
3221 }
3222 }
3223 else {
3224 EXTEND(SP, 1);
26fd367b 3225 PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx))));
faa9b3e7
TC
3226 }
3227 myfree(work);
3228 }
3229 else {
3230 if (GIMME_V != G_ARRAY) {
3231 EXTEND(SP, 1);
3232 PUSHs(&PL_sv_undef);
3233 }
3234 }
3235
3236int
3237i_ppal(im, l, y, ...)
3238 Imager::ImgRaw im
8d14daab
TC
3239 i_img_dim l
3240 i_img_dim y
faa9b3e7
TC
3241 PREINIT:
3242 i_palidx *work;
ebe9b189 3243 i_img_dim i;
faa9b3e7
TC
3244 CODE:
3245 if (items > 3) {
ebe9b189 3246 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
faa9b3e7
TC
3247 for (i=0; i < items-3; ++i) {
3248 work[i] = SvIV(ST(i+3));
3249 }
4cda4e76 3250 validate_i_ppal(im, work, items - 3);
faa9b3e7 3251 RETVAL = i_ppal(im, l, l+items-3, y, work);
faa9b3e7
TC
3252 }
3253 else {
3254 RETVAL = 0;
3255 }
3256 OUTPUT:
3257 RETVAL
3258
4cda4e76
TC
3259int
3260i_ppal_p(im, l, y, data)
3261 Imager::ImgRaw im
8d14daab
TC
3262 i_img_dim l
3263 i_img_dim y
4cda4e76
TC
3264 SV *data
3265 PREINIT:
3266 i_palidx const *work;
4cda4e76 3267 STRLEN len;
4cda4e76
TC
3268 CODE:
3269 work = (i_palidx const *)SvPV(data, len);
3270 len /= sizeof(i_palidx);
3271 if (len > 0) {
3272 validate_i_ppal(im, work, len);
3273 RETVAL = i_ppal(im, l, l+len, y, work);
3274 }
3275 else {
3276 RETVAL = 0;
3277 }
3278 OUTPUT:
3279 RETVAL
3280
42505e61 3281SysRet
faa9b3e7
TC
3282i_addcolors(im, ...)
3283 Imager::ImgRaw im
3284 PREINIT:
faa9b3e7
TC
3285 i_color *colors;
3286 int i;
3287 CODE:
3288 if (items < 2)
3289 croak("i_addcolors: no colors to add");
3290 colors = mymalloc((items-1) * sizeof(i_color));
3291 for (i=0; i < items-1; ++i) {
3292 if (sv_isobject(ST(i+1))
3293 && sv_derived_from(ST(i+1), "Imager::Color")) {
3294 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
4c4c2ffd 3295 colors[i] = *INT2PTR(i_color *, tmp);
faa9b3e7
TC
3296 }
3297 else {
3298 myfree(colors);
ca4d914e 3299 croak("i_addcolor: pixels must be Imager::Color objects");
faa9b3e7
TC
3300 }
3301 }
42505e61 3302 RETVAL = i_addcolors(im, colors, items-1);
7d5febef 3303 myfree(colors);
a659442a
TC
3304 OUTPUT:
3305 RETVAL
faa9b3e7 3306
1501d9b3 3307undef_int
faa9b3e7
TC
3308i_setcolors(im, index, ...)
3309 Imager::ImgRaw im
3310 int index
3311 PREINIT:
3312 i_color *colors;
3313 int i;
3314 CODE:
3315 if (items < 3)
3316 croak("i_setcolors: no colors to add");
3317 colors = mymalloc((items-2) * sizeof(i_color));
3318 for (i=0; i < items-2; ++i) {
3319 if (sv_isobject(ST(i+2))
3320 && sv_derived_from(ST(i+2), "Imager::Color")) {
3321 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
4c4c2ffd 3322 colors[i] = *INT2PTR(i_color *, tmp);
faa9b3e7
TC
3323 }
3324 else {
3325 myfree(colors);
3326 croak("i_setcolors: pixels must be Imager::Color objects");
3327 }
3328 }
3329 RETVAL = i_setcolors(im, index, colors, items-2);
3330 myfree(colors);
1501d9b3
TC
3331 OUTPUT:
3332 RETVAL
faa9b3e7
TC
3333
3334void
1592522f 3335i_getcolors(im, index, count=1)
faa9b3e7
TC
3336 Imager::ImgRaw im
3337 int index
1592522f 3338 int count
faa9b3e7
TC
3339 PREINIT:
3340 i_color *colors;
faa9b3e7
TC
3341 int i;
3342 PPCODE:
faa9b3e7
TC
3343 if (count < 1)
3344 croak("i_getcolors: count must be positive");
1592522f 3345 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
faa9b3e7 3346 if (i_getcolors(im, index, colors, count)) {
1592522f 3347 EXTEND(SP, count);
faa9b3e7 3348 for (i = 0; i < count; ++i) {
5e9a7fbd 3349 SV *sv = make_i_color_sv(aTHX_ colors+i);
faa9b3e7
TC
3350 PUSHs(sv);
3351 }
3352 }
faa9b3e7 3353
a659442a 3354undef_neg_int
faa9b3e7
TC
3355i_colorcount(im)
3356 Imager::ImgRaw im
faa9b3e7 3357
a659442a 3358undef_neg_int
faa9b3e7
TC
3359i_maxcolors(im)
3360 Imager::ImgRaw im
faa9b3e7 3361
0862f397 3362i_palidx
faa9b3e7
TC
3363i_findcolor(im, color)
3364 Imager::ImgRaw im
3365 Imager::Color color
faa9b3e7 3366 CODE:
0862f397
TC
3367 if (!i_findcolor(im, color, &RETVAL)) {
3368 XSRETURN_UNDEF;
faa9b3e7 3369 }
a659442a
TC
3370 OUTPUT:
3371 RETVAL
faa9b3e7
TC
3372
3373int
3374i_img_bits(im)
3375 Imager::ImgRaw im
3376
3377int
3378i_img_type(im)
3379 Imager::ImgRaw im
3380
3381int
3382i_img_virtual(im)
3383 Imager::ImgRaw im
3384
3385void
6a9807e8 3386i_gsamp(im, l, r, y, channels)
faa9b3e7 3387 Imager::ImgRaw im
8d14daab
TC
3388 i_img_dim l
3389 i_img_dim r
3390 i_img_dim y
6a9807e8 3391 i_channel_list channels
faa9b3e7 3392 PREINIT:
faa9b3e7 3393 i_sample_t *data;
8d14daab 3394 i_img_dim count, i;
faa9b3e7 3395 PPCODE:
faa9b3e7 3396 if (l < r) {
f37708ce 3397 data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
6a9807e8 3398 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
faa9b3e7
TC
3399 if (GIMME_V == G_ARRAY) {
3400 EXTEND(SP, count);
3401 for (i = 0; i < count; ++i)
3402 PUSHs(sv_2mortal(newSViv(data[i])));
3403 }
3404 else {
3405 EXTEND(SP, 1);
26fd367b 3406 PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t))));
faa9b3e7 3407 }
a73aeb5f 3408 myfree(data);
faa9b3e7
TC
3409 }
3410 else {
3411 if (GIMME_V != G_ARRAY) {
f37708ce 3412 XSRETURN_UNDEF;
faa9b3e7
TC
3413 }
3414 }
3415
bd8052a6 3416undef_neg_int
6a9807e8 3417i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
bd8052a6 3418 Imager::ImgRaw im
8d14daab
TC
3419 i_img_dim l
3420 i_img_dim r
3421 i_img_dim y
bd8052a6
TC
3422 int bits
3423 AV *target
8d14daab 3424 STRLEN offset
6a9807e8 3425 i_channel_list channels
bd8052a6 3426 PREINIT:
bd8052a6 3427 unsigned *data;
8d14daab 3428 i_img_dim count, i;
bd8052a6
TC
3429 CODE:
3430 i_clear_error();
3431 if (items < 8)
3432 croak("No channel numbers supplied to g_samp()");
3433 if (l < r) {
6a9807e8
TC
3434 data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
3435 count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
bd8052a6
TC
3436 for (i = 0; i < count; ++i) {
3437 av_store(target, i+offset, newSVuv(data[i]));
3438 }
3439 myfree(data);
3440 RETVAL = count;
3441 }
3442 else {
3443 RETVAL = 0;
3444 }
3445 OUTPUT:
3446 RETVAL
3447
3448undef_neg_int
6a9807e8 3449i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
bd8052a6 3450 Imager::ImgRaw im
8d14daab
TC
3451 i_img_dim l
3452 i_img_dim y
bd8052a6 3453 int bits
6a9807e8 3454 i_channel_list channels
bd8052a6 3455 AV *data_av
848b7f32
TC
3456 i_img_dim data_offset
3457 i_img_dim pixel_count
bd8052a6 3458 PREINIT:
8d14daab
TC
3459 STRLEN data_count;
3460 size_t data_used;
bd8052a6 3461 unsigned *data;
8d14daab 3462 ptrdiff_t i;
bd8052a6
TC
3463 CODE:
3464 i_clear_error();
bd8052a6
TC
3465
3466 data_count = av_len(data_av) + 1;
3467 if (data_offset < 0) {
848b7f32 3468 croak("data_offset must be non-negative");
bd8052a6
TC
3469 }
3470 if (data_offset > data_count) {
3471 croak("data_offset greater than number of samples supplied");
3472 }
3473 if (pixel_count == -1 ||
6a9807e8
TC
3474 data_offset + pixel_count * channels.count > data_count) {
3475 pixel_count = (data_count - data_offset) / channels.count;
bd8052a6
TC
3476 }
3477
6a9807e8 3478 data_used = pixel_count * channels.count;
bd8052a6
TC
3479 data = mymalloc(sizeof(unsigned) * data_count);
3480 for (i = 0; i < data_used; ++i)
3481 data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
3482
6a9807e8
TC
3483 RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
3484 channels.count, bits);
bd8052a6
TC
3485
3486 if (data)
3487 myfree(data);
bd8052a6
TC
3488 OUTPUT:
3489 RETVAL
a73aeb5f 3490
48b9a7bf 3491undef_neg_int
848b7f32 3492i_psamp(im, x, y, channels, data, offset = 0, width = -1)
48b9a7bf
TC
3493 Imager::ImgRaw im
3494 i_img_dim x
3495 i_img_dim y
3496 i_channel_list channels
3497 i_sample_list data
848b7f32
TC
3498 i_img_dim offset
3499 i_img_dim width
48b9a7bf
TC
3500 PREINIT:
3501 i_img_dim r;
3502 CODE:
48b9a7bf 3503 i_clear_error();
848b7f32
TC
3504 if (offset < 0) {
3505 i_push_error(0, "offset must be non-negative");
3506 XSRETURN_UNDEF;
3507 }
3508 if (offset > 0) {
3509 if (offset > data.count) {
3510 i_push_error(0, "offset greater than number of samples supplied");
3511 XSRETURN_UNDEF;
3512 }
3513 data.samples += offset;
3514 data.count -= offset;
3515 }
3516 if (width == -1 ||
3517 width * channels.count > data.count) {
3518 width = data.count / channels.count;
3519 }
3520 r = x + width;
48b9a7bf
TC
3521 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
3522 OUTPUT:
3523 RETVAL
3524
3525undef_neg_int
848b7f32 3526i_psampf(im, x, y, channels, data, offset = 0, width = -1)
48b9a7bf
TC
3527 Imager::ImgRaw im
3528 i_img_dim x
3529 i_img_dim y
3530 i_channel_list channels
3531 i_fsample_list data
848b7f32
TC
3532 i_img_dim offset
3533 i_img_dim width
48b9a7bf
TC
3534 PREINIT:
3535 i_img_dim r;
3536 CODE:
48b9a7bf 3537 i_clear_error();
848b7f32
TC
3538 if (offset < 0) {
3539 i_push_error(0, "offset must be non-negative");
3540 XSRETURN_UNDEF;
3541 }
3542 if (offset > 0) {
3543 if (offset > data.count) {
3544 i_push_error(0, "offset greater than number of samples supplied");
3545 XSRETURN_UNDEF;
3546 }
3547 data.samples += offset;
3548 data.count -= offset;
3549 }
3550 if (width == -1 ||
3551 width * channels.count > data.count) {
3552 width = data.count / channels.count;
3553 }
3554 r = x + width;
48b9a7bf
TC
3555 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
3556 OUTPUT:
3557 RETVAL
3558
faa9b3e7
TC
3559Imager::ImgRaw
3560i_img_masked_new(targ, mask, x, y, w, h)
3561 Imager::ImgRaw targ
8d14daab
TC
3562 i_img_dim x
3563 i_img_dim y
3564 i_img_dim w
3565 i_img_dim h
faa9b3e7
TC
3566 PREINIT:
3567 i_img *mask;
3568 CODE:
3569 if (SvOK(ST(1))) {
3570 if (!sv_isobject(ST(1))
3571 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
3572 croak("i_img_masked_new: parameter 2 must undef or an image");
3573 }
4c4c2ffd 3574 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
faa9b3e7
TC
3575 }
3576 else
3577 mask = NULL;
3578 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
3579 OUTPUT:
3580 RETVAL
3581
3582int
3583i_plin(im, l, y, ...)
3584 Imager::ImgRaw im
8d14daab
TC
3585 i_img_dim l
3586 i_img_dim y
faa9b3e7
TC
3587 PREINIT:
3588 i_color *work;
8d14daab 3589 STRLEN i;
ca4d914e 3590 STRLEN len;
8d14daab 3591 size_t count;
faa9b3e7
TC
3592 CODE:
3593 if (items > 3) {
ca4d914e
TC
3594 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3595 /* supplied as a byte string */
3596 work = (i_color *)SvPV(ST(3), len);
3597 count = len / sizeof(i_color);
3598 if (count * sizeof(i_color) != len) {
3599 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
faa9b3e7 3600 }
ca4d914e
TC
3601 RETVAL = i_plin(im, l, l+count, y, work);
3602 }
3603 else {
3604 work = mymalloc(sizeof(i_color) * (items-3));
3605 for (i=0; i < items-3; ++i) {
3606 if (sv_isobject(ST(i+3))
3607 && sv_derived_from(ST(i+3), "Imager::Color")) {
3608 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3609 work[i] = *INT2PTR(i_color *, tmp);
3610 }
3611 else {
3612 myfree(work);
3613 croak("i_plin: pixels must be Imager::Color objects");
3614 }
faa9b3e7 3615 }
ca4d914e
TC
3616 RETVAL = i_plin(im, l, l+items-3, y, work);
3617 myfree(work);
faa9b3e7 3618 }
faa9b3e7
TC
3619 }
3620 else {
3621 RETVAL = 0;
3622 }
3623 OUTPUT:
3624 RETVAL
3625
3626int
3627i_ppixf(im, x, y, cl)
3628 Imager::ImgRaw im
8d14daab
TC
3629 i_img_dim x
3630 i_img_dim y
faa9b3e7
TC
3631 Imager::Color::Float cl
3632
3633void
6a9807e8 3634i_gsampf(im, l, r, y, channels)
faa9b3e7 3635 Imager::ImgRaw im
8d14daab
TC
3636 i_img_dim l
3637 i_img_dim r
3638 i_img_dim y
6a9807e8 3639 i_channel_list channels
faa9b3e7 3640 PREINIT:
faa9b3e7 3641 i_fsample_t *data;
8d14daab 3642 i_img_dim count, i;
faa9b3e7 3643 PPCODE:
faa9b3e7 3644 if (l < r) {
6a9807e8
TC
3645 data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
3646 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
faa9b3e7
TC
3647 if (GIMME_V == G_ARRAY) {
3648 EXTEND(SP, count);
3649 for (i = 0; i < count; ++i)
3650 PUSHs(sv_2mortal(newSVnv(data[i])));
3651 }
3652 else {
3653 EXTEND(SP, 1);
3654 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
3655 }
3631271b 3656 myfree(data);
faa9b3e7
TC
3657 }
3658 else {
3659 if (GIMME_V != G_ARRAY) {
5736f588 3660 XSRETURN_UNDEF;
faa9b3e7
TC
3661 }
3662 }
3663
3664int
3665i_plinf(im, l, y, ...)
3666 Imager::ImgRaw im
8d14daab
TC
3667 i_img_dim l
3668 i_img_dim y
faa9b3e7
TC
3669 PREINIT:
3670 i_fcolor *work;
8d14daab 3671 i_img_dim i;
ca4d914e 3672 STRLEN len;
8d14daab 3673 size_t count;
faa9b3e7
TC
3674 CODE:
3675 if (items > 3) {
ca4d914e
TC
3676 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3677 /* supplied as a byte string */
3678 work = (i_fcolor *)SvPV(ST(3), len);
3679 count = len / sizeof(i_fcolor);
3680 if (count * sizeof(i_fcolor) != len) {
3681 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
faa9b3e7 3682 }
ca4d914e
TC
3683 RETVAL = i_plinf(im, l, l+count, y, work);
3684 }
3685 else {
3686 work = mymalloc(sizeof(i_fcolor) * (items-3));
3687 for (i=0; i < items-3; ++i) {
3688 if (sv_isobject(ST(i+3))
3689 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
3690 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3691 work[i] = *INT2PTR(i_fcolor *, tmp);
3692 }
3693 else {
3694 myfree(work);
3695 croak("i_plinf: pixels must be Imager::Color::Float objects");
3696 }
faa9b3e7 3697 }
ca4d914e
TC
3698 /**(char *)0 = 1;*/
3699 RETVAL = i_plinf(im, l, l+items-3, y, work);
3700 myfree(work);
faa9b3e7 3701 }
faa9b3e7
TC
3702 }
3703 else {
3704 RETVAL = 0;
3705 }
3706 OUTPUT:
3707 RETVAL
3708
73d80423 3709Imager::Color::Float
faa9b3e7
TC
3710i_gpixf(im, x, y)
3711 Imager::ImgRaw im
8d14daab
TC
3712 i_img_dim x
3713 i_img_dim y;
faa9b3e7 3714 CODE:
73d80423 3715 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2ea4aa42 3716 memset(RETVAL, 0, sizeof(*RETVAL));
73d80423
TC
3717 if (i_gpixf(im, x, y, RETVAL) != 0) {
3718 myfree(RETVAL);
3719 XSRETURN_UNDEF;
faa9b3e7 3720 }
a659442a
TC
3721 OUTPUT:
3722 RETVAL
3723
faa9b3e7
TC
3724void
3725i_glin(im, l, r, y)
3726 Imager::ImgRaw im
8d14daab
TC
3727 i_img_dim l
3728 i_img_dim r
3729 i_img_dim y
faa9b3e7
TC
3730 PREINIT:
3731 i_color *vals;
8d14daab 3732 i_img_dim count, i;
faa9b3e7
TC
3733 PPCODE:
3734 if (l < r) {
3735 vals = mymalloc((r-l) * sizeof(i_color));
b3aa972f 3736 memset(vals, 0, (r-l) * sizeof(i_color));
faa9b3e7 3737 count = i_glin(im, l, r, y, vals);
ca4d914e
TC
3738 if (GIMME_V == G_ARRAY) {
3739 EXTEND(SP, count);
3740 for (i = 0; i < count; ++i) {
5e9a7fbd 3741 SV *sv = make_i_color_sv(aTHX_ vals+i);
ca4d914e
TC
3742 PUSHs(sv);
3743 }
3744 }
3745 else if (count) {
3746 EXTEND(SP, 1);
3747 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color))));
faa9b3e7
TC
3748 }
3749 myfree(vals);
3750 }
3751
3752void
3753i_glinf(im, l, r, y)
3754 Imager::ImgRaw im
8d14daab
TC
3755 i_img_dim l
3756 i_img_dim r
3757 i_img_dim y
faa9b3e7
TC
3758 PREINIT:
3759 i_fcolor *vals;
8d14daab 3760 i_img_dim count, i;
919e0000 3761 i_fcolor zero;
faa9b3e7 3762 PPCODE:
919e0000
TC
3763 for (i = 0; i < MAXCHANNELS; ++i)
3764 zero.channel[i] = 0;
faa9b3e7
TC
3765 if (l < r) {
3766 vals = mymalloc((r-l) * sizeof(i_fcolor));
b3aa972f
TC
3767 for (i = 0; i < r-l; ++i)
3768 vals[i] = zero;
faa9b3e7 3769 count = i_glinf(im, l, r, y, vals);
ca4d914e
TC
3770 if (GIMME_V == G_ARRAY) {
3771 EXTEND(SP, count);
3772 for (i = 0; i < count; ++i) {
3773 SV *sv;
3774 i_fcolor *col = mymalloc(sizeof(i_fcolor));
3775 *col = vals[i];
3776 sv = sv_newmortal();
3777 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
3778 PUSHs(sv);
3779 }
3780 }
3781 else if (count) {
3782 EXTEND(SP, 1);
3783 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor))));
faa9b3e7
TC
3784 }
3785 myfree(vals);
3786 }
3787
bdd4c63b
TC
3788Imager::ImgRaw
3789i_img_8_new(x, y, ch)
3790 i_img_dim x
3791 i_img_dim y
3792 int ch
3793
faa9b3e7
TC
3794Imager::ImgRaw
3795i_img_16_new(x, y, ch)
8d14daab
TC
3796 i_img_dim x
3797 i_img_dim y
faa9b3e7
TC
3798 int ch
3799
167660cd
TC
3800Imager::ImgRaw
3801i_img_to_rgb16(im)
3802 Imager::ImgRaw im
3803
365ea842
TC
3804Imager::ImgRaw
3805i_img_double_new(x, y, ch)
8d14daab
TC
3806 i_img_dim x
3807 i_img_dim y
365ea842
TC
3808 int ch
3809
bfe6ba3f
TC
3810Imager::ImgRaw
3811i_img_to_drgb(im)
3812 Imager::ImgRaw im
3813
faa9b3e7 3814undef_int
b9e2571f 3815i_tags_addn(im, name_sv, code, idata)
faa9b3e7 3816 Imager::ImgRaw im
b9e2571f 3817 SV *name_sv
faa9b3e7
TC
3818 int code
3819 int idata
3820 PREINIT:
3821 char *name;
3822 STRLEN len;
3823 CODE:
b9e2571f
TC
3824 SvGETMAGIC(name_sv);
3825 if (SvOK(name_sv))
3826 name = SvPV_nomg(name_sv, len);
faa9b3e7
TC
3827 else
3828 name = NULL;
3829 RETVAL = i_tags_addn(&im->tags, name, code, idata);
3830 OUTPUT:
3831 RETVAL
3832
3833undef_int
a4da28d7 3834i_tags_add(im, name_sv, code, data_sv, idata)
faa9b3e7 3835 Imager::ImgRaw im
a4da28d7 3836 SV *name_sv
faa9b3e7 3837 int code
a4da28d7 3838 SV *data_sv
faa9b3e7
TC
3839 int idata
3840 PREINIT:
3841 char *name;
3842 char *data;
3843 STRLEN len;
3844 CODE:
a4da28d7
TC
3845 SvGETMAGIC(name_sv);
3846 if (SvOK(name_sv))
3847 name = SvPV_nomg(name_sv, len);
faa9b3e7
TC
3848 else
3849 name = NULL;
a4da28d7
TC
3850 SvGETMAGIC(data_sv);
3851 if (SvOK(data_sv))
3852 data = SvPV(data_sv, len);
faa9b3e7
TC
3853 else {
3854 data = NULL;
3855 len = 0;
3856 }
3857 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
3858 OUTPUT:
3859 RETVAL
3860
f4aca831 3861SysRet
faa9b3e7
TC
3862i_tags_find(im, name, start)
3863 Imager::ImgRaw im
3864 char *name
3865 int start
3866 PREINIT:
3867 int entry;
3868 CODE:
3869 if (i_tags_find(&im->tags, name, start, &entry)) {
f4aca831 3870 RETVAL = entry;
faa9b3e7 3871 } else {
f4aca831 3872 XSRETURN_UNDEF;
faa9b3e7 3873 }
a659442a
TC
3874 OUTPUT:
3875 RETVAL
faa9b3e7 3876
f4aca831 3877SysRet
faa9b3e7
TC
3878i_tags_findn(im, code, start)
3879 Imager::ImgRaw im
3880 int code
3881 int start
3882 PREINIT:
3883 int entry;
3884 CODE:
3885 if (i_tags_findn(&im->tags, code, start, &entry)) {
f4aca831 3886 RETVAL = entry;
faa9b3e7 3887 }
a659442a 3888 else {
f4aca831 3889 XSRETURN_UNDEF;
a659442a
TC
3890 }
3891 OUTPUT:
3892 RETVAL
faa9b3e7
TC
3893
3894int
3895i_tags_delete(im, entry)
3896 Imager::ImgRaw im
3897 int entry
3898 CODE:
3899 RETVAL = i_tags_delete(&im->tags, entry);
3900 OUTPUT:
3901 RETVAL
3902
3903int
3904i_tags_delbyname(im, name)
3905 Imager::ImgRaw im
3906 char * name
3907 CODE:
3908 RETVAL = i_tags_delbyname(&im->tags, name);
3909 OUTPUT:
3910 RETVAL
3911
3912int
3913i_tags_delbycode(im, code)
3914 Imager::ImgRaw im
3915 int code
3916 CODE:
3917 RETVAL = i_tags_delbycode(&im->tags, code);
3918 OUTPUT:
3919 RETVAL
3920
3921void
3922i_tags_get(im, index)
3923 Imager::ImgRaw im
3924 int index
3925 PPCODE:
3926 if (index >= 0 && index < im->tags.count) {
3927 i_img_tag *entry = im->tags.tags + index;
3928 EXTEND(SP, 5);
3929
3930 if (entry->name) {
3931 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
3932 }
3933 else {
3934 PUSHs(sv_2mortal(newSViv(entry->code)));
3935 }
3936 if (entry->data) {
3937 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
3938 }
3939 else {
3940 PUSHs(sv_2mortal(newSViv(entry->idata)));
3941 }
3942 }
3943
241defe8
TC
3944void
3945i_tags_get_string(im, what_sv)
3946 Imager::ImgRaw im
3947 SV *what_sv
3948 PREINIT:
3949 char const *name = NULL;
3950 int code;
3951 char buffer[200];
241defe8
TC
3952 PPCODE:
3953 if (SvIOK(what_sv)) {
3954 code = SvIV(what_sv);
3955 name = NULL;
3956 }
3957 else {
3958 name = SvPV_nolen(what_sv);
3959 code = 0;
3960 }
3961 if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
3962 EXTEND(SP, 1);
3963 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
3964 }</