]> git.imager.perl.org - imager.git/blame_incremental - typemap.local
extend some variable types to avoid overflows for mediancut
[imager.git] / typemap.local
... / ...
CommitLineData
1# definitions we don't want to make visible to the world
2# because they're intended for use specifically by Imager.xs
3
4# internal types used in Imager.xs
5i_channel_list T_IM_CHANNEL_LIST
6i_sample_list T_IM_SAMPLE_LIST
7i_fsample_list T_IM_FSAMPLE_LIST
8i_polygon_list T_IM_POLYGON_LIST
9
10off_t T_OFF_T
11
12Imager::Internal::Hlines T_PTROBJ
13
14Imager::Context T_PTROBJ
15
16i_palidx T_IV
17double * T_AVARRAY
18int * T_AVARRAY
19i_img_dim * T_AVARRAY
20i_color * T_AVARRAY
21
22i_poly_fill_mode_t T_I_POLY_FILL_MODE_T
23
24#############################################################################
25INPUT
26
27T_OFF_T
28 $var = i_sv_off_t(aTHX_ $arg);
29
30T_IM_CHANNEL_LIST
31 SvGETMAGIC($arg);
32 if (SvOK($arg)) {
33 AV *channels_av;
34 int i;
35 if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) {
36 croak(\"$var is not an array ref\");
37 }
38 channels_av = (AV *)SvRV($arg);
39 $var.count = av_len(channels_av) + 1;
40 if ($var.count < 1) {
41 croak(\"$pname: no channels provided\");
42 }
43 $var.channels = malloc_temp(aTHX_ sizeof(int) * $var.count);
44 for (i = 0; i < $var.count; ++i) {
45 SV **entry = av_fetch(channels_av, i, 0);
46 $var.channels[i] = entry ? SvIV(*entry) : 0;
47 }
48 }
49 else {
50 /* assumes we have an image */
51 $var.count = im->channels;
52 $var.channels = NULL;
53 }
54
55T_IM_SAMPLE_LIST
56 SvGETMAGIC($arg);
57 if (!SvOK($arg))
58 croak(\"$var must be a scalar or an arrayref\");
59 if (SvROK($arg)) {
60 i_img_dim i;
61 AV *av;
62 i_sample_t *s;
63 if (SvTYPE(SvRV($arg)) != SVt_PVAV)
64 croak(\"$var must be a scalar or an arrayref\");
65 av = (AV *)SvRV($arg);
66 $var.count = av_len(av) + 1;
67 if ($var.count < 1)
68 croak(\"$pname: no samples provided in $var\");
69 s = malloc_temp(aTHX_ sizeof(i_sample_t) * $var.count);
70 for (i = 0; i < $var.count; ++i) {
71 SV **entry = av_fetch(av, i, 0);
72 s[i] = entry ? SvIV(*entry) : 0;
73 }
74 $var.samples = s;
75 }
76 else {
77 /* non-magic would be preferable here */
78 $var.samples = (const i_sample_t *)SvPVbyte($arg, $var.count);
79 if ($var.count == 0)
80 croak(\"$pname: no samples provided in $var\");
81 }
82
83T_IM_FSAMPLE_LIST
84 SvGETMAGIC($arg);
85 if (!SvOK($arg))
86 croak(\"$var must be a scalar or an arrayref\");
87 if (SvROK($arg)) {
88 i_img_dim i;
89 AV *av;
90 i_fsample_t *s;
91 if (SvTYPE(SvRV($arg)) != SVt_PVAV)
92 croak(\"$var must be a scalar or an arrayref\");
93 av = (AV *)SvRV($arg);
94 $var.count = av_len(av) + 1;
95 if ($var.count < 1)
96 croak(\"$pname: no samples provided in $var\");
97 s = malloc_temp(aTHX_ sizeof(i_fsample_t) * $var.count);
98 for (i = 0; i < $var.count; ++i) {
99 SV **entry = av_fetch(av, i, 0);
100 s[i] = entry ? SvNV(*entry) : 0;
101 }
102 $var.samples = s;
103 }
104 else {
105 /* non-magic would be preferable here */
106 $var.samples = (const i_fsample_t *)SvPVbyte($arg, $var.count);
107 if ($var.count % sizeof(double))
108 croak(\"$pname: $var doesn't not contain a integer number of samples\");
109 $var.count /= sizeof(double);
110 if ($var.count == 0)
111 croak(\"$pname: no samples provided in $var\");
112 }
113
114T_IM_POLYGON_LIST
115 S_get_polygon_list(aTHX_ &$var, $arg);
116
117T_AVARRAY
118 STMT_START {
119 SV* const xsub_tmp_sv = $arg;
120 SvGETMAGIC(xsub_tmp_sv);
121 if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVAV){
122 AV *xsub_tmp_av = (AV*)SvRV(xsub_tmp_sv);
123 STRLEN xsub_index;
124 size_$var = av_len(xsub_tmp_av) + 1;
125 $var = $ntype(size_$var);
126 for (xsub_index = 0; xsub_index < size_$var; ++xsub_index) {
127 SV **sv = av_fetch(xsub_tmp_av, xsub_index, 0);
128 if (sv) {
129 ${var}[xsub_index] = Sv${(my $ntt = $ntype) =~ s/Ptr$//; \(ucfirst $ntt)}(*sv, \"$pname\");
130 }
131 }
132 }
133 else{
134 Perl_croak(aTHX_ \"%s: %s is not an ARRAY reference\",
135 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
136 \"$var\");
137 }
138 } STMT_END
139
140T_I_POLY_FILL_MODE_T
141 $var = S_get_poly_fill_mode(aTHX_ $arg);
142
143
144
145#############################################################################
146OUTPUT
147
148T_OFF_T
149 $arg = i_new_sv_off_t(aTHX_ $var);