Fixes to i_map function and map method. Added a testcase for both.
[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;
19typedef i_img* Imager__ImgRaw;
20
21
22#ifdef HAVE_LIBTT
23typedef TT_Fonthandle* Imager__TTHandle;
24#endif
25
26typedef struct i_reader_data_tag
27{
28 /* presumably a CODE ref or name of a sub */
29 SV *sv;
30} i_reader_data;
31
32/* used by functions that want callbacks */
33static int read_callback(char *userdata, char *buffer, int need, int want) {
34 i_reader_data *rd = (i_reader_data *)userdata;
35 int count;
36 int result;
37 SV *data;
38 dSP; dTARG = sv_newmortal();
39 /* thanks to Simon Cozens for help with the dTARG above */
40
41 ENTER;
42 SAVETMPS;
43 EXTEND(SP, 2);
44 PUSHMARK(SP);
45 PUSHi(want);
46 PUSHi(need);
47 PUTBACK;
48
49 count = perl_call_sv(rd->sv, G_SCALAR);
50
51 SPAGAIN;
52
53 if (count != 1)
54 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
55
56 data = POPs;
57
58 if (SvOK(data)) {
59 STRLEN len;
60 char *ptr = SvPV(data, len);
61 if (len > want)
62 croak("Too much data returned in reader callback");
63
64 memcpy(buffer, ptr, len);
65 result = len;
66 }
67 else {
68 result = -1;
69 }
70
71 PUTBACK;
72 FREETMPS;
73 LEAVE;
74
75 return result;
76}
77
78typedef struct
79{
80 SV *sv; /* a coderef or sub name */
81} i_writer_data;
82
83/* used by functions that want callbacks */
84static int write_callback(char *userdata, char const *data, int size) {
85 i_writer_data *wd = (i_writer_data *)userdata;
86 int count;
87 int success;
88 SV *sv;
89 dSP;
90
91 ENTER;
92 SAVETMPS;
93 EXTEND(SP, 1);
94 PUSHMARK(SP);
95 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
96 PUTBACK;
97
98 count = perl_call_sv(wd->sv, G_SCALAR);
99
100 SPAGAIN;
101
102 if (count != 1)
103 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
104
105 sv = POPs;
106 success = SvTRUE(sv);
107
108
109 PUTBACK;
110 FREETMPS;
111 LEAVE;
112
113 return success;
114}
115
116struct value_name {
117 char *name;
118 int value;
119};
120static int lookup_name(struct value_name *names, int count, char *name, int def_value)
121{
122 int i;
123 for (i = 0; i < count; ++i)
124 if (strEQ(names[i].name, name))
125 return names[i].value;
126
127 return def_value;
128}
129static struct value_name transp_names[] =
130{
131 { "none", tr_none },
132 { "threshold", tr_threshold },
133 { "errdiff", tr_errdiff },
134 { "ordered", tr_ordered, },
135};
136
137static struct value_name make_color_names[] =
138{
139 { "none", mc_none, },
140 { "webmap", mc_web_map, },
141 { "addi", mc_addi, },
142};
143
144static struct value_name translate_names[] =
145{
146#ifdef HAVE_LIBGIF
147 { "giflib", pt_giflib, },
148#endif
149 { "closest", pt_closest, },
150 { "perturb", pt_perturb, },
151 { "errdiff", pt_errdiff, },
152};
153
154static struct value_name errdiff_names[] =
155{
156 { "floyd", ed_floyd, },
157 { "jarvis", ed_jarvis, },
158 { "stucki", ed_stucki, },
159 { "custom", ed_custom, },
160};
161
162static struct value_name orddith_names[] =
163{
164 { "random", od_random, },
165 { "dot8", od_dot8, },
166 { "dot4", od_dot4, },
167 { "hline", od_hline, },
168 { "vline", od_vline, },
169 { "/line", od_slashline, },
170 { "slashline", od_slashline, },
171 { "\\line", od_backline, },
172 { "backline", od_backline, },
e7d4ea82 173 { "tiny", od_tiny, },
02d1d628
AMH
174 { "custom", od_custom, },
175};
176
177/* look through the hash for quantization options */
178static void handle_quant_opts(i_quantize *quant, HV *hv)
179{
180 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
181 SV **sv;
182 int i;
183 STRLEN len;
184 char *str;
185
186 sv = hv_fetch(hv, "transp", 6, 0);
187 if (sv && *sv && (str = SvPV(*sv, len))) {
188 quant->transp =
189 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
190 str, tr_none);
191 if (quant->transp != tr_none) {
192 quant->tr_threshold = 127;
193 sv = hv_fetch(hv, "tr_threshold", 12, 0);
194 if (sv && *sv)
195 quant->tr_threshold = SvIV(*sv);
196 }
197 if (quant->transp == tr_errdiff) {
198 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
199 if (sv && *sv && (str = SvPV(*sv, len)))
200 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
201 }
202 if (quant->transp == tr_ordered) {
e7d4ea82 203 quant->tr_orddith = od_tiny;
02d1d628
AMH
204 sv = hv_fetch(hv, "tr_orddith", 10, 0);
205 if (sv && *sv && (str = SvPV(*sv, len)))
206 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
207
208 if (quant->tr_orddith == od_custom) {
209 sv = hv_fetch(hv, "tr_map", 6, 0);
210 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
211 AV *av = (AV*)SvRV(*sv);
212 len = av_len(av) + 1;
213 if (len > sizeof(quant->tr_custom))
214 len = sizeof(quant->tr_custom);
215 for (i = 0; i < len; ++i) {
216 SV **sv2 = av_fetch(av, i, 0);
217 if (sv2 && *sv2) {
218 quant->tr_custom[i] = SvIV(*sv2);
219 }
220 }
221 while (i < sizeof(quant->tr_custom))
222 quant->tr_custom[i++] = 0;
223 }
224 }
225 }
226 }
227 quant->make_colors = mc_addi;
228 sv = hv_fetch(hv, "make_colors", 11, 0);
229 if (sv && *sv && (str = SvPV(*sv, len))) {
230 quant->make_colors =
231 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
232 }
233 sv = hv_fetch(hv, "colors", 6, 0);
234 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
235 /* needs to be an array of Imager::Color
236 note that the caller allocates the mc_color array and sets mc_size
237 to it's size */
238 AV *av = (AV *)SvRV(*sv);
239 quant->mc_count = av_len(av)+1;
240 if (quant->mc_count > quant->mc_size)
241 quant->mc_count = quant->mc_size;
242 for (i = 0; i < quant->mc_count; ++i) {
243 SV **sv1 = av_fetch(av, i, 0);
244 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
245 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
246 quant->mc_colors[i] = *col;
247 }
248 }
249 }
250 sv = hv_fetch(hv, "max_colors", 10, 0);
251 if (sv && *sv) {
252 i = SvIV(*sv);
253 if (i <= quant->mc_size && i >= quant->mc_count)
254 quant->mc_size = i;
255 }
256
257 quant->translate = pt_closest;
258 sv = hv_fetch(hv, "translate", 9, 0);
259 if (sv && *sv && (str = SvPV(*sv, len))) {
260 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
261 }
262 sv = hv_fetch(hv, "errdiff", 7, 0);
263 if (sv && *sv && (str = SvPV(*sv, len))) {
264 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
265 }
266 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
267 /* get the error diffusion map */
268 sv = hv_fetch(hv, "errdiff_width", 13, 0);
269 if (sv && *sv)
270 quant->ed_width = SvIV(*sv);
271 sv = hv_fetch(hv, "errdiff_height", 14, 0);
272 if (sv && *sv)
273 quant->ed_height = SvIV(*sv);
274 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
275 if (sv && *sv)
276 quant->ed_orig = SvIV(*sv);
277 if (quant->ed_width > 0 && quant->ed_height > 0) {
278 int sum = 0;
279 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
280 sv = hv_fetch(hv, "errdiff_map", 11, 0);
281 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
282 AV *av = (AV*)SvRV(*sv);
283 len = av_len(av) + 1;
284 if (len > quant->ed_width * quant->ed_height)
285 len = quant->ed_width * quant->ed_height;
286 for (i = 0; i < len; ++i) {
287 SV **sv2 = av_fetch(av, i, 0);
288 if (sv2 && *sv2) {
289 quant->ed_map[i] = SvIV(*sv2);
290 sum += quant->ed_map[i];
291 }
292 }
293 }
294 if (!sum) {
295 /* broken map */
296 myfree(quant->ed_map);
297 quant->ed_map = 0;
298 quant->errdiff = ed_floyd;
299 }
300 }
301 }
302 sv = hv_fetch(hv, "perturb", 7, 0);
303 if (sv && *sv)
304 quant->perturb = SvIV(*sv);
305}
306
307/* look through the hash for options to add to opts */
308static void handle_gif_opts(i_gif_opts *opts, HV *hv)
309{
310 /*** FIXME: POSSIBLY BROKEN: do I need to unref the SV from hv_fetch? ***/
311 SV **sv;
312 int i;
313 /**((char *)0) = '\0';*/
314 sv = hv_fetch(hv, "gif_each_palette", 16, 0);
315 if (sv && *sv)
316 opts->each_palette = SvIV(*sv);
317 sv = hv_fetch(hv, "interlace", 9, 0);
318 if (sv && *sv)
319 opts->interlace = SvIV(*sv);
320 sv = hv_fetch(hv, "gif_delays", 10, 0);
321 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
322 AV *av = (AV*)SvRV(*sv);
323 opts->delay_count = av_len(av)+1;
324 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
325 for (i = 0; i < opts->delay_count; ++i) {
326 SV *sv1 = *av_fetch(av, i, 0);
327 opts->delays[i] = SvIV(sv1);
328 }
329 }
330 sv = hv_fetch(hv, "gif_user_input", 14, 0);
331 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
332 AV *av = (AV*)SvRV(*sv);
333 opts->user_input_count = av_len(av)+1;
334 opts->user_input_flags = mymalloc(opts->user_input_count);
335 for (i = 0; i < opts->user_input_count; ++i) {
336 SV *sv1 = *av_fetch(av, i, 0);
337 opts->user_input_flags[i] = SvIV(sv1) != 0;
338 }
339 }
340 sv = hv_fetch(hv, "gif_disposal", 12, 0);
341 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
342 AV *av = (AV*)SvRV(*sv);
343 opts->disposal_count = av_len(av)+1;
344 opts->disposal = mymalloc(opts->disposal_count);
345 for (i = 0; i < opts->disposal_count; ++i) {
346 SV *sv1 = *av_fetch(av, i, 0);
347 opts->disposal[i] = SvIV(sv1);
348 }
349 }
350 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
351 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
352 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
353 opts->tran_color = *col;
354 }
355 sv = hv_fetch(hv, "gif_positions", 13, 0);
356 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
357 AV *av = (AV *)SvRV(*sv);
358 opts->position_count = av_len(av) + 1;
359 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
360 for (i = 0; i < opts->position_count; ++i) {
361 SV **sv2 = av_fetch(av, i, 0);
362 opts->positions[i].x = opts->positions[i].y = 0;
363 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
364 AV *av2 = (AV*)SvRV(*sv2);
365 SV **sv3;
366 sv3 = av_fetch(av2, 0, 0);
367 if (sv3 && *sv3)
368 opts->positions[i].x = SvIV(*sv3);
369 sv3 = av_fetch(av2, 1, 0);
370 if (sv3 && *sv3)
371 opts->positions[i].y = SvIV(*sv3);
372 }
373 }
374 }
375 /* Netscape2.0 loop count extension */
376 sv = hv_fetch(hv, "gif_loop_count", 14, 0);
377 if (sv && *sv)
378 opts->loop_count = SvIV(*sv);
379}
380
381/* copies the color map from the hv into the colors member of the HV */
382static void copy_colors_back(HV *hv, i_quantize *quant) {
383 SV **sv;
384 AV *av;
385 int i;
386 SV *work;
387
388 sv = hv_fetch(hv, "colors", 6, 0);
389 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
390 SV *ref;
391 av = newAV();
392 ref = newRV_inc((SV*) av);
393 sv = hv_store(hv, "colors", 6, ref, 0);
394 }
395 else {
396 av = (AV *)SvRV(*sv);
397 }
398 av_extend(av, quant->mc_count+1);
399 for (i = 0; i < quant->mc_count; ++i) {
400 i_color *in = quant->mc_colors+i;
401 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
402 work = sv_newmortal();
403 sv_setref_pv(work, "Imager::Color", (void *)c);
404 SvREFCNT_inc(work);
405 if (!av_store(av, i, work)) {
406 SvREFCNT_dec(work);
407 }
408 }
409}
410
02d1d628
AMH
411MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
412
413Imager::Color
414ICL_new_internal(r,g,b,a)
415 unsigned char r
416 unsigned char g
417 unsigned char b
418 unsigned char a
419
420void
421ICL_DESTROY(cl)
422 Imager::Color cl
423
424
29106a11 425void
02d1d628
AMH
426ICL_set_internal(cl,r,g,b,a)
427 Imager::Color cl
428 unsigned char r
429 unsigned char g
430 unsigned char b
431 unsigned char a
29106a11 432 PPCODE:
46062ab6 433 ICL_set_internal(cl, r, g, b, a);
29106a11
TC
434 EXTEND(SP, 1);
435 PUSHs(ST(0));
02d1d628
AMH
436
437void
438ICL_info(cl)
439 Imager::Color cl
440
441
442void
443ICL_rgba(cl)
444 Imager::Color cl
445 PPCODE:
446 EXTEND(SP, 4);
447 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
448 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
449 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
450 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
451
452
453
454
455
456
457
458MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
459
460Imager::ImgRaw
461IIM_new(x,y,ch)
462 int x
463 int y
464 int ch
465
466void
467IIM_DESTROY(im)
468 Imager::ImgRaw im
469
470
471
472MODULE = Imager PACKAGE = Imager
473
474PROTOTYPES: ENABLE
475
476
477Imager::IO
478io_new_fd(fd)
479 int fd
480
481Imager::IO
482io_new_bufchain()
483
484
485void
486io_slurp(ig)
487 Imager::IO ig
488 PREINIT:
489 unsigned char* data;
490 size_t tlength;
491 SV* r;
492 PPCODE:
493 data = NULL;
494 tlength = io_slurp(ig, &data);
495 r = sv_newmortal();
496 EXTEND(SP,1);
497 PUSHs(sv_2mortal(newSVpv(data,tlength)));
498 myfree(data);
499
500
501
502void
503i_list_formats()
504 PREINIT:
505 char* item;
506 int i;
507 PPCODE:
508 i=0;
509 while( (item=i_format_list[i++]) != NULL ) {
510 EXTEND(SP, 1);
511 PUSHs(sv_2mortal(newSVpv(item,0)));
512 }
513
514undef_int
515i_has_format(frmt)
516 char* frmt
517
518Imager::ImgRaw
519i_img_new()
520
521Imager::ImgRaw
522i_img_empty(im,x,y)
523 Imager::ImgRaw im
524 int x
525 int y
526
527Imager::ImgRaw
528i_img_empty_ch(im,x,y,ch)
529 Imager::ImgRaw im
530 int x
531 int y
532 int ch
533
534void
535init_log(name,level)
536 char* name
537 int level
538
539void
540i_img_exorcise(im)
541 Imager::ImgRaw im
542
543void
544i_img_destroy(im)
545 Imager::ImgRaw im
546
547void
548i_img_info(im)
549 Imager::ImgRaw im
550 PREINIT:
551 int info[4];
552 PPCODE:
553 i_img_info(im,info);
554 EXTEND(SP, 4);
555 PUSHs(sv_2mortal(newSViv(info[0])));
556 PUSHs(sv_2mortal(newSViv(info[1])));
557 PUSHs(sv_2mortal(newSViv(info[2])));
558 PUSHs(sv_2mortal(newSViv(info[3])));
559
560
561
562
563void
564i_img_setmask(im,ch_mask)
565 Imager::ImgRaw im
566 int ch_mask
567
568int
569i_img_getmask(im)
570 Imager::ImgRaw im
571
572int
573i_img_getchannels(im)
574 Imager::ImgRaw im
575
576void
577i_img_getdata(im)
578 Imager::ImgRaw im
579 PPCODE:
580 EXTEND(SP, 1);
581 PUSHs(sv_2mortal(newSVpv(im->data, im->bytes)));
582
583
584void
585i_draw(im,x1,y1,x2,y2,val)
586 Imager::ImgRaw im
587 int x1
588 int y1
589 int x2
590 int y2
591 Imager::Color val
592
593void
594i_line_aa(im,x1,y1,x2,y2,val)
595 Imager::ImgRaw im
596 int x1
597 int y1
598 int x2
599 int y2
600 Imager::Color val
601
602void
603i_box(im,x1,y1,x2,y2,val)
604 Imager::ImgRaw im
605 int x1
606 int y1
607 int x2
608 int y2
609 Imager::Color val
610
611void
612i_box_filled(im,x1,y1,x2,y2,val)
613 Imager::ImgRaw im
614 int x1
615 int y1
616 int x2
617 int y2
618 Imager::Color val
619
620void
621i_arc(im,x,y,rad,d1,d2,val)
622 Imager::ImgRaw im
623 int x
624 int y
625 float rad
626 float d1
627 float d2
628 Imager::Color val
629
630
631
632void
633i_bezier_multi(im,xc,yc,val)
634 Imager::ImgRaw im
635 Imager::Color val
636 PREINIT:
637 double *x,*y;
638 int len;
639 AV *av1;
640 AV *av2;
641 SV *sv1;
642 SV *sv2;
643 int i;
644 PPCODE:
645 ICL_info(val);
646 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
647 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
648 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
649 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
650 av1=(AV*)SvRV(ST(1));
651 av2=(AV*)SvRV(ST(2));
652 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
653 len=av_len(av1)+1;
654 x=mymalloc( len*sizeof(double) );
655 y=mymalloc( len*sizeof(double) );
656 for(i=0;i<len;i++) {
657 sv1=(*(av_fetch(av1,i,0)));
658 sv2=(*(av_fetch(av2,i,0)));
659 x[i]=(double)SvNV(sv1);
660 y[i]=(double)SvNV(sv2);
661 }
662 i_bezier_multi(im,len,x,y,val);
663 myfree(x);
664 myfree(y);
665
666
667void
668i_poly_aa(im,xc,yc,val)
669 Imager::ImgRaw im
670 Imager::Color val
671 PREINIT:
672 double *x,*y;
673 int len;
674 AV *av1;
675 AV *av2;
676 SV *sv1;
677 SV *sv2;
678 int i;
679 PPCODE:
680 ICL_info(val);
681 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
682 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
683 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
684 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
685 av1=(AV*)SvRV(ST(1));
686 av2=(AV*)SvRV(ST(2));
687 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
688 len=av_len(av1)+1;
689 x=mymalloc( len*sizeof(double) );
690 y=mymalloc( len*sizeof(double) );
691 for(i=0;i<len;i++) {
692 sv1=(*(av_fetch(av1,i,0)));
693 sv2=(*(av_fetch(av2,i,0)));
694 x[i]=(double)SvNV(sv1);
695 y[i]=(double)SvNV(sv2);
696 }
697 i_poly_aa(im,len,x,y,val);
698 myfree(x);
699 myfree(y);
700
701
702
703void
704i_flood_fill(im,seedx,seedy,dcol)
705 Imager::ImgRaw im
706 int seedx
707 int seedy
708 Imager::Color dcol
709
710
711void
712i_copyto(im,src,x1,y1,x2,y2,tx,ty)
713 Imager::ImgRaw im
714 Imager::ImgRaw src
715 int x1
716 int y1
717 int x2
718 int y2
719 int tx
720 int ty
721
722
723void
724i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
725 Imager::ImgRaw im
726 Imager::ImgRaw src
727 int x1
728 int y1
729 int x2
730 int y2
731 int tx
732 int ty
733 Imager::Color trans
734
735void
736i_copy(im,src)
737 Imager::ImgRaw im
738 Imager::ImgRaw src
739
740
741void
742i_rubthru(im,src,tx,ty)
743 Imager::ImgRaw im
744 Imager::ImgRaw src
745 int tx
746 int ty
747
142c26ff
AMH
748undef_int
749i_flipxy(im, direction)
750 Imager::ImgRaw im
751 int direction
752
02d1d628
AMH
753
754void
755i_gaussian(im,stdev)
756 Imager::ImgRaw im
757 float stdev
758
759void
760i_conv(im,pcoef)
761 Imager::ImgRaw im
762 PREINIT:
763 float* coeff;
764 int len;
765 AV* av;
766 SV* sv1;
767 int i;
768 PPCODE:
769 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
770 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
771 av=(AV*)SvRV(ST(1));
772 len=av_len(av)+1;
773 coeff=mymalloc( len*sizeof(float) );
774 for(i=0;i<len;i++) {
775 sv1=(*(av_fetch(av,i,0)));
776 coeff[i]=(float)SvNV(sv1);
777 }
778 i_conv(im,coeff,len);
779 myfree(coeff);
780
f5991c03
TC
781undef_int
782i_convert(im, src, coeff)
783 Imager::ImgRaw im
784 Imager::ImgRaw src
785 PREINIT:
786 float *coeff;
787 int outchan;
788 int inchan;
789 AV *avmain;
790 SV **temp;
791 SV *svsub;
792 AV *avsub;
793 int len;
794 int i, j;
795 CODE:
f5991c03
TC
796 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
797 croak("i_convert: parameter 3 must be an arrayref\n");
798 avmain = (AV*)SvRV(ST(2));
799 outchan = av_len(avmain)+1;
800 /* find the biggest */
801 inchan = 0;
802 for (j=0; j < outchan; ++j) {
803 temp = av_fetch(avmain, j, 0);
804 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
805 avsub = (AV*)SvRV(*temp);
806 len = av_len(avsub)+1;
807 if (len > inchan)
808 inchan = len;
809 }
810 }
811 coeff = mymalloc(sizeof(float) * outchan * inchan);
812 for (j = 0; j < outchan; ++j) {
813 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
814 len = av_len(avsub)+1;
815 for (i = 0; i < len; ++i) {
816 temp = av_fetch(avsub, i, 0);
817 if (temp)
818 coeff[i+j*inchan] = SvNV(*temp);
819 else
820 coeff[i+j*inchan] = 0;
821 }
822 while (i < inchan)
823 coeff[i++ + j*inchan] = 0;
824 }
825 RETVAL = i_convert(im, src, coeff, outchan, inchan);
826 myfree(coeff);
f5991c03
TC
827 OUTPUT:
828 RETVAL
40eba1ea
AMH
829
830
831void
832i_map(im, pmaps)
833 Imager::ImgRaw im
834 PREINIT:
835 unsigned int mask = 0;
836 AV *avmain;
837 AV *avsub;
838 SV **temp;
839 int len;
840 int i, j;
841 unsigned char (*maps)[256];
842 CODE:
843 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
844 croak("i_map: parameter 2 must be an arrayref\n");
845 avmain = (AV*)SvRV(ST(1));
846 len = av_len(avmain)+1;
847 if (im->channels < len) len = im->channels;
848
849 maps = mymalloc( len * sizeof(unsigned char [256]) );
850
851 for (j=0; j<len ; j++) {
852 temp = av_fetch(avmain, j, 0);
853 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
854 avsub = (AV*)SvRV(*temp);
855 if(av_len(avsub) != 255) continue;
856 mask |= 1<<j;
857 for (i=0; i<256 ; i++) {
858 temp = av_fetch(avsub, i, 0);
859 maps[j][i] = temp ? SvIV(*temp) : 0;
860 }
861 }
862 }
863 i_map(im, maps, mask);
864 myfree(maps);
865
866
867
02d1d628
AMH
868float
869i_img_diff(im1,im2)
870 Imager::ImgRaw im1
871 Imager::ImgRaw im2
872
873
874
875undef_int
876i_init_fonts()
877
878#ifdef HAVE_LIBT1
879
880void
881i_t1_set_aa(st)
882 int st
883
884int
885i_t1_new(pfb,afm=NULL)
886 char* pfb
887 char* afm
888
889int
890i_t1_destroy(font_id)
891 int font_id
892
893
894undef_int
895i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
896 Imager::ImgRaw im
897 int xb
898 int yb
899 int channel
900 int fontnum
901 float points
902 char* str
903 int len
904 int align
905
906void
907i_t1_bbox(fontnum,point,str,len)
908 int fontnum
909 float point
910 char* str
911 int len
912 PREINIT:
913 int cords[6];
914 PPCODE:
915 i_t1_bbox(fontnum,point,str,len,cords);
916 EXTEND(SP, 4);
917 PUSHs(sv_2mortal(newSViv(cords[0])));
918 PUSHs(sv_2mortal(newSViv(cords[1])));
919 PUSHs(sv_2mortal(newSViv(cords[2])));
920 PUSHs(sv_2mortal(newSViv(cords[3])));
921 PUSHs(sv_2mortal(newSViv(cords[4])));
922 PUSHs(sv_2mortal(newSViv(cords[5])));
923
924
925
926undef_int
927i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
928 Imager::ImgRaw im
929 int xb
930 int yb
931 Imager::Color cl
932 int fontnum
933 float points
934 char* str
935 int len
936 int align
937
938#endif
939
940#ifdef HAVE_LIBTT
941
942
943Imager::TTHandle
944i_tt_new(fontname)
945 char* fontname
946
947void
948i_tt_destroy(handle)
949 Imager::TTHandle handle
950
951
952
953undef_int
954i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
955 Imager::TTHandle handle
956 Imager::ImgRaw im
957 int xb
958 int yb
959 Imager::Color cl
960 float points
961 char* str
962 int len
963 int smooth
964
965
966undef_int
967i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
968 Imager::TTHandle handle
969 Imager::ImgRaw im
970 int xb
971 int yb
972 int channel
973 float points
974 char* str
975 int len
976 int smooth
977
978
979
980undef_int
981i_tt_bbox(handle,point,str,len)
982 Imager::TTHandle handle
983 float point
984 char* str
985 int len
986 PREINIT:
987 int cords[6],rc;
988 PPCODE:
989 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
990 EXTEND(SP, 4);
991 PUSHs(sv_2mortal(newSViv(cords[0])));
992 PUSHs(sv_2mortal(newSViv(cords[1])));
993 PUSHs(sv_2mortal(newSViv(cords[2])));
994 PUSHs(sv_2mortal(newSViv(cords[3])));
995 PUSHs(sv_2mortal(newSViv(cords[4])));
996 PUSHs(sv_2mortal(newSViv(cords[5])));
997 }
998
999
1000#endif
1001
1002
1003
1004
1005#ifdef HAVE_LIBJPEG
1006undef_int
1007i_writejpeg(im,fd,qfactor)
1008 Imager::ImgRaw im
1009 int fd
1010 int qfactor
1011
1012void
1013i_readjpeg(fd)
1014 int fd
1015 PREINIT:
1016 char* iptc_itext;
1017 int tlength;
1018 i_img* rimg;
1019 SV* r;
1020 PPCODE:
1021 iptc_itext = NULL;
1022 rimg=i_readjpeg(fd,&iptc_itext,&tlength);
1023 if (iptc_itext == NULL) {
1024 r = sv_newmortal();
1025 EXTEND(SP,1);
1026 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1027 PUSHs(r);
1028 } else {
1029 r = sv_newmortal();
1030 EXTEND(SP,2);
1031 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1032 PUSHs(r);
1033 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1034 myfree(iptc_itext);
1035 }
1036
1037
1038void
1039i_readjpeg_scalar(...)
1040 PROTOTYPE: $
1041 PREINIT:
1042 char* data;
1043 unsigned int length;
1044 char* iptc_itext;
1045 int tlength;
1046 i_img* rimg;
1047 SV* r;
1048 PPCODE:
1049 iptc_itext = NULL;
1050 data = (char *)SvPV(ST(0), length);
1051 rimg=i_readjpeg_scalar(data,length,&iptc_itext,&tlength);
1052 mm_log((1,"i_readjpeg_scalar: 0x%08X\n",rimg));
1053 if (iptc_itext == NULL) {
1054 r = sv_newmortal();
1055 EXTEND(SP,1);
1056 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1057 PUSHs(r);
1058 } else {
1059 r = sv_newmortal();
1060 EXTEND(SP,2);
1061 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1062 PUSHs(r);
1063 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1064 myfree(iptc_itext);
1065 }
1066
1067
1068void
1069i_readjpeg_wiol(ig)
1070 Imager::IO ig
1071 PREINIT:
1072 char* iptc_itext;
1073 int tlength;
1074 i_img* rimg;
1075 SV* r;
1076 PPCODE:
1077 iptc_itext = NULL;
1078 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1079 if (iptc_itext == NULL) {
1080 r = sv_newmortal();
1081 EXTEND(SP,1);
1082 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1083 PUSHs(r);
1084 } else {
1085 r = sv_newmortal();
1086 EXTEND(SP,2);
1087 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1088 PUSHs(r);
1089 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1090 myfree(iptc_itext);
1091 }
1092
1093
1094#endif
1095
1096
1097
1098
1099#ifdef HAVE_LIBTIFF
1100
1101Imager::ImgRaw
1102i_readtiff_wiol(ig, length)
1103 Imager::IO ig
1104 int length
1105
1106
1107undef_int
1108i_writetiff_wiol(im, ig)
1109 Imager::ImgRaw im
1110 Imager::IO ig
1111
d2dfdcc9 1112undef_int
4c2d6970 1113i_writetiff_wiol_faxable(im, ig, fine)
d2dfdcc9
TC
1114 Imager::ImgRaw im
1115 Imager::IO ig
4c2d6970 1116 int fine
d2dfdcc9 1117
02d1d628
AMH
1118
1119#endif /* HAVE_LIBTIFF */
1120
1121
1122
1123
1124
1125#ifdef HAVE_LIBPNG
1126
1127Imager::ImgRaw
1128i_readpng(fd)
1129 int fd
1130
1131
1132undef_int
1133i_writepng(im,fd)
1134 Imager::ImgRaw im
1135 int fd
1136
1137
1138Imager::ImgRaw
1139i_readpng_scalar(...)
1140 PROTOTYPE: $
1141 PREINIT:
1142 char* data;
1143 unsigned int length;
1144 CODE:
1145 data = (char *)SvPV(ST(0), length);
1146 RETVAL=i_readpng_scalar(data,length);
1147 OUTPUT:
1148 RETVAL
1149
1150
1151
1152#endif
1153
1154
1155#ifdef HAVE_LIBGIF
1156
03bd24d4
TC
1157void
1158i_giflib_version()
1159 PPCODE:
1160 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1161
02d1d628
AMH
1162undef_int
1163i_writegif(im,fd,colors,pixdev,fixed)
1164 Imager::ImgRaw im
1165 int fd
1166 int colors
1167 int pixdev
1168 PREINIT:
1169 int fixedlen;
1170 Imager__Color fixed;
1171 Imager__Color tmp;
1172 AV* av;
1173 SV* sv1;
1174 IV Itmp;
1175 int i;
1176 CODE:
1177 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1178 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1179 av=(AV*)SvRV(ST(4));
1180 fixedlen=av_len(av)+1;
1181 fixed=mymalloc( fixedlen*sizeof(i_color) );
1182 for(i=0;i<fixedlen;i++) {
1183 sv1=(*(av_fetch(av,i,0)));
1184 if (sv_derived_from(sv1, "Imager::Color")) {
1185 Itmp = SvIV((SV*)SvRV(sv1));
1186 tmp = (i_color*) Itmp;
1187 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1188 fixed[i]=*tmp;
1189 }
1190 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1191 myfree(fixed);
1192 ST(0) = sv_newmortal();
1193 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1194 else sv_setiv(ST(0), (IV)RETVAL);
1195
1196
1197
1198
1199undef_int
1200i_writegifmc(im,fd,colors)
1201 Imager::ImgRaw im
1202 int fd
1203 int colors
1204
02d1d628
AMH
1205
1206undef_int
1207i_writegif_gen(fd, ...)
1208 int fd
1209 PROTOTYPE: $$@
1210 PREINIT:
1211 i_quantize quant;
1212 i_gif_opts opts;
1213 i_img **imgs = NULL;
1214 int img_count;
1215 int i;
1216 HV *hv;
1217 CODE:
1218 if (items < 3)
1219 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1220 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1221 croak("i_writegif_gen: Second argument must be a hash ref");
1222 hv = (HV *)SvRV(ST(1));
1223 memset(&quant, 0, sizeof(quant));
1224 quant.mc_size = 256;
1225 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1226 memset(&opts, 0, sizeof(opts));
1227 handle_quant_opts(&quant, hv);
1228 handle_gif_opts(&opts, hv);
1229 img_count = items - 2;
1230 RETVAL = 1;
1231 if (img_count < 1) {
1232 RETVAL = 0;
95b44a76
TC
1233 i_clear_error();
1234 i_push_error(0, "You need to specify images to save");
02d1d628
AMH
1235 }
1236 else {
1237 imgs = mymalloc(sizeof(i_img *) * img_count);
1238 for (i = 0; i < img_count; ++i) {
1239 SV *sv = ST(2+i);
1240 imgs[i] = NULL;
1241 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1242 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1243 }
1244 else {
95b44a76
TC
1245 i_clear_error();
1246 i_push_error(0, "Only images can be saved");
02d1d628
AMH
1247 RETVAL = 0;
1248 break;
1249 }
1250 }
1251 if (RETVAL) {
1252 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1253 }
1254 myfree(imgs);
1255 if (RETVAL) {
1256 copy_colors_back(hv, &quant);
1257 }
1258 }
1259 ST(0) = sv_newmortal();
1260 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1261 else sv_setiv(ST(0), (IV)RETVAL);
1262
1263undef_int
1264i_writegif_callback(cb, maxbuffer,...)
1265 int maxbuffer;
1266 PREINIT:
1267 i_quantize quant;
1268 i_gif_opts opts;
1269 i_img **imgs = NULL;
1270 int img_count;
1271 int i;
1272 HV *hv;
1273 i_writer_data wd;
1274 CODE:
1275 if (items < 4)
1276 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1277 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1278 croak("i_writegif_callback: Second argument must be a hash ref");
1279 hv = (HV *)SvRV(ST(2));
1280 memset(&quant, 0, sizeof(quant));
1281 quant.mc_size = 256;
1282 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1283 memset(&opts, 0, sizeof(opts));
1284 handle_quant_opts(&quant, hv);
1285 handle_gif_opts(&opts, hv);
1286 img_count = items - 3;
1287 RETVAL = 1;
1288 if (img_count < 1) {
1289 RETVAL = 0;
1290 }
1291 else {
1292 imgs = mymalloc(sizeof(i_img *) * img_count);
1293 for (i = 0; i < img_count; ++i) {
1294 SV *sv = ST(3+i);
1295 imgs[i] = NULL;
1296 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1297 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1298 }
1299 else {
1300 RETVAL = 0;
1301 break;
1302 }
1303 }
1304 if (RETVAL) {
1305 wd.sv = ST(0);
1306 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1307 }
1308 myfree(imgs);
1309 if (RETVAL) {
1310 copy_colors_back(hv, &quant);
1311 }
1312 }
1313 ST(0) = sv_newmortal();
1314 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1315 else sv_setiv(ST(0), (IV)RETVAL);
1316
1317void
1318i_readgif(fd)
1319 int fd
1320 PREINIT:
1321 int* colour_table;
1322 int colours, q, w;
1323 i_img* rimg;
1324 SV* temp[3];
1325 AV* ct;
1326 SV* r;
1327 PPCODE:
1328 colour_table = NULL;
1329 colours = 0;
1330
1331 if(GIMME_V == G_ARRAY) {
1332 rimg = i_readgif(fd,&colour_table,&colours);
1333 } else {
1334 /* don't waste time with colours if they aren't wanted */
1335 rimg = i_readgif(fd,NULL,NULL);
1336 }
1337
1338 if (colour_table == NULL) {
1339 EXTEND(SP,1);
1340 r=sv_newmortal();
1341 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1342 PUSHs(r);
1343 } else {
1344 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1345 /* I don't know if I have the reference counts right or not :( */
1346 /* Neither do I :-) */
1347 /* No Idea here either */
1348
1349 ct=newAV();
1350 av_extend(ct, colours);
1351 for(q=0; q<colours; q++) {
1352 for(w=0; w<3; w++)
1353 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1354 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1355 }
1356 myfree(colour_table);
1357
1358 EXTEND(SP,2);
1359 r=sv_newmortal();
1360 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1361 PUSHs(r);
1362 PUSHs(newRV_noinc((SV*)ct));
1363 }
1364
1365
1366
1367
1368
1369void
1370i_readgif_scalar(...)
1371 PROTOTYPE: $
1372 PREINIT:
1373 char* data;
1374 unsigned int length;
1375 int* colour_table;
1376 int colours, q, w;
1377 i_img* rimg;
1378 SV* temp[3];
1379 AV* ct;
1380 SV* r;
1381 PPCODE:
1382 data = (char *)SvPV(ST(0), length);
1383 colour_table=NULL;
1384 colours=0;
1385
1386 if(GIMME_V == G_ARRAY) {
1387 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1388 } else {
1389 /* don't waste time with colours if they aren't wanted */
1390 rimg=i_readgif_scalar(data,length,NULL,NULL);
1391 }
1392
1393 if (colour_table == NULL) {
1394 EXTEND(SP,1);
1395 r=sv_newmortal();
1396 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1397 PUSHs(r);
1398 } else {
1399 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1400 /* I don't know if I have the reference counts right or not :( */
1401 /* Neither do I :-) */
1402 ct=newAV();
1403 av_extend(ct, colours);
1404 for(q=0; q<colours; q++) {
1405 for(w=0; w<3; w++)
1406 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1407 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1408 }
1409 myfree(colour_table);
1410
1411 EXTEND(SP,2);
1412 r=sv_newmortal();
1413 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1414 PUSHs(r);
1415 PUSHs(newRV_noinc((SV*)ct));
1416 }
1417
1418void
1419i_readgif_callback(...)
1420 PROTOTYPE: &
1421 PREINIT:
1422 char* data;
1423 int length;
1424 int* colour_table;
1425 int colours, q, w;
1426 i_img* rimg;
1427 SV* temp[3];
1428 AV* ct;
1429 SV* r;
1430 i_reader_data rd;
1431 PPCODE:
1432 rd.sv = ST(0);
1433 colour_table=NULL;
1434 colours=0;
1435
1436 if(GIMME_V == G_ARRAY) {
1437 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1438 } else {
1439 /* don't waste time with colours if they aren't wanted */
1440 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1441 }
1442
1443 if (colour_table == NULL) {
1444 EXTEND(SP,1);
1445 r=sv_newmortal();
1446 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1447 PUSHs(r);
1448 } else {
1449 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1450 /* I don't know if I have the reference counts right or not :( */
1451 /* Neither do I :-) */
1452 /* Neither do I - maybe I'll move this somewhere */
1453 ct=newAV();
1454 av_extend(ct, colours);
1455 for(q=0; q<colours; q++) {
1456 for(w=0; w<3; w++)
1457 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1458 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1459 }
1460 myfree(colour_table);
1461
1462 EXTEND(SP,2);
1463 r=sv_newmortal();
1464 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1465 PUSHs(r);
1466 PUSHs(newRV_noinc((SV*)ct));
1467 }
1468
1469
1470
1471
1472
1473
1474#endif
1475
1476
1477
1478Imager::ImgRaw
1479i_readpnm_wiol(ig, length)
1480 Imager::IO ig
1481 int length
1482
1483
1484undef_int
1485i_writeppm(im,fd)
1486 Imager::ImgRaw im
1487 int fd
1488
1489Imager::ImgRaw
1490i_readraw(fd,x,y,datachannels,storechannels,intrl)
1491 int fd
1492 int x
1493 int y
1494 int datachannels
1495 int storechannels
1496 int intrl
1497
1498undef_int
1499i_writeraw(im,fd)
1500 Imager::ImgRaw im
1501 int fd
1502
1503
1504Imager::ImgRaw
1505i_scaleaxis(im,Value,Axis)
1506 Imager::ImgRaw im
1507 float Value
1508 int Axis
1509
1510Imager::ImgRaw
1511i_scale_nn(im,scx,scy)
1512 Imager::ImgRaw im
1513 float scx
1514 float scy
1515
1516Imager::ImgRaw
1517i_haar(im)
1518 Imager::ImgRaw im
1519
1520int
1521i_count_colors(im,maxc)
1522 Imager::ImgRaw im
1523 int maxc
1524
1525
1526Imager::ImgRaw
1527i_transform(im,opx,opy,parm)
1528 Imager::ImgRaw im
1529 PREINIT:
1530 double* parm;
1531 int* opx;
1532 int* opy;
1533 int opxl;
1534 int opyl;
1535 int parmlen;
1536 AV* av;
1537 SV* sv1;
1538 int i;
1539 CODE:
1540 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1541 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1542 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1543 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1544 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1545 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1546 av=(AV*)SvRV(ST(1));
1547 opxl=av_len(av)+1;
1548 opx=mymalloc( opxl*sizeof(int) );
1549 for(i=0;i<opxl;i++) {
1550 sv1=(*(av_fetch(av,i,0)));
1551 opx[i]=(int)SvIV(sv1);
1552 }
1553 av=(AV*)SvRV(ST(2));
1554 opyl=av_len(av)+1;
1555 opy=mymalloc( opyl*sizeof(int) );
1556 for(i=0;i<opyl;i++) {
1557 sv1=(*(av_fetch(av,i,0)));
1558 opy[i]=(int)SvIV(sv1);
1559 }
1560 av=(AV*)SvRV(ST(3));
1561 parmlen=av_len(av)+1;
1562 parm=mymalloc( parmlen*sizeof(double) );
1563 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1564 sv1=(*(av_fetch(av,i,0)));
1565 parm[i]=(double)SvNV(sv1);
1566 }
1567 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1568 myfree(parm);
1569 myfree(opy);
1570 myfree(opx);
1571 ST(0) = sv_newmortal();
1572 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1573 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1574
1575Imager::ImgRaw
1576i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1577 PREINIT:
1578 int width;
1579 int height;
1580 double* parm;
1581 struct rm_op *ops;
1582 unsigned int ops_len;
1583 int ops_count;
1584 double *n_regs;
1585 int n_regs_count;
1586 i_color *c_regs;
1587 int c_regs_count;
1588 int in_imgs_count;
1589 i_img **in_imgs;
1590 AV* av;
1591 SV* sv1;
1592 IV tmp;
1593 int i;
1594 CODE:
1595 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1596 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1597 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1598 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1599 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1600
1601 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1602
1603 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1604 av = (AV*)SvRV(ST(5));
1605 in_imgs_count = av_len(av)+1;
1606 for (i = 0; i < in_imgs_count; ++i) {
1607 sv1 = *av_fetch(av, i, 0);
1608 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1609 croak("Parameter 5 must contain only images");
1610 }
1611 }
1612 }
1613 else {
1614 in_imgs_count = 0;
1615 }
1616 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1617 av = (AV*)SvRV(ST(5));
1618 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1619 for (i = 0; i < in_imgs_count; ++i) {
1620 sv1 = *av_fetch(av,i,0);
1621 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1622 croak("Parameter 5 must contain only images");
1623 }
1624 tmp = SvIV((SV*)SvRV(sv1));
1625 in_imgs[i] = (i_img*)tmp;
1626 }
1627 }
1628 else {
1629 /* no input images */
1630 in_imgs = NULL;
1631 }
1632 /* default the output size from the first input if possible */
1633 if (SvOK(ST(0)))
1634 width = SvIV(ST(0));
1635 else if (in_imgs_count)
1636 width = in_imgs[0]->xsize;
1637 else
1638 croak("No output image width supplied");
1639
1640 if (SvOK(ST(1)))
1641 height = SvIV(ST(1));
1642 else if (in_imgs_count)
1643 height = in_imgs[0]->ysize;
1644 else
1645 croak("No output image height supplied");
1646
1647 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1648 if (ops_len % sizeof(struct rm_op))
1649 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1650 ops_count = ops_len / sizeof(struct rm_op);
1651 av = (AV*)SvRV(ST(3));
1652 n_regs_count = av_len(av)+1;
1653 n_regs = mymalloc(n_regs_count * sizeof(double));
1654 for (i = 0; i < n_regs_count; ++i) {
1655 sv1 = *av_fetch(av,i,0);
1656 if (SvOK(sv1))
1657 n_regs[i] = SvNV(sv1);
1658 }
1659 av = (AV*)SvRV(ST(4));
1660 c_regs_count = av_len(av)+1;
1661 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1662 /* I don't bother initializing the colou?r registers */
1663
1664 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1665 n_regs, n_regs_count,
1666 c_regs, c_regs_count, in_imgs, in_imgs_count);
1667 if (in_imgs)
1668 myfree(in_imgs);
1669 myfree(n_regs);
1670 myfree(c_regs);
1671 ST(0) = sv_newmortal();
1672 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1673 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1674
1675
1676void
1677i_contrast(im,intensity)
1678 Imager::ImgRaw im
1679 float intensity
1680
1681void
1682i_hardinvert(im)
1683 Imager::ImgRaw im
1684
1685void
1686i_noise(im,amount,type)
1687 Imager::ImgRaw im
1688 float amount
1689 unsigned char type
1690
1691void
1692i_bumpmap(im,bump,channel,light_x,light_y,strength)
1693 Imager::ImgRaw im
1694 Imager::ImgRaw bump
1695 int channel
1696 int light_x
1697 int light_y
1698 int strength
1699
1700void
1701i_postlevels(im,levels)
1702 Imager::ImgRaw im
1703 int levels
1704
1705void
1706i_mosaic(im,size)
1707 Imager::ImgRaw im
1708 int size
1709
1710void
1711i_watermark(im,wmark,tx,ty,pixdiff)
1712 Imager::ImgRaw im
1713 Imager::ImgRaw wmark
1714 int tx
1715 int ty
1716 int pixdiff
1717
1718
1719void
1720i_autolevels(im,lsat,usat,skew)
1721 Imager::ImgRaw im
1722 float lsat
1723 float usat
1724 float skew
1725
1726void
1727i_radnoise(im,xo,yo,rscale,ascale)
1728 Imager::ImgRaw im
1729 float xo
1730 float yo
1731 float rscale
1732 float ascale
1733
1734void
1735i_turbnoise(im, xo, yo, scale)
1736 Imager::ImgRaw im
1737 float xo
1738 float yo
1739 float scale
1740
1741
1742void
1743i_gradgen(im, ...)
1744 Imager::ImgRaw im
1745 PREINIT:
1746 int num;
1747 int *xo;
1748 int *yo;
1749 i_color *ival;
1750 int dmeasure;
1751 int i;
1752 SV *sv;
1753 AV *axx;
1754 AV *ayy;
1755 AV *ac;
1756 CODE:
1757 if (items != 5)
1758 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
1759 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1760 croak("i_gradgen: Second argument must be an array ref");
1761 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1762 croak("i_gradgen: Third argument must be an array ref");
1763 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1764 croak("i_gradgen: Fourth argument must be an array ref");
1765 axx = (AV *)SvRV(ST(1));
1766 ayy = (AV *)SvRV(ST(2));
1767 ac = (AV *)SvRV(ST(3));
1768 dmeasure = (int)SvIV(ST(4));
1769
1770 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1771 num = num <= av_len(ac) ? num : av_len(ac);
1772 num++;
1773 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
1774 xo = mymalloc( sizeof(int) * num );
1775 yo = mymalloc( sizeof(int) * num );
1776 ival = mymalloc( sizeof(i_color) * num );
1777 for(i = 0; i<num; i++) {
1778 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1779 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1780 sv = *av_fetch(ac, i, 0);
1781 if ( !sv_derived_from(sv, "Imager::Color") ) {
1782 free(axx); free(ayy); free(ac);
1783 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
1784 }
1785 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1786 }
1787 i_gradgen(im, num, xo, yo, ival, dmeasure);
1788
1789
1790
1791
1792
4f4f776a
TC
1793void
1794i_errors()
1795 PREINIT:
1796 i_errmsg *errors;
1797 int i;
1798 int count;
1799 AV *av;
1800 SV *ref;
1801 SV *sv;
1802 PPCODE:
1803 errors = i_errors();
1804 i = 0;
1805 while (errors[i].msg) {
1806 av = newAV();
1807 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
1808 if (!av_store(av, 0, sv)) {
1809 SvREFCNT_dec(sv);
1810 }
1811 sv = newSViv(errors[i].code);
1812 if (!av_store(av, 1, sv)) {
1813 SvREFCNT_dec(sv);
1814 }
1815 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
1816 ++i;
1817 }
02d1d628
AMH
1818
1819void
1820i_nearest_color(im, ...)
1821 Imager::ImgRaw im
1822 PREINIT:
1823 int num;
1824 int *xo;
1825 int *yo;
1826 i_color *ival;
1827 int dmeasure;
1828 int i;
1829 SV *sv;
1830 AV *axx;
1831 AV *ayy;
1832 AV *ac;
1833 CODE:
1834 if (items != 5)
1835 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
1836 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1837 croak("i_nearest_color: Second argument must be an array ref");
1838 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1839 croak("i_nearest_color: Third argument must be an array ref");
1840 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1841 croak("i_nearest_color: Fourth argument must be an array ref");
1842 axx = (AV *)SvRV(ST(1));
1843 ayy = (AV *)SvRV(ST(2));
1844 ac = (AV *)SvRV(ST(3));
1845 dmeasure = (int)SvIV(ST(4));
1846
1847 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1848 num = num <= av_len(ac) ? num : av_len(ac);
1849 num++;
1850 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
1851 xo = mymalloc( sizeof(int) * num );
1852 yo = mymalloc( sizeof(int) * num );
1853 ival = mymalloc( sizeof(i_color) * num );
1854 for(i = 0; i<num; i++) {
1855 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1856 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1857 sv = *av_fetch(ac, i, 0);
1858 if ( !sv_derived_from(sv, "Imager::Color") ) {
1859 free(axx); free(ayy); free(ac);
1860 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
1861 }
1862 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1863 }
1864 i_nearest_color(im, num, xo, yo, ival, dmeasure);
1865
1866
1867
1868
1869void
1870malloc_state()
1871
1872void
1873hashinfo(hv)
1874 PREINIT:
1875 HV* hv;
1876 int stuff;
1877 PPCODE:
1878 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
1879 hv=(HV*)SvRV(ST(0));
1880 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
1881 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1882 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1883
1884void
1885DSO_open(filename)
1886 char* filename
1887 PREINIT:
1888 void *rc;
1889 char *evstr;
1890 PPCODE:
1891 rc=DSO_open(filename,&evstr);
1892 if (rc!=NULL) {
1893 if (evstr!=NULL) {
1894 EXTEND(SP,2);
1895 PUSHs(sv_2mortal(newSViv((IV)rc)));
1896 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
1897 } else {
1898 EXTEND(SP,1);
1899 PUSHs(sv_2mortal(newSViv((IV)rc)));
1900 }
1901 }
1902
1903
1904undef_int
1905DSO_close(dso_handle)
1906 void* dso_handle
1907
1908void
1909DSO_funclist(dso_handle_v)
1910 void* dso_handle_v
1911 PREINIT:
1912 int i;
1913 DSO_handle *dso_handle;
1914 PPCODE:
1915 dso_handle=(DSO_handle*)dso_handle_v;
1916 i=0;
1917 while( dso_handle->function_list[i].name != NULL) {
1918 EXTEND(SP,1);
1919 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
1920 EXTEND(SP,1);
1921 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
1922 }
1923
1924
1925void
1926DSO_call(handle,func_index,hv)
1927 void* handle
1928 int func_index
1929 PREINIT:
1930 HV* hv;
1931 PPCODE:
1932 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
1933 hv=(HV*)SvRV(ST(2));
1934 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
1935 DSO_call( (DSO_handle *)handle,func_index,hv);
1936
1937
1938
f5991c03
TC
1939# this is mostly for testing...
1940Imager::Color
1941i_get_pixel(im, x, y)
1942 Imager::ImgRaw im
1943 int x
1944 int y;
1945 CODE:
1946 RETVAL = (i_color *)mymalloc(sizeof(i_color));
1947 i_gpix(im, x, y, RETVAL);
1948 OUTPUT:
1949 RETVAL
02d1d628 1950