17 typedef io_glue* Imager__IO;
18 typedef i_color* Imager__Color;
19 typedef i_fcolor* Imager__Color__Float;
20 typedef i_img* Imager__ImgRaw;
24 typedef TT_Fonthandle* Imager__Font__TT;
28 typedef FT2_Fonthandle* Imager__Font__FT2;
32 void my_SvREFCNT_dec(void *p) {
38 log_entry(char *string, int level) {
39 mm_log((level, string));
43 typedef struct i_reader_data_tag
45 /* presumably a CODE ref or name of a sub */
49 /* used by functions that want callbacks */
50 static int read_callback(char *userdata, char *buffer, int need, int want) {
51 i_reader_data *rd = (i_reader_data *)userdata;
55 dSP; dTARG = sv_newmortal();
56 /* thanks to Simon Cozens for help with the dTARG above */
66 count = perl_call_sv(rd->sv, G_SCALAR);
71 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
77 char *ptr = SvPV(data, len);
79 croak("Too much data returned in reader callback");
81 memcpy(buffer, ptr, len);
97 SV *sv; /* a coderef or sub name */
100 /* used by functions that want callbacks */
101 static int write_callback(char *userdata, char const *data, int size) {
102 i_writer_data *wd = (i_writer_data *)userdata;
112 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
115 count = perl_call_sv(wd->sv, G_SCALAR);
120 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
123 success = SvTRUE(sv);
137 static int lookup_name(struct value_name *names, int count, char *name, int def_value)
140 for (i = 0; i < count; ++i)
141 if (strEQ(names[i].name, name))
142 return names[i].value;
146 static struct value_name transp_names[] =
149 { "threshold", tr_threshold },
150 { "errdiff", tr_errdiff },
151 { "ordered", tr_ordered, },
154 static struct value_name make_color_names[] =
156 { "none", mc_none, },
157 { "webmap", mc_web_map, },
158 { "addi", mc_addi, },
161 static struct value_name translate_names[] =
164 { "giflib", pt_giflib, },
166 { "closest", pt_closest, },
167 { "perturb", pt_perturb, },
168 { "errdiff", pt_errdiff, },
171 static struct value_name errdiff_names[] =
173 { "floyd", ed_floyd, },
174 { "jarvis", ed_jarvis, },
175 { "stucki", ed_stucki, },
176 { "custom", ed_custom, },
179 static struct value_name orddith_names[] =
181 { "random", od_random, },
182 { "dot8", od_dot8, },
183 { "dot4", od_dot4, },
184 { "hline", od_hline, },
185 { "vline", od_vline, },
186 { "/line", od_slashline, },
187 { "slashline", od_slashline, },
188 { "\\line", od_backline, },
189 { "backline", od_backline, },
190 { "tiny", od_tiny, },
191 { "custom", od_custom, },
195 hv_fetch_bool(HV *hv, char *name, int def) {
198 sv = hv_fetch(hv, name, strlen(name), 0);
207 hv_fetch_int(HV *hv, char *name, int def) {
210 sv = hv_fetch(hv, name, strlen(name), 0);
218 /* look through the hash for quantization options */
219 static void handle_quant_opts(i_quantize *quant, HV *hv)
221 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
227 quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color));
229 sv = hv_fetch(hv, "transp", 6, 0);
230 if (sv && *sv && (str = SvPV(*sv, len))) {
232 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
234 if (quant->transp != tr_none) {
235 quant->tr_threshold = 127;
236 sv = hv_fetch(hv, "tr_threshold", 12, 0);
238 quant->tr_threshold = SvIV(*sv);
240 if (quant->transp == tr_errdiff) {
241 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
242 if (sv && *sv && (str = SvPV(*sv, len)))
243 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
245 if (quant->transp == tr_ordered) {
246 quant->tr_orddith = od_tiny;
247 sv = hv_fetch(hv, "tr_orddith", 10, 0);
248 if (sv && *sv && (str = SvPV(*sv, len)))
249 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
251 if (quant->tr_orddith == od_custom) {
252 sv = hv_fetch(hv, "tr_map", 6, 0);
253 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
254 AV *av = (AV*)SvRV(*sv);
255 len = av_len(av) + 1;
256 if (len > sizeof(quant->tr_custom))
257 len = sizeof(quant->tr_custom);
258 for (i = 0; i < len; ++i) {
259 SV **sv2 = av_fetch(av, i, 0);
261 quant->tr_custom[i] = SvIV(*sv2);
264 while (i < sizeof(quant->tr_custom))
265 quant->tr_custom[i++] = 0;
270 quant->make_colors = mc_addi;
271 sv = hv_fetch(hv, "make_colors", 11, 0);
272 if (sv && *sv && (str = SvPV(*sv, len))) {
274 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
276 sv = hv_fetch(hv, "colors", 6, 0);
277 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
278 /* needs to be an array of Imager::Color
279 note that the caller allocates the mc_color array and sets mc_size
281 AV *av = (AV *)SvRV(*sv);
282 quant->mc_count = av_len(av)+1;
283 if (quant->mc_count > quant->mc_size)
284 quant->mc_count = quant->mc_size;
285 for (i = 0; i < quant->mc_count; ++i) {
286 SV **sv1 = av_fetch(av, i, 0);
287 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
288 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
289 quant->mc_colors[i] = *col;
293 sv = hv_fetch(hv, "max_colors", 10, 0);
296 if (i <= quant->mc_size && i >= quant->mc_count)
300 quant->translate = pt_closest;
301 sv = hv_fetch(hv, "translate", 9, 0);
302 if (sv && *sv && (str = SvPV(*sv, len))) {
303 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
305 sv = hv_fetch(hv, "errdiff", 7, 0);
306 if (sv && *sv && (str = SvPV(*sv, len))) {
307 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
309 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
310 /* get the error diffusion map */
311 sv = hv_fetch(hv, "errdiff_width", 13, 0);
313 quant->ed_width = SvIV(*sv);
314 sv = hv_fetch(hv, "errdiff_height", 14, 0);
316 quant->ed_height = SvIV(*sv);
317 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
319 quant->ed_orig = SvIV(*sv);
320 if (quant->ed_width > 0 && quant->ed_height > 0) {
322 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
323 sv = hv_fetch(hv, "errdiff_map", 11, 0);
324 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
325 AV *av = (AV*)SvRV(*sv);
326 len = av_len(av) + 1;
327 if (len > quant->ed_width * quant->ed_height)
328 len = quant->ed_width * quant->ed_height;
329 for (i = 0; i < len; ++i) {
330 SV **sv2 = av_fetch(av, i, 0);
332 quant->ed_map[i] = SvIV(*sv2);
333 sum += quant->ed_map[i];
339 myfree(quant->ed_map);
341 quant->errdiff = ed_floyd;
345 sv = hv_fetch(hv, "perturb", 7, 0);
347 quant->perturb = SvIV(*sv);
350 static void cleanup_quant_opts(i_quantize *quant) {
351 myfree(quant->mc_colors);
353 myfree(quant->ed_map);
356 /* look through the hash for options to add to opts */
357 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
361 /**((char *)0) = '\0';*/
362 opts->each_palette = hv_fetch_bool(hv, "gif_each_palette", 0);
363 opts->interlace = hv_fetch_bool(hv, "interlace", 0);
365 sv = hv_fetch(hv, "gif_delays", 10, 0);
366 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
367 AV *av = (AV*)SvRV(*sv);
368 opts->delay_count = av_len(av)+1;
369 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
370 for (i = 0; i < opts->delay_count; ++i) {
371 SV *sv1 = *av_fetch(av, i, 0);
372 opts->delays[i] = SvIV(sv1);
375 sv = hv_fetch(hv, "gif_user_input", 14, 0);
376 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
377 AV *av = (AV*)SvRV(*sv);
378 opts->user_input_count = av_len(av)+1;
379 opts->user_input_flags = mymalloc(opts->user_input_count);
380 for (i = 0; i < opts->user_input_count; ++i) {
381 SV *sv1 = *av_fetch(av, i, 0);
382 opts->user_input_flags[i] = SvIV(sv1) != 0;
385 sv = hv_fetch(hv, "gif_disposal", 12, 0);
386 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
387 AV *av = (AV*)SvRV(*sv);
388 opts->disposal_count = av_len(av)+1;
389 opts->disposal = mymalloc(opts->disposal_count);
390 for (i = 0; i < opts->disposal_count; ++i) {
391 SV *sv1 = *av_fetch(av, i, 0);
392 opts->disposal[i] = SvIV(sv1);
395 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
396 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
397 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
398 opts->tran_color = *col;
400 sv = hv_fetch(hv, "gif_positions", 13, 0);
401 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
402 AV *av = (AV *)SvRV(*sv);
403 opts->position_count = av_len(av) + 1;
404 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
405 for (i = 0; i < opts->position_count; ++i) {
406 SV **sv2 = av_fetch(av, i, 0);
407 opts->positions[i].x = opts->positions[i].y = 0;
408 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
409 AV *av2 = (AV*)SvRV(*sv2);
411 sv3 = av_fetch(av2, 0, 0);
413 opts->positions[i].x = SvIV(*sv3);
414 sv3 = av_fetch(av2, 1, 0);
416 opts->positions[i].y = SvIV(*sv3);
420 /* Netscape2.0 loop count extension */
421 opts->loop_count = hv_fetch_int(hv, "gif_loop_count", 0);
423 opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1);
426 static void cleanup_gif_opts(i_gif_opts *opts) {
428 myfree(opts->delays);
429 if (opts->user_input_flags)
430 myfree(opts->user_input_flags);
432 myfree(opts->disposal);
434 myfree(opts->positions);
437 /* copies the color map from the hv into the colors member of the HV */
438 static void copy_colors_back(HV *hv, i_quantize *quant) {
444 sv = hv_fetch(hv, "colors", 6, 0);
445 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
448 ref = newRV_inc((SV*) av);
449 sv = hv_store(hv, "colors", 6, ref, 0);
452 av = (AV *)SvRV(*sv);
454 av_extend(av, quant->mc_count+1);
455 for (i = 0; i < quant->mc_count; ++i) {
456 i_color *in = quant->mc_colors+i;
457 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
458 work = sv_newmortal();
459 sv_setref_pv(work, "Imager::Color", (void *)c);
461 if (!av_store(av, i, work)) {
467 /* loads the segments of a fountain fill into an array */
468 i_fountain_seg *load_fount_segs(AV *asegs, int *count) {
469 /* Each element of segs must contain:
470 [ start, middle, end, c0, c1, segtype, colortrans ]
471 start, middle, end are doubles from 0 to 1
472 c0, c1 are Imager::Color::Float or Imager::Color objects
473 segtype, colortrans are ints
478 i_fountain_seg *segs;
482 *count = av_len(asegs)+1;
484 croak("i_fountain must have at least one segment");
485 segs = mymalloc(sizeof(i_fountain_seg) * *count);
486 for(i = 0; i < *count; i++) {
487 SV **sv1 = av_fetch(asegs, i, 0);
488 if (!sv1 || !*sv1 || !SvROK(*sv1)
489 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
491 croak("i_fountain: segs must be an arrayref of arrayrefs");
493 aseg = (AV *)SvRV(*sv1);
494 if (av_len(aseg) != 7-1) {
496 croak("i_fountain: a segment must have 7 members");
498 for (j = 0; j < 3; ++j) {
499 SV **sv2 = av_fetch(aseg, j, 0);
502 croak("i_fountain: XS error");
504 work[j] = SvNV(*sv2);
506 segs[i].start = work[0];
507 segs[i].middle = work[1];
508 segs[i].end = work[2];
509 for (j = 0; j < 2; ++j) {
510 SV **sv3 = av_fetch(aseg, 3+j, 0);
511 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
512 (!sv_derived_from(*sv3, "Imager::Color")
513 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
515 croak("i_fountain: segs must contain colors in elements 3 and 4");
517 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
518 segs[i].c[j] = *(i_fcolor *)SvIV((SV *)SvRV(*sv3));
521 i_color c = *(i_color *)SvIV((SV *)SvRV(*sv3));
523 for (ch = 0; ch < MAXCHANNELS; ++ch) {
524 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
528 for (j = 0; j < 2; ++j) {
529 SV **sv2 = av_fetch(aseg, j+5, 0);
532 croak("i_fountain: XS error");
534 worki[j] = SvIV(*sv2);
536 segs[i].type = worki[0];
537 segs[i].color = worki[1];
543 /* I don't think ICLF_* names belong at the C interface
544 this makes the XS code think we have them, to let us avoid
545 putting function bodies in the XS code
547 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
548 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
550 /* for the fill objects
551 Since a fill object may later have dependent images, (or fills!)
552 we need perl wrappers - oh well
554 #define IFILL_DESTROY(fill) i_fill_destroy(fill);
555 typedef i_fill_t* Imager__FillHandle;
557 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
560 ICL_new_internal(r,g,b,a)
572 ICL_set_internal(cl,r,g,b,a)
579 ICL_set_internal(cl, r, g, b, a);
593 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
594 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
595 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
596 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
602 RETVAL = mymalloc(sizeof(i_color));
604 i_hsv_to_rgb(RETVAL);
612 RETVAL = mymalloc(sizeof(i_color));
614 i_rgb_to_hsv(RETVAL);
620 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
623 ICLF_new_internal(r, g, b, a)
631 Imager::Color::Float cl
635 Imager::Color::Float cl
639 EXTEND(SP, MAXCHANNELS);
640 for (ch = 0; ch < MAXCHANNELS; ++ch) {
641 /* printf("%d: %g\n", ch, cl->channel[ch]); */
642 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
646 ICLF_set_internal(cl,r,g,b,a)
647 Imager::Color::Float cl
662 Imager::Color::Float c
664 RETVAL = mymalloc(sizeof(i_fcolor));
666 i_hsv_to_rgbf(RETVAL);
672 Imager::Color::Float c
674 RETVAL = mymalloc(sizeof(i_fcolor));
676 i_rgb_to_hsvf(RETVAL);
681 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
695 MODULE = Imager PACKAGE = Imager
717 RETVAL = io_new_buffer(data, length, my_SvREFCNT_dec, ST(0));
730 tlength = io_slurp(ig, &data);
732 PUSHs(sv_2mortal(newSVpv(data,tlength)));
736 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_glue_
743 MODULE = Imager PACKAGE = Imager
756 while( (item=i_format_list[i++]) != NULL ) {
758 PUSHs(sv_2mortal(newSVpv(item,0)));
775 i_img_empty_ch(im,x,y,ch)
787 log_entry(string,level)
808 PUSHs(sv_2mortal(newSViv(info[0])));
809 PUSHs(sv_2mortal(newSViv(info[1])));
810 PUSHs(sv_2mortal(newSViv(info[2])));
811 PUSHs(sv_2mortal(newSViv(info[3])));
817 i_img_setmask(im,ch_mask)
826 i_img_getchannels(im)
834 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
839 i_draw(im,x1,y1,x2,y2,val)
848 i_line_aa(im,x1,y1,x2,y2,val)
857 i_box(im,x1,y1,x2,y2,val)
866 i_box_filled(im,x1,y1,x2,y2,val)
875 i_box_cfill(im,x1,y1,x2,y2,fill)
881 Imager::FillHandle fill
884 i_arc(im,x,y,rad,d1,d2,val)
894 i_arc_cfill(im,x,y,rad,d1,d2,fill)
901 Imager::FillHandle fill
906 i_circle_aa(im,x,y,rad,val)
916 i_bezier_multi(im,xc,yc,val)
929 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
930 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
931 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
932 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
933 av1=(AV*)SvRV(ST(1));
934 av2=(AV*)SvRV(ST(2));
935 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
937 x=mymalloc( len*sizeof(double) );
938 y=mymalloc( len*sizeof(double) );
940 sv1=(*(av_fetch(av1,i,0)));
941 sv2=(*(av_fetch(av2,i,0)));
942 x[i]=(double)SvNV(sv1);
943 y[i]=(double)SvNV(sv2);
945 i_bezier_multi(im,len,x,y,val);
951 i_poly_aa(im,xc,yc,val)
964 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
965 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
966 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
967 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
968 av1=(AV*)SvRV(ST(1));
969 av2=(AV*)SvRV(ST(2));
970 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
972 x=mymalloc( len*sizeof(double) );
973 y=mymalloc( len*sizeof(double) );
975 sv1=(*(av_fetch(av1,i,0)));
976 sv2=(*(av_fetch(av2,i,0)));
977 x[i]=(double)SvNV(sv1);
978 y[i]=(double)SvNV(sv2);
980 i_poly_aa(im,len,x,y,val);
985 i_poly_aa_cfill(im,xc,yc,fill)
987 Imager::FillHandle fill
997 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
998 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
999 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
1000 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa_cfill must be a reference to an array\n");
1001 av1=(AV*)SvRV(ST(1));
1002 av2=(AV*)SvRV(ST(2));
1003 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
1005 x=mymalloc( len*sizeof(double) );
1006 y=mymalloc( len*sizeof(double) );
1007 for(i=0;i<len;i++) {
1008 sv1=(*(av_fetch(av1,i,0)));
1009 sv2=(*(av_fetch(av2,i,0)));
1010 x[i]=(double)SvNV(sv1);
1011 y[i]=(double)SvNV(sv2);
1013 i_poly_aa_cfill(im,len,x,y,fill);
1020 i_flood_fill(im,seedx,seedy,dcol)
1027 i_flood_cfill(im,seedx,seedy,fill)
1031 Imager::FillHandle fill
1035 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
1047 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
1065 i_rubthru(im,src,tx,ty)
1072 i_flipxy(im, direction)
1077 i_rotate90(im, degrees)
1082 i_rotate_exact(im, amount)
1087 i_matrix_transform(im, xsize, ysize, matrix)
1098 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
1099 croak("i_matrix_transform: parameter 4 must be an array ref\n");
1100 av=(AV*)SvRV(ST(3));
1104 for (i = 0; i < len; ++i) {
1105 sv1=(*(av_fetch(av,i,0)));
1106 matrix[i] = SvNV(sv1);
1110 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
1115 i_gaussian(im,stdev)
1120 i_unsharp_mask(im,stdev,scale)
1135 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1136 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1137 av=(AV*)SvRV(ST(1));
1139 coeff=mymalloc( len*sizeof(float) );
1140 for(i=0;i<len;i++) {
1141 sv1=(*(av_fetch(av,i,0)));
1142 coeff[i]=(float)SvNV(sv1);
1144 i_conv(im,coeff,len);
1148 i_convert(im, src, coeff)
1162 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
1163 croak("i_convert: parameter 3 must be an arrayref\n");
1164 avmain = (AV*)SvRV(ST(2));
1165 outchan = av_len(avmain)+1;
1166 /* find the biggest */
1168 for (j=0; j < outchan; ++j) {
1169 temp = av_fetch(avmain, j, 0);
1170 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1171 avsub = (AV*)SvRV(*temp);
1172 len = av_len(avsub)+1;
1177 coeff = mymalloc(sizeof(float) * outchan * inchan);
1178 for (j = 0; j < outchan; ++j) {
1179 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1180 len = av_len(avsub)+1;
1181 for (i = 0; i < len; ++i) {
1182 temp = av_fetch(avsub, i, 0);
1184 coeff[i+j*inchan] = SvNV(*temp);
1186 coeff[i+j*inchan] = 0;
1189 coeff[i++ + j*inchan] = 0;
1191 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1201 unsigned int mask = 0;
1207 unsigned char (*maps)[256];
1209 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1210 croak("i_map: parameter 2 must be an arrayref\n");
1211 avmain = (AV*)SvRV(ST(1));
1212 len = av_len(avmain)+1;
1213 if (im->channels < len) len = im->channels;
1215 maps = mymalloc( len * sizeof(unsigned char [256]) );
1217 for (j=0; j<len ; j++) {
1218 temp = av_fetch(avmain, j, 0);
1219 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1220 avsub = (AV*)SvRV(*temp);
1221 if(av_len(avsub) != 255) continue;
1223 for (i=0; i<256 ; i++) {
1225 temp = av_fetch(avsub, i, 0);
1226 val = temp ? SvIV(*temp) : 0;
1228 if (val>255) val = 255;
1233 i_map(im, maps, mask);
1255 i_t1_new(pfb,afm=NULL)
1260 i_t1_destroy(font_id)
1265 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1277 i_t1_bbox(fontnum,point,str,len)
1285 i_t1_bbox(fontnum,point,str,len,cords);
1287 PUSHs(sv_2mortal(newSViv(cords[0])));
1288 PUSHs(sv_2mortal(newSViv(cords[1])));
1289 PUSHs(sv_2mortal(newSViv(cords[2])));
1290 PUSHs(sv_2mortal(newSViv(cords[3])));
1291 PUSHs(sv_2mortal(newSViv(cords[4])));
1292 PUSHs(sv_2mortal(newSViv(cords[5])));
1297 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1318 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
1320 #define TT_DESTROY(handle) i_tt_destroy(handle)
1324 Imager::Font::TT handle
1327 MODULE = Imager PACKAGE = Imager
1331 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1332 Imager::Font::TT handle
1344 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1345 Imager::Font::TT handle
1358 i_tt_bbox(handle,point,str,len)
1359 Imager::Font::TT handle
1366 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1368 PUSHs(sv_2mortal(newSViv(cords[0])));
1369 PUSHs(sv_2mortal(newSViv(cords[1])));
1370 PUSHs(sv_2mortal(newSViv(cords[2])));
1371 PUSHs(sv_2mortal(newSViv(cords[3])));
1372 PUSHs(sv_2mortal(newSViv(cords[4])));
1373 PUSHs(sv_2mortal(newSViv(cords[5])));
1384 i_writejpeg_wiol(im, ig, qfactor)
1400 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1401 if (iptc_itext == NULL) {
1404 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1409 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1411 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1424 i_readtiff_wiol(ig, length)
1430 i_writetiff_wiol(im, ig)
1435 i_writetiff_wiol_faxable(im, ig, fine)
1441 #endif /* HAVE_LIBTIFF */
1450 i_readpng_wiol(ig, length)
1456 i_writepng_wiol(im, ig)
1469 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1472 i_writegif(im,fd,colors,pixdev,fixed)
1479 Imager__Color fixed;
1486 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1487 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1488 av=(AV*)SvRV(ST(4));
1489 fixedlen=av_len(av)+1;
1490 fixed=mymalloc( fixedlen*sizeof(i_color) );
1491 for(i=0;i<fixedlen;i++) {
1492 sv1=(*(av_fetch(av,i,0)));
1493 if (sv_derived_from(sv1, "Imager::Color")) {
1494 Itmp = SvIV((SV*)SvRV(sv1));
1495 tmp = (i_color*) Itmp;
1496 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1499 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1501 ST(0) = sv_newmortal();
1502 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1503 else sv_setiv(ST(0), (IV)RETVAL);
1509 i_writegifmc(im,fd,colors)
1516 i_writegif_gen(fd, ...)
1522 i_img **imgs = NULL;
1528 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1529 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1530 croak("i_writegif_gen: Second argument must be a hash ref");
1531 hv = (HV *)SvRV(ST(1));
1532 memset(&quant, 0, sizeof(quant));
1533 quant.mc_size = 256;
1534 memset(&opts, 0, sizeof(opts));
1535 handle_quant_opts(&quant, hv);
1536 handle_gif_opts(&opts, hv);
1537 img_count = items - 2;
1539 if (img_count < 1) {
1542 i_push_error(0, "You need to specify images to save");
1545 imgs = mymalloc(sizeof(i_img *) * img_count);
1546 for (i = 0; i < img_count; ++i) {
1549 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1550 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1554 i_push_error(0, "Only images can be saved");
1560 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1564 copy_colors_back(hv, &quant);
1567 ST(0) = sv_newmortal();
1568 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1569 else sv_setiv(ST(0), (IV)RETVAL);
1570 cleanup_gif_opts(&opts);
1571 cleanup_quant_opts(&quant);
1575 i_writegif_callback(cb, maxbuffer,...)
1580 i_img **imgs = NULL;
1587 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1588 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1589 croak("i_writegif_callback: Second argument must be a hash ref");
1590 hv = (HV *)SvRV(ST(2));
1591 memset(&quant, 0, sizeof(quant));
1592 quant.mc_size = 256;
1593 memset(&opts, 0, sizeof(opts));
1594 handle_quant_opts(&quant, hv);
1595 handle_gif_opts(&opts, hv);
1596 img_count = items - 3;
1598 if (img_count < 1) {
1602 imgs = mymalloc(sizeof(i_img *) * img_count);
1603 for (i = 0; i < img_count; ++i) {
1606 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1607 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1616 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1620 copy_colors_back(hv, &quant);
1623 ST(0) = sv_newmortal();
1624 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1625 else sv_setiv(ST(0), (IV)RETVAL);
1626 cleanup_gif_opts(&opts);
1627 cleanup_quant_opts(&quant);
1640 colour_table = NULL;
1643 if(GIMME_V == G_ARRAY) {
1644 rimg = i_readgif(fd,&colour_table,&colours);
1646 /* don't waste time with colours if they aren't wanted */
1647 rimg = i_readgif(fd,NULL,NULL);
1650 if (colour_table == NULL) {
1653 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1656 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1657 /* I don't know if I have the reference counts right or not :( */
1658 /* Neither do I :-) */
1659 /* No Idea here either */
1662 av_extend(ct, colours);
1663 for(q=0; q<colours; q++) {
1665 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1666 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1668 myfree(colour_table);
1672 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1674 PUSHs(newRV_noinc((SV*)ct));
1682 i_readgif_scalar(...)
1686 unsigned int length;
1694 data = (char *)SvPV(ST(0), length);
1698 if(GIMME_V == G_ARRAY) {
1699 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1701 /* don't waste time with colours if they aren't wanted */
1702 rimg=i_readgif_scalar(data,length,NULL,NULL);
1705 if (colour_table == NULL) {
1708 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1711 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1712 /* I don't know if I have the reference counts right or not :( */
1713 /* Neither do I :-) */
1715 av_extend(ct, colours);
1716 for(q=0; q<colours; q++) {
1718 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1719 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1721 myfree(colour_table);
1725 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1727 PUSHs(newRV_noinc((SV*)ct));
1731 i_readgif_callback(...)
1748 if(GIMME_V == G_ARRAY) {
1749 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1751 /* don't waste time with colours if they aren't wanted */
1752 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1755 if (colour_table == NULL) {
1758 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1761 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1762 /* I don't know if I have the reference counts right or not :( */
1763 /* Neither do I :-) */
1764 /* Neither do I - maybe I'll move this somewhere */
1766 av_extend(ct, colours);
1767 for(q=0; q<colours; q++) {
1769 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1770 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1772 myfree(colour_table);
1776 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1778 PUSHs(newRV_noinc((SV*)ct));
1789 imgs = i_readgif_multi(fd, &count);
1792 for (i = 0; i < count; ++i) {
1793 SV *sv = sv_newmortal();
1794 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1801 i_readgif_multi_scalar(data)
1806 unsigned int length;
1809 data = (char *)SvPV(ST(0), length);
1810 imgs = i_readgif_multi_scalar(data, length, &count);
1813 for (i = 0; i < count; ++i) {
1814 SV *sv = sv_newmortal();
1815 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1822 i_readgif_multi_callback(cb)
1830 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1833 for (i = 0; i < count; ++i) {
1834 SV *sv = sv_newmortal();
1835 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1846 i_readpnm_wiol(ig, length)
1852 i_writeppm_wiol(im, ig)
1858 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1867 i_writeraw_wiol(im,ig)
1872 i_writebmp_wiol(im,ig)
1882 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
1893 idlen = SvCUR(ST(4));
1894 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
1900 i_readtga_wiol(ig, length)
1906 i_scaleaxis(im,Value,Axis)
1912 i_scale_nn(im,scx,scy)
1922 i_count_colors(im,maxc)
1928 i_transform(im,opx,opy,parm)
1941 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1942 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1943 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1944 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1945 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1946 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1947 av=(AV*)SvRV(ST(1));
1949 opx=mymalloc( opxl*sizeof(int) );
1950 for(i=0;i<opxl;i++) {
1951 sv1=(*(av_fetch(av,i,0)));
1952 opx[i]=(int)SvIV(sv1);
1954 av=(AV*)SvRV(ST(2));
1956 opy=mymalloc( opyl*sizeof(int) );
1957 for(i=0;i<opyl;i++) {
1958 sv1=(*(av_fetch(av,i,0)));
1959 opy[i]=(int)SvIV(sv1);
1961 av=(AV*)SvRV(ST(3));
1962 parmlen=av_len(av)+1;
1963 parm=mymalloc( parmlen*sizeof(double) );
1964 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1965 sv1=(*(av_fetch(av,i,0)));
1966 parm[i]=(double)SvNV(sv1);
1968 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1972 ST(0) = sv_newmortal();
1973 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1974 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1977 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1996 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1997 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1998 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1999 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
2000 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
2002 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
2004 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
2005 av = (AV*)SvRV(ST(5));
2006 in_imgs_count = av_len(av)+1;
2007 for (i = 0; i < in_imgs_count; ++i) {
2008 sv1 = *av_fetch(av, i, 0);
2009 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2010 croak("Parameter 5 must contain only images");
2017 if (in_imgs_count > 0) {
2018 av = (AV*)SvRV(ST(5));
2019 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2020 for (i = 0; i < in_imgs_count; ++i) {
2021 sv1 = *av_fetch(av,i,0);
2022 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2023 croak("Parameter 5 must contain only images");
2025 tmp = SvIV((SV*)SvRV(sv1));
2026 in_imgs[i] = (i_img*)tmp;
2030 /* no input images */
2033 /* default the output size from the first input if possible */
2035 width = SvIV(ST(0));
2036 else if (in_imgs_count)
2037 width = in_imgs[0]->xsize;
2039 croak("No output image width supplied");
2042 height = SvIV(ST(1));
2043 else if (in_imgs_count)
2044 height = in_imgs[0]->ysize;
2046 croak("No output image height supplied");
2048 ops = (struct rm_op *)SvPV(ST(2), ops_len);
2049 if (ops_len % sizeof(struct rm_op))
2050 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2051 ops_count = ops_len / sizeof(struct rm_op);
2052 av = (AV*)SvRV(ST(3));
2053 n_regs_count = av_len(av)+1;
2054 n_regs = mymalloc(n_regs_count * sizeof(double));
2055 for (i = 0; i < n_regs_count; ++i) {
2056 sv1 = *av_fetch(av,i,0);
2058 n_regs[i] = SvNV(sv1);
2060 av = (AV*)SvRV(ST(4));
2061 c_regs_count = av_len(av)+1;
2062 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2063 /* I don't bother initializing the colou?r registers */
2065 RETVAL=i_transform2(width, height, 3, ops, ops_count,
2066 n_regs, n_regs_count,
2067 c_regs, c_regs_count, in_imgs, in_imgs_count);
2072 ST(0) = sv_newmortal();
2073 if (RETVAL == 0) ST(0)=&PL_sv_undef;
2074 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
2078 i_contrast(im,intensity)
2087 i_noise(im,amount,type)
2093 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2103 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2122 i_postlevels(im,levels)
2132 i_watermark(im,wmark,tx,ty,pixdiff)
2134 Imager::ImgRaw wmark
2141 i_autolevels(im,lsat,usat,skew)
2148 i_radnoise(im,xo,yo,rscale,ascale)
2156 i_turbnoise(im, xo, yo, scale)
2179 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2180 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2181 croak("i_gradgen: Second argument must be an array ref");
2182 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2183 croak("i_gradgen: Third argument must be an array ref");
2184 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2185 croak("i_gradgen: Fourth argument must be an array ref");
2186 axx = (AV *)SvRV(ST(1));
2187 ayy = (AV *)SvRV(ST(2));
2188 ac = (AV *)SvRV(ST(3));
2189 dmeasure = (int)SvIV(ST(4));
2191 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2192 num = num <= av_len(ac) ? num : av_len(ac);
2194 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2195 xo = mymalloc( sizeof(int) * num );
2196 yo = mymalloc( sizeof(int) * num );
2197 ival = mymalloc( sizeof(i_color) * num );
2198 for(i = 0; i<num; i++) {
2199 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2200 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2201 sv = *av_fetch(ac, i, 0);
2202 if ( !sv_derived_from(sv, "Imager::Color") ) {
2203 free(axx); free(ayy); free(ac);
2204 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2206 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2208 i_gradgen(im, num, xo, yo, ival, dmeasure);
2215 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2225 double ssample_param
2229 i_fountain_seg *segs;
2231 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2232 croak("i_fountain: argument 11 must be an array ref");
2234 asegs = (AV *)SvRV(ST(10));
2235 segs = load_fount_segs(asegs, &count);
2236 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2237 ssample_param, count, segs);
2241 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2250 double ssample_param
2254 i_fountain_seg *segs;
2256 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2257 croak("i_fountain: argument 11 must be an array ref");
2259 asegs = (AV *)SvRV(ST(9));
2260 segs = load_fount_segs(asegs, &count);
2261 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2262 super_sample, ssample_param, count, segs);
2276 errors = i_errors();
2278 while (errors[i].msg) {
2280 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2281 if (!av_store(av, 0, sv)) {
2284 sv = newSViv(errors[i].code);
2285 if (!av_store(av, 1, sv)) {
2288 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2293 i_nearest_color(im, ...)
2308 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2309 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2310 croak("i_nearest_color: Second argument must be an array ref");
2311 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2312 croak("i_nearest_color: Third argument must be an array ref");
2313 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2314 croak("i_nearest_color: Fourth argument must be an array ref");
2315 axx = (AV *)SvRV(ST(1));
2316 ayy = (AV *)SvRV(ST(2));
2317 ac = (AV *)SvRV(ST(3));
2318 dmeasure = (int)SvIV(ST(4));
2320 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2321 num = num <= av_len(ac) ? num : av_len(ac);
2323 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2324 xo = mymalloc( sizeof(int) * num );
2325 yo = mymalloc( sizeof(int) * num );
2326 ival = mymalloc( sizeof(i_color) * num );
2327 for(i = 0; i<num; i++) {
2328 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2329 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2330 sv = *av_fetch(ac, i, 0);
2331 if ( !sv_derived_from(sv, "Imager::Color") ) {
2332 free(axx); free(ayy); free(ac);
2333 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2335 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2337 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2351 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2352 hv=(HV*)SvRV(ST(0));
2353 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2354 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2355 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2364 rc=DSO_open(filename,&evstr);
2368 PUSHs(sv_2mortal(newSViv((IV)rc)));
2369 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2372 PUSHs(sv_2mortal(newSViv((IV)rc)));
2378 DSO_close(dso_handle)
2382 DSO_funclist(dso_handle_v)
2386 DSO_handle *dso_handle;
2388 dso_handle=(DSO_handle*)dso_handle_v;
2390 while( dso_handle->function_list[i].name != NULL) {
2392 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2394 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2399 DSO_call(handle,func_index,hv)
2405 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2406 hv=(HV*)SvRV(ST(2));
2407 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2408 DSO_call( (DSO_handle *)handle,func_index,hv);
2412 # this is mostly for testing...
2414 i_get_pixel(im, x, y)
2421 color = (i_color *)mymalloc(sizeof(i_color));
2422 if (i_gpix(im, x, y, color) == 0) {
2423 ST(0) = sv_newmortal();
2424 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2428 ST(0) = &PL_sv_undef;
2433 i_ppix(im, x, y, cl)
2440 i_img_pal_new(x, y, channels, maxpal)
2447 i_img_to_pal(src, quant)
2453 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2454 croak("i_img_to_pal: second argument must be a hash ref");
2455 hv = (HV *)SvRV(ST(1));
2456 memset(&quant, 0, sizeof(quant));
2457 quant.mc_size = 256;
2458 handle_quant_opts(&quant, hv);
2459 RETVAL = i_img_to_pal(src, &quant);
2461 copy_colors_back(hv, &quant);
2463 cleanup_quant_opts(&quant);
2482 work = mymalloc((r-l) * sizeof(i_palidx));
2483 count = i_gpal(im, l, r, y, work);
2484 if (GIMME_V == G_ARRAY) {
2486 for (i = 0; i < count; ++i) {
2487 PUSHs(sv_2mortal(newSViv(work[i])));
2492 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2497 if (GIMME_V != G_ARRAY) {
2499 PUSHs(&PL_sv_undef);
2504 i_ppal(im, l, y, ...)
2513 work = mymalloc(sizeof(i_palidx) * (items-3));
2514 for (i=0; i < items-3; ++i) {
2515 work[i] = SvIV(ST(i+3));
2517 RETVAL = i_ppal(im, l, l+items-3, y, work);
2527 i_addcolors(im, ...)
2535 croak("i_addcolors: no colors to add");
2536 colors = mymalloc((items-1) * sizeof(i_color));
2537 for (i=0; i < items-1; ++i) {
2538 if (sv_isobject(ST(i+1))
2539 && sv_derived_from(ST(i+1), "Imager::Color")) {
2540 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2541 colors[i] = *(i_color *)tmp;
2545 croak("i_plin: pixels must be Imager::Color objects");
2548 index = i_addcolors(im, colors, items-1);
2551 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2553 else if (index == -1) {
2554 ST(0) = &PL_sv_undef;
2557 ST(0) = sv_2mortal(newSViv(index));
2561 i_setcolors(im, index, ...)
2569 croak("i_setcolors: no colors to add");
2570 colors = mymalloc((items-2) * sizeof(i_color));
2571 for (i=0; i < items-2; ++i) {
2572 if (sv_isobject(ST(i+2))
2573 && sv_derived_from(ST(i+2), "Imager::Color")) {
2574 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2575 colors[i] = *(i_color *)tmp;
2579 croak("i_setcolors: pixels must be Imager::Color objects");
2582 RETVAL = i_setcolors(im, index, colors, items-2);
2586 i_getcolors(im, index, ...)
2595 croak("i_getcolors: too many arguments");
2597 count = SvIV(ST(2));
2599 croak("i_getcolors: count must be positive");
2600 colors = mymalloc(sizeof(i_color) * count);
2601 if (i_getcolors(im, index, colors, count)) {
2602 for (i = 0; i < count; ++i) {
2604 SV *sv = sv_newmortal();
2605 pv = mymalloc(sizeof(i_color));
2607 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2620 count = i_colorcount(im);
2622 ST(0) = sv_2mortal(newSViv(count));
2625 ST(0) = &PL_sv_undef;
2634 count = i_maxcolors(im);
2636 ST(0) = sv_2mortal(newSViv(count));
2639 ST(0) = &PL_sv_undef;
2643 i_findcolor(im, color)
2649 if (i_findcolor(im, color, &index)) {
2650 ST(0) = sv_2mortal(newSViv(index));
2653 ST(0) = &PL_sv_undef;
2669 i_gsamp(im, l, r, y, ...)
2681 croak("No channel numbers supplied to g_samp()");
2683 chan_count = items - 4;
2684 chans = mymalloc(sizeof(int) * chan_count);
2685 for (i = 0; i < chan_count; ++i)
2686 chans[i] = SvIV(ST(i+4));
2687 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count); /* XXX: memleak? */
2688 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2690 if (GIMME_V == G_ARRAY) {
2692 for (i = 0; i < count; ++i)
2693 PUSHs(sv_2mortal(newSViv(data[i])));
2697 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2702 if (GIMME_V != G_ARRAY) {
2704 PUSHs(&PL_sv_undef);
2710 i_img_masked_new(targ, mask, x, y, w, h)
2720 if (!sv_isobject(ST(1))
2721 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2722 croak("i_img_masked_new: parameter 2 must undef or an image");
2724 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2728 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2733 i_plin(im, l, y, ...)
2742 work = mymalloc(sizeof(i_color) * (items-3));
2743 for (i=0; i < items-3; ++i) {
2744 if (sv_isobject(ST(i+3))
2745 && sv_derived_from(ST(i+3), "Imager::Color")) {
2746 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2747 work[i] = *(i_color *)tmp;
2751 croak("i_plin: pixels must be Imager::Color objects");
2755 RETVAL = i_plin(im, l, l+items-3, y, work);
2765 i_ppixf(im, x, y, cl)
2769 Imager::Color::Float cl
2772 i_gsampf(im, l, r, y, ...)
2784 croak("No channel numbers supplied to g_sampf()");
2786 chan_count = items - 4;
2787 chans = mymalloc(sizeof(int) * chan_count);
2788 for (i = 0; i < chan_count; ++i)
2789 chans[i] = SvIV(ST(i+4));
2790 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2791 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2792 if (GIMME_V == G_ARRAY) {
2794 for (i = 0; i < count; ++i)
2795 PUSHs(sv_2mortal(newSVnv(data[i])));
2799 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2803 if (GIMME_V != G_ARRAY) {
2805 PUSHs(&PL_sv_undef);
2810 i_plinf(im, l, y, ...)
2819 work = mymalloc(sizeof(i_fcolor) * (items-3));
2820 for (i=0; i < items-3; ++i) {
2821 if (sv_isobject(ST(i+3))
2822 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2823 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2824 work[i] = *(i_fcolor *)tmp;
2828 croak("i_plin: pixels must be Imager::Color::Float objects");
2832 RETVAL = i_plinf(im, l, l+items-3, y, work);
2849 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2850 if (i_gpixf(im, x, y, color) == 0) {
2851 ST(0) = sv_newmortal();
2852 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2856 ST(0) = &PL_sv_undef;
2870 vals = mymalloc((r-l) * sizeof(i_color));
2871 count = i_glin(im, l, r, y, vals);
2873 for (i = 0; i < count; ++i) {
2875 i_color *col = mymalloc(sizeof(i_color));
2876 sv = sv_newmortal();
2877 sv_setref_pv(sv, "Imager::Color", (void *)col);
2884 i_glinf(im, l, r, y)
2894 vals = mymalloc((r-l) * sizeof(i_fcolor));
2895 count = i_glinf(im, l, r, y, vals);
2897 for (i = 0; i < count; ++i) {
2899 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2901 sv = sv_newmortal();
2902 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2909 i_img_16_new(x, y, ch)
2915 i_img_double_new(x, y, ch)
2921 i_tags_addn(im, name, code, idata)
2930 name = SvPV(ST(1), len);
2933 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2938 i_tags_add(im, name, code, data, idata)
2948 name = SvPV(ST(1), len);
2952 data = SvPV(ST(3), len);
2957 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2962 i_tags_find(im, name, start)
2969 if (i_tags_find(&im->tags, name, start, &entry)) {
2971 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2973 ST(0) = sv_2mortal(newSViv(entry));
2975 ST(0) = &PL_sv_undef;
2979 i_tags_findn(im, code, start)
2986 if (i_tags_findn(&im->tags, code, start, &entry)) {
2988 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2990 ST(0) = sv_2mortal(newSViv(entry));
2993 ST(0) = &PL_sv_undef;
2996 i_tags_delete(im, entry)
3000 RETVAL = i_tags_delete(&im->tags, entry);
3005 i_tags_delbyname(im, name)
3009 RETVAL = i_tags_delbyname(&im->tags, name);
3014 i_tags_delbycode(im, code)
3018 RETVAL = i_tags_delbycode(&im->tags, code);
3023 i_tags_get(im, index)
3027 if (index >= 0 && index < im->tags.count) {
3028 i_img_tag *entry = im->tags.tags + index;
3032 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
3035 PUSHs(sv_2mortal(newSViv(entry->code)));
3038 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
3041 PUSHs(sv_2mortal(newSViv(entry->idata)));
3049 RETVAL = im->tags.count;
3056 i_wf_bbox(face, size, text)
3063 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
3065 PUSHs(sv_2mortal(newSViv(cords[0])));
3066 PUSHs(sv_2mortal(newSViv(cords[1])));
3067 PUSHs(sv_2mortal(newSViv(cords[2])));
3068 PUSHs(sv_2mortal(newSViv(cords[3])));
3069 PUSHs(sv_2mortal(newSViv(cords[4])));
3070 PUSHs(sv_2mortal(newSViv(cords[5])));
3074 i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
3085 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
3091 i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
3102 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
3112 MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
3114 #define FT2_DESTROY(font) i_ft2_destroy(font)
3118 Imager::Font::FT2 font
3120 MODULE = Imager PACKAGE = Imager::Font::FreeType2
3123 i_ft2_new(name, index)
3128 i_ft2_setdpi(font, xdpi, ydpi)
3129 Imager::Font::FT2 font
3135 Imager::Font::FT2 font
3139 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
3141 PUSHs(sv_2mortal(newSViv(xdpi)));
3142 PUSHs(sv_2mortal(newSViv(ydpi)));
3146 i_ft2_sethinting(font, hinting)
3147 Imager::Font::FT2 font
3151 i_ft2_settransform(font, matrix)
3152 Imager::Font::FT2 font
3160 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3161 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3162 av=(AV*)SvRV(ST(1));
3166 for (i = 0; i < len; ++i) {
3167 sv1=(*(av_fetch(av,i,0)));
3168 matrix[i] = SvNV(sv1);
3172 RETVAL = i_ft2_settransform(font, matrix);
3177 i_ft2_bbox(font, cheight, cwidth, text, utf8)
3178 Imager::Font::FT2 font
3191 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox, utf8)) {
3193 for (i = 0; i < 6; ++i)
3194 PUSHs(sv_2mortal(newSViv(bbox[i])));
3198 i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3199 Imager::Font::FT2 font
3213 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3216 for (i = 0; i < 8; ++i)
3217 PUSHs(sv_2mortal(newSViv(bbox[i])));
3221 i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3222 Imager::Font::FT2 font
3238 if (SvUTF8(ST(7))) {
3242 text = SvPV(ST(7), len);
3243 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3244 len, align, aa, vlayout, utf8);
3249 i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3250 Imager::Font::FT2 font
3267 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3268 strlen(text), align, aa, vlayout, 1);
3273 ft2_transform_box(font, x0, x1, x2, x3)
3274 Imager::Font::FT2 font
3282 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3283 ft2_transform_box(font, box);
3285 PUSHs(sv_2mortal(newSViv(box[0])));
3286 PUSHs(sv_2mortal(newSViv(box[1])));
3287 PUSHs(sv_2mortal(newSViv(box[2])));
3288 PUSHs(sv_2mortal(newSViv(box[3])));
3291 i_ft2_has_chars(handle, text, utf8)
3292 Imager::Font::FT2 handle
3305 text = SvPV(ST(1), len);
3306 work = mymalloc(len);
3307 count = i_ft2_has_chars(handle, text, len, utf8, work);
3308 if (GIMME_V == G_ARRAY) {
3310 for (i = 0; i < count; ++i) {
3311 PUSHs(sv_2mortal(newSViv(work[i])));
3316 PUSHs(sv_2mortal(newSVpv(work, count)));
3322 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3326 Imager::FillHandle fill
3328 MODULE = Imager PACKAGE = Imager
3331 i_new_fill_solid(cl, combine)
3336 i_new_fill_solidf(cl, combine)
3337 Imager::Color::Float cl
3341 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3349 unsigned char *cust_hatch;
3353 cust_hatch = SvPV(ST(4), len);
3357 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3362 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3363 Imager::Color::Float fg
3364 Imager::Color::Float bg
3370 unsigned char *cust_hatch;
3374 cust_hatch = SvPV(ST(4), len);
3378 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3383 i_new_fill_image(src, matrix, xoff, yoff, combine)
3400 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3401 croak("i_new_fill_image: parameter must be an arrayref");
3402 av=(AV*)SvRV(ST(1));
3406 for (i = 0; i < len; ++i) {
3407 sv1=(*(av_fetch(av,i,0)));
3408 matrix[i] = SvNV(sv1);
3414 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);