From: Tony Cook Date: Tue, 21 May 2013 13:13:42 +0000 (+1000) Subject: [rt #69243] add the T_AVARRAY typemap and use it X-Git-Tag: v0.96_01~16^2~18 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/19e9591baa02172b384aec1d599cdc281076b637?ds=inline [rt #69243] add the T_AVARRAY typemap and use it --- diff --git a/Changes b/Changes index c703648b..c10aa5d4 100644 --- a/Changes +++ b/Changes @@ -20,9 +20,11 @@ Imager release history. Older releases can be found in Changes.old - Imager::Color's rgba() method now returns it's values as integers instead of floating point. (IV instead of NV). - - The XS for i_poly_aa(), i_poly_aa_cfill(), i_map(), i_transform() - and i_matrix_transform() now use the AV * typemap instead of - rolling their own. + - The XS for i_map() and i_matrix_transform() now use the AV * + typemap instead of rolling their own. + + - The XS for i_poly_aa(), i_poly_aa_cfill(), i_transform() now use + a new T_AVARRAY typemap that greatly simplifies the XS code. - some XS code formatting diff --git a/Imager.xs b/Imager.xs index e643aec5..fe1273a4 100644 --- a/Imager.xs +++ b/Imager.xs @@ -122,6 +122,13 @@ malloc_temp(pTHX_ size_t size) { return SvPVX(sv); } +/* for use with the T_AVARRAY typemap */ +#define doublePtr(size) ((double *)malloc_temp(aTHX_ sizeof(double) * (size))) +#define SvDouble(sv) (SvNV(sv)) + +#define intPtr(size) ((int *)malloc_temp(aTHX_ sizeof(int) * (size))) +#define SvInt(sv) (SvIV(sv)) + /* These functions are all shared - then comes platform dependant code */ static int getstr(void *hv_t,char *key,char **store) { dTHX; @@ -1743,62 +1750,34 @@ i_bezier_multi(im,xc,yc,val) int -i_poly_aa(im,x_av,y_av,val) +i_poly_aa(im,x,y,val) Imager::ImgRaw im - AV *x_av - AV *y_av + double *x + double *y Imager::Color val PREINIT: - double *x,*y; - int len; - SV *x_sv; - SV *y_sv; - SSize_t i; + STRLEN size_x; + STRLEN size_y; CODE: - if (av_len(x_av) != av_len(y_av)) + if (size_x != size_y) croak("Imager: x and y arrays to i_poly_aa must be equal length\n"); - len=av_len(x_av)+1; - x=mymalloc( len*sizeof(double) ); - y=mymalloc( len*sizeof(double) ); - for(i=0;i