17 typedef io_glue* Imager__IO;
18 typedef i_color* Imager__Color;
19 typedef i_fcolor* Imager__Color__Float;
20 typedef i_img* Imager__ImgRaw;
24 typedef TT_Fonthandle* Imager__TTHandle;
28 typedef FT2_Fonthandle* Imager__Font__FT2;
31 typedef struct i_reader_data_tag
33 /* presumably a CODE ref or name of a sub */
37 /* used by functions that want callbacks */
38 static int read_callback(char *userdata, char *buffer, int need, int want) {
39 i_reader_data *rd = (i_reader_data *)userdata;
43 dSP; dTARG = sv_newmortal();
44 /* thanks to Simon Cozens for help with the dTARG above */
54 count = perl_call_sv(rd->sv, G_SCALAR);
59 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
65 char *ptr = SvPV(data, len);
67 croak("Too much data returned in reader callback");
69 memcpy(buffer, ptr, len);
85 SV *sv; /* a coderef or sub name */
88 /* used by functions that want callbacks */
89 static int write_callback(char *userdata, char const *data, int size) {
90 i_writer_data *wd = (i_writer_data *)userdata;
100 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
103 count = perl_call_sv(wd->sv, G_SCALAR);
108 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
111 success = SvTRUE(sv);
125 static int lookup_name(struct value_name *names, int count, char *name, int def_value)
128 for (i = 0; i < count; ++i)
129 if (strEQ(names[i].name, name))
130 return names[i].value;
134 static struct value_name transp_names[] =
137 { "threshold", tr_threshold },
138 { "errdiff", tr_errdiff },
139 { "ordered", tr_ordered, },
142 static struct value_name make_color_names[] =
144 { "none", mc_none, },
145 { "webmap", mc_web_map, },
146 { "addi", mc_addi, },
149 static struct value_name translate_names[] =
152 { "giflib", pt_giflib, },
154 { "closest", pt_closest, },
155 { "perturb", pt_perturb, },
156 { "errdiff", pt_errdiff, },
159 static struct value_name errdiff_names[] =
161 { "floyd", ed_floyd, },
162 { "jarvis", ed_jarvis, },
163 { "stucki", ed_stucki, },
164 { "custom", ed_custom, },
167 static struct value_name orddith_names[] =
169 { "random", od_random, },
170 { "dot8", od_dot8, },
171 { "dot4", od_dot4, },
172 { "hline", od_hline, },
173 { "vline", od_vline, },
174 { "/line", od_slashline, },
175 { "slashline", od_slashline, },
176 { "\\line", od_backline, },
177 { "backline", od_backline, },
178 { "tiny", od_tiny, },
179 { "custom", od_custom, },
182 /* look through the hash for quantization options */
183 static void handle_quant_opts(i_quantize *quant, HV *hv)
185 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
191 sv = hv_fetch(hv, "transp", 6, 0);
192 if (sv && *sv && (str = SvPV(*sv, len))) {
194 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
196 if (quant->transp != tr_none) {
197 quant->tr_threshold = 127;
198 sv = hv_fetch(hv, "tr_threshold", 12, 0);
200 quant->tr_threshold = SvIV(*sv);
202 if (quant->transp == tr_errdiff) {
203 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
204 if (sv && *sv && (str = SvPV(*sv, len)))
205 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
207 if (quant->transp == tr_ordered) {
208 quant->tr_orddith = od_tiny;
209 sv = hv_fetch(hv, "tr_orddith", 10, 0);
210 if (sv && *sv && (str = SvPV(*sv, len)))
211 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
213 if (quant->tr_orddith == od_custom) {
214 sv = hv_fetch(hv, "tr_map", 6, 0);
215 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
216 AV *av = (AV*)SvRV(*sv);
217 len = av_len(av) + 1;
218 if (len > sizeof(quant->tr_custom))
219 len = sizeof(quant->tr_custom);
220 for (i = 0; i < len; ++i) {
221 SV **sv2 = av_fetch(av, i, 0);
223 quant->tr_custom[i] = SvIV(*sv2);
226 while (i < sizeof(quant->tr_custom))
227 quant->tr_custom[i++] = 0;
232 quant->make_colors = mc_addi;
233 sv = hv_fetch(hv, "make_colors", 11, 0);
234 if (sv && *sv && (str = SvPV(*sv, len))) {
236 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
238 sv = hv_fetch(hv, "colors", 6, 0);
239 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
240 /* needs to be an array of Imager::Color
241 note that the caller allocates the mc_color array and sets mc_size
243 AV *av = (AV *)SvRV(*sv);
244 quant->mc_count = av_len(av)+1;
245 if (quant->mc_count > quant->mc_size)
246 quant->mc_count = quant->mc_size;
247 for (i = 0; i < quant->mc_count; ++i) {
248 SV **sv1 = av_fetch(av, i, 0);
249 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
250 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
251 quant->mc_colors[i] = *col;
255 sv = hv_fetch(hv, "max_colors", 10, 0);
258 if (i <= quant->mc_size && i >= quant->mc_count)
262 quant->translate = pt_closest;
263 sv = hv_fetch(hv, "translate", 9, 0);
264 if (sv && *sv && (str = SvPV(*sv, len))) {
265 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
267 sv = hv_fetch(hv, "errdiff", 7, 0);
268 if (sv && *sv && (str = SvPV(*sv, len))) {
269 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
271 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
272 /* get the error diffusion map */
273 sv = hv_fetch(hv, "errdiff_width", 13, 0);
275 quant->ed_width = SvIV(*sv);
276 sv = hv_fetch(hv, "errdiff_height", 14, 0);
278 quant->ed_height = SvIV(*sv);
279 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
281 quant->ed_orig = SvIV(*sv);
282 if (quant->ed_width > 0 && quant->ed_height > 0) {
284 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
285 sv = hv_fetch(hv, "errdiff_map", 11, 0);
286 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
287 AV *av = (AV*)SvRV(*sv);
288 len = av_len(av) + 1;
289 if (len > quant->ed_width * quant->ed_height)
290 len = quant->ed_width * quant->ed_height;
291 for (i = 0; i < len; ++i) {
292 SV **sv2 = av_fetch(av, i, 0);
294 quant->ed_map[i] = SvIV(*sv2);
295 sum += quant->ed_map[i];
301 myfree(quant->ed_map);
303 quant->errdiff = ed_floyd;
307 sv = hv_fetch(hv, "perturb", 7, 0);
309 quant->perturb = SvIV(*sv);
312 /* look through the hash for options to add to opts */
313 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
317 /**((char *)0) = '\0';*/
318 sv = hv_fetch(hv, "gif_each_palette", 16, 0);
320 opts->each_palette = SvIV(*sv);
321 sv = hv_fetch(hv, "interlace", 9, 0);
323 opts->interlace = SvIV(*sv);
324 sv = hv_fetch(hv, "gif_delays", 10, 0);
325 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
326 AV *av = (AV*)SvRV(*sv);
327 opts->delay_count = av_len(av)+1;
328 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
329 for (i = 0; i < opts->delay_count; ++i) {
330 SV *sv1 = *av_fetch(av, i, 0);
331 opts->delays[i] = SvIV(sv1);
334 sv = hv_fetch(hv, "gif_user_input", 14, 0);
335 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
336 AV *av = (AV*)SvRV(*sv);
337 opts->user_input_count = av_len(av)+1;
338 opts->user_input_flags = mymalloc(opts->user_input_count);
339 for (i = 0; i < opts->user_input_count; ++i) {
340 SV *sv1 = *av_fetch(av, i, 0);
341 opts->user_input_flags[i] = SvIV(sv1) != 0;
344 sv = hv_fetch(hv, "gif_disposal", 12, 0);
345 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
346 AV *av = (AV*)SvRV(*sv);
347 opts->disposal_count = av_len(av)+1;
348 opts->disposal = mymalloc(opts->disposal_count);
349 for (i = 0; i < opts->disposal_count; ++i) {
350 SV *sv1 = *av_fetch(av, i, 0);
351 opts->disposal[i] = SvIV(sv1);
354 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
355 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
356 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
357 opts->tran_color = *col;
359 sv = hv_fetch(hv, "gif_positions", 13, 0);
360 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
361 AV *av = (AV *)SvRV(*sv);
362 opts->position_count = av_len(av) + 1;
363 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
364 for (i = 0; i < opts->position_count; ++i) {
365 SV **sv2 = av_fetch(av, i, 0);
366 opts->positions[i].x = opts->positions[i].y = 0;
367 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
368 AV *av2 = (AV*)SvRV(*sv2);
370 sv3 = av_fetch(av2, 0, 0);
372 opts->positions[i].x = SvIV(*sv3);
373 sv3 = av_fetch(av2, 1, 0);
375 opts->positions[i].y = SvIV(*sv3);
379 /* Netscape2.0 loop count extension */
380 sv = hv_fetch(hv, "gif_loop_count", 14, 0);
382 opts->loop_count = SvIV(*sv);
385 /* copies the color map from the hv into the colors member of the HV */
386 static void copy_colors_back(HV *hv, i_quantize *quant) {
392 sv = hv_fetch(hv, "colors", 6, 0);
393 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
396 ref = newRV_inc((SV*) av);
397 sv = hv_store(hv, "colors", 6, ref, 0);
400 av = (AV *)SvRV(*sv);
402 av_extend(av, quant->mc_count+1);
403 for (i = 0; i < quant->mc_count; ++i) {
404 i_color *in = quant->mc_colors+i;
405 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
406 work = sv_newmortal();
407 sv_setref_pv(work, "Imager::Color", (void *)c);
409 if (!av_store(av, i, work)) {
415 /* loads the segments of a fountain fill into an array */
416 i_fountain_seg *load_fount_segs(AV *asegs, int *count) {
417 /* Each element of segs must contain:
418 [ start, middle, end, c0, c1, segtype, colortrans ]
419 start, middle, end are doubles from 0 to 1
420 c0, c1 are Imager::Color::Float or Imager::Color objects
421 segtype, colortrans are ints
426 i_fountain_seg *segs;
430 *count = av_len(asegs)+1;
432 croak("i_fountain must have at least one segment");
433 segs = mymalloc(sizeof(i_fountain_seg) * *count);
434 for(i = 0; i < *count; i++) {
435 SV **sv1 = av_fetch(asegs, i, 0);
436 if (!sv1 || !*sv1 || !SvROK(*sv1)
437 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
439 croak("i_fountain: segs must be an arrayref of arrayrefs");
441 aseg = (AV *)SvRV(*sv1);
442 if (av_len(aseg) != 7-1) {
444 croak("i_fountain: a segment must have 7 members");
446 for (j = 0; j < 3; ++j) {
447 SV **sv2 = av_fetch(aseg, j, 0);
450 croak("i_fountain: XS error");
452 work[j] = SvNV(*sv2);
454 segs[i].start = work[0];
455 segs[i].middle = work[1];
456 segs[i].end = work[2];
457 for (j = 0; j < 2; ++j) {
458 SV **sv3 = av_fetch(aseg, 3+j, 0);
459 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
460 (!sv_derived_from(*sv3, "Imager::Color")
461 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
463 croak("i_fountain: segs must contain colors in elements 3 and 4");
465 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
466 segs[i].c[j] = *(i_fcolor *)SvIV((SV *)SvRV(*sv3));
469 i_color c = *(i_color *)SvIV((SV *)SvRV(*sv3));
471 for (ch = 0; ch < MAXCHANNELS; ++ch) {
472 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
476 for (j = 0; j < 2; ++j) {
477 SV **sv2 = av_fetch(aseg, j+5, 0);
480 croak("i_fountain: XS error");
482 worki[j] = SvIV(*sv2);
484 segs[i].type = worki[0];
485 segs[i].color = worki[1];
491 /* I don't think ICLF_* names belong at the C interface
492 this makes the XS code think we have them, to let us avoid
493 putting function bodies in the XS code
495 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
496 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
498 /* for the fill objects
499 Since a fill object may later have dependent images, (or fills!)
500 we need perl wrappers - oh well
502 #define IFILL_DESTROY(fill) i_fill_destroy(fill);
503 typedef i_fill_t* Imager__FillHandle;
505 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
508 ICL_new_internal(r,g,b,a)
520 ICL_set_internal(cl,r,g,b,a)
527 ICL_set_internal(cl, r, g, b, a);
541 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
542 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
543 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
544 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
549 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
552 ICLF_new_internal(r, g, b, a)
560 Imager::Color::Float cl
564 Imager::Color::Float cl
568 EXTEND(SP, MAXCHANNELS);
569 for (ch = 0; ch < MAXCHANNELS; ++ch) {
570 /* printf("%d: %g\n", ch, cl->channel[ch]); */
571 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
575 ICLF_set_internal(cl,r,g,b,a)
576 Imager::Color::Float cl
589 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
603 MODULE = Imager PACKAGE = Imager
625 tlength = io_slurp(ig, &data);
628 PUSHs(sv_2mortal(newSVpv(data,tlength)));
640 while( (item=i_format_list[i++]) != NULL ) {
642 PUSHs(sv_2mortal(newSVpv(item,0)));
659 i_img_empty_ch(im,x,y,ch)
686 PUSHs(sv_2mortal(newSViv(info[0])));
687 PUSHs(sv_2mortal(newSViv(info[1])));
688 PUSHs(sv_2mortal(newSViv(info[2])));
689 PUSHs(sv_2mortal(newSViv(info[3])));
695 i_img_setmask(im,ch_mask)
704 i_img_getchannels(im)
712 PUSHs(im->idata ? sv_2mortal(newSVpv(im->idata, im->bytes))
717 i_draw(im,x1,y1,x2,y2,val)
726 i_line_aa(im,x1,y1,x2,y2,val)
735 i_box(im,x1,y1,x2,y2,val)
744 i_box_filled(im,x1,y1,x2,y2,val)
753 i_box_cfill(im,x1,y1,x2,y2,fill)
759 Imager::FillHandle fill
762 i_arc(im,x,y,rad,d1,d2,val)
772 i_arc_cfill(im,x,y,rad,d1,d2,fill)
779 Imager::FillHandle fill
784 i_circle_aa(im,x,y,rad,val)
794 i_bezier_multi(im,xc,yc,val)
807 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
808 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
809 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
810 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
811 av1=(AV*)SvRV(ST(1));
812 av2=(AV*)SvRV(ST(2));
813 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
815 x=mymalloc( len*sizeof(double) );
816 y=mymalloc( len*sizeof(double) );
818 sv1=(*(av_fetch(av1,i,0)));
819 sv2=(*(av_fetch(av2,i,0)));
820 x[i]=(double)SvNV(sv1);
821 y[i]=(double)SvNV(sv2);
823 i_bezier_multi(im,len,x,y,val);
829 i_poly_aa(im,xc,yc,val)
842 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
843 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
844 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
845 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
846 av1=(AV*)SvRV(ST(1));
847 av2=(AV*)SvRV(ST(2));
848 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
850 x=mymalloc( len*sizeof(double) );
851 y=mymalloc( len*sizeof(double) );
853 sv1=(*(av_fetch(av1,i,0)));
854 sv2=(*(av_fetch(av2,i,0)));
855 x[i]=(double)SvNV(sv1);
856 y[i]=(double)SvNV(sv2);
858 i_poly_aa(im,len,x,y,val);
865 i_flood_fill(im,seedx,seedy,dcol)
873 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
885 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
903 i_rubthru(im,src,tx,ty)
910 i_flipxy(im, direction)
915 i_rotate90(im, degrees)
920 i_rotate_exact(im, amount)
925 i_matrix_transform(im, xsize, ysize, matrix)
936 if (!SvROK(ST(3)) || SvTYPE(SvRV(ST(3))) != SVt_PVAV)
937 croak("i_matrix_transform: parameter 4 must be an array ref\n");
942 for (i = 0; i < len; ++i) {
943 sv1=(*(av_fetch(av,i,0)));
944 matrix[i] = SvNV(sv1);
948 RETVAL = i_matrix_transform(im, xsize, ysize, matrix);
967 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
968 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
971 coeff=mymalloc( len*sizeof(float) );
973 sv1=(*(av_fetch(av,i,0)));
974 coeff[i]=(float)SvNV(sv1);
976 i_conv(im,coeff,len);
980 i_convert(im, src, coeff)
994 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
995 croak("i_convert: parameter 3 must be an arrayref\n");
996 avmain = (AV*)SvRV(ST(2));
997 outchan = av_len(avmain)+1;
998 /* find the biggest */
1000 for (j=0; j < outchan; ++j) {
1001 temp = av_fetch(avmain, j, 0);
1002 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
1003 avsub = (AV*)SvRV(*temp);
1004 len = av_len(avsub)+1;
1009 coeff = mymalloc(sizeof(float) * outchan * inchan);
1010 for (j = 0; j < outchan; ++j) {
1011 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
1012 len = av_len(avsub)+1;
1013 for (i = 0; i < len; ++i) {
1014 temp = av_fetch(avsub, i, 0);
1016 coeff[i+j*inchan] = SvNV(*temp);
1018 coeff[i+j*inchan] = 0;
1021 coeff[i++ + j*inchan] = 0;
1023 RETVAL = i_convert(im, src, coeff, outchan, inchan);
1033 unsigned int mask = 0;
1039 unsigned char (*maps)[256];
1041 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
1042 croak("i_map: parameter 2 must be an arrayref\n");
1043 avmain = (AV*)SvRV(ST(1));
1044 len = av_len(avmain)+1;
1045 if (im->channels < len) len = im->channels;
1047 maps = mymalloc( len * sizeof(unsigned char [256]) );
1049 for (j=0; j<len ; j++) {
1050 temp = av_fetch(avmain, j, 0);
1051 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
1052 avsub = (AV*)SvRV(*temp);
1053 if(av_len(avsub) != 255) continue;
1055 for (i=0; i<256 ; i++) {
1057 temp = av_fetch(avsub, i, 0);
1058 val = temp ? SvIV(*temp) : 0;
1060 if (val>255) val = 255;
1065 i_map(im, maps, mask);
1087 i_t1_new(pfb,afm=NULL)
1092 i_t1_destroy(font_id)
1097 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
1109 i_t1_bbox(fontnum,point,str,len)
1117 i_t1_bbox(fontnum,point,str,len,cords);
1119 PUSHs(sv_2mortal(newSViv(cords[0])));
1120 PUSHs(sv_2mortal(newSViv(cords[1])));
1121 PUSHs(sv_2mortal(newSViv(cords[2])));
1122 PUSHs(sv_2mortal(newSViv(cords[3])));
1123 PUSHs(sv_2mortal(newSViv(cords[4])));
1124 PUSHs(sv_2mortal(newSViv(cords[5])));
1129 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
1150 i_tt_destroy(handle)
1151 Imager::TTHandle handle
1156 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
1157 Imager::TTHandle handle
1169 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
1170 Imager::TTHandle handle
1183 i_tt_bbox(handle,point,str,len)
1184 Imager::TTHandle handle
1191 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
1193 PUSHs(sv_2mortal(newSViv(cords[0])));
1194 PUSHs(sv_2mortal(newSViv(cords[1])));
1195 PUSHs(sv_2mortal(newSViv(cords[2])));
1196 PUSHs(sv_2mortal(newSViv(cords[3])));
1197 PUSHs(sv_2mortal(newSViv(cords[4])));
1198 PUSHs(sv_2mortal(newSViv(cords[5])));
1209 i_writejpeg_wiol(im, ig, qfactor)
1225 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1226 if (iptc_itext == NULL) {
1229 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1234 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1236 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1249 i_readtiff_wiol(ig, length)
1255 i_writetiff_wiol(im, ig)
1260 i_writetiff_wiol_faxable(im, ig, fine)
1266 #endif /* HAVE_LIBTIFF */
1275 i_readpng_wiol(ig, length)
1281 i_writepng_wiol(im, ig)
1294 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1297 i_writegif(im,fd,colors,pixdev,fixed)
1304 Imager__Color fixed;
1311 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1312 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1313 av=(AV*)SvRV(ST(4));
1314 fixedlen=av_len(av)+1;
1315 fixed=mymalloc( fixedlen*sizeof(i_color) );
1316 for(i=0;i<fixedlen;i++) {
1317 sv1=(*(av_fetch(av,i,0)));
1318 if (sv_derived_from(sv1, "Imager::Color")) {
1319 Itmp = SvIV((SV*)SvRV(sv1));
1320 tmp = (i_color*) Itmp;
1321 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1324 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1326 ST(0) = sv_newmortal();
1327 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1328 else sv_setiv(ST(0), (IV)RETVAL);
1334 i_writegifmc(im,fd,colors)
1341 i_writegif_gen(fd, ...)
1347 i_img **imgs = NULL;
1353 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1354 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1355 croak("i_writegif_gen: Second argument must be a hash ref");
1356 hv = (HV *)SvRV(ST(1));
1357 memset(&quant, 0, sizeof(quant));
1358 quant.mc_size = 256;
1359 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1360 memset(&opts, 0, sizeof(opts));
1361 handle_quant_opts(&quant, hv);
1362 handle_gif_opts(&opts, hv);
1363 img_count = items - 2;
1365 if (img_count < 1) {
1368 i_push_error(0, "You need to specify images to save");
1371 imgs = mymalloc(sizeof(i_img *) * img_count);
1372 for (i = 0; i < img_count; ++i) {
1375 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1376 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1380 i_push_error(0, "Only images can be saved");
1386 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1390 copy_colors_back(hv, &quant);
1393 ST(0) = sv_newmortal();
1394 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1395 else sv_setiv(ST(0), (IV)RETVAL);
1398 i_writegif_callback(cb, maxbuffer,...)
1403 i_img **imgs = NULL;
1410 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1411 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1412 croak("i_writegif_callback: Second argument must be a hash ref");
1413 hv = (HV *)SvRV(ST(2));
1414 memset(&quant, 0, sizeof(quant));
1415 quant.mc_size = 256;
1416 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1417 memset(&opts, 0, sizeof(opts));
1418 handle_quant_opts(&quant, hv);
1419 handle_gif_opts(&opts, hv);
1420 img_count = items - 3;
1422 if (img_count < 1) {
1426 imgs = mymalloc(sizeof(i_img *) * img_count);
1427 for (i = 0; i < img_count; ++i) {
1430 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1431 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1440 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1444 copy_colors_back(hv, &quant);
1447 ST(0) = sv_newmortal();
1448 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1449 else sv_setiv(ST(0), (IV)RETVAL);
1462 colour_table = NULL;
1465 if(GIMME_V == G_ARRAY) {
1466 rimg = i_readgif(fd,&colour_table,&colours);
1468 /* don't waste time with colours if they aren't wanted */
1469 rimg = i_readgif(fd,NULL,NULL);
1472 if (colour_table == NULL) {
1475 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1478 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1479 /* I don't know if I have the reference counts right or not :( */
1480 /* Neither do I :-) */
1481 /* No Idea here either */
1484 av_extend(ct, colours);
1485 for(q=0; q<colours; q++) {
1487 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1488 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1490 myfree(colour_table);
1494 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1496 PUSHs(newRV_noinc((SV*)ct));
1504 i_readgif_scalar(...)
1508 unsigned int length;
1516 data = (char *)SvPV(ST(0), length);
1520 if(GIMME_V == G_ARRAY) {
1521 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1523 /* don't waste time with colours if they aren't wanted */
1524 rimg=i_readgif_scalar(data,length,NULL,NULL);
1527 if (colour_table == NULL) {
1530 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1533 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1534 /* I don't know if I have the reference counts right or not :( */
1535 /* Neither do I :-) */
1537 av_extend(ct, colours);
1538 for(q=0; q<colours; q++) {
1540 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1541 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1543 myfree(colour_table);
1547 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1549 PUSHs(newRV_noinc((SV*)ct));
1553 i_readgif_callback(...)
1570 if(GIMME_V == G_ARRAY) {
1571 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1573 /* don't waste time with colours if they aren't wanted */
1574 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1577 if (colour_table == NULL) {
1580 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1583 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1584 /* I don't know if I have the reference counts right or not :( */
1585 /* Neither do I :-) */
1586 /* Neither do I - maybe I'll move this somewhere */
1588 av_extend(ct, colours);
1589 for(q=0; q<colours; q++) {
1591 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1592 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1594 myfree(colour_table);
1598 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1600 PUSHs(newRV_noinc((SV*)ct));
1611 imgs = i_readgif_multi(fd, &count);
1614 for (i = 0; i < count; ++i) {
1615 SV *sv = sv_newmortal();
1616 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1623 i_readgif_multi_scalar(data)
1628 unsigned int length;
1631 data = (char *)SvPV(ST(0), length);
1632 imgs = i_readgif_multi_scalar(data, length, &count);
1635 for (i = 0; i < count; ++i) {
1636 SV *sv = sv_newmortal();
1637 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1644 i_readgif_multi_callback(cb)
1652 imgs = i_readgif_multi_callback(read_callback, (char *)&rd, &count);
1655 for (i = 0; i < count; ++i) {
1656 SV *sv = sv_newmortal();
1657 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
1668 i_readpnm_wiol(ig, length)
1674 i_writeppm_wiol(im, ig)
1680 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
1689 i_writeraw_wiol(im,ig)
1694 i_writebmp_wiol(im,ig)
1703 i_scaleaxis(im,Value,Axis)
1709 i_scale_nn(im,scx,scy)
1719 i_count_colors(im,maxc)
1725 i_transform(im,opx,opy,parm)
1738 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1739 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1740 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1741 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1742 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1743 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1744 av=(AV*)SvRV(ST(1));
1746 opx=mymalloc( opxl*sizeof(int) );
1747 for(i=0;i<opxl;i++) {
1748 sv1=(*(av_fetch(av,i,0)));
1749 opx[i]=(int)SvIV(sv1);
1751 av=(AV*)SvRV(ST(2));
1753 opy=mymalloc( opyl*sizeof(int) );
1754 for(i=0;i<opyl;i++) {
1755 sv1=(*(av_fetch(av,i,0)));
1756 opy[i]=(int)SvIV(sv1);
1758 av=(AV*)SvRV(ST(3));
1759 parmlen=av_len(av)+1;
1760 parm=mymalloc( parmlen*sizeof(double) );
1761 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1762 sv1=(*(av_fetch(av,i,0)));
1763 parm[i]=(double)SvNV(sv1);
1765 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1769 ST(0) = sv_newmortal();
1770 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1771 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1774 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1780 unsigned int ops_len;
1793 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1794 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1795 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1796 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1797 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1799 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1801 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1802 av = (AV*)SvRV(ST(5));
1803 in_imgs_count = av_len(av)+1;
1804 for (i = 0; i < in_imgs_count; ++i) {
1805 sv1 = *av_fetch(av, i, 0);
1806 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1807 croak("Parameter 5 must contain only images");
1814 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1815 av = (AV*)SvRV(ST(5));
1816 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1817 for (i = 0; i < in_imgs_count; ++i) {
1818 sv1 = *av_fetch(av,i,0);
1819 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1820 croak("Parameter 5 must contain only images");
1822 tmp = SvIV((SV*)SvRV(sv1));
1823 in_imgs[i] = (i_img*)tmp;
1827 /* no input images */
1830 /* default the output size from the first input if possible */
1832 width = SvIV(ST(0));
1833 else if (in_imgs_count)
1834 width = in_imgs[0]->xsize;
1836 croak("No output image width supplied");
1839 height = SvIV(ST(1));
1840 else if (in_imgs_count)
1841 height = in_imgs[0]->ysize;
1843 croak("No output image height supplied");
1845 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1846 if (ops_len % sizeof(struct rm_op))
1847 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1848 ops_count = ops_len / sizeof(struct rm_op);
1849 av = (AV*)SvRV(ST(3));
1850 n_regs_count = av_len(av)+1;
1851 n_regs = mymalloc(n_regs_count * sizeof(double));
1852 for (i = 0; i < n_regs_count; ++i) {
1853 sv1 = *av_fetch(av,i,0);
1855 n_regs[i] = SvNV(sv1);
1857 av = (AV*)SvRV(ST(4));
1858 c_regs_count = av_len(av)+1;
1859 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1860 /* I don't bother initializing the colou?r registers */
1862 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1863 n_regs, n_regs_count,
1864 c_regs, c_regs_count, in_imgs, in_imgs_count);
1869 ST(0) = sv_newmortal();
1870 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1871 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1875 i_contrast(im,intensity)
1884 i_noise(im,amount,type)
1890 i_bumpmap(im,bump,channel,light_x,light_y,strength)
1899 i_postlevels(im,levels)
1909 i_watermark(im,wmark,tx,ty,pixdiff)
1911 Imager::ImgRaw wmark
1918 i_autolevels(im,lsat,usat,skew)
1925 i_radnoise(im,xo,yo,rscale,ascale)
1933 i_turbnoise(im, xo, yo, scale)
1956 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
1957 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1958 croak("i_gradgen: Second argument must be an array ref");
1959 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1960 croak("i_gradgen: Third argument must be an array ref");
1961 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1962 croak("i_gradgen: Fourth argument must be an array ref");
1963 axx = (AV *)SvRV(ST(1));
1964 ayy = (AV *)SvRV(ST(2));
1965 ac = (AV *)SvRV(ST(3));
1966 dmeasure = (int)SvIV(ST(4));
1968 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1969 num = num <= av_len(ac) ? num : av_len(ac);
1971 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
1972 xo = mymalloc( sizeof(int) * num );
1973 yo = mymalloc( sizeof(int) * num );
1974 ival = mymalloc( sizeof(i_color) * num );
1975 for(i = 0; i<num; i++) {
1976 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1977 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1978 sv = *av_fetch(ac, i, 0);
1979 if ( !sv_derived_from(sv, "Imager::Color") ) {
1980 free(axx); free(ayy); free(ac);
1981 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
1983 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1985 i_gradgen(im, num, xo, yo, ival, dmeasure);
1988 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
1998 double ssample_param
2002 i_fountain_seg *segs;
2004 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2005 croak("i_fountain: argument 11 must be an array ref");
2007 asegs = (AV *)SvRV(ST(10));
2008 segs = load_fount_segs(asegs, &count);
2009 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample,
2010 ssample_param, count, segs);
2014 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2023 double ssample_param
2027 i_fountain_seg *segs;
2029 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2030 croak("i_fountain: argument 11 must be an array ref");
2032 asegs = (AV *)SvRV(ST(9));
2033 segs = load_fount_segs(asegs, &count);
2034 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2035 super_sample, ssample_param, count, segs);
2049 errors = i_errors();
2051 while (errors[i].msg) {
2053 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2054 if (!av_store(av, 0, sv)) {
2057 sv = newSViv(errors[i].code);
2058 if (!av_store(av, 1, sv)) {
2061 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
2066 i_nearest_color(im, ...)
2081 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
2082 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2083 croak("i_nearest_color: Second argument must be an array ref");
2084 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
2085 croak("i_nearest_color: Third argument must be an array ref");
2086 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
2087 croak("i_nearest_color: Fourth argument must be an array ref");
2088 axx = (AV *)SvRV(ST(1));
2089 ayy = (AV *)SvRV(ST(2));
2090 ac = (AV *)SvRV(ST(3));
2091 dmeasure = (int)SvIV(ST(4));
2093 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
2094 num = num <= av_len(ac) ? num : av_len(ac);
2096 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
2097 xo = mymalloc( sizeof(int) * num );
2098 yo = mymalloc( sizeof(int) * num );
2099 ival = mymalloc( sizeof(i_color) * num );
2100 for(i = 0; i<num; i++) {
2101 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
2102 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
2103 sv = *av_fetch(ac, i, 0);
2104 if ( !sv_derived_from(sv, "Imager::Color") ) {
2105 free(axx); free(ayy); free(ac);
2106 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
2108 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
2110 i_nearest_color(im, num, xo, yo, ival, dmeasure);
2124 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
2125 hv=(HV*)SvRV(ST(0));
2126 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
2127 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2128 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
2137 rc=DSO_open(filename,&evstr);
2141 PUSHs(sv_2mortal(newSViv((IV)rc)));
2142 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
2145 PUSHs(sv_2mortal(newSViv((IV)rc)));
2151 DSO_close(dso_handle)
2155 DSO_funclist(dso_handle_v)
2159 DSO_handle *dso_handle;
2161 dso_handle=(DSO_handle*)dso_handle_v;
2163 while( dso_handle->function_list[i].name != NULL) {
2165 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
2167 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
2172 DSO_call(handle,func_index,hv)
2178 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
2179 hv=(HV*)SvRV(ST(2));
2180 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
2181 DSO_call( (DSO_handle *)handle,func_index,hv);
2185 # this is mostly for testing...
2187 i_get_pixel(im, x, y)
2194 color = (i_color *)mymalloc(sizeof(i_color));
2195 if (i_gpix(im, x, y, color) == 0) {
2196 ST(0) = sv_newmortal();
2197 sv_setref_pv(ST(0), "Imager::Color", (void *)color);
2201 ST(0) = &PL_sv_undef;
2206 i_ppix(im, x, y, cl)
2213 i_img_pal_new(x, y, channels, maxpal)
2220 i_img_to_pal(src, quant)
2226 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
2227 croak("i_img_to_pal: second argument must be a hash ref");
2228 hv = (HV *)SvRV(ST(1));
2229 memset(&quant, 0, sizeof(quant));
2230 quant.mc_size = 256;
2231 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
2232 handle_quant_opts(&quant, hv);
2233 RETVAL = i_img_to_pal(src, &quant);
2235 copy_colors_back(hv, &quant);
2237 myfree(quant.mc_colors);
2256 work = mymalloc((r-l) * sizeof(i_palidx));
2257 count = i_gpal(im, l, r, y, work);
2258 if (GIMME_V == G_ARRAY) {
2260 for (i = 0; i < count; ++i) {
2261 PUSHs(sv_2mortal(newSViv(work[i])));
2266 PUSHs(sv_2mortal(newSVpv(work, count * sizeof(i_palidx))));
2271 if (GIMME_V != G_ARRAY) {
2273 PUSHs(&PL_sv_undef);
2278 i_ppal(im, l, y, ...)
2287 work = mymalloc(sizeof(i_palidx) * (items-3));
2288 for (i=0; i < items-3; ++i) {
2289 work[i] = SvIV(ST(i+3));
2291 RETVAL = i_ppal(im, l, l+items-3, y, work);
2301 i_addcolors(im, ...)
2309 croak("i_addcolors: no colors to add");
2310 colors = mymalloc((items-1) * sizeof(i_color));
2311 for (i=0; i < items-1; ++i) {
2312 if (sv_isobject(ST(i+1))
2313 && sv_derived_from(ST(i+1), "Imager::Color")) {
2314 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
2315 colors[i] = *(i_color *)tmp;
2319 croak("i_plin: pixels must be Imager::Color objects");
2322 index = i_addcolors(im, colors, items-1);
2325 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2327 else if (index == -1) {
2328 ST(0) = &PL_sv_undef;
2331 ST(0) = sv_2mortal(newSViv(index));
2335 i_setcolors(im, index, ...)
2343 croak("i_setcolors: no colors to add");
2344 colors = mymalloc((items-2) * sizeof(i_color));
2345 for (i=0; i < items-2; ++i) {
2346 if (sv_isobject(ST(i+2))
2347 && sv_derived_from(ST(i+2), "Imager::Color")) {
2348 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
2349 colors[i] = *(i_color *)tmp;
2353 croak("i_setcolors: pixels must be Imager::Color objects");
2356 RETVAL = i_setcolors(im, index, colors, items-2);
2360 i_getcolors(im, index, ...)
2369 croak("i_getcolors: too many arguments");
2371 count = SvIV(ST(2));
2373 croak("i_getcolors: count must be positive");
2374 colors = mymalloc(sizeof(i_color) * count);
2375 if (i_getcolors(im, index, colors, count)) {
2376 for (i = 0; i < count; ++i) {
2378 SV *sv = sv_newmortal();
2379 pv = mymalloc(sizeof(i_color));
2381 sv_setref_pv(sv, "Imager::Color", (void *)pv);
2394 count = i_colorcount(im);
2396 ST(0) = sv_2mortal(newSViv(count));
2399 ST(0) = &PL_sv_undef;
2408 count = i_maxcolors(im);
2410 ST(0) = sv_2mortal(newSViv(count));
2413 ST(0) = &PL_sv_undef;
2417 i_findcolor(im, color)
2423 if (i_findcolor(im, color, &index)) {
2424 ST(0) = sv_2mortal(newSViv(index));
2427 ST(0) = &PL_sv_undef;
2443 i_gsamp(im, l, r, y, ...)
2455 croak("No channel numbers supplied to g_samp()");
2457 chan_count = items - 4;
2458 chans = mymalloc(sizeof(int) * chan_count);
2459 for (i = 0; i < chan_count; ++i)
2460 chans[i] = SvIV(ST(i+4));
2461 data = mymalloc(sizeof(i_sample_t) * (r-l) * chan_count);
2462 count = i_gsamp(im, l, r, y, data, chans, chan_count);
2463 if (GIMME_V == G_ARRAY) {
2465 for (i = 0; i < count; ++i)
2466 PUSHs(sv_2mortal(newSViv(data[i])));
2470 PUSHs(sv_2mortal(newSVpv(data, count * sizeof(i_sample_t))));
2474 if (GIMME_V != G_ARRAY) {
2476 PUSHs(&PL_sv_undef);
2481 i_img_masked_new(targ, mask, x, y, w, h)
2491 if (!sv_isobject(ST(1))
2492 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
2493 croak("i_img_masked_new: parameter 2 must undef or an image");
2495 mask = (i_img *)SvIV((SV *)SvRV(ST(1)));
2499 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
2504 i_plin(im, l, y, ...)
2513 work = mymalloc(sizeof(i_color) * (items-3));
2514 for (i=0; i < items-3; ++i) {
2515 if (sv_isobject(ST(i+3))
2516 && sv_derived_from(ST(i+3), "Imager::Color")) {
2517 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2518 work[i] = *(i_color *)tmp;
2522 croak("i_plin: pixels must be Imager::Color objects");
2526 RETVAL = i_plin(im, l, l+items-3, y, work);
2536 i_ppixf(im, x, y, cl)
2540 Imager::Color::Float cl
2543 i_gsampf(im, l, r, y, ...)
2555 croak("No channel numbers supplied to g_sampf()");
2557 chan_count = items - 4;
2558 chans = mymalloc(sizeof(int) * chan_count);
2559 for (i = 0; i < chan_count; ++i)
2560 chans[i] = SvIV(ST(i+4));
2561 data = mymalloc(sizeof(i_fsample_t) * (r-l) * chan_count);
2562 count = i_gsampf(im, l, r, y, data, chans, chan_count);
2563 if (GIMME_V == G_ARRAY) {
2565 for (i = 0; i < count; ++i)
2566 PUSHs(sv_2mortal(newSVnv(data[i])));
2570 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
2574 if (GIMME_V != G_ARRAY) {
2576 PUSHs(&PL_sv_undef);
2581 i_plinf(im, l, y, ...)
2590 work = mymalloc(sizeof(i_fcolor) * (items-3));
2591 for (i=0; i < items-3; ++i) {
2592 if (sv_isobject(ST(i+3))
2593 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
2594 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
2595 work[i] = *(i_fcolor *)tmp;
2599 croak("i_plin: pixels must be Imager::Color::Float objects");
2603 RETVAL = i_plinf(im, l, l+items-3, y, work);
2620 color = (i_fcolor *)mymalloc(sizeof(i_fcolor));
2621 if (i_gpixf(im, x, y, color) == 0) {
2622 ST(0) = sv_newmortal();
2623 sv_setref_pv(ST(0), "Imager::Color::Float", (void *)color);
2627 ST(0) = &PL_sv_undef;
2641 vals = mymalloc((r-l) * sizeof(i_color));
2642 count = i_glin(im, l, r, y, vals);
2644 for (i = 0; i < count; ++i) {
2646 i_color *col = mymalloc(sizeof(i_color));
2647 sv = sv_newmortal();
2648 sv_setref_pv(sv, "Imager::Color", (void *)col);
2655 i_glinf(im, l, r, y)
2665 vals = mymalloc((r-l) * sizeof(i_fcolor));
2666 count = i_glinf(im, l, r, y, vals);
2668 for (i = 0; i < count; ++i) {
2670 i_fcolor *col = mymalloc(sizeof(i_fcolor));
2672 sv = sv_newmortal();
2673 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
2680 i_img_16_new(x, y, ch)
2686 i_tags_addn(im, name, code, idata)
2695 name = SvPV(ST(1), len);
2698 RETVAL = i_tags_addn(&im->tags, name, code, idata);
2703 i_tags_add(im, name, code, data, idata)
2713 name = SvPV(ST(1), len);
2717 data = SvPV(ST(3), len);
2722 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
2727 i_tags_find(im, name, start)
2734 if (i_tags_find(&im->tags, name, start, &entry)) {
2736 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2738 ST(0) = sv_2mortal(newSViv(entry));
2740 ST(0) = &PL_sv_undef;
2744 i_tags_findn(im, code, start)
2751 if (i_tags_findn(&im->tags, code, start, &entry)) {
2753 ST(0) = sv_2mortal(newSVpv("0 but true", 0));
2755 ST(0) = sv_2mortal(newSViv(entry));
2758 ST(0) = &PL_sv_undef;
2761 i_tags_delete(im, entry)
2765 RETVAL = i_tags_delete(&im->tags, entry);
2770 i_tags_delbyname(im, name)
2774 RETVAL = i_tags_delbyname(&im->tags, name);
2779 i_tags_delbycode(im, code)
2783 RETVAL = i_tags_delbycode(&im->tags, code);
2788 i_tags_get(im, index)
2792 if (index >= 0 && index < im->tags.count) {
2793 i_img_tag *entry = im->tags.tags + index;
2797 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
2800 PUSHs(sv_2mortal(newSViv(entry->code)));
2803 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
2806 PUSHs(sv_2mortal(newSViv(entry->idata)));
2814 RETVAL = im->tags.count;
2821 i_wf_bbox(face, size, text)
2828 if (i_wf_bbox(face, size, text, strlen(text), cords)) {
2830 PUSHs(sv_2mortal(newSViv(cords[0])));
2831 PUSHs(sv_2mortal(newSViv(cords[1])));
2832 PUSHs(sv_2mortal(newSViv(cords[2])));
2833 PUSHs(sv_2mortal(newSViv(cords[3])));
2834 PUSHs(sv_2mortal(newSViv(cords[4])));
2835 PUSHs(sv_2mortal(newSViv(cords[5])));
2839 i_wf_text(face, im, tx, ty, cl, size, text, align, aa)
2850 RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, strlen(text),
2856 i_wf_cp(face, im, tx, ty, channel, size, text, align, aa)
2867 RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, strlen(text),
2877 MODULE = Imager PACKAGE = Imager::Font::FT2 PREFIX=FT2_
2879 #define FT2_DESTROY(font) i_ft2_destroy(font)
2883 Imager::Font::FT2 font
2885 MODULE = Imager PACKAGE = Imager::Font::FreeType2
2888 i_ft2_new(name, index)
2893 i_ft2_setdpi(font, xdpi, ydpi)
2894 Imager::Font::FT2 font
2900 Imager::Font::FT2 font
2904 if (i_ft2_getdpi(font, &xdpi, &ydpi)) {
2906 PUSHs(sv_2mortal(newSViv(xdpi)));
2907 PUSHs(sv_2mortal(newSViv(ydpi)));
2911 i_ft2_sethinting(font, hinting)
2912 Imager::Font::FT2 font
2916 i_ft2_settransform(font, matrix)
2917 Imager::Font::FT2 font
2925 if (!SvROK(ST(1)) || SvTYPE(SvRV(ST(1))) != SVt_PVAV)
2926 croak("i_ft2_settransform: parameter 2 must be an array ref\n");
2927 av=(AV*)SvRV(ST(1));
2931 for (i = 0; i < len; ++i) {
2932 sv1=(*(av_fetch(av,i,0)));
2933 matrix[i] = SvNV(sv1);
2937 RETVAL = i_ft2_settransform(font, matrix);
2942 i_ft2_bbox(font, cheight, cwidth, text)
2943 Imager::Font::FT2 font
2951 if (i_ft2_bbox(font, cheight, cwidth, text, strlen(text), bbox)) {
2953 for (i = 0; i < 6; ++i)
2954 PUSHs(sv_2mortal(newSViv(bbox[i])));
2958 i_ft2_bbox_r(font, cheight, cwidth, text, vlayout, utf8)
2959 Imager::Font::FT2 font
2973 if (i_ft2_bbox_r(font, cheight, cwidth, text, strlen(text), vlayout,
2976 for (i = 0; i < 8; ++i)
2977 PUSHs(sv_2mortal(newSViv(bbox[i])));
2981 i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text, align, aa, vlayout, utf8)
2982 Imager::Font::FT2 font
2998 if (SvUTF8(ST(7))) {
3002 text = SvPV(ST(7), len);
3003 RETVAL = i_ft2_text(font, im, tx, ty, cl, cheight, cwidth, text,
3004 len, align, aa, vlayout, utf8);
3009 i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text, align, aa, vlayout, utf8)
3010 Imager::Font::FT2 font
3027 RETVAL = i_ft2_cp(font, im, tx, ty, channel, cheight, cwidth, text,
3028 strlen(text), align, aa, vlayout, 1);
3033 ft2_transform_box(font, x0, x1, x2, x3)
3034 Imager::Font::FT2 font
3042 box[0] = x0; box[1] = x1; box[2] = x2; box[3] = x3;
3043 ft2_transform_box(font, box);
3045 PUSHs(sv_2mortal(newSViv(box[0])));
3046 PUSHs(sv_2mortal(newSViv(box[1])));
3047 PUSHs(sv_2mortal(newSViv(box[2])));
3048 PUSHs(sv_2mortal(newSViv(box[3])));
3052 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3056 Imager::FillHandle fill
3058 MODULE = Imager PACKAGE = Imager
3061 i_new_fill_solid(cl, combine)
3066 i_new_fill_solidf(cl, combine)
3067 Imager::Color::Float cl
3071 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
3079 unsigned char *cust_hatch;
3083 cust_hatch = SvPV(ST(4), len);
3087 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);