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,
544 lookup_name(const struct value_name *names, int count, char *name, int def_value, int push_errors, const char *id, int *failed)
551 for (i = 0; i < count; ++i)
552 if (strEQ(names[i].name, name))
553 return names[i].value;
556 i_push_errorf(0, "unknown value '%s' for %s", name, id);
563 static struct value_name transp_names[] =
566 { "threshold", tr_threshold },
567 { "errdiff", tr_errdiff },
568 { "ordered", tr_ordered, },
571 static struct value_name make_color_names[] =
573 { "none", mc_none, },
574 { "webmap", mc_web_map, },
575 { "addi", mc_addi, },
576 { "mediancut", mc_median_cut, },
577 { "mono", mc_mono, },
578 { "monochrome", mc_mono, },
579 { "gray", mc_gray, },
580 { "gray4", mc_gray4, },
581 { "gray16", mc_gray16, },
584 static struct value_name translate_names[] =
586 { "giflib", pt_giflib, },
587 { "closest", pt_closest, },
588 { "perturb", pt_perturb, },
589 { "errdiff", pt_errdiff, },
592 static struct value_name errdiff_names[] =
594 { "floyd", ed_floyd, },
595 { "jarvis", ed_jarvis, },
596 { "stucki", ed_stucki, },
597 { "custom", ed_custom, },
600 static struct value_name orddith_names[] =
602 { "random", od_random, },
603 { "dot8", od_dot8, },
604 { "dot4", od_dot4, },
605 { "hline", od_hline, },
606 { "vline", od_vline, },
607 { "/line", od_slashline, },
608 { "slashline", od_slashline, },
609 { "\\line", od_backline, },
610 { "backline", od_backline, },
611 { "tiny", od_tiny, },
612 { "custom", od_custom, },
615 /* look through the hash for quantization options */
617 ip_handle_quant_opts_low(pTHX_ i_quantize *quant, HV *hv, int push_errors)
625 quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color));
627 sv = hv_fetch(hv, "transp", 6, 0);
628 if (sv && *sv && (str = SvPV(*sv, len))) {
630 lookup_name(transp_names, sizeof(transp_names)/sizeof(*transp_names),
631 str, tr_none, push_errors, "transp", &failed);
634 if (quant->transp != tr_none) {
635 quant->tr_threshold = 127;
636 sv = hv_fetch(hv, "tr_threshold", 12, 0);
638 quant->tr_threshold = SvIV(*sv);
640 if (quant->transp == tr_errdiff) {
641 sv = hv_fetch(hv, "tr_errdiff", 10, 0);
642 if (sv && *sv && (str = SvPV(*sv, len)))
643 quant->tr_errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "tr_errdiff", &failed);
647 if (quant->transp == tr_ordered) {
648 quant->tr_orddith = od_tiny;
649 sv = hv_fetch(hv, "tr_orddith", 10, 0);
650 if (sv && *sv && (str = SvPV(*sv, len))) {
651 quant->tr_orddith = lookup_name(orddith_names, sizeof(orddith_names)/sizeof(*orddith_names), str, od_random, push_errors, "tr_orddith", &failed);
656 if (quant->tr_orddith == od_custom) {
657 sv = hv_fetch(hv, "tr_map", 6, 0);
658 if (sv && *sv && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
659 AV *av = (AV*)SvRV(*sv);
660 len = av_len(av) + 1;
661 if (len > sizeof(quant->tr_custom))
662 len = sizeof(quant->tr_custom);
663 for (i = 0; i < len; ++i) {
664 SV **sv2 = av_fetch(av, i, 0);
666 quant->tr_custom[i] = SvIV(*sv2);
669 while (i < sizeof(quant->tr_custom))
670 quant->tr_custom[i++] = 0;
675 quant->make_colors = mc_median_cut;
676 sv = hv_fetch(hv, "make_colors", 11, 0);
677 if (sv && *sv && (str = SvPV(*sv, len))) {
679 lookup_name(make_color_names, sizeof(make_color_names)/sizeof(*make_color_names), str, mc_median_cut, push_errors, "make_colors", &failed);
683 sv = hv_fetch(hv, "colors", 6, 0);
684 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
685 /* needs to be an array of Imager::Color
686 note that the caller allocates the mc_color array and sets mc_size
688 AV *av = (AV *)SvRV(*sv);
689 quant->mc_count = av_len(av)+1;
690 if (quant->mc_count > quant->mc_size)
691 quant->mc_count = quant->mc_size;
692 for (i = 0; i < quant->mc_count; ++i) {
693 SV **sv1 = av_fetch(av, i, 0);
694 if (sv1 && *sv1 && SvROK(*sv1) && sv_derived_from(*sv1, "Imager::Color")) {
695 i_color *col = INT2PTR(i_color *, SvIV((SV*)SvRV(*sv1)));
696 quant->mc_colors[i] = *col;
698 else if (push_errors) {
699 i_push_errorf(0, "colors[%d] isn't an Imager::Color object", i);
704 sv = hv_fetch(hv, "max_colors", 10, 0);
707 if (i <= quant->mc_size && i >= quant->mc_count)
711 quant->translate = pt_closest;
712 sv = hv_fetch(hv, "translate", 9, 0);
713 if (sv && *sv && (str = SvPV(*sv, len))) {
714 quant->translate = lookup_name(translate_names, sizeof(translate_names)/sizeof(*translate_names), str, pt_closest, push_errors, "translate", &failed);
718 sv = hv_fetch(hv, "errdiff", 7, 0);
719 if (sv && *sv && (str = SvPV(*sv, len))) {
720 quant->errdiff = lookup_name(errdiff_names, sizeof(errdiff_names)/sizeof(*errdiff_names), str, ed_floyd, push_errors, "errdiff", &failed);
724 if (quant->translate == pt_errdiff && quant->errdiff == ed_custom) {
725 /* get the error diffusion map */
726 sv = hv_fetch(hv, "errdiff_width", 13, 0);
728 quant->ed_width = SvIV(*sv);
729 sv = hv_fetch(hv, "errdiff_height", 14, 0);
731 quant->ed_height = SvIV(*sv);
732 sv = hv_fetch(hv, "errdiff_orig", 12, 0);
734 quant->ed_orig = SvIV(*sv);
735 if (quant->ed_width > 0 && quant->ed_height > 0) {
737 quant->ed_map = mymalloc(sizeof(int)*quant->ed_width*quant->ed_height);
738 sv = hv_fetch(hv, "errdiff_map", 11, 0);
739 if (sv && *sv && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVAV) {
740 AV *av = (AV*)SvRV(*sv);
741 len = av_len(av) + 1;
742 if (len > quant->ed_width * quant->ed_height)
743 len = quant->ed_width * quant->ed_height;
744 for (i = 0; i < len; ++i) {
745 SV **sv2 = av_fetch(av, i, 0);
748 if (push_errors && iv < 0) {
749 i_push_errorf(0, "errdiff_map values must be non-negative, errdiff[%d] is negative", i);
752 quant->ed_map[i] = iv;
753 sum += quant->ed_map[i];
759 myfree(quant->ed_map);
761 quant->errdiff = ed_floyd;
763 i_push_error(0, "error diffusion map must contain some non-zero values");
769 sv = hv_fetch(hv, "perturb", 7, 0);
771 quant->perturb = SvIV(*sv);
777 ip_cleanup_quant_opts(pTHX_ i_quantize *quant) {
778 myfree(quant->mc_colors);
780 myfree(quant->ed_map);
784 ip_handle_quant_opts2(pTHX_ i_quantize *quant, HV *hv) {
785 int result = ip_handle_quant_opts_low(aTHX_ quant, hv, 1);
787 ip_cleanup_quant_opts(aTHX_ quant);
793 ip_handle_quant_opts(pTHX_ i_quantize *quant, HV *hv) {
794 (void)ip_handle_quant_opts_low(aTHX_ quant, hv, 0);
797 /* copies the color map from the hv into the colors member of the HV */
799 ip_copy_colors_back(pTHX_ HV *hv, i_quantize *quant) {
805 sv = hv_fetch(hv, "colors", 6, 0);
806 if (!sv || !*sv || !SvROK(*sv) || SvTYPE(SvRV(*sv)) != SVt_PVAV) {
811 av = (AV *)SvRV(*sv);
813 av_extend(av, quant->mc_count+1);
814 for (i = 0; i < quant->mc_count; ++i) {
815 i_color *in = quant->mc_colors+i;
816 Imager__Color c = ICL_new_internal(in->rgb.r, in->rgb.g, in->rgb.b, 255);
817 work = sv_newmortal();
818 sv_setref_pv(work, "Imager::Color", (void *)c);
824 static struct value_name
825 poly_fill_mode_names[] =
827 { "evenodd", i_pfm_evenodd },
828 { "nonzero", i_pfm_nonzero }
831 static i_poly_fill_mode_t
832 S_get_poly_fill_mode(pTHX_ SV *sv) {
833 if (looks_like_number(sv)) {
835 if (work < (IV)i_pfm_evenodd || work > (IV)i_pfm_nonzero)
836 work = (IV)i_pfm_evenodd;
837 return (i_poly_fill_mode_t)work;
840 return (i_poly_fill_mode_t)lookup_name
841 (poly_fill_mode_names, ARRAY_COUNT(poly_fill_mode_names),
842 SvPV_nolen(sv), i_pfm_evenodd, 0, NULL, NULL);
847 S_get_polygon_list(pTHX_ i_polygon_list *polys, SV *sv) {
853 if (!SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV)
854 croak("polys must be an arrayref");
857 polys->count = av_len(av) + 1;
858 if (polys->count < 1)
859 croak("polypolygon: no polygons provided");
860 s = malloc_temp(aTHX_ sizeof(i_polygon_t) * polys->count);
861 for (i = 0; i < polys->count; ++i) {
862 SV **poly_sv = av_fetch(av, i, 0);
866 double *x_data, *y_data;
871 croak("poly_polygon: nothing found for polygon %d", i);
872 /* needs to be another av */
873 SvGETMAGIC(*poly_sv);
874 if (!SvOK(*poly_sv) || !SvROK(*poly_sv) || SvTYPE(SvRV(*poly_sv)) != SVt_PVAV)
875 croak("poly_polygon: polygon %d isn't an arrayref", i);
876 poly_av = (AV*)SvRV(*poly_sv);
877 /* with two elements */
878 if (av_len(poly_av) != 1)
879 croak("poly_polygon: polygon %d should contain two arrays", i);
880 x_sv = av_fetch(poly_av, 0, 0);
881 y_sv = av_fetch(poly_av, 1, 0);
883 croak("poly_polygon: polygon %d has no x elements", i);
885 croak("poly_polygon: polygon %d has no y elements", i);
888 if (!SvOK(*x_sv) || !SvROK(*x_sv) || SvTYPE(SvRV(*x_sv)) != SVt_PVAV)
889 croak("poly_polygon: polygon %d x elements isn't an array", i);
890 if (!SvOK(*y_sv) || !SvROK(*y_sv) || SvTYPE(SvRV(*y_sv)) != SVt_PVAV)
891 croak("poly_polygon: polygon %d y elements isn't an array", i);
892 x_av = (AV*)SvRV(*x_sv);
893 y_av = (AV*)SvRV(*y_sv);
894 if (av_len(x_av) != av_len(y_av))
895 croak("poly_polygon: polygon %d x and y arrays different lengths", i+1);
896 point_count = av_len(x_av)+1;
897 x_data = malloc_temp(aTHX_ sizeof(double) * point_count * 2);
898 y_data = x_data + point_count;
900 for (j = 0; j < point_count; ++j) {
901 SV **x_item_sv = av_fetch(x_av, j, 0);
902 SV **y_item_sv = av_fetch(y_av, j, 0);
903 x_data[j] = x_item_sv ? SvNV(*x_item_sv) : 0;
904 y_data[j] = y_item_sv ? SvNV(*y_item_sv) : 0;
908 s[i].count = point_count;
913 /* loads the segments of a fountain fill into an array */
914 static i_fountain_seg *
915 load_fount_segs(pTHX_ AV *asegs, int *count) {
916 /* Each element of segs must contain:
917 [ start, middle, end, c0, c1, segtype, colortrans ]
918 start, middle, end are doubles from 0 to 1
919 c0, c1 are Imager::Color::Float or Imager::Color objects
920 segtype, colortrans are ints
924 i_fountain_seg *segs;
928 *count = av_len(asegs)+1;
930 croak("i_fountain must have at least one segment");
931 segs = mymalloc(sizeof(i_fountain_seg) * *count);
932 for(i = 0; i < *count; i++) {
933 SV **sv1 = av_fetch(asegs, i, 0);
934 if (!sv1 || !*sv1 || !SvROK(*sv1)
935 || SvTYPE(SvRV(*sv1)) != SVt_PVAV) {
937 croak("i_fountain: segs must be an arrayref of arrayrefs");
939 aseg = (AV *)SvRV(*sv1);
940 if (av_len(aseg) != 7-1) {
942 croak("i_fountain: a segment must have 7 members");
944 for (j = 0; j < 3; ++j) {
945 SV **sv2 = av_fetch(aseg, j, 0);
948 croak("i_fountain: XS error");
950 work[j] = SvNV(*sv2);
952 segs[i].start = work[0];
953 segs[i].middle = work[1];
954 segs[i].end = work[2];
955 for (j = 0; j < 2; ++j) {
956 SV **sv3 = av_fetch(aseg, 3+j, 0);
957 if (!sv3 || !*sv3 || !SvROK(*sv3) ||
958 (!sv_derived_from(*sv3, "Imager::Color")
959 && !sv_derived_from(*sv3, "Imager::Color::Float"))) {
961 croak("i_fountain: segs must contain colors in elements 3 and 4");
963 if (sv_derived_from(*sv3, "Imager::Color::Float")) {
964 segs[i].c[j] = *INT2PTR(i_fcolor *, SvIV((SV *)SvRV(*sv3)));
967 i_color c = *INT2PTR(i_color *, SvIV((SV *)SvRV(*sv3)));
969 for (ch = 0; ch < MAXCHANNELS; ++ch) {
970 segs[i].c[j].channel[ch] = c.channel[ch] / 255.0;
974 for (j = 0; j < 2; ++j) {
975 SV **sv2 = av_fetch(aseg, j+5, 0);
978 croak("i_fountain: XS error");
980 worki[j] = SvIV(*sv2);
982 segs[i].type = worki[0];
983 segs[i].color = worki[1];
989 /* validates the indexes supplied to i_ppal
991 i_ppal() doesn't do that for speed, but I'm not comfortable doing that
996 validate_i_ppal(i_img *im, i_palidx const *indexes, int count) {
997 int color_count = i_colorcount(im);
1000 if (color_count == -1)
1001 croak("i_plin() called on direct color image");
1003 for (i = 0; i < count; ++i) {
1004 if (indexes[i] >= color_count) {
1005 croak("i_plin() called with out of range color index %d (max %d)",
1006 indexes[i], color_count-1);
1011 /* I don't think ICLF_* names belong at the C interface
1012 this makes the XS code think we have them, to let us avoid
1013 putting function bodies in the XS code
1015 #define ICLF_new_internal(r, g, b, a) i_fcolor_new((r), (g), (b), (a))
1016 #define ICLF_DESTROY(cl) i_fcolor_destroy(cl)
1019 #define i_log_enabled() 1
1021 #define i_log_enabled() 0
1024 #if i_int_hlines_testing()
1026 typedef i_int_hlines *Imager__Internal__Hlines;
1028 static i_int_hlines *
1029 i_int_hlines_new(i_img_dim start_y, i_img_dim count_y, i_img_dim start_x, i_img_dim count_x) {
1030 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
1031 i_int_init_hlines(result, start_y, count_y, start_x, count_x);
1036 static i_int_hlines *
1037 i_int_hlines_new_img(i_img *im) {
1038 i_int_hlines *result = mymalloc(sizeof(i_int_hlines));
1039 i_int_init_hlines_img(result, im);
1045 i_int_hlines_DESTROY(i_int_hlines *hlines) {
1046 i_int_hlines_destroy(hlines);
1050 #define i_int_hlines_CLONE_SKIP(cls) 1
1052 static int seg_compare(const void *vleft, const void *vright) {
1053 const i_int_hline_seg *left = vleft;
1054 const i_int_hline_seg *right = vright;
1056 return left->minx - right->minx;
1060 i_int_hlines_dump(i_int_hlines *hlines) {
1062 SV *dump = newSVpvf("start_y: %" i_DF " limit_y: %" i_DF " start_x: %" i_DF " limit_x: %" i_DF"\n",
1063 i_DFc(hlines->start_y), i_DFc(hlines->limit_y), i_DFc(hlines->start_x), i_DFc(hlines->limit_x));
1066 for (y = hlines->start_y; y < hlines->limit_y; ++y) {
1067 i_int_hline_entry *entry = hlines->entries[y-hlines->start_y];
1070 /* sort the segments, if any */
1072 qsort(entry->segs, entry->count, sizeof(i_int_hline_seg), seg_compare);
1074 sv_catpvf(dump, " %" i_DF " (%" i_DF "):", i_DFc(y), i_DFc(entry->count));
1075 for (i = 0; i < entry->count; ++i) {
1076 sv_catpvf(dump, " [%" i_DF ", %" i_DF ")", i_DFc(entry->segs[i].minx),
1077 i_DFc(entry->segs[i].x_limit));
1079 sv_catpv(dump, "\n");
1089 i_sv_off_t(pTHX_ SV *sv) {
1090 #if LSEEKSIZE > IVSIZE
1091 return (off_t)SvNV(sv);
1093 return (off_t)SvIV(sv);
1098 i_new_sv_off_t(pTHX_ off_t off) {
1099 #if LSEEKSIZE > IVSIZE
1100 return newSVnv(off);
1102 return newSViv(off);
1106 static im_pl_ext_funcs im_perl_funcs =
1108 IMAGER_PL_API_VERSION,
1109 IMAGER_PL_API_LEVEL,
1110 ip_handle_quant_opts,
1111 ip_cleanup_quant_opts,
1112 ip_copy_colors_back,
1113 ip_handle_quant_opts2
1116 #define PERL_PL_SET_GLOBAL_CALLBACKS \
1117 sv_setiv(get_sv(PERL_PL_FUNCTION_TABLE_NAME, 1), PTR2IV(&im_perl_funcs));
1119 #define IIM_new i_img_8_new
1120 #define IIM_DESTROY i_img_destroy
1123 #ifdef IMEXIF_ENABLE
1124 #define i_exif_enabled() 1
1126 #define i_exif_enabled() 0
1129 /* trying to use more C style names, map them here */
1130 #define i_io_DESTROY(ig) io_glue_destroy(ig)
1132 #define i_img_get_width(im) ((im)->xsize)
1133 #define i_img_get_height(im) ((im)->ysize)
1135 #define i_img_epsilonf() (DBL_EPSILON * 4)
1137 /* avoid some xsubpp strangeness */
1138 #define NEWLINE '\n'
1140 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
1143 ICL_new_internal(r,g,b,a)
1155 ICL_set_internal(cl,r,g,b,a)
1179 PUSHs(sv_2mortal(newSViv(cl->rgba.r)));
1180 PUSHs(sv_2mortal(newSViv(cl->rgba.g)));
1181 PUSHs(sv_2mortal(newSViv(cl->rgba.b)));
1182 PUSHs(sv_2mortal(newSViv(cl->rgba.a)));
1188 RETVAL = mymalloc(sizeof(i_color));
1190 i_hsv_to_rgb(RETVAL);
1198 RETVAL = mymalloc(sizeof(i_color));
1200 i_rgb_to_hsv(RETVAL);
1206 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
1208 Imager::Color::Float
1209 ICLF_new_internal(r, g, b, a)
1217 Imager::Color::Float cl
1221 Imager::Color::Float cl
1225 EXTEND(SP, MAXCHANNELS);
1226 for (ch = 0; ch < MAXCHANNELS; ++ch) {
1227 /* printf("%d: %g\n", ch, cl->channel[ch]); */
1228 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
1232 ICLF_set_internal(cl,r,g,b,a)
1233 Imager::Color::Float cl
1246 Imager::Color::Float
1248 Imager::Color::Float c
1250 RETVAL = mymalloc(sizeof(i_fcolor));
1252 i_hsv_to_rgbf(RETVAL);
1256 Imager::Color::Float
1258 Imager::Color::Float c
1260 RETVAL = mymalloc(sizeof(i_fcolor));
1262 i_rgb_to_hsvf(RETVAL);
1266 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
1280 MODULE = Imager PACKAGE = Imager
1294 io_new_buffer(data_sv)
1298 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1305 io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE)
1311 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1319 unsigned char* data;
1323 tlength = io_slurp(ig, &data);
1324 RETVAL = newSVpv((char *)data,tlength);
1331 i_set_image_file_limits(width, height, bytes)
1337 i_get_image_file_limits()
1339 i_img_dim width, height;
1342 if (i_get_image_file_limits(&width, &height, &bytes)) {
1344 PUSHs(sv_2mortal(newSViv(width)));
1345 PUSHs(sv_2mortal(newSViv(height)));
1346 PUSHs(sv_2mortal(newSVuv(bytes)));
1350 i_int_check_image_file_limits(width, height, channels, sample_size)
1357 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_
1360 io_new_fd(class, fd)
1363 RETVAL = io_new_fd(fd);
1368 io_new_buffer(class, data_sv)
1372 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1379 io_new_cb(class, writecb, readcb, seekcb, closecb)
1385 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1390 io_new_bufchain(class)
1392 RETVAL = io_new_bufchain();
1397 io__new_perlio(class, io)
1400 RETVAL = im_io_new_perlio(aTHX_ io);
1408 unsigned char* data;
1412 tlength = io_slurp(ig, &data);
1413 RETVAL = newSVpv((char *)data,tlength);
1418 MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_
1421 i_io_raw_write(ig, data_sv)
1428 data = SvPVbyte(data_sv, size);
1429 RETVAL = i_io_raw_write(ig, data, size);
1434 i_io_raw_read(ig, buffer_sv, size)
1443 croak("size negative in call to i_io_raw_read()");
1444 /* prevent an undefined value warning if they supplied an
1446 Orginally conditional on !SvOK(), but this will prevent the
1447 downgrade from croaking */
1448 sv_setpvn(buffer_sv, "", 0);
1450 if (SvUTF8(buffer_sv))
1451 sv_utf8_downgrade(buffer_sv, FALSE);
1453 buffer = SvGROW(buffer_sv, size+1);
1454 result = i_io_raw_read(ig, buffer, size);
1456 SvCUR_set(buffer_sv, result);
1457 *SvEND(buffer_sv) = '\0';
1458 SvPOK_only(buffer_sv);
1460 PUSHs(sv_2mortal(newSViv(result)));
1466 i_io_raw_read2(ig, size)
1475 croak("size negative in call to i_io_read2()");
1476 buffer_sv = newSV(size);
1477 buffer = SvGROW(buffer_sv, size+1);
1478 result = i_io_raw_read(ig, buffer, size);
1480 SvCUR_set(buffer_sv, result);
1481 *SvEND(buffer_sv) = '\0';
1482 SvPOK_only(buffer_sv);
1484 PUSHs(sv_2mortal(buffer_sv));
1488 SvREFCNT_dec(buffer_sv);
1492 i_io_raw_seek(ig, position, whence)
1506 i_io_CLONE_SKIP(...)
1508 (void)items; /* avoid unused warning for XS variable */
1539 i_io_seek(ig, off, whence)
1545 i_io_peekn(ig, size)
1553 buffer_sv = newSV(size+1);
1554 buffer = SvGROW(buffer_sv, size+1);
1555 result = i_io_peekn(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_read(ig, buffer_sv, size)
1578 croak("size negative in call to i_io_read()");
1579 /* prevent an undefined value warning if they supplied an
1581 Orginally conditional on !SvOK(), but this will prevent the
1582 downgrade from croaking */
1583 sv_setpvn(buffer_sv, "", 0);
1585 if (SvUTF8(buffer_sv))
1586 sv_utf8_downgrade(buffer_sv, FALSE);
1588 buffer = SvGROW(buffer_sv, size+1);
1589 result = i_io_read(ig, buffer, size);
1591 SvCUR_set(buffer_sv, result);
1592 *SvEND(buffer_sv) = '\0';
1593 SvPOK_only(buffer_sv);
1595 PUSHs(sv_2mortal(newSViv(result)));
1601 i_io_read2(ig, size)
1610 croak("size zero in call to read2()");
1611 buffer_sv = newSV(size);
1612 buffer = SvGROW(buffer_sv, size+1);
1613 result = i_io_read(ig, buffer, size);
1615 SvCUR_set(buffer_sv, result);
1616 *SvEND(buffer_sv) = '\0';
1617 SvPOK_only(buffer_sv);
1619 PUSHs(sv_2mortal(buffer_sv));
1623 SvREFCNT_dec(buffer_sv);
1627 i_io_gets(ig, size = 8192, eol = NEWLINE)
1637 croak("size too small in call to gets()");
1638 buffer_sv = sv_2mortal(newSV(size+1));
1639 buffer = SvPVX(buffer_sv);
1640 result = i_io_gets(ig, buffer, size+1, eol);
1642 SvCUR_set(buffer_sv, result);
1643 *SvEND(buffer_sv) = '\0';
1644 SvPOK_only(buffer_sv);
1650 i_io_write(ig, data_sv)
1657 data = SvPVbyte(data_sv, size);
1658 RETVAL = i_io_write(ig, data, size);
1663 i_io_dump(ig, flags = I_IO_DUMP_DEFAULT)
1668 i_io_set_buffered(ig, flag = 1)
1673 i_io_is_buffered(ig)
1684 MODULE = Imager PACKAGE = Imager
1695 while( (item=i_format_list[i++]) != NULL ) {
1697 PUSHs(sv_2mortal(newSVpv(item,0)));
1701 i_sametype(im, x, y)
1707 i_sametype_chans(im, x, y, channels)
1714 i_init_log(name_sv,level)
1718 const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL;
1720 RETVAL = i_init_log(name, level);
1725 i_log_entry(string,level)
1738 i_img_info(im,info);
1740 PUSHs(sv_2mortal(newSViv(info[0])));
1741 PUSHs(sv_2mortal(newSViv(info[1])));
1742 PUSHs(sv_2mortal(newSViv(info[2])));
1743 PUSHs(sv_2mortal(newSViv(info[3])));
1749 i_img_setmask(im,ch_mask)
1758 i_img_getchannels(im)
1767 sv_2mortal(newSVpv((char *)im->idata, im->bytes))
1775 i_img_get_height(im)
1779 i_img_color_model(im)
1783 i_img_color_channels(im)
1787 i_img_alpha_channel(im)
1790 if (!i_img_alpha_channel(im, &RETVAL))
1796 i_img_is_monochrome(im)
1802 result = i_img_is_monochrome(im, &zero_is_white);
1804 if (GIMME_V == G_ARRAY) {
1807 PUSHs(sv_2mortal(newSViv(zero_is_white)));
1816 i_line(im,x1,y1,x2,y2,val,endp)
1826 i_line_aa(im,x1,y1,x2,y2,val,endp)
1836 i_box(im,x1,y1,x2,y2,val)
1845 i_box_filled(im,x1,y1,x2,y2,val)
1854 i_box_filledf(im,x1,y1,x2,y2,val)
1860 Imager::Color::Float val
1863 i_box_cfill(im,x1,y1,x2,y2,fill)
1869 Imager::FillHandle fill
1872 i_arc(im,x,y,rad,d1,d2,val)
1882 i_arc_aa(im,x,y,rad,d1,d2,val)
1892 i_arc_cfill(im,x,y,rad,d1,d2,fill)
1899 Imager::FillHandle fill
1902 i_arc_aa_cfill(im,x,y,rad,d1,d2,fill)
1909 Imager::FillHandle fill
1913 i_circle_aa(im,x,y,rad,val)
1921 i_circle_aa_fill(im,x,y,rad,fill)
1926 Imager::FillHandle fill
1929 i_circle_out(im,x,y,rad,val)
1937 i_circle_out_aa(im,x,y,rad,val)
1945 i_arc_out(im,x,y,rad,d1,d2,val)
1955 i_arc_out_aa(im,x,y,rad,d1,d2,val)
1966 i_bezier_multi(im,x,y,val)
1975 if (size_x != size_y)
1976 croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
1977 i_bezier_multi(im,size_x,x,y,val);
1980 i_poly_aa_m(im,x,y,mode,val)
1984 i_poly_fill_mode_t mode
1990 if (size_x != size_y)
1991 croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
1992 RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val);
1997 i_poly_aa_cfill_m(im, x, y, mode, fill)
2001 i_poly_fill_mode_t mode
2002 Imager::FillHandle fill
2007 if (size_x != size_y)
2008 croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
2009 RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill);
2014 i_poly_poly_aa(im, polys, mode, color)
2016 i_polygon_list polys
2017 i_poly_fill_mode_t mode
2020 RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color);
2025 i_poly_poly_aa_cfill(im, polys, mode, fill)
2027 i_polygon_list polys
2028 i_poly_fill_mode_t mode
2029 Imager::FillHandle fill
2031 RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill);
2036 i_flood_fill(im,seedx,seedy,dcol)
2043 i_flood_cfill(im,seedx,seedy,fill)
2047 Imager::FillHandle fill
2050 i_flood_fill_border(im,seedx,seedy,dcol, border)
2055 Imager::Color border
2058 i_flood_cfill_border(im,seedx,seedy,fill, border)
2062 Imager::FillHandle fill
2063 Imager::Color border
2067 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
2079 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
2096 i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy)
2107 i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0)
2120 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)
2136 i_combine(src_av, channels_av = NULL)
2140 i_img **imgs = NULL;
2142 int *channels = NULL;
2147 in_count = av_len(src_av) + 1;
2149 imgs = mymalloc(sizeof(i_img*) * in_count);
2150 channels = mymalloc(sizeof(int) * in_count);
2151 for (i = 0; i < in_count; ++i) {
2152 psv = av_fetch(src_av, i, 0);
2153 if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) {
2156 croak("imgs must contain only images");
2158 tmp = SvIV((SV*)SvRV(*psv));
2159 imgs[i] = INT2PTR(i_img*, tmp);
2161 (psv = av_fetch(channels_av, i, 0)) != NULL &&
2163 channels[i] = SvIV(*psv);
2170 RETVAL = i_combine(imgs, channels, in_count);
2177 i_flipxy(im, direction)
2182 i_rotate90(im, degrees)
2187 i_rotate_exact(im, amount, ...)
2191 i_color *backp = NULL;
2192 i_fcolor *fbackp = NULL;
2196 /* extract the bg colors if any */
2197 /* yes, this is kind of strange */
2198 for (i = 2; i < items; ++i) {
2200 if (sv_derived_from(sv1, "Imager::Color")) {
2201 IV tmp = SvIV((SV*)SvRV(sv1));
2202 backp = INT2PTR(i_color *, tmp);
2204 else if (sv_derived_from(sv1, "Imager::Color::Float")) {
2205 IV tmp = SvIV((SV*)SvRV(sv1));
2206 fbackp = INT2PTR(i_fcolor *, tmp);
2209 RETVAL = i_rotate_exact_bg(im, amount, backp, fbackp);
2214 i_matrix_transform(im, xsize, ysize, matrix_av, ...)
2224 i_color *backp = NULL;
2225 i_fcolor *fbackp = NULL;
2227 len=av_len(matrix_av)+1;
2230 for (i = 0; i < len; ++i) {
2231 sv1=(*(av_fetch(matrix_av,i,0)));
2232 matrix[i] = SvNV(sv1);
2236 /* extract the bg colors if any */
2237 /* yes, this is kind of strange */
2238 for (i = 4; i < items; ++i) {
2240 if (sv_derived_from(sv1, "Imager::Color")) {
2241 IV tmp = SvIV((SV*)SvRV(sv1));
2242 backp = INT2PTR(i_color *, tmp);
2244 else if (sv_derived_from(sv1, "Imager::Color::Float")) {
2245 IV tmp = SvIV((SV*)SvRV(sv1));
2246 fbackp = INT2PTR(i_fcolor *, tmp);
2249 RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
2254 i_gaussian(im,stdev)
2259 i_unsharp_mask(im,stdev,scale)
2274 len = av_len(coef) + 1;
2275 c_coef=mymalloc( len * sizeof(double) );
2276 for(i = 0; i < len; i++) {
2277 sv1 = (*(av_fetch(coef, i, 0)));
2278 c_coef[i] = (double)SvNV(sv1);
2280 RETVAL = i_conv(im, c_coef, len);
2286 i_convert(src, avmain)
2298 outchan = av_len(avmain)+1;
2299 /* find the biggest */
2301 for (j=0; j < outchan; ++j) {
2302 temp = av_fetch(avmain, j, 0);
2303 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
2304 avsub = (AV*)SvRV(*temp);
2305 len = av_len(avsub)+1;
2310 i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
2314 coeff = mymalloc(sizeof(double) * outchan * inchan);
2315 for (j = 0; j < outchan; ++j) {
2316 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
2317 len = av_len(avsub)+1;
2318 for (i = 0; i < len; ++i) {
2319 temp = av_fetch(avsub, i, 0);
2321 coeff[i+j*inchan] = SvNV(*temp);
2323 coeff[i+j*inchan] = 0;
2326 coeff[i++ + j*inchan] = 0;
2328 RETVAL = i_convert(src, coeff, outchan, inchan);
2339 unsigned int mask = 0;
2344 unsigned char (*maps)[256];
2346 len = av_len(pmaps_av)+1;
2347 if (im->channels < len)
2349 maps = mymalloc( len * sizeof(unsigned char [256]) );
2350 for (j=0; j<len ; j++) {
2351 temp = av_fetch(pmaps_av, j, 0);
2352 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
2353 avsub = (AV*)SvRV(*temp);
2354 if(av_len(avsub) != 255)
2357 for (i=0; i<256 ; i++) {
2359 temp = av_fetch(avsub, i, 0);
2360 val = temp ? SvIV(*temp) : 0;
2362 if (val>255) val = 255;
2367 i_map(im, maps, mask);
2379 i_img_diffd(im1,im2)
2384 i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL)
2394 _is_color_object(sv)
2398 RETVAL = SvOK(sv) && SvROK(sv) &&
2399 (sv_derived_from(sv, "Imager::Color")
2400 || sv_derived_from(sv, "Imager::Color::Float"));
2412 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
2414 #define TT_DESTROY(handle) i_tt_destroy(handle)
2418 Imager::Font::TT handle
2423 (void)items; /* avoid unused warning */
2429 MODULE = Imager PACKAGE = Imager
2433 i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1)
2434 Imager::Font::TT handle
2448 str = SvPV(str_sv, len);
2453 RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
2454 len, smooth, utf8, align);
2460 i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1)
2461 Imager::Font::TT handle
2475 str = SvPV(str_sv, len);
2480 RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
2481 smooth, utf8, align);
2487 i_tt_bbox(handle,point,str_sv,utf8)
2488 Imager::Font::TT handle
2493 i_img_dim cords[BOUNDING_BOX_COUNT];
2499 str = SvPV(str_sv, len);
2504 if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
2506 for (i = 0; i < rc; ++i) {
2507 PUSHs(sv_2mortal(newSViv(cords[i])));
2512 i_tt_has_chars(handle, text_sv, utf8)
2513 Imager::Font::TT handle
2524 text = SvPV(text_sv, len);
2526 if (SvUTF8(text_sv))
2529 work = mymalloc(len);
2530 count = i_tt_has_chars(handle, text, len, utf8, work);
2531 if (GIMME_V == G_ARRAY) {
2534 for (i = 0; i < count; ++i) {
2535 PUSHs(boolSV(work[i]));
2541 PUSHs(sv_2mortal(newSVpv(work, count)));
2546 i_tt_dump_names(handle)
2547 Imager::Font::TT handle
2550 i_tt_face_name(handle)
2551 Imager::Font::TT handle
2556 len = i_tt_face_name(handle, name, sizeof(name));
2559 PUSHs(sv_2mortal(newSVpv(name, len-1)));
2563 i_tt_glyph_name(handle, text_sv, utf8 = 0)
2564 Imager::Font::TT handle
2575 text = SvPV(text_sv, work_len);
2577 if (SvUTF8(text_sv))
2584 ch = i_utf8_advance(&text, &len);
2586 i_push_error(0, "invalid UTF8 character");
2595 if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
2596 PUSHs(sv_2mortal(newSVpv(name, 0)));
2599 PUSHs(&PL_sv_undef);
2606 i_test_format_probe(ig, length)
2611 i_readpnm_wiol(ig, allow_incomplete)
2613 int allow_incomplete
2617 i_readpnm_multi_wiol(ig, allow_incomplete)
2619 int allow_incomplete
2625 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
2628 for (i = 0; i < count; ++i) {
2629 SV *sv = sv_newmortal();
2630 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
2637 i_writeppm_wiol(im, ig)
2646 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
2655 i_writeraw_wiol(im,ig)
2660 i_writebmp_wiol(im,ig)
2665 i_readbmp_wiol(ig, allow_incomplete=0)
2667 int allow_incomplete
2671 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
2680 idlen = SvCUR(ST(4));
2681 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
2687 i_readtga_wiol(ig, length)
2695 i_scaleaxis(im,Value,Axis)
2701 i_scale_nn(im,scx,scy)
2707 i_scale_mixing(im, width, height)
2717 i_count_colors(im,maxc)
2722 i_get_anonymous_color_histo(im, maxc = 0x40000000)
2727 unsigned int * col_usage = NULL;
2730 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
2734 EXTEND(SP, col_cnt);
2735 for (i = 0; i < col_cnt; i++) {
2736 PUSHs(sv_2mortal(newSViv( col_usage[i])));
2742 i_transform(im, opx, opy, parm)
2748 STRLEN size_opx, size_opy, size_parm;
2751 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
2753 SV *result_sv = sv_newmortal();
2755 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2760 i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
2786 in_imgs_count = av_len(av_in_imgs)+1;
2787 for (i = 0; i < in_imgs_count; ++i) {
2788 sv1 = *av_fetch(av_in_imgs, i, 0);
2789 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2790 croak("sv_in_img must contain only images");
2793 if (in_imgs_count > 0) {
2794 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2795 for (i = 0; i < in_imgs_count; ++i) {
2796 sv1 = *av_fetch(av_in_imgs,i,0);
2797 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2798 croak("Parameter 5 must contain only images");
2800 tmp = SvIV((SV*)SvRV(sv1));
2801 in_imgs[i] = INT2PTR(i_img*, tmp);
2805 /* no input images */
2808 /* default the output size from the first input if possible */
2810 width = SvIV(sv_width);
2811 else if (in_imgs_count)
2812 width = in_imgs[0]->xsize;
2814 croak("No output image width supplied");
2816 if (SvOK(sv_height))
2817 height = SvIV(sv_height);
2818 else if (in_imgs_count)
2819 height = in_imgs[0]->ysize;
2821 croak("No output image height supplied");
2823 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
2824 if (ops_len % sizeof(struct rm_op))
2825 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2826 ops_count = ops_len / sizeof(struct rm_op);
2828 n_regs_count = av_len(av_n_regs)+1;
2829 n_regs = mymalloc(n_regs_count * sizeof(double));
2830 for (i = 0; i < n_regs_count; ++i) {
2831 sv1 = *av_fetch(av_n_regs,i,0);
2833 n_regs[i] = SvNV(sv1);
2835 c_regs_count = av_len(av_c_regs)+1;
2836 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2837 /* I don't bother initializing the colou?r registers */
2839 result=i_transform2(width, height, channels, ops, ops_count,
2840 n_regs, n_regs_count,
2841 c_regs, c_regs_count, in_imgs, in_imgs_count);
2847 SV *result_sv = sv_newmortal();
2849 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2855 i_contrast(im,intensity)
2868 i_noise(im,amount,type)
2874 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2884 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2903 i_postlevels(im,levels)
2913 i_watermark(im,wmark,tx,ty,pixdiff)
2915 Imager::ImgRaw wmark
2922 i_autolevels(im,lsat,usat,skew)
2929 i_autolevels_mono(im,lsat,usat)
2935 i_radnoise(im,xo,yo,rscale,ascale)
2943 i_turbnoise(im, xo, yo, scale)
2951 i_gradgen(im, xo, yo, ac, dmeasure)
2962 if (size_xo != size_yo || size_xo != size_ac)
2963 croak("i_gradgen: x, y and color arrays must be the same size");
2965 croak("Usage: i_gradgen array refs must have more than 1 entry each");
2966 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
2969 i_diff_image(im, im2, mindist=0)
2975 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
2985 double ssample_param
2989 i_fountain_seg *segs;
2991 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
2992 croak("i_fountain: argument 11 must be an array ref");
2994 asegs = (AV *)SvRV(ST(10));
2995 segs = load_fount_segs(aTHX_ asegs, &count);
2996 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
2997 super_sample, ssample_param, count, segs);
3003 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3012 double ssample_param
3016 i_fountain_seg *segs;
3018 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
3019 croak("i_fountain: argument 11 must be an array ref");
3021 asegs = (AV *)SvRV(ST(9));
3022 segs = load_fount_segs(aTHX_ asegs, &count);
3023 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
3024 super_sample, ssample_param, count, segs);
3030 i_new_fill_opacity(other_fill, alpha_mult)
3031 Imager::FillHandle other_fill
3042 errors = i_errors();
3044 while (errors[i].msg) {
3046 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
3047 if (!av_store(av, 0, sv)) {
3050 sv = newSViv(errors[i].code);
3051 if (!av_store(av, 1, sv)) {
3054 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
3062 i_push_error(code, msg)
3067 i_nearest_color(im, ...)
3082 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3083 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3084 croak("i_nearest_color: Second argument must be an array ref");
3085 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
3086 croak("i_nearest_color: Third argument must be an array ref");
3087 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
3088 croak("i_nearest_color: Fourth argument must be an array ref");
3089 axx = (AV *)SvRV(ST(1));
3090 ayy = (AV *)SvRV(ST(2));
3091 ac = (AV *)SvRV(ST(3));
3092 dmeasure = (int)SvIV(ST(4));
3094 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
3095 num = num <= av_len(ac) ? num : av_len(ac);
3097 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
3098 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3099 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3100 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
3101 for(i = 0; i<num; i++) {
3102 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3103 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
3104 sv = *av_fetch(ac, i, 0);
3105 if ( !sv_derived_from(sv, "Imager::Color") ) {
3106 free(axx); free(ayy); free(ac);
3107 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3109 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
3111 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3125 rc=DSO_open(filename,&evstr);
3129 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3130 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
3133 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3139 DSO_close(dso_handle)
3143 DSO_funclist(dso_handle_v)
3147 DSO_handle *dso_handle;
3148 func_ptr *functions;
3150 dso_handle=(DSO_handle*)dso_handle_v;
3151 functions = DSO_funclist(dso_handle);
3153 while( functions[i].name != NULL) {
3155 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
3157 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
3161 DSO_call(handle,func_index,hv)
3166 DSO_call( (DSO_handle *)handle,func_index,hv);
3169 i_get_pixel(im, x, y)
3174 RETVAL = (i_color *)mymalloc(sizeof(i_color));
3175 memset(RETVAL, 0, sizeof(*RETVAL));
3176 if (i_gpix(im, x, y, RETVAL) != 0) {
3185 i_ppix(im, x, y, cl)
3192 i_img_pal_new(x, y, channels, maxpal)
3199 i_img_to_pal(src, quant_hv)
3206 memset(&quant, 0, sizeof(quant));
3208 quant.mc_size = 256;
3210 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3213 RETVAL = i_img_to_pal(src, &quant);
3215 ip_copy_colors_back(aTHX_ quant_hv, &quant);
3217 ip_cleanup_quant_opts(aTHX_ &quant);
3226 i_img_make_palette(HV *quant_hv, ...)
3228 size_t count = items - 1;
3230 i_img **imgs = NULL;
3234 croak("Please supply at least one image (%d)", (int)count);
3235 imgs = mymalloc(sizeof(i_img *) * count);
3236 for (i = 0; i < count; ++i) {
3237 SV *img_sv = ST(i + 1);
3238 if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
3239 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3243 croak("Image %d is not an image object", (int)i+1);
3246 memset(&quant, 0, sizeof(quant));
3248 quant.mc_size = 256;
3249 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3252 i_quant_makemap(&quant, imgs, count);
3253 EXTEND(SP, quant.mc_count);
3254 for (i = 0; i < quant.mc_count; ++i) {
3255 SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i);
3258 ip_cleanup_quant_opts(aTHX_ &quant);
3273 work = mymalloc((r-l) * sizeof(i_palidx));
3274 count = i_gpal(im, l, r, y, work);
3275 if (GIMME_V == G_ARRAY) {
3277 for (i = 0; i < count; ++i) {
3278 PUSHs(sv_2mortal(newSViv(work[i])));
3283 PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx))));
3288 if (GIMME_V != G_ARRAY) {
3290 PUSHs(&PL_sv_undef);
3295 i_ppal(im, l, y, ...)
3304 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
3305 for (i=0; i < items-3; ++i) {
3306 work[i] = SvIV(ST(i+3));
3308 validate_i_ppal(im, work, items - 3);
3309 RETVAL = i_ppal(im, l, l+items-3, y, work);
3318 i_ppal_p(im, l, y, data)
3324 i_palidx const *work;
3327 work = (i_palidx const *)SvPV(data, len);
3328 len /= sizeof(i_palidx);
3330 validate_i_ppal(im, work, len);
3331 RETVAL = i_ppal(im, l, l+len, y, work);
3340 i_addcolors(im, ...)
3347 croak("i_addcolors: no colors to add");
3348 colors = mymalloc((items-1) * sizeof(i_color));
3349 for (i=0; i < items-1; ++i) {
3350 if (sv_isobject(ST(i+1))
3351 && sv_derived_from(ST(i+1), "Imager::Color")) {
3352 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
3353 colors[i] = *INT2PTR(i_color *, tmp);
3357 croak("i_addcolor: pixels must be Imager::Color objects");
3360 RETVAL = i_addcolors(im, colors, items-1);
3366 i_setcolors(im, index, ...)
3374 croak("i_setcolors: no colors to add");
3375 colors = mymalloc((items-2) * sizeof(i_color));
3376 for (i=0; i < items-2; ++i) {
3377 if (sv_isobject(ST(i+2))
3378 && sv_derived_from(ST(i+2), "Imager::Color")) {
3379 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
3380 colors[i] = *INT2PTR(i_color *, tmp);
3384 croak("i_setcolors: pixels must be Imager::Color objects");
3387 RETVAL = i_setcolors(im, index, colors, items-2);
3393 i_getcolors(im, index, count=1)
3402 croak("i_getcolors: count must be positive");
3403 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
3404 if (i_getcolors(im, index, colors, count)) {
3406 for (i = 0; i < count; ++i) {
3407 SV *sv = make_i_color_sv(aTHX_ colors+i);
3421 i_findcolor(im, color)
3425 if (!i_findcolor(im, color, &RETVAL)) {
3444 i_gsamp(im, l, r, y, channels)
3449 i_channel_list channels
3455 data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
3456 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
3457 if (GIMME_V == G_ARRAY) {
3459 for (i = 0; i < count; ++i)
3460 PUSHs(sv_2mortal(newSViv(data[i])));
3464 PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t))));
3469 if (GIMME_V != G_ARRAY) {
3475 i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
3483 i_channel_list channels
3490 croak("No channel numbers supplied to g_samp()");
3492 data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
3493 count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
3494 for (i = 0; i < count; ++i) {
3495 av_store(target, i+offset, newSVuv(data[i]));
3507 i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
3512 i_channel_list channels
3514 i_img_dim data_offset
3515 i_img_dim pixel_count
3524 data_count = av_len(data_av) + 1;
3525 if (data_offset < 0) {
3526 croak("data_offset must be non-negative");
3528 if (data_offset > data_count) {
3529 croak("data_offset greater than number of samples supplied");
3531 if (pixel_count == -1 ||
3532 data_offset + pixel_count * channels.count > data_count) {
3533 pixel_count = (data_count - data_offset) / channels.count;
3536 data_used = pixel_count * channels.count;
3537 data = mymalloc(sizeof(unsigned) * data_count);
3538 for (i = 0; i < data_used; ++i)
3539 data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
3541 RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
3542 channels.count, bits);
3550 i_psamp(im, x, y, channels, data, offset = 0, width = -1)
3554 i_channel_list channels
3563 i_push_error(0, "offset must be non-negative");
3567 if (offset > data.count) {
3568 i_push_error(0, "offset greater than number of samples supplied");
3571 data.samples += offset;
3572 data.count -= offset;
3575 width * channels.count > data.count) {
3576 width = data.count / channels.count;
3579 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
3584 i_psampf(im, x, y, channels, data, offset = 0, width = -1)
3588 i_channel_list channels
3597 i_push_error(0, "offset must be non-negative");
3601 if (offset > data.count) {
3602 i_push_error(0, "offset greater than number of samples supplied");
3605 data.samples += offset;
3606 data.count -= offset;
3609 width * channels.count > data.count) {
3610 width = data.count / channels.count;
3613 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
3618 i_img_masked_new(targ, mask, x, y, w, h)
3628 if (!sv_isobject(ST(1))
3629 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
3630 croak("i_img_masked_new: parameter 2 must undef or an image");
3632 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
3636 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
3641 i_plin(im, l, y, ...)
3652 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3653 /* supplied as a byte string */
3654 work = (i_color *)SvPV(ST(3), len);
3655 count = len / sizeof(i_color);
3656 if (count * sizeof(i_color) != len) {
3657 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
3659 RETVAL = i_plin(im, l, l+count, y, work);
3662 work = mymalloc(sizeof(i_color) * (items-3));
3663 for (i=0; i < items-3; ++i) {
3664 if (sv_isobject(ST(i+3))
3665 && sv_derived_from(ST(i+3), "Imager::Color")) {
3666 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3667 work[i] = *INT2PTR(i_color *, tmp);
3671 croak("i_plin: pixels must be Imager::Color objects");
3674 RETVAL = i_plin(im, l, l+items-3, y, work);
3685 i_ppixf(im, x, y, cl)
3689 Imager::Color::Float cl
3692 i_gsampf(im, l, r, y, channels)
3697 i_channel_list channels
3703 data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
3704 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
3705 if (GIMME_V == G_ARRAY) {
3707 for (i = 0; i < count; ++i)
3708 PUSHs(sv_2mortal(newSVnv(data[i])));
3712 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
3717 if (GIMME_V != G_ARRAY) {
3723 i_plinf(im, l, y, ...)
3734 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3735 /* supplied as a byte string */
3736 work = (i_fcolor *)SvPV(ST(3), len);
3737 count = len / sizeof(i_fcolor);
3738 if (count * sizeof(i_fcolor) != len) {
3739 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
3741 RETVAL = i_plinf(im, l, l+count, y, work);
3744 work = mymalloc(sizeof(i_fcolor) * (items-3));
3745 for (i=0; i < items-3; ++i) {
3746 if (sv_isobject(ST(i+3))
3747 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
3748 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3749 work[i] = *INT2PTR(i_fcolor *, tmp);
3753 croak("i_plinf: pixels must be Imager::Color::Float objects");
3757 RETVAL = i_plinf(im, l, l+items-3, y, work);
3767 Imager::Color::Float
3773 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
3774 memset(RETVAL, 0, sizeof(*RETVAL));
3775 if (i_gpixf(im, x, y, RETVAL) != 0) {
3793 vals = mymalloc((r-l) * sizeof(i_color));
3794 memset(vals, 0, (r-l) * sizeof(i_color));
3795 count = i_glin(im, l, r, y, vals);
3796 if (GIMME_V == G_ARRAY) {
3798 for (i = 0; i < count; ++i) {
3799 SV *sv = make_i_color_sv(aTHX_ vals+i);
3805 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color))));
3811 i_glinf(im, l, r, y)
3821 for (i = 0; i < MAXCHANNELS; ++i)
3822 zero.channel[i] = 0;
3824 vals = mymalloc((r-l) * sizeof(i_fcolor));
3825 for (i = 0; i < r-l; ++i)
3827 count = i_glinf(im, l, r, y, vals);
3828 if (GIMME_V == G_ARRAY) {
3830 for (i = 0; i < count; ++i) {
3832 i_fcolor *col = mymalloc(sizeof(i_fcolor));
3834 sv = sv_newmortal();
3835 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
3841 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor))));
3847 i_img_8_new(x, y, ch)
3853 i_img_16_new(x, y, ch)
3863 i_img_double_new(x, y, ch)
3873 i_tags_addn(im, name_sv, code, idata)
3882 SvGETMAGIC(name_sv);
3884 name = SvPV_nomg(name_sv, len);
3887 RETVAL = i_tags_addn(&im->tags, name, code, idata);
3892 i_tags_add(im, name_sv, code, data_sv, idata)
3903 SvGETMAGIC(name_sv);
3905 name = SvPV_nomg(name_sv, len);
3908 SvGETMAGIC(data_sv);
3910 data = SvPV(data_sv, len);
3915 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
3920 i_tags_find(im, name, start)
3927 if (i_tags_find(&im->tags, name, start, &entry)) {
3936 i_tags_findn(im, code, start)
3943 if (i_tags_findn(&im->tags, code, start, &entry)) {
3953 i_tags_delete(im, entry)
3957 RETVAL = i_tags_delete(&im->tags, entry);
3962 i_tags_delbyname(im, name)
3966 RETVAL = i_tags_delbyname(&im->tags, name);
3971 i_tags_delbycode(im, code)
3975 RETVAL = i_tags_delbycode(&im->tags, code);
3980 i_tags_get(im, index)
3984 if (index >= 0 && index < im->tags.count) {
3985 i_img_tag *entry = im->tags.tags + index;
3989 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
3992 PUSHs(sv_2mortal(newSViv(entry->code)));
3995 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
3998 PUSHs(sv_2mortal(newSViv(entry->idata)));
4003 i_tags_get_string(im, what_sv)
4007 char const *name = NULL;
4011 if (SvIOK(what_sv)) {
4012 code = SvIV(what_sv);
4016 name = SvPV_nolen(what_sv);
4019 if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
4021 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
4028 RETVAL = im->tags.count;
4034 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
4038 Imager::FillHandle fill
4041 IFILL_CLONE_SKIP(...)
4043 (void)items; /* avoid unused warning for XS variable */
4048 MODULE = Imager PACKAGE = Imager
4051 i_new_fill_solid(cl, combine)
4056 i_new_fill_solidf(cl, combine)
4057 Imager::Color::Float cl
4061 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4070 unsigned char *cust_hatch;
4073 SvGETMAGIC(cust_hatch_sv);
4074 if (SvOK(cust_hatch_sv)) {
4075 cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
4079 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
4084 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4085 Imager::Color::Float fg
4086 Imager::Color::Float bg
4093 unsigned char *cust_hatch;
4096 SvGETMAGIC(cust_hatch_sv);
4097 if (SvOK(cust_hatch_sv)) {
4098 cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
4102 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
4107 i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
4121 SvGETMAGIC(matrix_sv);
4122 if (!SvOK(matrix_sv)) {
4126 if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
4127 croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
4128 av=(AV*)SvRV(matrix_sv);
4132 for (i = 0; i < len; ++i) {
4133 sv1=(*(av_fetch(av,i,0)));
4134 matrix[i] = SvNV(sv1);
4140 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
4144 MODULE = Imager PACKAGE = Imager::Internal::Hlines PREFIX=i_int_hlines_
4146 # this class is only exposed for testing
4149 i_int_hlines_testing()
4151 #if i_int_hlines_testing()
4153 Imager::Internal::Hlines
4154 i_int_hlines_new(start_y, count_y, start_x, count_x)
4160 Imager::Internal::Hlines
4161 i_int_hlines_new_img(im)
4165 i_int_hlines_add(hlines, y, minx, width)
4166 Imager::Internal::Hlines hlines
4172 i_int_hlines_DESTROY(hlines)
4173 Imager::Internal::Hlines hlines
4176 i_int_hlines_dump(hlines)
4177 Imager::Internal::Hlines hlines
4180 i_int_hlines_CLONE_SKIP(cls)
4184 MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
4187 im_context_DESTROY(ctx)
4190 #ifdef PERL_IMPLICIT_CONTEXT
4193 im_context_CLONE(...)
4197 /* the following sv_setref_pv() will free this inc */
4198 im_context_refinc(MY_CXT.ctx, "CLONE");
4199 MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
4200 if (MY_CXT.ctx == NULL) {
4201 croak("Failed to clone Imager context");
4203 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
4208 PERL_SET_GLOBAL_CALLBACKS;
4209 PERL_PL_SET_GLOBAL_CALLBACKS;
4210 #ifdef PERL_IMPLICIT_CONTEXT
4216 start_context(aTHX);
4217 im_get_context = perl_get_context;