have ->arc() call i_circle_aa when drawing a solid aa complete circle
[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
693
694void
695i_list_formats()
696 PREINIT:
697 char* item;
698 int i;
699 PPCODE:
700 i=0;
701 while( (item=i_format_list[i++]) != NULL ) {
702 EXTEND(SP, 1);
703 PUSHs(sv_2mortal(newSVpv(item,0)));
704 }
705
706undef_int
707i_has_format(frmt)
708 char* frmt
709
710Imager::ImgRaw
711i_img_new()
712
713Imager::ImgRaw
714i_img_empty(im,x,y)
715 Imager::ImgRaw im
716 int x
717 int y
718
719Imager::ImgRaw
720i_img_empty_ch(im,x,y,ch)
721 Imager::ImgRaw im
722 int x
723 int y
724 int ch
725
726void
727init_log(name,level)
728 char* name
729 int level
730
731void
732i_img_exorcise(im)
733 Imager::ImgRaw im
734
735void
736i_img_destroy(im)
737 Imager::ImgRaw im
738
739void
740i_img_info(im)
741 Imager::ImgRaw im
742 PREINIT:
743 int info[4];
744 PPCODE:
745 i_img_info(im,info);
746 EXTEND(SP, 4);
747 PUSHs(sv_2mortal(newSViv(info[0])));
748 PUSHs(sv_2mortal(newSViv(info[1])));
749 PUSHs(sv_2mortal(newSViv(info[2])));
750 PUSHs(sv_2mortal(newSViv(info[3])));
751
752
753
754
755void
756i_img_setmask(im,ch_mask)
757 Imager::ImgRaw im
758 int ch_mask
759
760int
761i_img_getmask(im)
762 Imager::ImgRaw im
763
764int
765i_img_getchannels(im)
766 Imager::ImgRaw im
767
768void
769i_img_getdata(im)
770 Imager::ImgRaw im
771 PPCODE:
772 EXTEND(SP, 1);
faa9b3e7
TC
773 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
774 : &PL_sv_undef);
02d1d628
AMH
775
776
777void
778i_draw(im,x1,y1,x2,y2,val)
779 Imager::ImgRaw im
780 int x1
781 int y1
782 int x2
783 int y2
784 Imager::Color val
785
786void
787i_line_aa(im,x1,y1,x2,y2,val)
788 Imager::ImgRaw im
789 int x1
790 int y1
791 int x2
792 int y2
793 Imager::Color val
794
795void
796i_box(im,x1,y1,x2,y2,val)
797 Imager::ImgRaw im
798 int x1
799 int y1
800 int x2
801 int y2
802 Imager::Color val
803
804void
805i_box_filled(im,x1,y1,x2,y2,val)
806 Imager::ImgRaw im
807 int x1
808 int y1
809 int x2
810 int y2
811 Imager::Color val
812
f1ac5027
TC
813void
814i_box_cfill(im,x1,y1,x2,y2,fill)
815 Imager::ImgRaw im
816 int x1
817 int y1
818 int x2
819 int y2
820 Imager::FillHandle fill
821
02d1d628
AMH
822void
823i_arc(im,x,y,rad,d1,d2,val)
824 Imager::ImgRaw im
825 int x
826 int y
827 float rad
828 float d1
829 float d2
830 Imager::Color val
831
f1ac5027
TC
832void
833i_arc_cfill(im,x,y,rad,d1,d2,fill)
834 Imager::ImgRaw im
835 int x
836 int y
837 float rad
838 float d1
839 float d2
840 Imager::FillHandle fill
841
02d1d628
AMH
842
843
6af18d2b
AMH
844void
845i_circle_aa(im,x,y,rad,val)
846 Imager::ImgRaw im
847 float x
848 float y
849 float rad
850 Imager::Color val
851
852
853
02d1d628
AMH
854void
855i_bezier_multi(im,xc,yc,val)
856 Imager::ImgRaw im
857 Imager::Color val
858 PREINIT:
859 double *x,*y;
860 int len;
861 AV *av1;
862 AV *av2;
863 SV *sv1;
864 SV *sv2;
865 int i;
866 PPCODE:
867 ICL_info(val);
868 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
869 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
870 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
871 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
872 av1=(AV*)SvRV(ST(1));
873 av2=(AV*)SvRV(ST(2));
874 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
875 len=av_len(av1)+1;
876 x=mymalloc( len*sizeof(double) );
877 y=mymalloc( len*sizeof(double) );
878 for(i=0;i<len;i++) {
879 sv1=(*(av_fetch(av1,i,0)));
880 sv2=(*(av_fetch(av2,i,0)));
881 x[i]=(double)SvNV(sv1);
882 y[i]=(double)SvNV(sv2);
883 }
884 i_bezier_multi(im,len,x,y,val);
885 myfree(x);
886 myfree(y);
887
888
889void
890i_poly_aa(im,xc,yc,val)
891 Imager::ImgRaw im
892 Imager::Color val
893 PREINIT:
894 double *x,*y;
895 int len;
896 AV *av1;
897 AV *av2;
898 SV *sv1;
899 SV *sv2;
900 int i;
901 PPCODE:
902 ICL_info(val);
903 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
904 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
905 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
906 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
907 av1=(AV*)SvRV(ST(1));
908 av2=(AV*)SvRV(ST(2));
909 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
910 len=av_len(av1)+1;
911 x=mymalloc( len*sizeof(double) );
912 y=mymalloc( len*sizeof(double) );
913 for(i=0;i<len;i++) {
914 sv1=(*(av_fetch(av1,i,0)));
915 sv2=(*(av_fetch(av2,i,0)));
916 x[i]=(double)SvNV(sv1);
917 y[i]=(double)SvNV(sv2);
918 }
919 i_poly_aa(im,len,x,y,val);
920 myfree(x);
921 myfree(y);
922
923
924
925void
926i_flood_fill(im,seedx,seedy,dcol)
927 Imager::ImgRaw im
928 int seedx
929 int seedy
930 Imager::Color dcol
931
cc6483e0
TC
932void
933i_flood_cfill(im,seedx,seedy,fill)
934 Imager::ImgRaw im
935 int seedx
936 int seedy
937 Imager::FillHandle fill
938
02d1d628
AMH
939
940void
941i_copyto(im,src,x1,y1,x2,y2,tx,ty)
942 Imager::ImgRaw im
943 Imager::ImgRaw src
944 int x1
945 int y1
946 int x2
947 int y2
948 int tx
949 int ty
950
951
952void
953i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
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 Imager::Color trans
963
964void
965i_copy(im,src)
966 Imager::ImgRaw im
967 Imager::ImgRaw src
968
969
faa9b3e7 970undef_int
02d1d628
AMH
971i_rubthru(im,src,tx,ty)
972 Imager::ImgRaw im
973 Imager::ImgRaw src
974 int tx
975 int ty
976
142c26ff
AMH
977undef_int
978i_flipxy(im, direction)
979 Imager::ImgRaw im
980 int direction
981
faa9b3e7
TC
982Imager::ImgRaw
983i_rotate90(im, degrees)
984 Imager::ImgRaw im
985 int degrees
986
987Imager::ImgRaw
988i_rotate_exact(im, amount)
989 Imager::ImgRaw im
990 double amount
991
992Imager::ImgRaw
993i_matrix_transform(im, xsize, ysize, matrix)
994 Imager::ImgRaw im
995 int xsize
996 int ysize
997 PREINIT:
998 double matrix[9];
999 AV *av;
1000 IV len;
1001 SV *sv1;
1002 int i;
1003 CODE:
1004 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
1005 croak("i_matrix_transform: parameter 4 must be an array ref\n");
1006 av=(AV*)SvRV(ST(3));
1007 len=av_len(av)+1;
1008 if (len > 9)
1009 len = 9;
1010 for (i = 0; i < len; ++i) {
1011 sv1=(*(av_fetch(av,i,0)));
1012 matrix[i] = SvNV(sv1);
1013 }
1014 for (; i < 9; ++i)
1015 matrix[i] = 0;
1016 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
1017 OUTPUT:
1018 RETVAL
02d1d628
AMH
1019
1020void
1021i_gaussian(im,stdev)
1022 Imager::ImgRaw im
1023 float stdev
1024
1025void
1026i_conv(im,pcoef)
1027 Imager::ImgRaw im
1028 PREINIT:
1029 float* coeff;
1030 int len;
1031 AV* av;
1032 SV* sv1;
1033 int i;
1034 PPCODE:
1035 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1036 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1037 av=(AV*)SvRV(ST(1));
1038 len=av_len(av)+1;
1039 coeff=mymalloc( len*sizeof(float) );
1040 for(i=0;i<len;i++) {
1041 sv1=(*(av_fetch(av,i,0)));
1042 coeff[i]=(float)SvNV(sv1);
1043 }
1044 i_conv(im,coeff,len);
1045 myfree(coeff);
1046
f5991c03
TC
1047undef_int
1048i_convert(im, src, coeff)
1049 Imager::ImgRaw im
1050 Imager::ImgRaw src
1051 PREINIT:
1052 float *coeff;
1053 int outchan;
1054 int inchan;
1055 AV *avmain;
1056 SV **temp;
1057 SV *svsub;
1058 AV *avsub;
1059 int len;
1060 int i, j;
1061 CODE:
f5991c03
TC
1062 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
1063 croak("i_convert: parameter 3 must be an arrayref\n");
1064 avmain = (AV*)SvRV(ST(2));
1065 outchan = av_len(avmain)+1;
1066 /* find the biggest */
1067 inchan = 0;
1068 for (j=0; j < outchan; ++j) {
1069 temp = av_fetch(avmain, j, 0);
1070 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1071 avsub = (AV*)SvRV(*temp);
1072 len = av_len(avsub)+1;
1073 if (len > inchan)
1074 inchan = len;
1075 }
1076 }
1077 coeff = mymalloc(sizeof(float) * outchan * inchan);
1078 for (j = 0; j < outchan; ++j) {
1079 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1080 len = av_len(avsub)+1;
1081 for (i = 0; i < len; ++i) {
1082 temp = av_fetch(avsub, i, 0);
1083 if (temp)
1084 coeff[i+j*inchan] = SvNV(*temp);
1085 else
1086 coeff[i+j*inchan] = 0;
1087 }
1088 while (i < inchan)
1089 coeff[i++ + j*inchan] = 0;
1090 }
1091 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1092 myfree(coeff);
f5991c03
TC
1093 OUTPUT:
1094 RETVAL
40eba1ea
AMH
1095
1096
1097void
1098i_map(im, pmaps)
1099 Imager::ImgRaw im
1100 PREINIT:
1101 unsigned int mask = 0;
1102 AV *avmain;
1103 AV *avsub;
1104 SV **temp;
1105 int len;
1106 int i, j;
1107 unsigned char (*maps)[256];
1108 CODE:
1109 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1110 croak("i_map: parameter 2 must be an arrayref\n");
1111 avmain = (AV*)SvRV(ST(1));
1112 len = av_len(avmain)+1;
1113 if (im->channels < len) len = im->channels;
1114
1115 maps = mymalloc( len * sizeof(unsigned char [256]) );
1116
1117 for (j=0; j<len ; j++) {
1118 temp = av_fetch(avmain, j, 0);
1119 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1120 avsub = (AV*)SvRV(*temp);
1121 if(av_len(avsub) != 255) continue;
1122 mask |= 1<<j;
1123 for (i=0; i<256 ; i++) {
9495ee93 1124 int val;
40eba1ea 1125 temp = av_fetch(avsub, i, 0);
9495ee93
AMH
1126 val = temp ? SvIV(*temp) : 0;
1127 if (val<0) val = 0;
1128 if (val>255) val = 255;
1129 maps[j][i] = val;
40eba1ea
AMH
1130 }
1131 }
1132 }
1133 i_map(im, maps, mask);
1134 myfree(maps);
1135
1136
1137
02d1d628
AMH
1138float
1139i_img_diff(im1,im2)
1140 Imager::ImgRaw im1
1141 Imager::ImgRaw im2
1142
1143
1144
1145undef_int
1146i_init_fonts()
1147
1148#ifdef HAVE_LIBT1
1149
1150void
1151i_t1_set_aa(st)
1152 int st
1153
1154int
1155i_t1_new(pfb,afm=NULL)
1156 char* pfb
1157 char* afm
1158
1159int
1160i_t1_destroy(font_id)
1161 int font_id
1162
1163
1164undef_int
1165i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1166 Imager::ImgRaw im
1167 int xb
1168 int yb
1169 int channel
1170 int fontnum
1171 float points
1172 char* str
1173 int len
1174 int align
1175
1176void
1177i_t1_bbox(fontnum,point,str,len)
1178 int fontnum
1179 float point
1180 char* str
1181 int len
1182 PREINIT:
1183 int cords[6];
1184 PPCODE:
1185 i_t1_bbox(fontnum,point,str,len,cords);
1186 EXTEND(SP, 4);
1187 PUSHs(sv_2mortal(newSViv(cords[0])));
1188 PUSHs(sv_2mortal(newSViv(cords[1])));
1189 PUSHs(sv_2mortal(newSViv(cords[2])));
1190 PUSHs(sv_2mortal(newSViv(cords[3])));
1191 PUSHs(sv_2mortal(newSViv(cords[4])));
1192 PUSHs(sv_2mortal(newSViv(cords[5])));
1193
1194
1195
1196undef_int
1197i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1198 Imager::ImgRaw im
1199 int xb
1200 int yb
1201 Imager::Color cl
1202 int fontnum
1203 float points
1204 char* str
1205 int len
1206 int align
1207
1208#endif
1209
1210#ifdef HAVE_LIBTT
1211
1212
1213Imager::TTHandle
1214i_tt_new(fontname)
1215 char* fontname
1216
1217void
1218i_tt_destroy(handle)
1219 Imager::TTHandle handle
1220
1221
1222
1223undef_int
1224i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1225 Imager::TTHandle handle
1226 Imager::ImgRaw im
1227 int xb
1228 int yb
1229 Imager::Color cl
1230 float points
1231 char* str
1232 int len
1233 int smooth
1234
1235
1236undef_int
1237i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1238 Imager::TTHandle handle
1239 Imager::ImgRaw im
1240 int xb
1241 int yb
1242 int channel
1243 float points
1244 char* str
1245 int len
1246 int smooth
1247
1248
1249
1250undef_int
1251i_tt_bbox(handle,point,str,len)
1252 Imager::TTHandle handle
1253 float point
1254 char* str
1255 int len
1256 PREINIT:
1257 int cords[6],rc;
1258 PPCODE:
1259 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1260 EXTEND(SP, 4);
1261 PUSHs(sv_2mortal(newSViv(cords[0])));
1262 PUSHs(sv_2mortal(newSViv(cords[1])));
1263 PUSHs(sv_2mortal(newSViv(cords[2])));
1264 PUSHs(sv_2mortal(newSViv(cords[3])));
1265 PUSHs(sv_2mortal(newSViv(cords[4])));
1266 PUSHs(sv_2mortal(newSViv(cords[5])));
1267 }
1268
1269
1270#endif
1271
1272
1273
1274
1275#ifdef HAVE_LIBJPEG
1276undef_int
dd55acc8 1277i_writejpeg_wiol(im, ig, qfactor)
02d1d628 1278 Imager::ImgRaw im
dd55acc8 1279 Imager::IO ig
02d1d628
AMH
1280 int qfactor
1281
02d1d628
AMH
1282
1283void
1284i_readjpeg_wiol(ig)
1285 Imager::IO ig
1286 PREINIT:
1287 char* iptc_itext;
1288 int tlength;
1289 i_img* rimg;
1290 SV* r;
1291 PPCODE:
1292 iptc_itext = NULL;
1293 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1294 if (iptc_itext == NULL) {
1295 r = sv_newmortal();
1296 EXTEND(SP,1);
1297 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1298 PUSHs(r);
1299 } else {
1300 r = sv_newmortal();
1301 EXTEND(SP,2);
1302 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1303 PUSHs(r);
1304 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1305 myfree(iptc_itext);
1306 }
1307
1308
1309#endif
1310
1311
1312
1313
1314#ifdef HAVE_LIBTIFF
1315
1316Imager::ImgRaw
1317i_readtiff_wiol(ig, length)
1318 Imager::IO ig
1319 int length
1320
1321
1322undef_int
1323i_writetiff_wiol(im, ig)
1324 Imager::ImgRaw im
1325 Imager::IO ig
1326
d2dfdcc9 1327undef_int
4c2d6970 1328i_writetiff_wiol_faxable(im, ig, fine)
d2dfdcc9
TC
1329 Imager::ImgRaw im
1330 Imager::IO ig
4c2d6970 1331 int fine
d2dfdcc9 1332
02d1d628
AMH
1333
1334#endif /* HAVE_LIBTIFF */
1335
1336
1337
1338
1339
1340#ifdef HAVE_LIBPNG
1341
1342Imager::ImgRaw
790923a4
AMH
1343i_readpng_wiol(ig, length)
1344 Imager::IO ig
1345 int length
02d1d628
AMH
1346
1347
1348undef_int
790923a4 1349i_writepng_wiol(im, ig)
02d1d628 1350 Imager::ImgRaw im
790923a4 1351 Imager::IO ig
02d1d628
AMH
1352
1353
1354#endif
1355
1356
1357#ifdef HAVE_LIBGIF
1358
03bd24d4
TC
1359void
1360i_giflib_version()
1361 PPCODE:
1362 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1363
02d1d628
AMH
1364undef_int
1365i_writegif(im,fd,colors,pixdev,fixed)
1366 Imager::ImgRaw im
1367 int fd
1368 int colors
1369 int pixdev
1370 PREINIT:
1371 int fixedlen;
1372 Imager__Color fixed;
1373 Imager__Color tmp;
1374 AV* av;
1375 SV* sv1;
1376 IV Itmp;
1377 int i;
1378 CODE:
1379 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1380 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1381 av=(AV*)SvRV(ST(4));
1382 fixedlen=av_len(av)+1;
1383 fixed=mymalloc( fixedlen*sizeof(i_color) );
1384 for(i=0;i<fixedlen;i++) {
1385 sv1=(*(av_fetch(av,i,0)));
1386 if (sv_derived_from(sv1, "Imager::Color")) {
1387 Itmp = SvIV((SV*)SvRV(sv1));
1388 tmp = (i_color*) Itmp;
1389 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1390 fixed[i]=*tmp;
1391 }
1392 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1393 myfree(fixed);
1394 ST(0) = sv_newmortal();
1395 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1396 else sv_setiv(ST(0), (IV)RETVAL);
1397
1398
1399
1400
1401undef_int
1402i_writegifmc(im,fd,colors)
067d6bdc 1403 Imager::ImgRaw im
02d1d628
AMH
1404 int fd
1405 int colors
1406
02d1d628
AMH
1407
1408undef_int
1409i_writegif_gen(fd, ...)
1410 int fd
1411 PROTOTYPE: $$@
1412 PREINIT:
1413 i_quantize quant;
1414 i_gif_opts opts;
1415 i_img **imgs = NULL;
1416 int img_count;
1417 int i;
1418 HV *hv;
1419 CODE:
1420 if (items < 3)
1421 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1422 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1423 croak("i_writegif_gen: Second argument must be a hash ref");
1424 hv = (HV *)SvRV(ST(1));
1425 memset(&quant, 0, sizeof(quant));
1426 quant.mc_size = 256;
1427 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1428 memset(&opts, 0, sizeof(opts));
1429 handle_quant_opts(&quant, hv);
1430 handle_gif_opts(&opts, hv);
1431 img_count = items - 2;
1432 RETVAL = 1;
1433 if (img_count < 1) {
1434 RETVAL = 0;
95b44a76
TC
1435 i_clear_error();
1436 i_push_error(0, "You need to specify images to save");
02d1d628
AMH
1437 }
1438 else {
1439 imgs = mymalloc(sizeof(i_img *) * img_count);
1440 for (i = 0; i < img_count; ++i) {
1441 SV *sv = ST(2+i);
1442 imgs[i] = NULL;
1443 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1444 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1445 }
1446 else {
95b44a76
TC
1447 i_clear_error();
1448 i_push_error(0, "Only images can be saved");
02d1d628
AMH
1449 RETVAL = 0;
1450 break;
1451 }
1452 }
1453 if (RETVAL) {
1454 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1455 }
1456 myfree(imgs);
1457 if (RETVAL) {
1458 copy_colors_back(hv, &quant);
1459 }
1460 }
1461 ST(0) = sv_newmortal();
1462 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1463 else sv_setiv(ST(0), (IV)RETVAL);
1464
1465undef_int
1466i_writegif_callback(cb, maxbuffer,...)
1467 int maxbuffer;
1468 PREINIT:
1469 i_quantize quant;
1470 i_gif_opts opts;
1471 i_img **imgs = NULL;
1472 int img_count;
1473 int i;
1474 HV *hv;
1475 i_writer_data wd;
1476 CODE:
1477 if (items < 4)
1478 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1479 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1480 croak("i_writegif_callback: Second argument must be a hash ref");
1481 hv = (HV *)SvRV(ST(2));
1482 memset(&quant, 0, sizeof(quant));
1483 quant.mc_size = 256;
1484 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1485 memset(&opts, 0, sizeof(opts));
1486 handle_quant_opts(&quant, hv);
1487 handle_gif_opts(&opts, hv);
1488 img_count = items - 3;
1489 RETVAL = 1;
1490 if (img_count < 1) {
1491 RETVAL = 0;
1492 }
1493 else {
1494 imgs = mymalloc(sizeof(i_img *) * img_count);
1495 for (i = 0; i < img_count; ++i) {
1496 SV *sv = ST(3+i);
1497 imgs[i] = NULL;
1498 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1499 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1500 }
1501 else {
1502 RETVAL = 0;
1503 break;
1504 }
1505 }
1506 if (RETVAL) {
1507 wd.sv = ST(0);
1508 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1509 }
1510 myfree(imgs);
1511 if (RETVAL) {
1512 copy_colors_back(hv, &quant);
1513 }
1514 }
1515 ST(0) = sv_newmortal();
1516 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1517 else sv_setiv(ST(0), (IV)RETVAL);
1518
1519void
1520i_readgif(fd)
1521 int fd
1522 PREINIT:
1523 int* colour_table;
1524 int colours, q, w;
1525 i_img* rimg;
1526 SV* temp[3];
1527 AV* ct;
1528 SV* r;
1529 PPCODE:
1530 colour_table = NULL;
1531 colours = 0;
1532
895dbd34 1533 if(GIMME_V == G_ARRAY) {
02d1d628
AMH
1534 rimg = i_readgif(fd,&colour_table,&colours);
1535 } else {
1536 /* don't waste time with colours if they aren't wanted */
1537 rimg = i_readgif(fd,NULL,NULL);
1538 }
895dbd34 1539
02d1d628
AMH
1540 if (colour_table == NULL) {
1541 EXTEND(SP,1);
1542 r=sv_newmortal();
1543 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1544 PUSHs(r);
1545 } else {
1546 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1547 /* I don't know if I have the reference counts right or not :( */
1548 /* Neither do I :-) */
1549 /* No Idea here either */
1550
1551 ct=newAV();
1552 av_extend(ct, colours);
1553 for(q=0; q<colours; q++) {
1554 for(w=0; w<3; w++)
1555 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1556 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1557 }
1558 myfree(colour_table);
895dbd34 1559
02d1d628 1560 EXTEND(SP,2);
895dbd34 1561 r = sv_newmortal();
02d1d628
AMH
1562 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1563 PUSHs(r);
1564 PUSHs(newRV_noinc((SV*)ct));
1565 }
1566
1567
1568
1569
1570
1571void
1572i_readgif_scalar(...)
1573 PROTOTYPE: $
1574 PREINIT:
1575 char* data;
1576 unsigned int length;
1577 int* colour_table;
1578 int colours, q, w;
1579 i_img* rimg;
1580 SV* temp[3];
1581 AV* ct;
1582 SV* r;
1583 PPCODE:
1584 data = (char *)SvPV(ST(0), length);
1585 colour_table=NULL;
1586 colours=0;
1587
1588 if(GIMME_V == G_ARRAY) {
1589 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1590 } else {
1591 /* don't waste time with colours if they aren't wanted */
1592 rimg=i_readgif_scalar(data,length,NULL,NULL);
1593 }
1594
1595 if (colour_table == NULL) {
1596 EXTEND(SP,1);
1597 r=sv_newmortal();
1598 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1599 PUSHs(r);
1600 } else {
1601 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1602 /* I don't know if I have the reference counts right or not :( */
1603 /* Neither do I :-) */
1604 ct=newAV();
1605 av_extend(ct, colours);
1606 for(q=0; q<colours; q++) {
1607 for(w=0; w<3; w++)
1608 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1609 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1610 }
1611 myfree(colour_table);
1612
1613 EXTEND(SP,2);
1614 r=sv_newmortal();
1615 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1616 PUSHs(r);
1617 PUSHs(newRV_noinc((SV*)ct));
1618 }
1619
1620void
1621i_readgif_callback(...)
1622 PROTOTYPE: &
1623 PREINIT:
1624 char* data;
1625 int length;
1626 int* colour_table;
1627 int colours, q, w;
1628 i_img* rimg;
1629 SV* temp[3];
1630 AV* ct;
1631 SV* r;
1632 i_reader_data rd;
1633 PPCODE:
1634 rd.sv = ST(0);
1635 colour_table=NULL;
1636 colours=0;
1637
1638 if(GIMME_V == G_ARRAY) {
1639 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1640 } else {
1641 /* don't waste time with colours if they aren't wanted */
1642 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1643 }
1644
1645 if (colour_table == NULL) {
1646 EXTEND(SP,1);
1647 r=sv_newmortal();
1648 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1649 PUSHs(r);
1650 } else {
1651 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1652 /* I don't know if I have the reference counts right or not :( */
1653 /* Neither do I :-) */
1654 /* Neither do I - maybe I'll move this somewhere */
1655 ct=newAV();
1656 av_extend(ct, colours);
1657 for(q=0; q<colours; q++) {
1658 for(w=0; w<3; w++)
1659 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1660 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1661 }
1662 myfree(colour_table);
1663
1664 EXTEND(SP,2);
1665 r=sv_newmortal();
1666 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1667 PUSHs(r);
1668 PUSHs(newRV_noinc((SV*)ct));
1669 }
1670
faa9b3e7
TC
1671void
1672i_readgif_multi(fd)
1673 int fd
1674 PREINIT:
1675 i_img **imgs;
1676 int count;
1677 int i;
1678 PPCODE:
1679 imgs = i_readgif_multi(fd, &count);
1680 if (imgs) {
1681 EXTEND(SP, count);
1682 for (i = 0; i < count; ++i) {
1683 SV *sv = sv_newmortal();
1684 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1685 PUSHs(sv);
1686 }
1687 myfree(imgs);
1688 }
02d1d628 1689
faa9b3e7
TC
1690void
1691i_readgif_multi_scalar(data)
1692 PREINIT:
1693 i_img **imgs;
1694 int count;
1695 char *data;
1696 unsigned int length;
1697 int i;
1698 PPCODE:
1699 data = (char *)SvPV(ST(0), length);
1700 imgs = i_readgif_multi_scalar(data, length, &count);
1701 if (imgs) {
1702 EXTEND(SP, count);
1703 for (i = 0; i < count; ++i) {
1704 SV *sv = sv_newmortal();
1705 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1706 PUSHs(sv);
1707 }
1708 myfree(imgs);
1709 }
02d1d628 1710
faa9b3e7
TC
1711void
1712i_readgif_multi_callback(cb)
1713 PREINIT:
1714 i_reader_data rd;
1715 i_img **imgs;
1716 int count;
1717 int i;
1718 PPCODE:
1719 rd.sv = ST(0);
1720 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1721 if (imgs) {
1722 EXTEND(SP, count);
1723 for (i = 0; i < count; ++i) {
1724 SV *sv = sv_newmortal();
1725 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1726 PUSHs(sv);
1727 }
1728 myfree(imgs);
1729 }
02d1d628
AMH
1730
1731#endif
1732
1733
1734
1735Imager::ImgRaw
1736i_readpnm_wiol(ig, length)
1737 Imager::IO ig
1738 int length
1739
1740
067d6bdc
AMH
1741undef_int
1742i_writeppm_wiol(im, ig)
1743 Imager::ImgRaw im
1744 Imager::IO ig
1745
1746
02d1d628 1747Imager::ImgRaw
895dbd34
AMH
1748i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1749 Imager::IO ig
02d1d628
AMH
1750 int x
1751 int y
1752 int datachannels
1753 int storechannels
1754 int intrl
1755
1756undef_int
895dbd34 1757i_writeraw_wiol(im,ig)
02d1d628 1758 Imager::ImgRaw im
895dbd34
AMH
1759 Imager::IO ig
1760
261f91c5
TC
1761undef_int
1762i_writebmp_wiol(im,ig)
1763 Imager::ImgRaw im
1764 Imager::IO ig
02d1d628 1765
705fd961
TC
1766Imager::ImgRaw
1767i_readbmp_wiol(ig)
1768 Imager::IO ig
1769
1ec86afa
AMH
1770
1771undef_int
1772i_writetga_wiol(im,ig)
1773 Imager::ImgRaw im
1774 Imager::IO ig
1775
1776Imager::ImgRaw
1777i_readtga_wiol(ig, length)
1778 Imager::IO ig
1779 int length
1780
1781
02d1d628
AMH
1782Imager::ImgRaw
1783i_scaleaxis(im,Value,Axis)
1784 Imager::ImgRaw im
1785 float Value
1786 int Axis
1787
1788Imager::ImgRaw
1789i_scale_nn(im,scx,scy)
1790 Imager::ImgRaw im
1791 float scx
1792 float scy
1793
1794Imager::ImgRaw
1795i_haar(im)
1796 Imager::ImgRaw im
1797
1798int
1799i_count_colors(im,maxc)
1800 Imager::ImgRaw im
1801 int maxc
1802
1803
1804Imager::ImgRaw
1805i_transform(im,opx,opy,parm)
1806 Imager::ImgRaw im
1807 PREINIT:
1808 double* parm;
1809 int* opx;
1810 int* opy;
1811 int opxl;
1812 int opyl;
1813 int parmlen;
1814 AV* av;
1815 SV* sv1;
1816 int i;
1817 CODE:
1818 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1819 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1820 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1821 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1822 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1823 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1824 av=(AV*)SvRV(ST(1));
1825 opxl=av_len(av)+1;
1826 opx=mymalloc( opxl*sizeof(int) );
1827 for(i=0;i<opxl;i++) {
1828 sv1=(*(av_fetch(av,i,0)));
1829 opx[i]=(int)SvIV(sv1);
1830 }
1831 av=(AV*)SvRV(ST(2));
1832 opyl=av_len(av)+1;
1833 opy=mymalloc( opyl*sizeof(int) );
1834 for(i=0;i<opyl;i++) {
1835 sv1=(*(av_fetch(av,i,0)));
1836 opy[i]=(int)SvIV(sv1);
1837 }
1838 av=(AV*)SvRV(ST(3));
1839 parmlen=av_len(av)+1;
1840 parm=mymalloc( parmlen*sizeof(double) );
1841 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1842 sv1=(*(av_fetch(av,i,0)));
1843 parm[i]=(double)SvNV(sv1);
1844 }
1845 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1846 myfree(parm);
1847 myfree(opy);
1848 myfree(opx);
1849 ST(0) = sv_newmortal();
1850 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1851 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1852
1853Imager::ImgRaw
1854i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1855 PREINIT:
1856 int width;
1857 int height;
1858 double* parm;
1859 struct rm_op *ops;
1860 unsigned int ops_len;
1861 int ops_count;
1862 double *n_regs;
1863 int n_regs_count;
1864 i_color *c_regs;
1865 int c_regs_count;
1866 int in_imgs_count;
1867 i_img **in_imgs;
1868 AV* av;
1869 SV* sv1;
1870 IV tmp;
1871 int i;
1872 CODE:
1873 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1874 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1875 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1876 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1877 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1878
1879 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1880
1881 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1882 av = (AV*)SvRV(ST(5));
1883 in_imgs_count = av_len(av)+1;
1884 for (i = 0; i < in_imgs_count; ++i) {
1885 sv1 = *av_fetch(av, i, 0);
1886 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1887 croak("Parameter 5 must contain only images");
1888 }
1889 }
1890 }
1891 else {
1892 in_imgs_count = 0;
1893 }
1894 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1895 av = (AV*)SvRV(ST(5));
1896 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1897 for (i = 0; i < in_imgs_count; ++i) {
1898 sv1 = *av_fetch(av,i,0);
1899 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1900 croak("Parameter 5 must contain only images");
1901 }
1902 tmp = SvIV((SV*)SvRV(sv1));
1903 in_imgs[i] = (i_img*)tmp;
1904 }
1905 }
1906 else {
1907 /* no input images */
1908 in_imgs = NULL;
1909 }
1910 /* default the output size from the first input if possible */
1911 if (SvOK(ST(0)))
1912 width = SvIV(ST(0));
1913 else if (in_imgs_count)
1914 width = in_imgs[0]->xsize;
1915 else
1916 croak("No output image width supplied");
1917
1918 if (SvOK(ST(1)))
1919 height = SvIV(ST(1));
1920 else if (in_imgs_count)
1921 height = in_imgs[0]->ysize;
1922 else
1923 croak("No output image height supplied");
1924
1925 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1926 if (ops_len % sizeof(struct rm_op))
1927 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1928 ops_count = ops_len / sizeof(struct rm_op);
1929 av = (AV*)SvRV(ST(3));
1930 n_regs_count = av_len(av)+1;
1931 n_regs = mymalloc(n_regs_count * sizeof(double));
1932 for (i = 0; i < n_regs_count; ++i) {
1933 sv1 = *av_fetch(av,i,0);
1934 if (SvOK(sv1))
1935 n_regs[i] = SvNV(sv1);
1936 }
1937 av = (AV*)SvRV(ST(4));
1938 c_regs_count = av_len(av)+1;
1939 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1940 /* I don't bother initializing the colou?r registers */
1941
1942 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1943 n_regs, n_regs_count,
1944 c_regs, c_regs_count, in_imgs, in_imgs_count);
1945 if (in_imgs)
1946 myfree(in_imgs);
1947 myfree(n_regs);
1948 myfree(c_regs);
1949 ST(0) = sv_newmortal();
1950 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1951 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1952
1953
1954void
1955i_contrast(im,intensity)
1956 Imager::ImgRaw im
1957 float intensity
1958
1959void
1960i_hardinvert(im)
1961 Imager::ImgRaw im
1962
1963void
1964i_noise(im,amount,type)
1965 Imager::ImgRaw im
1966 float amount
1967 unsigned char type
1968
1969void
1970i_bumpmap(im,bump,channel,light_x,light_y,strength)
1971 Imager::ImgRaw im
1972 Imager::ImgRaw bump
1973 int channel
1974 int light_x
1975 int light_y
1976 int strength
1977
1978void
1979i_postlevels(im,levels)
1980 Imager::ImgRaw im
1981 int levels
1982
1983void
1984i_mosaic(im,size)
1985 Imager::ImgRaw im
1986 int size
1987
1988void
1989i_watermark(im,wmark,tx,ty,pixdiff)
1990 Imager::ImgRaw im
1991 Imager::ImgRaw wmark
1992 int tx
1993 int ty
1994 int pixdiff
1995
1996
1997void
1998i_autolevels(im,lsat,usat,skew)
1999 Imager::ImgRaw im
2000 float lsat
2001 float usat
2002 float skew
2003
2004void
2005i_radnoise(im,xo,yo,rscale,ascale)
2006 Imager::ImgRaw im
2007 float xo
2008 float yo
2009 float rscale
2010 float ascale
2011
2012void
2013i_turbnoise(im, xo, yo, scale)
2014 Imager::ImgRaw im
2015 float xo
2016 float yo
2017 float scale
2018
2019
2020void
2021i_gradgen(im, ...)
2022 Imager::ImgRaw im
2023 PREINIT:
2024 int num;
2025 int *xo;
2026 int *yo;
2027 i_color *ival;
2028 int dmeasure;
2029 int i;
2030 SV *sv;
2031 AV *axx;
2032 AV *ayy;
2033 AV *ac;
2034 CODE:
2035 if (items != 5)
2036 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2037 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2038 croak("i_gradgen: Second argument must be an array ref");
2039 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2040 croak("i_gradgen: Third argument must be an array ref");
2041 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2042 croak("i_gradgen: Fourth argument must be an array ref");
2043 axx = (AV *)SvRV(ST(1));
2044 ayy = (AV *)SvRV(ST(2));
2045 ac = (AV *)SvRV(ST(3));
2046 dmeasure = (int)SvIV(ST(4));
2047
2048 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2049 num = num <= av_len(ac) ? num : av_len(ac);
2050 num++;
2051 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2052 xo = mymalloc( sizeof(int) * num );
2053 yo = mymalloc( sizeof(int) * num );
2054 ival = mymalloc( sizeof(i_color) * num );
2055 for(i = 0; i<num; i++) {
2056 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2057 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2058 sv = *av_fetch(ac, i, 0);
2059 if ( !sv_derived_from(sv, "Imager::Color") ) {
2060 free(axx); free(ayy); free(ac);
2061 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2062 }
2063 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2064 }
2065 i_gradgen(im, num, xo, yo, ival, dmeasure);
2066
6607600c
TC
2067void
2068i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2069 Imager::ImgRaw im
2070 double xa
2071 double ya
2072 double xb
2073 double yb
2074 int type
2075 int repeat
2076 int combine
2077 int super_sample
2078 double ssample_param
2079 PREINIT:
6607600c 2080 AV *asegs;
6607600c
TC
2081 int count;
2082 i_fountain_seg *segs;
6607600c 2083 CODE:
6607600c
TC
2084 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2085 croak("i_fountain: argument 11 must be an array ref");
2086
2087 asegs = (AV *)SvRV(ST(10));
f1ac5027 2088 segs = load_fount_segs(asegs, &count);
6607600c
TC
2089 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2090 ssample_param, count, segs);
2091 myfree(segs);
02d1d628 2092
f1ac5027
TC
2093Imager::FillHandle
2094i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2095 double xa
2096 double ya
2097 double xb
2098 double yb
2099 int type
2100 int repeat
2101 int combine
2102 int super_sample
2103 double ssample_param
2104 PREINIT:
2105 AV *asegs;
2106 int count;
2107 i_fountain_seg *segs;
2108 CODE:
2109 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2110 croak("i_fountain: argument 11 must be an array ref");
2111
2112 asegs = (AV *)SvRV(ST(9));
2113 segs = load_fount_segs(asegs, &count);
2114 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2115 super_sample, ssample_param, count, segs);
2116 myfree(segs);
2117 OUTPUT:
2118 RETVAL
2119
4f4f776a
TC
2120void
2121i_errors()
2122 PREINIT:
2123 i_errmsg *errors;
2124 int i;
4f4f776a
TC
2125 AV *av;
2126 SV *ref;
2127 SV *sv;
2128 PPCODE:
2129 errors = i_errors();
2130 i = 0;
2131 while (errors[i].msg) {
2132 av = newAV();
2133 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2134 if (!av_store(av, 0, sv)) {
2135 SvREFCNT_dec(sv);
2136 }
2137 sv = newSViv(errors[i].code);
2138 if (!av_store(av, 1, sv)) {
2139 SvREFCNT_dec(sv);
2140 }
2141 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2142 ++i;
2143 }
02d1d628
AMH
2144
2145void
2146i_nearest_color(im, ...)
2147 Imager::ImgRaw im
2148 PREINIT:
2149 int num;
2150 int *xo;
2151 int *yo;
2152 i_color *ival;
2153 int dmeasure;
2154 int i;
2155 SV *sv;
2156 AV *axx;
2157 AV *ayy;
2158 AV *ac;
2159 CODE:
2160 if (items != 5)
2161 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2162 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2163 croak("i_nearest_color: Second argument must be an array ref");
2164 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2165 croak("i_nearest_color: Third argument must be an array ref");
2166 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2167 croak("i_nearest_color: Fourth argument must be an array ref");
2168 axx = (AV *)SvRV(ST(1));
2169 ayy = (AV *)SvRV(ST(2));
2170 ac = (AV *)SvRV(ST(3));
2171 dmeasure = (int)SvIV(ST(4));
2172
2173 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2174 num = num <= av_len(ac) ? num : av_len(ac);
2175 num++;
2176 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2177 xo = mymalloc( sizeof(int) * num );
2178 yo = mymalloc( sizeof(int) * num );
2179 ival = mymalloc( sizeof(i_color) * num );
2180 for(i = 0; i<num; i++) {
2181 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2182 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2183 sv = *av_fetch(ac, i, 0);
2184 if ( !sv_derived_from(sv, "Imager::Color") ) {
2185 free(axx); free(ayy); free(ac);
2186 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2187 }
2188 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2189 }
2190 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2191
2192
2193
2194
2195void
2196malloc_state()
2197
2198void
2199hashinfo(hv)
2200 PREINIT:
2201 HV* hv;
2202 int stuff;
2203 PPCODE:
2204 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2205 hv=(HV*)SvRV(ST(0));
2206 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2207 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2208 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2209
2210void
2211DSO_open(filename)
2212 char* filename
2213 PREINIT:
2214 void *rc;
2215 char *evstr;
2216 PPCODE:
2217 rc=DSO_open(filename,&evstr);
2218 if (rc!=NULL) {
2219 if (evstr!=NULL) {
2220 EXTEND(SP,2);
2221 PUSHs(sv_2mortal(newSViv((IV)rc)));
2222 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2223 } else {
2224 EXTEND(SP,1);
2225 PUSHs(sv_2mortal(newSViv((IV)rc)));
2226 }
2227 }
2228
2229
2230undef_int
2231DSO_close(dso_handle)
2232 void* dso_handle
2233
2234void
2235DSO_funclist(dso_handle_v)
2236 void* dso_handle_v
2237 PREINIT:
2238 int i;
2239 DSO_handle *dso_handle;
2240 PPCODE:
2241 dso_handle=(DSO_handle*)dso_handle_v;
2242 i=0;
2243 while( dso_handle->function_list[i].name != NULL) {
2244 EXTEND(SP,1);
2245 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2246 EXTEND(SP,1);
2247 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2248 }
2249
2250
2251void
2252DSO_call(handle,func_index,hv)
2253 void* handle
2254 int func_index
2255 PREINIT:
2256 HV* hv;
2257 PPCODE:
2258 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2259 hv=(HV*)SvRV(ST(2));
2260 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2261 DSO_call( (DSO_handle *)handle,func_index,hv);
2262
2263
2264
f5991c03 2265# this is mostly for testing...
faa9b3e7 2266SV *
f5991c03
TC
2267i_get_pixel(im, x, y)
2268 Imager::ImgRaw im
2269 int x
2270 int y;
faa9b3e7
TC
2271 PREINIT:
2272 i_color *color;
2273 CODE:
2274 color = (i_color *)mymalloc(sizeof(i_color));
2275 if (i_gpix(im, x, y, color) == 0) {
2276 ST(0) = sv_newmortal();
2277 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2278 }
2279 else {
2280 myfree(color);
2281 ST(0) = &PL_sv_undef;
2282 }
2283
2284
2285int
2286i_ppix(im, x, y, cl)
2287 Imager::ImgRaw im
2288 int x
2289 int y
2290 Imager::Color cl
2291
2292Imager::ImgRaw
2293i_img_pal_new(x, y, channels, maxpal)
2294 int x
2295 int y
2296 int channels
2297 int maxpal
2298
2299Imager::ImgRaw
2300i_img_to_pal(src, quant)
2301 Imager::ImgRaw src
2302 PREINIT:
2303 HV *hv;
2304 i_quantize quant;
2305 CODE:
2306 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2307 croak("i_img_to_pal: second argument must be a hash ref");
2308 hv = (HV *)SvRV(ST(1));
2309 memset(&quant, 0, sizeof(quant));
2310 quant.mc_size = 256;
2311 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2312 handle_quant_opts(&quant, hv);
2313 RETVAL = i_img_to_pal(src, &quant);
2314 if (RETVAL) {
2315 copy_colors_back(hv, &quant);
2316 }
2317 myfree(quant.mc_colors);
2318 OUTPUT:
2319 RETVAL
2320
2321Imager::ImgRaw
2322i_img_to_rgb(src)
2323 Imager::ImgRaw src
2324
2325void
2326i_gpal(im, l, r, y)
2327 Imager::ImgRaw im
2328 int l
2329 int r
2330 int y
2331 PREINIT:
2332 i_palidx *work;
2333 int count, i;
2334 PPCODE:
2335 if (l < r) {
2336 work = mymalloc((r-l) * sizeof(i_palidx));
2337 count = i_gpal(im, l, r, y, work);
2338 if (GIMME_V == G_ARRAY) {
2339 EXTEND(SP, count);
2340 for (i = 0; i < count; ++i) {
2341 PUSHs(sv_2mortal(newSViv(work[i])));
2342 }
2343 }
2344 else {
2345 EXTEND(SP, 1);
2346 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2347 }
2348 myfree(work);
2349 }
2350 else {
2351 if (GIMME_V != G_ARRAY) {
2352 EXTEND(SP, 1);
2353 PUSHs(&PL_sv_undef);
2354 }
2355 }
2356
2357int
2358i_ppal(im, l, y, ...)
2359 Imager::ImgRaw im
2360 int l
2361 int y
2362 PREINIT:
2363 i_palidx *work;
2364 int count, i;
2365 CODE:
2366 if (items > 3) {
2367 work = mymalloc(sizeof(i_palidx) * (items-3));
2368 for (i=0; i < items-3; ++i) {
2369 work[i] = SvIV(ST(i+3));
2370 }
2371 RETVAL = i_ppal(im, l, l+items-3, y, work);
2372 myfree(work);
2373 }
2374 else {
2375 RETVAL = 0;
2376 }
2377 OUTPUT:
2378 RETVAL
2379
2380SV *
2381i_addcolors(im, ...)
2382 Imager::ImgRaw im
2383 PREINIT:
2384 int index;
2385 i_color *colors;
2386 int i;
2387 CODE:
2388 if (items < 2)
2389 croak("i_addcolors: no colors to add");
2390 colors = mymalloc((items-1) * sizeof(i_color));
2391 for (i=0; i < items-1; ++i) {
2392 if (sv_isobject(ST(i+1))
2393 && sv_derived_from(ST(i+1), "Imager::Color")) {
2394 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2395 colors[i] = *(i_color *)tmp;
2396 }
2397 else {
2398 myfree(colors);
2399 croak("i_plin: pixels must be Imager::Color objects");
2400 }
2401 }
2402 index = i_addcolors(im, colors, items-1);
2403 myfree(colors);
2404 if (index == 0) {
2405 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2406 }
2407 else if (index == -1) {
2408 ST(0) = &PL_sv_undef;
2409 }
2410 else {
2411 ST(0) = sv_2mortal(newSViv(index));
2412 }
2413
2414int
2415i_setcolors(im, index, ...)
2416 Imager::ImgRaw im
2417 int index
2418 PREINIT:
2419 i_color *colors;
2420 int i;
2421 CODE:
2422 if (items < 3)
2423 croak("i_setcolors: no colors to add");
2424 colors = mymalloc((items-2) * sizeof(i_color));
2425 for (i=0; i < items-2; ++i) {
2426 if (sv_isobject(ST(i+2))
2427 && sv_derived_from(ST(i+2), "Imager::Color")) {
2428 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2429 colors[i] = *(i_color *)tmp;
2430 }
2431 else {
2432 myfree(colors);
2433 croak("i_setcolors: pixels must be Imager::Color objects");
2434 }
2435 }
2436 RETVAL = i_setcolors(im, index, colors, items-2);
2437 myfree(colors);
2438
2439void
2440i_getcolors(im, index, ...)
2441 Imager::ImgRaw im
2442 int index
2443 PREINIT:
2444 i_color *colors;
2445 int count = 1;
2446 int i;
2447 PPCODE:
2448 if (items > 3)
2449 croak("i_getcolors: too many arguments");
2450 if (items == 3)
2451 count = SvIV(ST(2));
2452 if (count < 1)
2453 croak("i_getcolors: count must be positive");
2454 colors = mymalloc(sizeof(i_color) * count);
2455 if (i_getcolors(im, index, colors, count)) {
2456 for (i = 0; i < count; ++i) {
2457 i_color *pv;
2458 SV *sv = sv_newmortal();
2459 pv = mymalloc(sizeof(i_color));
2460 *pv = colors[i];
2461 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2462 PUSHs(sv);
2463 }
2464 }
2465 myfree(colors);
2466
2467
2468SV *
2469i_colorcount(im)
2470 Imager::ImgRaw im
2471 PREINIT:
2472 int count;
2473 CODE:
2474 count = i_colorcount(im);
2475 if (count >= 0) {
2476 ST(0) = sv_2mortal(newSViv(count));
2477 }
2478 else {
2479 ST(0) = &PL_sv_undef;
2480 }
2481
2482SV *
2483i_maxcolors(im)
2484 Imager::ImgRaw im
2485 PREINIT:
2486 int count;
2487 CODE:
2488 count = i_maxcolors(im);
2489 if (count >= 0) {
2490 ST(0) = sv_2mortal(newSViv(count));
2491 }
2492 else {
2493 ST(0) = &PL_sv_undef;
2494 }
2495
2496SV *
2497i_findcolor(im, color)
2498 Imager::ImgRaw im
2499 Imager::Color color
2500 PREINIT:
2501 i_palidx index;
2502 CODE:
2503 if (i_findcolor(im, color, &index)) {
2504 ST(0) = sv_2mortal(newSViv(index));
2505 }
2506 else {
2507 ST(0) = &PL_sv_undef;
2508 }
2509
2510int
2511i_img_bits(im)
2512 Imager::ImgRaw im
2513
2514int
2515i_img_type(im)
2516 Imager::ImgRaw im
2517
2518int
2519i_img_virtual(im)
2520 Imager::ImgRaw im
2521
2522void
2523i_gsamp(im, l, r, y, ...)
2524 Imager::ImgRaw im
2525 int l
2526 int r
2527 int y
2528 PREINIT:
2529 int *chans;
2530 int chan_count;
2531 i_sample_t *data;
2532 int count, i;
2533 PPCODE:
2534 if (items < 5)
2535 croak("No channel numbers supplied to g_samp()");
2536 if (l < r) {
2537 chan_count = items - 4;
2538 chans = mymalloc(sizeof(int) * chan_count);
2539 for (i = 0; i < chan_count; ++i)
2540 chans[i] = SvIV(ST(i+4));
2541 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count);
2542 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2543 if (GIMME_V == G_ARRAY) {
2544 EXTEND(SP, count);
2545 for (i = 0; i < count; ++i)
2546 PUSHs(sv_2mortal(newSViv(data[i])));
2547 }
2548 else {
2549 EXTEND(SP, 1);
2550 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2551 }
2552 }
2553 else {
2554 if (GIMME_V != G_ARRAY) {
2555 EXTEND(SP, 1);
2556 PUSHs(&PL_sv_undef);
2557 }
2558 }
2559
2560Imager::ImgRaw
2561i_img_masked_new(targ, mask, x, y, w, h)
2562 Imager::ImgRaw targ
2563 int x
2564 int y
2565 int w
2566 int h
2567 PREINIT:
2568 i_img *mask;
2569 CODE:
2570 if (SvOK(ST(1))) {
2571 if (!sv_isobject(ST(1))
2572 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2573 croak("i_img_masked_new: parameter 2 must undef or an image");
2574 }
2575 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2576 }
2577 else
2578 mask = NULL;
2579 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2580 OUTPUT:
2581 RETVAL
2582
2583int
2584i_plin(im, l, y, ...)
2585 Imager::ImgRaw im
2586 int l
2587 int y
2588 PREINIT:
2589 i_color *work;
2590 int count, i;
2591 CODE:
2592 if (items > 3) {
2593 work = mymalloc(sizeof(i_color) * (items-3));
2594 for (i=0; i < items-3; ++i) {
2595 if (sv_isobject(ST(i+3))
2596 && sv_derived_from(ST(i+3), "Imager::Color")) {
2597 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2598 work[i] = *(i_color *)tmp;
2599 }
2600 else {
2601 myfree(work);
2602 croak("i_plin: pixels must be Imager::Color objects");
2603 }
2604 }
2605 /**(char *)0 = 1;*/
2606 RETVAL = i_plin(im, l, l+items-3, y, work);
2607 myfree(work);
2608 }
2609 else {
2610 RETVAL = 0;
2611 }
2612 OUTPUT:
2613 RETVAL
2614
2615int
2616i_ppixf(im, x, y, cl)
2617 Imager::ImgRaw im
2618 int x
2619 int y
2620 Imager::Color::Float cl
2621
2622void
2623i_gsampf(im, l, r, y, ...)
2624 Imager::ImgRaw im
2625 int l
2626 int r
2627 int y
2628 PREINIT:
2629 int *chans;
2630 int chan_count;
2631 i_fsample_t *data;
2632 int count, i;
2633 PPCODE:
2634 if (items < 5)
2635 croak("No channel numbers supplied to g_sampf()");
2636 if (l < r) {
2637 chan_count = items - 4;
2638 chans = mymalloc(sizeof(int) * chan_count);
2639 for (i = 0; i < chan_count; ++i)
2640 chans[i] = SvIV(ST(i+4));
2641 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2642 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2643 if (GIMME_V == G_ARRAY) {
2644 EXTEND(SP, count);
2645 for (i = 0; i < count; ++i)
2646 PUSHs(sv_2mortal(newSVnv(data[i])));
2647 }
2648 else {
2649 EXTEND(SP, 1);
2650 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2651 }
2652 }
2653 else {
2654 if (GIMME_V != G_ARRAY) {
2655 EXTEND(SP, 1);
2656 PUSHs(&PL_sv_undef);
2657 }
2658 }
2659
2660int
2661i_plinf(im, l, y, ...)
2662 Imager::ImgRaw im
2663 int l
2664 int y
2665 PREINIT:
2666 i_fcolor *work;
2667 int count, i;
2668 CODE:
2669 if (items > 3) {
2670 work = mymalloc(sizeof(i_fcolor) * (items-3));
2671 for (i=0; i < items-3; ++i) {
2672 if (sv_isobject(ST(i+3))
2673 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2674 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2675 work[i] = *(i_fcolor *)tmp;
2676 }
2677 else {
2678 myfree(work);
2679 croak("i_plin: pixels must be Imager::Color::Float objects");
2680 }
2681 }
2682 /**(char *)0 = 1;*/
2683 RETVAL = i_plinf(im, l, l+items-3, y, work);
2684 myfree(work);
2685 }
2686 else {
2687 RETVAL = 0;
2688 }
2689 OUTPUT:
2690 RETVAL
2691
2692SV *
2693i_gpixf(im, x, y)
2694 Imager::ImgRaw im
2695 int x
2696 int y;
2697 PREINIT:
2698 i_fcolor *color;
2699 CODE:
2700 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2701 if (i_gpixf(im, x, y, color) == 0) {
2702 ST(0) = sv_newmortal();
2703 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2704 }
2705 else {
2706 myfree(color);
2707 ST(0) = &PL_sv_undef;
2708 }
2709
2710void
2711i_glin(im, l, r, y)
2712 Imager::ImgRaw im
2713 int l
2714 int r
2715 int y
2716 PREINIT:
2717 i_color *vals;
2718 int count, i;
2719 PPCODE:
2720 if (l < r) {
2721 vals = mymalloc((r-l) * sizeof(i_color));
2722 count = i_glin(im, l, r, y, vals);
2723 EXTEND(SP, count);
2724 for (i = 0; i < count; ++i) {
2725 SV *sv;
2726 i_color *col = mymalloc(sizeof(i_color));
2727 sv = sv_newmortal();
2728 sv_setref_pv(sv, "Imager::Color", (void *)col);
2729 PUSHs(sv);
2730 }
2731 myfree(vals);
2732 }
2733
2734void
2735i_glinf(im, l, r, y)
2736 Imager::ImgRaw im
2737 int l
2738 int r
2739 int y
2740 PREINIT:
2741 i_fcolor *vals;
2742 int count, i;
2743 PPCODE:
2744 if (l < r) {
2745 vals = mymalloc((r-l) * sizeof(i_fcolor));
2746 count = i_glinf(im, l, r, y, vals);
2747 EXTEND(SP, count);
2748 for (i = 0; i < count; ++i) {
2749 SV *sv;
2750 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2751 *col = vals[i];
2752 sv = sv_newmortal();
2753 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2754 PUSHs(sv);
2755 }
2756 myfree(vals);
2757 }
2758
2759Imager::ImgRaw
2760i_img_16_new(x, y, ch)
2761 int x
2762 int y
2763 int ch
2764
2765undef_int
2766i_tags_addn(im, name, code, idata)
2767 Imager::ImgRaw im
2768 int code
2769 int idata
2770 PREINIT:
2771 char *name;
2772 STRLEN len;
2773 CODE:
2774 if (SvOK(ST(1)))
2775 name = SvPV(ST(1), len);
2776 else
2777 name = NULL;
2778 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2779 OUTPUT:
2780 RETVAL
2781
2782undef_int
2783i_tags_add(im, name, code, data, idata)
2784 Imager::ImgRaw im
2785 int code
2786 int idata
2787 PREINIT:
2788 char *name;
2789 char *data;
2790 STRLEN len;
2791 CODE:
2792 if (SvOK(ST(1)))
2793 name = SvPV(ST(1), len);
2794 else
2795 name = NULL;
2796 if (SvOK(ST(3)))
2797 data = SvPV(ST(3), len);
2798 else {
2799 data = NULL;
2800 len = 0;
2801 }
2802 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2803 OUTPUT:
2804 RETVAL
2805
2806SV *
2807i_tags_find(im, name, start)
2808 Imager::ImgRaw im
2809 char *name
2810 int start
2811 PREINIT:
2812 int entry;
2813 CODE:
2814 if (i_tags_find(&im->tags, name, start, &entry)) {
2815 if (entry == 0)
2816 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2817 else
2818 ST(0) = sv_2mortal(newSViv(entry));
2819 } else {
2820 ST(0) = &PL_sv_undef;
2821 }
2822
2823SV *
2824i_tags_findn(im, code, start)
2825 Imager::ImgRaw im
2826 int code
2827 int start
2828 PREINIT:
2829 int entry;
2830 CODE:
2831 if (i_tags_findn(&im->tags, code, start, &entry)) {
2832 if (entry == 0)
2833 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2834 else
2835 ST(0) = sv_2mortal(newSViv(entry));
2836 }
2837 else
2838 ST(0) = &PL_sv_undef;
2839
2840int
2841i_tags_delete(im, entry)
2842 Imager::ImgRaw im
2843 int entry
2844 CODE:
2845 RETVAL = i_tags_delete(&im->tags, entry);
2846 OUTPUT:
2847 RETVAL
2848
2849int
2850i_tags_delbyname(im, name)
2851 Imager::ImgRaw im
2852 char * name
2853 CODE:
2854 RETVAL = i_tags_delbyname(&im->tags, name);
2855 OUTPUT:
2856 RETVAL
2857
2858int
2859i_tags_delbycode(im, code)
2860 Imager::ImgRaw im
2861 int code
2862 CODE:
2863 RETVAL = i_tags_delbycode(&im->tags, code);
2864 OUTPUT:
2865 RETVAL
2866
2867void
2868i_tags_get(im, index)
2869 Imager::ImgRaw im
2870 int index
2871 PPCODE:
2872 if (index >= 0 && index < im->tags.count) {
2873 i_img_tag *entry = im->tags.tags + index;
2874 EXTEND(SP, 5);
2875
2876 if (entry->name) {
2877 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2878 }
2879 else {
2880 PUSHs(sv_2mortal(newSViv(entry->code)));
2881 }
2882 if (entry->data) {
2883 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2884 }
2885 else {
2886 PUSHs(sv_2mortal(newSViv(entry->idata)));
2887 }
2888 }
2889
2890int
2891i_tags_count(im)
2892 Imager::ImgRaw im
2893 CODE:
2894 RETVAL = im->tags.count;
2895 OUTPUT:
2896 RETVAL
2897
2898#ifdef HAVE_WIN32
2899
2900void
2901i_wf_bbox(face, size, text)
2902 char *face
2903 int size
2904 char *text
2905 PREINIT:
2906 int cords[6];
2907 PPCODE:
2908 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
2909 EXTEND(SP, 6);
2910 PUSHs(sv_2mortal(newSViv(cords[0])));
2911 PUSHs(sv_2mortal(newSViv(cords[1])));
2912 PUSHs(sv_2mortal(newSViv(cords[2])));
2913 PUSHs(sv_2mortal(newSViv(cords[3])));
2914 PUSHs(sv_2mortal(newSViv(cords[4])));
2915 PUSHs(sv_2mortal(newSViv(cords[5])));
2916 }
2917
2918undef_int
2919i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
2920 char *face
2921 Imager::ImgRaw im
2922 int tx
2923 int ty
2924 Imager::Color cl
2925 int size
2926 char *text
2927 int align
2928 int aa
2929 CODE:
2930 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
2931 align, aa);
2932 OUTPUT:
2933 RETVAL
2934
2935undef_int
2936i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
2937 char *face
2938 Imager::ImgRaw im
2939 int tx
2940 int ty
2941 int channel
2942 int size
2943 char *text
2944 int align
2945 int aa
f5991c03 2946 CODE:
faa9b3e7
TC
2947 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
2948 align, aa);
f5991c03
TC
2949 OUTPUT:
2950 RETVAL
02d1d628 2951
faa9b3e7
TC
2952
2953#endif
2954
2955#ifdef HAVE_FT2
2956
2957MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
2958
2959#define FT2_DESTROY(font) i_ft2_destroy(font)
2960
2961void
2962FT2_DESTROY(font)
2963 Imager::Font::FT2 font
2964
2965MODULE = Imager PACKAGE = Imager::Font::FreeType2
2966
2967Imager::Font::FT2
2968i_ft2_new(name, index)
2969 char *name
2970 int index
2971
2972undef_int
2973i_ft2_setdpi(font, xdpi, ydpi)
2974 Imager::Font::FT2 font
2975 int xdpi
2976 int ydpi
2977
2978void
2979i_ft2_getdpi(font)
2980 Imager::Font::FT2 font
2981 PREINIT:
2982 int xdpi, ydpi;
2983 CODE:
2984 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
2985 EXTEND(SP, 2);
2986 PUSHs(sv_2mortal(newSViv(xdpi)));
2987 PUSHs(sv_2mortal(newSViv(ydpi)));
2988 }
2989
2990undef_int
2991i_ft2_sethinting(font, hinting)
2992 Imager::Font::FT2 font
2993 int hinting
2994
2995undef_int
2996i_ft2_settransform(font, matrix)
2997 Imager::Font::FT2 font
2998 PREINIT:
2999 double matrix[6];
3000 int len;
3001 AV *av;
3002 SV *sv1;
3003 int i;
3004 CODE:
3005 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3006 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3007 av=(AV*)SvRV(ST(1));
3008 len=av_len(av)+1;
3009 if (len > 6)
3010 len = 6;
3011 for (i = 0; i < len; ++i) {
3012 sv1=(*(av_fetch(av,i,0)));
3013 matrix[i] = SvNV(sv1);
3014 }
3015 for (; i < 6; ++i)
3016 matrix[i] = 0;
3017 RETVAL = i_ft2_settransform(font, matrix);
3018 OUTPUT:
3019 RETVAL
3020
3021void
3022i_ft2_bbox(font, cheight, cwidth, text)
3023 Imager::Font::FT2 font
3024 double cheight
3025 double cwidth
3026 char *text
3027 PREINIT:
3028 int bbox[6];
3029 int i;
3030 PPCODE:
3031 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
3032 EXTEND(SP, 6);
3033 for (i = 0; i < 6; ++i)
3034 PUSHs(sv_2mortal(newSViv(bbox[i])));
3035 }
3036
3037void
3038i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3039 Imager::Font::FT2 font
3040 double cheight
3041 double cwidth
3042 char *text
3043 int vlayout
3044 int utf8
3045 PREINIT:
3046 int bbox[8];
3047 int i;
3048 PPCODE:
3049#ifdef SvUTF8
3050 if (SvUTF8(ST(3)))
3051 utf8 = 1;
3052#endif
3053 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3054 utf8, bbox)) {
3055 EXTEND(SP, 8);
3056 for (i = 0; i < 8; ++i)
3057 PUSHs(sv_2mortal(newSViv(bbox[i])));
3058 }
3059
3060undef_int
3061i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3062 Imager::Font::FT2 font
3063 Imager::ImgRaw im
3064 int tx
3065 int ty
3066 Imager::Color cl
3067 double cheight
3068 double cwidth
3069 int align
3070 int aa
3071 int vlayout
3072 int utf8
3073 PREINIT:
3074 char *text;
3075 STRLEN len;
3076 CODE:
3077#ifdef SvUTF8
3078 if (SvUTF8(ST(7))) {
3079 utf8 = 1;
3080 }
3081#endif
3082 text = SvPV(ST(7), len);
3083 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3084 len, align, aa, vlayout, utf8);
3085 OUTPUT:
3086 RETVAL
3087
3088undef_int
3089i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3090 Imager::Font::FT2 font
3091 Imager::ImgRaw im
3092 int tx
3093 int ty
3094 int channel
3095 double cheight
3096 double cwidth
3097 char *text
3098 int align
3099 int aa
3100 int vlayout
3101 int utf8
3102 CODE:
3103#ifdef SvUTF8
3104 if (SvUTF8(ST(7)))
3105 utf8 = 1;
3106#endif
3107 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3108 strlen(text), align, aa, vlayout, 1);
3109 OUTPUT:
3110 RETVAL
3111
3112void
3113ft2_transform_box(font, x0, x1, x2, x3)
3114 Imager::Font::FT2 font
3115 int x0
3116 int x1
3117 int x2
3118 int x3
3119 PREINIT:
3120 int box[4];
3121 PPCODE:
3122 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3123 ft2_transform_box(font, box);
3124 EXTEND(SP, 4);
3125 PUSHs(sv_2mortal(newSViv(box[0])));
3126 PUSHs(sv_2mortal(newSViv(box[1])));
3127 PUSHs(sv_2mortal(newSViv(box[2])));
3128 PUSHs(sv_2mortal(newSViv(box[3])));
3129
3130#endif
3131
f1ac5027
TC
3132MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3133
3134void
3135IFILL_DESTROY(fill)
3136 Imager::FillHandle fill
3137
3138MODULE = Imager PACKAGE = Imager
3139
3140Imager::FillHandle
3141i_new_fill_solid(cl, combine)
3142 Imager::Color cl
3143 int combine
3144
3145Imager::FillHandle
3146i_new_fill_solidf(cl, combine)
3147 Imager::Color::Float cl
3148 int combine
3149
3150Imager::FillHandle
3151i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3152 Imager::Color fg
3153 Imager::Color bg
3154 int combine
3155 int hatch
3156 int dx
3157 int dy
3158 PREINIT:
3159 unsigned char *cust_hatch;
3160 STRLEN len;
3161 CODE:
3162 if (SvOK(ST(4))) {
3163 cust_hatch = SvPV(ST(4), len);
3164 }
3165 else
3166 cust_hatch = NULL;
3167 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3168 OUTPUT:
3169 RETVAL
3170
efdc2568
TC
3171Imager::FillHandle
3172i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3173 Imager::Color::Float fg
3174 Imager::Color::Float bg
3175 int combine
3176 int hatch
3177 int dx
3178 int dy
3179 PREINIT:
3180 unsigned char *cust_hatch;
3181 STRLEN len;
3182 CODE:
3183 if (SvOK(ST(4))) {
3184 cust_hatch = SvPV(ST(4), len);
3185 }
3186 else
3187 cust_hatch = NULL;
3188 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3189 OUTPUT:
3190 RETVAL
3191