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 { "tiny", od_tiny, },
174 { "custom", od_custom, },
177 /* look through the hash for quantization options */
178 static void handle_quant_opts(i_quantize *quant, HV *hv)
180 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
186 sv = hv_fetch(hv, "transp", 6, 0);
187 if (sv && *sv && (str = SvPV(*sv, len))) {
189 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
191 if (quant->transp != tr_none) {
192 quant->tr_threshold = 127;
193 sv = hv_fetch(hv, "tr_threshold", 12, 0);
195 quant->tr_threshold = SvIV(*sv);
197 if (quant->transp == tr_errdiff) {
198 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
199 if (sv && *sv && (str = SvPV(*sv, len)))
200 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
202 if (quant->transp == tr_ordered) {
203 quant->tr_orddith = od_tiny;
204 sv = hv_fetch(hv, "tr_orddith", 10, 0);
205 if (sv && *sv && (str = SvPV(*sv, len)))
206 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
208 if (quant->tr_orddith == od_custom) {
209 sv = hv_fetch(hv, "tr_map", 6, 0);
210 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
211 AV *av = (AV*)SvRV(*sv);
212 len = av_len(av) + 1;
213 if (len > sizeof(quant->tr_custom))
214 len = sizeof(quant->tr_custom);
215 for (i = 0; i < len; ++i) {
216 SV **sv2 = av_fetch(av, i, 0);
218 quant->tr_custom[i] = SvIV(*sv2);
221 while (i < sizeof(quant->tr_custom))
222 quant->tr_custom[i++] = 0;
227 quant->make_colors = mc_addi;
228 sv = hv_fetch(hv, "make_colors", 11, 0);
229 if (sv && *sv && (str = SvPV(*sv, len))) {
231 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_addi);
233 sv = hv_fetch(hv, "colors", 6, 0);
234 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
235 /* needs to be an array of Imager::Color
236 note that the caller allocates the mc_color array and sets mc_size
238 AV *av = (AV *)SvRV(*sv);
239 quant->mc_count = av_len(av)+1;
240 if (quant->mc_count > quant->mc_size)
241 quant->mc_count = quant->mc_size;
242 for (i = 0; i < quant->mc_count; ++i) {
243 SV **sv1 = av_fetch(av, i, 0);
244 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
245 i_color *col = (i_color *)SvIV((SV*)SvRV(*sv1));
246 quant->mc_colors[i] = *col;
250 sv = hv_fetch(hv, "max_colors", 10, 0);
253 if (i <= quant->mc_size && i >= quant->mc_count)
257 quant->translate = pt_closest;
258 sv = hv_fetch(hv, "translate", 9, 0);
259 if (sv && *sv && (str = SvPV(*sv, len))) {
260 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
262 sv = hv_fetch(hv, "errdiff", 7, 0);
263 if (sv && *sv && (str = SvPV(*sv, len))) {
264 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
266 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
267 /* get the error diffusion map */
268 sv = hv_fetch(hv, "errdiff_width", 13, 0);
270 quant->ed_width = SvIV(*sv);
271 sv = hv_fetch(hv, "errdiff_height", 14, 0);
273 quant->ed_height = SvIV(*sv);
274 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
276 quant->ed_orig = SvIV(*sv);
277 if (quant->ed_width > 0 && quant->ed_height > 0) {
279 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
280 sv = hv_fetch(hv, "errdiff_map", 11, 0);
281 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
282 AV *av = (AV*)SvRV(*sv);
283 len = av_len(av) + 1;
284 if (len > quant->ed_width * quant->ed_height)
285 len = quant->ed_width * quant->ed_height;
286 for (i = 0; i < len; ++i) {
287 SV **sv2 = av_fetch(av, i, 0);
289 quant->ed_map[i] = SvIV(*sv2);
290 sum += quant->ed_map[i];
296 myfree(quant->ed_map);
298 quant->errdiff = ed_floyd;
302 sv = hv_fetch(hv, "perturb", 7, 0);
304 quant->perturb = SvIV(*sv);
307 /* look through the hash for options to add to opts */
308 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
310 /*** FIXME: POSSIBLY BROKEN: do I need to unref the SV from hv_fetch? ***/
313 /**((char *)0) = '\0';*/
314 sv = hv_fetch(hv, "gif_each_palette", 16, 0);
316 opts->each_palette = SvIV(*sv);
317 sv = hv_fetch(hv, "interlace", 9, 0);
319 opts->interlace = SvIV(*sv);
320 sv = hv_fetch(hv, "gif_delays", 10, 0);
321 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
322 AV *av = (AV*)SvRV(*sv);
323 opts->delay_count = av_len(av)+1;
324 opts->delays = mymalloc(sizeof(int) * opts->delay_count);
325 for (i = 0; i < opts->delay_count; ++i) {
326 SV *sv1 = *av_fetch(av, i, 0);
327 opts->delays[i] = SvIV(sv1);
330 sv = hv_fetch(hv, "gif_user_input", 14, 0);
331 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
332 AV *av = (AV*)SvRV(*sv);
333 opts->user_input_count = av_len(av)+1;
334 opts->user_input_flags = mymalloc(opts->user_input_count);
335 for (i = 0; i < opts->user_input_count; ++i) {
336 SV *sv1 = *av_fetch(av, i, 0);
337 opts->user_input_flags[i] = SvIV(sv1) != 0;
340 sv = hv_fetch(hv, "gif_disposal", 12, 0);
341 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
342 AV *av = (AV*)SvRV(*sv);
343 opts->disposal_count = av_len(av)+1;
344 opts->disposal = mymalloc(opts->disposal_count);
345 for (i = 0; i < opts->disposal_count; ++i) {
346 SV *sv1 = *av_fetch(av, i, 0);
347 opts->disposal[i] = SvIV(sv1);
350 sv = hv_fetch(hv, "gif_tran_color", 14, 0);
351 if (sv && *sv && SvROK(*sv) && sv_derived_from(*sv, "Imager::Color")) {
352 i_color *col = (i_color *)SvIV((SV *)SvRV(*sv));
353 opts->tran_color = *col;
355 sv = hv_fetch(hv, "gif_positions", 13, 0);
356 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
357 AV *av = (AV *)SvRV(*sv);
358 opts->position_count = av_len(av) + 1;
359 opts->positions = mymalloc(sizeof(i_gif_pos) * opts->position_count);
360 for (i = 0; i < opts->position_count; ++i) {
361 SV **sv2 = av_fetch(av, i, 0);
362 opts->positions[i].x = opts->positions[i].y = 0;
363 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
364 AV *av2 = (AV*)SvRV(*sv2);
366 sv3 = av_fetch(av2, 0, 0);
368 opts->positions[i].x = SvIV(*sv3);
369 sv3 = av_fetch(av2, 1, 0);
371 opts->positions[i].y = SvIV(*sv3);
375 /* Netscape2.0 loop count extension */
376 sv = hv_fetch(hv, "gif_loop_count", 14, 0);
378 opts->loop_count = SvIV(*sv);
381 /* copies the color map from the hv into the colors member of the HV */
382 static void copy_colors_back(HV *hv, i_quantize *quant) {
388 sv = hv_fetch(hv, "colors", 6, 0);
389 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
392 ref = newRV_inc((SV*) av);
393 sv = hv_store(hv, "colors", 6, ref, 0);
396 av = (AV *)SvRV(*sv);
398 av_extend(av, quant->mc_count+1);
399 for (i = 0; i < quant->mc_count; ++i) {
400 i_color *in = quant->mc_colors+i;
401 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
402 work = sv_newmortal();
403 sv_setref_pv(work, "Imager::Color", (void *)c);
405 if (!av_store(av, i, work)) {
411 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
414 ICL_new_internal(r,g,b,a)
426 ICL_set_internal(cl,r,g,b,a)
433 ICL_set_internal(cl, r, g, b, a);
447 PUSHs(sv_2mortal(newSVnv(cl->rgba.r)));
448 PUSHs(sv_2mortal(newSVnv(cl->rgba.g)));
449 PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
450 PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
458 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
472 MODULE = Imager PACKAGE = Imager
494 tlength = io_slurp(ig, &data);
497 PUSHs(sv_2mortal(newSVpv(data,tlength)));
509 while( (item=i_format_list[i++]) != NULL ) {
511 PUSHs(sv_2mortal(newSVpv(item,0)));
528 i_img_empty_ch(im,x,y,ch)
555 PUSHs(sv_2mortal(newSViv(info[0])));
556 PUSHs(sv_2mortal(newSViv(info[1])));
557 PUSHs(sv_2mortal(newSViv(info[2])));
558 PUSHs(sv_2mortal(newSViv(info[3])));
564 i_img_setmask(im,ch_mask)
573 i_img_getchannels(im)
581 PUSHs(sv_2mortal(newSVpv(im->data, im->bytes)));
585 i_draw(im,x1,y1,x2,y2,val)
594 i_line_aa(im,x1,y1,x2,y2,val)
603 i_box(im,x1,y1,x2,y2,val)
612 i_box_filled(im,x1,y1,x2,y2,val)
621 i_arc(im,x,y,rad,d1,d2,val)
633 i_bezier_multi(im,xc,yc,val)
646 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
647 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_bezier_multi must be a reference to an array\n");
648 if (!SvROK(ST(2))) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
649 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 to i_bezier_multi must be a reference to an array\n");
650 av1=(AV*)SvRV(ST(1));
651 av2=(AV*)SvRV(ST(2));
652 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
654 x=mymalloc( len*sizeof(double) );
655 y=mymalloc( len*sizeof(double) );
657 sv1=(*(av_fetch(av1,i,0)));
658 sv2=(*(av_fetch(av2,i,0)));
659 x[i]=(double)SvNV(sv1);
660 y[i]=(double)SvNV(sv2);
662 i_bezier_multi(im,len,x,y,val);
668 i_poly_aa(im,xc,yc,val)
681 if (!SvROK(ST(1))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
682 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
683 if (!SvROK(ST(2))) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
684 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 1 to i_poly_aa must be a reference to an array\n");
685 av1=(AV*)SvRV(ST(1));
686 av2=(AV*)SvRV(ST(2));
687 if (av_len(av1) != av_len(av2)) croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
689 x=mymalloc( len*sizeof(double) );
690 y=mymalloc( len*sizeof(double) );
692 sv1=(*(av_fetch(av1,i,0)));
693 sv2=(*(av_fetch(av2,i,0)));
694 x[i]=(double)SvNV(sv1);
695 y[i]=(double)SvNV(sv2);
697 i_poly_aa(im,len,x,y,val);
704 i_flood_fill(im,seedx,seedy,dcol)
712 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
724 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
742 i_rubthru(im,src,tx,ty)
749 i_flipxy(im, direction)
769 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
770 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
773 coeff=mymalloc( len*sizeof(float) );
775 sv1=(*(av_fetch(av,i,0)));
776 coeff[i]=(float)SvNV(sv1);
778 i_conv(im,coeff,len);
782 i_convert(im, src, coeff)
796 if (!SvROK(ST(2)) || SvTYPE(SvRV(ST(2))) != SVt_PVAV)
797 croak("i_convert: parameter 3 must be an arrayref\n");
798 avmain = (AV*)SvRV(ST(2));
799 outchan = av_len(avmain)+1;
800 /* find the biggest */
802 for (j=0; j < outchan; ++j) {
803 temp = av_fetch(avmain, j, 0);
804 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
805 avsub = (AV*)SvRV(*temp);
806 len = av_len(avsub)+1;
811 coeff = mymalloc(sizeof(float) * outchan * inchan);
812 for (j = 0; j < outchan; ++j) {
813 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
814 len = av_len(avsub)+1;
815 for (i = 0; i < len; ++i) {
816 temp = av_fetch(avsub, i, 0);
818 coeff[i+j*inchan] = SvNV(*temp);
820 coeff[i+j*inchan] = 0;
823 coeff[i++ + j*inchan] = 0;
825 RETVAL = i_convert(im, src, coeff, outchan, inchan);
847 i_t1_new(pfb,afm=NULL)
852 i_t1_destroy(font_id)
857 i_t1_cp(im,xb,yb,channel,fontnum,points,str,len,align)
869 i_t1_bbox(fontnum,point,str,len)
877 i_t1_bbox(fontnum,point,str,len,cords);
879 PUSHs(sv_2mortal(newSViv(cords[0])));
880 PUSHs(sv_2mortal(newSViv(cords[1])));
881 PUSHs(sv_2mortal(newSViv(cords[2])));
882 PUSHs(sv_2mortal(newSViv(cords[3])));
883 PUSHs(sv_2mortal(newSViv(cords[4])));
884 PUSHs(sv_2mortal(newSViv(cords[5])));
889 i_t1_text(im,xb,yb,cl,fontnum,points,str,len,align)
911 Imager::TTHandle handle
916 i_tt_text(handle,im,xb,yb,cl,points,str,len,smooth)
917 Imager::TTHandle handle
929 i_tt_cp(handle,im,xb,yb,channel,points,str,len,smooth)
930 Imager::TTHandle handle
943 i_tt_bbox(handle,point,str,len)
944 Imager::TTHandle handle
951 if ((rc=i_tt_bbox(handle,point,str,len,cords))) {
953 PUSHs(sv_2mortal(newSViv(cords[0])));
954 PUSHs(sv_2mortal(newSViv(cords[1])));
955 PUSHs(sv_2mortal(newSViv(cords[2])));
956 PUSHs(sv_2mortal(newSViv(cords[3])));
957 PUSHs(sv_2mortal(newSViv(cords[4])));
958 PUSHs(sv_2mortal(newSViv(cords[5])));
969 i_writejpeg(im,fd,qfactor)
984 rimg=i_readjpeg(fd,&iptc_itext,&tlength);
985 if (iptc_itext == NULL) {
988 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
993 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
995 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1001 i_readjpeg_scalar(...)
1005 unsigned int length;
1012 data = (char *)SvPV(ST(0), length);
1013 rimg=i_readjpeg_scalar(data,length,&iptc_itext,&tlength);
1014 mm_log((1,"i_readjpeg_scalar: 0x%08X\n",rimg));
1015 if (iptc_itext == NULL) {
1018 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1023 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1025 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1040 rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
1041 if (iptc_itext == NULL) {
1044 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1049 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1051 PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
1064 i_readtiff_wiol(ig, length)
1070 i_writetiff_wiol(im, ig)
1075 i_writetiff_wiol_faxable(im, ig)
1080 #endif /* HAVE_LIBTIFF */
1100 i_readpng_scalar(...)
1104 unsigned int length;
1106 data = (char *)SvPV(ST(0), length);
1107 RETVAL=i_readpng_scalar(data,length);
1121 PUSHs(sv_2mortal(newSVnv(IM_GIFMAJOR+IM_GIFMINOR*0.1)));
1124 i_writegif(im,fd,colors,pixdev,fixed)
1131 Imager__Color fixed;
1138 if (!SvROK(ST(4))) croak("Imager: Parameter 4 must be a reference to an array\n");
1139 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1140 av=(AV*)SvRV(ST(4));
1141 fixedlen=av_len(av)+1;
1142 fixed=mymalloc( fixedlen*sizeof(i_color) );
1143 for(i=0;i<fixedlen;i++) {
1144 sv1=(*(av_fetch(av,i,0)));
1145 if (sv_derived_from(sv1, "Imager::Color")) {
1146 Itmp = SvIV((SV*)SvRV(sv1));
1147 tmp = (i_color*) Itmp;
1148 } else croak("Imager: one of the elements of array ref is not of Imager::Color type\n");
1151 RETVAL=i_writegif(im,fd,colors,pixdev,fixedlen,fixed);
1153 ST(0) = sv_newmortal();
1154 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1155 else sv_setiv(ST(0), (IV)RETVAL);
1161 i_writegifmc(im,fd,colors)
1168 i_writegif_gen(fd, ...)
1174 i_img **imgs = NULL;
1180 croak("Usage: i_writegif_gen(fd,hashref, images...)");
1181 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1182 croak("i_writegif_gen: Second argument must be a hash ref");
1183 hv = (HV *)SvRV(ST(1));
1184 memset(&quant, 0, sizeof(quant));
1185 quant.mc_size = 256;
1186 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1187 memset(&opts, 0, sizeof(opts));
1188 handle_quant_opts(&quant, hv);
1189 handle_gif_opts(&opts, hv);
1190 img_count = items - 2;
1192 if (img_count < 1) {
1195 i_push_error(0, "You need to specify images to save");
1198 imgs = mymalloc(sizeof(i_img *) * img_count);
1199 for (i = 0; i < img_count; ++i) {
1202 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1203 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1207 i_push_error(0, "Only images can be saved");
1213 RETVAL = i_writegif_gen(&quant, fd, imgs, img_count, &opts);
1217 copy_colors_back(hv, &quant);
1220 ST(0) = sv_newmortal();
1221 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1222 else sv_setiv(ST(0), (IV)RETVAL);
1225 i_writegif_callback(cb, maxbuffer,...)
1230 i_img **imgs = NULL;
1237 croak("Usage: i_writegif_callback(\\&callback,maxbuffer,hashref, images...)");
1238 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1239 croak("i_writegif_callback: Second argument must be a hash ref");
1240 hv = (HV *)SvRV(ST(2));
1241 memset(&quant, 0, sizeof(quant));
1242 quant.mc_size = 256;
1243 quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
1244 memset(&opts, 0, sizeof(opts));
1245 handle_quant_opts(&quant, hv);
1246 handle_gif_opts(&opts, hv);
1247 img_count = items - 3;
1249 if (img_count < 1) {
1253 imgs = mymalloc(sizeof(i_img *) * img_count);
1254 for (i = 0; i < img_count; ++i) {
1257 if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
1258 imgs[i] = (i_img *)SvIV((SV*)SvRV(sv));
1267 RETVAL = i_writegif_callback(&quant, write_callback, (char *)&wd, maxbuffer, imgs, img_count, &opts);
1271 copy_colors_back(hv, &quant);
1274 ST(0) = sv_newmortal();
1275 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1276 else sv_setiv(ST(0), (IV)RETVAL);
1289 colour_table = NULL;
1292 if(GIMME_V == G_ARRAY) {
1293 rimg = i_readgif(fd,&colour_table,&colours);
1295 /* don't waste time with colours if they aren't wanted */
1296 rimg = i_readgif(fd,NULL,NULL);
1299 if (colour_table == NULL) {
1302 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1305 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1306 /* I don't know if I have the reference counts right or not :( */
1307 /* Neither do I :-) */
1308 /* No Idea here either */
1311 av_extend(ct, colours);
1312 for(q=0; q<colours; q++) {
1314 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1315 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1317 myfree(colour_table);
1321 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1323 PUSHs(newRV_noinc((SV*)ct));
1331 i_readgif_scalar(...)
1335 unsigned int length;
1343 data = (char *)SvPV(ST(0), length);
1347 if(GIMME_V == G_ARRAY) {
1348 rimg=i_readgif_scalar(data,length,&colour_table,&colours);
1350 /* don't waste time with colours if they aren't wanted */
1351 rimg=i_readgif_scalar(data,length,NULL,NULL);
1354 if (colour_table == NULL) {
1357 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1360 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1361 /* I don't know if I have the reference counts right or not :( */
1362 /* Neither do I :-) */
1364 av_extend(ct, colours);
1365 for(q=0; q<colours; q++) {
1367 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1368 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1370 myfree(colour_table);
1374 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1376 PUSHs(newRV_noinc((SV*)ct));
1380 i_readgif_callback(...)
1397 if(GIMME_V == G_ARRAY) {
1398 rimg=i_readgif_callback(read_callback, (char *)&rd,&colour_table,&colours);
1400 /* don't waste time with colours if they aren't wanted */
1401 rimg=i_readgif_callback(read_callback, (char *)&rd,NULL,NULL);
1404 if (colour_table == NULL) {
1407 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1410 /* the following creates an [[r,g,b], [r, g, b], [r, g, b]...] */
1411 /* I don't know if I have the reference counts right or not :( */
1412 /* Neither do I :-) */
1413 /* Neither do I - maybe I'll move this somewhere */
1415 av_extend(ct, colours);
1416 for(q=0; q<colours; q++) {
1418 temp[w]=sv_2mortal(newSViv(colour_table[q*3 + w]));
1419 av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
1421 myfree(colour_table);
1425 sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
1427 PUSHs(newRV_noinc((SV*)ct));
1440 i_readpnm_wiol(ig, length)
1451 i_readraw(fd,x,y,datachannels,storechannels,intrl)
1466 i_scaleaxis(im,Value,Axis)
1472 i_scale_nn(im,scx,scy)
1482 i_count_colors(im,maxc)
1488 i_transform(im,opx,opy,parm)
1501 if (!SvROK(ST(1))) croak("Imager: Parameter 1 must be a reference to an array\n");
1502 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to an array\n");
1503 if (!SvROK(ST(3))) croak("Imager: Parameter 3 must be a reference to an array\n");
1504 if (SvTYPE(SvRV(ST(1))) != SVt_PVAV) croak("Imager: Parameter 1 must be a reference to an array\n");
1505 if (SvTYPE(SvRV(ST(2))) != SVt_PVAV) croak("Imager: Parameter 2 must be a reference to an array\n");
1506 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 3 must be a reference to an array\n");
1507 av=(AV*)SvRV(ST(1));
1509 opx=mymalloc( opxl*sizeof(int) );
1510 for(i=0;i<opxl;i++) {
1511 sv1=(*(av_fetch(av,i,0)));
1512 opx[i]=(int)SvIV(sv1);
1514 av=(AV*)SvRV(ST(2));
1516 opy=mymalloc( opyl*sizeof(int) );
1517 for(i=0;i<opyl;i++) {
1518 sv1=(*(av_fetch(av,i,0)));
1519 opy[i]=(int)SvIV(sv1);
1521 av=(AV*)SvRV(ST(3));
1522 parmlen=av_len(av)+1;
1523 parm=mymalloc( parmlen*sizeof(double) );
1524 for(i=0;i<parmlen;i++) { /* FIXME: Bug? */
1525 sv1=(*(av_fetch(av,i,0)));
1526 parm[i]=(double)SvNV(sv1);
1528 RETVAL=i_transform(im,opx,opxl,opy,opyl,parm,parmlen);
1532 ST(0) = sv_newmortal();
1533 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1534 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1537 i_transform2(width,height,ops,n_regs,c_regs,in_imgs)
1543 unsigned int ops_len;
1556 if (!SvROK(ST(3))) croak("Imager: Parameter 4 must be a reference to an array\n");
1557 if (!SvROK(ST(4))) croak("Imager: Parameter 5 must be a reference to an array\n");
1558 if (!SvROK(ST(5))) croak("Imager: Parameter 6 must be a reference to an array of images\n");
1559 if (SvTYPE(SvRV(ST(3))) != SVt_PVAV) croak("Imager: Parameter 4 must be a reference to an array\n");
1560 if (SvTYPE(SvRV(ST(4))) != SVt_PVAV) croak("Imager: Parameter 5 must be a reference to an array\n");
1562 /*if (SvTYPE(SvRV(ST(5))) != SVt_PVAV) croak("Imager: Parameter 6 must be a reference to an array\n");*/
1564 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1565 av = (AV*)SvRV(ST(5));
1566 in_imgs_count = av_len(av)+1;
1567 for (i = 0; i < in_imgs_count; ++i) {
1568 sv1 = *av_fetch(av, i, 0);
1569 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1570 croak("Parameter 5 must contain only images");
1577 if (SvTYPE(SvRV(ST(5))) == SVt_PVAV) {
1578 av = (AV*)SvRV(ST(5));
1579 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
1580 for (i = 0; i < in_imgs_count; ++i) {
1581 sv1 = *av_fetch(av,i,0);
1582 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
1583 croak("Parameter 5 must contain only images");
1585 tmp = SvIV((SV*)SvRV(sv1));
1586 in_imgs[i] = (i_img*)tmp;
1590 /* no input images */
1593 /* default the output size from the first input if possible */
1595 width = SvIV(ST(0));
1596 else if (in_imgs_count)
1597 width = in_imgs[0]->xsize;
1599 croak("No output image width supplied");
1602 height = SvIV(ST(1));
1603 else if (in_imgs_count)
1604 height = in_imgs[0]->ysize;
1606 croak("No output image height supplied");
1608 ops = (struct rm_op *)SvPV(ST(2), ops_len);
1609 if (ops_len % sizeof(struct rm_op))
1610 croak("Imager: Parameter 3 must be a bitmap of regops\n");
1611 ops_count = ops_len / sizeof(struct rm_op);
1612 av = (AV*)SvRV(ST(3));
1613 n_regs_count = av_len(av)+1;
1614 n_regs = mymalloc(n_regs_count * sizeof(double));
1615 for (i = 0; i < n_regs_count; ++i) {
1616 sv1 = *av_fetch(av,i,0);
1618 n_regs[i] = SvNV(sv1);
1620 av = (AV*)SvRV(ST(4));
1621 c_regs_count = av_len(av)+1;
1622 c_regs = mymalloc(c_regs_count * sizeof(i_color));
1623 /* I don't bother initializing the colou?r registers */
1625 RETVAL=i_transform2(width, height, 3, ops, ops_count,
1626 n_regs, n_regs_count,
1627 c_regs, c_regs_count, in_imgs, in_imgs_count);
1632 ST(0) = sv_newmortal();
1633 if (RETVAL == 0) ST(0)=&PL_sv_undef;
1634 else sv_setref_pv(ST(0), "Imager::ImgRaw", (void*)RETVAL);
1638 i_contrast(im,intensity)
1647 i_noise(im,amount,type)
1653 i_bumpmap(im,bump,channel,light_x,light_y,strength)
1662 i_postlevels(im,levels)
1672 i_watermark(im,wmark,tx,ty,pixdiff)
1674 Imager::ImgRaw wmark
1681 i_autolevels(im,lsat,usat,skew)
1688 i_radnoise(im,xo,yo,rscale,ascale)
1696 i_turbnoise(im, xo, yo, scale)
1719 croak("Usage: i_gradgen(im, xo, yo, ival, dmeasure)");
1720 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1721 croak("i_gradgen: Second argument must be an array ref");
1722 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1723 croak("i_gradgen: Third argument must be an array ref");
1724 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1725 croak("i_gradgen: Fourth argument must be an array ref");
1726 axx = (AV *)SvRV(ST(1));
1727 ayy = (AV *)SvRV(ST(2));
1728 ac = (AV *)SvRV(ST(3));
1729 dmeasure = (int)SvIV(ST(4));
1731 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1732 num = num <= av_len(ac) ? num : av_len(ac);
1734 if (num < 2) croak("Usage: i_gradgen array refs must have more than 1 entry each");
1735 xo = mymalloc( sizeof(int) * num );
1736 yo = mymalloc( sizeof(int) * num );
1737 ival = mymalloc( sizeof(i_color) * num );
1738 for(i = 0; i<num; i++) {
1739 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1740 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1741 sv = *av_fetch(ac, i, 0);
1742 if ( !sv_derived_from(sv, "Imager::Color") ) {
1743 free(axx); free(ayy); free(ac);
1744 croak("i_gradgen: Element of fourth argument is not derived from Imager::Color");
1746 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1748 i_gradgen(im, num, xo, yo, ival, dmeasure);
1764 errors = i_errors();
1766 while (errors[i].msg) {
1768 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
1769 if (!av_store(av, 0, sv)) {
1772 sv = newSViv(errors[i].code);
1773 if (!av_store(av, 1, sv)) {
1776 PUSHs(sv_2mortal(newRV_noinc((SV*)av)));
1781 i_nearest_color(im, ...)
1796 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
1797 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
1798 croak("i_nearest_color: Second argument must be an array ref");
1799 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
1800 croak("i_nearest_color: Third argument must be an array ref");
1801 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
1802 croak("i_nearest_color: Fourth argument must be an array ref");
1803 axx = (AV *)SvRV(ST(1));
1804 ayy = (AV *)SvRV(ST(2));
1805 ac = (AV *)SvRV(ST(3));
1806 dmeasure = (int)SvIV(ST(4));
1808 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
1809 num = num <= av_len(ac) ? num : av_len(ac);
1811 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
1812 xo = mymalloc( sizeof(int) * num );
1813 yo = mymalloc( sizeof(int) * num );
1814 ival = mymalloc( sizeof(i_color) * num );
1815 for(i = 0; i<num; i++) {
1816 xo[i] = (int)SvIV(* av_fetch(axx, i, 0));
1817 yo[i] = (int)SvIV(* av_fetch(ayy, i, 0));
1818 sv = *av_fetch(ac, i, 0);
1819 if ( !sv_derived_from(sv, "Imager::Color") ) {
1820 free(axx); free(ayy); free(ac);
1821 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
1823 ival[i] = *(i_color *)SvIV((SV *)SvRV(sv));
1825 i_nearest_color(im, num, xo, yo, ival, dmeasure);
1839 if (!SvROK(ST(0))) croak("Imager: Parameter 0 must be a reference to a hash\n");
1840 hv=(HV*)SvRV(ST(0));
1841 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 0 must be a reference to a hash\n");
1842 if (getint(hv,"stuff",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1843 if (getint(hv,"stuff2",&stuff)) printf("ok: %d\n",stuff); else printf("key doesn't exist\n");
1852 rc=DSO_open(filename,&evstr);
1856 PUSHs(sv_2mortal(newSViv((IV)rc)));
1857 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
1860 PUSHs(sv_2mortal(newSViv((IV)rc)));
1866 DSO_close(dso_handle)
1870 DSO_funclist(dso_handle_v)
1874 DSO_handle *dso_handle;
1876 dso_handle=(DSO_handle*)dso_handle_v;
1878 while( dso_handle->function_list[i].name != NULL) {
1880 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
1882 PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
1887 DSO_call(handle,func_index,hv)
1893 if (!SvROK(ST(2))) croak("Imager: Parameter 2 must be a reference to a hash\n");
1894 hv=(HV*)SvRV(ST(2));
1895 if (SvTYPE(hv)!=SVt_PVHV) croak("Imager: Parameter 2 must be a reference to a hash\n");
1896 DSO_call( (DSO_handle *)handle,func_index,hv);
1900 # this is mostly for testing...
1902 i_get_pixel(im, x, y)
1907 RETVAL = (i_color *)mymalloc(sizeof(i_color));
1908 i_gpix(im, x, y, RETVAL);