17 typedef io_glue* Imager__IO;
18 typedef i_color* Imager__Color;
19 typedef i_fcolor* Imager__Color__Float;
20 typedef i_img* Imager__ImgRaw;
24 typedef TT_Fonthandle* Imager__Font__TT;
28 typedef FT2_Fonthandle* Imager__Font__FT2;
32 void my_SvREFCNT_dec(void *p) {
38 log_entry(char *string, int level) {
39 mm_log((level, string));
43 typedef struct i_reader_data_tag
45 /* presumably a CODE ref or name of a sub */
49 /* used by functions that want callbacks */
50 static int read_callback(char *userdata, char *buffer, int need, int want) {
51 i_reader_data *rd = (i_reader_data *)userdata;
55 dSP; dTARG = sv_newmortal();
56 /* thanks to Simon Cozens for help with the dTARG above */
66 count = perl_call_sv(rd->sv, G_SCALAR);
71 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
77 char *ptr = SvPV(data, len);
79 croak("Too much data returned in reader callback");
81 memcpy(buffer, ptr, len);
97 SV *sv; /* a coderef or sub name */
100 /* used by functions that want callbacks */
101 static int write_callback(char *userdata, char const *data, int size) {
102 i_writer_data *wd = (i_writer_data *)userdata;
112 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
115 count = perl_call_sv(wd->sv, G_SCALAR);
120 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
123 success = SvTRUE(sv);
137 static int lookup_name(struct value_name *names, int count, char *name, int def_value)
140 for (i = 0; i < count; ++i)
141 if (strEQ(names[i].name, name))
142 return names[i].value;
146 static struct value_name transp_names[] =
149 { "threshold", tr_threshold },
150 { "errdiff", tr_errdiff },
151 { "ordered", tr_ordered, },
154 static struct value_name make_color_names[] =
156 { "none", mc_none, },
157 { "webmap", mc_web_map, },
158 { "addi", mc_addi, },
161 static struct value_name translate_names[] =
164 { "giflib", pt_giflib, },
166 { "closest", pt_closest, },
167 { "perturb", pt_perturb, },
168 { "errdiff", pt_errdiff, },
171 static struct value_name errdiff_names[] =
173 { "floyd", ed_floyd, },
174 { "jarvis", ed_jarvis, },
175 { "stucki", ed_stucki, },
176 { "custom", ed_custom, },
179 static struct value_name orddith_names[] =
181 { "random", od_random, },
182 { "dot8", od_dot8, },
183 { "dot4", od_dot4, },
184 { "hline", od_hline, },
185 { "vline", od_vline, },
186 { "/line", od_slashline, },
187 { "slashline", od_slashline, },
188 { "\\line", od_backline, },
189 { "backline", od_backline, },
190 { "tiny", od_tiny, },
191 { "custom", od_custom, },
195 hv_fetch_bool(HV *hv, char *name, int def) {
198 sv = hv_fetch(hv, name, strlen(name), 0);
207 hv_fetch_int(HV *hv, char *name, int def) {
210 sv = hv_fetch(hv, name, strlen(name), 0);
218 /* look through the hash for quantization options */
219 static void handle_quant_opts(i_quantize *quant, HV *hv)
221 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
227 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 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
1268 #define TT_DESTROY(handle) i_tt_destroy(handle)
1272 Imager::Font::TT handle
1275 MODULE = Imager PACKAGE = Imager
1279 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1280 Imager::Font::TT handle
1292 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1293 Imager::Font::TT handle
1306 i_tt_bbox(handle,point,str,len)
1307 Imager::Font::TT handle
1314 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1316 PUSHs(sv_2mortal(newSViv(cords[0])));
1317 PUSHs(sv_2mortal(newSViv(cords[1])));
1318 PUSHs(sv_2mortal(newSViv(cords[2])));
1319 PUSHs(sv_2mortal(newSViv(cords[3])));
1320 PUSHs(sv_2mortal(newSViv(cords[4])));
1321 PUSHs(sv_2mortal(newSViv(cords[5])));
1332 i_writejpeg_wiol(im, ig, qfactor)
1348 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1349 if (iptc_itext == NULL) {
1352 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1357 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1359 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1372 i_readtiff_wiol(ig, length)
1378 i_writetiff_wiol(im, ig)
1383 i_writetiff_wiol_faxable(im, ig, fine)
1389 #endif /* HAVE_LIBTIFF */
1398 i_readpng_wiol(ig, length)
1404 i_writepng_wiol(im, ig)
1417 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1420 i_writegif(im,fd,colors,pixdev,fixed)
1427 Imager__Color fixed;
1434 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1435 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1436 av=(AV*)SvRV(ST(4));
1437 fixedlen=av_len(av)+1;
1438 fixed=mymalloc( fixedlen*sizeof(i_color) );
1439 for(i=0;i<fixedlen;i++) {
1440 sv1=(*(av_fetch(av,i,0)));
1441 if (sv_derived_from(sv1, "Imager::Color")) {
1442 Itmp = SvIV((SV*)SvRV(sv1));
1443 tmp = (i_color*) Itmp;
1444 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1447 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1449 ST(0) = sv_newmortal();
1450 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1451 else sv_setiv(ST(0), (IV)RETVAL);
1457 i_writegifmc(im,fd,colors)
1464 i_writegif_gen(fd, ...)
1470 i_img **imgs = NULL;
1476 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1477 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1478 croak("i_writegif_gen: Second argument must be a hash ref");
1479 hv = (HV *)SvRV(ST(1));
1480 memset(&quant, 0, sizeof(quant));
1481 quant.mc_size = 256;
1482 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1483 memset(&opts, 0, sizeof(opts));
1484 handle_quant_opts(&quant, hv);
1485 handle_gif_opts(&opts, hv);
1486 img_count = items - 2;
1488 if (img_count < 1) {
1491 i_push_error(0, "You need to specify images to save");
1494 imgs = mymalloc(sizeof(i_img *) * img_count);
1495 for (i = 0; i < img_count; ++i) {
1498 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1499 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1503 i_push_error(0, "Only images can be saved");
1509 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1513 copy_colors_back(hv, &quant);
1516 ST(0) = sv_newmortal();
1517 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1518 else sv_setiv(ST(0), (IV)RETVAL);
1519 myfree(quant.mc_colors);
1523 i_writegif_callback(cb, maxbuffer,...)
1528 i_img **imgs = NULL;
1535 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1536 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1537 croak("i_writegif_callback: Second argument must be a hash ref");
1538 hv = (HV *)SvRV(ST(2));
1539 memset(&quant, 0, sizeof(quant));
1540 quant.mc_size = 256;
1541 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1542 memset(&opts, 0, sizeof(opts));
1543 handle_quant_opts(&quant, hv);
1544 handle_gif_opts(&opts, hv);
1545 img_count = items - 3;
1547 if (img_count < 1) {
1551 imgs = mymalloc(sizeof(i_img *) * img_count);
1552 for (i = 0; i < img_count; ++i) {
1555 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1556 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1565 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1569 copy_colors_back(hv, &quant);
1572 ST(0) = sv_newmortal();
1573 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1574 else sv_setiv(ST(0), (IV)RETVAL);
1587 colour_table = NULL;
1590 if(GIMME_V == G_ARRAY) {
1591 rimg = i_readgif(fd,&colour_table,&colours);
1593 /* don't waste time with colours if they aren't wanted */
1594 rimg = i_readgif(fd,NULL,NULL);
1597 if (colour_table == NULL) {
1600 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1603 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1604 /* I don't know if I have the reference counts right or not :( */
1605 /* Neither do I :-) */
1606 /* No Idea here either */
1609 av_extend(ct, colours);
1610 for(q=0; q<colours; q++) {
1612 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1613 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1615 myfree(colour_table);
1619 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1621 PUSHs(newRV_noinc((SV*)ct));
1629 i_readgif_scalar(...)
1633 unsigned int length;
1641 data = (char *)SvPV(ST(0), length);
1645 if(GIMME_V == G_ARRAY) {
1646 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1648 /* don't waste time with colours if they aren't wanted */
1649 rimg=i_readgif_scalar(data,length,NULL,NULL);
1652 if (colour_table == NULL) {
1655 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1658 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1659 /* I don't know if I have the reference counts right or not :( */
1660 /* Neither do I :-) */
1662 av_extend(ct, colours);
1663 for(q=0; q<colours; q++) {
1665 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1666 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1668 myfree(colour_table);
1672 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1674 PUSHs(newRV_noinc((SV*)ct));
1678 i_readgif_callback(...)
1695 if(GIMME_V == G_ARRAY) {
1696 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1698 /* don't waste time with colours if they aren't wanted */
1699 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1702 if (colour_table == NULL) {
1705 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1708 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1709 /* I don't know if I have the reference counts right or not :( */
1710 /* Neither do I :-) */
1711 /* Neither do I - maybe I'll move this somewhere */
1713 av_extend(ct, colours);
1714 for(q=0; q<colours; q++) {
1716 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1717 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1719 myfree(colour_table);
1723 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1725 PUSHs(newRV_noinc((SV*)ct));
1736 imgs = i_readgif_multi(fd, &count);
1739 for (i = 0; i < count; ++i) {
1740 SV *sv = sv_newmortal();
1741 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1748 i_readgif_multi_scalar(data)
1753 unsigned int length;
1756 data = (char *)SvPV(ST(0), length);
1757 imgs = i_readgif_multi_scalar(data, length, &count);
1760 for (i = 0; i < count; ++i) {
1761 SV *sv = sv_newmortal();
1762 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1769 i_readgif_multi_callback(cb)
1777 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1780 for (i = 0; i < count; ++i) {
1781 SV *sv = sv_newmortal();
1782 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1793 i_readpnm_wiol(ig, length)
1799 i_writeppm_wiol(im, ig)
1805 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1814 i_writeraw_wiol(im,ig)
1819 i_writebmp_wiol(im,ig)
1829 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
1840 idlen = SvCUR(ST(4));
1841 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
1847 i_readtga_wiol(ig, length)
1853 i_scaleaxis(im,Value,Axis)
1859 i_scale_nn(im,scx,scy)
1869 i_count_colors(im,maxc)
1875 i_transform(im,opx,opy,parm)
1888 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1889 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1890 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1891 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1892 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1893 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1894 av=(AV*)SvRV(ST(1));
1896 opx=mymalloc( opxl*sizeof(int) );
1897 for(i=0;i<opxl;i++) {
1898 sv1=(*(av_fetch(av,i,0)));
1899 opx[i]=(int)SvIV(sv1);
1901 av=(AV*)SvRV(ST(2));
1903 opy=mymalloc( opyl*sizeof(int) );
1904 for(i=0;i<opyl;i++) {
1905 sv1=(*(av_fetch(av,i,0)));
1906 opy[i]=(int)SvIV(sv1);
1908 av=(AV*)SvRV(ST(3));
1909 parmlen=av_len(av)+1;
1910 parm=mymalloc( parmlen*sizeof(double) );
1911 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1912 sv1=(*(av_fetch(av,i,0)));
1913 parm[i]=(double)SvNV(sv1);
1915 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1919 ST(0) = sv_newmortal();
1920 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1921 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1924 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1943 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1944 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1945 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1946 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1947 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1949 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1951 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1952 av = (AV*)SvRV(ST(5));
1953 in_imgs_count = av_len(av)+1;
1954 for (i = 0; i < in_imgs_count; ++i) {
1955 sv1 = *av_fetch(av, i, 0);
1956 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1957 croak("Parameter 5 must contain only images");
1964 if (in_imgs_count > 0) {
1965 av = (AV*)SvRV(ST(5));
1966 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1967 for (i = 0; i < in_imgs_count; ++i) {
1968 sv1 = *av_fetch(av,i,0);
1969 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1970 croak("Parameter 5 must contain only images");
1972 tmp = SvIV((SV*)SvRV(sv1));
1973 in_imgs[i] = (i_img*)tmp;
1977 /* no input images */
1980 /* default the output size from the first input if possible */
1982 width = SvIV(ST(0));
1983 else if (in_imgs_count)
1984 width = in_imgs[0]->xsize;
1986 croak("No output image width supplied");
1989 height = SvIV(ST(1));
1990 else if (in_imgs_count)
1991 height = in_imgs[0]->ysize;
1993 croak("No output image height supplied");
1995 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1996 if (ops_len % sizeof(struct rm_op))
1997 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1998 ops_count = ops_len / sizeof(struct rm_op);
1999 av = (AV*)SvRV(ST(3));
2000 n_regs_count = av_len(av)+1;
2001 n_regs = mymalloc(n_regs_count * sizeof(double));
2002 for (i = 0; i < n_regs_count; ++i) {
2003 sv1 = *av_fetch(av,i,0);
2005 n_regs[i] = SvNV(sv1);
2007 av = (AV*)SvRV(ST(4));
2008 c_regs_count = av_len(av)+1;
2009 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2010 /* I don't bother initializing the colou?r registers */
2012 RETVAL=i_transform2(width, height, 3, ops, ops_count,
2013 n_regs, n_regs_count,
2014 c_regs, c_regs_count, in_imgs, in_imgs_count);
2019 ST(0) = sv_newmortal();
2020 if (RETVAL == 0) ST(0)=&PL_sv_undef;
2021 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
2025 i_contrast(im,intensity)
2034 i_noise(im,amount,type)
2040 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2050 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2069 i_postlevels(im,levels)
2079 i_watermark(im,wmark,tx,ty,pixdiff)
2081 Imager::ImgRaw wmark
2088 i_autolevels(im,lsat,usat,skew)
2095 i_radnoise(im,xo,yo,rscale,ascale)
2103 i_turbnoise(im, xo, yo, scale)
2126 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
2127 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2128 croak("i_gradgen: Second argument must be an array ref");
2129 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2130 croak("i_gradgen: Third argument must be an array ref");
2131 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2132 croak("i_gradgen: Fourth argument must be an array ref");
2133 axx = (AV *)SvRV(ST(1));
2134 ayy = (AV *)SvRV(ST(2));
2135 ac = (AV *)SvRV(ST(3));
2136 dmeasure = (int)SvIV(ST(4));
2138 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2139 num = num <= av_len(ac) ? num : av_len(ac);
2141 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
2142 xo = mymalloc( sizeof(int) * num );
2143 yo = mymalloc( sizeof(int) * num );
2144 ival = mymalloc( sizeof(i_color) * num );
2145 for(i = 0; i<num; i++) {
2146 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2147 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2148 sv = *av_fetch(ac, i, 0);
2149 if ( !sv_derived_from(sv, "Imager::Color") ) {
2150 free(axx); free(ayy); free(ac);
2151 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
2153 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2155 i_gradgen(im, num, xo, yo, ival, dmeasure);
2162 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2172 double ssample_param
2176 i_fountain_seg *segs;
2178 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2179 croak("i_fountain: argument 11 must be an array ref");
2181 asegs = (AV *)SvRV(ST(10));
2182 segs = load_fount_segs(asegs, &count);
2183 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2184 ssample_param, count, segs);
2188 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2197 double ssample_param
2201 i_fountain_seg *segs;
2203 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2204 croak("i_fountain: argument 11 must be an array ref");
2206 asegs = (AV *)SvRV(ST(9));
2207 segs = load_fount_segs(asegs, &count);
2208 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2209 super_sample, ssample_param, count, segs);
2223 errors = i_errors();
2225 while (errors[i].msg) {
2227 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2228 if (!av_store(av, 0, sv)) {
2231 sv = newSViv(errors[i].code);
2232 if (!av_store(av, 1, sv)) {
2235 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2240 i_nearest_color(im, ...)
2255 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2256 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2257 croak("i_nearest_color: Second argument must be an array ref");
2258 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2259 croak("i_nearest_color: Third argument must be an array ref");
2260 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2261 croak("i_nearest_color: Fourth argument must be an array ref");
2262 axx = (AV *)SvRV(ST(1));
2263 ayy = (AV *)SvRV(ST(2));
2264 ac = (AV *)SvRV(ST(3));
2265 dmeasure = (int)SvIV(ST(4));
2267 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2268 num = num <= av_len(ac) ? num : av_len(ac);
2270 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2271 xo = mymalloc( sizeof(int) * num );
2272 yo = mymalloc( sizeof(int) * num );
2273 ival = mymalloc( sizeof(i_color) * num );
2274 for(i = 0; i<num; i++) {
2275 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2276 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2277 sv = *av_fetch(ac, i, 0);
2278 if ( !sv_derived_from(sv, "Imager::Color") ) {
2279 free(axx); free(ayy); free(ac);
2280 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2282 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2284 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2298 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2299 hv=(HV*)SvRV(ST(0));
2300 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2301 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2302 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2311 rc=DSO_open(filename,&evstr);
2315 PUSHs(sv_2mortal(newSViv((IV)rc)));
2316 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2319 PUSHs(sv_2mortal(newSViv((IV)rc)));
2325 DSO_close(dso_handle)
2329 DSO_funclist(dso_handle_v)
2333 DSO_handle *dso_handle;
2335 dso_handle=(DSO_handle*)dso_handle_v;
2337 while( dso_handle->function_list[i].name != NULL) {
2339 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2341 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2346 DSO_call(handle,func_index,hv)
2352 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2353 hv=(HV*)SvRV(ST(2));
2354 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2355 DSO_call( (DSO_handle *)handle,func_index,hv);
2359 # this is mostly for testing...
2361 i_get_pixel(im, x, y)
2368 color = (i_color *)mymalloc(sizeof(i_color));
2369 if (i_gpix(im, x, y, color) == 0) {
2370 ST(0) = sv_newmortal();
2371 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2375 ST(0) = &PL_sv_undef;
2380 i_ppix(im, x, y, cl)
2387 i_img_pal_new(x, y, channels, maxpal)
2394 i_img_to_pal(src, quant)
2400 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2401 croak("i_img_to_pal: second argument must be a hash ref");
2402 hv = (HV *)SvRV(ST(1));
2403 memset(&quant, 0, sizeof(quant));
2404 quant.mc_size = 256;
2405 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2406 handle_quant_opts(&quant, hv);
2407 RETVAL = i_img_to_pal(src, &quant);
2409 copy_colors_back(hv, &quant);
2411 myfree(quant.mc_colors);
2430 work = mymalloc((r-l) * sizeof(i_palidx));
2431 count = i_gpal(im, l, r, y, work);
2432 if (GIMME_V == G_ARRAY) {
2434 for (i = 0; i < count; ++i) {
2435 PUSHs(sv_2mortal(newSViv(work[i])));
2440 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2445 if (GIMME_V != G_ARRAY) {
2447 PUSHs(&PL_sv_undef);
2452 i_ppal(im, l, y, ...)
2461 work = mymalloc(sizeof(i_palidx) * (items-3));
2462 for (i=0; i < items-3; ++i) {
2463 work[i] = SvIV(ST(i+3));
2465 RETVAL = i_ppal(im, l, l+items-3, y, work);
2475 i_addcolors(im, ...)
2483 croak("i_addcolors: no colors to add");
2484 colors = mymalloc((items-1) * sizeof(i_color));
2485 for (i=0; i < items-1; ++i) {
2486 if (sv_isobject(ST(i+1))
2487 && sv_derived_from(ST(i+1), "Imager::Color")) {
2488 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2489 colors[i] = *(i_color *)tmp;
2493 croak("i_plin: pixels must be Imager::Color objects");
2496 index = i_addcolors(im, colors, items-1);
2499 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2501 else if (index == -1) {
2502 ST(0) = &PL_sv_undef;
2505 ST(0) = sv_2mortal(newSViv(index));
2509 i_setcolors(im, index, ...)
2517 croak("i_setcolors: no colors to add");
2518 colors = mymalloc((items-2) * sizeof(i_color));
2519 for (i=0; i < items-2; ++i) {
2520 if (sv_isobject(ST(i+2))
2521 && sv_derived_from(ST(i+2), "Imager::Color")) {
2522 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2523 colors[i] = *(i_color *)tmp;
2527 croak("i_setcolors: pixels must be Imager::Color objects");
2530 RETVAL = i_setcolors(im, index, colors, items-2);
2534 i_getcolors(im, index, ...)
2543 croak("i_getcolors: too many arguments");
2545 count = SvIV(ST(2));
2547 croak("i_getcolors: count must be positive");
2548 colors = mymalloc(sizeof(i_color) * count);
2549 if (i_getcolors(im, index, colors, count)) {
2550 for (i = 0; i < count; ++i) {
2552 SV *sv = sv_newmortal();
2553 pv = mymalloc(sizeof(i_color));
2555 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2568 count = i_colorcount(im);
2570 ST(0) = sv_2mortal(newSViv(count));
2573 ST(0) = &PL_sv_undef;
2582 count = i_maxcolors(im);
2584 ST(0) = sv_2mortal(newSViv(count));
2587 ST(0) = &PL_sv_undef;
2591 i_findcolor(im, color)
2597 if (i_findcolor(im, color, &index)) {
2598 ST(0) = sv_2mortal(newSViv(index));
2601 ST(0) = &PL_sv_undef;
2617 i_gsamp(im, l, r, y, ...)
2629 croak("No channel numbers supplied to g_samp()");
2631 chan_count = items - 4;
2632 chans = mymalloc(sizeof(int) * chan_count);
2633 for (i = 0; i < chan_count; ++i)
2634 chans[i] = SvIV(ST(i+4));
2635 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count); /* XXX: memleak? */
2636 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2638 if (GIMME_V == G_ARRAY) {
2640 for (i = 0; i < count; ++i)
2641 PUSHs(sv_2mortal(newSViv(data[i])));
2645 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2650 if (GIMME_V != G_ARRAY) {
2652 PUSHs(&PL_sv_undef);
2658 i_img_masked_new(targ, mask, x, y, w, h)
2668 if (!sv_isobject(ST(1))
2669 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2670 croak("i_img_masked_new: parameter 2 must undef or an image");
2672 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2676 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2681 i_plin(im, l, y, ...)
2690 work = mymalloc(sizeof(i_color) * (items-3));
2691 for (i=0; i < items-3; ++i) {
2692 if (sv_isobject(ST(i+3))
2693 && sv_derived_from(ST(i+3), "Imager::Color")) {
2694 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2695 work[i] = *(i_color *)tmp;
2699 croak("i_plin: pixels must be Imager::Color objects");
2703 RETVAL = i_plin(im, l, l+items-3, y, work);
2713 i_ppixf(im, x, y, cl)
2717 Imager::Color::Float cl
2720 i_gsampf(im, l, r, y, ...)
2732 croak("No channel numbers supplied to g_sampf()");
2734 chan_count = items - 4;
2735 chans = mymalloc(sizeof(int) * chan_count);
2736 for (i = 0; i < chan_count; ++i)
2737 chans[i] = SvIV(ST(i+4));
2738 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2739 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2740 if (GIMME_V == G_ARRAY) {
2742 for (i = 0; i < count; ++i)
2743 PUSHs(sv_2mortal(newSVnv(data[i])));
2747 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2751 if (GIMME_V != G_ARRAY) {
2753 PUSHs(&PL_sv_undef);
2758 i_plinf(im, l, y, ...)
2767 work = mymalloc(sizeof(i_fcolor) * (items-3));
2768 for (i=0; i < items-3; ++i) {
2769 if (sv_isobject(ST(i+3))
2770 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2771 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2772 work[i] = *(i_fcolor *)tmp;
2776 croak("i_plin: pixels must be Imager::Color::Float objects");
2780 RETVAL = i_plinf(im, l, l+items-3, y, work);
2797 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2798 if (i_gpixf(im, x, y, color) == 0) {
2799 ST(0) = sv_newmortal();
2800 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2804 ST(0) = &PL_sv_undef;
2818 vals = mymalloc((r-l) * sizeof(i_color));
2819 count = i_glin(im, l, r, y, vals);
2821 for (i = 0; i < count; ++i) {
2823 i_color *col = mymalloc(sizeof(i_color));
2824 sv = sv_newmortal();
2825 sv_setref_pv(sv, "Imager::Color", (void *)col);
2832 i_glinf(im, l, r, y)
2842 vals = mymalloc((r-l) * sizeof(i_fcolor));
2843 count = i_glinf(im, l, r, y, vals);
2845 for (i = 0; i < count; ++i) {
2847 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2849 sv = sv_newmortal();
2850 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2857 i_img_16_new(x, y, ch)
2863 i_img_double_new(x, y, ch)
2869 i_tags_addn(im, name, code, idata)
2878 name = SvPV(ST(1), len);
2881 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2886 i_tags_add(im, name, code, data, idata)
2896 name = SvPV(ST(1), len);
2900 data = SvPV(ST(3), len);
2905 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2910 i_tags_find(im, name, start)
2917 if (i_tags_find(&im->tags, name, start, &entry)) {
2919 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2921 ST(0) = sv_2mortal(newSViv(entry));
2923 ST(0) = &PL_sv_undef;
2927 i_tags_findn(im, code, start)
2934 if (i_tags_findn(&im->tags, code, start, &entry)) {
2936 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2938 ST(0) = sv_2mortal(newSViv(entry));
2941 ST(0) = &PL_sv_undef;
2944 i_tags_delete(im, entry)
2948 RETVAL = i_tags_delete(&im->tags, entry);
2953 i_tags_delbyname(im, name)
2957 RETVAL = i_tags_delbyname(&im->tags, name);
2962 i_tags_delbycode(im, code)
2966 RETVAL = i_tags_delbycode(&im->tags, code);
2971 i_tags_get(im, index)
2975 if (index >= 0 && index < im->tags.count) {
2976 i_img_tag *entry = im->tags.tags + index;
2980 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2983 PUSHs(sv_2mortal(newSViv(entry->code)));
2986 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2989 PUSHs(sv_2mortal(newSViv(entry->idata)));
2997 RETVAL = im->tags.count;
3004 i_wf_bbox(face, size, text)
3011 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
3013 PUSHs(sv_2mortal(newSViv(cords[0])));
3014 PUSHs(sv_2mortal(newSViv(cords[1])));
3015 PUSHs(sv_2mortal(newSViv(cords[2])));
3016 PUSHs(sv_2mortal(newSViv(cords[3])));
3017 PUSHs(sv_2mortal(newSViv(cords[4])));
3018 PUSHs(sv_2mortal(newSViv(cords[5])));
3022 i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
3033 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
3039 i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
3050 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
3060 MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
3062 #define FT2_DESTROY(font) i_ft2_destroy(font)
3066 Imager::Font::FT2 font
3068 MODULE = Imager PACKAGE = Imager::Font::FreeType2
3071 i_ft2_new(name, index)
3076 i_ft2_setdpi(font, xdpi, ydpi)
3077 Imager::Font::FT2 font
3083 Imager::Font::FT2 font
3087 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
3089 PUSHs(sv_2mortal(newSViv(xdpi)));
3090 PUSHs(sv_2mortal(newSViv(ydpi)));
3094 i_ft2_sethinting(font, hinting)
3095 Imager::Font::FT2 font
3099 i_ft2_settransform(font, matrix)
3100 Imager::Font::FT2 font
3108 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3109 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
3110 av=(AV*)SvRV(ST(1));
3114 for (i = 0; i < len; ++i) {
3115 sv1=(*(av_fetch(av,i,0)));
3116 matrix[i] = SvNV(sv1);
3120 RETVAL = i_ft2_settransform(font, matrix);
3125 i_ft2_bbox(font, cheight, cwidth, text)
3126 Imager::Font::FT2 font
3134 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
3136 for (i = 0; i < 6; ++i)
3137 PUSHs(sv_2mortal(newSViv(bbox[i])));
3141 i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
3142 Imager::Font::FT2 font
3156 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
3159 for (i = 0; i < 8; ++i)
3160 PUSHs(sv_2mortal(newSViv(bbox[i])));
3164 i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
3165 Imager::Font::FT2 font
3181 if (SvUTF8(ST(7))) {
3185 text = SvPV(ST(7), len);
3186 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3187 len, align, aa, vlayout, utf8);
3192 i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3193 Imager::Font::FT2 font
3210 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3211 strlen(text), align, aa, vlayout, 1);
3216 ft2_transform_box(font, x0, x1, x2, x3)
3217 Imager::Font::FT2 font
3225 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3226 ft2_transform_box(font, box);
3228 PUSHs(sv_2mortal(newSViv(box[0])));
3229 PUSHs(sv_2mortal(newSViv(box[1])));
3230 PUSHs(sv_2mortal(newSViv(box[2])));
3231 PUSHs(sv_2mortal(newSViv(box[3])));
3235 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3239 Imager::FillHandle fill
3241 MODULE = Imager PACKAGE = Imager
3244 i_new_fill_solid(cl, combine)
3249 i_new_fill_solidf(cl, combine)
3250 Imager::Color::Float cl
3254 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3262 unsigned char *cust_hatch;
3266 cust_hatch = SvPV(ST(4), len);
3270 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
3275 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
3276 Imager::Color::Float fg
3277 Imager::Color::Float bg
3283 unsigned char *cust_hatch;
3287 cust_hatch = SvPV(ST(4), len);
3291 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
3296 i_new_fill_image(src, matrix, xoff, yoff, combine)
3313 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
3314 croak("i_new_fill_image: parameter must be an arrayref");
3315 av=(AV*)SvRV(ST(1));
3319 for (i = 0; i < len; ++i) {
3320 sv1=(*(av_fetch(av,i,0)));
3321 matrix[i] = SvNV(sv1);
3327 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);