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