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 #define ICL_red(c) ((c)->rgba.r)
1141 #define ICL_green(c) ((c)->rgba.g)
1142 #define ICL_blue(c) ((c)->rgba.b)
1143 #define ICL_alpha(c) ((c)->rgba.a)
1145 #define ICLF_red(c) ((c)->rgba.r)
1146 #define ICLF_green(c) ((c)->rgba.g)
1147 #define ICLF_blue(c) ((c)->rgba.b)
1148 #define ICLF_alpha(c) ((c)->rgba.a)
1150 MODULE = Imager PACKAGE = Imager::Color PREFIX = ICL_
1153 ICL_new_internal(r,g,b,a)
1165 ICL_set_internal(cl,r,g,b,a)
1189 PUSHs(sv_2mortal(newSViv(cl->rgba.r)));
1190 PUSHs(sv_2mortal(newSViv(cl->rgba.g)));
1191 PUSHs(sv_2mortal(newSViv(cl->rgba.b)));
1192 PUSHs(sv_2mortal(newSViv(cl->rgba.a)));
1198 RETVAL = mymalloc(sizeof(i_color));
1200 i_hsv_to_rgb(RETVAL);
1208 RETVAL = mymalloc(sizeof(i_color));
1210 i_rgb_to_hsv(RETVAL);
1230 MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
1232 Imager::Color::Float
1233 ICLF_new_internal(r, g, b, a)
1241 Imager::Color::Float cl
1245 Imager::Color::Float cl
1249 EXTEND(SP, MAXCHANNELS);
1250 for (ch = 0; ch < MAXCHANNELS; ++ch) {
1251 /* printf("%d: %g\n", ch, cl->channel[ch]); */
1252 PUSHs(sv_2mortal(newSVnv(cl->channel[ch])));
1256 ICLF_set_internal(cl,r,g,b,a)
1257 Imager::Color::Float cl
1270 Imager::Color::Float
1272 Imager::Color::Float c
1274 RETVAL = mymalloc(sizeof(i_fcolor));
1276 i_hsv_to_rgbf(RETVAL);
1280 Imager::Color::Float
1282 Imager::Color::Float c
1284 RETVAL = mymalloc(sizeof(i_fcolor));
1286 i_rgb_to_hsvf(RETVAL);
1292 Imager::Color::Float c
1296 Imager::Color::Float c
1300 Imager::Color::Float c
1304 Imager::Color::Float c
1306 MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
1309 IIM_new(xsize,ysize,ch)
1320 MODULE = Imager PACKAGE = Imager
1334 io_new_buffer(data_sv)
1338 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1345 io_new_cb(writecb, readcb, seekcb, closecb, maxwrite = CBDATA_BUFSIZE)
1351 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1359 unsigned char* data;
1363 tlength = io_slurp(ig, &data);
1364 RETVAL = newSVpv((char *)data,tlength);
1371 i_set_image_file_limits(width, height, bytes)
1377 i_get_image_file_limits()
1379 i_img_dim width, height;
1382 if (i_get_image_file_limits(&width, &height, &bytes)) {
1384 PUSHs(sv_2mortal(newSViv(width)));
1385 PUSHs(sv_2mortal(newSViv(height)));
1386 PUSHs(sv_2mortal(newSVuv(bytes)));
1390 i_int_check_image_file_limits(width, height, channels, sample_size)
1397 MODULE = Imager PACKAGE = Imager::IO PREFIX = io_
1400 io_new_fd(class, fd)
1403 RETVAL = io_new_fd(fd);
1408 io_new_buffer(class, data_sv)
1412 RETVAL = do_io_new_buffer(aTHX_ data_sv);
1419 io_new_cb(class, writecb, readcb, seekcb, closecb)
1425 RETVAL = do_io_new_cb(aTHX_ writecb, readcb, seekcb, closecb);
1430 io_new_bufchain(class)
1432 RETVAL = io_new_bufchain();
1437 io__new_perlio(class, io)
1440 RETVAL = im_io_new_perlio(aTHX_ io);
1448 unsigned char* data;
1452 tlength = io_slurp(ig, &data);
1453 RETVAL = newSVpv((char *)data,tlength);
1458 MODULE = Imager PACKAGE = Imager::IO PREFIX = i_io_
1461 i_io_raw_write(ig, data_sv)
1468 data = SvPVbyte(data_sv, size);
1469 RETVAL = i_io_raw_write(ig, data, size);
1474 i_io_raw_read(ig, buffer_sv, size)
1483 croak("size negative in call to i_io_raw_read()");
1484 /* prevent an undefined value warning if they supplied an
1486 Orginally conditional on !SvOK(), but this will prevent the
1487 downgrade from croaking */
1488 sv_setpvn(buffer_sv, "", 0);
1490 if (SvUTF8(buffer_sv))
1491 sv_utf8_downgrade(buffer_sv, FALSE);
1493 buffer = SvGROW(buffer_sv, size+1);
1494 result = i_io_raw_read(ig, buffer, size);
1496 SvCUR_set(buffer_sv, result);
1497 *SvEND(buffer_sv) = '\0';
1498 SvPOK_only(buffer_sv);
1500 PUSHs(sv_2mortal(newSViv(result)));
1506 i_io_raw_read2(ig, size)
1515 croak("size negative in call to i_io_read2()");
1516 buffer_sv = newSV(size);
1517 buffer = SvGROW(buffer_sv, size+1);
1518 result = i_io_raw_read(ig, buffer, size);
1520 SvCUR_set(buffer_sv, result);
1521 *SvEND(buffer_sv) = '\0';
1522 SvPOK_only(buffer_sv);
1524 PUSHs(sv_2mortal(buffer_sv));
1528 SvREFCNT_dec(buffer_sv);
1532 i_io_raw_seek(ig, position, whence)
1546 i_io_CLONE_SKIP(...)
1548 (void)items; /* avoid unused warning for XS variable */
1579 i_io_seek(ig, off, whence)
1585 i_io_peekn(ig, size)
1593 buffer_sv = newSV(size+1);
1594 buffer = SvGROW(buffer_sv, size+1);
1595 result = i_io_peekn(ig, buffer, size);
1597 SvCUR_set(buffer_sv, result);
1598 *SvEND(buffer_sv) = '\0';
1599 SvPOK_only(buffer_sv);
1601 PUSHs(sv_2mortal(buffer_sv));
1605 SvREFCNT_dec(buffer_sv);
1609 i_io_read(ig, buffer_sv, size)
1618 croak("size negative in call to i_io_read()");
1619 /* prevent an undefined value warning if they supplied an
1621 Orginally conditional on !SvOK(), but this will prevent the
1622 downgrade from croaking */
1623 sv_setpvn(buffer_sv, "", 0);
1625 if (SvUTF8(buffer_sv))
1626 sv_utf8_downgrade(buffer_sv, FALSE);
1628 buffer = SvGROW(buffer_sv, size+1);
1629 result = i_io_read(ig, buffer, size);
1631 SvCUR_set(buffer_sv, result);
1632 *SvEND(buffer_sv) = '\0';
1633 SvPOK_only(buffer_sv);
1635 PUSHs(sv_2mortal(newSViv(result)));
1641 i_io_read2(ig, size)
1650 croak("size zero in call to read2()");
1651 buffer_sv = newSV(size);
1652 buffer = SvGROW(buffer_sv, size+1);
1653 result = i_io_read(ig, buffer, size);
1655 SvCUR_set(buffer_sv, result);
1656 *SvEND(buffer_sv) = '\0';
1657 SvPOK_only(buffer_sv);
1659 PUSHs(sv_2mortal(buffer_sv));
1663 SvREFCNT_dec(buffer_sv);
1667 i_io_gets(ig, size = 8192, eol = NEWLINE)
1677 croak("size too small in call to gets()");
1678 buffer_sv = sv_2mortal(newSV(size+1));
1679 buffer = SvPVX(buffer_sv);
1680 result = i_io_gets(ig, buffer, size+1, eol);
1682 SvCUR_set(buffer_sv, result);
1683 *SvEND(buffer_sv) = '\0';
1684 SvPOK_only(buffer_sv);
1690 i_io_write(ig, data_sv)
1697 data = SvPVbyte(data_sv, size);
1698 RETVAL = i_io_write(ig, data, size);
1703 i_io_dump(ig, flags = I_IO_DUMP_DEFAULT)
1708 i_io_set_buffered(ig, flag = 1)
1713 i_io_is_buffered(ig)
1724 MODULE = Imager PACKAGE = Imager
1735 while( (item=i_format_list[i++]) != NULL ) {
1737 PUSHs(sv_2mortal(newSVpv(item,0)));
1741 i_sametype(im, x, y)
1747 i_sametype_chans(im, x, y, channels)
1754 i_init_log(name_sv,level)
1758 const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL;
1760 RETVAL = i_init_log(name, level);
1765 i_log_entry(string,level)
1778 i_img_info(im,info);
1780 PUSHs(sv_2mortal(newSViv(info[0])));
1781 PUSHs(sv_2mortal(newSViv(info[1])));
1782 PUSHs(sv_2mortal(newSViv(info[2])));
1783 PUSHs(sv_2mortal(newSViv(info[3])));
1789 i_img_setmask(im,ch_mask)
1798 i_img_getchannels(im)
1807 sv_2mortal(newSVpv((char *)im->idata, im->bytes))
1815 i_img_get_height(im)
1819 i_img_color_model(im)
1823 i_img_color_channels(im)
1827 i_img_alpha_channel(im)
1830 if (!i_img_alpha_channel(im, &RETVAL))
1836 i_img_is_monochrome(im)
1842 result = i_img_is_monochrome(im, &zero_is_white);
1844 if (GIMME_V == G_ARRAY) {
1847 PUSHs(sv_2mortal(newSViv(zero_is_white)));
1856 i_line(im,x1,y1,x2,y2,val,endp)
1866 i_line_aa(im,x1,y1,x2,y2,val,endp)
1876 i_box(im,x1,y1,x2,y2,val)
1885 i_box_filled(im,x1,y1,x2,y2,val)
1894 i_box_filledf(im,x1,y1,x2,y2,val)
1900 Imager::Color::Float val
1903 i_box_cfill(im,x1,y1,x2,y2,fill)
1909 Imager::FillHandle fill
1912 i_arc(im,x,y,rad,d1,d2,val)
1922 i_arc_aa(im,x,y,rad,d1,d2,val)
1932 i_arc_cfill(im,x,y,rad,d1,d2,fill)
1939 Imager::FillHandle fill
1942 i_arc_aa_cfill(im,x,y,rad,d1,d2,fill)
1949 Imager::FillHandle fill
1953 i_circle_aa(im,x,y,rad,val)
1961 i_circle_aa_fill(im,x,y,rad,fill)
1966 Imager::FillHandle fill
1969 i_circle_out(im,x,y,rad,val)
1977 i_circle_out_aa(im,x,y,rad,val)
1985 i_arc_out(im,x,y,rad,d1,d2,val)
1995 i_arc_out_aa(im,x,y,rad,d1,d2,val)
2006 i_bezier_multi(im,x,y,val)
2015 if (size_x != size_y)
2016 croak("Imager: x and y arrays to i_bezier_multi must be equal length\n");
2017 i_bezier_multi(im,size_x,x,y,val);
2020 i_poly_aa_m(im,x,y,mode,val)
2024 i_poly_fill_mode_t mode
2030 if (size_x != size_y)
2031 croak("Imager: x and y arrays to i_poly_aa must be equal length\n");
2032 RETVAL = i_poly_aa_m(im, size_x, x, y, mode, val);
2037 i_poly_aa_cfill_m(im, x, y, mode, fill)
2041 i_poly_fill_mode_t mode
2042 Imager::FillHandle fill
2047 if (size_x != size_y)
2048 croak("Imager: x and y arrays to i_poly_aa_cfill must be equal length\n");
2049 RETVAL = i_poly_aa_cfill_m(im, size_x, x, y, mode, fill);
2054 i_poly_poly_aa(im, polys, mode, color)
2056 i_polygon_list polys
2057 i_poly_fill_mode_t mode
2060 RETVAL = i_poly_poly_aa(im, polys.count, polys.polygons, mode, color);
2065 i_poly_poly_aa_cfill(im, polys, mode, fill)
2067 i_polygon_list polys
2068 i_poly_fill_mode_t mode
2069 Imager::FillHandle fill
2071 RETVAL = i_poly_poly_aa_cfill(im, polys.count, polys.polygons, mode, fill);
2076 i_flood_fill(im,seedx,seedy,dcol)
2083 i_flood_cfill(im,seedx,seedy,fill)
2087 Imager::FillHandle fill
2090 i_flood_fill_border(im,seedx,seedy,dcol, border)
2095 Imager::Color border
2098 i_flood_cfill_border(im,seedx,seedy,fill, border)
2102 Imager::FillHandle fill
2103 Imager::Color border
2107 i_copyto(im,src,x1,y1,x2,y2,tx,ty)
2119 i_copyto_trans(im,src,x1,y1,x2,y2,tx,ty,trans)
2136 i_rubthru(im,src,tx,ty,src_minx,src_miny,src_maxx,src_maxy)
2147 i_compose(out, src, out_left, out_top, src_left, src_top, width, height, combine = ic_normal, opacity = 0.0)
2160 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)
2176 i_combine(src_av, channels_av = NULL)
2180 i_img **imgs = NULL;
2182 int *channels = NULL;
2187 in_count = av_len(src_av) + 1;
2189 imgs = mymalloc(sizeof(i_img*) * in_count);
2190 channels = mymalloc(sizeof(int) * in_count);
2191 for (i = 0; i < in_count; ++i) {
2192 psv = av_fetch(src_av, i, 0);
2193 if (!psv || !*psv || !sv_derived_from(*psv, "Imager::ImgRaw")) {
2196 croak("imgs must contain only images");
2198 tmp = SvIV((SV*)SvRV(*psv));
2199 imgs[i] = INT2PTR(i_img*, tmp);
2201 (psv = av_fetch(channels_av, i, 0)) != NULL &&
2203 channels[i] = SvIV(*psv);
2210 RETVAL = i_combine(imgs, channels, in_count);
2217 i_flipxy(im, direction)
2222 i_rotate90(im, degrees)
2227 i_rotate_exact(im, amount, ...)
2231 i_color *backp = NULL;
2232 i_fcolor *fbackp = NULL;
2236 /* extract the bg colors if any */
2237 /* yes, this is kind of strange */
2238 for (i = 2; 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_rotate_exact_bg(im, amount, backp, fbackp);
2254 i_matrix_transform(im, xsize, ysize, matrix_av, ...)
2264 i_color *backp = NULL;
2265 i_fcolor *fbackp = NULL;
2267 len=av_len(matrix_av)+1;
2270 for (i = 0; i < len; ++i) {
2271 sv1=(*(av_fetch(matrix_av,i,0)));
2272 matrix[i] = SvNV(sv1);
2276 /* extract the bg colors if any */
2277 /* yes, this is kind of strange */
2278 for (i = 4; i < items; ++i) {
2280 if (sv_derived_from(sv1, "Imager::Color")) {
2281 IV tmp = SvIV((SV*)SvRV(sv1));
2282 backp = INT2PTR(i_color *, tmp);
2284 else if (sv_derived_from(sv1, "Imager::Color::Float")) {
2285 IV tmp = SvIV((SV*)SvRV(sv1));
2286 fbackp = INT2PTR(i_fcolor *, tmp);
2289 RETVAL = i_matrix_transform_bg(im, xsize, ysize, matrix, backp, fbackp);
2294 i_gaussian(im,stddev)
2299 i_gaussian2(im,stddevX,stddevY)
2305 i_unsharp_mask(im,stdev,scale)
2320 len = av_len(coef) + 1;
2321 c_coef=mymalloc( len * sizeof(double) );
2322 for(i = 0; i < len; i++) {
2323 sv1 = (*(av_fetch(coef, i, 0)));
2324 c_coef[i] = (double)SvNV(sv1);
2326 RETVAL = i_conv(im, c_coef, len);
2332 i_convert(src, avmain)
2344 outchan = av_len(avmain)+1;
2345 /* find the biggest */
2347 for (j=0; j < outchan; ++j) {
2348 temp = av_fetch(avmain, j, 0);
2349 if (temp && SvROK(*temp) && SvTYPE(SvRV(*temp)) == SVt_PVAV) {
2350 avsub = (AV*)SvRV(*temp);
2351 len = av_len(avsub)+1;
2356 i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
2360 coeff = mymalloc(sizeof(double) * outchan * inchan);
2361 for (j = 0; j < outchan; ++j) {
2362 avsub = (AV*)SvRV(*av_fetch(avmain, j, 0));
2363 len = av_len(avsub)+1;
2364 for (i = 0; i < len; ++i) {
2365 temp = av_fetch(avsub, i, 0);
2367 coeff[i+j*inchan] = SvNV(*temp);
2369 coeff[i+j*inchan] = 0;
2372 coeff[i++ + j*inchan] = 0;
2374 RETVAL = i_convert(src, coeff, outchan, inchan);
2385 unsigned int mask = 0;
2390 unsigned char (*maps)[256];
2392 len = av_len(pmaps_av)+1;
2393 if (im->channels < len)
2395 maps = mymalloc( len * sizeof(unsigned char [256]) );
2396 for (j=0; j<len ; j++) {
2397 temp = av_fetch(pmaps_av, j, 0);
2398 if (temp && SvROK(*temp) && (SvTYPE(SvRV(*temp)) == SVt_PVAV) ) {
2399 avsub = (AV*)SvRV(*temp);
2400 if(av_len(avsub) != 255)
2403 for (i=0; i<256 ; i++) {
2405 temp = av_fetch(avsub, i, 0);
2406 val = temp ? SvIV(*temp) : 0;
2408 if (val>255) val = 255;
2413 i_map(im, maps, mask);
2425 i_img_diffd(im1,im2)
2430 i_img_samef(im1, im2, epsilon = i_img_epsilonf(), what=NULL)
2440 _is_color_object(sv)
2444 RETVAL = SvOK(sv) && SvROK(sv) &&
2445 (sv_derived_from(sv, "Imager::Color")
2446 || sv_derived_from(sv, "Imager::Color::Float"));
2458 MODULE = Imager PACKAGE = Imager::Font::TT PREFIX=TT_
2460 #define TT_DESTROY(handle) i_tt_destroy(handle)
2464 Imager::Font::TT handle
2469 (void)items; /* avoid unused warning */
2475 MODULE = Imager PACKAGE = Imager
2479 i_tt_text(handle,im,xb,yb,cl,points,str_sv,smooth,utf8,align=1)
2480 Imager::Font::TT handle
2494 str = SvPV(str_sv, len);
2499 RETVAL = i_tt_text(handle, im, xb, yb, cl, points, str,
2500 len, smooth, utf8, align);
2506 i_tt_cp(handle,im,xb,yb,channel,points,str_sv,smooth,utf8,align=1)
2507 Imager::Font::TT handle
2521 str = SvPV(str_sv, len);
2526 RETVAL = i_tt_cp(handle, im, xb, yb, channel, points, str, len,
2527 smooth, utf8, align);
2533 i_tt_bbox(handle,point,str_sv,utf8)
2534 Imager::Font::TT handle
2539 i_img_dim cords[BOUNDING_BOX_COUNT];
2545 str = SvPV(str_sv, len);
2550 if ((rc=i_tt_bbox(handle,point,str,len,cords, utf8))) {
2552 for (i = 0; i < rc; ++i) {
2553 PUSHs(sv_2mortal(newSViv(cords[i])));
2558 i_tt_has_chars(handle, text_sv, utf8)
2559 Imager::Font::TT handle
2570 text = SvPV(text_sv, len);
2572 if (SvUTF8(text_sv))
2575 work = mymalloc(len);
2576 count = i_tt_has_chars(handle, text, len, utf8, work);
2577 if (GIMME_V == G_ARRAY) {
2580 for (i = 0; i < count; ++i) {
2581 PUSHs(boolSV(work[i]));
2587 PUSHs(sv_2mortal(newSVpv(work, count)));
2592 i_tt_dump_names(handle)
2593 Imager::Font::TT handle
2596 i_tt_face_name(handle)
2597 Imager::Font::TT handle
2602 len = i_tt_face_name(handle, name, sizeof(name));
2605 PUSHs(sv_2mortal(newSVpv(name, len-1)));
2609 i_tt_glyph_name(handle, text_sv, utf8 = 0)
2610 Imager::Font::TT handle
2621 text = SvPV(text_sv, work_len);
2623 if (SvUTF8(text_sv))
2630 ch = i_utf8_advance(&text, &len);
2632 i_push_error(0, "invalid UTF8 character");
2641 if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
2642 PUSHs(sv_2mortal(newSVpv(name, 0)));
2645 PUSHs(&PL_sv_undef);
2652 i_test_format_probe(ig, length)
2657 i_add_file_magic(name, bits_sv, mask_sv)
2662 const unsigned char *bits;
2663 const unsigned char *mask;
2668 bits = SvPV(bits_sv, bits_size);
2669 mask = SvPV(mask_sv, mask_size);
2670 if (bits_size == 0) {
2671 i_push_error(0, "bits must be non-empty");
2674 if (mask_size == 0) {
2675 i_push_error(0, "mask must be non-empty");
2678 if (bits_size != mask_size) {
2679 i_push_error(0, "bits and mask must be the same length");
2683 i_push_error(0, "name must be non-empty");
2686 RETVAL = i_add_file_magic(name, bits, mask, bits_size);
2691 i_readpnm_wiol(ig, allow_incomplete)
2693 int allow_incomplete
2697 i_readpnm_multi_wiol(ig, allow_incomplete)
2699 int allow_incomplete
2705 imgs = i_readpnm_multi_wiol(ig, &count, allow_incomplete);
2708 for (i = 0; i < count; ++i) {
2709 SV *sv = sv_newmortal();
2710 sv_setref_pv(sv, "Imager::ImgRaw", (void *)imgs[i]);
2717 i_writeppm_wiol(im, ig)
2726 i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
2735 i_writeraw_wiol(im,ig)
2740 i_writebmp_wiol(im,ig)
2745 i_readbmp_wiol(ig, allow_incomplete=0)
2747 int allow_incomplete
2751 i_writetga_wiol(im,ig, wierdpack, compress, idstring)
2760 idlen = SvCUR(ST(4));
2761 RETVAL = i_writetga_wiol(im, ig, wierdpack, compress, idstring, idlen);
2767 i_readtga_wiol(ig, length)
2775 i_scaleaxis(im,Value,Axis)
2781 i_scale_nn(im,scx,scy)
2787 i_scale_mixing(im, width, height)
2797 i_count_colors(im,maxc)
2802 i_get_anonymous_color_histo(im, maxc = 0x40000000)
2807 unsigned int * col_usage = NULL;
2810 col_cnt = i_get_anonymous_color_histo(im, &col_usage, maxc);
2814 EXTEND(SP, col_cnt);
2815 for (i = 0; i < col_cnt; i++) {
2816 PUSHs(sv_2mortal(newSViv( col_usage[i])));
2822 i_transform(im, opx, opy, parm)
2828 STRLEN size_opx, size_opy, size_parm;
2831 result=i_transform(im,opx,size_opx,opy,size_opy,parm,size_parm);
2833 SV *result_sv = sv_newmortal();
2835 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2840 i_transform2(sv_width,sv_height,channels,sv_ops,av_n_regs,av_c_regs,av_in_imgs)
2866 in_imgs_count = av_len(av_in_imgs)+1;
2867 for (i = 0; i < in_imgs_count; ++i) {
2868 sv1 = *av_fetch(av_in_imgs, i, 0);
2869 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2870 croak("sv_in_img must contain only images");
2873 if (in_imgs_count > 0) {
2874 in_imgs = mymalloc(in_imgs_count*sizeof(i_img*));
2875 for (i = 0; i < in_imgs_count; ++i) {
2876 sv1 = *av_fetch(av_in_imgs,i,0);
2877 if (!sv_derived_from(sv1, "Imager::ImgRaw")) {
2878 croak("Parameter 5 must contain only images");
2880 tmp = SvIV((SV*)SvRV(sv1));
2881 in_imgs[i] = INT2PTR(i_img*, tmp);
2885 /* no input images */
2888 /* default the output size from the first input if possible */
2890 width = SvIV(sv_width);
2891 else if (in_imgs_count)
2892 width = in_imgs[0]->xsize;
2894 croak("No output image width supplied");
2896 if (SvOK(sv_height))
2897 height = SvIV(sv_height);
2898 else if (in_imgs_count)
2899 height = in_imgs[0]->ysize;
2901 croak("No output image height supplied");
2903 ops = (struct rm_op *)SvPV(sv_ops, ops_len);
2904 if (ops_len % sizeof(struct rm_op))
2905 croak("Imager: Parameter 3 must be a bitmap of regops\n");
2906 ops_count = ops_len / sizeof(struct rm_op);
2908 n_regs_count = av_len(av_n_regs)+1;
2909 n_regs = mymalloc(n_regs_count * sizeof(double));
2910 for (i = 0; i < n_regs_count; ++i) {
2911 sv1 = *av_fetch(av_n_regs,i,0);
2913 n_regs[i] = SvNV(sv1);
2915 c_regs_count = av_len(av_c_regs)+1;
2916 c_regs = mymalloc(c_regs_count * sizeof(i_color));
2917 /* I don't bother initializing the colou?r registers */
2919 result=i_transform2(width, height, channels, ops, ops_count,
2920 n_regs, n_regs_count,
2921 c_regs, c_regs_count, in_imgs, in_imgs_count);
2927 SV *result_sv = sv_newmortal();
2929 sv_setref_pv(result_sv, "Imager::ImgRaw", (void*)result);
2935 i_contrast(im,intensity)
2948 i_noise(im,amount,type)
2954 i_bumpmap(im,bump,channel,light_x,light_y,strength)
2964 i_bumpmap_complex(im,bump,channel,tx,ty,Lx,Ly,Lz,cd,cs,n,Ia,Il,Is)
2983 i_postlevels(im,levels)
2993 i_watermark(im,wmark,tx,ty,pixdiff)
2995 Imager::ImgRaw wmark
3002 i_autolevels(im,lsat,usat,skew)
3009 i_autolevels_mono(im,lsat,usat)
3015 i_radnoise(im,xo,yo,rscale,ascale)
3023 i_turbnoise(im, xo, yo, scale)
3031 i_gradgen(im, xo, yo, ac, dmeasure)
3042 if (size_xo != size_yo || size_xo != size_ac)
3043 croak("i_gradgen: x, y and color arrays must be the same size");
3045 croak("Usage: i_gradgen array refs must have more than 1 entry each");
3046 i_gradgen(im, size_xo, xo, yo, ac, dmeasure);
3049 i_diff_image(im, im2, mindist=0)
3055 i_rgbdiff_image(im, im2)
3060 i_fountain(im, xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3070 im_double ssample_param
3074 i_fountain_seg *segs;
3076 if (!SvROK(ST(10)) || ! SvTYPE(SvRV(ST(10))))
3077 croak("i_fountain: argument 11 must be an array ref");
3079 asegs = (AV *)SvRV(ST(10));
3080 segs = load_fount_segs(aTHX_ asegs, &count);
3081 RETVAL = i_fountain(im, xa, ya, xb, yb, type, repeat, combine,
3082 super_sample, ssample_param, count, segs);
3088 i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine, super_sample, ssample_param, segs)
3097 im_double ssample_param
3101 i_fountain_seg *segs;
3103 if (!SvROK(ST(9)) || ! SvTYPE(SvRV(ST(9))))
3104 croak("i_fountain: argument 11 must be an array ref");
3106 asegs = (AV *)SvRV(ST(9));
3107 segs = load_fount_segs(aTHX_ asegs, &count);
3108 RETVAL = i_new_fill_fount(xa, ya, xb, yb, type, repeat, combine,
3109 super_sample, ssample_param, count, segs);
3115 i_new_fill_opacity(other_fill, alpha_mult)
3116 Imager::FillHandle other_fill
3117 im_double alpha_mult
3127 errors = i_errors();
3129 while (errors[i].msg) {
3131 sv = newSVpv(errors[i].msg, strlen(errors[i].msg));
3132 if (!av_store(av, 0, sv)) {
3135 sv = newSViv(errors[i].code);
3136 if (!av_store(av, 1, sv)) {
3139 XPUSHs(sv_2mortal(newRV_noinc((SV*)av)));
3147 i_push_error(code, msg)
3152 i_nearest_color(im, ...)
3167 croak("Usage: i_nearest_color(im, xo, yo, ival, dmeasure)");
3168 if (!SvROK(ST(1)) || ! SvTYPE(SvRV(ST(1))))
3169 croak("i_nearest_color: Second argument must be an array ref");
3170 if (!SvROK(ST(2)) || ! SvTYPE(SvRV(ST(2))))
3171 croak("i_nearest_color: Third argument must be an array ref");
3172 if (!SvROK(ST(3)) || ! SvTYPE(SvRV(ST(3))))
3173 croak("i_nearest_color: Fourth argument must be an array ref");
3174 axx = (AV *)SvRV(ST(1));
3175 ayy = (AV *)SvRV(ST(2));
3176 ac = (AV *)SvRV(ST(3));
3177 dmeasure = (int)SvIV(ST(4));
3179 num = av_len(axx) < av_len(ayy) ? av_len(axx) : av_len(ayy);
3180 num = num <= av_len(ac) ? num : av_len(ac);
3182 if (num < 2) croak("Usage: i_nearest_color array refs must have more than 1 entry each");
3183 xo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3184 yo = malloc_temp(aTHX_ sizeof(i_img_dim) * num );
3185 ival = malloc_temp(aTHX_ sizeof(i_color) * num );
3186 for(i = 0; i<num; i++) {
3187 xo[i] = (i_img_dim)SvIV(* av_fetch(axx, i, 0));
3188 yo[i] = (i_img_dim)SvIV(* av_fetch(ayy, i, 0));
3189 sv = *av_fetch(ac, i, 0);
3190 if ( !sv_derived_from(sv, "Imager::Color") ) {
3191 free(axx); free(ayy); free(ac);
3192 croak("i_nearest_color: Element of fourth argument is not derived from Imager::Color");
3194 ival[i] = *INT2PTR(i_color *, SvIV((SV *)SvRV(sv)));
3196 RETVAL = i_nearest_color(im, num, xo, yo, ival, dmeasure);
3210 rc=DSO_open(filename,&evstr);
3214 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3215 PUSHs(sv_2mortal(newSVpvn(evstr, strlen(evstr))));
3218 PUSHs(sv_2mortal(newSViv(PTR2IV(rc))));
3224 DSO_close(dso_handle)
3228 DSO_funclist(dso_handle_v)
3232 DSO_handle *dso_handle;
3233 func_ptr *functions;
3235 dso_handle=(DSO_handle*)dso_handle_v;
3236 functions = DSO_funclist(dso_handle);
3238 while( functions[i].name != NULL) {
3240 PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
3242 PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
3246 DSO_call(handle,func_index,hv)
3251 DSO_call( (DSO_handle *)handle,func_index,hv);
3254 i_get_pixel(im, x, y)
3259 RETVAL = (i_color *)mymalloc(sizeof(i_color));
3260 memset(RETVAL, 0, sizeof(*RETVAL));
3261 if (i_gpix(im, x, y, RETVAL) != 0) {
3270 i_ppix(im, x, y, cl)
3277 i_img_pal_new(x, y, channels, maxpal)
3284 i_img_to_pal(src, quant_hv)
3291 memset(&quant, 0, sizeof(quant));
3293 quant.mc_size = 256;
3295 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3298 RETVAL = i_img_to_pal(src, &quant);
3300 ip_copy_colors_back(aTHX_ quant_hv, &quant);
3302 ip_cleanup_quant_opts(aTHX_ &quant);
3311 i_img_make_palette(HV *quant_hv, ...)
3313 size_t count = items - 1;
3315 i_img **imgs = NULL;
3319 croak("Please supply at least one image (%d)", (int)count);
3320 imgs = malloc_temp(aTHX_ count * sizeof(i_img *));
3321 for (i = 0; i < count; ++i) {
3322 SV *img_sv = ST(i + 1);
3323 if (SvROK(img_sv) && sv_derived_from(img_sv, "Imager::ImgRaw")) {
3324 imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(img_sv)));
3327 croak("Image %d is not an image object", (int)i+1);
3330 memset(&quant, 0, sizeof(quant));
3332 quant.mc_size = 256;
3333 if (!ip_handle_quant_opts2(aTHX_ &quant, quant_hv)) {
3336 i_quant_makemap(&quant, imgs, count);
3337 EXTEND(SP, quant.mc_count);
3338 for (i = 0; i < quant.mc_count; ++i) {
3339 SV *sv_c = make_i_color_sv(aTHX_ quant.mc_colors + i);
3342 ip_cleanup_quant_opts(aTHX_ &quant);
3356 work = mymalloc((r-l) * sizeof(i_palidx));
3357 count = i_gpal(im, l, r, y, work);
3358 if (GIMME_V == G_ARRAY) {
3360 for (i = 0; i < count; ++i) {
3361 PUSHs(sv_2mortal(newSViv(work[i])));
3366 PUSHs(sv_2mortal(newSVpv((char *)work, count * sizeof(i_palidx))));
3371 if (GIMME_V != G_ARRAY) {
3373 PUSHs(&PL_sv_undef);
3378 i_ppal(im, l, y, ...)
3387 work = malloc_temp(aTHX_ sizeof(i_palidx) * (items-3));
3388 for (i=0; i < items-3; ++i) {
3389 work[i] = SvIV(ST(i+3));
3391 validate_i_ppal(im, work, items - 3);
3392 RETVAL = i_ppal(im, l, l+items-3, y, work);
3401 i_ppal_p(im, l, y, data)
3407 i_palidx const *work;
3410 work = (i_palidx const *)SvPV(data, len);
3411 len /= sizeof(i_palidx);
3413 validate_i_ppal(im, work, len);
3414 RETVAL = i_ppal(im, l, l+len, y, work);
3423 i_addcolors(im, ...)
3430 croak("i_addcolors: no colors to add");
3431 colors = mymalloc((items-1) * sizeof(i_color));
3432 for (i=0; i < items-1; ++i) {
3433 if (sv_isobject(ST(i+1))
3434 && sv_derived_from(ST(i+1), "Imager::Color")) {
3435 IV tmp = SvIV((SV *)SvRV(ST(i+1)));
3436 colors[i] = *INT2PTR(i_color *, tmp);
3440 croak("i_addcolor: pixels must be Imager::Color objects");
3443 RETVAL = i_addcolors(im, colors, items-1);
3449 i_setcolors(im, index, ...)
3457 croak("i_setcolors: no colors to add");
3458 colors = mymalloc((items-2) * sizeof(i_color));
3459 for (i=0; i < items-2; ++i) {
3460 if (sv_isobject(ST(i+2))
3461 && sv_derived_from(ST(i+2), "Imager::Color")) {
3462 IV tmp = SvIV((SV *)SvRV(ST(i+2)));
3463 colors[i] = *INT2PTR(i_color *, tmp);
3467 croak("i_setcolors: pixels must be Imager::Color objects");
3470 RETVAL = i_setcolors(im, index, colors, items-2);
3476 i_getcolors(im, index, count=1)
3485 croak("i_getcolors: count must be positive");
3486 colors = malloc_temp(aTHX_ sizeof(i_color) * count);
3487 if (i_getcolors(im, index, colors, count)) {
3489 for (i = 0; i < count; ++i) {
3490 SV *sv = make_i_color_sv(aTHX_ colors+i);
3504 i_findcolor(im, color)
3508 if (!i_findcolor(im, color, &RETVAL)) {
3527 i_gsamp(im, l, r, y, channels)
3532 i_channel_list channels
3538 data = mymalloc(sizeof(i_sample_t) * (r-l) * channels.count);
3539 count = i_gsamp(im, l, r, y, data, channels.channels, channels.count);
3540 if (GIMME_V == G_ARRAY) {
3542 for (i = 0; i < count; ++i)
3543 PUSHs(sv_2mortal(newSViv(data[i])));
3547 PUSHs(sv_2mortal(newSVpv((char *)data, count * sizeof(i_sample_t))));
3552 if (GIMME_V != G_ARRAY) {
3558 i_gsamp_bits(im, l, r, y, bits, target, offset, channels)
3566 i_channel_list channels
3573 croak("No channel numbers supplied to g_samp()");
3575 data = mymalloc(sizeof(unsigned) * (r-l) * channels.count);
3576 count = i_gsamp_bits(im, l, r, y, data, channels.channels, channels.count, bits);
3577 for (i = 0; i < count; ++i) {
3578 av_store(target, i+offset, newSVuv(data[i]));
3590 i_psamp_bits(im, l, y, bits, channels, data_av, data_offset = 0, pixel_count = -1)
3595 i_channel_list channels
3597 i_img_dim data_offset
3598 i_img_dim pixel_count
3607 data_count = av_len(data_av) + 1;
3608 if (data_offset < 0) {
3609 croak("data_offset must be non-negative");
3611 if (data_offset > data_count) {
3612 croak("data_offset greater than number of samples supplied");
3614 if (pixel_count == -1 ||
3615 data_offset + pixel_count * channels.count > data_count) {
3616 pixel_count = (data_count - data_offset) / channels.count;
3619 data_used = pixel_count * channels.count;
3620 data = mymalloc(sizeof(unsigned) * data_count);
3621 for (i = 0; i < data_used; ++i)
3622 data[i] = SvUV(*av_fetch(data_av, data_offset + i, 0));
3624 RETVAL = i_psamp_bits(im, l, l + pixel_count, y, data, channels.channels,
3625 channels.count, bits);
3633 i_psamp(im, x, y, channels, data, offset = 0, width = -1)
3637 i_channel_list channels
3646 i_push_error(0, "offset must be non-negative");
3650 if (offset > data.count) {
3651 i_push_error(0, "offset greater than number of samples supplied");
3654 data.samples += offset;
3655 data.count -= offset;
3658 width * channels.count > data.count) {
3659 width = data.count / channels.count;
3662 RETVAL = i_psamp(im, x, r, y, data.samples, channels.channels, channels.count);
3667 i_psampf(im, x, y, channels, data, offset = 0, width = -1)
3671 i_channel_list channels
3680 i_push_error(0, "offset must be non-negative");
3684 if (offset > data.count) {
3685 i_push_error(0, "offset greater than number of samples supplied");
3688 data.samples += offset;
3689 data.count -= offset;
3692 width * channels.count > data.count) {
3693 width = data.count / channels.count;
3696 RETVAL = i_psampf(im, x, r, y, data.samples, channels.channels, channels.count);
3701 i_img_masked_new(targ, mask, x, y, w, h)
3711 if (!sv_isobject(ST(1))
3712 || !sv_derived_from(ST(1), "Imager::ImgRaw")) {
3713 croak("i_img_masked_new: parameter 2 must undef or an image");
3715 mask = INT2PTR(i_img *, SvIV((SV *)SvRV(ST(1))));
3719 RETVAL = i_img_masked_new(targ, mask, x, y, w, h);
3724 i_plin(im, l, y, ...)
3735 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3736 /* supplied as a byte string */
3737 work = (i_color *)SvPV(ST(3), len);
3738 count = len / sizeof(i_color);
3739 if (count * sizeof(i_color) != len) {
3740 croak("i_plin: length of scalar argument must be multiple of sizeof i_color");
3742 RETVAL = i_plin(im, l, l+count, y, work);
3745 work = mymalloc(sizeof(i_color) * (items-3));
3746 for (i=0; i < items-3; ++i) {
3747 if (sv_isobject(ST(i+3))
3748 && sv_derived_from(ST(i+3), "Imager::Color")) {
3749 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3750 work[i] = *INT2PTR(i_color *, tmp);
3754 croak("i_plin: pixels must be Imager::Color objects");
3757 RETVAL = i_plin(im, l, l+items-3, y, work);
3768 i_ppixf(im, x, y, cl)
3772 Imager::Color::Float cl
3775 i_gsampf(im, l, r, y, channels)
3780 i_channel_list channels
3786 data = mymalloc(sizeof(i_fsample_t) * (r-l) * channels.count);
3787 count = i_gsampf(im, l, r, y, data, channels.channels, channels.count);
3788 if (GIMME_V == G_ARRAY) {
3790 for (i = 0; i < count; ++i)
3791 PUSHs(sv_2mortal(newSVnv(data[i])));
3795 PUSHs(sv_2mortal(newSVpv((void *)data, count * sizeof(i_fsample_t))));
3800 if (GIMME_V != G_ARRAY) {
3806 i_plinf(im, l, y, ...)
3817 if (items == 4 && SvOK(ST(3)) && !SvROK(ST(3))) {
3818 /* supplied as a byte string */
3819 work = (i_fcolor *)SvPV(ST(3), len);
3820 count = len / sizeof(i_fcolor);
3821 if (count * sizeof(i_fcolor) != len) {
3822 croak("i_plin: length of scalar argument must be multiple of sizeof i_fcolor");
3824 RETVAL = i_plinf(im, l, l+count, y, work);
3827 work = mymalloc(sizeof(i_fcolor) * (items-3));
3828 for (i=0; i < items-3; ++i) {
3829 if (sv_isobject(ST(i+3))
3830 && sv_derived_from(ST(i+3), "Imager::Color::Float")) {
3831 IV tmp = SvIV((SV *)SvRV(ST(i+3)));
3832 work[i] = *INT2PTR(i_fcolor *, tmp);
3836 croak("i_plinf: pixels must be Imager::Color::Float objects");
3840 RETVAL = i_plinf(im, l, l+items-3, y, work);
3850 Imager::Color::Float
3856 RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor));
3857 memset(RETVAL, 0, sizeof(*RETVAL));
3858 if (i_gpixf(im, x, y, RETVAL) != 0) {
3876 vals = mymalloc((r-l) * sizeof(i_color));
3877 memset(vals, 0, (r-l) * sizeof(i_color));
3878 count = i_glin(im, l, r, y, vals);
3879 if (GIMME_V == G_ARRAY) {
3881 for (i = 0; i < count; ++i) {
3882 SV *sv = make_i_color_sv(aTHX_ vals+i);
3888 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_color))));
3894 i_glinf(im, l, r, y)
3904 for (i = 0; i < MAXCHANNELS; ++i)
3905 zero.channel[i] = 0;
3907 vals = mymalloc((r-l) * sizeof(i_fcolor));
3908 for (i = 0; i < r-l; ++i)
3910 count = i_glinf(im, l, r, y, vals);
3911 if (GIMME_V == G_ARRAY) {
3913 for (i = 0; i < count; ++i) {
3915 i_fcolor *col = mymalloc(sizeof(i_fcolor));
3917 sv = sv_newmortal();
3918 sv_setref_pv(sv, "Imager::Color::Float", (void *)col);
3924 PUSHs(sv_2mortal(newSVpv((void *)vals, count * sizeof(i_fcolor))));
3930 i_img_8_new(xsize, ysize, channels)
3936 i_img_16_new(xsize, ysize, channels)
3946 i_img_double_new(xsize, ysize, channels)
3956 i_tags_addn(im, name_sv, code, idata)
3965 SvGETMAGIC(name_sv);
3967 name = SvPV_nomg(name_sv, len);
3970 RETVAL = i_tags_addn(&im->tags, name, code, idata);
3975 i_tags_add(im, name_sv, code, data_sv, idata)
3986 SvGETMAGIC(name_sv);
3988 name = SvPV_nomg(name_sv, len);
3991 SvGETMAGIC(data_sv);
3993 data = SvPV(data_sv, len);
3998 RETVAL = i_tags_add(&im->tags, name, code, data, len, idata);
4003 i_tags_find(im, name, start)
4010 if (i_tags_find(&im->tags, name, start, &entry)) {
4019 i_tags_findn(im, code, start)
4026 if (i_tags_findn(&im->tags, code, start, &entry)) {
4036 i_tags_delete(im, entry)
4040 RETVAL = i_tags_delete(&im->tags, entry);
4045 i_tags_delbyname(im, name)
4049 RETVAL = i_tags_delbyname(&im->tags, name);
4054 i_tags_delbycode(im, code)
4058 RETVAL = i_tags_delbycode(&im->tags, code);
4063 i_tags_get(im, index)
4067 if (index >= 0 && index < im->tags.count) {
4068 i_img_tag *entry = im->tags.tags + index;
4072 PUSHs(sv_2mortal(newSVpv(entry->name, 0)));
4075 PUSHs(sv_2mortal(newSViv(entry->code)));
4078 PUSHs(sv_2mortal(newSVpvn(entry->data, entry->size)));
4081 PUSHs(sv_2mortal(newSViv(entry->idata)));
4086 i_tags_get_string(im, what_sv)
4090 char const *name = NULL;
4094 if (SvIOK(what_sv)) {
4095 code = SvIV(what_sv);
4099 name = SvPV_nolen(what_sv);
4102 if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
4104 PUSHs(sv_2mortal(newSVpv(buffer, 0)));
4111 RETVAL = im->tags.count;
4117 MODULE = Imager PACKAGE = Imager::FillHandle PREFIX=IFILL_
4121 Imager::FillHandle fill
4124 IFILL_CLONE_SKIP(...)
4126 (void)items; /* avoid unused warning for XS variable */
4131 MODULE = Imager PACKAGE = Imager
4134 i_new_fill_solid(cl, combine)
4139 i_new_fill_solidf(cl, combine)
4140 Imager::Color::Float cl
4144 i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4153 unsigned char *cust_hatch;
4156 SvGETMAGIC(cust_hatch_sv);
4157 if (SvOK(cust_hatch_sv)) {
4158 cust_hatch = (unsigned char *)SvPV_nomg(cust_hatch_sv, len);
4162 RETVAL = i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy);
4167 i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch_sv, dx, dy)
4168 Imager::Color::Float fg
4169 Imager::Color::Float bg
4176 unsigned char *cust_hatch;
4179 SvGETMAGIC(cust_hatch_sv);
4180 if (SvOK(cust_hatch_sv)) {
4181 cust_hatch = (unsigned char *)SvPV(cust_hatch_sv, len);
4185 RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
4190 i_new_fill_image(src, matrix_sv, xoff, yoff, combine)
4204 SvGETMAGIC(matrix_sv);
4205 if (!SvOK(matrix_sv)) {
4209 if (!SvROK(matrix_sv) || SvTYPE(SvRV(matrix_sv)) != SVt_PVAV)
4210 croak("i_new_fill_image: matrix parameter must be an arrayref or undef");
4211 av=(AV*)SvRV(matrix_sv);
4215 for (i = 0; i < len; ++i) {
4216 sv1=(*(av_fetch(av,i,0)));
4217 matrix[i] = SvNV(sv1);
4223 RETVAL = i_new_fill_image(src, matrixp, xoff, yoff, combine);
4227 MODULE = Imager PACKAGE = Imager::Internal::Hlines PREFIX=i_int_hlines_
4229 # this class is only exposed for testing
4232 i_int_hlines_testing()
4234 #if i_int_hlines_testing()
4236 Imager::Internal::Hlines
4237 i_int_hlines_new(start_y, count_y, start_x, count_x)
4243 Imager::Internal::Hlines
4244 i_int_hlines_new_img(im)
4248 i_int_hlines_add(hlines, y, minx, width)
4249 Imager::Internal::Hlines hlines
4255 i_int_hlines_DESTROY(hlines)
4256 Imager::Internal::Hlines hlines
4259 i_int_hlines_dump(hlines)
4260 Imager::Internal::Hlines hlines
4263 i_int_hlines_CLONE_SKIP(cls)
4267 MODULE = Imager PACKAGE = Imager::Context PREFIX=im_context_
4270 im_context_DESTROY(ctx)
4273 #ifdef PERL_IMPLICIT_CONTEXT
4276 im_context_CLONE(...)
4280 /* the following sv_setref_pv() will free this inc */
4281 im_context_refinc(MY_CXT.ctx, "CLONE");
4282 MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
4283 if (MY_CXT.ctx == NULL) {
4284 croak("Failed to clone Imager context");
4286 sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
4291 PERL_SET_GLOBAL_CALLBACKS;
4292 PERL_PL_SET_GLOBAL_CALLBACKS;
4293 #ifdef PERL_IMPLICIT_CONTEXT
4299 start_context(aTHX);
4300 im_get_context = perl_get_context;