1 #define PERL_NO_GET_CONTEXT
8 #define NEED_newRV_noinc
9 #define NEED_sv_2pv_nolen
10 #define NEED_sv_2pvbyte
16 #define i_int_hlines_testing() 1
23 #include "imextpltypes.h"
27 #if i_int_hlines_testing()
33 #define ARRAY_COUNT(array) (sizeof(array)/sizeof(*array))
37 Context object management
41 typedef im_context_t Imager__Context;
43 #define im_context_DESTROY(ctx) im_context_refdec((ctx), "DESTROY")
45 #ifdef PERL_IMPLICIT_CONTEXT
47 #define MY_CXT_KEY "Imager::_context" XS_VERSION
58 MY_CXT.ctx = im_context_new();
59 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
63 perl_get_context(void) {
72 static im_context_t perl_context;
76 perl_context = im_context_new();
78 /* just so it gets destroyed */
79 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", perl_context);
83 perl_get_context(void) {
89 /* used to represent channel lists parameters */
90 typedef struct i_channel_list_tag {
97 const i_sample_t *samples;
102 const i_fsample_t *samples;
107 const i_polygon_t *polygons;
112 Allocate memory that will be discarded when mortals are discarded.
117 malloc_temp(pTHX_ size_t size) {
119 Newx(result, size, char);
126 calloc_temp(pTHX_ size_t size) {
128 Newxz(result, size, char);
134 /* for use with the T_AVARRAY typemap */
135 #define doublePtr(size) ((double *)calloc_temp(aTHX_ sizeof(double) * (size)))
136 #define SvDouble(sv, pname) (SvNV(sv))
138 #define intPtr(size) ((int *)calloc_temp(aTHX_ sizeof(int) * (size)))
139 #define SvInt(sv, pname) (SvIV(sv))
141 #define i_img_dimPtr(size) ((i_img_dim *)calloc_temp(aTHX_ sizeof(i_img_dim) * (size)))
142 #define SvI_img_dim(sv, pname) (SvIV(sv))
144 #define i_colorPtr(size) ((i_color *)calloc_temp(aTHX_ sizeof(i_color) * (size)))
146 #define SvI_color(sv, pname) S_sv_to_i_color(aTHX_ sv, pname)
149 S_sv_to_i_color(pTHX_ SV *sv, const char *pname) {
150 if (!sv_derived_from(sv, "Imager::Color")) {
151 croak("%s: not a color object", pname);
153 return *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
156 /* These functions are all shared - then comes platform dependant code */
157 static int getstr(void *hv_t,char *key,char **store) {
162 mm_log((1,"getstr(hv_t %p, key %s, store %p)\n",hv_t,key,store));
164 if ( !hv_exists(hv,key,strlen(key)) ) return 0;
166 svpp=hv_fetch(hv, key, strlen(key), 0);
167 *store=SvPV(*svpp, PL_na );
172 static int getint(void *hv_t,char *key,int *store) {
177 mm_log((1,"getint(hv_t %p, key %s, store %p)\n",hv_t,key,store));
179 if ( !hv_exists(hv,key,strlen(key)) ) return 0;
181 svpp=hv_fetch(hv, key, strlen(key), 0);
182 *store=(int)SvIV(*svpp);
186 static int getdouble(void *hv_t,char* key,double *store) {
191 mm_log((1,"getdouble(hv_t %p, key %s, store %p)\n",hv_t,key,store));
193 if ( !hv_exists(hv,key,strlen(key)) ) return 0;
194 svpp=hv_fetch(hv, key, strlen(key), 0);
195 *store=(double)SvNV(*svpp);
199 static int getvoid(void *hv_t,char* key,void **store) {
204 mm_log((1,"getvoid(hv_t %p, key %s, store %p)\n",hv_t,key,store));
206 if ( !hv_exists(hv,key,strlen(key)) ) return 0;
208 svpp=hv_fetch(hv, key, strlen(key), 0);
209 *store = INT2PTR(void*, SvIV(*svpp));
214 static int getobj(void *hv_t,char *key,char *type,void **store) {
219 mm_log((1,"getobj(hv_t %p, key %s,type %s, store %p)\n",hv_t,key,type,store));
221 if ( !hv_exists(hv,key,strlen(key)) ) return 0;
223 svpp=hv_fetch(hv, key, strlen(key), 0);
225 if (sv_derived_from(*svpp,type)) {
226 IV tmp = SvIV((SV*)SvRV(*svpp));
227 *store = INT2PTR(void*, tmp);
229 mm_log((1,"getobj: key exists in hash but is not of correct type"));
236 UTIL_table_t i_UTIL_table={getstr,getint,getdouble,getvoid,getobj};
239 free_buffer(void *p) {
245 i_log_entry(char *string, int level) {
246 mm_log((level, "%s", string));
250 make_i_color_sv(pTHX_ const i_color *c) {
252 i_color *col = mymalloc(sizeof(i_color));
255 sv_setref_pv(sv, "Imager::Color", (void *)col);
260 #define CBDATA_BUFSIZE 8192
263 /* the SVs we use to call back to Perl */
271 call_reader(struct cbdata *cbd, void *buf, size_t size,
279 if (!SvOK(cbd->readcb)) {
280 mm_log((1, "read callback called but no readcb supplied\n"));
281 i_push_error(0, "read callback called but no readcb supplied");
289 PUSHs(sv_2mortal(newSViv(size)));
290 PUSHs(sv_2mortal(newSViv(maxread)));
293 count = perl_call_sv(cbd->readcb, G_SCALAR);
298 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
304 char *ptr = SvPVbyte(data, len);
306 croak("Too much data returned in reader callback (wanted %d, got %d, expected %d)",
307 (int)size, (int)len, (int)maxread);
309 memcpy(buf, ptr, len);
324 io_seeker(void *p, off_t offset, int whence) {
326 struct cbdata *cbd = p;
331 if (!SvOK(cbd->seekcb)) {
332 mm_log((1, "seek callback called but no seekcb supplied\n"));
333 i_push_error(0, "seek callback called but no seekcb supplied");
341 PUSHs(sv_2mortal(newSViv(offset)));
342 PUSHs(sv_2mortal(newSViv(whence)));
345 count = perl_call_sv(cbd->seekcb, G_SCALAR);
350 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
362 io_writer(void *p, void const *data, size_t size) {
364 struct cbdata *cbd = p;
370 if (!SvOK(cbd->writecb)) {
371 mm_log((1, "write callback called but no writecb supplied\n"));
372 i_push_error(0, "write callback called but no writecb supplied");
380 PUSHs(sv_2mortal(newSVpv((char *)data, size)));
383 count = perl_call_sv(cbd->writecb, G_SCALAR);
387 croak("Result of perl_call_sv(..., G_SCALAR) != 1");
390 success = SvTRUE(sv);
397 return success ? size : -1;
401 io_reader(void *p, void *data, size_t size) {
402 struct cbdata *cbd = p;
404 return call_reader(cbd, data, size, size);
407 static int io_closer(void *p) {
409 struct cbdata *cbd = p;
412 if (SvOK(cbd->closecb)) {
421 count = perl_call_sv(cbd->closecb, G_SCALAR);
427 success = SvTRUE(sv);
437 return success ? 0 : -1;
440 static void io_destroyer(void *p) {
442 struct cbdata *cbd = p;
444 SvREFCNT_dec(cbd->writecb);
445 SvREFCNT_dec(cbd->readcb);
446 SvREFCNT_dec(cbd->seekcb);
447 SvREFCNT_dec(cbd->closecb);
452 im_SvREFSCALAR(SV *sv) {
453 svtype type = SvTYPE(sv);
463 #if PERL_VERSION > 10
474 describe_sv(SV *sv) {
477 svtype type = SvTYPE(SvRV(sv));
479 case SVt_PVCV: return "CV";
480 case SVt_PVGV: return "GV";
481 case SVt_PVLV: return "LV";
482 default: return "some reference";
486 return "non-reference scalar";
495 do_io_new_buffer(pTHX_ SV *data_sv) {
502 if (SvROK(data_sv)) {
503 if (im_SvREFSCALAR(SvRV(data_sv))) {
507 i_push_errorf(0, "data is not a scalar or a reference to scalar");
515 /* previously this would keep the SV around, but this is unsafe in
516 many ways, so always copy the bytes */
517 data = SvPVbyte(sv, length);
518 data_copy = mymalloc(length);
519 memcpy(data_copy, data, length);
520 return io_new_buffer(data_copy, length, free_buffer, data_copy);
524 do_io_new_cb(pTHX_ SV *writecb, SV *readcb, SV *seekcb, SV *closecb) {
527 cbd = mymalloc(sizeof(struct cbdata));
528 cbd->writecb = newSVsv(writecb);
529 cbd->readcb = newSVsv(readcb);
530 cbd->seekcb = newSVsv(seekcb);
531 cbd->closecb = newSVsv(closecb);
533 mm_log((1, "do_io_new_cb(writecb %p (%s), readcb %p (%s), seekcb %p (%s), closecb %p (%s))\n", writecb, describe_sv(writecb), readcb, describe_sv(readcb), seekcb, describe_sv(seekcb), closecb, describe_sv(closecb)));
535 return io_new_cb(cbd, io_reader, io_writer, io_seeker, io_closer,
543 static int lookup_name(const struct value_name *names, int count, char *name, int def_value)
546 for (i = 0; i < count; ++i)
547 if (strEQ(names[i].name, name))
548 return names[i].value;
552 static struct value_name transp_names[] =
555 { "threshold", tr_threshold },
556 { "errdiff", tr_errdiff },
557 { "ordered", tr_ordered, },
560 static struct value_name make_color_names[] =
562 { "none", mc_none, },
563 { "webmap", mc_web_map, },
564 { "addi", mc_addi, },
565 { "mediancut", mc_median_cut, },
566 { "mono", mc_mono, },
567 { "monochrome", mc_mono, },
568 { "gray", mc_gray, },
569 { "gray4", mc_gray4, },
570 { "gray16", mc_gray16, },
573 static struct value_name translate_names[] =
575 { "giflib", pt_giflib, },
576 { "closest", pt_closest, },
577 { "perturb", pt_perturb, },
578 { "errdiff", pt_errdiff, },
581 static struct value_name errdiff_names[] =
583 { "floyd", ed_floyd, },
584 { "jarvis", ed_jarvis, },
585 { "stucki", ed_stucki, },
586 { "custom", ed_custom, },
589 static struct value_name orddith_names[] =
591 { "random", od_random, },
592 { "dot8", od_dot8, },
593 { "dot4", od_dot4, },
594 { "hline", od_hline, },
595 { "vline", od_vline, },
596 { "/line", od_slashline, },
597 { "slashline", od_slashline, },
598 { "\\line", od_backline, },
599 { "backline", od_backline, },
600 { "tiny", od_tiny, },
601 { "custom", od_custom, },
604 /* look through the hash for quantization options */
606 ip_handle_quant_opts(pTHX_ i_quantize *quant, HV *hv)
608 /*** POSSIBLY BROKEN: do I need to unref the SV from hv_fetch ***/
614 quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color));
616 sv = hv_fetch(hv, "transp", 6, 0);
617 if (sv && *sv && (str = SvPV(*sv, len))) {
619 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
621 if (quant->transp != tr_none) {
622 quant->tr_threshold = 127;
623 sv = hv_fetch(hv, "tr_threshold", 12, 0);
625 quant->tr_threshold = SvIV(*sv);
627 if (quant->transp == tr_errdiff) {
628 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
629 if (sv && *sv && (str = SvPV(*sv, len)))
630 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
632 if (quant->transp == tr_ordered) {
633 quant->tr_orddith = od_tiny;
634 sv = hv_fetch(hv, "tr_orddith", 10, 0);
635 if (sv && *sv && (str = SvPV(*sv, len)))
636 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random);
638 if (quant->tr_orddith == od_custom) {
639 sv = hv_fetch(hv, "tr_map", 6, 0);
640 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
641 AV *av = (AV*)SvRV(*sv);
642 len = av_len(av) + 1;
643 if (len > sizeof(quant->tr_custom))
644 len = sizeof(quant->tr_custom);
645 for (i = 0; i < len; ++i) {
646 SV **sv2 = av_fetch(av, i, 0);
648 quant->tr_custom[i] = SvIV(*sv2);
651 while (i < sizeof(quant->tr_custom))
652 quant->tr_custom[i++] = 0;
657 quant->make_colors = mc_median_cut;
658 sv = hv_fetch(hv, "make_colors", 11, 0);
659 if (sv && *sv && (str = SvPV(*sv, len))) {
661 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_median_cut);
663 sv = hv_fetch(hv, "colors", 6, 0);
664 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
665 /* needs to be an array of Imager::Color
666 note that the caller allocates the mc_color array and sets mc_size
668 AV *av = (AV *)SvRV(*sv);
669 quant->mc_count = av_len(av)+1;
670 if (quant->mc_count > quant->mc_size)
671 quant->mc_count = quant->mc_size;
672 for (i = 0; i < quant->mc_count; ++i) {
673 SV **sv1 = av_fetch(av, i, 0);
674 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
675 i_color *col = INT2PTR(i_color *, SvIV((SV*)SvRV(*sv1)));
676 quant->mc_colors[i] = *col;
680 sv = hv_fetch(hv, "max_colors", 10, 0);
683 if (i <= quant->mc_size && i >= quant->mc_count)
687 quant->translate = pt_closest;
688 sv = hv_fetch(hv, "translate", 9, 0);
689 if (sv && *sv && (str = SvPV(*sv, len))) {
690 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest);
692 sv = hv_fetch(hv, "errdiff", 7, 0);
693 if (sv && *sv && (str = SvPV(*sv, len))) {
694 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd);
696 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
697 /* get the error diffusion map */
698 sv = hv_fetch(hv, "errdiff_width", 13, 0);
700 quant->ed_width = SvIV(*sv);
701 sv = hv_fetch(hv, "errdiff_height", 14, 0);
703 quant->ed_height = SvIV(*sv);
704 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
706 quant->ed_orig = SvIV(*sv);
707 if (quant->ed_width > 0 && quant->ed_height > 0) {
709 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
710 sv = hv_fetch(hv, "errdiff_map", 11, 0);
711 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
712 AV *av = (AV*)SvRV(*sv);
713 len = av_len(av) + 1;
714 if (len > quant->ed_width * quant->ed_height)
715 len = quant->ed_width * quant->ed_height;
716 for (i = 0; i < len; ++i) {
717 SV **sv2 = av_fetch(av, i, 0);
719 quant->ed_map[i] = SvIV(*sv2);
720 sum += quant->ed_map[i];
726 myfree(quant->ed_map);
728 quant->errdiff = ed_floyd;
732 sv = hv_fetch(hv, "perturb", 7, 0);
734 quant->perturb = SvIV(*sv);
738 ip_cleanup_quant_opts(pTHX_ i_quantize *quant) {
739 myfree(quant->mc_colors);
741 myfree(quant->ed_map);
744 /* copies the color map from the hv into the colors member of the HV */
746 ip_copy_colors_back(pTHX_ HV *hv, i_quantize *quant) {
752 sv = hv_fetch(hv, "colors", 6, 0);
753 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
758 av = (AV *)SvRV(*sv);
760 av_extend(av, quant->mc_count+1);
761 for (i = 0; i < quant->mc_count; ++i) {
762 i_color *in = quant->mc_colors+i;
763 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
764 work = sv_newmortal();
765 sv_setref_pv(work, "Imager::Color", (void *)c);
771 static struct value_name
772 poly_fill_mode_names[] =
774 { "evenodd", i_pfm_evenodd },
775 { "nonzero", i_pfm_nonzero }
778 static i_poly_fill_mode_t
779 S_get_poly_fill_mode(pTHX_ SV *sv) {
780 if (looks_like_number(sv)) {
782 if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero)
783 work = (IV)i_pfm_evenodd;
784 return (i_poly_fill_mode_t)work;
787 return (i_poly_fill_mode_t)lookup_name
788 (poly_fill_mode_names, ARRAY_COUNT(poly_fill_mode_names),
789 SvPV_nolen(sv), i_pfm_evenodd);
794 S_get_polygon_list(pTHX_ i_polygon_list *polys, SV *sv) {
800 if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV)
801 croak("polys must be an arrayref");
804 polys->count = av_len(av) + 1;
805 if (polys->count < 1)
806 croak("polypolygon: no polygons provided");
807 s = malloc_temp(aTHX_ sizeof(i_polygon_t) * polys->count);
808 for (i = 0; i < polys->count; ++i) {
809 SV **poly_sv = av_fetch(av, i, 0);
813 double *x_data, *y_data;
818 croak("poly_polygon: nothing found for polygon %d", i);
819 /* needs to be another av */
820 SvGETMAGIC(*poly_sv);
821 if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV)
822 croak("poly_polygon: polygon %d isn't an arrayref", i);
823 poly_av = (AV*)SvRV(*poly_sv);
824 /* with two elements */
825 if (av_len(poly_av) != 1)
826 croak("poly_polygon: polygon %d should contain two arrays", i);
827 x_sv = av_fetch(poly_av, 0, 0);
828 y_sv = av_fetch(poly_av, 1, 0);
830 croak("poly_polygon: polygon %d has no x elements", i);
832 croak("poly_polygon: polygon %d has no y elements", i);
835 if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV)
836 croak("poly_polygon: polygon %d x elements isn't an array", i);
837 if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV)
838 croak("poly_polygon: polygon %d y elements isn't an array", i);
839 x_av = (AV*)SvRV(*x_sv);
840 y_av = (AV*)SvRV(*y_sv);
841 if (av_len(x_av) != av_len(y_av))
842 croak("poly_polygon: polygon %d x and y arrays different lengths", i+1);
843 point_count = av_len(x_av)+1;
844 x_data = malloc_temp(aTHX_ sizeof(double) * point_count * 2);
845 y_data = x_data + point_count;
847 for (j = 0; j < point_count; ++j) {
848 SV **x_item_sv = av_fetch(x_av, j, 0);
849 SV **y_item_sv = av_fetch(y_av, j, 0);
850 x_data[j] = x_item_sv ? SvNV(*x_item_sv) : 0;
851 y_data[j] = y_item_sv ? SvNV(*y_item_sv) : 0;
855 s[i].count = point_count;
860 /* loads the segments of a fountain fill into an array */
861 static i_fountain_seg *
862 load_fount_segs(pTHX_ AV *asegs, int *count) {
863 /* Each element of segs must contain:
864 [ start, middle, end, c0, c1, segtype, colortrans ]
865 start, middle, end are doubles from 0 to 1
866 c0, c1 are Imager::Color::Float or Imager::Color objects
867 segtype, colortrans are ints
871 i_fountain_seg *segs;
875 *count = av_len(asegs)+1;
877 croak("i_fountain must have at least one segment");
878 segs = mymalloc(sizeof(i_fountain_seg) * *count);
879 for(i = 0; i < *count; i++) {
880 SV **sv1 = av_fetch(asegs, i, 0);
881 if (!sv1 || !*sv1 || !SvROK(*sv1)
882 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
884 croak("i_fountain: segs must be an arrayref of arrayrefs");
886 aseg = (AV *)SvRV(*sv1);
887 if (av_len(aseg) != 7-1) {
889 croak("i_fountain: a segment must have 7 members");
891 for (j = 0; j < 3; ++j) {
892 SV **sv2 = av_fetch(aseg, j, 0);
895 croak("i_fountain: XS error");
897 work[j] = SvNV(*sv2);
899 segs[i].start = work[0];
900 segs[i].middle = work[1];
901 segs[i].end = work[2];
902 for (j = 0; j < 2; ++j) {
903 SV **sv3 = av_fetch(aseg, 3+j, 0);
904 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
905 (!sv_derived_from(*sv3, "Imager::Color")
906 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
908 croak("i_fountain: segs must contain colors in elements 3 and 4");
910 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
911 segs[i].c[j] = *INT2PTR(i_fcolor *, SvIV((SV *)SvRV(*sv3)));
914 i_color c = *INT2PTR(i_color *, SvIV((SV *)SvRV(*sv3)));
916 for (ch = 0; ch < MAXCHANNELS; ++ch) {
917 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
921 for (j = 0; j < 2; ++j) {
922 SV **sv2 = av_fetch(aseg, j+5, 0);
925 croak("i_fountain: XS error");
927 worki[j] = SvIV(*sv2);
929 segs[i].type = worki[0];
930 segs[i].color = worki[1];
936 /* validates the indexes supplied to i_ppal
938 i_ppal() doesn't do that for speed, but I'm not comfortable doing that
943 validate_i_ppal(i_img *im, i_palidx const *indexes, int count) {
944 int color_count = i_colorcount(im);
947 if (color_count == -1)
948 croak("i_plin() called on direct color image");
950 for (i = 0; i < count; ++i) {
951 if (indexes[i] >= color_count) {
952 croak("i_plin() called with out of range color index %d (max %d)",
953 indexes[i], color_count-1);
958 /* I don't think ICLF_* names belong at the C interface
959 this makes the XS code think we have them, to let us avoid
960 putting function bodies in the XS code
962 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
963 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
966 #define i_log_enabled() 1
968 #define i_log_enabled() 0
971 #if i_int_hlines_testing()
973 typedef i_int_hlines *Imager__Internal__Hlines;
975 static i_int_hlines *
976 i_int_hlines_new(i_img_dim start_y, i_img_dim count_y, i_img_dim start_x, i_img_dim count_x) {
977 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
978 i_int_init_hlines(result, start_y, count_y, start_x, count_x);
983 static i_int_hlines *
984 i_int_hlines_new_img(i_img *im) {
985 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
986 i_int_init_hlines_img(result, im);
992 i_int_hlines_DESTROY(i_int_hlines *hlines) {
993 i_int_hlines_destroy(hlines);
997 #define i_int_hlines_CLONE_SKIP(cls) 1
999 static int seg_compare(const void *vleft, const void *vright) {
1000 const i_int_hline_seg *left = vleft;
1001 const i_int_hline_seg *right = vright;
1003 return left->minx - right->minx;
1007 i_int_hlines_dump(i_int_hlines *hlines) {
1009 SV *dump = newSVpvf("start_y: %" i_DF " limit_y: %" i_DF " start_x: %" i_DF " limit_x: %" i_DF"\n",
1010 i_DFc(hlines->start_y), i_DFc(hlines->limit_y), i_DFc(hlines->start_x), i_DFc(hlines->limit_x));
1013 for (y = hlines->start_y; y < hlines->limit_y; ++y) {
1014 i_int_hline_entry *entry = hlines->entries[y-hlines->start_y];
1017 /* sort the segments, if any */
1019 qsort(entry->segs, entry->count, sizeof(i_int_hline_seg), seg_compare);
1021 sv_catpvf(dump, " %" i_DF " (%" i_DF "):", i_DFc(y), i_DFc(entry->count));
1022 for (i = 0; i < entry->count; ++i) {
1023 sv_catpvf(dump, " [%" i_DF ", %" i_DF ")", i_DFc(entry->segs[i].minx),
1024 i_DFc(entry->segs[i].x_limit));
1026 sv_catpv(dump, "\n");
1036 i_sv_off_t(pTHX_ SV *sv) {
1037 #if LSEEKSIZE > IVSIZE
1038 return (off_t)SvNV(sv);
1040 return (off_t)SvIV(sv);
1045 i_new_sv_off_t(pTHX_ off_t off) {
1046 #if LSEEKSIZE > IVSIZE
1047 return newSVnv(off);
1049 return newSViv(off);
1053 static im_pl_ext_funcs im_perl_funcs =
1055 IMAGER_PL_API_VERSION,
1056 IMAGER_PL_API_LEVEL,
1057 ip_handle_quant_opts,
1058 ip_cleanup_quant_opts,
1062 #define PERL_PL_SET_GLOBAL_CALLBACKS \
1063 sv_setiv(get_sv(PERL_PL_FUNCTION_TABLE_NAME, 1), PTR2IV(&im_perl_funcs));
1065 #define IIM_new i_img_8_new
1066 #define IIM_DESTROY i_img_destroy
1069 #ifdef IMEXIF_ENABLE
1070 #define i_exif_enabled() 1
1072 #define i_exif_enabled() 0
1075 /* trying to use more C style names, map them here */
1076 #define i_io_DESTROY(ig) io_glue_destroy(ig)
1078 #define i_img_get_width(im) ((im)->xsize)
1079 #define i_img_get_height(im) ((im)->ysize)
1081 #define i_img_epsilonf() (DBL_EPSILON * 4)
1083 /* avoid some xsubpp strangeness */
1084 #define NEWLINE '\n'
1086 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
1089 ICL_new_internal(r,g,b,a)
1101 ICL_set_internal(cl,r,g,b,a)
1125 PUSHs(sv_2mortal(newSViv(cl->rgba.r)));
1126 PUSHs(sv_2mortal(newSViv(cl->rgba.g)));
1127 PUSHs(sv_2mortal(newSViv(cl->rgba.b)));
1128 PUSHs(sv_2mortal(newSViv(cl->rgba.a)));
1134 RETVAL = mymalloc(sizeof(i_color));
1136 i_hsv_to_rgb(RETVAL);
1144 RETVAL = mymalloc(sizeof(i_color));
1146 i_rgb_to_hsv(RETVAL);
1152 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
1154 Imager::Color::Float
1155 ICLF_new_internal(r, g, b, a)
1163 Imager::Color::Float cl
1167 Imager::Color::Float cl
1171 EXTEND(SP, MAXCHANNELS);
1172 for (ch = 0; ch < MAXCHANNELS; ++ch) {
1173 /* printf("%d: %g\n", ch, cl->channel[ch]); */
1174 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
1178 ICLF_set_internal(cl,r,g,b,a)
1179 Imager::Color::Float cl
1192 Imager::Color::Float
1194 Imager::Color::Float c
1196 RETVAL = mymalloc(sizeof(i_fcolor));
1198 i_hsv_to_rgbf(RETVAL);
1202 Imager::Color::Float
1204 Imager::Color::Float c
1206 RETVAL = mymalloc(sizeof(i_fcolor));
1208 i_rgb_to_hsvf(RETVAL);
1212 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
1226 MODULE = Imager PACKAGE = Imager
1240 io_new_buffer(data_sv)
1244 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1251 io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE)
1257 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1265 unsigned char* data;
1269 tlength = io_slurp(ig, &data);
1270 RETVAL = newSVpv((char *)data,tlength);
1277 i_set_image_file_limits(width, height, bytes)
1283 i_get_image_file_limits()
1285 i_img_dim width, height;
1288 if (i_get_image_file_limits(&width, &height, &bytes)) {
1290 PUSHs(sv_2mortal(newSViv(width)));
1291 PUSHs(sv_2mortal(newSViv(height)));
1292 PUSHs(sv_2mortal(newSVuv(bytes)));
1296 i_int_check_image_file_limits(width, height, channels, sample_size)
1303 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_
1306 io_new_fd(class, fd)
1309 RETVAL = io_new_fd(fd);
1314 io_new_buffer(class, data_sv)
1318 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1325 io_new_cb(class, writecb, readcb, seekcb, closecb)
1331 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1336 io_new_bufchain(class)
1338 RETVAL = io_new_bufchain();
1343 io__new_perlio(class, io)
1346 RETVAL = im_io_new_perlio(aTHX_ io);
1354 unsigned char* data;
1358 tlength = io_slurp(ig, &data);
1359 RETVAL = newSVpv((char *)data,tlength);
1364 MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_
1367 i_io_raw_write(ig, data_sv)
1374 data = SvPVbyte(data_sv, size);
1375 RETVAL = i_io_raw_write(ig, data, size);
1380 i_io_raw_read(ig, buffer_sv, size)
1389 croak("size negative in call to i_io_raw_read()");
1390 /* prevent an undefined value warning if they supplied an
1392 Orginally conditional on !SvOK(), but this will prevent the
1393 downgrade from croaking */
1394 sv_setpvn(buffer_sv, "", 0);
1396 if (SvUTF8(buffer_sv))
1397 sv_utf8_downgrade(buffer_sv, FALSE);
1399 buffer = SvGROW(buffer_sv, size+1);
1400 result = i_io_raw_read(ig, buffer, size);
1402 SvCUR_set(buffer_sv, result);
1403 *SvEND(buffer_sv) = '\0';
1404 SvPOK_only(buffer_sv);
1406 PUSHs(sv_2mortal(newSViv(result)));
1412 i_io_raw_read2(ig, size)
1421 croak("size negative in call to i_io_read2()");
1422 buffer_sv = newSV(size);
1423 buffer = SvGROW(buffer_sv, size+1);
1424 result = i_io_raw_read(ig, buffer, size);
1426 SvCUR_set(buffer_sv, result);
1427 *SvEND(buffer_sv) = '\0';
1428 SvPOK_only(buffer_sv);
1430 PUSHs(sv_2mortal(buffer_sv));
1434 SvREFCNT_dec(buffer_sv);
1438 i_io_raw_seek(ig, position, whence)
1452 i_io_CLONE_SKIP(...)
1454 (void)items; /* avoid unused warning for XS variable */
1481 i_io_seek(ig, off, whence)
1487 i_io_peekn(ig, size)
1495 buffer_sv = newSV(size+1);
1496 buffer = SvGROW(buffer_sv, size+1);
1497 result = i_io_peekn(ig, buffer, size);
1499 SvCUR_set(buffer_sv, result);
1500 *SvEND(buffer_sv) = '\0';
1501 SvPOK_only(buffer_sv);
1503 PUSHs(sv_2mortal(buffer_sv));
1507 SvREFCNT_dec(buffer_sv);
1511 i_io_read(ig, buffer_sv, size)
1520 croak("size negative in call to i_io_read()");
1521 /* prevent an undefined value warning if they supplied an
1523 Orginally conditional on !SvOK(), but this will prevent the
1524 downgrade from croaking */
1525 sv_setpvn(buffer_sv, "", 0);
1527 if (SvUTF8(buffer_sv))
1528 sv_utf8_downgrade(buffer_sv, FALSE);
1530 buffer = SvGROW(buffer_sv, size+1);
1531 result = i_io_read(ig, buffer, size);
1533 SvCUR_set(buffer_sv, result);
1534 *SvEND(buffer_sv) = '\0';
1535 SvPOK_only(buffer_sv);
1537 PUSHs(sv_2mortal(newSViv(result)));
1543 i_io_read2(ig, size)
1552 croak("size zero in call to read2()");
1553 buffer_sv = newSV(size);
1554 buffer = SvGROW(buffer_sv, size+1);
1555 result = i_io_read(ig, buffer, size);
1557 SvCUR_set(buffer_sv, result);
1558 *SvEND(buffer_sv) = '\0';
1559 SvPOK_only(buffer_sv);
1561 PUSHs(sv_2mortal(buffer_sv));
1565 SvREFCNT_dec(buffer_sv);
1569 i_io_gets(ig, size = 8192, eol = NEWLINE)
1579 croak("size too small in call to gets()");
1580 buffer_sv = sv_2mortal(newSV(size+1));
1581 buffer = SvPVX(buffer_sv);
1582 result = i_io_gets(ig, buffer, size+1, eol);
1584 SvCUR_set(buffer_sv, result);
1585 *SvEND(buffer_sv) = '\0';
1586 SvPOK_only(buffer_sv);
1592 i_io_write(ig, data_sv)
1599 data = SvPVbyte(data_sv, size);
1600 RETVAL = i_io_write(ig, data, size);
1605 i_io_dump(ig, flags = I_IO_DUMP_DEFAULT)
1610 i_io_set_buffered(ig, flag = 1)
1615 i_io_is_buffered(ig)
1626 MODULE = Imager PACKAGE = Imager
1637 while( (item=i_format_list[i++]) != NULL ) {
1639 PUSHs(sv_2mortal(newSVpv(item,0)));
1643 i_sametype(im, x, y)
1649 i_sametype_chans(im, x, y, channels)
1656 i_init_log(name_sv,level)
1660 const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL;
1662 RETVAL = i_init_log(name, level);
1667 i_log_entry(string,level)
1680 i_img_info(im,info);
1682 PUSHs(sv_2mortal(newSViv(info[0])));
1683 PUSHs(sv_2mortal(newSViv(info[1])));
1684 PUSHs(sv_2mortal(newSViv(info[2])));
1685 PUSHs(sv_2mortal(newSViv(info[3])));
1691 i_img_setmask(im,ch_mask)
1700 i_img_getchannels(im)
1709 sv_2mortal(newSVpv((char *)im->idata, im->bytes))
1717 i_img_get_height(im)
1721 i_img_color_model(im)
1725 i_img_color_channels(im)
1729 i_img_alpha_channel(im)
1732 if (!i_img_alpha_channel(im, &RETVAL))
1738 i_img_is_monochrome(im)
1744 result = i_img_is_monochrome(im, &zero_is_white);
1746 if (GIMME_V == G_ARRAY) {
1749 PUSHs(sv_2mortal(newSViv(zero_is_white)));
1758 i_line(im,x1,y1,x2,y2,val,endp)
1768 i_line_aa(im,x1,y1,x2,y2,val,endp)
1778 i_box(im,x1,y1,x2,y2,val)
1787 i_box_filled(im,x1,y1,x2,y2,val)
1796 i_box_filledf(im,x1,y1,x2,y2,val)
1802 Imager::Color::Float val
1805 i_box_cfill(im,x1,y1,x2,y2,fill)
1811 Imager::FillHandle fill
1814 i_arc(im,x,y,rad,d1,d2,val)
1824 i_arc_aa(im,x,y,rad,d1,d2,val)
1834 i_arc_cfill(im,x,y,rad,d1,d2,fill)
1841 Imager::FillHandle fill
1844 i_arc_aa_cfill(im,x,y,rad,d1,d2,fill)
1851 Imager::FillHandle fill
1855 i_circle_aa(im,x,y,rad,val)
1863 i_circle_aa_fill(im,x,y,rad,fill)
1868 Imager::FillHandle fill
1871 i_circle_out(im,x,y,rad,val)
1879 i_circle_out_aa(im,x,y,rad,val)
1887 i_arc_out(im,x,y,rad,d1,d2,val)
1897 i_arc_out_aa(im,x,y,rad,d1,d2,val)
1908 i_bezier_multi(im,x,y,val)
1917 if (size_x != size_y)
1918 croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
1919 i_bezier_multi(im,size_x,x,y,val);
1922 i_poly_aa_m(im,x,y,mode,val)
1926 i_poly_fill_mode_t mode
1932 if (size_x != size_y)
1933 croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
1934 RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val);
1939 i_poly_aa_cfill_m(im, x, y, mode, fill)
1943 i_poly_fill_mode_t mode
1944 Imager::FillHandle fill
1949 if (size_x != size_y)
1950 croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
1951 RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill);
1956 i_poly_poly_aa(im, polys, mode, color)
1958 i_polygon_list polys
1959 i_poly_fill_mode_t mode
1962 RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color);
1967 i_poly_poly_aa_cfill(im, polys, mode, fill)
1969 i_polygon_list polys
1970 i_poly_fill_mode_t mode
1971 Imager::FillHandle fill
1973 RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill);
1978 i_flood_fill(im,seedx,seedy,dcol)
1985 i_flood_cfill(im,seedx,seedy,fill)
1989 Imager::FillHandle fill
1992 i_flood_fill_border(im,seedx,seedy,dcol, border)
1997 Imager::Color border
2000 i_flood_cfill_border(im,seedx,seedy,fill, border)
2004 Imager::FillHandle fill
2005 Imager::Color border
2009 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
2021 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
2038 i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy)
2049 i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0)
2062 i_compose_mask(out, src, mask, out_left, out_top, src_left, src_top, mask_left, mask_top, width, height, combine = ic_normal, opacity = 0.0)
2078 i_combine(src_av, channels_av = NULL)
2082 i_img **imgs = NULL;
2084 int *channels = NULL;
2089 in_count = av_len(src_av) + 1;
2091 imgs = mymalloc(sizeof(i_img*) * in_count);
2092 channels = mymalloc(sizeof(int) * in_count);
2093 for (i = 0; i < in_count; ++i) {
2094 psv = av_fetch(src_av, i, 0);
2095 if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) {
2098 croak("imgs must contain only images");
2100 tmp = SvIV((SV*)SvRV(*psv));
2101 imgs[i] = INT2PTR(i_img*, tmp);
2103 (psv = av_fetch(channels_av, i, 0)) != NULL &&
2105 channels[i] = SvIV(*psv);
2112 RETVAL = i_combine(imgs, channels, in_count);
2119 i_flipxy(im, direction)
2124 i_rotate90(im, degrees)
2129 i_rotate_exact(im, amount, ...)
2133 i_color *backp = NULL;
2134 i_fcolor *fbackp = NULL;
2138 /* extract the bg colors if any */
2139 /* yes, this is kind of strange */
2140 for (i = 2; i < items; ++i) {
2142 if (sv_derived_from(sv1, "Imager::Color")) {
2143 IV tmp = SvIV((SV*)SvRV(sv1));
2144 backp = INT2PTR(i_color *, tmp);
2146 else if (sv_derived_from(sv1, "Imager::Color::Float")) {
2147 IV tmp = SvIV((SV*)SvRV(sv1));
2148 fbackp = INT2PTR(i_fcolor *, tmp);
2151 RETVAL = i_rotate_exact_bg(im, amount, backp, fbackp);
2156 i_matrix_transform(im, xsize, ysize, matrix_av, ...)
2166 i_color *backp = NULL;
2167 i_fcolor *fbackp = NULL;
2169 len=av_len(matrix_av)+1;
2172 for (i = 0; i < len; ++i) {
2173 sv1=(*(av_fetch(matrix_av,i,0)));
2174 matrix[i] = SvNV(sv1);
2178 /* extract the bg colors if any */
2179 /* yes, this is kind of strange */
2180 for (i = 4; i < items; ++i) {
2182 if (sv_derived_from(sv1, "Imager::Color")) {
2183 IV tmp = SvIV((SV*)SvRV(sv1));
2184 backp = INT2PTR(i_color *, tmp);
2186 else if (sv_derived_from(sv1, "Imager::Color::Float")) {
2187 IV tmp = SvIV((SV*)SvRV(sv1));
2188 fbackp = INT2PTR(i_fcolor *, tmp);
2191 RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
2196 i_gaussian(im,stdev)
2201 i_unsharp_mask(im,stdev,scale)
2216 len = av_len(coef) + 1;
2217 c_coef=mymalloc( len * sizeof(double) );
2218 for(i = 0; i < len; i++) {
2219 sv1 = (*(av_fetch(coef, i, 0)));
2220 c_coef[i] = (double)SvNV(sv1);
2222 RETVAL = i_conv(im, c_coef, len);
2228 i_convert(src, avmain)
2240 outchan = av_len(avmain)+1;
2241 /* find the biggest */
2243 for (j=0; j < outchan; ++j) {
2244 temp = av_fetch(avmain, j, 0);
2245 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
2246 avsub = (AV*)SvRV(*temp);
2247 len = av_len(avsub)+1;
2252 i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
2256 coeff = mymalloc(sizeof(double) * outchan * inchan);
2257 for (j = 0; j < outchan; ++j) {
2258 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
2259 len = av_len(avsub)+1;
2260 for (i = 0; i < len; ++i) {
2261 temp = av_fetch(avsub, i, 0);
2263 coeff[i+j*inchan] = SvNV(*temp);
2265 coeff[i+j*inchan] = 0;
2268 coeff[i++ + j*inchan] = 0;
2270 RETVAL = i_convert(src, coeff, outchan, inchan);
2281 unsigned int mask = 0;
2286 unsigned char (*maps)[256];
2288 len = av_len(pmaps_av)+1;
2289 if (im->channels < len)
2291 maps = mymalloc( len * sizeof(unsigned char [256]) );
2292 for (j=0; j<len ; j++) {
2293 temp = av_fetch(pmaps_av, j, 0);
2294 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
2295 avsub = (AV*)SvRV(*temp);
2296 if(av_len(avsub) != 255)
2299 for (i=0; i<256 ; i++) {
2301 temp = av_fetch(avsub, i, 0);
2302 val = temp ? SvIV(*temp) : 0;
2304 if (val>255) val = 255;
2309 i_map(im, maps, mask);
2321 i_img_diffd(im1,im2)
2326 i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL)
2336 _is_color_object(sv)
2340 RETVAL = SvOK(sv) && SvROK(sv) &&
2341 (sv_derived_from(sv, "Imager::Color")
2342 || sv_derived_from(sv, "Imager::Color::Float"));
2354 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
2356 #define TT_DESTROY(handle) i_tt_destroy(handle)
2360 Imager::Font::TT handle
2365 (void)items; /* avoid unused warning */
2371 MODULE = Imager PACKAGE = Imager
2375 i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1)
2376 Imager::Font::TT handle
2390 str = SvPV(str_sv, len);
2395 RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
2396 len, smooth, utf8, align);
2402 i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1)
2403 Imager::Font::TT handle
2417 str = SvPV(str_sv, len);
2422 RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
2423 smooth, utf8, align);
2429 i_tt_bbox(handle,point,str_sv,utf8)
2430 Imager::Font::TT handle
2435 i_img_dim cords[BOUNDING_BOX_COUNT];
2441 str = SvPV(str_sv, len);
2446 if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
2448 for (i = 0; i < rc; ++i) {
2449 PUSHs(sv_2mortal(newSViv(cords[i])));
2454 i_tt_has_chars(handle, text_sv, utf8)
2455 Imager::Font::TT handle
2466 text = SvPV(text_sv, len);
2468 if (SvUTF8(text_sv))
2471 work = mymalloc(len);
2472 count = i_tt_has_chars(handle, text, len, utf8, work);
2473 if (GIMME_V == G_ARRAY) {
2476 for (i = 0; i < count; ++i) {
2477 PUSHs(boolSV(work[i]));
2483 PUSHs(sv_2mortal(newSVpv(work, count)));
2488 i_tt_dump_names(handle)
2489 Imager::Font::TT handle
2492 i_tt_face_name(handle)
2493 Imager::Font::TT handle
2498 len = i_tt_face_name(handle, name, sizeof(name));
2501 PUSHs(sv_2mortal(newSVpv(name, len-1)));
2505 i_tt_glyph_name(handle, text_sv, utf8 = 0)
2506 Imager::Font::TT handle
2517 text = SvPV(text_sv, work_len);
2519 if (SvUTF8(text_sv))
2526 ch = i_utf8_advance(&text, &len);
2528 i_push_error(0, "invalid UTF8 character");
2537 if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
2538 PUSHs(sv_2mortal(newSVpv(name, 0)));
2541 PUSHs(&PL_sv_undef);
2548 i_test_format_probe(ig, length)
2553 i_readpnm_wiol(ig, allow_incomplete)
2555 int allow_incomplete
2559 i_readpnm_multi_wiol(ig, allow_incomplete)
2561 int allow_incomplete
2567 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
2570 for (i = 0; i < count; ++i) {
2571 SV *sv = sv_newmortal();
2572 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
2579 i_writeppm_wiol(im, ig)
2588 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
2597 i_writeraw_wiol(im,ig)
2602 i_writebmp_wiol(im,ig)
2607 i_readbmp_wiol(ig, allow_incomplete=0)
2609 int allow_incomplete
2613 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
2622 idlen = SvCUR(ST(4));
2623 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
2629 i_readtga_wiol(ig, length)
2637 i_scaleaxis(im,Value,Axis)
2643 i_scale_nn(im,scx,scy)
2649 i_scale_mixing(im, width, height)
2659 i_count_colors(im,maxc)
2664 i_get_anonymous_color_histo(im, maxc = 0x40000000)
2669 unsigned int * col_usage = NULL;
2672 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
2676 EXTEND(SP, col_cnt);
2677 for (i = 0; i < col_cnt; i++) {
2678 PUSHs(sv_2mortal(newSViv( col_usage[i])));
2684 i_transform(im, opx, opy, parm)
2690 STRLEN size_opx, size_opy, size_parm;
2693 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
2695 SV *result_sv = sv_newmortal();
2697 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2702 i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
2728 in_imgs_count = av_len(av_in_imgs)+1;
2729 for (i = 0; i < in_imgs_count; ++i) {
2730 sv1 = *av_fetch(av_in_imgs, i, 0);
2731 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2732 croak("sv_in_img must contain only images");
2735 if (in_imgs_count > 0) {
2736 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2737 for (i = 0; i < in_imgs_count; ++i) {
2738 sv1 = *av_fetch(av_in_imgs,i,0);
2739 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2740 croak("Parameter 5 must contain only images");
2742 tmp = SvIV((SV*)SvRV(sv1));
2743 in_imgs[i] = INT2PTR(i_img*, tmp);
2747 /* no input images */
2750 /* default the output size from the first input if possible */
2752 width = SvIV(sv_width);
2753 else if (in_imgs_count)
2754 width = in_imgs[0]->xsize;
2756 croak("No output image width supplied");
2758 if (SvOK(sv_height))
2759 height = SvIV(sv_height);
2760 else if (in_imgs_count)
2761 height = in_imgs[0]->ysize;
2763 croak("No output image height supplied");
2765 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
2766 if (ops_len % sizeof(struct rm_op))
2767 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2768 ops_count = ops_len / sizeof(struct rm_op);
2770 n_regs_count = av_len(av_n_regs)+1;
2771 n_regs = mymalloc(n_regs_count * sizeof(double));
2772 for (i = 0; i < n_regs_count; ++i) {
2773 sv1 = *av_fetch(av_n_regs,i,0);
2775 n_regs[i] = SvNV(sv1);
2777 c_regs_count = av_len(av_c_regs)+1;
2778 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2779 /* I don't bother initializing the colou?r registers */
2781 result=i_transform2(width, height, channels, ops, ops_count,
2782 n_regs, n_regs_count,
2783 c_regs, c_regs_count, in_imgs, in_imgs_count);
2789 SV *result_sv = sv_newmortal();
2791 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2797 i_contrast(im,intensity)
2810 i_noise(im,amount,type)
2816 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2826 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2845 i_postlevels(im,levels)
2855 i_watermark(im,wmark,tx,ty,pixdiff)
2857 Imager::ImgRaw wmark
2864 i_autolevels(im,lsat,usat,skew)
2871 i_autolevels_mono(im,lsat,usat)
2877 i_radnoise(im,xo,yo,rscale,ascale)
2885 i_turbnoise(im, xo, yo, scale)
2893 i_gradgen(im, xo, yo, ac, dmeasure)
2904 if (size_xo != size_yo || size_xo != size_ac)
2905 croak("i_gradgen: x, y and color arrays must be the same size");
2907 croak("Usage: i_gradgen array refs must have more than 1 entry each");
2908 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
2911 i_diff_image(im, im2, mindist=0)
2917 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2927 double ssample_param
2931 i_fountain_seg *segs;
2933 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2934 croak("i_fountain: argument 11 must be an array ref");
2936 asegs = (AV *)SvRV(ST(10));
2937 segs = load_fount_segs(aTHX_ asegs, &count);
2938 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
2939 super_sample, ssample_param, count, segs);
2945 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2954 double ssample_param
2958 i_fountain_seg *segs;
2960 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
2961 croak("i_fountain: argument 11 must be an array ref");
2963 asegs = (AV *)SvRV(ST(9));
2964 segs = load_fount_segs(aTHX_ asegs, &count);
2965 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
2966 super_sample, ssample_param, count, segs);
2972 i_new_fill_opacity(other_fill, alpha_mult)
2973 Imager::FillHandle other_fill
2984 errors = i_errors();
2986 while (errors[i].msg) {
2988 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
2989 if (!av_store(av, 0, sv)) {
2992 sv = newSViv(errors[i].code);
2993 if (!av_store(av, 1, sv)) {
2996 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
3004 i_push_error(code, msg)
3009 i_nearest_color(im, ...)
3024 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3025 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3026 croak("i_nearest_color: Second argument must be an array ref");
3027 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
3028 croak("i_nearest_color: Third argument must be an array ref");
3029 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
3030 croak("i_nearest_color: Fourth argument must be an array ref");
3031 axx = (AV *)SvRV(ST(1));
3032 ayy = (AV *)SvRV(ST(2));
3033 ac = (AV *)SvRV(ST(3));
3034 dmeasure = (int)SvIV(ST(4));
3036 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
3037 num = num <= av_len(ac) ? num : av_len(ac);
3039 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
3040 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3041 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3042 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
3043 for(i = 0; i<num; i++) {
3044 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3045 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
3046 sv = *av_fetch(ac, i, 0);
3047 if ( !sv_derived_from(sv, "Imager::Color") ) {
3048 free(axx); free(ayy); free(ac);
3049 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3051 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
3053 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3067 rc=DSO_open(filename,&evstr);
3071 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3072 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
3075 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3081 DSO_close(dso_handle)
3085 DSO_funclist(dso_handle_v)
3089 DSO_handle *dso_handle;
3090 func_ptr *functions;
3092 dso_handle=(DSO_handle*)dso_handle_v;
3093 functions = DSO_funclist(dso_handle);
3095 while( functions[i].name != NULL) {
3097 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
3099 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
3103 DSO_call(handle,func_index,hv)
3108 DSO_call( (DSO_handle *)handle,func_index,hv);
3111 i_get_pixel(im, x, y)
3116 RETVAL = (i_color *)mymalloc(sizeof(i_color));
3117 memset(RETVAL, 0, sizeof(*RETVAL));
3118 if (i_gpix(im, x, y, RETVAL) != 0) {
3127 i_ppix(im, x, y, cl)
3134 i_img_pal_new(x, y, channels, maxpal)
3141 i_img_to_pal(src, quant_hv)
3148 memset(&quant, 0, sizeof(quant));
3150 quant.mc_size = 256;
3151 ip_handle_quant_opts(aTHX_ &quant, quant_hv);
3152 RETVAL = i_img_to_pal(src, &quant);
3154 ip_copy_colors_back(aTHX_ quant_hv, &quant);
3156 ip_cleanup_quant_opts(aTHX_ &quant);
3165 i_img_make_palette(HV *quant_hv, ...)
3167 size_t count = items - 1;
3169 i_img **imgs = NULL;
3173 croak("Please supply at least one image (%d)", (int)count);
3174 imgs = mymalloc(sizeof(i_img *) * count);
3175 for (i = 0; i < count; ++i) {
3176 SV *img_sv = ST(i + 1);
3177 if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
3178 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3182 croak("Image %d is not an image object", (int)i+1);
3185 memset(&quant, 0, sizeof(quant));
3187 quant.mc_size = 256;
3188 ip_handle_quant_opts(aTHX_ &quant, quant_hv);
3189 i_quant_makemap(&quant, imgs, count);
3190 EXTEND(SP, quant.mc_count);
3191 for (i = 0; i < quant.mc_count; ++i) {
3192 SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i);
3195 ip_cleanup_quant_opts(aTHX_ &quant);
3210 work = mymalloc((r-l) * sizeof(i_palidx));
3211 count = i_gpal(im, l, r, y, work);
3212 if (GIMME_V == G_ARRAY) {
3214 for (i = 0; i < count; ++i) {
3215 PUSHs(sv_2mortal(newSViv(work[i])));
3220 PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx))));
3225 if (GIMME_V != G_ARRAY) {
3227 PUSHs(&PL_sv_undef);
3232 i_ppal(im, l, y, ...)
3241 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
3242 for (i=0; i < items-3; ++i) {
3243 work[i] = SvIV(ST(i+3));
3245 validate_i_ppal(im, work, items - 3);
3246 RETVAL = i_ppal(im, l, l+items-3, y, work);
3255 i_ppal_p(im, l, y, data)
3261 i_palidx const *work;
3264 work = (i_palidx const *)SvPV(data, len);
3265 len /= sizeof(i_palidx);
3267 validate_i_ppal(im, work, len);
3268 RETVAL = i_ppal(im, l, l+len, y, work);
3277 i_addcolors(im, ...)
3284 croak("i_addcolors: no colors to add");
3285 colors = mymalloc((items-1) * sizeof(i_color));
3286 for (i=0; i < items-1; ++i) {
3287 if (sv_isobject(ST(i+1))
3288 && sv_derived_from(ST(i+1), "Imager::Color")) {
3289 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
3290 colors[i] = *INT2PTR(i_color *, tmp);
3294 croak("i_addcolor: pixels must be Imager::Color objects");
3297 RETVAL = i_addcolors(im, colors, items-1);
3303 i_setcolors(im, index, ...)
3311 croak("i_setcolors: no colors to add");
3312 colors = mymalloc((items-2) * sizeof(i_color));
3313 for (i=0; i < items-2; ++i) {
3314 if (sv_isobject(ST(i+2))
3315 && sv_derived_from(ST(i+2), "Imager::Color")) {
3316 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
3317 colors[i] = *INT2PTR(i_color *, tmp);
3321 croak("i_setcolors: pixels must be Imager::Color objects");
3324 RETVAL = i_setcolors(im, index, colors, items-2);
3330 i_getcolors(im, index, count=1)
3339 croak("i_getcolors: count must be positive");
3340 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
3341 if (i_getcolors(im, index, colors, count)) {
3343 for (i = 0; i < count; ++i) {
3344 SV *sv = make_i_color_sv(aTHX_ colors+i);
3358 i_findcolor(im, color)
3362 if (!i_findcolor(im, color, &RETVAL)) {
3381 i_gsamp(im, l, r, y, channels)
3386 i_channel_list channels
3392 data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
3393 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
3394 if (GIMME_V == G_ARRAY) {
3396 for (i = 0; i < count; ++i)
3397 PUSHs(sv_2mortal(newSViv(data[i])));
3401 PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t))));
3406 if (GIMME_V != G_ARRAY) {
3412 i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
3420 i_channel_list channels
3427 croak("No channel numbers supplied to g_samp()");
3429 data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
3430 count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
3431 for (i = 0; i < count; ++i) {
3432 av_store(target, i+offset, newSVuv(data[i]));
3444 i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
3449 i_channel_list channels
3451 i_img_dim data_offset
3452 i_img_dim pixel_count
3461 data_count = av_len(data_av) + 1;
3462 if (data_offset < 0) {
3463 croak("data_offset must be non-negative");
3465 if (data_offset > data_count) {
3466 croak("data_offset greater than number of samples supplied");
3468 if (pixel_count == -1 ||
3469 data_offset + pixel_count * channels.count > data_count) {
3470 pixel_count = (data_count - data_offset) / channels.count;
3473 data_used = pixel_count * channels.count;
3474 data = mymalloc(sizeof(unsigned) * data_count);
3475 for (i = 0; i < data_used; ++i)
3476 data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
3478 RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
3479 channels.count, bits);
3487 i_psamp(im, x, y, channels, data, offset = 0, width = -1)
3491 i_channel_list channels
3500 i_push_error(0, "offset must be non-negative");
3504 if (offset > data.count) {
3505 i_push_error(0, "offset greater than number of samples supplied");
3508 data.samples += offset;
3509 data.count -= offset;
3512 width * channels.count > data.count) {
3513 width = data.count / channels.count;
3516 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
3521 i_psampf(im, x, y, channels, data, offset = 0, width = -1)
3525 i_channel_list channels
3534 i_push_error(0, "offset must be non-negative");
3538 if (offset > data.count) {
3539 i_push_error(0, "offset greater than number of samples supplied");
3542 data.samples += offset;
3543 data.count -= offset;
3546 width * channels.count > data.count) {
3547 width = data.count / channels.count;
3550 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
3555 i_img_masked_new(targ, mask, x, y, w, h)
3565 if (!sv_isobject(ST(1))
3566 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
3567 croak("i_img_masked_new: parameter 2 must undef or an image");
3569 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
3573 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
3578 i_plin(im, l, y, ...)
3589 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3590 /* supplied as a byte string */
3591 work = (i_color *)SvPV(ST(3), len);
3592 count = len / sizeof(i_color);
3593 if (count * sizeof(i_color) != len) {
3594 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
3596 RETVAL = i_plin(im, l, l+count, y, work);
3599 work = mymalloc(sizeof(i_color) * (items-3));
3600 for (i=0; i < items-3; ++i) {
3601 if (sv_isobject(ST(i+3))
3602 && sv_derived_from(ST(i+3), "Imager::Color")) {
3603 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3604 work[i] = *INT2PTR(i_color *, tmp);
3608 croak("i_plin: pixels must be Imager::Color objects");
3611 RETVAL = i_plin(im, l, l+items-3, y, work);
3622 i_ppixf(im, x, y, cl)
3626 Imager::Color::Float cl
3629 i_gsampf(im, l, r, y, channels)
3634 i_channel_list channels
3640 data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
3641 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
3642 if (GIMME_V == G_ARRAY) {
3644 for (i = 0; i < count; ++i)
3645 PUSHs(sv_2mortal(newSVnv(data[i])));
3649 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
3654 if (GIMME_V != G_ARRAY) {
3660 i_plinf(im, l, y, ...)
3671 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3672 /* supplied as a byte string */
3673 work = (i_fcolor *)SvPV(ST(3), len);
3674 count = len / sizeof(i_fcolor);
3675 if (count * sizeof(i_fcolor) != len) {
3676 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
3678 RETVAL = i_plinf(im, l, l+count, y, work);
3681 work = mymalloc(sizeof(i_fcolor) * (items-3));
3682 for (i=0; i < items-3; ++i) {
3683 if (sv_isobject(ST(i+3))
3684 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
3685 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3686 work[i] = *INT2PTR(i_fcolor *, tmp);
3690 croak("i_plinf: pixels must be Imager::Color::Float objects");
3694 RETVAL = i_plinf(im, l, l+items-3, y, work);
3704 Imager::Color::Float
3710 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
3711 memset(RETVAL, 0, sizeof(*RETVAL));
3712 if (i_gpixf(im, x, y, RETVAL) != 0) {
3730 vals = mymalloc((r-l) * sizeof(i_color));
3731 memset(vals, 0, (r-l) * sizeof(i_color));
3732 count = i_glin(im, l, r, y, vals);
3733 if (GIMME_V == G_ARRAY) {
3735 for (i = 0; i < count; ++i) {
3736 SV *sv = make_i_color_sv(aTHX_ vals+i);
3742 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color))));
3748 i_glinf(im, l, r, y)
3758 for (i = 0; i < MAXCHANNELS; ++i)
3759 zero.channel[i] = 0;
3761 vals = mymalloc((r-l) * sizeof(i_fcolor));
3762 for (i = 0; i < r-l; ++i)
3764 count = i_glinf(im, l, r, y, vals);
3765 if (GIMME_V == G_ARRAY) {
3767 for (i = 0; i < count; ++i) {
3769 i_fcolor *col = mymalloc(sizeof(i_fcolor));
3771 sv = sv_newmortal();
3772 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
3778 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor))));
3784 i_img_8_new(x, y, ch)
3790 i_img_16_new(x, y, ch)
3800 i_img_double_new(x, y, ch)
3810 i_tags_addn(im, name_sv, code, idata)
3819 SvGETMAGIC(name_sv);
3821 name = SvPV_nomg(name_sv, len);
3824 RETVAL = i_tags_addn(&im->tags, name, code, idata);
3829 i_tags_add(im, name_sv, code, data_sv, idata)
3840 SvGETMAGIC(name_sv);
3842 name = SvPV_nomg(name_sv, len);
3845 SvGETMAGIC(data_sv);
3847 data = SvPV(data_sv, len);
3852 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
3857 i_tags_find(im, name, start)
3864 if (i_tags_find(&im->tags, name, start, &entry)) {
3873 i_tags_findn(im, code, start)
3880 if (i_tags_findn(&im->tags, code, start, &entry)) {
3890 i_tags_delete(im, entry)
3894 RETVAL = i_tags_delete(&im->tags, entry);
3899 i_tags_delbyname(im, name)
3903 RETVAL = i_tags_delbyname(&im->tags, name);
3908 i_tags_delbycode(im, code)
3912 RETVAL = i_tags_delbycode(&im->tags, code);
3917 i_tags_get(im, index)
3921 if (index >= 0 && index < im->tags.count) {
3922 i_img_tag *entry = im->tags.tags + index;
3926 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
3929 PUSHs(sv_2mortal(newSViv(entry->code)));
3932 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
3935 PUSHs(sv_2mortal(newSViv(entry->idata)));
3940 i_tags_get_string(im, what_sv)
3944 char const *name = NULL;
3948 if (SvIOK(what_sv)) {
3949 code = SvIV(what_sv);
3953 name = SvPV_nolen(what_sv);
3956 if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
3958 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
3965 RETVAL = im->tags.count;
3971 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
3975 Imager::FillHandle fill
3978 IFILL_CLONE_SKIP(...)
3980 (void)items; /* avoid unused warning for XS variable */
3985 MODULE = Imager PACKAGE = Imager
3988 i_new_fill_solid(cl, combine)
3993 i_new_fill_solidf(cl, combine)
3994 Imager::Color::Float cl
3998 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4007 unsigned char *cust_hatch;
4010 SvGETMAGIC(cust_hatch_sv);
4011 if (SvOK(cust_hatch_sv)) {
4012 cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
4016 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
4021 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4022 Imager::Color::Float fg
4023 Imager::Color::Float bg
4030 unsigned char *cust_hatch;
4033 SvGETMAGIC(cust_hatch_sv);
4034 if (SvOK(cust_hatch_sv)) {
4035 cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
4039 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
4044 i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
4058 SvGETMAGIC(matrix_sv);
4059 if (!SvOK(matrix_sv)) {
4063 if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
4064 croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
4065 av=(AV*)SvRV(matrix_sv);
4069 for (i = 0; i < len; ++i) {
4070 sv1=(*(av_fetch(av,i,0)));
4071 matrix[i] = SvNV(sv1);
4077 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
4081 MODULE = Imager PACKAGE = Imager::Internal::Hlines PREFIX=i_int_hlines_
4083 # this class is only exposed for testing
4086 i_int_hlines_testing()
4088 #if i_int_hlines_testing()
4090 Imager::Internal::Hlines
4091 i_int_hlines_new(start_y, count_y, start_x, count_x)
4097 Imager::Internal::Hlines
4098 i_int_hlines_new_img(im)
4102 i_int_hlines_add(hlines, y, minx, width)
4103 Imager::Internal::Hlines hlines
4109 i_int_hlines_DESTROY(hlines)
4110 Imager::Internal::Hlines hlines
4113 i_int_hlines_dump(hlines)
4114 Imager::Internal::Hlines hlines
4117 i_int_hlines_CLONE_SKIP(cls)
4121 MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
4124 im_context_DESTROY(ctx)
4127 #ifdef PERL_IMPLICIT_CONTEXT
4130 im_context_CLONE(...)
4134 /* the following sv_setref_pv() will free this inc */
4135 im_context_refinc(MY_CXT.ctx, "CLONE");
4136 MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
4137 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
4142 PERL_SET_GLOBAL_CALLBACKS;
4143 PERL_PL_SET_GLOBAL_CALLBACKS;
4144 #ifdef PERL_IMPLICIT_CONTEXT
4150 start_context(aTHX);
4151 im_get_context = perl_get_context;