From 1aff375d41b4ff32ff6b4ae7a2e75b269ea6df63 Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Wed, 19 Aug 2009 01:33:17 +0000 Subject: Introduce and use sws_allocVec(). Originally committed as revision 29536 to svn://svn.mplayerhq.hu/mplayer/trunk/libswscale --- libswscale/swscale.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'libswscale/swscale.c') diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 5b80843..6dfbed7 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -3240,20 +3240,28 @@ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, return filter; } +SwsVector *sws_allocVec(int length) +{ + SwsVector *vec = av_malloc(sizeof(SwsVector)); + if (!vec) + return NULL; + vec->length = length; + vec->coeff = av_malloc(sizeof(double) * length); + if (!vec->coeff) + av_freep(&vec); + return vec; +} + SwsVector *sws_getGaussianVec(double variance, double quality) { const int length= (int)(variance*quality + 0.5) | 1; int i; - double *coeff= av_malloc(length*sizeof(double)); double middle= (length-1)*0.5; - SwsVector *vec= av_malloc(sizeof(SwsVector)); - - vec->coeff= coeff; - vec->length= length; + SwsVector *vec= sws_allocVec(length); for (i=0; icoeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*PI); } sws_normalizeVec(vec, 1.0); @@ -3264,14 +3272,10 @@ SwsVector *sws_getGaussianVec(double variance, double quality) SwsVector *sws_getConstVec(double c, int length) { int i; - double *coeff= av_malloc(length*sizeof(double)); - SwsVector *vec= av_malloc(sizeof(SwsVector)); - - vec->coeff= coeff; - vec->length= length; + SwsVector *vec= sws_allocVec(length); for (i=0; icoeff[i]= c; return vec; } @@ -3397,14 +3401,10 @@ void sws_convVec(SwsVector *a, SwsVector *b) SwsVector *sws_cloneVec(SwsVector *a) { - double *coeff= av_malloc(a->length*sizeof(double)); int i; - SwsVector *vec= av_malloc(sizeof(SwsVector)); - - vec->coeff= coeff; - vec->length= a->length; + SwsVector *vec= sws_allocVec(a->length); - for (i=0; ilength; i++) coeff[i]= a->coeff[i]; + for (i=0; ilength; i++) vec->coeff[i]= a->coeff[i]; return vec; } -- cgit v1.1