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__TTHandle;
28 typedef FT2_Fonthandle* Imager__Font__FT2;
31 typedef struct i_reader_data_tag
33 /* presumably a CODE ref or name of a sub */
37 /* used by functions that want callbacks */
38 static int read_callback(char *userdata, char *buffer, int need, int want) {
39 i_reader_data *rd = (i_reader_data *)userdata;
43 dSP; dTARG = sv_newmortal();
44 /* thanks to Simon Cozens for help with the dTARG above */
54 count = perl_call_sv(rd->sv, G_SCALAR);
59 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
65 char *ptr = SvPV(data, len);
67 croak("Too much data returned in reader callback");
69 memcpy(buffer, ptr, len);
85 SV *sv; /* a coderef or sub name */
88 /* used by functions that want callbacks */
89 static int write_callback(char *userdata, char const *data, int size) {
90 i_writer_data *wd = (i_writer_data *)userdata;
100 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
103 count = perl_call_sv(wd->sv, G_SCALAR);
108 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
111 success = SvTRUE(sv);
125 static int lookup_name(struct value_name *names, int count, char *name, int def_value)
128 for (i = 0; i < count; ++i)
129 if (strEQ(names[i].name, name))
130 return names[i].value;
134 static struct value_name transp_names[] =
137 { "threshold", tr_threshold },
138 { "errdiff", tr_errdiff },
139 { "ordered", tr_ordered, },
142 static struct value_name make_color_names[] =
144 { "none", mc_none, },
145 { "webmap", mc_web_map, },
146 { "addi", mc_addi, },
149 static struct value_name translate_names[] =
152 { "giflib", pt_giflib, },
154 { "closest", pt_closest, },
155 { "perturb", pt_perturb, },
156 { "errdiff", pt_errdiff, },
159 static struct value_name errdiff_names[] =
161 { "floyd", ed_floyd, },
162 { "jarvis", ed_jarvis, },
163 { "stucki", ed_stucki, },
164 { "custom", ed_custom, },
167 static struct value_name orddith_names[] =
169 { "random", od_random, },
170 { "dot8", od_dot8, },
171 { "dot4", od_dot4, },
172 { "hline", od_hline, },
173 { "vline", od_vline, },
174 { "/line", od_slashline, },
175 { "slashline", od_slashline, },
176 { "\\line", od_backline, },
177 { "backline", od_backline, },
178 { "tiny", od_tiny, },
179 { "custom", od_custom, },
183 hv_fetch_bool(HV *hv, char *name, int def) {
186 sv = hv_fetch(hv, name, strlen(name), 0);
195 hv_fetch_int(HV *hv, char *name, int def) {
198 sv = hv_fetch(hv, name, strlen(name), 0);
206 /* look through the hash for quantization options */
207 static void handle_quant_opts(i_quantize *quant, HV *hv)
209 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
215 sv = hv_fetch(hv, "transp", 6, 0);
216 if (sv && *sv && (str = SvPV(*sv, len))) {
218 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
220 if (quant->transp != tr_none) {
221 quant->tr_threshold = 127;
222 sv = hv_fetch(hv, "tr_threshold", 12, 0);
224 quant->tr_threshold = SvIV(*sv);
226 if (quant->transp == tr_errdiff) {
227 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
228 if (sv && *sv && (str = SvPV(*sv, len)))
229 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
231 if (quant->transp == tr_ordered) {
232 quant->tr_orddith = od_tiny;
233 sv = hv_fetch(hv, "tr_orddith", 10, 0);
234 if (sv && *sv && (str = SvPV(*sv, len)))
235 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
237 if (quant->tr_orddith == od_custom) {
238 sv = hv_fetch(hv, "tr_map", 6, 0);
239 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
240 AV *av = (AV*)SvRV(*sv);
241 len = av_len(av) + 1;
242 if (len > sizeof(quant->tr_custom))
243 len = sizeof(quant->tr_custom);
244 for (i = 0; i < len; ++i) {
245 SV **sv2 = av_fetch(av, i, 0);
247 quant->tr_custom[i] = SvIV(*sv2);
250 while (i < sizeof(quant->tr_custom))
251 quant->tr_custom[i++] = 0;
256 quant->make_colors = mc_addi;
257 sv = hv_fetch(hv, "make_colors", 11, 0);
258 if (sv && *sv && (str = SvPV(*sv, len))) {
260 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
262 sv = hv_fetch(hv, "colors", 6, 0);
263 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
264 /* needs to be an array of Imager::Color
265 note that the caller allocates the mc_color array and sets mc_size
267 AV *av = (AV *)SvRV(*sv);
268 quant->mc_count = av_len(av)+1;
269 if (quant->mc_count > quant->mc_size)
270 quant->mc_count = quant->mc_size;
271 for (i = 0; i < quant->mc_count; ++i) {
272 SV **sv1 = av_fetch(av, i, 0);
273 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
274 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
275 quant->mc_colors[i] = *col;
279 sv = hv_fetch(hv, "max_colors", 10, 0);
282 if (i <= quant->mc_size && i >= quant->mc_count)
286 quant->translate = pt_closest;
287 sv = hv_fetch(hv, "translate", 9, 0);
288 if (sv && *sv && (str = SvPV(*sv, len))) {
289 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
291 sv = hv_fetch(hv, "errdiff", 7, 0);
292 if (sv && *sv && (str = SvPV(*sv, len))) {
293 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
295 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
296 /* get the error diffusion map */
297 sv = hv_fetch(hv, "errdiff_width", 13, 0);
299 quant->ed_width = SvIV(*sv);
300 sv = hv_fetch(hv, "errdiff_height", 14, 0);
302 quant->ed_height = SvIV(*sv);
303 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
305 quant->ed_orig = SvIV(*sv);
306 if (quant->ed_width > 0 && quant->ed_height > 0) {
308 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
309 sv = hv_fetch(hv, "errdiff_map", 11, 0);
310 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
311 AV *av = (AV*)SvRV(*sv);
312 len = av_len(av) + 1;
313 if (len > quant->ed_width * quant->ed_height)
314 len = quant->ed_width * quant->ed_height;
315 for (i = 0; i < len; ++i) {
316 SV **sv2 = av_fetch(av, i, 0);
318 quant->ed_map[i] = SvIV(*sv2);
319 sum += quant->ed_map[i];
325 myfree(quant->ed_map);
327 quant->errdiff = ed_floyd;
331 sv = hv_fetch(hv, "perturb", 7, 0);
333 quant->perturb = SvIV(*sv);
336 /* look through the hash for options to add to opts */
337 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
341 /**((char *)0) = '\0';*/
342 opts->each_palette = hv_fetch_bool(hv, "gif_each_palette", 0);
343 opts->interlace = hv_fetch_bool(hv, "interlace", 0);
345 sv = hv_fetch(hv, "gif_delays", 10, 0);
346 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
347 AV *av = (AV*)SvRV(*sv);
348 opts->delay_count = av_len(av)+1;
349 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
350 for (i = 0; i < opts->delay_count; ++i) {
351 SV *sv1 = *av_fetch(av, i, 0);
352 opts->delays[i] = SvIV(sv1);
355 sv = hv_fetch(hv, "gif_user_input", 14, 0);
356 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
357 AV *av = (AV*)SvRV(*sv);
358 opts->user_input_count = av_len(av)+1;
359 opts->user_input_flags = mymalloc(opts->user_input_count);
360 for (i = 0; i < opts->user_input_count; ++i) {
361 SV *sv1 = *av_fetch(av, i, 0);
362 opts->user_input_flags[i] = SvIV(sv1) != 0;
365 sv = hv_fetch(hv, "gif_disposal", 12, 0);
366 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
367 AV *av = (AV*)SvRV(*sv);
368 opts->disposal_count = av_len(av)+1;
369 opts->disposal = mymalloc(opts->disposal_count);
370 for (i = 0; i < opts->disposal_count; ++i) {
371 SV *sv1 = *av_fetch(av, i, 0);
372 opts->disposal[i] = SvIV(sv1);
375 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
376 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
377 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
378 opts->tran_color = *col;
380 sv = hv_fetch(hv, "gif_positions", 13, 0);
381 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
382 AV *av = (AV *)SvRV(*sv);
383 opts->position_count = av_len(av) + 1;
384 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
385 for (i = 0; i < opts->position_count; ++i) {
386 SV **sv2 = av_fetch(av, i, 0);
387 opts->positions[i].x = opts->positions[i].y = 0;
388 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
389 AV *av2 = (AV*)SvRV(*sv2);
391 sv3 = av_fetch(av2, 0, 0);
393 opts->positions[i].x = SvIV(*sv3);
394 sv3 = av_fetch(av2, 1, 0);
396 opts->positions[i].y = SvIV(*sv3);
400 /* Netscape2.0 loop count extension */
401 opts->loop_count = hv_fetch_int(hv, "gif_loop_count", 0);
403 opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1);
406 /* copies the color map from the hv into the colors member of the HV */
407 static void copy_colors_back(HV *hv, i_quantize *quant) {
413 sv = hv_fetch(hv, "colors", 6, 0);
414 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
417 ref = newRV_inc((SV*) av);
418 sv = hv_store(hv, "colors", 6, ref, 0);
421 av = (AV *)SvRV(*sv);
423 av_extend(av, quant->mc_count+1);
424 for (i = 0; i < quant->mc_count; ++i) {
425 i_color *in = quant->mc_colors+i;
426 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
427 work = sv_newmortal();
428 sv_setref_pv(work, "Imager::Color", (void *)c);
430 if (!av_store(av, i, work)) {
436 /* loads the segments of a fountain fill into an array */
437 i_fountain_seg *load_fount_segs(AV *asegs, int *count) {
438 /* Each element of segs must contain:
439 [ start, middle, end, c0, c1, segtype, colortrans ]
440 start, middle, end are doubles from 0 to 1
441 c0, c1 are Imager::Color::Float or Imager::Color objects
442 segtype, colortrans are ints
447 i_fountain_seg *segs;
451 *count = av_len(asegs)+1;
453 croak("i_fountain must have at least one segment");
454 segs = mymalloc(sizeof(i_fountain_seg) * *count);
455 for(i = 0; i < *count; i++) {
456 SV **sv1 = av_fetch(asegs, i, 0);
457 if (!sv1 || !*sv1 || !SvROK(*sv1)
458 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
460 croak("i_fountain: segs must be an arrayref of arrayrefs");
462 aseg = (AV *)SvRV(*sv1);
463 if (av_len(aseg) != 7-1) {
465 croak("i_fountain: a segment must have 7 members");
467 for (j = 0; j < 3; ++j) {
468 SV **sv2 = av_fetch(aseg, j, 0);
471 croak("i_fountain: XS error");
473 work[j] = SvNV(*sv2);
475 segs[i].start = work[0];
476 segs[i].middle = work[1];
477 segs[i].end = work[2];
478 for (j = 0; j < 2; ++j) {
479 SV **sv3 = av_fetch(aseg, 3+j, 0);
480 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
481 (!sv_derived_from(*sv3, "Imager::Color")
482 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
484 croak("i_fountain: segs must contain colors in elements 3 and 4");
486 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
487 segs[i].c[j] = *(i_fcolor *)SvIV((SV *)SvRV(*sv3));
490 i_color c = *(i_color *)SvIV((SV *)SvRV(*sv3));
492 for (ch = 0; ch < MAXCHANNELS; ++ch) {
493 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
497 for (j = 0; j < 2; ++j) {
498 SV **sv2 = av_fetch(aseg, j+5, 0);
501 croak("i_fountain: XS error");
503 worki[j] = SvIV(*sv2);
505 segs[i].type = worki[0];
506 segs[i].color = worki[1];
512 /* I don't think ICLF_* names belong at the C interface
513 this makes the XS code think we have them, to let us avoid
514 putting function bodies in the XS code
516 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
517 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
519 /* for the fill objects
520 Since a fill object may later have dependent images, (or fills!)
521 we need perl wrappers - oh well
523 #define IFILL_DESTROY(fill) i_fill_destroy(fill);
524 typedef i_fill_t* Imager__FillHandle;
526 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
529 ICL_new_internal(r,g,b,a)
541 ICL_set_internal(cl,r,g,b,a)
548 ICL_set_internal(cl, r, g, b, a);
562 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
563 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
564 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
565 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
571 RETVAL = mymalloc(sizeof(i_color));
573 i_hsv_to_rgb(RETVAL);
581 RETVAL = mymalloc(sizeof(i_color));
583 i_rgb_to_hsv(RETVAL);
589 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
592 ICLF_new_internal(r, g, b, a)
600 Imager::Color::Float cl
604 Imager::Color::Float cl
608 EXTEND(SP, MAXCHANNELS);
609 for (ch = 0; ch < MAXCHANNELS; ++ch) {
610 /* printf("%d: %g\n", ch, cl->channel[ch]); */
611 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
615 ICLF_set_internal(cl,r,g,b,a)
616 Imager::Color::Float cl
631 Imager::Color::Float c
633 RETVAL = mymalloc(sizeof(i_fcolor));
635 i_hsv_to_rgbf(RETVAL);
641 Imager::Color::Float c
643 RETVAL = mymalloc(sizeof(i_fcolor));
645 i_rgb_to_hsvf(RETVAL);
650 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
664 MODULE = Imager PACKAGE = Imager
686 tlength = io_slurp(ig, &data);
689 PUSHs(sv_2mortal(newSVpv(data,tlength)));
693 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_glue_
700 MODULE = Imager PACKAGE = Imager
713 while( (item=i_format_list[i++]) != NULL ) {
715 PUSHs(sv_2mortal(newSVpv(item,0)));
732 i_img_empty_ch(im,x,y,ch)
759 PUSHs(sv_2mortal(newSViv(info[0])));
760 PUSHs(sv_2mortal(newSViv(info[1])));
761 PUSHs(sv_2mortal(newSViv(info[2])));
762 PUSHs(sv_2mortal(newSViv(info[3])));
768 i_img_setmask(im,ch_mask)
777 i_img_getchannels(im)
785 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
790 i_draw(im,x1,y1,x2,y2,val)
799 i_line_aa(im,x1,y1,x2,y2,val)
808 i_box(im,x1,y1,x2,y2,val)
817 i_box_filled(im,x1,y1,x2,y2,val)
826 i_box_cfill(im,x1,y1,x2,y2,fill)
832 Imager::FillHandle fill
835 i_arc(im,x,y,rad,d1,d2,val)
845 i_arc_cfill(im,x,y,rad,d1,d2,fill)
852 Imager::FillHandle fill
857 i_circle_aa(im,x,y,rad,val)
867 i_bezier_multi(im,xc,yc,val)
880 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
881 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
882 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
883 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
884 av1=(AV*)SvRV(ST(1));
885 av2=(AV*)SvRV(ST(2));
886 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
888 x=mymalloc( len*sizeof(double) );
889 y=mymalloc( len*sizeof(double) );
891 sv1=(*(av_fetch(av1,i,0)));
892 sv2=(*(av_fetch(av2,i,0)));
893 x[i]=(double)SvNV(sv1);
894 y[i]=(double)SvNV(sv2);
896 i_bezier_multi(im,len,x,y,val);
902 i_poly_aa(im,xc,yc,val)
915 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
916 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
917 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
918 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
919 av1=(AV*)SvRV(ST(1));
920 av2=(AV*)SvRV(ST(2));
921 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
923 x=mymalloc( len*sizeof(double) );
924 y=mymalloc( len*sizeof(double) );
926 sv1=(*(av_fetch(av1,i,0)));
927 sv2=(*(av_fetch(av2,i,0)));
928 x[i]=(double)SvNV(sv1);
929 y[i]=(double)SvNV(sv2);
931 i_poly_aa(im,len,x,y,val);
938 i_flood_fill(im,seedx,seedy,dcol)
945 i_flood_cfill(im,seedx,seedy,fill)
949 Imager::FillHandle fill
953 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
965 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
983 i_rubthru(im,src,tx,ty)
990 i_flipxy(im, direction)
995 i_rotate90(im, degrees)
1000 i_rotate_exact(im, amount)
1005 i_matrix_transform(im, xsize, ysize, matrix)
1016 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
1017 croak("i_matrix_transform: parameter 4 must be an array ref\n");
1018 av=(AV*)SvRV(ST(3));
1022 for (i = 0; i < len; ++i) {
1023 sv1=(*(av_fetch(av,i,0)));
1024 matrix[i] = SvNV(sv1);
1028 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
1033 i_gaussian(im,stdev)
1038 i_unsharp_mask(im,stdev,scale)
1053 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1054 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1055 av=(AV*)SvRV(ST(1));
1057 coeff=mymalloc( len*sizeof(float) );
1058 for(i=0;i<len;i++) {
1059 sv1=(*(av_fetch(av,i,0)));
1060 coeff[i]=(float)SvNV(sv1);
1062 i_conv(im,coeff,len);
1066 i_convert(im, src, coeff)
1080 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
1081 croak("i_convert: parameter 3 must be an arrayref\n");
1082 avmain = (AV*)SvRV(ST(2));
1083 outchan = av_len(avmain)+1;
1084 /* find the biggest */
1086 for (j=0; j < outchan; ++j) {
1087 temp = av_fetch(avmain, j, 0);
1088 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1089 avsub = (AV*)SvRV(*temp);
1090 len = av_len(avsub)+1;
1095 coeff = mymalloc(sizeof(float) * outchan * inchan);
1096 for (j = 0; j < outchan; ++j) {
1097 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1098 len = av_len(avsub)+1;
1099 for (i = 0; i < len; ++i) {
1100 temp = av_fetch(avsub, i, 0);
1102 coeff[i+j*inchan] = SvNV(*temp);
1104 coeff[i+j*inchan] = 0;
1107 coeff[i++ + j*inchan] = 0;
1109 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1119 unsigned int mask = 0;
1125 unsigned char (*maps)[256];
1127 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1128 croak("i_map: parameter 2 must be an arrayref\n");
1129 avmain = (AV*)SvRV(ST(1));
1130 len = av_len(avmain)+1;
1131 if (im->channels < len) len = im->channels;
1133 maps = mymalloc( len * sizeof(unsigned char [256]) );
1135 for (j=0; j<len ; j++) {
1136 temp = av_fetch(avmain, j, 0);
1137 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1138 avsub = (AV*)SvRV(*temp);
1139 if(av_len(avsub) != 255) continue;
1141 for (i=0; i<256 ; i++) {
1143 temp = av_fetch(avsub, i, 0);
1144 val = temp ? SvIV(*temp) : 0;
1146 if (val>255) val = 255;
1151 i_map(im, maps, mask);
1173 i_t1_new(pfb,afm=NULL)
1178 i_t1_destroy(font_id)
1183 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1195 i_t1_bbox(fontnum,point,str,len)
1203 i_t1_bbox(fontnum,point,str,len,cords);
1205 PUSHs(sv_2mortal(newSViv(cords[0])));
1206 PUSHs(sv_2mortal(newSViv(cords[1])));
1207 PUSHs(sv_2mortal(newSViv(cords[2])));
1208 PUSHs(sv_2mortal(newSViv(cords[3])));
1209 PUSHs(sv_2mortal(newSViv(cords[4])));
1210 PUSHs(sv_2mortal(newSViv(cords[5])));
1215 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1236 i_tt_destroy(handle)
1237 Imager::TTHandle handle
1242 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1243 Imager::TTHandle handle
1255 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1256 Imager::TTHandle handle
1269 i_tt_bbox(handle,point,str,len)
1270 Imager::TTHandle handle
1277 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1279 PUSHs(sv_2mortal(newSViv(cords[0])));
1280 PUSHs(sv_2mortal(newSViv(cords[1])));
1281 PUSHs(sv_2mortal(newSViv(cords[2])));
1282 PUSHs(sv_2mortal(newSViv(cords[3])));
1283 PUSHs(sv_2mortal(newSViv(cords[4])));
1284 PUSHs(sv_2mortal(newSViv(cords[5])));
1295 i_writejpeg_wiol(im, ig, qfactor)
1311 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1312 if (iptc_itext == NULL) {
1315 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1320 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1322 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1335 i_readtiff_wiol(ig, length)
1341 i_writetiff_wiol(im, ig)
1346 i_writetiff_wiol_faxable(im, ig, fine)
1352 #endif /* HAVE_LIBTIFF */
1361 i_readpng_wiol(ig, length)
1367 i_writepng_wiol(im, ig)
1380 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1383 i_writegif(im,fd,colors,pixdev,fixed)
1390 Imager__Color fixed;
1397 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1398 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1399 av=(AV*)SvRV(ST(4));
1400 fixedlen=av_len(av)+1;
1401 fixed=mymalloc( fixedlen*sizeof(i_color) );
1402 for(i=0;i<fixedlen;i++) {
1403 sv1=(*(av_fetch(av,i,0)));
1404 if (sv_derived_from(sv1, "Imager::Color")) {
1405 Itmp = SvIV((SV*)SvRV(sv1));
1406 tmp = (i_color*) Itmp;
1407 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1410 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1412 ST(0) = sv_newmortal();
1413 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1414 else sv_setiv(ST(0), (IV)RETVAL);
1420 i_writegifmc(im,fd,colors)
1427 i_writegif_gen(fd, ...)
1433 i_img **imgs = NULL;
1439 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1440 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1441 croak("i_writegif_gen: Second argument must be a hash ref");
1442 hv = (HV *)SvRV(ST(1));
1443 memset(&quant, 0, sizeof(quant));
1444 quant.mc_size = 256;
1445 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1446 memset(&opts, 0, sizeof(opts));
1447 handle_quant_opts(&quant, hv);
1448 handle_gif_opts(&opts, hv);
1449 img_count = items - 2;
1451 if (img_count < 1) {
1454 i_push_error(0, "You need to specify images to save");
1457 imgs = mymalloc(sizeof(i_img *) * img_count);
1458 for (i = 0; i < img_count; ++i) {
1461 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1462 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1466 i_push_error(0, "Only images can be saved");
1472 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1476 copy_colors_back(hv, &quant);
1479 ST(0) = sv_newmortal();
1480 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1481 else sv_setiv(ST(0), (IV)RETVAL);
1484 i_writegif_callback(cb, maxbuffer,...)
1489 i_img **imgs = NULL;
1496 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1497 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1498 croak("i_writegif_callback: Second argument must be a hash ref");
1499 hv = (HV *)SvRV(ST(2));
1500 memset(&quant, 0, sizeof(quant));
1501 quant.mc_size = 256;
1502 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1503 memset(&opts, 0, sizeof(opts));
1504 handle_quant_opts(&quant, hv);
1505 handle_gif_opts(&opts, hv);
1506 img_count = items - 3;
1508 if (img_count < 1) {
1512 imgs = mymalloc(sizeof(i_img *) * img_count);
1513 for (i = 0; i < img_count; ++i) {
1516 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1517 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1526 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1530 copy_colors_back(hv, &quant);
1533 ST(0) = sv_newmortal();
1534 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1535 else sv_setiv(ST(0), (IV)RETVAL);
1548 colour_table = NULL;
1551 if(GIMME_V == G_ARRAY) {
1552 rimg = i_readgif(fd,&colour_table,&colours);
1554 /* don't waste time with colours if they aren't wanted */
1555 rimg = i_readgif(fd,NULL,NULL);
1558 if (colour_table == NULL) {
1561 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1564 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1565 /* I don't know if I have the reference counts right or not :( */
1566 /* Neither do I :-) */
1567 /* No Idea here either */
1570 av_extend(ct, colours);
1571 for(q=0; q<colours; q++) {
1573 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1574 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1576 myfree(colour_table);
1580 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1582 PUSHs(newRV_noinc((SV*)ct));
1590 i_readgif_scalar(...)
1594 unsigned int length;
1602 data = (char *)SvPV(ST(0), length);
1606 if(GIMME_V == G_ARRAY) {
1607 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1609 /* don't waste time with colours if they aren't wanted */
1610 rimg=i_readgif_scalar(data,length,NULL,NULL);
1613 if (colour_table == NULL) {
1616 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1619 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1620 /* I don't know if I have the reference counts right or not :( */
1621 /* Neither do I :-) */
1623 av_extend(ct, colours);
1624 for(q=0; q<colours; q++) {
1626 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1627 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1629 myfree(colour_table);
1633 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1635 PUSHs(newRV_noinc((SV*)ct));
1639 i_readgif_callback(...)
1656 if(GIMME_V == G_ARRAY) {
1657 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1659 /* don't waste time with colours if they aren't wanted */
1660 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1663 if (colour_table == NULL) {
1666 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1669 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1670 /* I don't know if I have the reference counts right or not :( */
1671 /* Neither do I :-) */
1672 /* Neither do I - maybe I'll move this somewhere */
1674 av_extend(ct, colours);
1675 for(q=0; q<colours; q++) {
1677 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1678 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1680 myfree(colour_table);
1684 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1686 PUSHs(newRV_noinc((SV*)ct));
1697 imgs = i_readgif_multi(fd, &count);
1700 for (i = 0; i < count; ++i) {
1701 SV *sv = sv_newmortal();
1702 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1709 i_readgif_multi_scalar(data)
1714 unsigned int length;
1717 data = (char *)SvPV(ST(0), length);
1718 imgs = i_readgif_multi_scalar(data, length, &count);
1721 for (i = 0; i < count; ++i) {
1722 SV *sv = sv_newmortal();
1723 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1730 i_readgif_multi_callback(cb)
1738 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1741 for (i = 0; i < count; ++i) {
1742 SV *sv = sv_newmortal();
1743 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1754 i_readpnm_wiol(ig, length)
1760 i_writeppm_wiol(im, ig)
1766 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1775 i_writeraw_wiol(im,ig)
1780 i_writebmp_wiol(im,ig)
1790 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
1801 idlen = SvCUR(ST(4));
1802 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
1808 i_readtga_wiol(ig, length)
1814 i_scaleaxis(im,Value,Axis)
1820 i_scale_nn(im,scx,scy)
1830 i_count_colors(im,maxc)
1836 i_transform(im,opx,opy,parm)
1849 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1850 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1851 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1852 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1853 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1854 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1855 av=(AV*)SvRV(ST(1));
1857 opx=mymalloc( opxl*sizeof(int) );
1858 for(i=0;i<opxl;i++) {
1859 sv1=(*(av_fetch(av,i,0)));
1860 opx[i]=(int)SvIV(sv1);
1862 av=(AV*)SvRV(ST(2));
1864 opy=mymalloc( opyl*sizeof(int) );
1865 for(i=0;i<opyl;i++) {
1866 sv1=(*(av_fetch(av,i,0)));
1867 opy[i]=(int)SvIV(sv1);
1869 av=(AV*)SvRV(ST(3));
1870 parmlen=av_len(av)+1;
1871 parm=mymalloc( parmlen*sizeof(double) );
1872 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1873 sv1=(*(av_fetch(av,i,0)));
1874 parm[i]=(double)SvNV(sv1);
1876 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1880 ST(0) = sv_newmortal();
1881 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1882 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1885 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1904 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1905 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1906 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1907 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1908 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1910 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1912 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1913 av = (AV*)SvRV(ST(5));
1914 in_imgs_count = av_len(av)+1;
1915 for (i = 0; i < in_imgs_count; ++i) {
1916 sv1 = *av_fetch(av, i, 0);
1917 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1918 croak("Parameter 5 must contain only images");
1925 if (in_imgs_count > 0) {
1926 av = (AV*)SvRV(ST(5));
1927 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1928 for (i = 0; i < in_imgs_count; ++i) {
1929 sv1 = *av_fetch(av,i,0);
1930 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1931 croak("Parameter 5 must contain only images");
1933 tmp = SvIV((SV*)SvRV(sv1));
1934 in_imgs[i] = (i_img*)tmp;
1938 /* no input images */
1941 /* default the output size from the first input if possible */
1943 width = SvIV(ST(0));
1944 else if (in_imgs_count)
1945 width = in_imgs[0]->xsize;
1947 croak("No output image width supplied");
1950 height = SvIV(ST(1));
1951 else if (in_imgs_count)
1952 height = in_imgs[0]->ysize;
1954 croak("No output image height supplied");
1956 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1957 if (ops_len % sizeof(struct rm_op))
1958 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1959 ops_count = ops_len / sizeof(struct rm_op);
1960 av = (AV*)SvRV(ST(3));
1961 n_regs_count = av_len(av)+1;
1962 n_regs = mymalloc(n_regs_count * sizeof(double));
1963 for (i = 0; i < n_regs_count; ++i) {
1964 sv1 = *av_fetch(av,i,0);
1966 n_regs[i] = SvNV(sv1);
1968 av = (AV*)SvRV(ST(4));
1969 c_regs_count = av_len(av)+1;
1970 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1971 /* I don't bother initializing the colou?r registers */
1973 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1974 n_regs, n_regs_count,
1975 c_regs, c_regs_count, in_imgs, in_imgs_count);
1980 ST(0) = sv_newmortal();
1981 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1982 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1986 i_contrast(im,intensity)
1995 i_noise(im,amount,type)
2001 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2011 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2030 i_postlevels(im,levels)
2040 i_watermark(im,wmark,tx,ty,pixdiff)
2042 Imager::ImgRaw wmark
2049 i_autolevels(im,lsat,usat,skew)
2056 i_radnoise(im,xo,yo,rscale,ascale)
2064 i_turbnoise(im, xo, yo, scale)
2087 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2088 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2089 croak("i_gradgen: Second argument must be an array ref");
2090 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2091 croak("i_gradgen: Third argument must be an array ref");
2092 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2093 croak("i_gradgen: Fourth argument must be an array ref");
2094 axx = (AV *)SvRV(ST(1));
2095 ayy = (AV *)SvRV(ST(2));
2096 ac = (AV *)SvRV(ST(3));
2097 dmeasure = (int)SvIV(ST(4));
2099 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2100 num = num <= av_len(ac) ? num : av_len(ac);
2102 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2103 xo = mymalloc( sizeof(int) * num );
2104 yo = mymalloc( sizeof(int) * num );
2105 ival = mymalloc( sizeof(i_color) * num );
2106 for(i = 0; i<num; i++) {
2107 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2108 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2109 sv = *av_fetch(ac, i, 0);
2110 if ( !sv_derived_from(sv, "Imager::Color") ) {
2111 free(axx); free(ayy); free(ac);
2112 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2114 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2116 i_gradgen(im, num, xo, yo, ival, dmeasure);
2119 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2129 double ssample_param
2133 i_fountain_seg *segs;
2135 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2136 croak("i_fountain: argument 11 must be an array ref");
2138 asegs = (AV *)SvRV(ST(10));
2139 segs = load_fount_segs(asegs, &count);
2140 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2141 ssample_param, count, segs);
2145 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2154 double ssample_param
2158 i_fountain_seg *segs;
2160 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2161 croak("i_fountain: argument 11 must be an array ref");
2163 asegs = (AV *)SvRV(ST(9));
2164 segs = load_fount_segs(asegs, &count);
2165 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2166 super_sample, ssample_param, count, segs);
2180 errors = i_errors();
2182 while (errors[i].msg) {
2184 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2185 if (!av_store(av, 0, sv)) {
2188 sv = newSViv(errors[i].code);
2189 if (!av_store(av, 1, sv)) {
2192 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2197 i_nearest_color(im, ...)
2212 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2213 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2214 croak("i_nearest_color: Second argument must be an array ref");
2215 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2216 croak("i_nearest_color: Third argument must be an array ref");
2217 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2218 croak("i_nearest_color: Fourth argument must be an array ref");
2219 axx = (AV *)SvRV(ST(1));
2220 ayy = (AV *)SvRV(ST(2));
2221 ac = (AV *)SvRV(ST(3));
2222 dmeasure = (int)SvIV(ST(4));
2224 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2225 num = num <= av_len(ac) ? num : av_len(ac);
2227 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2228 xo = mymalloc( sizeof(int) * num );
2229 yo = mymalloc( sizeof(int) * num );
2230 ival = mymalloc( sizeof(i_color) * num );
2231 for(i = 0; i<num; i++) {
2232 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2233 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2234 sv = *av_fetch(ac, i, 0);
2235 if ( !sv_derived_from(sv, "Imager::Color") ) {
2236 free(axx); free(ayy); free(ac);
2237 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2239 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2241 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2255 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2256 hv=(HV*)SvRV(ST(0));
2257 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2258 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2259 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2268 rc=DSO_open(filename,&evstr);
2272 PUSHs(sv_2mortal(newSViv((IV)rc)));
2273 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2276 PUSHs(sv_2mortal(newSViv((IV)rc)));
2282 DSO_close(dso_handle)
2286 DSO_funclist(dso_handle_v)
2290 DSO_handle *dso_handle;
2292 dso_handle=(DSO_handle*)dso_handle_v;
2294 while( dso_handle->function_list[i].name != NULL) {
2296 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2298 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2303 DSO_call(handle,func_index,hv)
2309 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2310 hv=(HV*)SvRV(ST(2));
2311 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2312 DSO_call( (DSO_handle *)handle,func_index,hv);
2316 # this is mostly for testing...
2318 i_get_pixel(im, x, y)
2325 color = (i_color *)mymalloc(sizeof(i_color));
2326 if (i_gpix(im, x, y, color) == 0) {
2327 ST(0) = sv_newmortal();
2328 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2332 ST(0) = &PL_sv_undef;
2337 i_ppix(im, x, y, cl)
2344 i_img_pal_new(x, y, channels, maxpal)
2351 i_img_to_pal(src, quant)
2357 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2358 croak("i_img_to_pal: second argument must be a hash ref");
2359 hv = (HV *)SvRV(ST(1));
2360 memset(&quant, 0, sizeof(quant));
2361 quant.mc_size = 256;
2362 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2363 handle_quant_opts(&quant, hv);
2364 RETVAL = i_img_to_pal(src, &quant);
2366 copy_colors_back(hv, &quant);
2368 myfree(quant.mc_colors);
2387 work = mymalloc((r-l) * sizeof(i_palidx));
2388 count = i_gpal(im, l, r, y, work);
2389 if (GIMME_V == G_ARRAY) {
2391 for (i = 0; i < count; ++i) {
2392 PUSHs(sv_2mortal(newSViv(work[i])));
2397 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2402 if (GIMME_V != G_ARRAY) {
2404 PUSHs(&PL_sv_undef);
2409 i_ppal(im, l, y, ...)
2418 work = mymalloc(sizeof(i_palidx) * (items-3));
2419 for (i=0; i < items-3; ++i) {
2420 work[i] = SvIV(ST(i+3));
2422 RETVAL = i_ppal(im, l, l+items-3, y, work);
2432 i_addcolors(im, ...)
2440 croak("i_addcolors: no colors to add");
2441 colors = mymalloc((items-1) * sizeof(i_color));
2442 for (i=0; i < items-1; ++i) {
2443 if (sv_isobject(ST(i+1))
2444 && sv_derived_from(ST(i+1), "Imager::Color")) {
2445 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2446 colors[i] = *(i_color *)tmp;
2450 croak("i_plin: pixels must be Imager::Color objects");
2453 index = i_addcolors(im, colors, items-1);
2456 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2458 else if (index == -1) {
2459 ST(0) = &PL_sv_undef;
2462 ST(0) = sv_2mortal(newSViv(index));
2466 i_setcolors(im, index, ...)
2474 croak("i_setcolors: no colors to add");
2475 colors = mymalloc((items-2) * sizeof(i_color));
2476 for (i=0; i < items-2; ++i) {
2477 if (sv_isobject(ST(i+2))
2478 && sv_derived_from(ST(i+2), "Imager::Color")) {
2479 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2480 colors[i] = *(i_color *)tmp;
2484 croak("i_setcolors: pixels must be Imager::Color objects");
2487 RETVAL = i_setcolors(im, index, colors, items-2);
2491 i_getcolors(im, index, ...)
2500 croak("i_getcolors: too many arguments");
2502 count = SvIV(ST(2));
2504 croak("i_getcolors: count must be positive");
2505 colors = mymalloc(sizeof(i_color) * count);
2506 if (i_getcolors(im, index, colors, count)) {
2507 for (i = 0; i < count; ++i) {
2509 SV *sv = sv_newmortal();
2510 pv = mymalloc(sizeof(i_color));
2512 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2525 count = i_colorcount(im);
2527 ST(0) = sv_2mortal(newSViv(count));
2530 ST(0) = &PL_sv_undef;
2539 count = i_maxcolors(im);
2541 ST(0) = sv_2mortal(newSViv(count));
2544 ST(0) = &PL_sv_undef;
2548 i_findcolor(im, color)
2554 if (i_findcolor(im, color, &index)) {
2555 ST(0) = sv_2mortal(newSViv(index));
2558 ST(0) = &PL_sv_undef;
2574 i_gsamp(im, l, r, y, ...)
2586 croak("No channel numbers supplied to g_samp()");
2588 chan_count = items - 4;
2589 chans = mymalloc(sizeof(int) * chan_count);
2590 for (i = 0; i < chan_count; ++i)
2591 chans[i] = SvIV(ST(i+4));
2592 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count);
2593 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2594 if (GIMME_V == G_ARRAY) {
2596 for (i = 0; i < count; ++i)
2597 PUSHs(sv_2mortal(newSViv(data[i])));
2601 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2605 if (GIMME_V != G_ARRAY) {
2607 PUSHs(&PL_sv_undef);
2612 i_img_masked_new(targ, mask, x, y, w, h)
2622 if (!sv_isobject(ST(1))
2623 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2624 croak("i_img_masked_new: parameter 2 must undef or an image");
2626 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2630 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2635 i_plin(im, l, y, ...)
2644 work = mymalloc(sizeof(i_color) * (items-3));
2645 for (i=0; i < items-3; ++i) {
2646 if (sv_isobject(ST(i+3))
2647 && sv_derived_from(ST(i+3), "Imager::Color")) {
2648 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2649 work[i] = *(i_color *)tmp;
2653 croak("i_plin: pixels must be Imager::Color objects");
2657 RETVAL = i_plin(im, l, l+items-3, y, work);
2667 i_ppixf(im, x, y, cl)
2671 Imager::Color::Float cl
2674 i_gsampf(im, l, r, y, ...)
2686 croak("No channel numbers supplied to g_sampf()");
2688 chan_count = items - 4;
2689 chans = mymalloc(sizeof(int) * chan_count);
2690 for (i = 0; i < chan_count; ++i)
2691 chans[i] = SvIV(ST(i+4));
2692 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2693 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2694 if (GIMME_V == G_ARRAY) {
2696 for (i = 0; i < count; ++i)
2697 PUSHs(sv_2mortal(newSVnv(data[i])));
2701 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2705 if (GIMME_V != G_ARRAY) {
2707 PUSHs(&PL_sv_undef);
2712 i_plinf(im, l, y, ...)
2721 work = mymalloc(sizeof(i_fcolor) * (items-3));
2722 for (i=0; i < items-3; ++i) {
2723 if (sv_isobject(ST(i+3))
2724 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2725 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2726 work[i] = *(i_fcolor *)tmp;
2730 croak("i_plin: pixels must be Imager::Color::Float objects");
2734 RETVAL = i_plinf(im, l, l+items-3, y, work);
2751 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2752 if (i_gpixf(im, x, y, color) == 0) {
2753 ST(0) = sv_newmortal();
2754 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2758 ST(0) = &PL_sv_undef;
2772 vals = mymalloc((r-l) * sizeof(i_color));
2773 count = i_glin(im, l, r, y, vals);
2775 for (i = 0; i < count; ++i) {
2777 i_color *col = mymalloc(sizeof(i_color));
2778 sv = sv_newmortal();
2779 sv_setref_pv(sv, "Imager::Color", (void *)col);
2786 i_glinf(im, l, r, y)
2796 vals = mymalloc((r-l) * sizeof(i_fcolor));
2797 count = i_glinf(im, l, r, y, vals);
2799 for (i = 0; i < count; ++i) {
2801 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2803 sv = sv_newmortal();
2804 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2811 i_img_16_new(x, y, ch)
2817 i_img_double_new(x, y, ch)
2823 i_tags_addn(im, name, code, idata)
2832 name = SvPV(ST(1), len);
2835 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2840 i_tags_add(im, name, code, data, idata)
2850 name = SvPV(ST(1), len);
2854 data = SvPV(ST(3), len);
2859 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2864 i_tags_find(im, name, start)
2871 if (i_tags_find(&im->tags, name, start, &entry)) {
2873 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2875 ST(0) = sv_2mortal(newSViv(entry));
2877 ST(0) = &PL_sv_undef;
2881 i_tags_findn(im, code, start)
2888 if (i_tags_findn(&im->tags, code, start, &entry)) {
2890 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2892 ST(0) = sv_2mortal(newSViv(entry));
2895 ST(0) = &PL_sv_undef;
2898 i_tags_delete(im, entry)
2902 RETVAL = i_tags_delete(&im->tags, entry);
2907 i_tags_delbyname(im, name)
2911 RETVAL = i_tags_delbyname(&im->tags, name);
2916 i_tags_delbycode(im, code)
2920 RETVAL = i_tags_delbycode(&im->tags, code);
2925 i_tags_get(im, index)
2929 if (index >= 0 && index < im->tags.count) {
2930 i_img_tag *entry = im->tags.tags + index;
2934 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2937 PUSHs(sv_2mortal(newSViv(entry->code)));
2940 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2943 PUSHs(sv_2mortal(newSViv(entry->idata)));
2951 RETVAL = im->tags.count;
2958 i_wf_bbox(face, size, text)
2965 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
2967 PUSHs(sv_2mortal(newSViv(cords[0])));
2968 PUSHs(sv_2mortal(newSViv(cords[1])));
2969 PUSHs(sv_2mortal(newSViv(cords[2])));
2970 PUSHs(sv_2mortal(newSViv(cords[3])));
2971 PUSHs(sv_2mortal(newSViv(cords[4])));
2972 PUSHs(sv_2mortal(newSViv(cords[5])));
2976 i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
2987 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
2993 i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
3004 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
3014 MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
3016 #define FT2_DESTROY(font) i_ft2_destroy(font)
3020 Imager::Font::FT2 font
3022 MODULE = Imager PACKAGE = Imager::Font::FreeType2
3025 i_ft2_new(name, index)
3030 i_ft2_setdpi(font, xdpi, ydpi)
3031 Imager::Font::FT2 font
3037 Imager::Font::FT2 font
3041 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
3043 PUSHs(sv_2mortal(newSViv(xdpi)));
3044 PUSHs(sv_2mortal(newSViv(ydpi)));
3048 i_ft2_sethinting(font, hinting)
3049 Imager::Font::FT2 font
3053 i_ft2_settransform(font, matrix)
3054 Imager::Font::FT2 font
3062 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3063 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3064 av=(AV*)SvRV(ST(1));
3068 for (i = 0; i < len; ++i) {
3069 sv1=(*(av_fetch(av,i,0)));
3070 matrix[i] = SvNV(sv1);
3074 RETVAL = i_ft2_settransform(font, matrix);
3079 i_ft2_bbox(font, cheight, cwidth, text)
3080 Imager::Font::FT2 font
3088 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
3090 for (i = 0; i < 6; ++i)
3091 PUSHs(sv_2mortal(newSViv(bbox[i])));
3095 i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3096 Imager::Font::FT2 font
3110 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3113 for (i = 0; i < 8; ++i)
3114 PUSHs(sv_2mortal(newSViv(bbox[i])));
3118 i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3119 Imager::Font::FT2 font
3135 if (SvUTF8(ST(7))) {
3139 text = SvPV(ST(7), len);
3140 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3141 len, align, aa, vlayout, utf8);
3146 i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3147 Imager::Font::FT2 font
3164 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3165 strlen(text), align, aa, vlayout, 1);
3170 ft2_transform_box(font, x0, x1, x2, x3)
3171 Imager::Font::FT2 font
3179 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3180 ft2_transform_box(font, box);
3182 PUSHs(sv_2mortal(newSViv(box[0])));
3183 PUSHs(sv_2mortal(newSViv(box[1])));
3184 PUSHs(sv_2mortal(newSViv(box[2])));
3185 PUSHs(sv_2mortal(newSViv(box[3])));
3189 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3193 Imager::FillHandle fill
3195 MODULE = Imager PACKAGE = Imager
3198 i_new_fill_solid(cl, combine)
3203 i_new_fill_solidf(cl, combine)
3204 Imager::Color::Float cl
3208 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3216 unsigned char *cust_hatch;
3220 cust_hatch = SvPV(ST(4), len);
3224 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3229 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3230 Imager::Color::Float fg
3231 Imager::Color::Float bg
3237 unsigned char *cust_hatch;
3241 cust_hatch = SvPV(ST(4), len);
3245 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3250 i_new_fill_image(src, matrix, xoff, yoff, combine)
3267 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3268 croak("i_new_fill_image: parameter must be an arrayref");
3269 av=(AV*)SvRV(ST(1));
3273 for (i = 0; i < len; ++i) {
3274 sv1=(*(av_fetch(av,i,0)));
3275 matrix[i] = SvNV(sv1);
3281 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);