[FFmpeg-devel] [PATCH] lsws/swscale.h: introduce sws_get_gaussian_vec

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Aug 26 18:15:27 EEST 2023


Stefano Sabatini:
> Use in place of sws_getGaussianVec.
> 
> The new function enable better log handling, and provide better naming

Better log handling? Why?

> for the variance variable, now named standard_deviation to reflect the
> meaning of the parameter.
> ---
>  doc/APIchanges             |  3 +++
>  libswscale/swscale.h       | 21 ++++++++++++++++++-
>  libswscale/utils.c         | 41 +++++++++++++++++++++++++++++---------
>  libswscale/version.h       |  2 +-
>  libswscale/version_major.h |  4 ++++
>  5 files changed, 60 insertions(+), 11 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ad1efe708d..bad2d61027 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>  
>  API changes, most recent first:
>  
> +2023-08-26 - xxxxxxxxxx - lsws 7.4.100 - swscale.h
> +  Introduce sws_get_gaussian_vec, use in place of sws_getGaussianVec.
> +
>  2023-08-18 - xxxxxxxxxx - lavu 58.17.100 - channel_layout.h
>    All AV_CHANNEL_LAYOUT_* macros are now compatible with C++ 17 and older.
>  
> diff --git a/libswscale/swscale.h b/libswscale/swscale.h
> index 9d4612aaf3..f002b5c7d2 100644
> --- a/libswscale/swscale.h
> +++ b/libswscale/swscale.h
> @@ -355,11 +355,30 @@ int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table,
>   */
>  SwsVector *sws_allocVec(int length);
>  
> +#if FF_API_SWS_GET_GAUSSIAN_VEC
>  /**
> - * Return a normalized Gaussian curve used to filter stuff
> + * Return a normalized Gaussian curve used to filter stuff.
> + *
>   * quality = 3 is high quality, lower is lower quality.
>   */
>  SwsVector *sws_getGaussianVec(double variance, double quality);

Missing attribute_deprecated as well as the @deprecated doxygen thing
refering to its replacement.

> +#endif
> +
> +/**
> + * Compute and return a normalized Gaussian vector.
> + *
> + * @param vecp: pointer where the computed vector is put in case of
> + *        success
> + * @param standard_deviation the standard deviation used to generate
> + *        the Gaussian vector, must be a non-negative value
> + * @param quality the quality of the generated Gaussian vector, must
> + *        be a non-negative value. It affects the lenght of the generated
> + *        vector. A value equal to 3 corresponds to high quality.
> + *
> + * @return a negative error code on error, non negative otherwise
> + */
> +int sws_get_gaussian_vec(SwsVector **vecp,
> +                         double standard_deviation, double quality);
>  
>  /**
>   * Scale all the coefficients of a by the scalar value.
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index 8e74c6603e..96034af1e0 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -2139,31 +2139,54 @@ SwsVector *sws_allocVec(int length)
>      return vec;
>  }
>  
> -SwsVector *sws_getGaussianVec(double variance, double quality)
> +int sws_get_gaussian_vec(SwsVector **vecp,
> +                         double standard_deviation, double quality)
>  {
> -    const int length = (int)(variance * quality + 0.5) | 1;
> +    const int length = (int)(standard_deviation * quality + 0.5) | 1;
>      int i;
>      double middle  = (length - 1) * 0.5;
>      SwsVector *vec;
> +    const double variance = standard_deviation * standard_deviation;
>  
> -    if(variance < 0 || quality < 0)
> -        return NULL;
> +    if (standard_deviation < 0 || quality < 0) {
> +        av_log(NULL, AV_LOG_ERROR,
> +               "Invalid negative standard deviation %f or quality %f provided as input to the sws_get_gaussian_vec function\n",
> +               standard_deviation, quality);
> +        return AVERROR(EINVAL);
> +    }
>  
>      vec = sws_allocVec(length);
> -
> -    if (!vec)
> -        return NULL;
> +    if (!vec) {
> +        av_log(NULL, AV_LOG_ERROR,
> +               "Could not allocate vector for the sws_get_gaussian_vec function\n");
> +        return AVERROR(ENOMEM);
> +    }
>  
>      for (i = 0; i < length; i++) {
>          double dist = i - middle;
> -        vec->coeff[i] = exp(-dist * dist / (2 * variance * variance)) /
> -                        sqrt(2 * variance * M_PI);
> +        vec->coeff[i] = exp(-dist * dist / (2 * variance)) /
> +                        sqrt(2 * standard_deviation * M_PI);
>      }
>  
>      sws_normalizeVec(vec, 1.0);
> +    *vecp = vec;
>  
> +    return 0;
> +}
> +
> +#if FF_API_SWS_GET_GAUSSIAN_VEC
> +SwsVector *sws_getGaussianVec(double variance, double quality)
> +{
> +    SwsVector *vec;
> +    int ret;
> +
> +    ret = sws_get_gaussian_vec(&vec, variance, quality);
> +    if (ret < 0) {
> +        return NULL;
> +    }
>      return vec;
>  }
> +#endif // FF_API_SWS_GET_GAUSSIAN_VEC
>  
>  /**
>   * Allocate and return a vector with length coefficients, all
> diff --git a/libswscale/version.h b/libswscale/version.h
> index 51eb013a29..12412bd538 100644
> --- a/libswscale/version.h
> +++ b/libswscale/version.h
> @@ -28,7 +28,7 @@
>  
>  #include "version_major.h"
>  
> -#define LIBSWSCALE_VERSION_MINOR   3
> +#define LIBSWSCALE_VERSION_MINOR   4
>  #define LIBSWSCALE_VERSION_MICRO 100
>  
>  #define LIBSWSCALE_VERSION_INT  AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
> diff --git a/libswscale/version_major.h b/libswscale/version_major.h
> index 88577a2b42..aa0baef7c6 100644
> --- a/libswscale/version_major.h
> +++ b/libswscale/version_major.h
> @@ -32,4 +32,8 @@
>   * the public API and may change, break or disappear at any time.
>   */
>  
> +#ifndef FF_API_SWS_GET_GAUSSIAN_VEC
> +#define FF_API_SWS_GET_GAUSSIAN_VEC       (LIBSWSCALE_VERSION_MAJOR < 8)
> +#endif
> +
>  #endif /* SWSCALE_VERSION_MAJOR_H */



More information about the ffmpeg-devel mailing list