Cleaned up io.h, io.c which had functions not used any more, removed unused
[imager.git] / Imager.xs
CommitLineData
02d1d628
AMH
1#ifdef __cplusplus
2extern "C" {
3#endif
4#include "EXTERN.h"
5#include "perl.h"
6#include "XSUB.h"
7#include "ppport.h"
8#ifdef __cplusplus
9
10#endif
11
12#include "image.h"
13#include "feat.h"
14#include "dynaload.h"
15#include "regmach.h"
16
17typedef io_glue* Imager__IO;
18typedef i_color* Imager__Color;
faa9b3e7 19typedef i_fcolor* Imager__Color__Float;
02d1d628
AMH
20typedef i_img* Imager__ImgRaw;
21
22
23#ifdef HAVE_LIBTT
24typedef TT_Fonthandle* Imager__TTHandle;
25#endif
26
faa9b3e7
TC
27#ifdef HAVE_FT2
28typedef FT2_Fonthandle* Imager__Font__FT2;
29#endif
30
02d1d628
AMH
31typedef struct i_reader_data_tag
32{
33 /* presumably a CODE ref or name of a sub */
34 SV *sv;
35} i_reader_data;
36
37/* used by functions that want callbacks */
38static int read_callback(char *userdata, char *buffer, int need, int want) {
39 i_reader_data *rd = (i_reader_data *)userdata;
40 int count;
41 int result;
42 SV *data;
43 dSP; dTARG = sv_newmortal();
44 /* thanks to Simon Cozens for help with the dTARG above */
45
46 ENTER;
47 SAVETMPS;
48 EXTEND(SP, 2);
49 PUSHMARK(SP);
50 PUSHi(want);
51 PUSHi(need);
52 PUTBACK;
53
54 count = perl_call_sv(rd->sv, G_SCALAR);
55
56 SPAGAIN;
57
58 if (count != 1)
59 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
60
61 data = POPs;
62
63 if (SvOK(data)) {
64 STRLEN len;
65 char *ptr = SvPV(data, len);
66 if (len > want)
67 croak("Too much data returned in reader callback");
68
69 memcpy(buffer, ptr, len);
70 result = len;
71 }
72 else {
73 result = -1;
74 }
75
76 PUTBACK;
77 FREETMPS;
78 LEAVE;
79
80 return result;
81}
82
83typedef struct
84{
85 SV *sv; /* a coderef or sub name */
86} i_writer_data;
87
88/* used by functions that want callbacks */
89static int write_callback(char *userdata, char const *data, int size) {
90 i_writer_data *wd = (i_writer_data *)userdata;
91 int count;
92 int success;
93 SV *sv;
94 dSP;
95
96 ENTER;
97 SAVETMPS;
98 EXTEND(SP, 1);
99 PUSHMARK(SP);
100 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
101 PUTBACK;
102
103 count = perl_call_sv(wd->sv, G_SCALAR);
104
105 SPAGAIN;
106
107 if (count != 1)
108 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
109
110 sv = POPs;
111 success = SvTRUE(sv);
112
113
114 PUTBACK;
115 FREETMPS;
116 LEAVE;
117
118 return success;
119}
120
121struct value_name {
122 char *name;
123 int value;
124};
125static int lookup_name(struct value_name *names, int count, char *name, int def_value)
126{
127 int i;
128 for (i = 0; i < count; ++i)
129 if (strEQ(names[i].name, name))
130 return names[i].value;
131
132 return def_value;
133}
134static struct value_name transp_names[] =
135{
136 { "none", tr_none },
137 { "threshold", tr_threshold },
138 { "errdiff", tr_errdiff },
139 { "ordered", tr_ordered, },
140};
141
142static struct value_name make_color_names[] =
143{
144 { "none", mc_none, },
145 { "webmap", mc_web_map, },
146 { "addi", mc_addi, },
147};
148
149static struct value_name translate_names[] =
150{
151#ifdef HAVE_LIBGIF
152 { "giflib", pt_giflib, },
153#endif
154 { "closest", pt_closest, },
155 { "perturb", pt_perturb, },
156 { "errdiff", pt_errdiff, },
157};
158
159static struct value_name errdiff_names[] =
160{
161 { "floyd", ed_floyd, },
162 { "jarvis", ed_jarvis, },
163 { "stucki", ed_stucki, },
164 { "custom", ed_custom, },
165};
166
167static struct value_name orddith_names[] =
168{
169 { "random", od_random, },
170 { "dot8", od_dot8, },
171 { "dot4", od_dot4, },
172 { "hline", od_hline, },
173 { "vline", od_vline, },
174 { "/line", od_slashline, },
175 { "slashline", od_slashline, },
176 { "\\line", od_backline, },
177 { "backline", od_backline, },
e7d4ea82 178 { "tiny", od_tiny, },
02d1d628
AMH
179 { "custom", od_custom, },
180};
181
bf9dd17c 182static int
07e3e23d 183hv_fetch_bool(HV *hv, char *name, int def) {
bf9dd17c
TC
184 SV **sv;
185
186 sv = hv_fetch(hv, name, strlen(name), 0);
187 if (sv && *sv) {
188 return SvTRUE(*sv);
189 }
190 else
191 return def;
192}
193
194static int
07e3e23d 195hv_fetch_int(HV *hv, char *name, int def) {
bf9dd17c
TC
196 SV **sv;
197
198 sv = hv_fetch(hv, name, strlen(name), 0);
199 if (sv && *sv) {
200 return SvIV(*sv);
201 }
202 else
203 return def;
204}
205
02d1d628
AMH
206/* look through the hash for quantization options */
207static void handle_quant_opts(i_quantize *quant, HV *hv)
208{
209 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
210 SV **sv;
211 int i;
212 STRLEN len;
213 char *str;
214
215 sv = hv_fetch(hv, "transp", 6, 0);
216 if (sv && *sv && (str = SvPV(*sv, len))) {
217 quant->transp =
218 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
219 str, tr_none);
220 if (quant->transp != tr_none) {
221 quant->tr_threshold = 127;
222 sv = hv_fetch(hv, "tr_threshold", 12, 0);
223 if (sv && *sv)
224 quant->tr_threshold = SvIV(*sv);
225 }
226 if (quant->transp == tr_errdiff) {
227 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
228 if (sv && *sv && (str = SvPV(*sv, len)))
229 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
230 }
231 if (quant->transp == tr_ordered) {
e7d4ea82 232 quant->tr_orddith = od_tiny;
02d1d628
AMH
233 sv = hv_fetch(hv, "tr_orddith", 10, 0);
234 if (sv && *sv && (str = SvPV(*sv, len)))
235 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
236
237 if (quant->tr_orddith == od_custom) {
238 sv = hv_fetch(hv, "tr_map", 6, 0);
239 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
240 AV *av = (AV*)SvRV(*sv);
241 len = av_len(av) + 1;
242 if (len > sizeof(quant->tr_custom))
243 len = sizeof(quant->tr_custom);
244 for (i = 0; i < len; ++i) {
245 SV **sv2 = av_fetch(av, i, 0);
246 if (sv2 && *sv2) {
247 quant->tr_custom[i] = SvIV(*sv2);
248 }
249 }
250 while (i < sizeof(quant->tr_custom))
251 quant->tr_custom[i++] = 0;
252 }
253 }
254 }
255 }
256 quant->make_colors = mc_addi;
257 sv = hv_fetch(hv, "make_colors", 11, 0);
258 if (sv && *sv && (str = SvPV(*sv, len))) {
259 quant->make_colors =
260 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
261 }
262 sv = hv_fetch(hv, "colors", 6, 0);
263 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
264 /* needs to be an array of Imager::Color
265 note that the caller allocates the mc_color array and sets mc_size
266 to it's size */
267 AV *av = (AV *)SvRV(*sv);
268 quant->mc_count = av_len(av)+1;
269 if (quant->mc_count > quant->mc_size)
270 quant->mc_count = quant->mc_size;
271 for (i = 0; i < quant->mc_count; ++i) {
272 SV **sv1 = av_fetch(av, i, 0);
273 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
274 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
275 quant->mc_colors[i] = *col;
276 }
277 }
278 }
279 sv = hv_fetch(hv, "max_colors", 10, 0);
280 if (sv && *sv) {
281 i = SvIV(*sv);
282 if (i <= quant->mc_size && i >= quant->mc_count)
283 quant->mc_size = i;
284 }
285
286 quant->translate = pt_closest;
287 sv = hv_fetch(hv, "translate", 9, 0);
288 if (sv && *sv && (str = SvPV(*sv, len))) {
289 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
290 }
291 sv = hv_fetch(hv, "errdiff", 7, 0);
292 if (sv && *sv && (str = SvPV(*sv, len))) {
293 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
294 }
295 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
296 /* get the error diffusion map */
297 sv = hv_fetch(hv, "errdiff_width", 13, 0);
298 if (sv && *sv)
299 quant->ed_width = SvIV(*sv);
300 sv = hv_fetch(hv, "errdiff_height", 14, 0);
301 if (sv && *sv)
302 quant->ed_height = SvIV(*sv);
303 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
304 if (sv && *sv)
305 quant->ed_orig = SvIV(*sv);
306 if (quant->ed_width > 0 && quant->ed_height > 0) {
307 int sum = 0;
308 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
309 sv = hv_fetch(hv, "errdiff_map", 11, 0);
310 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
311 AV *av = (AV*)SvRV(*sv);
312 len = av_len(av) + 1;
313 if (len > quant->ed_width * quant->ed_height)
314 len = quant->ed_width * quant->ed_height;
315 for (i = 0; i < len; ++i) {
316 SV **sv2 = av_fetch(av, i, 0);
317 if (sv2 && *sv2) {
318 quant->ed_map[i] = SvIV(*sv2);
319 sum += quant->ed_map[i];
320 }
321 }
322 }
323 if (!sum) {
324 /* broken map */
325 myfree(quant->ed_map);
326 quant->ed_map = 0;
327 quant->errdiff = ed_floyd;
328 }
329 }
330 }
331 sv = hv_fetch(hv, "perturb", 7, 0);
332 if (sv && *sv)
333 quant->perturb = SvIV(*sv);
334}
335
336/* look through the hash for options to add to opts */
337static void handle_gif_opts(i_gif_opts *opts, HV *hv)
338{
02d1d628
AMH
339 SV **sv;
340 int i;
341 /**((char *)0) = '\0';*/
bf9dd17c
TC
342 opts->each_palette = hv_fetch_bool(hv, "gif_each_palette", 0);
343 opts->interlace = hv_fetch_bool(hv, "interlace", 0);
344
02d1d628
AMH
345 sv = hv_fetch(hv, "gif_delays", 10, 0);
346 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
347 AV *av = (AV*)SvRV(*sv);
348 opts->delay_count = av_len(av)+1;
349 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
350 for (i = 0; i < opts->delay_count; ++i) {
351 SV *sv1 = *av_fetch(av, i, 0);
352 opts->delays[i] = SvIV(sv1);
353 }
354 }
355 sv = hv_fetch(hv, "gif_user_input", 14, 0);
356 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
357 AV *av = (AV*)SvRV(*sv);
358 opts->user_input_count = av_len(av)+1;
359 opts->user_input_flags = mymalloc(opts->user_input_count);
360 for (i = 0; i < opts->user_input_count; ++i) {
361 SV *sv1 = *av_fetch(av, i, 0);
362 opts->user_input_flags[i] = SvIV(sv1) != 0;
363 }
364 }
365 sv = hv_fetch(hv, "gif_disposal", 12, 0);
366 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
367 AV *av = (AV*)SvRV(*sv);
368 opts->disposal_count = av_len(av)+1;
369 opts->disposal = mymalloc(opts->disposal_count);
370 for (i = 0; i < opts->disposal_count; ++i) {
371 SV *sv1 = *av_fetch(av, i, 0);
372 opts->disposal[i] = SvIV(sv1);
373 }
374 }
375 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
376 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
377 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
378 opts->tran_color = *col;
379 }
380 sv = hv_fetch(hv, "gif_positions", 13, 0);
381 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
382 AV *av = (AV *)SvRV(*sv);
383 opts->position_count = av_len(av) + 1;
384 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
385 for (i = 0; i < opts->position_count; ++i) {
386 SV **sv2 = av_fetch(av, i, 0);
387 opts->positions[i].x = opts->positions[i].y = 0;
388 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
389 AV *av2 = (AV*)SvRV(*sv2);
390 SV **sv3;
391 sv3 = av_fetch(av2, 0, 0);
392 if (sv3 && *sv3)
393 opts->positions[i].x = SvIV(*sv3);
394 sv3 = av_fetch(av2, 1, 0);
395 if (sv3 && *sv3)
396 opts->positions[i].y = SvIV(*sv3);
397 }
398 }
399 }
400 /* Netscape2.0 loop count extension */
bf9dd17c
TC
401 opts->loop_count = hv_fetch_int(hv, "gif_loop_count", 0);
402
403 opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1);
02d1d628
AMH
404}
405
406/* copies the color map from the hv into the colors member of the HV */
407static void copy_colors_back(HV *hv, i_quantize *quant) {
408 SV **sv;
409 AV *av;
410 int i;
411 SV *work;
412
413 sv = hv_fetch(hv, "colors", 6, 0);
414 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
415 SV *ref;
416 av = newAV();
417 ref = newRV_inc((SV*) av);
418 sv = hv_store(hv, "colors", 6, ref, 0);
419 }
420 else {
421 av = (AV *)SvRV(*sv);
422 }
423 av_extend(av, quant->mc_count+1);
424 for (i = 0; i < quant->mc_count; ++i) {
425 i_color *in = quant->mc_colors+i;
426 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
427 work = sv_newmortal();
428 sv_setref_pv(work, "Imager::Color", (void *)c);
429 SvREFCNT_inc(work);
430 if (!av_store(av, i, work)) {
431 SvREFCNT_dec(work);
432 }
433 }
434}
435
f1ac5027
TC
436/* loads the segments of a fountain fill into an array */
437i_fountain_seg *load_fount_segs(AV *asegs, int *count) {
438 /* Each element of segs must contain:
439 [ start, middle, end, c0, c1, segtype, colortrans ]
440 start, middle, end are doubles from 0 to 1
441 c0, c1 are Imager::Color::Float or Imager::Color objects
442 segtype, colortrans are ints
443 */
444 int i, j;
445 AV *aseg;
446 SV *sv;
447 i_fountain_seg *segs;
448 double work[3];
449 int worki[2];
450
451 *count = av_len(asegs)+1;
452 if (*count < 1)
453 croak("i_fountain must have at least one segment");
454 segs = mymalloc(sizeof(i_fountain_seg) * *count);
455 for(i = 0; i < *count; i++) {
456 SV **sv1 = av_fetch(asegs, i, 0);
457 if (!sv1 || !*sv1 || !SvROK(*sv1)
458 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
459 myfree(segs);
460 croak("i_fountain: segs must be an arrayref of arrayrefs");
461 }
462 aseg = (AV *)SvRV(*sv1);
463 if (av_len(aseg) != 7-1) {
464 myfree(segs);
465 croak("i_fountain: a segment must have 7 members");
466 }
467 for (j = 0; j < 3; ++j) {
468 SV **sv2 = av_fetch(aseg, j, 0);
469 if (!sv2 || !*sv2) {
470 myfree(segs);
471 croak("i_fountain: XS error");
472 }
473 work[j] = SvNV(*sv2);
474 }
475 segs[i].start = work[0];
476 segs[i].middle = work[1];
477 segs[i].end = work[2];
478 for (j = 0; j < 2; ++j) {
479 SV **sv3 = av_fetch(aseg, 3+j, 0);
480 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
481 (!sv_derived_from(*sv3, "Imager::Color")
482 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
483 myfree(segs);
484 croak("i_fountain: segs must contain colors in elements 3 and 4");
485 }
486 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
487 segs[i].c[j] = *(i_fcolor *)SvIV((SV *)SvRV(*sv3));
488 }
489 else {
490 i_color c = *(i_color *)SvIV((SV *)SvRV(*sv3));
491 int ch;
492 for (ch = 0; ch < MAXCHANNELS; ++ch) {
493 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
494 }
495 }
496 }
497 for (j = 0; j < 2; ++j) {
498 SV **sv2 = av_fetch(aseg, j+5, 0);
499 if (!sv2 || !*sv2) {
500 myfree(segs);
501 croak("i_fountain: XS error");
502 }
503 worki[j] = SvIV(*sv2);
504 }
505 segs[i].type = worki[0];
506 segs[i].color = worki[1];
507 }
508
509 return segs;
510}
511
faa9b3e7
TC
512/* I don't think ICLF_* names belong at the C interface
513 this makes the XS code think we have them, to let us avoid
514 putting function bodies in the XS code
515*/
516#define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
517#define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
518
f1ac5027
TC
519/* for the fill objects
520 Since a fill object may later have dependent images, (or fills!)
521 we need perl wrappers - oh well
522*/
523#define IFILL_DESTROY(fill) i_fill_destroy(fill);
524typedef i_fill_t* Imager__FillHandle;
525
02d1d628
AMH
526MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
527
528Imager::Color
529ICL_new_internal(r,g,b,a)
530 unsigned char r
531 unsigned char g
532 unsigned char b
533 unsigned char a
534
535void
536ICL_DESTROY(cl)
537 Imager::Color cl
538
539
29106a11 540void
02d1d628
AMH
541ICL_set_internal(cl,r,g,b,a)
542 Imager::Color cl
543 unsigned char r
544 unsigned char g
545 unsigned char b
546 unsigned char a
29106a11 547 PPCODE:
46062ab6 548 ICL_set_internal(cl, r, g, b, a);
29106a11
TC
549 EXTEND(SP, 1);
550 PUSHs(ST(0));
02d1d628
AMH
551
552void
553ICL_info(cl)
554 Imager::Color cl
555
556
557void
558ICL_rgba(cl)
559 Imager::Color cl
560 PPCODE:
561 EXTEND(SP, 4);
562 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
563 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
564 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
565 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
566
efdc2568
TC
567Imager::Color
568i_hsv_to_rgb(c)
569 Imager::Color c
570 CODE:
571 RETVAL = mymalloc(sizeof(i_color));
572 *RETVAL = *c;
573 i_hsv_to_rgb(RETVAL);
574 OUTPUT:
575 RETVAL
576
577Imager::Color
578i_rgb_to_hsv(c)
579 Imager::Color c
580 CODE:
581 RETVAL = mymalloc(sizeof(i_color));
582 *RETVAL = *c;
583 i_rgb_to_hsv(RETVAL);
584 OUTPUT:
585 RETVAL
586
02d1d628
AMH
587
588
faa9b3e7 589MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
02d1d628 590
faa9b3e7
TC
591Imager::Color::Float
592ICLF_new_internal(r, g, b, a)
593 double r
594 double g
595 double b
596 double a
597
598void
599ICLF_DESTROY(cl)
600 Imager::Color::Float cl
02d1d628 601
faa9b3e7
TC
602void
603ICLF_rgba(cl)
604 Imager::Color::Float cl
605 PREINIT:
606 int ch;
607 PPCODE:
608 EXTEND(SP, MAXCHANNELS);
609 for (ch = 0; ch < MAXCHANNELS; ++ch) {
610 /* printf("%d: %g\n", ch, cl->channel[ch]); */
611 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
612 }
613
614void
615ICLF_set_internal(cl,r,g,b,a)
616 Imager::Color::Float cl
617 double r
618 double g
619 double b
620 double a
621 PPCODE:
622 cl->rgba.r = r;
623 cl->rgba.g = g;
624 cl->rgba.b = b;
625 cl->rgba.a = a;
626 EXTEND(SP, 1);
627 PUSHs(ST(0));
02d1d628 628
efdc2568
TC
629Imager::Color::Float
630i_hsv_to_rgb(c)
631 Imager::Color::Float c
632 CODE:
633 RETVAL = mymalloc(sizeof(i_fcolor));
634 *RETVAL = *c;
635 i_hsv_to_rgbf(RETVAL);
636 OUTPUT:
637 RETVAL
638
639Imager::Color::Float
640i_rgb_to_hsv(c)
641 Imager::Color::Float c
642 CODE:
643 RETVAL = mymalloc(sizeof(i_fcolor));
644 *RETVAL = *c;
645 i_rgb_to_hsvf(RETVAL);
646 OUTPUT:
647 RETVAL
648
649
02d1d628
AMH
650MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
651
652Imager::ImgRaw
653IIM_new(x,y,ch)
654 int x
655 int y
656 int ch
657
658void
659IIM_DESTROY(im)
660 Imager::ImgRaw im
661
662
663
664MODULE = Imager PACKAGE = Imager
665
666PROTOTYPES: ENABLE
667
668
669Imager::IO
670io_new_fd(fd)
671 int fd
672
673Imager::IO
674io_new_bufchain()
675
676
677void
678io_slurp(ig)
679 Imager::IO ig
680 PREINIT:
681 unsigned char* data;
682 size_t tlength;
683 SV* r;
684 PPCODE:
685 data = NULL;
686 tlength = io_slurp(ig, &data);
687 r = sv_newmortal();
688 EXTEND(SP,1);
689 PUSHs(sv_2mortal(newSVpv(data,tlength)));
690 myfree(data);
691
692
c3cc977e
AMH
693MODULE = Imager PACKAGE = Imager::IO PREFIX = io_glue_
694
695void
696io_glue_DESTROY(ig)
697 Imager::IO ig
698
699
700MODULE = Imager PACKAGE = Imager
701
702PROTOTYPES: ENABLE
703
704
02d1d628
AMH
705
706void
707i_list_formats()
708 PREINIT:
709 char* item;
710 int i;
711 PPCODE:
712 i=0;
713 while( (item=i_format_list[i++]) != NULL ) {
714 EXTEND(SP, 1);
715 PUSHs(sv_2mortal(newSVpv(item,0)));
716 }
717
718undef_int
719i_has_format(frmt)
720 char* frmt
721
722Imager::ImgRaw
723i_img_new()
724
725Imager::ImgRaw
726i_img_empty(im,x,y)
727 Imager::ImgRaw im
728 int x
729 int y
730
731Imager::ImgRaw
732i_img_empty_ch(im,x,y,ch)
733 Imager::ImgRaw im
734 int x
735 int y
736 int ch
737
738void
739init_log(name,level)
740 char* name
741 int level
742
743void
744i_img_exorcise(im)
745 Imager::ImgRaw im
746
747void
748i_img_destroy(im)
749 Imager::ImgRaw im
750
751void
752i_img_info(im)
753 Imager::ImgRaw im
754 PREINIT:
755 int info[4];
756 PPCODE:
757 i_img_info(im,info);
758 EXTEND(SP, 4);
759 PUSHs(sv_2mortal(newSViv(info[0])));
760 PUSHs(sv_2mortal(newSViv(info[1])));
761 PUSHs(sv_2mortal(newSViv(info[2])));
762 PUSHs(sv_2mortal(newSViv(info[3])));
763
764
765
766
767void
768i_img_setmask(im,ch_mask)
769 Imager::ImgRaw im
770 int ch_mask
771
772int
773i_img_getmask(im)
774 Imager::ImgRaw im
775
776int
777i_img_getchannels(im)
778 Imager::ImgRaw im
779
780void
781i_img_getdata(im)
782 Imager::ImgRaw im
783 PPCODE:
784 EXTEND(SP, 1);
faa9b3e7
TC
785 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
786 : &PL_sv_undef);
02d1d628
AMH
787
788
789void
790i_draw(im,x1,y1,x2,y2,val)
791 Imager::ImgRaw im
792 int x1
793 int y1
794 int x2
795 int y2
796 Imager::Color val
797
798void
799i_line_aa(im,x1,y1,x2,y2,val)
800 Imager::ImgRaw im
801 int x1
802 int y1
803 int x2
804 int y2
805 Imager::Color val
806
807void
808i_box(im,x1,y1,x2,y2,val)
809 Imager::ImgRaw im
810 int x1
811 int y1
812 int x2
813 int y2
814 Imager::Color val
815
816void
817i_box_filled(im,x1,y1,x2,y2,val)
818 Imager::ImgRaw im
819 int x1
820 int y1
821 int x2
822 int y2
823 Imager::Color val
824
f1ac5027
TC
825void
826i_box_cfill(im,x1,y1,x2,y2,fill)
827 Imager::ImgRaw im
828 int x1
829 int y1
830 int x2
831 int y2
832 Imager::FillHandle fill
833
02d1d628
AMH
834void
835i_arc(im,x,y,rad,d1,d2,val)
836 Imager::ImgRaw im
837 int x
838 int y
839 float rad
840 float d1
841 float d2
842 Imager::Color val
843
f1ac5027
TC
844void
845i_arc_cfill(im,x,y,rad,d1,d2,fill)
846 Imager::ImgRaw im
847 int x
848 int y
849 float rad
850 float d1
851 float d2
852 Imager::FillHandle fill
853
02d1d628
AMH
854
855
6af18d2b
AMH
856void
857i_circle_aa(im,x,y,rad,val)
858 Imager::ImgRaw im
859 float x
860 float y
861 float rad
862 Imager::Color val
863
864
865
02d1d628
AMH
866void
867i_bezier_multi(im,xc,yc,val)
868 Imager::ImgRaw im
869 Imager::Color val
870 PREINIT:
871 double *x,*y;
872 int len;
873 AV *av1;
874 AV *av2;
875 SV *sv1;
876 SV *sv2;
877 int i;
878 PPCODE:
879 ICL_info(val);
880 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
881 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
882 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
883 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
884 av1=(AV*)SvRV(ST(1));
885 av2=(AV*)SvRV(ST(2));
886 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
887 len=av_len(av1)+1;
888 x=mymalloc( len*sizeof(double) );
889 y=mymalloc( len*sizeof(double) );
890 for(i=0;i<len;i++) {
891 sv1=(*(av_fetch(av1,i,0)));
892 sv2=(*(av_fetch(av2,i,0)));
893 x[i]=(double)SvNV(sv1);
894 y[i]=(double)SvNV(sv2);
895 }
896 i_bezier_multi(im,len,x,y,val);
897 myfree(x);
898 myfree(y);
899
900
901void
902i_poly_aa(im,xc,yc,val)
903 Imager::ImgRaw im
904 Imager::Color val
905 PREINIT:
906 double *x,*y;
907 int len;
908 AV *av1;
909 AV *av2;
910 SV *sv1;
911 SV *sv2;
912 int i;
913 PPCODE:
914 ICL_info(val);
915 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
916 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
917 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
918 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
919 av1=(AV*)SvRV(ST(1));
920 av2=(AV*)SvRV(ST(2));
921 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
922 len=av_len(av1)+1;
923 x=mymalloc( len*sizeof(double) );
924 y=mymalloc( len*sizeof(double) );
925 for(i=0;i<len;i++) {
926 sv1=(*(av_fetch(av1,i,0)));
927 sv2=(*(av_fetch(av2,i,0)));
928 x[i]=(double)SvNV(sv1);
929 y[i]=(double)SvNV(sv2);
930 }
931 i_poly_aa(im,len,x,y,val);
932 myfree(x);
933 myfree(y);
934
935
936
937void
938i_flood_fill(im,seedx,seedy,dcol)
939 Imager::ImgRaw im
940 int seedx
941 int seedy
942 Imager::Color dcol
943
cc6483e0
TC
944void
945i_flood_cfill(im,seedx,seedy,fill)
946 Imager::ImgRaw im
947 int seedx
948 int seedy
949 Imager::FillHandle fill
950
02d1d628
AMH
951
952void
953i_copyto(im,src,x1,y1,x2,y2,tx,ty)
954 Imager::ImgRaw im
955 Imager::ImgRaw src
956 int x1
957 int y1
958 int x2
959 int y2
960 int tx
961 int ty
962
963
964void
965i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
966 Imager::ImgRaw im
967 Imager::ImgRaw src
968 int x1
969 int y1
970 int x2
971 int y2
972 int tx
973 int ty
974 Imager::Color trans
975
976void
977i_copy(im,src)
978 Imager::ImgRaw im
979 Imager::ImgRaw src
980
981
faa9b3e7 982undef_int
02d1d628
AMH
983i_rubthru(im,src,tx,ty)
984 Imager::ImgRaw im
985 Imager::ImgRaw src
986 int tx
987 int ty
988
142c26ff
AMH
989undef_int
990i_flipxy(im, direction)
991 Imager::ImgRaw im
992 int direction
993
faa9b3e7
TC
994Imager::ImgRaw
995i_rotate90(im, degrees)
996 Imager::ImgRaw im
997 int degrees
998
999Imager::ImgRaw
1000i_rotate_exact(im, amount)
1001 Imager::ImgRaw im
1002 double amount
1003
1004Imager::ImgRaw
1005i_matrix_transform(im, xsize, ysize, matrix)
1006 Imager::ImgRaw im
1007 int xsize
1008 int ysize
1009 PREINIT:
1010 double matrix[9];
1011 AV *av;
1012 IV len;
1013 SV *sv1;
1014 int i;
1015 CODE:
1016 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
1017 croak("i_matrix_transform: parameter 4 must be an array ref\n");
1018 av=(AV*)SvRV(ST(3));
1019 len=av_len(av)+1;
1020 if (len > 9)
1021 len = 9;
1022 for (i = 0; i < len; ++i) {
1023 sv1=(*(av_fetch(av,i,0)));
1024 matrix[i] = SvNV(sv1);
1025 }
1026 for (; i < 9; ++i)
1027 matrix[i] = 0;
1028 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
1029 OUTPUT:
1030 RETVAL
02d1d628
AMH
1031
1032void
1033i_gaussian(im,stdev)
1034 Imager::ImgRaw im
1035 float stdev
1036
b6381851
TC
1037void
1038i_unsharp_mask(im,stdev,scale)
1039 Imager::ImgRaw im
1040 float stdev
1041 double scale
1042
02d1d628
AMH
1043void
1044i_conv(im,pcoef)
1045 Imager::ImgRaw im
1046 PREINIT:
1047 float* coeff;
1048 int len;
1049 AV* av;
1050 SV* sv1;
1051 int i;
1052 PPCODE:
1053 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1054 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1055 av=(AV*)SvRV(ST(1));
1056 len=av_len(av)+1;
1057 coeff=mymalloc( len*sizeof(float) );
1058 for(i=0;i<len;i++) {
1059 sv1=(*(av_fetch(av,i,0)));
1060 coeff[i]=(float)SvNV(sv1);
1061 }
1062 i_conv(im,coeff,len);
1063 myfree(coeff);
1064
f5991c03
TC
1065undef_int
1066i_convert(im, src, coeff)
1067 Imager::ImgRaw im
1068 Imager::ImgRaw src
1069 PREINIT:
1070 float *coeff;
1071 int outchan;
1072 int inchan;
1073 AV *avmain;
1074 SV **temp;
1075 SV *svsub;
1076 AV *avsub;
1077 int len;
1078 int i, j;
1079 CODE:
f5991c03
TC
1080 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
1081 croak("i_convert: parameter 3 must be an arrayref\n");
1082 avmain = (AV*)SvRV(ST(2));
1083 outchan = av_len(avmain)+1;
1084 /* find the biggest */
1085 inchan = 0;
1086 for (j=0; j < outchan; ++j) {
1087 temp = av_fetch(avmain, j, 0);
1088 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1089 avsub = (AV*)SvRV(*temp);
1090 len = av_len(avsub)+1;
1091 if (len > inchan)
1092 inchan = len;
1093 }
1094 }
1095 coeff = mymalloc(sizeof(float) * outchan * inchan);
1096 for (j = 0; j < outchan; ++j) {
1097 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1098 len = av_len(avsub)+1;
1099 for (i = 0; i < len; ++i) {
1100 temp = av_fetch(avsub, i, 0);
1101 if (temp)
1102 coeff[i+j*inchan] = SvNV(*temp);
1103 else
1104 coeff[i+j*inchan] = 0;
1105 }
1106 while (i < inchan)
1107 coeff[i++ + j*inchan] = 0;
1108 }
1109 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1110 myfree(coeff);
f5991c03
TC
1111 OUTPUT:
1112 RETVAL
40eba1ea
AMH
1113
1114
1115void
1116i_map(im, pmaps)
1117 Imager::ImgRaw im
1118 PREINIT:
1119 unsigned int mask = 0;
1120 AV *avmain;
1121 AV *avsub;
1122 SV **temp;
1123 int len;
1124 int i, j;
1125 unsigned char (*maps)[256];
1126 CODE:
1127 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1128 croak("i_map: parameter 2 must be an arrayref\n");
1129 avmain = (AV*)SvRV(ST(1));
1130 len = av_len(avmain)+1;
1131 if (im->channels < len) len = im->channels;
1132
1133 maps = mymalloc( len * sizeof(unsigned char [256]) );
1134
1135 for (j=0; j<len ; j++) {
1136 temp = av_fetch(avmain, j, 0);
1137 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1138 avsub = (AV*)SvRV(*temp);
1139 if(av_len(avsub) != 255) continue;
1140 mask |= 1<<j;
1141 for (i=0; i<256 ; i++) {
9495ee93 1142 int val;
40eba1ea 1143 temp = av_fetch(avsub, i, 0);
9495ee93
AMH
1144 val = temp ? SvIV(*temp) : 0;
1145 if (val<0) val = 0;
1146 if (val>255) val = 255;
1147 maps[j][i] = val;
40eba1ea
AMH
1148 }
1149 }
1150 }
1151 i_map(im, maps, mask);
1152 myfree(maps);
1153
1154
1155
02d1d628
AMH
1156float
1157i_img_diff(im1,im2)
1158 Imager::ImgRaw im1
1159 Imager::ImgRaw im2
1160
1161
1162
1163undef_int
1164i_init_fonts()
1165
1166#ifdef HAVE_LIBT1
1167
1168void
1169i_t1_set_aa(st)
1170 int st
1171
1172int
1173i_t1_new(pfb,afm=NULL)
1174 char* pfb
1175 char* afm
1176
1177int
1178i_t1_destroy(font_id)
1179 int font_id
1180
1181
1182undef_int
1183i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1184 Imager::ImgRaw im
1185 int xb
1186 int yb
1187 int channel
1188 int fontnum
1189 float points
1190 char* str
1191 int len
1192 int align
1193
1194void
1195i_t1_bbox(fontnum,point,str,len)
1196 int fontnum
1197 float point
1198 char* str
1199 int len
1200 PREINIT:
1201 int cords[6];
1202 PPCODE:
1203 i_t1_bbox(fontnum,point,str,len,cords);
1204 EXTEND(SP, 4);
1205 PUSHs(sv_2mortal(newSViv(cords[0])));
1206 PUSHs(sv_2mortal(newSViv(cords[1])));
1207 PUSHs(sv_2mortal(newSViv(cords[2])));
1208 PUSHs(sv_2mortal(newSViv(cords[3])));
1209 PUSHs(sv_2mortal(newSViv(cords[4])));
1210 PUSHs(sv_2mortal(newSViv(cords[5])));
1211
1212
1213
1214undef_int
1215i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1216 Imager::ImgRaw im
1217 int xb
1218 int yb
1219 Imager::Color cl
1220 int fontnum
1221 float points
1222 char* str
1223 int len
1224 int align
1225
1226#endif
1227
1228#ifdef HAVE_LIBTT
1229
1230
1231Imager::TTHandle
1232i_tt_new(fontname)
1233 char* fontname
1234
1235void
1236i_tt_destroy(handle)
1237 Imager::TTHandle handle
1238
1239
1240
1241undef_int
1242i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1243 Imager::TTHandle handle
1244 Imager::ImgRaw im
1245 int xb
1246 int yb
1247 Imager::Color cl
1248 float points
1249 char* str
1250 int len
1251 int smooth
1252
1253
1254undef_int
1255i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1256 Imager::TTHandle handle
1257 Imager::ImgRaw im
1258 int xb
1259 int yb
1260 int channel
1261 float points
1262 char* str
1263 int len
1264 int smooth
1265
1266
1267
1268undef_int
1269i_tt_bbox(handle,point,str,len)
1270 Imager::TTHandle handle
1271 float point
1272 char* str
1273 int len
1274 PREINIT:
1275 int cords[6],rc;
1276 PPCODE:
1277 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1278 EXTEND(SP, 4);
1279 PUSHs(sv_2mortal(newSViv(cords[0])));
1280 PUSHs(sv_2mortal(newSViv(cords[1])));
1281 PUSHs(sv_2mortal(newSViv(cords[2])));
1282 PUSHs(sv_2mortal(newSViv(cords[3])));
1283 PUSHs(sv_2mortal(newSViv(cords[4])));
1284 PUSHs(sv_2mortal(newSViv(cords[5])));
1285 }
1286
1287
1288#endif
1289
1290
1291
1292
1293#ifdef HAVE_LIBJPEG
1294undef_int
dd55acc8 1295i_writejpeg_wiol(im, ig, qfactor)
02d1d628 1296 Imager::ImgRaw im
dd55acc8 1297 Imager::IO ig
02d1d628
AMH
1298 int qfactor
1299
02d1d628
AMH
1300
1301void
1302i_readjpeg_wiol(ig)
1303 Imager::IO ig
1304 PREINIT:
1305 char* iptc_itext;
1306 int tlength;
1307 i_img* rimg;
1308 SV* r;
1309 PPCODE:
1310 iptc_itext = NULL;
1311 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1312 if (iptc_itext == NULL) {
1313 r = sv_newmortal();
1314 EXTEND(SP,1);
1315 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1316 PUSHs(r);
1317 } else {
1318 r = sv_newmortal();
1319 EXTEND(SP,2);
1320 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1321 PUSHs(r);
1322 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1323 myfree(iptc_itext);
1324 }
1325
1326
1327#endif
1328
1329
1330
1331
1332#ifdef HAVE_LIBTIFF
1333
1334Imager::ImgRaw
1335i_readtiff_wiol(ig, length)
1336 Imager::IO ig
1337 int length
1338
1339
1340undef_int
1341i_writetiff_wiol(im, ig)
1342 Imager::ImgRaw im
1343 Imager::IO ig
1344
d2dfdcc9 1345undef_int
4c2d6970 1346i_writetiff_wiol_faxable(im, ig, fine)
d2dfdcc9
TC
1347 Imager::ImgRaw im
1348 Imager::IO ig
4c2d6970 1349 int fine
d2dfdcc9 1350
02d1d628
AMH
1351
1352#endif /* HAVE_LIBTIFF */
1353
1354
1355
1356
1357
1358#ifdef HAVE_LIBPNG
1359
1360Imager::ImgRaw
790923a4
AMH
1361i_readpng_wiol(ig, length)
1362 Imager::IO ig
1363 int length
02d1d628
AMH
1364
1365
1366undef_int
790923a4 1367i_writepng_wiol(im, ig)
02d1d628 1368 Imager::ImgRaw im
790923a4 1369 Imager::IO ig
02d1d628
AMH
1370
1371
1372#endif
1373
1374
1375#ifdef HAVE_LIBGIF
1376
03bd24d4
TC
1377void
1378i_giflib_version()
1379 PPCODE:
1380 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1381
02d1d628
AMH
1382undef_int
1383i_writegif(im,fd,colors,pixdev,fixed)
1384 Imager::ImgRaw im
1385 int fd
1386 int colors
1387 int pixdev
1388 PREINIT:
1389 int fixedlen;
1390 Imager__Color fixed;
1391 Imager__Color tmp;
1392 AV* av;
1393 SV* sv1;
1394 IV Itmp;
1395 int i;
1396 CODE:
1397 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1398 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1399 av=(AV*)SvRV(ST(4));
1400 fixedlen=av_len(av)+1;
1401 fixed=mymalloc( fixedlen*sizeof(i_color) );
1402 for(i=0;i<fixedlen;i++) {
1403 sv1=(*(av_fetch(av,i,0)));
1404 if (sv_derived_from(sv1, "Imager::Color")) {
1405 Itmp = SvIV((SV*)SvRV(sv1));
1406 tmp = (i_color*) Itmp;
1407 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1408 fixed[i]=*tmp;
1409 }
1410 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1411 myfree(fixed);
1412 ST(0) = sv_newmortal();
1413 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1414 else sv_setiv(ST(0), (IV)RETVAL);
1415
1416
1417
1418
1419undef_int
1420i_writegifmc(im,fd,colors)
067d6bdc 1421 Imager::ImgRaw im
02d1d628
AMH
1422 int fd
1423 int colors
1424
02d1d628
AMH
1425
1426undef_int
1427i_writegif_gen(fd, ...)
1428 int fd
1429 PROTOTYPE: $$@
1430 PREINIT:
1431 i_quantize quant;
1432 i_gif_opts opts;
1433 i_img **imgs = NULL;
1434 int img_count;
1435 int i;
1436 HV *hv;
1437 CODE:
1438 if (items < 3)
1439 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1440 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1441 croak("i_writegif_gen: Second argument must be a hash ref");
1442 hv = (HV *)SvRV(ST(1));
1443 memset(&quant, 0, sizeof(quant));
1444 quant.mc_size = 256;
1445 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1446 memset(&opts, 0, sizeof(opts));
1447 handle_quant_opts(&quant, hv);
1448 handle_gif_opts(&opts, hv);
1449 img_count = items - 2;
1450 RETVAL = 1;
1451 if (img_count < 1) {
1452 RETVAL = 0;
95b44a76
TC
1453 i_clear_error();
1454 i_push_error(0, "You need to specify images to save");
02d1d628
AMH
1455 }
1456 else {
1457 imgs = mymalloc(sizeof(i_img *) * img_count);
1458 for (i = 0; i < img_count; ++i) {
1459 SV *sv = ST(2+i);
1460 imgs[i] = NULL;
1461 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1462 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1463 }
1464 else {
95b44a76
TC
1465 i_clear_error();
1466 i_push_error(0, "Only images can be saved");
02d1d628
AMH
1467 RETVAL = 0;
1468 break;
1469 }
1470 }
1471 if (RETVAL) {
1472 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1473 }
1474 myfree(imgs);
1475 if (RETVAL) {
1476 copy_colors_back(hv, &quant);
1477 }
1478 }
1479 ST(0) = sv_newmortal();
1480 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1481 else sv_setiv(ST(0), (IV)RETVAL);
1482
1483undef_int
1484i_writegif_callback(cb, maxbuffer,...)
1485 int maxbuffer;
1486 PREINIT:
1487 i_quantize quant;
1488 i_gif_opts opts;
1489 i_img **imgs = NULL;
1490 int img_count;
1491 int i;
1492 HV *hv;
1493 i_writer_data wd;
1494 CODE:
1495 if (items < 4)
1496 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1497 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1498 croak("i_writegif_callback: Second argument must be a hash ref");
1499 hv = (HV *)SvRV(ST(2));
1500 memset(&quant, 0, sizeof(quant));
1501 quant.mc_size = 256;
1502 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1503 memset(&opts, 0, sizeof(opts));
1504 handle_quant_opts(&quant, hv);
1505 handle_gif_opts(&opts, hv);
1506 img_count = items - 3;
1507 RETVAL = 1;
1508 if (img_count < 1) {
1509 RETVAL = 0;
1510 }
1511 else {
1512 imgs = mymalloc(sizeof(i_img *) * img_count);
1513 for (i = 0; i < img_count; ++i) {
1514 SV *sv = ST(3+i);
1515 imgs[i] = NULL;
1516 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1517 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1518 }
1519 else {
1520 RETVAL = 0;
1521 break;
1522 }
1523 }
1524 if (RETVAL) {
1525 wd.sv = ST(0);
1526 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1527 }
1528 myfree(imgs);
1529 if (RETVAL) {
1530 copy_colors_back(hv, &quant);
1531 }
1532 }
1533 ST(0) = sv_newmortal();
1534 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1535 else sv_setiv(ST(0), (IV)RETVAL);
1536
1537void
1538i_readgif(fd)
1539 int fd
1540 PREINIT:
1541 int* colour_table;
1542 int colours, q, w;
1543 i_img* rimg;
1544 SV* temp[3];
1545 AV* ct;
1546 SV* r;
1547 PPCODE:
1548 colour_table = NULL;
1549 colours = 0;
1550
895dbd34 1551 if(GIMME_V == G_ARRAY) {
02d1d628
AMH
1552 rimg = i_readgif(fd,&colour_table,&colours);
1553 } else {
1554 /* don't waste time with colours if they aren't wanted */
1555 rimg = i_readgif(fd,NULL,NULL);
1556 }
895dbd34 1557
02d1d628
AMH
1558 if (colour_table == NULL) {
1559 EXTEND(SP,1);
1560 r=sv_newmortal();
1561 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1562 PUSHs(r);
1563 } else {
1564 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1565 /* I don't know if I have the reference counts right or not :( */
1566 /* Neither do I :-) */
1567 /* No Idea here either */
1568
1569 ct=newAV();
1570 av_extend(ct, colours);
1571 for(q=0; q<colours; q++) {
1572 for(w=0; w<3; w++)
1573 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1574 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1575 }
1576 myfree(colour_table);
895dbd34 1577
02d1d628 1578 EXTEND(SP,2);
895dbd34 1579 r = sv_newmortal();
02d1d628
AMH
1580 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1581 PUSHs(r);
1582 PUSHs(newRV_noinc((SV*)ct));
1583 }
1584
1585
1586
1587
1588
1589void
1590i_readgif_scalar(...)
1591 PROTOTYPE: $
1592 PREINIT:
1593 char* data;
1594 unsigned int length;
1595 int* colour_table;
1596 int colours, q, w;
1597 i_img* rimg;
1598 SV* temp[3];
1599 AV* ct;
1600 SV* r;
1601 PPCODE:
1602 data = (char *)SvPV(ST(0), length);
1603 colour_table=NULL;
1604 colours=0;
1605
1606 if(GIMME_V == G_ARRAY) {
1607 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1608 } else {
1609 /* don't waste time with colours if they aren't wanted */
1610 rimg=i_readgif_scalar(data,length,NULL,NULL);
1611 }
1612
1613 if (colour_table == NULL) {
1614 EXTEND(SP,1);
1615 r=sv_newmortal();
1616 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1617 PUSHs(r);
1618 } else {
1619 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1620 /* I don't know if I have the reference counts right or not :( */
1621 /* Neither do I :-) */
1622 ct=newAV();
1623 av_extend(ct, colours);
1624 for(q=0; q<colours; q++) {
1625 for(w=0; w<3; w++)
1626 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1627 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1628 }
1629 myfree(colour_table);
1630
1631 EXTEND(SP,2);
1632 r=sv_newmortal();
1633 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1634 PUSHs(r);
1635 PUSHs(newRV_noinc((SV*)ct));
1636 }
1637
1638void
1639i_readgif_callback(...)
1640 PROTOTYPE: &
1641 PREINIT:
1642 char* data;
1643 int length;
1644 int* colour_table;
1645 int colours, q, w;
1646 i_img* rimg;
1647 SV* temp[3];
1648 AV* ct;
1649 SV* r;
1650 i_reader_data rd;
1651 PPCODE:
1652 rd.sv = ST(0);
1653 colour_table=NULL;
1654 colours=0;
1655
1656 if(GIMME_V == G_ARRAY) {
1657 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1658 } else {
1659 /* don't waste time with colours if they aren't wanted */
1660 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1661 }
1662
1663 if (colour_table == NULL) {
1664 EXTEND(SP,1);
1665 r=sv_newmortal();
1666 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1667 PUSHs(r);
1668 } else {
1669 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1670 /* I don't know if I have the reference counts right or not :( */
1671 /* Neither do I :-) */
1672 /* Neither do I - maybe I'll move this somewhere */
1673 ct=newAV();
1674 av_extend(ct, colours);
1675 for(q=0; q<colours; q++) {
1676 for(w=0; w<3; w++)
1677 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1678 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1679 }
1680 myfree(colour_table);
1681
1682 EXTEND(SP,2);
1683 r=sv_newmortal();
1684 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1685 PUSHs(r);
1686 PUSHs(newRV_noinc((SV*)ct));
1687 }
1688
faa9b3e7
TC
1689void
1690i_readgif_multi(fd)
1691 int fd
1692 PREINIT:
1693 i_img **imgs;
1694 int count;
1695 int i;
1696 PPCODE:
1697 imgs = i_readgif_multi(fd, &count);
1698 if (imgs) {
1699 EXTEND(SP, count);
1700 for (i = 0; i < count; ++i) {
1701 SV *sv = sv_newmortal();
1702 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1703 PUSHs(sv);
1704 }
1705 myfree(imgs);
1706 }
02d1d628 1707
faa9b3e7
TC
1708void
1709i_readgif_multi_scalar(data)
1710 PREINIT:
1711 i_img **imgs;
1712 int count;
1713 char *data;
1714 unsigned int length;
1715 int i;
1716 PPCODE:
1717 data = (char *)SvPV(ST(0), length);
1718 imgs = i_readgif_multi_scalar(data, length, &count);
1719 if (imgs) {
1720 EXTEND(SP, count);
1721 for (i = 0; i < count; ++i) {
1722 SV *sv = sv_newmortal();
1723 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1724 PUSHs(sv);
1725 }
1726 myfree(imgs);
1727 }
02d1d628 1728
faa9b3e7
TC
1729void
1730i_readgif_multi_callback(cb)
1731 PREINIT:
1732 i_reader_data rd;
1733 i_img **imgs;
1734 int count;
1735 int i;
1736 PPCODE:
1737 rd.sv = ST(0);
1738 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1739 if (imgs) {
1740 EXTEND(SP, count);
1741 for (i = 0; i < count; ++i) {
1742 SV *sv = sv_newmortal();
1743 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1744 PUSHs(sv);
1745 }
1746 myfree(imgs);
1747 }
02d1d628
AMH
1748
1749#endif
1750
1751
1752
1753Imager::ImgRaw
1754i_readpnm_wiol(ig, length)
1755 Imager::IO ig
1756 int length
1757
1758
067d6bdc
AMH
1759undef_int
1760i_writeppm_wiol(im, ig)
1761 Imager::ImgRaw im
1762 Imager::IO ig
1763
1764
02d1d628 1765Imager::ImgRaw
895dbd34
AMH
1766i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1767 Imager::IO ig
02d1d628
AMH
1768 int x
1769 int y
1770 int datachannels
1771 int storechannels
1772 int intrl
1773
1774undef_int
895dbd34 1775i_writeraw_wiol(im,ig)
02d1d628 1776 Imager::ImgRaw im
895dbd34
AMH
1777 Imager::IO ig
1778
261f91c5
TC
1779undef_int
1780i_writebmp_wiol(im,ig)
1781 Imager::ImgRaw im
1782 Imager::IO ig
02d1d628 1783
705fd961
TC
1784Imager::ImgRaw
1785i_readbmp_wiol(ig)
1786 Imager::IO ig
1787
1ec86afa
AMH
1788
1789undef_int
1790i_writetga_wiol(im,ig)
1791 Imager::ImgRaw im
1792 Imager::IO ig
1793
1794Imager::ImgRaw
1795i_readtga_wiol(ig, length)
1796 Imager::IO ig
1797 int length
1798
1799
02d1d628
AMH
1800Imager::ImgRaw
1801i_scaleaxis(im,Value,Axis)
1802 Imager::ImgRaw im
1803 float Value
1804 int Axis
1805
1806Imager::ImgRaw
1807i_scale_nn(im,scx,scy)
1808 Imager::ImgRaw im
1809 float scx
1810 float scy
1811
1812Imager::ImgRaw
1813i_haar(im)
1814 Imager::ImgRaw im
1815
1816int
1817i_count_colors(im,maxc)
1818 Imager::ImgRaw im
1819 int maxc
1820
1821
1822Imager::ImgRaw
1823i_transform(im,opx,opy,parm)
1824 Imager::ImgRaw im
1825 PREINIT:
1826 double* parm;
1827 int* opx;
1828 int* opy;
1829 int opxl;
1830 int opyl;
1831 int parmlen;
1832 AV* av;
1833 SV* sv1;
1834 int i;
1835 CODE:
1836 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1837 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1838 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1839 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1840 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1841 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1842 av=(AV*)SvRV(ST(1));
1843 opxl=av_len(av)+1;
1844 opx=mymalloc( opxl*sizeof(int) );
1845 for(i=0;i<opxl;i++) {
1846 sv1=(*(av_fetch(av,i,0)));
1847 opx[i]=(int)SvIV(sv1);
1848 }
1849 av=(AV*)SvRV(ST(2));
1850 opyl=av_len(av)+1;
1851 opy=mymalloc( opyl*sizeof(int) );
1852 for(i=0;i<opyl;i++) {
1853 sv1=(*(av_fetch(av,i,0)));
1854 opy[i]=(int)SvIV(sv1);
1855 }
1856 av=(AV*)SvRV(ST(3));
1857 parmlen=av_len(av)+1;
1858 parm=mymalloc( parmlen*sizeof(double) );
1859 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1860 sv1=(*(av_fetch(av,i,0)));
1861 parm[i]=(double)SvNV(sv1);
1862 }
1863 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1864 myfree(parm);
1865 myfree(opy);
1866 myfree(opx);
1867 ST(0) = sv_newmortal();
1868 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1869 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1870
1871Imager::ImgRaw
1872i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1873 PREINIT:
1874 int width;
1875 int height;
1876 double* parm;
1877 struct rm_op *ops;
1878 unsigned int ops_len;
1879 int ops_count;
1880 double *n_regs;
1881 int n_regs_count;
1882 i_color *c_regs;
1883 int c_regs_count;
1884 int in_imgs_count;
1885 i_img **in_imgs;
1886 AV* av;
1887 SV* sv1;
1888 IV tmp;
1889 int i;
1890 CODE:
1891 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1892 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1893 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1894 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1895 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1896
1897 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1898
1899 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1900 av = (AV*)SvRV(ST(5));
1901 in_imgs_count = av_len(av)+1;
1902 for (i = 0; i < in_imgs_count; ++i) {
1903 sv1 = *av_fetch(av, i, 0);
1904 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1905 croak("Parameter 5 must contain only images");
1906 }
1907 }
1908 }
1909 else {
1910 in_imgs_count = 0;
1911 }
1912 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1913 av = (AV*)SvRV(ST(5));
1914 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1915 for (i = 0; i < in_imgs_count; ++i) {
1916 sv1 = *av_fetch(av,i,0);
1917 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1918 croak("Parameter 5 must contain only images");
1919 }
1920 tmp = SvIV((SV*)SvRV(sv1));
1921 in_imgs[i] = (i_img*)tmp;
1922 }
1923 }
1924 else {
1925 /* no input images */
1926 in_imgs = NULL;
1927 }
1928 /* default the output size from the first input if possible */
1929 if (SvOK(ST(0)))
1930 width = SvIV(ST(0));
1931 else if (in_imgs_count)
1932 width = in_imgs[0]->xsize;
1933 else
1934 croak("No output image width supplied");
1935
1936 if (SvOK(ST(1)))
1937 height = SvIV(ST(1));
1938 else if (in_imgs_count)
1939 height = in_imgs[0]->ysize;
1940 else
1941 croak("No output image height supplied");
1942
1943 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1944 if (ops_len % sizeof(struct rm_op))
1945 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1946 ops_count = ops_len / sizeof(struct rm_op);
1947 av = (AV*)SvRV(ST(3));
1948 n_regs_count = av_len(av)+1;
1949 n_regs = mymalloc(n_regs_count * sizeof(double));
1950 for (i = 0; i < n_regs_count; ++i) {
1951 sv1 = *av_fetch(av,i,0);
1952 if (SvOK(sv1))
1953 n_regs[i] = SvNV(sv1);
1954 }
1955 av = (AV*)SvRV(ST(4));
1956 c_regs_count = av_len(av)+1;
1957 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1958 /* I don't bother initializing the colou?r registers */
1959
1960 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1961 n_regs, n_regs_count,
1962 c_regs, c_regs_count, in_imgs, in_imgs_count);
1963 if (in_imgs)
1964 myfree(in_imgs);
1965 myfree(n_regs);
1966 myfree(c_regs);
1967 ST(0) = sv_newmortal();
1968 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1969 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1970
1971
1972void
1973i_contrast(im,intensity)
1974 Imager::ImgRaw im
1975 float intensity
1976
1977void
1978i_hardinvert(im)
1979 Imager::ImgRaw im
1980
1981void
1982i_noise(im,amount,type)
1983 Imager::ImgRaw im
1984 float amount
1985 unsigned char type
1986
1987void
1988i_bumpmap(im,bump,channel,light_x,light_y,strength)
1989 Imager::ImgRaw im
1990 Imager::ImgRaw bump
1991 int channel
1992 int light_x
1993 int light_y
1994 int strength
1995
b2778574
AMH
1996
1997void
1998i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
1999 Imager::ImgRaw im
2000 Imager::ImgRaw bump
2001 int channel
2002 int tx
2003 int ty
2004 float Lx
2005 float Ly
2006 float Lz
2007 float cd
2008 float cs
2009 float n
2010 Imager::Color Ia
2011 Imager::Color Il
2012 Imager::Color Is
2013
2014
2015
02d1d628
AMH
2016void
2017i_postlevels(im,levels)
2018 Imager::ImgRaw im
2019 int levels
2020
2021void
2022i_mosaic(im,size)
2023 Imager::ImgRaw im
2024 int size
2025
2026void
2027i_watermark(im,wmark,tx,ty,pixdiff)
2028 Imager::ImgRaw im
2029 Imager::ImgRaw wmark
2030 int tx
2031 int ty
2032 int pixdiff
2033
2034
2035void
2036i_autolevels(im,lsat,usat,skew)
2037 Imager::ImgRaw im
2038 float lsat
2039 float usat
2040 float skew
2041
2042void
2043i_radnoise(im,xo,yo,rscale,ascale)
2044 Imager::ImgRaw im
2045 float xo
2046 float yo
2047 float rscale
2048 float ascale
2049
2050void
2051i_turbnoise(im, xo, yo, scale)
2052 Imager::ImgRaw im
2053 float xo
2054 float yo
2055 float scale
2056
2057
2058void
2059i_gradgen(im, ...)
2060 Imager::ImgRaw im
2061 PREINIT:
2062 int num;
2063 int *xo;
2064 int *yo;
2065 i_color *ival;
2066 int dmeasure;
2067 int i;
2068 SV *sv;
2069 AV *axx;
2070 AV *ayy;
2071 AV *ac;
2072 CODE:
2073 if (items != 5)
2074 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2075 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2076 croak("i_gradgen: Second argument must be an array ref");
2077 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2078 croak("i_gradgen: Third argument must be an array ref");
2079 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2080 croak("i_gradgen: Fourth argument must be an array ref");
2081 axx = (AV *)SvRV(ST(1));
2082 ayy = (AV *)SvRV(ST(2));
2083 ac = (AV *)SvRV(ST(3));
2084 dmeasure = (int)SvIV(ST(4));
2085
2086 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2087 num = num <= av_len(ac) ? num : av_len(ac);
2088 num++;
2089 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2090 xo = mymalloc( sizeof(int) * num );
2091 yo = mymalloc( sizeof(int) * num );
2092 ival = mymalloc( sizeof(i_color) * num );
2093 for(i = 0; i<num; i++) {
2094 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2095 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2096 sv = *av_fetch(ac, i, 0);
2097 if ( !sv_derived_from(sv, "Imager::Color") ) {
2098 free(axx); free(ayy); free(ac);
2099 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2100 }
2101 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2102 }
2103 i_gradgen(im, num, xo, yo, ival, dmeasure);
2104
6607600c
TC
2105void
2106i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2107 Imager::ImgRaw im
2108 double xa
2109 double ya
2110 double xb
2111 double yb
2112 int type
2113 int repeat
2114 int combine
2115 int super_sample
2116 double ssample_param
2117 PREINIT:
6607600c 2118 AV *asegs;
6607600c
TC
2119 int count;
2120 i_fountain_seg *segs;
6607600c 2121 CODE:
6607600c
TC
2122 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2123 croak("i_fountain: argument 11 must be an array ref");
2124
2125 asegs = (AV *)SvRV(ST(10));
f1ac5027 2126 segs = load_fount_segs(asegs, &count);
6607600c
TC
2127 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2128 ssample_param, count, segs);
2129 myfree(segs);
02d1d628 2130
f1ac5027
TC
2131Imager::FillHandle
2132i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2133 double xa
2134 double ya
2135 double xb
2136 double yb
2137 int type
2138 int repeat
2139 int combine
2140 int super_sample
2141 double ssample_param
2142 PREINIT:
2143 AV *asegs;
2144 int count;
2145 i_fountain_seg *segs;
2146 CODE:
2147 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2148 croak("i_fountain: argument 11 must be an array ref");
2149
2150 asegs = (AV *)SvRV(ST(9));
2151 segs = load_fount_segs(asegs, &count);
2152 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2153 super_sample, ssample_param, count, segs);
2154 myfree(segs);
2155 OUTPUT:
2156 RETVAL
2157
4f4f776a
TC
2158void
2159i_errors()
2160 PREINIT:
2161 i_errmsg *errors;
2162 int i;
4f4f776a
TC
2163 AV *av;
2164 SV *ref;
2165 SV *sv;
2166 PPCODE:
2167 errors = i_errors();
2168 i = 0;
2169 while (errors[i].msg) {
2170 av = newAV();
2171 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2172 if (!av_store(av, 0, sv)) {
2173 SvREFCNT_dec(sv);
2174 }
2175 sv = newSViv(errors[i].code);
2176 if (!av_store(av, 1, sv)) {
2177 SvREFCNT_dec(sv);
2178 }
2179 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2180 ++i;
2181 }
02d1d628
AMH
2182
2183void
2184i_nearest_color(im, ...)
2185 Imager::ImgRaw im
2186 PREINIT:
2187 int num;
2188 int *xo;
2189 int *yo;
2190 i_color *ival;
2191 int dmeasure;
2192 int i;
2193 SV *sv;
2194 AV *axx;
2195 AV *ayy;
2196 AV *ac;
2197 CODE:
2198 if (items != 5)
2199 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2200 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2201 croak("i_nearest_color: Second argument must be an array ref");
2202 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2203 croak("i_nearest_color: Third argument must be an array ref");
2204 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2205 croak("i_nearest_color: Fourth argument must be an array ref");
2206 axx = (AV *)SvRV(ST(1));
2207 ayy = (AV *)SvRV(ST(2));
2208 ac = (AV *)SvRV(ST(3));
2209 dmeasure = (int)SvIV(ST(4));
2210
2211 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2212 num = num <= av_len(ac) ? num : av_len(ac);
2213 num++;
2214 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2215 xo = mymalloc( sizeof(int) * num );
2216 yo = mymalloc( sizeof(int) * num );
2217 ival = mymalloc( sizeof(i_color) * num );
2218 for(i = 0; i<num; i++) {
2219 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2220 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2221 sv = *av_fetch(ac, i, 0);
2222 if ( !sv_derived_from(sv, "Imager::Color") ) {
2223 free(axx); free(ayy); free(ac);
2224 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2225 }
2226 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2227 }
2228 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2229
2230
2231
2232
2233void
2234malloc_state()
2235
2236void
2237hashinfo(hv)
2238 PREINIT:
2239 HV* hv;
2240 int stuff;
2241 PPCODE:
2242 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2243 hv=(HV*)SvRV(ST(0));
2244 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2245 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2246 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2247
2248void
2249DSO_open(filename)
2250 char* filename
2251 PREINIT:
2252 void *rc;
2253 char *evstr;
2254 PPCODE:
2255 rc=DSO_open(filename,&evstr);
2256 if (rc!=NULL) {
2257 if (evstr!=NULL) {
2258 EXTEND(SP,2);
2259 PUSHs(sv_2mortal(newSViv((IV)rc)));
2260 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2261 } else {
2262 EXTEND(SP,1);
2263 PUSHs(sv_2mortal(newSViv((IV)rc)));
2264 }
2265 }
2266
2267
2268undef_int
2269DSO_close(dso_handle)
2270 void* dso_handle
2271
2272void
2273DSO_funclist(dso_handle_v)
2274 void* dso_handle_v
2275 PREINIT:
2276 int i;
2277 DSO_handle *dso_handle;
2278 PPCODE:
2279 dso_handle=(DSO_handle*)dso_handle_v;
2280 i=0;
2281 while( dso_handle->function_list[i].name != NULL) {
2282 EXTEND(SP,1);
2283 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2284 EXTEND(SP,1);
2285 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2286 }
2287
2288
2289void
2290DSO_call(handle,func_index,hv)
2291 void* handle
2292 int func_index
2293 PREINIT:
2294 HV* hv;
2295 PPCODE:
2296 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2297 hv=(HV*)SvRV(ST(2));
2298 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2299 DSO_call( (DSO_handle *)handle,func_index,hv);
2300
2301
2302
f5991c03 2303# this is mostly for testing...
faa9b3e7 2304SV *
f5991c03
TC
2305i_get_pixel(im, x, y)
2306 Imager::ImgRaw im
2307 int x
2308 int y;
faa9b3e7
TC
2309 PREINIT:
2310 i_color *color;
2311 CODE:
2312 color = (i_color *)mymalloc(sizeof(i_color));
2313 if (i_gpix(im, x, y, color) == 0) {
2314 ST(0) = sv_newmortal();
2315 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2316 }
2317 else {
2318 myfree(color);
2319 ST(0) = &PL_sv_undef;
2320 }
2321
2322
2323int
2324i_ppix(im, x, y, cl)
2325 Imager::ImgRaw im
2326 int x
2327 int y
2328 Imager::Color cl
2329
2330Imager::ImgRaw
2331i_img_pal_new(x, y, channels, maxpal)
2332 int x
2333 int y
2334 int channels
2335 int maxpal
2336
2337Imager::ImgRaw
2338i_img_to_pal(src, quant)
2339 Imager::ImgRaw src
2340 PREINIT:
2341 HV *hv;
2342 i_quantize quant;
2343 CODE:
2344 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2345 croak("i_img_to_pal: second argument must be a hash ref");
2346 hv = (HV *)SvRV(ST(1));
2347 memset(&quant, 0, sizeof(quant));
2348 quant.mc_size = 256;
2349 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2350 handle_quant_opts(&quant, hv);
2351 RETVAL = i_img_to_pal(src, &quant);
2352 if (RETVAL) {
2353 copy_colors_back(hv, &quant);
2354 }
2355 myfree(quant.mc_colors);
2356 OUTPUT:
2357 RETVAL
2358
2359Imager::ImgRaw
2360i_img_to_rgb(src)
2361 Imager::ImgRaw src
2362
2363void
2364i_gpal(im, l, r, y)
2365 Imager::ImgRaw im
2366 int l
2367 int r
2368 int y
2369 PREINIT:
2370 i_palidx *work;
2371 int count, i;
2372 PPCODE:
2373 if (l < r) {
2374 work = mymalloc((r-l) * sizeof(i_palidx));
2375 count = i_gpal(im, l, r, y, work);
2376 if (GIMME_V == G_ARRAY) {
2377 EXTEND(SP, count);
2378 for (i = 0; i < count; ++i) {
2379 PUSHs(sv_2mortal(newSViv(work[i])));
2380 }
2381 }
2382 else {
2383 EXTEND(SP, 1);
2384 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2385 }
2386 myfree(work);
2387 }
2388 else {
2389 if (GIMME_V != G_ARRAY) {
2390 EXTEND(SP, 1);
2391 PUSHs(&PL_sv_undef);
2392 }
2393 }
2394
2395int
2396i_ppal(im, l, y, ...)
2397 Imager::ImgRaw im
2398 int l
2399 int y
2400 PREINIT:
2401 i_palidx *work;
2402 int count, i;
2403 CODE:
2404 if (items > 3) {
2405 work = mymalloc(sizeof(i_palidx) * (items-3));
2406 for (i=0; i < items-3; ++i) {
2407 work[i] = SvIV(ST(i+3));
2408 }
2409 RETVAL = i_ppal(im, l, l+items-3, y, work);
2410 myfree(work);
2411 }
2412 else {
2413 RETVAL = 0;
2414 }
2415 OUTPUT:
2416 RETVAL
2417
2418SV *
2419i_addcolors(im, ...)
2420 Imager::ImgRaw im
2421 PREINIT:
2422 int index;
2423 i_color *colors;
2424 int i;
2425 CODE:
2426 if (items < 2)
2427 croak("i_addcolors: no colors to add");
2428 colors = mymalloc((items-1) * sizeof(i_color));
2429 for (i=0; i < items-1; ++i) {
2430 if (sv_isobject(ST(i+1))
2431 && sv_derived_from(ST(i+1), "Imager::Color")) {
2432 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2433 colors[i] = *(i_color *)tmp;
2434 }
2435 else {
2436 myfree(colors);
2437 croak("i_plin: pixels must be Imager::Color objects");
2438 }
2439 }
2440 index = i_addcolors(im, colors, items-1);
2441 myfree(colors);
2442 if (index == 0) {
2443 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2444 }
2445 else if (index == -1) {
2446 ST(0) = &PL_sv_undef;
2447 }
2448 else {
2449 ST(0) = sv_2mortal(newSViv(index));
2450 }
2451
2452int
2453i_setcolors(im, index, ...)
2454 Imager::ImgRaw im
2455 int index
2456 PREINIT:
2457 i_color *colors;
2458 int i;
2459 CODE:
2460 if (items < 3)
2461 croak("i_setcolors: no colors to add");
2462 colors = mymalloc((items-2) * sizeof(i_color));
2463 for (i=0; i < items-2; ++i) {
2464 if (sv_isobject(ST(i+2))
2465 && sv_derived_from(ST(i+2), "Imager::Color")) {
2466 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2467 colors[i] = *(i_color *)tmp;
2468 }
2469 else {
2470 myfree(colors);
2471 croak("i_setcolors: pixels must be Imager::Color objects");
2472 }
2473 }
2474 RETVAL = i_setcolors(im, index, colors, items-2);
2475 myfree(colors);
2476
2477void
2478i_getcolors(im, index, ...)
2479 Imager::ImgRaw im
2480 int index
2481 PREINIT:
2482 i_color *colors;
2483 int count = 1;
2484 int i;
2485 PPCODE:
2486 if (items > 3)
2487 croak("i_getcolors: too many arguments");
2488 if (items == 3)
2489 count = SvIV(ST(2));
2490 if (count < 1)
2491 croak("i_getcolors: count must be positive");
2492 colors = mymalloc(sizeof(i_color) * count);
2493 if (i_getcolors(im, index, colors, count)) {
2494 for (i = 0; i < count; ++i) {
2495 i_color *pv;
2496 SV *sv = sv_newmortal();
2497 pv = mymalloc(sizeof(i_color));
2498 *pv = colors[i];
2499 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2500 PUSHs(sv);
2501 }
2502 }
2503 myfree(colors);
2504
2505
2506SV *
2507i_colorcount(im)
2508 Imager::ImgRaw im
2509 PREINIT:
2510 int count;
2511 CODE:
2512 count = i_colorcount(im);
2513 if (count >= 0) {
2514 ST(0) = sv_2mortal(newSViv(count));
2515 }
2516 else {
2517 ST(0) = &PL_sv_undef;
2518 }
2519
2520SV *
2521i_maxcolors(im)
2522 Imager::ImgRaw im
2523 PREINIT:
2524 int count;
2525 CODE:
2526 count = i_maxcolors(im);
2527 if (count >= 0) {
2528 ST(0) = sv_2mortal(newSViv(count));
2529 }
2530 else {
2531 ST(0) = &PL_sv_undef;
2532 }
2533
2534SV *
2535i_findcolor(im, color)
2536 Imager::ImgRaw im
2537 Imager::Color color
2538 PREINIT:
2539 i_palidx index;
2540 CODE:
2541 if (i_findcolor(im, color, &index)) {
2542 ST(0) = sv_2mortal(newSViv(index));
2543 }
2544 else {
2545 ST(0) = &PL_sv_undef;
2546 }
2547
2548int
2549i_img_bits(im)
2550 Imager::ImgRaw im
2551
2552int
2553i_img_type(im)
2554 Imager::ImgRaw im
2555
2556int
2557i_img_virtual(im)
2558 Imager::ImgRaw im
2559
2560void
2561i_gsamp(im, l, r, y, ...)
2562 Imager::ImgRaw im
2563 int l
2564 int r
2565 int y
2566 PREINIT:
2567 int *chans;
2568 int chan_count;
2569 i_sample_t *data;
2570 int count, i;
2571 PPCODE:
2572 if (items < 5)
2573 croak("No channel numbers supplied to g_samp()");
2574 if (l < r) {
2575 chan_count = items - 4;
2576 chans = mymalloc(sizeof(int) * chan_count);
2577 for (i = 0; i < chan_count; ++i)
2578 chans[i] = SvIV(ST(i+4));
2579 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count);
2580 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2581 if (GIMME_V == G_ARRAY) {
2582 EXTEND(SP, count);
2583 for (i = 0; i < count; ++i)
2584 PUSHs(sv_2mortal(newSViv(data[i])));
2585 }
2586 else {
2587 EXTEND(SP, 1);
2588 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2589 }
2590 }
2591 else {
2592 if (GIMME_V != G_ARRAY) {
2593 EXTEND(SP, 1);
2594 PUSHs(&PL_sv_undef);
2595 }
2596 }
2597
2598Imager::ImgRaw
2599i_img_masked_new(targ, mask, x, y, w, h)
2600 Imager::ImgRaw targ
2601 int x
2602 int y
2603 int w
2604 int h
2605 PREINIT:
2606 i_img *mask;
2607 CODE:
2608 if (SvOK(ST(1))) {
2609 if (!sv_isobject(ST(1))
2610 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2611 croak("i_img_masked_new: parameter 2 must undef or an image");
2612 }
2613 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2614 }
2615 else
2616 mask = NULL;
2617 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2618 OUTPUT:
2619 RETVAL
2620
2621int
2622i_plin(im, l, y, ...)
2623 Imager::ImgRaw im
2624 int l
2625 int y
2626 PREINIT:
2627 i_color *work;
2628 int count, i;
2629 CODE:
2630 if (items > 3) {
2631 work = mymalloc(sizeof(i_color) * (items-3));
2632 for (i=0; i < items-3; ++i) {
2633 if (sv_isobject(ST(i+3))
2634 && sv_derived_from(ST(i+3), "Imager::Color")) {
2635 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2636 work[i] = *(i_color *)tmp;
2637 }
2638 else {
2639 myfree(work);
2640 croak("i_plin: pixels must be Imager::Color objects");
2641 }
2642 }
2643 /**(char *)0 = 1;*/
2644 RETVAL = i_plin(im, l, l+items-3, y, work);
2645 myfree(work);
2646 }
2647 else {
2648 RETVAL = 0;
2649 }
2650 OUTPUT:
2651 RETVAL
2652
2653int
2654i_ppixf(im, x, y, cl)
2655 Imager::ImgRaw im
2656 int x
2657 int y
2658 Imager::Color::Float cl
2659
2660void
2661i_gsampf(im, l, r, y, ...)
2662 Imager::ImgRaw im
2663 int l
2664 int r
2665 int y
2666 PREINIT:
2667 int *chans;
2668 int chan_count;
2669 i_fsample_t *data;
2670 int count, i;
2671 PPCODE:
2672 if (items < 5)
2673 croak("No channel numbers supplied to g_sampf()");
2674 if (l < r) {
2675 chan_count = items - 4;
2676 chans = mymalloc(sizeof(int) * chan_count);
2677 for (i = 0; i < chan_count; ++i)
2678 chans[i] = SvIV(ST(i+4));
2679 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2680 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2681 if (GIMME_V == G_ARRAY) {
2682 EXTEND(SP, count);
2683 for (i = 0; i < count; ++i)
2684 PUSHs(sv_2mortal(newSVnv(data[i])));
2685 }
2686 else {
2687 EXTEND(SP, 1);
2688 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2689 }
2690 }
2691 else {
2692 if (GIMME_V != G_ARRAY) {
2693 EXTEND(SP, 1);
2694 PUSHs(&PL_sv_undef);
2695 }
2696 }
2697
2698int
2699i_plinf(im, l, y, ...)
2700 Imager::ImgRaw im
2701 int l
2702 int y
2703 PREINIT:
2704 i_fcolor *work;
2705 int count, i;
2706 CODE:
2707 if (items > 3) {
2708 work = mymalloc(sizeof(i_fcolor) * (items-3));
2709 for (i=0; i < items-3; ++i) {
2710 if (sv_isobject(ST(i+3))
2711 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2712 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2713 work[i] = *(i_fcolor *)tmp;
2714 }
2715 else {
2716 myfree(work);
2717 croak("i_plin: pixels must be Imager::Color::Float objects");
2718 }
2719 }
2720 /**(char *)0 = 1;*/
2721 RETVAL = i_plinf(im, l, l+items-3, y, work);
2722 myfree(work);
2723 }
2724 else {
2725 RETVAL = 0;
2726 }
2727 OUTPUT:
2728 RETVAL
2729
2730SV *
2731i_gpixf(im, x, y)
2732 Imager::ImgRaw im
2733 int x
2734 int y;
2735 PREINIT:
2736 i_fcolor *color;
2737 CODE:
2738 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2739 if (i_gpixf(im, x, y, color) == 0) {
2740 ST(0) = sv_newmortal();
2741 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2742 }
2743 else {
2744 myfree(color);
2745 ST(0) = &PL_sv_undef;
2746 }
2747
2748void
2749i_glin(im, l, r, y)
2750 Imager::ImgRaw im
2751 int l
2752 int r
2753 int y
2754 PREINIT:
2755 i_color *vals;
2756 int count, i;
2757 PPCODE:
2758 if (l < r) {
2759 vals = mymalloc((r-l) * sizeof(i_color));
2760 count = i_glin(im, l, r, y, vals);
2761 EXTEND(SP, count);
2762 for (i = 0; i < count; ++i) {
2763 SV *sv;
2764 i_color *col = mymalloc(sizeof(i_color));
2765 sv = sv_newmortal();
2766 sv_setref_pv(sv, "Imager::Color", (void *)col);
2767 PUSHs(sv);
2768 }
2769 myfree(vals);
2770 }
2771
2772void
2773i_glinf(im, l, r, y)
2774 Imager::ImgRaw im
2775 int l
2776 int r
2777 int y
2778 PREINIT:
2779 i_fcolor *vals;
2780 int count, i;
2781 PPCODE:
2782 if (l < r) {
2783 vals = mymalloc((r-l) * sizeof(i_fcolor));
2784 count = i_glinf(im, l, r, y, vals);
2785 EXTEND(SP, count);
2786 for (i = 0; i < count; ++i) {
2787 SV *sv;
2788 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2789 *col = vals[i];
2790 sv = sv_newmortal();
2791 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2792 PUSHs(sv);
2793 }
2794 myfree(vals);
2795 }
2796
2797Imager::ImgRaw
2798i_img_16_new(x, y, ch)
2799 int x
2800 int y
2801 int ch
2802
365ea842
TC
2803Imager::ImgRaw
2804i_img_double_new(x, y, ch)
2805 int x
2806 int y
2807 int ch
2808
faa9b3e7
TC
2809undef_int
2810i_tags_addn(im, name, code, idata)
2811 Imager::ImgRaw im
2812 int code
2813 int idata
2814 PREINIT:
2815 char *name;
2816 STRLEN len;
2817 CODE:
2818 if (SvOK(ST(1)))
2819 name = SvPV(ST(1), len);
2820 else
2821 name = NULL;
2822 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2823 OUTPUT:
2824 RETVAL
2825
2826undef_int
2827i_tags_add(im, name, code, data, idata)
2828 Imager::ImgRaw im
2829 int code
2830 int idata
2831 PREINIT:
2832 char *name;
2833 char *data;
2834 STRLEN len;
2835 CODE:
2836 if (SvOK(ST(1)))
2837 name = SvPV(ST(1), len);
2838 else
2839 name = NULL;
2840 if (SvOK(ST(3)))
2841 data = SvPV(ST(3), len);
2842 else {
2843 data = NULL;
2844 len = 0;
2845 }
2846 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2847 OUTPUT:
2848 RETVAL
2849
2850SV *
2851i_tags_find(im, name, start)
2852 Imager::ImgRaw im
2853 char *name
2854 int start
2855 PREINIT:
2856 int entry;
2857 CODE:
2858 if (i_tags_find(&im->tags, name, start, &entry)) {
2859 if (entry == 0)
2860 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2861 else
2862 ST(0) = sv_2mortal(newSViv(entry));
2863 } else {
2864 ST(0) = &PL_sv_undef;
2865 }
2866
2867SV *
2868i_tags_findn(im, code, start)
2869 Imager::ImgRaw im
2870 int code
2871 int start
2872 PREINIT:
2873 int entry;
2874 CODE:
2875 if (i_tags_findn(&im->tags, code, start, &entry)) {
2876 if (entry == 0)
2877 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2878 else
2879 ST(0) = sv_2mortal(newSViv(entry));
2880 }
2881 else
2882 ST(0) = &PL_sv_undef;
2883
2884int
2885i_tags_delete(im, entry)
2886 Imager::ImgRaw im
2887 int entry
2888 CODE:
2889 RETVAL = i_tags_delete(&im->tags, entry);
2890 OUTPUT:
2891 RETVAL
2892
2893int
2894i_tags_delbyname(im, name)
2895 Imager::ImgRaw im
2896 char * name
2897 CODE:
2898 RETVAL = i_tags_delbyname(&im->tags, name);
2899 OUTPUT:
2900 RETVAL
2901
2902int
2903i_tags_delbycode(im, code)
2904 Imager::ImgRaw im
2905 int code
2906 CODE:
2907 RETVAL = i_tags_delbycode(&im->tags, code);
2908 OUTPUT:
2909 RETVAL
2910
2911void
2912i_tags_get(im, index)
2913 Imager::ImgRaw im
2914 int index
2915 PPCODE:
2916 if (index >= 0 && index < im->tags.count) {
2917 i_img_tag *entry = im->tags.tags + index;
2918 EXTEND(SP, 5);
2919
2920 if (entry->name) {
2921 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2922 }
2923 else {
2924 PUSHs(sv_2mortal(newSViv(entry->code)));
2925 }
2926 if (entry->data) {
2927 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2928 }
2929 else {
2930 PUSHs(sv_2mortal(newSViv(entry->idata)));
2931 }
2932 }
2933
2934int
2935i_tags_count(im)
2936 Imager::ImgRaw im
2937 CODE:
2938 RETVAL = im->tags.count;
2939 OUTPUT:
2940 RETVAL
2941
2942#ifdef HAVE_WIN32
2943
2944void
2945i_wf_bbox(face, size, text)
2946 char *face
2947 int size
2948 char *text
2949 PREINIT:
2950 int cords[6];
2951 PPCODE:
2952 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
2953 EXTEND(SP, 6);
2954 PUSHs(sv_2mortal(newSViv(cords[0])));
2955 PUSHs(sv_2mortal(newSViv(cords[1])));
2956 PUSHs(sv_2mortal(newSViv(cords[2])));
2957 PUSHs(sv_2mortal(newSViv(cords[3])));
2958 PUSHs(sv_2mortal(newSViv(cords[4])));
2959 PUSHs(sv_2mortal(newSViv(cords[5])));
2960 }
2961
2962undef_int
2963i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
2964 char *face
2965 Imager::ImgRaw im
2966 int tx
2967 int ty
2968 Imager::Color cl
2969 int size
2970 char *text
2971 int align
2972 int aa
2973 CODE:
2974 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
2975 align, aa);
2976 OUTPUT:
2977 RETVAL
2978
2979undef_int
2980i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
2981 char *face
2982 Imager::ImgRaw im
2983 int tx
2984 int ty
2985 int channel
2986 int size
2987 char *text
2988 int align
2989 int aa
f5991c03 2990 CODE:
faa9b3e7
TC
2991 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
2992 align, aa);
f5991c03
TC
2993 OUTPUT:
2994 RETVAL
02d1d628 2995
faa9b3e7
TC
2996
2997#endif
2998
2999#ifdef HAVE_FT2
3000
3001MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
3002
3003#define FT2_DESTROY(font) i_ft2_destroy(font)
3004
3005void
3006FT2_DESTROY(font)
3007 Imager::Font::FT2 font
3008
3009MODULE = Imager PACKAGE = Imager::Font::FreeType2
3010
3011Imager::Font::FT2
3012i_ft2_new(name, index)
3013 char *name
3014 int index
3015
3016undef_int
3017i_ft2_setdpi(font, xdpi, ydpi)
3018 Imager::Font::FT2 font
3019 int xdpi
3020 int ydpi
3021
3022void
3023i_ft2_getdpi(font)
3024 Imager::Font::FT2 font
3025 PREINIT:
3026 int xdpi, ydpi;
3027 CODE:
3028 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
3029 EXTEND(SP, 2);
3030 PUSHs(sv_2mortal(newSViv(xdpi)));
3031 PUSHs(sv_2mortal(newSViv(ydpi)));
3032 }
3033
3034undef_int
3035i_ft2_sethinting(font, hinting)
3036 Imager::Font::FT2 font
3037 int hinting
3038
3039undef_int
3040i_ft2_settransform(font, matrix)
3041 Imager::Font::FT2 font
3042 PREINIT:
3043 double matrix[6];
3044 int len;
3045 AV *av;
3046 SV *sv1;
3047 int i;
3048 CODE:
3049 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3050 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3051 av=(AV*)SvRV(ST(1));
3052 len=av_len(av)+1;
3053 if (len > 6)
3054 len = 6;
3055 for (i = 0; i < len; ++i) {
3056 sv1=(*(av_fetch(av,i,0)));
3057 matrix[i] = SvNV(sv1);
3058 }
3059 for (; i < 6; ++i)
3060 matrix[i] = 0;
3061 RETVAL = i_ft2_settransform(font, matrix);
3062 OUTPUT:
3063 RETVAL
3064
3065void
3066i_ft2_bbox(font, cheight, cwidth, text)
3067 Imager::Font::FT2 font
3068 double cheight
3069 double cwidth
3070 char *text
3071 PREINIT:
3072 int bbox[6];
3073 int i;
3074 PPCODE:
3075 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
3076 EXTEND(SP, 6);
3077 for (i = 0; i < 6; ++i)
3078 PUSHs(sv_2mortal(newSViv(bbox[i])));
3079 }
3080
3081void
3082i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3083 Imager::Font::FT2 font
3084 double cheight
3085 double cwidth
3086 char *text
3087 int vlayout
3088 int utf8
3089 PREINIT:
3090 int bbox[8];
3091 int i;
3092 PPCODE:
3093#ifdef SvUTF8
3094 if (SvUTF8(ST(3)))
3095 utf8 = 1;
3096#endif
3097 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3098 utf8, bbox)) {
3099 EXTEND(SP, 8);
3100 for (i = 0; i < 8; ++i)
3101 PUSHs(sv_2mortal(newSViv(bbox[i])));
3102 }
3103
3104undef_int
3105i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3106 Imager::Font::FT2 font
3107 Imager::ImgRaw im
3108 int tx
3109 int ty
3110 Imager::Color cl
3111 double cheight
3112 double cwidth
3113 int align
3114 int aa
3115 int vlayout
3116 int utf8
3117 PREINIT:
3118 char *text;
3119 STRLEN len;
3120 CODE:
3121#ifdef SvUTF8
3122 if (SvUTF8(ST(7))) {
3123 utf8 = 1;
3124 }
3125#endif
3126 text = SvPV(ST(7), len);
3127 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3128 len, align, aa, vlayout, utf8);
3129 OUTPUT:
3130 RETVAL
3131
3132undef_int
3133i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3134 Imager::Font::FT2 font
3135 Imager::ImgRaw im
3136 int tx
3137 int ty
3138 int channel
3139 double cheight
3140 double cwidth
3141 char *text
3142 int align
3143 int aa
3144 int vlayout
3145 int utf8
3146 CODE:
3147#ifdef SvUTF8
3148 if (SvUTF8(ST(7)))
3149 utf8 = 1;
3150#endif
3151 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3152 strlen(text), align, aa, vlayout, 1);
3153 OUTPUT:
3154 RETVAL
3155
3156void
3157ft2_transform_box(font, x0, x1, x2, x3)
3158 Imager::Font::FT2 font
3159 int x0
3160 int x1
3161 int x2
3162 int x3
3163 PREINIT:
3164 int box[4];
3165 PPCODE:
3166 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3167 ft2_transform_box(font, box);
3168 EXTEND(SP, 4);
3169 PUSHs(sv_2mortal(newSViv(box[0])));
3170 PUSHs(sv_2mortal(newSViv(box[1])));
3171 PUSHs(sv_2mortal(newSViv(box[2])));
3172 PUSHs(sv_2mortal(newSViv(box[3])));
3173
3174#endif
3175
f1ac5027
TC
3176MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3177
3178void
3179IFILL_DESTROY(fill)
3180 Imager::FillHandle fill
3181
3182MODULE = Imager PACKAGE = Imager
3183
3184Imager::FillHandle
3185i_new_fill_solid(cl, combine)
3186 Imager::Color cl
3187 int combine
3188
3189Imager::FillHandle
3190i_new_fill_solidf(cl, combine)
3191 Imager::Color::Float cl
3192 int combine
3193
3194Imager::FillHandle
3195i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3196 Imager::Color fg
3197 Imager::Color bg
3198 int combine
3199 int hatch
3200 int dx
3201 int dy
3202 PREINIT:
3203 unsigned char *cust_hatch;
3204 STRLEN len;
3205 CODE:
3206 if (SvOK(ST(4))) {
3207 cust_hatch = SvPV(ST(4), len);
3208 }
3209 else
3210 cust_hatch = NULL;
3211 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3212 OUTPUT:
3213 RETVAL
3214
efdc2568
TC
3215Imager::FillHandle
3216i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3217 Imager::Color::Float fg
3218 Imager::Color::Float bg
3219 int combine
3220 int hatch
3221 int dx
3222 int dy
3223 PREINIT:
3224 unsigned char *cust_hatch;
3225 STRLEN len;
3226 CODE:
3227 if (SvOK(ST(4))) {
3228 cust_hatch = SvPV(ST(4), len);
3229 }
3230 else
3231 cust_hatch = NULL;
3232 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3233 OUTPUT:
3234 RETVAL
3235
f576ce7e
TC
3236Imager::FillHandle
3237i_new_fill_image(src, matrix, xoff, yoff, combine)
3238 Imager::ImgRaw src
3239 int xoff
3240 int yoff
3241 int combine
3242 PREINIT:
3243 double matrix[9];
3244 double *matrixp;
3245 AV *av;
3246 IV len;
3247 SV *sv1;
3248 int i;
3249 CODE:
3250 if (!SvOK(ST(1))) {
3251 matrixp = NULL;
3252 }
3253 else {
3254 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3255 croak("i_new_fill_image: parameter must be an arrayref");
3256 av=(AV*)SvRV(ST(1));
3257 len=av_len(av)+1;
3258 if (len > 9)
3259 len = 9;
3260 for (i = 0; i < len; ++i) {
3261 sv1=(*(av_fetch(av,i,0)));
3262 matrix[i] = SvNV(sv1);
3263 }
3264 for (; i < 9; ++i)
3265 matrix[i] = 0;
3266 matrixp = matrix;
3267 }
3268 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
3269 OUTPUT:
3270 RETVAL