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;
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 sv = hv_fetch(hv, "transp", 6, 0);
228 if (sv && *sv && (str = SvPV(*sv, len))) {
230 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
232 if (quant->transp != tr_none) {
233 quant->tr_threshold = 127;
234 sv = hv_fetch(hv, "tr_threshold", 12, 0);
236 quant->tr_threshold = SvIV(*sv);
238 if (quant->transp == tr_errdiff) {
239 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
240 if (sv && *sv && (str = SvPV(*sv, len)))
241 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
243 if (quant->transp == tr_ordered) {
244 quant->tr_orddith = od_tiny;
245 sv = hv_fetch(hv, "tr_orddith", 10, 0);
246 if (sv && *sv && (str = SvPV(*sv, len)))
247 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
249 if (quant->tr_orddith == od_custom) {
250 sv = hv_fetch(hv, "tr_map", 6, 0);
251 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
252 AV *av = (AV*)SvRV(*sv);
253 len = av_len(av) + 1;
254 if (len > sizeof(quant->tr_custom))
255 len = sizeof(quant->tr_custom);
256 for (i = 0; i < len; ++i) {
257 SV **sv2 = av_fetch(av, i, 0);
259 quant->tr_custom[i] = SvIV(*sv2);
262 while (i < sizeof(quant->tr_custom))
263 quant->tr_custom[i++] = 0;
268 quant->make_colors = mc_addi;
269 sv = hv_fetch(hv, "make_colors", 11, 0);
270 if (sv && *sv && (str = SvPV(*sv, len))) {
272 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
274 sv = hv_fetch(hv, "colors", 6, 0);
275 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
276 /* needs to be an array of Imager::Color
277 note that the caller allocates the mc_color array and sets mc_size
279 AV *av = (AV *)SvRV(*sv);
280 quant->mc_count = av_len(av)+1;
281 if (quant->mc_count > quant->mc_size)
282 quant->mc_count = quant->mc_size;
283 for (i = 0; i < quant->mc_count; ++i) {
284 SV **sv1 = av_fetch(av, i, 0);
285 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
286 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
287 quant->mc_colors[i] = *col;
291 sv = hv_fetch(hv, "max_colors", 10, 0);
294 if (i <= quant->mc_size && i >= quant->mc_count)
298 quant->translate = pt_closest;
299 sv = hv_fetch(hv, "translate", 9, 0);
300 if (sv && *sv && (str = SvPV(*sv, len))) {
301 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
303 sv = hv_fetch(hv, "errdiff", 7, 0);
304 if (sv && *sv && (str = SvPV(*sv, len))) {
305 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
307 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
308 /* get the error diffusion map */
309 sv = hv_fetch(hv, "errdiff_width", 13, 0);
311 quant->ed_width = SvIV(*sv);
312 sv = hv_fetch(hv, "errdiff_height", 14, 0);
314 quant->ed_height = SvIV(*sv);
315 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
317 quant->ed_orig = SvIV(*sv);
318 if (quant->ed_width > 0 && quant->ed_height > 0) {
320 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
321 sv = hv_fetch(hv, "errdiff_map", 11, 0);
322 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
323 AV *av = (AV*)SvRV(*sv);
324 len = av_len(av) + 1;
325 if (len > quant->ed_width * quant->ed_height)
326 len = quant->ed_width * quant->ed_height;
327 for (i = 0; i < len; ++i) {
328 SV **sv2 = av_fetch(av, i, 0);
330 quant->ed_map[i] = SvIV(*sv2);
331 sum += quant->ed_map[i];
337 myfree(quant->ed_map);
339 quant->errdiff = ed_floyd;
343 sv = hv_fetch(hv, "perturb", 7, 0);
345 quant->perturb = SvIV(*sv);
348 /* look through the hash for options to add to opts */
349 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
353 /**((char *)0) = '\0';*/
354 opts->each_palette = hv_fetch_bool(hv, "gif_each_palette", 0);
355 opts->interlace = hv_fetch_bool(hv, "interlace", 0);
357 sv = hv_fetch(hv, "gif_delays", 10, 0);
358 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
359 AV *av = (AV*)SvRV(*sv);
360 opts->delay_count = av_len(av)+1;
361 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
362 for (i = 0; i < opts->delay_count; ++i) {
363 SV *sv1 = *av_fetch(av, i, 0);
364 opts->delays[i] = SvIV(sv1);
367 sv = hv_fetch(hv, "gif_user_input", 14, 0);
368 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
369 AV *av = (AV*)SvRV(*sv);
370 opts->user_input_count = av_len(av)+1;
371 opts->user_input_flags = mymalloc(opts->user_input_count);
372 for (i = 0; i < opts->user_input_count; ++i) {
373 SV *sv1 = *av_fetch(av, i, 0);
374 opts->user_input_flags[i] = SvIV(sv1) != 0;
377 sv = hv_fetch(hv, "gif_disposal", 12, 0);
378 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
379 AV *av = (AV*)SvRV(*sv);
380 opts->disposal_count = av_len(av)+1;
381 opts->disposal = mymalloc(opts->disposal_count);
382 for (i = 0; i < opts->disposal_count; ++i) {
383 SV *sv1 = *av_fetch(av, i, 0);
384 opts->disposal[i] = SvIV(sv1);
387 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
388 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
389 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
390 opts->tran_color = *col;
392 sv = hv_fetch(hv, "gif_positions", 13, 0);
393 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
394 AV *av = (AV *)SvRV(*sv);
395 opts->position_count = av_len(av) + 1;
396 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
397 for (i = 0; i < opts->position_count; ++i) {
398 SV **sv2 = av_fetch(av, i, 0);
399 opts->positions[i].x = opts->positions[i].y = 0;
400 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
401 AV *av2 = (AV*)SvRV(*sv2);
403 sv3 = av_fetch(av2, 0, 0);
405 opts->positions[i].x = SvIV(*sv3);
406 sv3 = av_fetch(av2, 1, 0);
408 opts->positions[i].y = SvIV(*sv3);
412 /* Netscape2.0 loop count extension */
413 opts->loop_count = hv_fetch_int(hv, "gif_loop_count", 0);
415 opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1);
418 /* copies the color map from the hv into the colors member of the HV */
419 static void copy_colors_back(HV *hv, i_quantize *quant) {
425 sv = hv_fetch(hv, "colors", 6, 0);
426 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
429 ref = newRV_inc((SV*) av);
430 sv = hv_store(hv, "colors", 6, ref, 0);
433 av = (AV *)SvRV(*sv);
435 av_extend(av, quant->mc_count+1);
436 for (i = 0; i < quant->mc_count; ++i) {
437 i_color *in = quant->mc_colors+i;
438 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
439 work = sv_newmortal();
440 sv_setref_pv(work, "Imager::Color", (void *)c);
442 if (!av_store(av, i, work)) {
448 /* loads the segments of a fountain fill into an array */
449 i_fountain_seg *load_fount_segs(AV *asegs, int *count) {
450 /* Each element of segs must contain:
451 [ start, middle, end, c0, c1, segtype, colortrans ]
452 start, middle, end are doubles from 0 to 1
453 c0, c1 are Imager::Color::Float or Imager::Color objects
454 segtype, colortrans are ints
459 i_fountain_seg *segs;
463 *count = av_len(asegs)+1;
465 croak("i_fountain must have at least one segment");
466 segs = mymalloc(sizeof(i_fountain_seg) * *count);
467 for(i = 0; i < *count; i++) {
468 SV **sv1 = av_fetch(asegs, i, 0);
469 if (!sv1 || !*sv1 || !SvROK(*sv1)
470 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
472 croak("i_fountain: segs must be an arrayref of arrayrefs");
474 aseg = (AV *)SvRV(*sv1);
475 if (av_len(aseg) != 7-1) {
477 croak("i_fountain: a segment must have 7 members");
479 for (j = 0; j < 3; ++j) {
480 SV **sv2 = av_fetch(aseg, j, 0);
483 croak("i_fountain: XS error");
485 work[j] = SvNV(*sv2);
487 segs[i].start = work[0];
488 segs[i].middle = work[1];
489 segs[i].end = work[2];
490 for (j = 0; j < 2; ++j) {
491 SV **sv3 = av_fetch(aseg, 3+j, 0);
492 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
493 (!sv_derived_from(*sv3, "Imager::Color")
494 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
496 croak("i_fountain: segs must contain colors in elements 3 and 4");
498 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
499 segs[i].c[j] = *(i_fcolor *)SvIV((SV *)SvRV(*sv3));
502 i_color c = *(i_color *)SvIV((SV *)SvRV(*sv3));
504 for (ch = 0; ch < MAXCHANNELS; ++ch) {
505 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
509 for (j = 0; j < 2; ++j) {
510 SV **sv2 = av_fetch(aseg, j+5, 0);
513 croak("i_fountain: XS error");
515 worki[j] = SvIV(*sv2);
517 segs[i].type = worki[0];
518 segs[i].color = worki[1];
524 /* I don't think ICLF_* names belong at the C interface
525 this makes the XS code think we have them, to let us avoid
526 putting function bodies in the XS code
528 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
529 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
531 /* for the fill objects
532 Since a fill object may later have dependent images, (or fills!)
533 we need perl wrappers - oh well
535 #define IFILL_DESTROY(fill) i_fill_destroy(fill);
536 typedef i_fill_t* Imager__FillHandle;
538 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
541 ICL_new_internal(r,g,b,a)
553 ICL_set_internal(cl,r,g,b,a)
560 ICL_set_internal(cl, r, g, b, a);
574 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
575 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
576 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
577 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
583 RETVAL = mymalloc(sizeof(i_color));
585 i_hsv_to_rgb(RETVAL);
593 RETVAL = mymalloc(sizeof(i_color));
595 i_rgb_to_hsv(RETVAL);
601 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
604 ICLF_new_internal(r, g, b, a)
612 Imager::Color::Float cl
616 Imager::Color::Float cl
620 EXTEND(SP, MAXCHANNELS);
621 for (ch = 0; ch < MAXCHANNELS; ++ch) {
622 /* printf("%d: %g\n", ch, cl->channel[ch]); */
623 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
627 ICLF_set_internal(cl,r,g,b,a)
628 Imager::Color::Float cl
643 Imager::Color::Float c
645 RETVAL = mymalloc(sizeof(i_fcolor));
647 i_hsv_to_rgbf(RETVAL);
653 Imager::Color::Float c
655 RETVAL = mymalloc(sizeof(i_fcolor));
657 i_rgb_to_hsvf(RETVAL);
662 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
676 MODULE = Imager PACKAGE = Imager
698 RETVAL = io_new_buffer(data, length, my_SvREFCNT_dec, ST(0));
711 tlength = io_slurp(ig, &data);
713 PUSHs(sv_2mortal(newSVpv(data,tlength)));
717 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_glue_
724 MODULE = Imager PACKAGE = Imager
737 while( (item=i_format_list[i++]) != NULL ) {
739 PUSHs(sv_2mortal(newSVpv(item,0)));
756 i_img_empty_ch(im,x,y,ch)
768 log_entry(string,level)
789 PUSHs(sv_2mortal(newSViv(info[0])));
790 PUSHs(sv_2mortal(newSViv(info[1])));
791 PUSHs(sv_2mortal(newSViv(info[2])));
792 PUSHs(sv_2mortal(newSViv(info[3])));
798 i_img_setmask(im,ch_mask)
807 i_img_getchannels(im)
815 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
820 i_draw(im,x1,y1,x2,y2,val)
829 i_line_aa(im,x1,y1,x2,y2,val)
838 i_box(im,x1,y1,x2,y2,val)
847 i_box_filled(im,x1,y1,x2,y2,val)
856 i_box_cfill(im,x1,y1,x2,y2,fill)
862 Imager::FillHandle fill
865 i_arc(im,x,y,rad,d1,d2,val)
875 i_arc_cfill(im,x,y,rad,d1,d2,fill)
882 Imager::FillHandle fill
887 i_circle_aa(im,x,y,rad,val)
897 i_bezier_multi(im,xc,yc,val)
910 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
911 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
912 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
913 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
914 av1=(AV*)SvRV(ST(1));
915 av2=(AV*)SvRV(ST(2));
916 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
918 x=mymalloc( len*sizeof(double) );
919 y=mymalloc( len*sizeof(double) );
921 sv1=(*(av_fetch(av1,i,0)));
922 sv2=(*(av_fetch(av2,i,0)));
923 x[i]=(double)SvNV(sv1);
924 y[i]=(double)SvNV(sv2);
926 i_bezier_multi(im,len,x,y,val);
932 i_poly_aa(im,xc,yc,val)
945 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
946 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
947 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
948 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
949 av1=(AV*)SvRV(ST(1));
950 av2=(AV*)SvRV(ST(2));
951 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
953 x=mymalloc( len*sizeof(double) );
954 y=mymalloc( len*sizeof(double) );
956 sv1=(*(av_fetch(av1,i,0)));
957 sv2=(*(av_fetch(av2,i,0)));
958 x[i]=(double)SvNV(sv1);
959 y[i]=(double)SvNV(sv2);
961 i_poly_aa(im,len,x,y,val);
968 i_flood_fill(im,seedx,seedy,dcol)
975 i_flood_cfill(im,seedx,seedy,fill)
979 Imager::FillHandle fill
983 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
995 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
1013 i_rubthru(im,src,tx,ty)
1020 i_flipxy(im, direction)
1025 i_rotate90(im, degrees)
1030 i_rotate_exact(im, amount)
1035 i_matrix_transform(im, xsize, ysize, matrix)
1046 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
1047 croak("i_matrix_transform: parameter 4 must be an array ref\n");
1048 av=(AV*)SvRV(ST(3));
1052 for (i = 0; i < len; ++i) {
1053 sv1=(*(av_fetch(av,i,0)));
1054 matrix[i] = SvNV(sv1);
1058 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
1063 i_gaussian(im,stdev)
1068 i_unsharp_mask(im,stdev,scale)
1083 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1084 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1085 av=(AV*)SvRV(ST(1));
1087 coeff=mymalloc( len*sizeof(float) );
1088 for(i=0;i<len;i++) {
1089 sv1=(*(av_fetch(av,i,0)));
1090 coeff[i]=(float)SvNV(sv1);
1092 i_conv(im,coeff,len);
1096 i_convert(im, src, coeff)
1110 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
1111 croak("i_convert: parameter 3 must be an arrayref\n");
1112 avmain = (AV*)SvRV(ST(2));
1113 outchan = av_len(avmain)+1;
1114 /* find the biggest */
1116 for (j=0; j < outchan; ++j) {
1117 temp = av_fetch(avmain, j, 0);
1118 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1119 avsub = (AV*)SvRV(*temp);
1120 len = av_len(avsub)+1;
1125 coeff = mymalloc(sizeof(float) * outchan * inchan);
1126 for (j = 0; j < outchan; ++j) {
1127 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1128 len = av_len(avsub)+1;
1129 for (i = 0; i < len; ++i) {
1130 temp = av_fetch(avsub, i, 0);
1132 coeff[i+j*inchan] = SvNV(*temp);
1134 coeff[i+j*inchan] = 0;
1137 coeff[i++ + j*inchan] = 0;
1139 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1149 unsigned int mask = 0;
1155 unsigned char (*maps)[256];
1157 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1158 croak("i_map: parameter 2 must be an arrayref\n");
1159 avmain = (AV*)SvRV(ST(1));
1160 len = av_len(avmain)+1;
1161 if (im->channels < len) len = im->channels;
1163 maps = mymalloc( len * sizeof(unsigned char [256]) );
1165 for (j=0; j<len ; j++) {
1166 temp = av_fetch(avmain, j, 0);
1167 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1168 avsub = (AV*)SvRV(*temp);
1169 if(av_len(avsub) != 255) continue;
1171 for (i=0; i<256 ; i++) {
1173 temp = av_fetch(avsub, i, 0);
1174 val = temp ? SvIV(*temp) : 0;
1176 if (val>255) val = 255;
1181 i_map(im, maps, mask);
1203 i_t1_new(pfb,afm=NULL)
1208 i_t1_destroy(font_id)
1213 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1225 i_t1_bbox(fontnum,point,str,len)
1233 i_t1_bbox(fontnum,point,str,len,cords);
1235 PUSHs(sv_2mortal(newSViv(cords[0])));
1236 PUSHs(sv_2mortal(newSViv(cords[1])));
1237 PUSHs(sv_2mortal(newSViv(cords[2])));
1238 PUSHs(sv_2mortal(newSViv(cords[3])));
1239 PUSHs(sv_2mortal(newSViv(cords[4])));
1240 PUSHs(sv_2mortal(newSViv(cords[5])));
1245 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1266 i_tt_destroy(handle)
1267 Imager::TTHandle handle
1272 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1273 Imager::TTHandle handle
1285 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1286 Imager::TTHandle handle
1299 i_tt_bbox(handle,point,str,len)
1300 Imager::TTHandle handle
1307 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1309 PUSHs(sv_2mortal(newSViv(cords[0])));
1310 PUSHs(sv_2mortal(newSViv(cords[1])));
1311 PUSHs(sv_2mortal(newSViv(cords[2])));
1312 PUSHs(sv_2mortal(newSViv(cords[3])));
1313 PUSHs(sv_2mortal(newSViv(cords[4])));
1314 PUSHs(sv_2mortal(newSViv(cords[5])));
1325 i_writejpeg_wiol(im, ig, qfactor)
1341 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1342 if (iptc_itext == NULL) {
1345 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1350 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1352 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1365 i_readtiff_wiol(ig, length)
1371 i_writetiff_wiol(im, ig)
1376 i_writetiff_wiol_faxable(im, ig, fine)
1382 #endif /* HAVE_LIBTIFF */
1391 i_readpng_wiol(ig, length)
1397 i_writepng_wiol(im, ig)
1410 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1413 i_writegif(im,fd,colors,pixdev,fixed)
1420 Imager__Color fixed;
1427 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1428 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1429 av=(AV*)SvRV(ST(4));
1430 fixedlen=av_len(av)+1;
1431 fixed=mymalloc( fixedlen*sizeof(i_color) );
1432 for(i=0;i<fixedlen;i++) {
1433 sv1=(*(av_fetch(av,i,0)));
1434 if (sv_derived_from(sv1, "Imager::Color")) {
1435 Itmp = SvIV((SV*)SvRV(sv1));
1436 tmp = (i_color*) Itmp;
1437 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1440 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1442 ST(0) = sv_newmortal();
1443 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1444 else sv_setiv(ST(0), (IV)RETVAL);
1450 i_writegifmc(im,fd,colors)
1457 i_writegif_gen(fd, ...)
1463 i_img **imgs = NULL;
1469 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1470 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1471 croak("i_writegif_gen: Second argument must be a hash ref");
1472 hv = (HV *)SvRV(ST(1));
1473 memset(&quant, 0, sizeof(quant));
1474 quant.mc_size = 256;
1475 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1476 memset(&opts, 0, sizeof(opts));
1477 handle_quant_opts(&quant, hv);
1478 handle_gif_opts(&opts, hv);
1479 img_count = items - 2;
1481 if (img_count < 1) {
1484 i_push_error(0, "You need to specify images to save");
1487 imgs = mymalloc(sizeof(i_img *) * img_count);
1488 for (i = 0; i < img_count; ++i) {
1491 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1492 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1496 i_push_error(0, "Only images can be saved");
1502 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1506 copy_colors_back(hv, &quant);
1509 ST(0) = sv_newmortal();
1510 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1511 else sv_setiv(ST(0), (IV)RETVAL);
1512 myfree(quant.mc_colors);
1516 i_writegif_callback(cb, maxbuffer,...)
1521 i_img **imgs = NULL;
1528 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1529 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1530 croak("i_writegif_callback: Second argument must be a hash ref");
1531 hv = (HV *)SvRV(ST(2));
1532 memset(&quant, 0, sizeof(quant));
1533 quant.mc_size = 256;
1534 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1535 memset(&opts, 0, sizeof(opts));
1536 handle_quant_opts(&quant, hv);
1537 handle_gif_opts(&opts, hv);
1538 img_count = items - 3;
1540 if (img_count < 1) {
1544 imgs = mymalloc(sizeof(i_img *) * img_count);
1545 for (i = 0; i < img_count; ++i) {
1548 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1549 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1558 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1562 copy_colors_back(hv, &quant);
1565 ST(0) = sv_newmortal();
1566 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1567 else sv_setiv(ST(0), (IV)RETVAL);
1580 colour_table = NULL;
1583 if(GIMME_V == G_ARRAY) {
1584 rimg = i_readgif(fd,&colour_table,&colours);
1586 /* don't waste time with colours if they aren't wanted */
1587 rimg = i_readgif(fd,NULL,NULL);
1590 if (colour_table == NULL) {
1593 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1596 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1597 /* I don't know if I have the reference counts right or not :( */
1598 /* Neither do I :-) */
1599 /* No Idea here either */
1602 av_extend(ct, colours);
1603 for(q=0; q<colours; q++) {
1605 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1606 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1608 myfree(colour_table);
1612 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1614 PUSHs(newRV_noinc((SV*)ct));
1622 i_readgif_scalar(...)
1626 unsigned int length;
1634 data = (char *)SvPV(ST(0), length);
1638 if(GIMME_V == G_ARRAY) {
1639 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1641 /* don't waste time with colours if they aren't wanted */
1642 rimg=i_readgif_scalar(data,length,NULL,NULL);
1645 if (colour_table == NULL) {
1648 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1651 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1652 /* I don't know if I have the reference counts right or not :( */
1653 /* Neither do I :-) */
1655 av_extend(ct, colours);
1656 for(q=0; q<colours; q++) {
1658 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1659 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1661 myfree(colour_table);
1665 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1667 PUSHs(newRV_noinc((SV*)ct));
1671 i_readgif_callback(...)
1688 if(GIMME_V == G_ARRAY) {
1689 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1691 /* don't waste time with colours if they aren't wanted */
1692 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1695 if (colour_table == NULL) {
1698 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1701 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1702 /* I don't know if I have the reference counts right or not :( */
1703 /* Neither do I :-) */
1704 /* Neither do I - maybe I'll move this somewhere */
1706 av_extend(ct, colours);
1707 for(q=0; q<colours; q++) {
1709 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1710 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1712 myfree(colour_table);
1716 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1718 PUSHs(newRV_noinc((SV*)ct));
1729 imgs = i_readgif_multi(fd, &count);
1732 for (i = 0; i < count; ++i) {
1733 SV *sv = sv_newmortal();
1734 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1741 i_readgif_multi_scalar(data)
1746 unsigned int length;
1749 data = (char *)SvPV(ST(0), length);
1750 imgs = i_readgif_multi_scalar(data, length, &count);
1753 for (i = 0; i < count; ++i) {
1754 SV *sv = sv_newmortal();
1755 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1762 i_readgif_multi_callback(cb)
1770 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1773 for (i = 0; i < count; ++i) {
1774 SV *sv = sv_newmortal();
1775 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1786 i_readpnm_wiol(ig, length)
1792 i_writeppm_wiol(im, ig)
1798 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1807 i_writeraw_wiol(im,ig)
1812 i_writebmp_wiol(im,ig)
1822 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
1833 idlen = SvCUR(ST(4));
1834 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
1840 i_readtga_wiol(ig, length)
1846 i_scaleaxis(im,Value,Axis)
1852 i_scale_nn(im,scx,scy)
1862 i_count_colors(im,maxc)
1868 i_transform(im,opx,opy,parm)
1881 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1882 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1883 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1884 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1885 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1886 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1887 av=(AV*)SvRV(ST(1));
1889 opx=mymalloc( opxl*sizeof(int) );
1890 for(i=0;i<opxl;i++) {
1891 sv1=(*(av_fetch(av,i,0)));
1892 opx[i]=(int)SvIV(sv1);
1894 av=(AV*)SvRV(ST(2));
1896 opy=mymalloc( opyl*sizeof(int) );
1897 for(i=0;i<opyl;i++) {
1898 sv1=(*(av_fetch(av,i,0)));
1899 opy[i]=(int)SvIV(sv1);
1901 av=(AV*)SvRV(ST(3));
1902 parmlen=av_len(av)+1;
1903 parm=mymalloc( parmlen*sizeof(double) );
1904 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1905 sv1=(*(av_fetch(av,i,0)));
1906 parm[i]=(double)SvNV(sv1);
1908 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1912 ST(0) = sv_newmortal();
1913 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1914 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1917 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1936 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1937 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1938 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1939 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1940 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1942 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1944 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1945 av = (AV*)SvRV(ST(5));
1946 in_imgs_count = av_len(av)+1;
1947 for (i = 0; i < in_imgs_count; ++i) {
1948 sv1 = *av_fetch(av, i, 0);
1949 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1950 croak("Parameter 5 must contain only images");
1957 if (in_imgs_count > 0) {
1958 av = (AV*)SvRV(ST(5));
1959 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1960 for (i = 0; i < in_imgs_count; ++i) {
1961 sv1 = *av_fetch(av,i,0);
1962 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1963 croak("Parameter 5 must contain only images");
1965 tmp = SvIV((SV*)SvRV(sv1));
1966 in_imgs[i] = (i_img*)tmp;
1970 /* no input images */
1973 /* default the output size from the first input if possible */
1975 width = SvIV(ST(0));
1976 else if (in_imgs_count)
1977 width = in_imgs[0]->xsize;
1979 croak("No output image width supplied");
1982 height = SvIV(ST(1));
1983 else if (in_imgs_count)
1984 height = in_imgs[0]->ysize;
1986 croak("No output image height supplied");
1988 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1989 if (ops_len % sizeof(struct rm_op))
1990 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1991 ops_count = ops_len / sizeof(struct rm_op);
1992 av = (AV*)SvRV(ST(3));
1993 n_regs_count = av_len(av)+1;
1994 n_regs = mymalloc(n_regs_count * sizeof(double));
1995 for (i = 0; i < n_regs_count; ++i) {
1996 sv1 = *av_fetch(av,i,0);
1998 n_regs[i] = SvNV(sv1);
2000 av = (AV*)SvRV(ST(4));
2001 c_regs_count = av_len(av)+1;
2002 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2003 /* I don't bother initializing the colou?r registers */
2005 RETVAL=i_transform2(width, height, 3, ops, ops_count,
2006 n_regs, n_regs_count,
2007 c_regs, c_regs_count, in_imgs, in_imgs_count);
2012 ST(0) = sv_newmortal();
2013 if (RETVAL == 0) ST(0)=&PL_sv_undef;
2014 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
2018 i_contrast(im,intensity)
2027 i_noise(im,amount,type)
2033 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2043 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2062 i_postlevels(im,levels)
2072 i_watermark(im,wmark,tx,ty,pixdiff)
2074 Imager::ImgRaw wmark
2081 i_autolevels(im,lsat,usat,skew)
2088 i_radnoise(im,xo,yo,rscale,ascale)
2096 i_turbnoise(im, xo, yo, scale)
2119 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2120 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2121 croak("i_gradgen: Second argument must be an array ref");
2122 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2123 croak("i_gradgen: Third argument must be an array ref");
2124 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2125 croak("i_gradgen: Fourth argument must be an array ref");
2126 axx = (AV *)SvRV(ST(1));
2127 ayy = (AV *)SvRV(ST(2));
2128 ac = (AV *)SvRV(ST(3));
2129 dmeasure = (int)SvIV(ST(4));
2131 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2132 num = num <= av_len(ac) ? num : av_len(ac);
2134 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2135 xo = mymalloc( sizeof(int) * num );
2136 yo = mymalloc( sizeof(int) * num );
2137 ival = mymalloc( sizeof(i_color) * num );
2138 for(i = 0; i<num; i++) {
2139 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2140 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2141 sv = *av_fetch(ac, i, 0);
2142 if ( !sv_derived_from(sv, "Imager::Color") ) {
2143 free(axx); free(ayy); free(ac);
2144 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2146 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2148 i_gradgen(im, num, xo, yo, ival, dmeasure);
2155 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2165 double ssample_param
2169 i_fountain_seg *segs;
2171 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2172 croak("i_fountain: argument 11 must be an array ref");
2174 asegs = (AV *)SvRV(ST(10));
2175 segs = load_fount_segs(asegs, &count);
2176 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2177 ssample_param, count, segs);
2181 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2190 double ssample_param
2194 i_fountain_seg *segs;
2196 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2197 croak("i_fountain: argument 11 must be an array ref");
2199 asegs = (AV *)SvRV(ST(9));
2200 segs = load_fount_segs(asegs, &count);
2201 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2202 super_sample, ssample_param, count, segs);
2216 errors = i_errors();
2218 while (errors[i].msg) {
2220 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2221 if (!av_store(av, 0, sv)) {
2224 sv = newSViv(errors[i].code);
2225 if (!av_store(av, 1, sv)) {
2228 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2233 i_nearest_color(im, ...)
2248 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2249 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2250 croak("i_nearest_color: Second argument must be an array ref");
2251 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2252 croak("i_nearest_color: Third argument must be an array ref");
2253 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2254 croak("i_nearest_color: Fourth argument must be an array ref");
2255 axx = (AV *)SvRV(ST(1));
2256 ayy = (AV *)SvRV(ST(2));
2257 ac = (AV *)SvRV(ST(3));
2258 dmeasure = (int)SvIV(ST(4));
2260 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2261 num = num <= av_len(ac) ? num : av_len(ac);
2263 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2264 xo = mymalloc( sizeof(int) * num );
2265 yo = mymalloc( sizeof(int) * num );
2266 ival = mymalloc( sizeof(i_color) * num );
2267 for(i = 0; i<num; i++) {
2268 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2269 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2270 sv = *av_fetch(ac, i, 0);
2271 if ( !sv_derived_from(sv, "Imager::Color") ) {
2272 free(axx); free(ayy); free(ac);
2273 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2275 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2277 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2291 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2292 hv=(HV*)SvRV(ST(0));
2293 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2294 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2295 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2304 rc=DSO_open(filename,&evstr);
2308 PUSHs(sv_2mortal(newSViv((IV)rc)));
2309 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2312 PUSHs(sv_2mortal(newSViv((IV)rc)));
2318 DSO_close(dso_handle)
2322 DSO_funclist(dso_handle_v)
2326 DSO_handle *dso_handle;
2328 dso_handle=(DSO_handle*)dso_handle_v;
2330 while( dso_handle->function_list[i].name != NULL) {
2332 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2334 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2339 DSO_call(handle,func_index,hv)
2345 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2346 hv=(HV*)SvRV(ST(2));
2347 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2348 DSO_call( (DSO_handle *)handle,func_index,hv);
2352 # this is mostly for testing...
2354 i_get_pixel(im, x, y)
2361 color = (i_color *)mymalloc(sizeof(i_color));
2362 if (i_gpix(im, x, y, color) == 0) {
2363 ST(0) = sv_newmortal();
2364 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2368 ST(0) = &PL_sv_undef;
2373 i_ppix(im, x, y, cl)
2380 i_img_pal_new(x, y, channels, maxpal)
2387 i_img_to_pal(src, quant)
2393 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2394 croak("i_img_to_pal: second argument must be a hash ref");
2395 hv = (HV *)SvRV(ST(1));
2396 memset(&quant, 0, sizeof(quant));
2397 quant.mc_size = 256;
2398 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2399 handle_quant_opts(&quant, hv);
2400 RETVAL = i_img_to_pal(src, &quant);
2402 copy_colors_back(hv, &quant);
2404 myfree(quant.mc_colors);
2423 work = mymalloc((r-l) * sizeof(i_palidx));
2424 count = i_gpal(im, l, r, y, work);
2425 if (GIMME_V == G_ARRAY) {
2427 for (i = 0; i < count; ++i) {
2428 PUSHs(sv_2mortal(newSViv(work[i])));
2433 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2438 if (GIMME_V != G_ARRAY) {
2440 PUSHs(&PL_sv_undef);
2445 i_ppal(im, l, y, ...)
2454 work = mymalloc(sizeof(i_palidx) * (items-3));
2455 for (i=0; i < items-3; ++i) {
2456 work[i] = SvIV(ST(i+3));
2458 RETVAL = i_ppal(im, l, l+items-3, y, work);
2468 i_addcolors(im, ...)
2476 croak("i_addcolors: no colors to add");
2477 colors = mymalloc((items-1) * sizeof(i_color));
2478 for (i=0; i < items-1; ++i) {
2479 if (sv_isobject(ST(i+1))
2480 && sv_derived_from(ST(i+1), "Imager::Color")) {
2481 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2482 colors[i] = *(i_color *)tmp;
2486 croak("i_plin: pixels must be Imager::Color objects");
2489 index = i_addcolors(im, colors, items-1);
2492 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2494 else if (index == -1) {
2495 ST(0) = &PL_sv_undef;
2498 ST(0) = sv_2mortal(newSViv(index));
2502 i_setcolors(im, index, ...)
2510 croak("i_setcolors: no colors to add");
2511 colors = mymalloc((items-2) * sizeof(i_color));
2512 for (i=0; i < items-2; ++i) {
2513 if (sv_isobject(ST(i+2))
2514 && sv_derived_from(ST(i+2), "Imager::Color")) {
2515 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2516 colors[i] = *(i_color *)tmp;
2520 croak("i_setcolors: pixels must be Imager::Color objects");
2523 RETVAL = i_setcolors(im, index, colors, items-2);
2527 i_getcolors(im, index, ...)
2536 croak("i_getcolors: too many arguments");
2538 count = SvIV(ST(2));
2540 croak("i_getcolors: count must be positive");
2541 colors = mymalloc(sizeof(i_color) * count);
2542 if (i_getcolors(im, index, colors, count)) {
2543 for (i = 0; i < count; ++i) {
2545 SV *sv = sv_newmortal();
2546 pv = mymalloc(sizeof(i_color));
2548 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2561 count = i_colorcount(im);
2563 ST(0) = sv_2mortal(newSViv(count));
2566 ST(0) = &PL_sv_undef;
2575 count = i_maxcolors(im);
2577 ST(0) = sv_2mortal(newSViv(count));
2580 ST(0) = &PL_sv_undef;
2584 i_findcolor(im, color)
2590 if (i_findcolor(im, color, &index)) {
2591 ST(0) = sv_2mortal(newSViv(index));
2594 ST(0) = &PL_sv_undef;
2610 i_gsamp(im, l, r, y, ...)
2622 croak("No channel numbers supplied to g_samp()");
2624 chan_count = items - 4;
2625 chans = mymalloc(sizeof(int) * chan_count);
2626 for (i = 0; i < chan_count; ++i)
2627 chans[i] = SvIV(ST(i+4));
2628 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count); /* XXX: memleak? */
2629 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2631 if (GIMME_V == G_ARRAY) {
2633 for (i = 0; i < count; ++i)
2634 PUSHs(sv_2mortal(newSViv(data[i])));
2638 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2643 if (GIMME_V != G_ARRAY) {
2645 PUSHs(&PL_sv_undef);
2651 i_img_masked_new(targ, mask, x, y, w, h)
2661 if (!sv_isobject(ST(1))
2662 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2663 croak("i_img_masked_new: parameter 2 must undef or an image");
2665 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2669 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2674 i_plin(im, l, y, ...)
2683 work = mymalloc(sizeof(i_color) * (items-3));
2684 for (i=0; i < items-3; ++i) {
2685 if (sv_isobject(ST(i+3))
2686 && sv_derived_from(ST(i+3), "Imager::Color")) {
2687 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2688 work[i] = *(i_color *)tmp;
2692 croak("i_plin: pixels must be Imager::Color objects");
2696 RETVAL = i_plin(im, l, l+items-3, y, work);
2706 i_ppixf(im, x, y, cl)
2710 Imager::Color::Float cl
2713 i_gsampf(im, l, r, y, ...)
2725 croak("No channel numbers supplied to g_sampf()");
2727 chan_count = items - 4;
2728 chans = mymalloc(sizeof(int) * chan_count);
2729 for (i = 0; i < chan_count; ++i)
2730 chans[i] = SvIV(ST(i+4));
2731 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2732 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2733 if (GIMME_V == G_ARRAY) {
2735 for (i = 0; i < count; ++i)
2736 PUSHs(sv_2mortal(newSVnv(data[i])));
2740 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2744 if (GIMME_V != G_ARRAY) {
2746 PUSHs(&PL_sv_undef);
2751 i_plinf(im, l, y, ...)
2760 work = mymalloc(sizeof(i_fcolor) * (items-3));
2761 for (i=0; i < items-3; ++i) {
2762 if (sv_isobject(ST(i+3))
2763 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2764 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2765 work[i] = *(i_fcolor *)tmp;
2769 croak("i_plin: pixels must be Imager::Color::Float objects");
2773 RETVAL = i_plinf(im, l, l+items-3, y, work);
2790 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2791 if (i_gpixf(im, x, y, color) == 0) {
2792 ST(0) = sv_newmortal();
2793 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2797 ST(0) = &PL_sv_undef;
2811 vals = mymalloc((r-l) * sizeof(i_color));
2812 count = i_glin(im, l, r, y, vals);
2814 for (i = 0; i < count; ++i) {
2816 i_color *col = mymalloc(sizeof(i_color));
2817 sv = sv_newmortal();
2818 sv_setref_pv(sv, "Imager::Color", (void *)col);
2825 i_glinf(im, l, r, y)
2835 vals = mymalloc((r-l) * sizeof(i_fcolor));
2836 count = i_glinf(im, l, r, y, vals);
2838 for (i = 0; i < count; ++i) {
2840 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2842 sv = sv_newmortal();
2843 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2850 i_img_16_new(x, y, ch)
2856 i_img_double_new(x, y, ch)
2862 i_tags_addn(im, name, code, idata)
2871 name = SvPV(ST(1), len);
2874 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2879 i_tags_add(im, name, code, data, idata)
2889 name = SvPV(ST(1), len);
2893 data = SvPV(ST(3), len);
2898 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2903 i_tags_find(im, name, start)
2910 if (i_tags_find(&im->tags, name, start, &entry)) {
2912 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2914 ST(0) = sv_2mortal(newSViv(entry));
2916 ST(0) = &PL_sv_undef;
2920 i_tags_findn(im, code, start)
2927 if (i_tags_findn(&im->tags, code, start, &entry)) {
2929 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2931 ST(0) = sv_2mortal(newSViv(entry));
2934 ST(0) = &PL_sv_undef;
2937 i_tags_delete(im, entry)
2941 RETVAL = i_tags_delete(&im->tags, entry);
2946 i_tags_delbyname(im, name)
2950 RETVAL = i_tags_delbyname(&im->tags, name);
2955 i_tags_delbycode(im, code)
2959 RETVAL = i_tags_delbycode(&im->tags, code);
2964 i_tags_get(im, index)
2968 if (index >= 0 && index < im->tags.count) {
2969 i_img_tag *entry = im->tags.tags + index;
2973 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2976 PUSHs(sv_2mortal(newSViv(entry->code)));
2979 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2982 PUSHs(sv_2mortal(newSViv(entry->idata)));
2990 RETVAL = im->tags.count;
2997 i_wf_bbox(face, size, text)
3004 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
3006 PUSHs(sv_2mortal(newSViv(cords[0])));
3007 PUSHs(sv_2mortal(newSViv(cords[1])));
3008 PUSHs(sv_2mortal(newSViv(cords[2])));
3009 PUSHs(sv_2mortal(newSViv(cords[3])));
3010 PUSHs(sv_2mortal(newSViv(cords[4])));
3011 PUSHs(sv_2mortal(newSViv(cords[5])));
3015 i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
3026 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
3032 i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
3043 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
3053 MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
3055 #define FT2_DESTROY(font) i_ft2_destroy(font)
3059 Imager::Font::FT2 font
3061 MODULE = Imager PACKAGE = Imager::Font::FreeType2
3064 i_ft2_new(name, index)
3069 i_ft2_setdpi(font, xdpi, ydpi)
3070 Imager::Font::FT2 font
3076 Imager::Font::FT2 font
3080 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
3082 PUSHs(sv_2mortal(newSViv(xdpi)));
3083 PUSHs(sv_2mortal(newSViv(ydpi)));
3087 i_ft2_sethinting(font, hinting)
3088 Imager::Font::FT2 font
3092 i_ft2_settransform(font, matrix)
3093 Imager::Font::FT2 font
3101 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3102 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3103 av=(AV*)SvRV(ST(1));
3107 for (i = 0; i < len; ++i) {
3108 sv1=(*(av_fetch(av,i,0)));
3109 matrix[i] = SvNV(sv1);
3113 RETVAL = i_ft2_settransform(font, matrix);
3118 i_ft2_bbox(font, cheight, cwidth, text)
3119 Imager::Font::FT2 font
3127 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
3129 for (i = 0; i < 6; ++i)
3130 PUSHs(sv_2mortal(newSViv(bbox[i])));
3134 i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3135 Imager::Font::FT2 font
3149 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3152 for (i = 0; i < 8; ++i)
3153 PUSHs(sv_2mortal(newSViv(bbox[i])));
3157 i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3158 Imager::Font::FT2 font
3174 if (SvUTF8(ST(7))) {
3178 text = SvPV(ST(7), len);
3179 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3180 len, align, aa, vlayout, utf8);
3185 i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3186 Imager::Font::FT2 font
3203 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3204 strlen(text), align, aa, vlayout, 1);
3209 ft2_transform_box(font, x0, x1, x2, x3)
3210 Imager::Font::FT2 font
3218 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3219 ft2_transform_box(font, box);
3221 PUSHs(sv_2mortal(newSViv(box[0])));
3222 PUSHs(sv_2mortal(newSViv(box[1])));
3223 PUSHs(sv_2mortal(newSViv(box[2])));
3224 PUSHs(sv_2mortal(newSViv(box[3])));
3228 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3232 Imager::FillHandle fill
3234 MODULE = Imager PACKAGE = Imager
3237 i_new_fill_solid(cl, combine)
3242 i_new_fill_solidf(cl, combine)
3243 Imager::Color::Float cl
3247 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3255 unsigned char *cust_hatch;
3259 cust_hatch = SvPV(ST(4), len);
3263 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3268 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3269 Imager::Color::Float fg
3270 Imager::Color::Float bg
3276 unsigned char *cust_hatch;
3280 cust_hatch = SvPV(ST(4), len);
3284 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3289 i_new_fill_image(src, matrix, xoff, yoff, combine)
3306 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3307 croak("i_new_fill_image: parameter must be an arrayref");
3308 av=(AV*)SvRV(ST(1));
3312 for (i = 0; i < len; ++i) {
3313 sv1=(*(av_fetch(av,i,0)));
3314 matrix[i] = SvNV(sv1);
3320 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);