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_
1269 IIM_new(xsize,ysize,ch)
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_add_file_magic(name, bits_sv, mask_sv)
2616 const unsigned char *bits;
2617 const unsigned char *mask;
2622 bits = SvPV(bits_sv, bits_size);
2623 mask = SvPV(mask_sv, mask_size);
2624 if (bits_size == 0) {
2625 i_push_error(0, "bits must be non-empty");
2628 if (mask_size == 0) {
2629 i_push_error(0, "mask must be non-empty");
2632 if (bits_size != mask_size) {
2633 i_push_error(0, "bits and mask must be the same length");
2637 i_push_error(0, "name must be non-empty");
2640 RETVAL = i_add_file_magic(name, bits, mask, bits_size);
2645 i_readpnm_wiol(ig, allow_incomplete)
2647 int allow_incomplete
2651 i_readpnm_multi_wiol(ig, allow_incomplete)
2653 int allow_incomplete
2659 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
2662 for (i = 0; i < count; ++i) {
2663 SV *sv = sv_newmortal();
2664 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
2671 i_writeppm_wiol(im, ig)
2680 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
2689 i_writeraw_wiol(im,ig)
2694 i_writebmp_wiol(im,ig)
2699 i_readbmp_wiol(ig, allow_incomplete=0)
2701 int allow_incomplete
2705 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
2714 idlen = SvCUR(ST(4));
2715 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
2721 i_readtga_wiol(ig, length)
2729 i_scaleaxis(im,Value,Axis)
2735 i_scale_nn(im,scx,scy)
2741 i_scale_mixing(im, width, height)
2751 i_count_colors(im,maxc)
2756 i_get_anonymous_color_histo(im, maxc = 0x40000000)
2761 unsigned int * col_usage = NULL;
2764 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
2768 EXTEND(SP, col_cnt);
2769 for (i = 0; i < col_cnt; i++) {
2770 PUSHs(sv_2mortal(newSViv( col_usage[i])));
2776 i_transform(im, opx, opy, parm)
2782 STRLEN size_opx, size_opy, size_parm;
2785 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
2787 SV *result_sv = sv_newmortal();
2789 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2794 i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
2820 in_imgs_count = av_len(av_in_imgs)+1;
2821 for (i = 0; i < in_imgs_count; ++i) {
2822 sv1 = *av_fetch(av_in_imgs, i, 0);
2823 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2824 croak("sv_in_img must contain only images");
2827 if (in_imgs_count > 0) {
2828 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2829 for (i = 0; i < in_imgs_count; ++i) {
2830 sv1 = *av_fetch(av_in_imgs,i,0);
2831 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2832 croak("Parameter 5 must contain only images");
2834 tmp = SvIV((SV*)SvRV(sv1));
2835 in_imgs[i] = INT2PTR(i_img*, tmp);
2839 /* no input images */
2842 /* default the output size from the first input if possible */
2844 width = SvIV(sv_width);
2845 else if (in_imgs_count)
2846 width = in_imgs[0]->xsize;
2848 croak("No output image width supplied");
2850 if (SvOK(sv_height))
2851 height = SvIV(sv_height);
2852 else if (in_imgs_count)
2853 height = in_imgs[0]->ysize;
2855 croak("No output image height supplied");
2857 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
2858 if (ops_len % sizeof(struct rm_op))
2859 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2860 ops_count = ops_len / sizeof(struct rm_op);
2862 n_regs_count = av_len(av_n_regs)+1;
2863 n_regs = mymalloc(n_regs_count * sizeof(double));
2864 for (i = 0; i < n_regs_count; ++i) {
2865 sv1 = *av_fetch(av_n_regs,i,0);
2867 n_regs[i] = SvNV(sv1);
2869 c_regs_count = av_len(av_c_regs)+1;
2870 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2871 /* I don't bother initializing the colou?r registers */
2873 result=i_transform2(width, height, channels, ops, ops_count,
2874 n_regs, n_regs_count,
2875 c_regs, c_regs_count, in_imgs, in_imgs_count);
2881 SV *result_sv = sv_newmortal();
2883 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2889 i_contrast(im,intensity)
2902 i_noise(im,amount,type)
2908 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2918 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2937 i_postlevels(im,levels)
2947 i_watermark(im,wmark,tx,ty,pixdiff)
2949 Imager::ImgRaw wmark
2956 i_autolevels(im,lsat,usat,skew)
2963 i_autolevels_mono(im,lsat,usat)
2969 i_radnoise(im,xo,yo,rscale,ascale)
2977 i_turbnoise(im, xo, yo, scale)
2985 i_gradgen(im, xo, yo, ac, dmeasure)
2996 if (size_xo != size_yo || size_xo != size_ac)
2997 croak("i_gradgen: x, y and color arrays must be the same size");
2999 croak("Usage: i_gradgen array refs must have more than 1 entry each");
3000 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
3003 i_diff_image(im, im2, mindist=0)
3009 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3019 im_double ssample_param
3023 i_fountain_seg *segs;
3025 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
3026 croak("i_fountain: argument 11 must be an array ref");
3028 asegs = (AV *)SvRV(ST(10));
3029 segs = load_fount_segs(aTHX_ asegs, &count);
3030 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
3031 super_sample, ssample_param, count, segs);
3037 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3046 im_double ssample_param
3050 i_fountain_seg *segs;
3052 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
3053 croak("i_fountain: argument 11 must be an array ref");
3055 asegs = (AV *)SvRV(ST(9));
3056 segs = load_fount_segs(aTHX_ asegs, &count);
3057 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
3058 super_sample, ssample_param, count, segs);
3064 i_new_fill_opacity(other_fill, alpha_mult)
3065 Imager::FillHandle other_fill
3066 im_double alpha_mult
3076 errors = i_errors();
3078 while (errors[i].msg) {
3080 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
3081 if (!av_store(av, 0, sv)) {
3084 sv = newSViv(errors[i].code);
3085 if (!av_store(av, 1, sv)) {
3088 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
3096 i_push_error(code, msg)
3101 i_nearest_color(im, ...)
3116 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3117 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3118 croak("i_nearest_color: Second argument must be an array ref");
3119 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
3120 croak("i_nearest_color: Third argument must be an array ref");
3121 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
3122 croak("i_nearest_color: Fourth argument must be an array ref");
3123 axx = (AV *)SvRV(ST(1));
3124 ayy = (AV *)SvRV(ST(2));
3125 ac = (AV *)SvRV(ST(3));
3126 dmeasure = (int)SvIV(ST(4));
3128 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
3129 num = num <= av_len(ac) ? num : av_len(ac);
3131 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
3132 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3133 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3134 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
3135 for(i = 0; i<num; i++) {
3136 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3137 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
3138 sv = *av_fetch(ac, i, 0);
3139 if ( !sv_derived_from(sv, "Imager::Color") ) {
3140 free(axx); free(ayy); free(ac);
3141 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3143 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
3145 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3159 rc=DSO_open(filename,&evstr);
3163 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3164 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
3167 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3173 DSO_close(dso_handle)
3177 DSO_funclist(dso_handle_v)
3181 DSO_handle *dso_handle;
3182 func_ptr *functions;
3184 dso_handle=(DSO_handle*)dso_handle_v;
3185 functions = DSO_funclist(dso_handle);
3187 while( functions[i].name != NULL) {
3189 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
3191 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
3195 DSO_call(handle,func_index,hv)
3200 DSO_call( (DSO_handle *)handle,func_index,hv);
3203 i_get_pixel(im, x, y)
3208 RETVAL = (i_color *)mymalloc(sizeof(i_color));
3209 memset(RETVAL, 0, sizeof(*RETVAL));
3210 if (i_gpix(im, x, y, RETVAL) != 0) {
3219 i_ppix(im, x, y, cl)
3226 i_img_pal_new(x, y, channels, maxpal)
3233 i_img_to_pal(src, quant_hv)
3240 memset(&quant, 0, sizeof(quant));
3242 quant.mc_size = 256;
3244 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3247 RETVAL = i_img_to_pal(src, &quant);
3249 ip_copy_colors_back(aTHX_ quant_hv, &quant);
3251 ip_cleanup_quant_opts(aTHX_ &quant);
3260 i_img_make_palette(HV *quant_hv, ...)
3262 size_t count = items - 1;
3264 i_img **imgs = NULL;
3268 croak("Please supply at least one image (%d)", (int)count);
3269 imgs = malloc_temp(aTHX_ count * sizeof(i_img *));
3270 for (i = 0; i < count; ++i) {
3271 SV *img_sv = ST(i + 1);
3272 if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
3273 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3276 croak("Image %d is not an image object", (int)i+1);
3279 memset(&quant, 0, sizeof(quant));
3281 quant.mc_size = 256;
3282 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3285 i_quant_makemap(&quant, imgs, count);
3286 EXTEND(SP, quant.mc_count);
3287 for (i = 0; i < quant.mc_count; ++i) {
3288 SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i);
3291 ip_cleanup_quant_opts(aTHX_ &quant);
3305 work = mymalloc((r-l) * sizeof(i_palidx));
3306 count = i_gpal(im, l, r, y, work);
3307 if (GIMME_V == G_ARRAY) {
3309 for (i = 0; i < count; ++i) {
3310 PUSHs(sv_2mortal(newSViv(work[i])));
3315 PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx))));
3320 if (GIMME_V != G_ARRAY) {
3322 PUSHs(&PL_sv_undef);
3327 i_ppal(im, l, y, ...)
3336 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
3337 for (i=0; i < items-3; ++i) {
3338 work[i] = SvIV(ST(i+3));
3340 validate_i_ppal(im, work, items - 3);
3341 RETVAL = i_ppal(im, l, l+items-3, y, work);
3350 i_ppal_p(im, l, y, data)
3356 i_palidx const *work;
3359 work = (i_palidx const *)SvPV(data, len);
3360 len /= sizeof(i_palidx);
3362 validate_i_ppal(im, work, len);
3363 RETVAL = i_ppal(im, l, l+len, y, work);
3372 i_addcolors(im, ...)
3379 croak("i_addcolors: no colors to add");
3380 colors = mymalloc((items-1) * sizeof(i_color));
3381 for (i=0; i < items-1; ++i) {
3382 if (sv_isobject(ST(i+1))
3383 && sv_derived_from(ST(i+1), "Imager::Color")) {
3384 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
3385 colors[i] = *INT2PTR(i_color *, tmp);
3389 croak("i_addcolor: pixels must be Imager::Color objects");
3392 RETVAL = i_addcolors(im, colors, items-1);
3398 i_setcolors(im, index, ...)
3406 croak("i_setcolors: no colors to add");
3407 colors = mymalloc((items-2) * sizeof(i_color));
3408 for (i=0; i < items-2; ++i) {
3409 if (sv_isobject(ST(i+2))
3410 && sv_derived_from(ST(i+2), "Imager::Color")) {
3411 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
3412 colors[i] = *INT2PTR(i_color *, tmp);
3416 croak("i_setcolors: pixels must be Imager::Color objects");
3419 RETVAL = i_setcolors(im, index, colors, items-2);
3425 i_getcolors(im, index, count=1)
3434 croak("i_getcolors: count must be positive");
3435 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
3436 if (i_getcolors(im, index, colors, count)) {
3438 for (i = 0; i < count; ++i) {
3439 SV *sv = make_i_color_sv(aTHX_ colors+i);
3453 i_findcolor(im, color)
3457 if (!i_findcolor(im, color, &RETVAL)) {
3476 i_gsamp(im, l, r, y, channels)
3481 i_channel_list channels
3487 data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
3488 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
3489 if (GIMME_V == G_ARRAY) {
3491 for (i = 0; i < count; ++i)
3492 PUSHs(sv_2mortal(newSViv(data[i])));
3496 PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t))));
3501 if (GIMME_V != G_ARRAY) {
3507 i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
3515 i_channel_list channels
3522 croak("No channel numbers supplied to g_samp()");
3524 data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
3525 count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
3526 for (i = 0; i < count; ++i) {
3527 av_store(target, i+offset, newSVuv(data[i]));
3539 i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
3544 i_channel_list channels
3546 i_img_dim data_offset
3547 i_img_dim pixel_count
3556 data_count = av_len(data_av) + 1;
3557 if (data_offset < 0) {
3558 croak("data_offset must be non-negative");
3560 if (data_offset > data_count) {
3561 croak("data_offset greater than number of samples supplied");
3563 if (pixel_count == -1 ||
3564 data_offset + pixel_count * channels.count > data_count) {
3565 pixel_count = (data_count - data_offset) / channels.count;
3568 data_used = pixel_count * channels.count;
3569 data = mymalloc(sizeof(unsigned) * data_count);
3570 for (i = 0; i < data_used; ++i)
3571 data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
3573 RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
3574 channels.count, bits);
3582 i_psamp(im, x, y, channels, data, offset = 0, width = -1)
3586 i_channel_list channels
3595 i_push_error(0, "offset must be non-negative");
3599 if (offset > data.count) {
3600 i_push_error(0, "offset greater than number of samples supplied");
3603 data.samples += offset;
3604 data.count -= offset;
3607 width * channels.count > data.count) {
3608 width = data.count / channels.count;
3611 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
3616 i_psampf(im, x, y, channels, data, offset = 0, width = -1)
3620 i_channel_list channels
3629 i_push_error(0, "offset must be non-negative");
3633 if (offset > data.count) {
3634 i_push_error(0, "offset greater than number of samples supplied");
3637 data.samples += offset;
3638 data.count -= offset;
3641 width * channels.count > data.count) {
3642 width = data.count / channels.count;
3645 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
3650 i_img_masked_new(targ, mask, x, y, w, h)
3660 if (!sv_isobject(ST(1))
3661 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
3662 croak("i_img_masked_new: parameter 2 must undef or an image");
3664 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
3668 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
3673 i_plin(im, l, y, ...)
3684 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3685 /* supplied as a byte string */
3686 work = (i_color *)SvPV(ST(3), len);
3687 count = len / sizeof(i_color);
3688 if (count * sizeof(i_color) != len) {
3689 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
3691 RETVAL = i_plin(im, l, l+count, y, work);
3694 work = mymalloc(sizeof(i_color) * (items-3));
3695 for (i=0; i < items-3; ++i) {
3696 if (sv_isobject(ST(i+3))
3697 && sv_derived_from(ST(i+3), "Imager::Color")) {
3698 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3699 work[i] = *INT2PTR(i_color *, tmp);
3703 croak("i_plin: pixels must be Imager::Color objects");
3706 RETVAL = i_plin(im, l, l+items-3, y, work);
3717 i_ppixf(im, x, y, cl)
3721 Imager::Color::Float cl
3724 i_gsampf(im, l, r, y, channels)
3729 i_channel_list channels
3735 data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
3736 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
3737 if (GIMME_V == G_ARRAY) {
3739 for (i = 0; i < count; ++i)
3740 PUSHs(sv_2mortal(newSVnv(data[i])));
3744 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
3749 if (GIMME_V != G_ARRAY) {
3755 i_plinf(im, l, y, ...)
3766 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3767 /* supplied as a byte string */
3768 work = (i_fcolor *)SvPV(ST(3), len);
3769 count = len / sizeof(i_fcolor);
3770 if (count * sizeof(i_fcolor) != len) {
3771 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
3773 RETVAL = i_plinf(im, l, l+count, y, work);
3776 work = mymalloc(sizeof(i_fcolor) * (items-3));
3777 for (i=0; i < items-3; ++i) {
3778 if (sv_isobject(ST(i+3))
3779 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
3780 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3781 work[i] = *INT2PTR(i_fcolor *, tmp);
3785 croak("i_plinf: pixels must be Imager::Color::Float objects");
3789 RETVAL = i_plinf(im, l, l+items-3, y, work);
3799 Imager::Color::Float
3805 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
3806 memset(RETVAL, 0, sizeof(*RETVAL));
3807 if (i_gpixf(im, x, y, RETVAL) != 0) {
3825 vals = mymalloc((r-l) * sizeof(i_color));
3826 memset(vals, 0, (r-l) * sizeof(i_color));
3827 count = i_glin(im, l, r, y, vals);
3828 if (GIMME_V == G_ARRAY) {
3830 for (i = 0; i < count; ++i) {
3831 SV *sv = make_i_color_sv(aTHX_ vals+i);
3837 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color))));
3843 i_glinf(im, l, r, y)
3853 for (i = 0; i < MAXCHANNELS; ++i)
3854 zero.channel[i] = 0;
3856 vals = mymalloc((r-l) * sizeof(i_fcolor));
3857 for (i = 0; i < r-l; ++i)
3859 count = i_glinf(im, l, r, y, vals);
3860 if (GIMME_V == G_ARRAY) {
3862 for (i = 0; i < count; ++i) {
3864 i_fcolor *col = mymalloc(sizeof(i_fcolor));
3866 sv = sv_newmortal();
3867 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
3873 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor))));
3879 i_img_8_new(xsize, ysize, channels)
3885 i_img_16_new(xsize, ysize, channels)
3895 i_img_double_new(xsize, ysize, channels)
3905 i_tags_addn(im, name_sv, code, idata)
3914 SvGETMAGIC(name_sv);
3916 name = SvPV_nomg(name_sv, len);
3919 RETVAL = i_tags_addn(&im->tags, name, code, idata);
3924 i_tags_add(im, name_sv, code, data_sv, idata)
3935 SvGETMAGIC(name_sv);
3937 name = SvPV_nomg(name_sv, len);
3940 SvGETMAGIC(data_sv);
3942 data = SvPV(data_sv, len);
3947 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
3952 i_tags_find(im, name, start)
3959 if (i_tags_find(&im->tags, name, start, &entry)) {
3968 i_tags_findn(im, code, start)
3975 if (i_tags_findn(&im->tags, code, start, &entry)) {
3985 i_tags_delete(im, entry)
3989 RETVAL = i_tags_delete(&im->tags, entry);
3994 i_tags_delbyname(im, name)
3998 RETVAL = i_tags_delbyname(&im->tags, name);
4003 i_tags_delbycode(im, code)
4007 RETVAL = i_tags_delbycode(&im->tags, code);
4012 i_tags_get(im, index)
4016 if (index >= 0 && index < im->tags.count) {
4017 i_img_tag *entry = im->tags.tags + index;
4021 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
4024 PUSHs(sv_2mortal(newSViv(entry->code)));
4027 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
4030 PUSHs(sv_2mortal(newSViv(entry->idata)));
4035 i_tags_get_string(im, what_sv)
4039 char const *name = NULL;
4043 if (SvIOK(what_sv)) {
4044 code = SvIV(what_sv);
4048 name = SvPV_nolen(what_sv);
4051 if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
4053 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
4060 RETVAL = im->tags.count;
4066 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
4070 Imager::FillHandle fill
4073 IFILL_CLONE_SKIP(...)
4075 (void)items; /* avoid unused warning for XS variable */
4080 MODULE = Imager PACKAGE = Imager
4083 i_new_fill_solid(cl, combine)
4088 i_new_fill_solidf(cl, combine)
4089 Imager::Color::Float cl
4093 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4102 unsigned char *cust_hatch;
4105 SvGETMAGIC(cust_hatch_sv);
4106 if (SvOK(cust_hatch_sv)) {
4107 cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
4111 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
4116 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4117 Imager::Color::Float fg
4118 Imager::Color::Float bg
4125 unsigned char *cust_hatch;
4128 SvGETMAGIC(cust_hatch_sv);
4129 if (SvOK(cust_hatch_sv)) {
4130 cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
4134 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
4139 i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
4153 SvGETMAGIC(matrix_sv);
4154 if (!SvOK(matrix_sv)) {
4158 if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
4159 croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
4160 av=(AV*)SvRV(matrix_sv);
4164 for (i = 0; i < len; ++i) {
4165 sv1=(*(av_fetch(av,i,0)));
4166 matrix[i] = SvNV(sv1);
4172 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
4176 MODULE = Imager PACKAGE = Imager::Internal::Hlines PREFIX=i_int_hlines_
4178 # this class is only exposed for testing
4181 i_int_hlines_testing()
4183 #if i_int_hlines_testing()
4185 Imager::Internal::Hlines
4186 i_int_hlines_new(start_y, count_y, start_x, count_x)
4192 Imager::Internal::Hlines
4193 i_int_hlines_new_img(im)
4197 i_int_hlines_add(hlines, y, minx, width)
4198 Imager::Internal::Hlines hlines
4204 i_int_hlines_DESTROY(hlines)
4205 Imager::Internal::Hlines hlines
4208 i_int_hlines_dump(hlines)
4209 Imager::Internal::Hlines hlines
4212 i_int_hlines_CLONE_SKIP(cls)
4216 MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
4219 im_context_DESTROY(ctx)
4222 #ifdef PERL_IMPLICIT_CONTEXT
4225 im_context_CLONE(...)
4229 /* the following sv_setref_pv() will free this inc */
4230 im_context_refinc(MY_CXT.ctx, "CLONE");
4231 MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
4232 if (MY_CXT.ctx == NULL) {
4233 croak("Failed to clone Imager context");
4235 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
4240 PERL_SET_GLOBAL_CALLBACKS;
4241 PERL_PL_SET_GLOBAL_CALLBACKS;
4242 #ifdef PERL_IMPLICIT_CONTEXT
4248 start_context(aTHX);
4249 im_get_context = perl_get_context;