# HG changeset patch # User ramiro # Date 1250645597 0 # Node ID 86786d090e11c0c539d8b556808e2ebc13a840ce # Parent 335da85c454cebaefd778959d11048b3db852b8f Introduce and use sws_allocVec(). diff -r 335da85c454c -r 86786d090e11 libswscale/swscale.c --- a/libswscale/swscale.c Wed Aug 19 01:32:06 2009 +0000 +++ b/libswscale/swscale.c Wed Aug 19 01:33:17 2009 +0000 @@ -3240,20 +3240,28 @@ 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_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 @@ 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; - - for (i=0; ilength; i++) coeff[i]= a->coeff[i]; + SwsVector *vec= sws_allocVec(a->length); + + for (i=0; ilength; i++) vec->coeff[i]= a->coeff[i]; return vec; } diff -r 335da85c454c -r 86786d090e11 libswscale/swscale.h --- a/libswscale/swscale.h Wed Aug 19 01:32:06 2009 +0000 +++ b/libswscale/swscale.h Wed Aug 19 01:33:17 2009 +0000 @@ -182,6 +182,11 @@ int *brightness, int *contrast, int *saturation); /** + * Allocates and returns an uninitialized vector with length coefficients. + */ +SwsVector *sws_allocVec(int length); + +/** * Returns a normalized Gaussian curve used to filter stuff * quality=3 is high quality, lower is lower quality. */