17 typedef io_glue* Imager__IO;
18 typedef i_color* Imager__Color;
19 typedef i_img* Imager__ImgRaw;
23 typedef TT_Fonthandle* Imager__TTHandle;
26 typedef struct i_reader_data_tag
28 /* presumably a CODE ref or name of a sub */
32 /* used by functions that want callbacks */
33 static int read_callback(char *userdata, char *buffer, int need, int want) {
34 i_reader_data *rd = (i_reader_data *)userdata;
38 dSP; dTARG = sv_newmortal();
39 /* thanks to Simon Cozens for help with the dTARG above */
49 count = perl_call_sv(rd->sv, G_SCALAR);
54 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
60 char *ptr = SvPV(data, len);
62 croak("Too much data returned in reader callback");
64 memcpy(buffer, ptr, len);
80 SV *sv; /* a coderef or sub name */
83 /* used by functions that want callbacks */
84 static int write_callback(char *userdata, char const *data, int size) {
85 i_writer_data *wd = (i_writer_data *)userdata;
95 XPUSHs(sv_2mortal(newSVpv((char *)data, size)));
98 count = perl_call_sv(wd->sv, G_SCALAR);
103 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
106 success = SvTRUE(sv);
120 static int lookup_name(struct value_name *names, int count, char *name, int def_value)
123 for (i = 0; i < count; ++i)
124 if (strEQ(names[i].name, name))
125 return names[i].value;
129 static struct value_name transp_names[] =
132 { "threshold", tr_threshold },
133 { "errdiff", tr_errdiff },
134 { "ordered", tr_ordered, },
137 static struct value_name make_color_names[] =
139 { "none", mc_none, },
140 { "webmap", mc_web_map, },
141 { "addi", mc_addi, },
144 static struct value_name translate_names[] =
147 { "giflib", pt_giflib, },
149 { "closest", pt_closest, },
150 { "perturb", pt_perturb, },
151 { "errdiff", pt_errdiff, },
154 static struct value_name errdiff_names[] =
156 { "floyd", ed_floyd, },
157 { "jarvis", ed_jarvis, },
158 { "stucki", ed_stucki, },
159 { "custom", ed_custom, },
162 static struct value_name orddith_names[] =
164 { "random", od_random, },
165 { "dot8", od_dot8, },
166 { "dot4", od_dot4, },
167 { "hline", od_hline, },
168 { "vline", od_vline, },
169 { "/line", od_slashline, },
170 { "slashline", od_slashline, },
171 { "\\line", od_backline, },
172 { "backline", od_backline, },
173 { "custom", od_custom, },
176 /* look through the hash for quantization options */
177 static void handle_quant_opts(i_quantize *quant, HV *hv)
179 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
185 sv = hv_fetch(hv, "transp", 6, 0);
186 if (sv && *sv && (str = SvPV(*sv, len))) {
188 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
190 if (quant->transp != tr_none) {
191 quant->tr_threshold = 127;
192 sv = hv_fetch(hv, "tr_threshold", 12, 0);
194 quant->tr_threshold = SvIV(*sv);
196 if (quant->transp == tr_errdiff) {
197 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
198 if (sv && *sv && (str = SvPV(*sv, len)))
199 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
201 if (quant->transp == tr_ordered) {
202 quant->tr_orddith = od_random;
203 sv = hv_fetch(hv, "tr_orddith", 10, 0);
204 if (sv && *sv && (str = SvPV(*sv, len)))
205 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
207 if (quant->tr_orddith == od_custom) {
208 sv = hv_fetch(hv, "tr_map", 6, 0);
209 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
210 AV *av = (AV*)SvRV(*sv);
211 len = av_len(av) + 1;
212 if (len > sizeof(quant->tr_custom))
213 len = sizeof(quant->tr_custom);
214 for (i = 0; i < len; ++i) {
215 SV **sv2 = av_fetch(av, i, 0);
217 quant->tr_custom[i] = SvIV(*sv2);
220 while (i < sizeof(quant->tr_custom))
221 quant->tr_custom[i++] = 0;
226 quant->make_colors = mc_addi;
227 sv = hv_fetch(hv, "make_colors", 11, 0);
228 if (sv && *sv && (str = SvPV(*sv, len))) {
230 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
232 sv = hv_fetch(hv, "colors", 6, 0);
233 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
234 /* needs to be an array of Imager::Color
235 note that the caller allocates the mc_color array and sets mc_size
237 AV *av = (AV *)SvRV(*sv);
238 quant->mc_count = av_len(av)+1;
239 if (quant->mc_count > quant->mc_size)
240 quant->mc_count = quant->mc_size;
241 for (i = 0; i < quant->mc_count; ++i) {
242 SV **sv1 = av_fetch(av, i, 0);
243 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
244 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
245 quant->mc_colors[i] = *col;
249 sv = hv_fetch(hv, "max_colors", 10, 0);
252 if (i <= quant->mc_size && i >= quant->mc_count)
256 quant->translate = pt_closest;
257 sv = hv_fetch(hv, "translate", 9, 0);
258 if (sv && *sv && (str = SvPV(*sv, len))) {
259 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
261 sv = hv_fetch(hv, "errdiff", 7, 0);
262 if (sv && *sv && (str = SvPV(*sv, len))) {
263 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
265 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
266 /* get the error diffusion map */
267 sv = hv_fetch(hv, "errdiff_width", 13, 0);
269 quant->ed_width = SvIV(*sv);
270 sv = hv_fetch(hv, "errdiff_height", 14, 0);
272 quant->ed_height = SvIV(*sv);
273 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
275 quant->ed_orig = SvIV(*sv);
276 if (quant->ed_width > 0 && quant->ed_height > 0) {
278 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
279 sv = hv_fetch(hv, "errdiff_map", 11, 0);
280 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
281 AV *av = (AV*)SvRV(*sv);
282 len = av_len(av) + 1;
283 if (len > quant->ed_width * quant->ed_height)
284 len = quant->ed_width * quant->ed_height;
285 for (i = 0; i < len; ++i) {
286 SV **sv2 = av_fetch(av, i, 0);
288 quant->ed_map[i] = SvIV(*sv2);
289 sum += quant->ed_map[i];
295 myfree(quant->ed_map);
297 quant->errdiff = ed_floyd;
301 sv = hv_fetch(hv, "perturb", 7, 0);
303 quant->perturb = SvIV(*sv);
306 /* look through the hash for options to add to opts */
307 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
309 /*** FIXME: POSSIBLY BROKEN: do I need to unref the SV from hv_fetch? ***/
312 /**((char *)0) = '\0';*/
313 sv = hv_fetch(hv, "gif_each_palette", 16, 0);
315 opts->each_palette = SvIV(*sv);
316 sv = hv_fetch(hv, "interlace", 9, 0);
318 opts->interlace = SvIV(*sv);
319 sv = hv_fetch(hv, "gif_delays", 10, 0);
320 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
321 AV *av = (AV*)SvRV(*sv);
322 opts->delay_count = av_len(av)+1;
323 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
324 for (i = 0; i < opts->delay_count; ++i) {
325 SV *sv1 = *av_fetch(av, i, 0);
326 opts->delays[i] = SvIV(sv1);
329 sv = hv_fetch(hv, "gif_user_input", 14, 0);
330 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
331 AV *av = (AV*)SvRV(*sv);
332 opts->user_input_count = av_len(av)+1;
333 opts->user_input_flags = mymalloc(opts->user_input_count);
334 for (i = 0; i < opts->user_input_count; ++i) {
335 SV *sv1 = *av_fetch(av, i, 0);
336 opts->user_input_flags[i] = SvIV(sv1) != 0;
339 sv = hv_fetch(hv, "gif_disposal", 12, 0);
340 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
341 AV *av = (AV*)SvRV(*sv);
342 opts->disposal_count = av_len(av)+1;
343 opts->disposal = mymalloc(opts->disposal_count);
344 for (i = 0; i < opts->disposal_count; ++i) {
345 SV *sv1 = *av_fetch(av, i, 0);
346 opts->disposal[i] = SvIV(sv1);
349 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
350 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
351 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
352 opts->tran_color = *col;
354 sv = hv_fetch(hv, "gif_positions", 13, 0);
355 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
356 AV *av = (AV *)SvRV(*sv);
357 opts->position_count = av_len(av) + 1;
358 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
359 for (i = 0; i < opts->position_count; ++i) {
360 SV **sv2 = av_fetch(av, i, 0);
361 opts->positions[i].x = opts->positions[i].y = 0;
362 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
363 AV *av2 = (AV*)SvRV(*sv2);
365 sv3 = av_fetch(av2, 0, 0);
367 opts->positions[i].x = SvIV(*sv3);
368 sv3 = av_fetch(av2, 1, 0);
370 opts->positions[i].y = SvIV(*sv3);
374 /* Netscape2.0 loop count extension */
375 sv = hv_fetch(hv, "gif_loop_count", 14, 0);
377 opts->loop_count = SvIV(*sv);
380 /* copies the color map from the hv into the colors member of the HV */
381 static void copy_colors_back(HV *hv, i_quantize *quant) {
387 sv = hv_fetch(hv, "colors", 6, 0);
388 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
391 ref = newRV_inc((SV*) av);
392 sv = hv_store(hv, "colors", 6, ref, 0);
395 av = (AV *)SvRV(*sv);
397 av_extend(av, quant->mc_count+1);
398 for (i = 0; i < quant->mc_count; ++i) {
399 i_color *in = quant->mc_colors+i;
400 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
401 work = sv_newmortal();
402 sv_setref_pv(work, "Imager::Color", (void *)c);
404 if (!av_store(av, i, work)) {
410 /* used to make the typemap happy */
413 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
416 ICL_new_internal(r,g,b,a)
428 ICL_set_internal(cl,r,g,b,a)
446 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
447 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
448 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
449 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
457 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
471 MODULE = Imager PACKAGE = Imager
493 tlength = io_slurp(ig, &data);
496 PUSHs(sv_2mortal(newSVpv(data,tlength)));
508 while( (item=i_format_list[i++]) != NULL ) {
510 PUSHs(sv_2mortal(newSVpv(item,0)));
527 i_img_empty_ch(im,x,y,ch)
554 PUSHs(sv_2mortal(newSViv(info[0])));
555 PUSHs(sv_2mortal(newSViv(info[1])));
556 PUSHs(sv_2mortal(newSViv(info[2])));
557 PUSHs(sv_2mortal(newSViv(info[3])));
563 i_img_setmask(im,ch_mask)
572 i_img_getchannels(im)
580 PUSHs(sv_2mortal(newSVpv(im->data, im->bytes)));
584 i_draw(im,x1,y1,x2,y2,val)
593 i_line_aa(im,x1,y1,x2,y2,val)
602 i_box(im,x1,y1,x2,y2,val)
611 i_box_filled(im,x1,y1,x2,y2,val)
620 i_arc(im,x,y,rad,d1,d2,val)
632 i_bezier_multi(im,xc,yc,val)
645 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
646 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
647 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
648 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
649 av1=(AV*)SvRV(ST(1));
650 av2=(AV*)SvRV(ST(2));
651 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
653 x=mymalloc( len*sizeof(double) );
654 y=mymalloc( len*sizeof(double) );
656 sv1=(*(av_fetch(av1,i,0)));
657 sv2=(*(av_fetch(av2,i,0)));
658 x[i]=(double)SvNV(sv1);
659 y[i]=(double)SvNV(sv2);
661 i_bezier_multi(im,len,x,y,val);
667 i_poly_aa(im,xc,yc,val)
680 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
681 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
682 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
683 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
684 av1=(AV*)SvRV(ST(1));
685 av2=(AV*)SvRV(ST(2));
686 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
688 x=mymalloc( len*sizeof(double) );
689 y=mymalloc( len*sizeof(double) );
691 sv1=(*(av_fetch(av1,i,0)));
692 sv2=(*(av_fetch(av2,i,0)));
693 x[i]=(double)SvNV(sv1);
694 y[i]=(double)SvNV(sv2);
696 i_poly_aa(im,len,x,y,val);
703 i_flood_fill(im,seedx,seedy,dcol)
711 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
723 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
741 i_rubthru(im,src,tx,ty)
763 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
764 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
767 coeff=mymalloc( len*sizeof(float) );
769 sv1=(*(av_fetch(av,i,0)));
770 coeff[i]=(float)SvNV(sv1);
772 i_conv(im,coeff,len);
793 i_t1_new(pfb,afm=NULL)
798 i_t1_destroy(font_id)
803 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
815 i_t1_bbox(fontnum,point,str,len)
823 i_t1_bbox(fontnum,point,str,len,cords);
825 PUSHs(sv_2mortal(newSViv(cords[0])));
826 PUSHs(sv_2mortal(newSViv(cords[1])));
827 PUSHs(sv_2mortal(newSViv(cords[2])));
828 PUSHs(sv_2mortal(newSViv(cords[3])));
829 PUSHs(sv_2mortal(newSViv(cords[4])));
830 PUSHs(sv_2mortal(newSViv(cords[5])));
835 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
857 Imager::TTHandle handle
862 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
863 Imager::TTHandle handle
875 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
876 Imager::TTHandle handle
889 i_tt_bbox(handle,point,str,len)
890 Imager::TTHandle handle
897 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
899 PUSHs(sv_2mortal(newSViv(cords[0])));
900 PUSHs(sv_2mortal(newSViv(cords[1])));
901 PUSHs(sv_2mortal(newSViv(cords[2])));
902 PUSHs(sv_2mortal(newSViv(cords[3])));
903 PUSHs(sv_2mortal(newSViv(cords[4])));
904 PUSHs(sv_2mortal(newSViv(cords[5])));
915 i_writejpeg(im,fd,qfactor)
930 rimg=i_readjpeg(fd,&iptc_itext,&tlength);
931 if (iptc_itext == NULL) {
934 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
939 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
941 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
947 i_readjpeg_scalar(...)
958 data = (char *)SvPV(ST(0), length);
959 rimg=i_readjpeg_scalar(data,length,&iptc_itext,&tlength);
960 mm_log((1,"i_readjpeg_scalar: 0x%08X\n",rimg));
961 if (iptc_itext == NULL) {
964 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
969 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
971 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
986 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
987 if (iptc_itext == NULL) {
990 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
995 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
997 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1010 i_readtiff_wiol(ig, length)
1016 i_writetiff_wiol(im, ig)
1021 #endif /* HAVE_LIBTIFF */
1041 i_readpng_scalar(...)
1045 unsigned int length;
1047 data = (char *)SvPV(ST(0), length);
1048 RETVAL=i_readpng_scalar(data,length);
1060 i_writegif(im,fd,colors,pixdev,fixed)
1067 Imager__Color fixed;
1074 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1075 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1076 av=(AV*)SvRV(ST(4));
1077 fixedlen=av_len(av)+1;
1078 fixed=mymalloc( fixedlen*sizeof(i_color) );
1079 for(i=0;i<fixedlen;i++) {
1080 sv1=(*(av_fetch(av,i,0)));
1081 if (sv_derived_from(sv1, "Imager::Color")) {
1082 Itmp = SvIV((SV*)SvRV(sv1));
1083 tmp = (i_color*) Itmp;
1084 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1087 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1089 ST(0) = sv_newmortal();
1090 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1091 else sv_setiv(ST(0), (IV)RETVAL);
1097 i_writegifmc(im,fd,colors)
1108 i_writegif_gen(fd, ...)
1114 i_img **imgs = NULL;
1120 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1121 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1122 croak("i_writegif_gen: Second argument must be a hash ref");
1123 hv = (HV *)SvRV(ST(1));
1124 memset(&quant, 0, sizeof(quant));
1125 quant.mc_size = 256;
1126 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1127 memset(&opts, 0, sizeof(opts));
1128 handle_quant_opts(&quant, hv);
1129 handle_gif_opts(&opts, hv);
1130 img_count = items - 2;
1132 if (img_count < 1) {
1136 imgs = mymalloc(sizeof(i_img *) * img_count);
1137 for (i = 0; i < img_count; ++i) {
1140 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1141 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1149 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1153 copy_colors_back(hv, &quant);
1156 ST(0) = sv_newmortal();
1157 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1158 else sv_setiv(ST(0), (IV)RETVAL);
1161 i_writegif_callback(cb, maxbuffer,...)
1166 i_img **imgs = NULL;
1173 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1174 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1175 croak("i_writegif_callback: Second argument must be a hash ref");
1176 hv = (HV *)SvRV(ST(2));
1177 memset(&quant, 0, sizeof(quant));
1178 quant.mc_size = 256;
1179 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1180 memset(&opts, 0, sizeof(opts));
1181 handle_quant_opts(&quant, hv);
1182 handle_gif_opts(&opts, hv);
1183 img_count = items - 3;
1185 if (img_count < 1) {
1189 imgs = mymalloc(sizeof(i_img *) * img_count);
1190 for (i = 0; i < img_count; ++i) {
1193 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1194 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1203 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1207 copy_colors_back(hv, &quant);
1210 ST(0) = sv_newmortal();
1211 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1212 else sv_setiv(ST(0), (IV)RETVAL);
1225 colour_table = NULL;
1228 if(GIMME_V == G_ARRAY) {
1229 rimg = i_readgif(fd,&colour_table,&colours);
1231 /* don't waste time with colours if they aren't wanted */
1232 rimg = i_readgif(fd,NULL,NULL);
1235 if (colour_table == NULL) {
1238 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1241 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1242 /* I don't know if I have the reference counts right or not :( */
1243 /* Neither do I :-) */
1244 /* No Idea here either */
1247 av_extend(ct, colours);
1248 for(q=0; q<colours; q++) {
1250 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1251 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1253 myfree(colour_table);
1257 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1259 PUSHs(newRV_noinc((SV*)ct));
1267 i_readgif_scalar(...)
1271 unsigned int length;
1279 data = (char *)SvPV(ST(0), length);
1283 if(GIMME_V == G_ARRAY) {
1284 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1286 /* don't waste time with colours if they aren't wanted */
1287 rimg=i_readgif_scalar(data,length,NULL,NULL);
1290 if (colour_table == NULL) {
1293 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1296 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1297 /* I don't know if I have the reference counts right or not :( */
1298 /* Neither do I :-) */
1300 av_extend(ct, colours);
1301 for(q=0; q<colours; q++) {
1303 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1304 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1306 myfree(colour_table);
1310 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1312 PUSHs(newRV_noinc((SV*)ct));
1316 i_readgif_callback(...)
1333 if(GIMME_V == G_ARRAY) {
1334 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1336 /* don't waste time with colours if they aren't wanted */
1337 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1340 if (colour_table == NULL) {
1343 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1346 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1347 /* I don't know if I have the reference counts right or not :( */
1348 /* Neither do I :-) */
1349 /* Neither do I - maybe I'll move this somewhere */
1351 av_extend(ct, colours);
1352 for(q=0; q<colours; q++) {
1354 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1355 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1357 myfree(colour_table);
1361 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1363 PUSHs(newRV_noinc((SV*)ct));
1376 i_readpnm_wiol(ig, length)
1387 i_readraw(fd,x,y,datachannels,storechannels,intrl)
1402 i_scaleaxis(im,Value,Axis)
1408 i_scale_nn(im,scx,scy)
1418 i_count_colors(im,maxc)
1424 i_transform(im,opx,opy,parm)
1437 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1438 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1439 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1440 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1441 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1442 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1443 av=(AV*)SvRV(ST(1));
1445 opx=mymalloc( opxl*sizeof(int) );
1446 for(i=0;i<opxl;i++) {
1447 sv1=(*(av_fetch(av,i,0)));
1448 opx[i]=(int)SvIV(sv1);
1450 av=(AV*)SvRV(ST(2));
1452 opy=mymalloc( opyl*sizeof(int) );
1453 for(i=0;i<opyl;i++) {
1454 sv1=(*(av_fetch(av,i,0)));
1455 opy[i]=(int)SvIV(sv1);
1457 av=(AV*)SvRV(ST(3));
1458 parmlen=av_len(av)+1;
1459 parm=mymalloc( parmlen*sizeof(double) );
1460 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1461 sv1=(*(av_fetch(av,i,0)));
1462 parm[i]=(double)SvNV(sv1);
1464 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1468 ST(0) = sv_newmortal();
1469 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1470 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1473 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1479 unsigned int ops_len;
1492 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1493 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1494 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1495 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1496 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1498 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1500 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1501 av = (AV*)SvRV(ST(5));
1502 in_imgs_count = av_len(av)+1;
1503 for (i = 0; i < in_imgs_count; ++i) {
1504 sv1 = *av_fetch(av, i, 0);
1505 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1506 croak("Parameter 5 must contain only images");
1513 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1514 av = (AV*)SvRV(ST(5));
1515 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1516 for (i = 0; i < in_imgs_count; ++i) {
1517 sv1 = *av_fetch(av,i,0);
1518 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1519 croak("Parameter 5 must contain only images");
1521 tmp = SvIV((SV*)SvRV(sv1));
1522 in_imgs[i] = (i_img*)tmp;
1526 /* no input images */
1529 /* default the output size from the first input if possible */
1531 width = SvIV(ST(0));
1532 else if (in_imgs_count)
1533 width = in_imgs[0]->xsize;
1535 croak("No output image width supplied");
1538 height = SvIV(ST(1));
1539 else if (in_imgs_count)
1540 height = in_imgs[0]->ysize;
1542 croak("No output image height supplied");
1544 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1545 if (ops_len % sizeof(struct rm_op))
1546 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1547 ops_count = ops_len / sizeof(struct rm_op);
1548 av = (AV*)SvRV(ST(3));
1549 n_regs_count = av_len(av)+1;
1550 n_regs = mymalloc(n_regs_count * sizeof(double));
1551 for (i = 0; i < n_regs_count; ++i) {
1552 sv1 = *av_fetch(av,i,0);
1554 n_regs[i] = SvNV(sv1);
1556 av = (AV*)SvRV(ST(4));
1557 c_regs_count = av_len(av)+1;
1558 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1559 /* I don't bother initializing the colou?r registers */
1561 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1562 n_regs, n_regs_count,
1563 c_regs, c_regs_count, in_imgs, in_imgs_count);
1568 ST(0) = sv_newmortal();
1569 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1570 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1574 i_contrast(im,intensity)
1583 i_noise(im,amount,type)
1589 i_bumpmap(im,bump,channel,light_x,light_y,strength)
1598 i_postlevels(im,levels)
1608 i_watermark(im,wmark,tx,ty,pixdiff)
1610 Imager::ImgRaw wmark
1617 i_autolevels(im,lsat,usat,skew)
1624 i_radnoise(im,xo,yo,rscale,ascale)
1632 i_turbnoise(im, xo, yo, scale)
1655 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
1656 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1657 croak("i_gradgen: Second argument must be an array ref");
1658 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1659 croak("i_gradgen: Third argument must be an array ref");
1660 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1661 croak("i_gradgen: Fourth argument must be an array ref");
1662 axx = (AV *)SvRV(ST(1));
1663 ayy = (AV *)SvRV(ST(2));
1664 ac = (AV *)SvRV(ST(3));
1665 dmeasure = (int)SvIV(ST(4));
1667 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1668 num = num <= av_len(ac) ? num : av_len(ac);
1670 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
1671 xo = mymalloc( sizeof(int) * num );
1672 yo = mymalloc( sizeof(int) * num );
1673 ival = mymalloc( sizeof(i_color) * num );
1674 for(i = 0; i<num; i++) {
1675 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1676 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1677 sv = *av_fetch(ac, i, 0);
1678 if ( !sv_derived_from(sv, "Imager::Color") ) {
1679 free(axx); free(ayy); free(ac);
1680 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
1682 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1684 i_gradgen(im, num, xo, yo, ival, dmeasure);
1694 i_nearest_color(im, ...)
1709 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
1710 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1711 croak("i_nearest_color: Second argument must be an array ref");
1712 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1713 croak("i_nearest_color: Third argument must be an array ref");
1714 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1715 croak("i_nearest_color: Fourth argument must be an array ref");
1716 axx = (AV *)SvRV(ST(1));
1717 ayy = (AV *)SvRV(ST(2));
1718 ac = (AV *)SvRV(ST(3));
1719 dmeasure = (int)SvIV(ST(4));
1721 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1722 num = num <= av_len(ac) ? num : av_len(ac);
1724 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
1725 xo = mymalloc( sizeof(int) * num );
1726 yo = mymalloc( sizeof(int) * num );
1727 ival = mymalloc( sizeof(i_color) * num );
1728 for(i = 0; i<num; i++) {
1729 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1730 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1731 sv = *av_fetch(ac, i, 0);
1732 if ( !sv_derived_from(sv, "Imager::Color") ) {
1733 free(axx); free(ayy); free(ac);
1734 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
1736 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1738 i_nearest_color(im, num, xo, yo, ival, dmeasure);
1752 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
1753 hv=(HV*)SvRV(ST(0));
1754 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
1755 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1756 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1765 rc=DSO_open(filename,&evstr);
1769 PUSHs(sv_2mortal(newSViv((IV)rc)));
1770 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
1773 PUSHs(sv_2mortal(newSViv((IV)rc)));
1779 DSO_close(dso_handle)
1783 DSO_funclist(dso_handle_v)
1787 DSO_handle *dso_handle;
1789 dso_handle=(DSO_handle*)dso_handle_v;
1791 while( dso_handle->function_list[i].name != NULL) {
1793 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
1795 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
1800 DSO_call(handle,func_index,hv)
1806 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
1807 hv=(HV*)SvRV(ST(2));
1808 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
1809 DSO_call( (DSO_handle *)handle,func_index,hv);