[FFmpeg-devel] [PATCH 1/2] lsws, lavfi: use sws_get_gaussian_vec
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Sat Aug 26 18:13:19 EEST 2023
Stefano Sabatini:
> Use in place of deprecated sws_getGaussianVec.
This patchset should have been sent as a reply to the patch actually
adding sws_get_gaussian_vec.
> ---
> libavfilter/vf_sab.c | 17 +++++++++++++----
> libavfilter/vf_smartblur.c | 8 ++++----
> libswscale/utils.c | 32 ++++++++++++++------------------
> 3 files changed, 31 insertions(+), 26 deletions(-)
>
> diff --git a/libavfilter/vf_sab.c b/libavfilter/vf_sab.c
> index 5e0687c9a2..b2e42a55af 100644
> --- a/libavfilter/vf_sab.c
> +++ b/libavfilter/vf_sab.c
> @@ -143,7 +143,7 @@ static int open_filter_param(FilterParam *f, int width, int height, unsigned int
> {
> SwsVector *vec;
> SwsFilter sws_f;
> - int i, x, y;
> + int ret, i, x, y;
> int linesize = FFALIGN(width, 8);
>
> f->pre_filter_buf = av_malloc(linesize * height);
> @@ -151,7 +151,10 @@ static int open_filter_param(FilterParam *f, int width, int height, unsigned int
> return AVERROR(ENOMEM);
>
> f->pre_filter_linesize = linesize;
> - vec = sws_getGaussianVec(f->pre_filter_radius, f->quality);
> + ret = sws_get_gaussian_vec(&vec, f->pre_filter_radius, f->quality);
> + if (ret < 0)
> + return ret;
> +
> sws_f.lumH = sws_f.lumV = vec;
> sws_f.chrH = sws_f.chrV = NULL;
> f->pre_filter_context = sws_getContext(width, height, AV_PIX_FMT_GRAY8,
> @@ -159,7 +162,10 @@ static int open_filter_param(FilterParam *f, int width, int height, unsigned int
> sws_flags, &sws_f, NULL, NULL);
> sws_freeVec(vec);
>
> - vec = sws_getGaussianVec(f->strength, 5.0);
> + ret = sws_get_gaussian_vec(&vec, f->strength, 5.0);
> + if (ret < 0)
> + return ret;
> +
> for (i = 0; i < COLOR_DIFF_COEFF_SIZE; i++) {
> double d;
> int index = i-COLOR_DIFF_COEFF_SIZE/2 + vec->length/2;
> @@ -171,7 +177,10 @@ static int open_filter_param(FilterParam *f, int width, int height, unsigned int
> }
> sws_freeVec(vec);
>
> - vec = sws_getGaussianVec(f->radius, f->quality);
> + ret = sws_get_gaussian_vec(&vec, f->radius, f->quality);
> + if (ret < 0)
> + return ret;
> +
> f->dist_width = vec->length;
> f->dist_linesize = FFALIGN(vec->length, 8);
> f->dist_coeff = av_malloc_array(f->dist_width, f->dist_linesize * sizeof(*f->dist_coeff));
> diff --git a/libavfilter/vf_smartblur.c b/libavfilter/vf_smartblur.c
> index 85d8d502e1..8a4e7bf1d3 100644
> --- a/libavfilter/vf_smartblur.c
> +++ b/libavfilter/vf_smartblur.c
> @@ -126,11 +126,11 @@ static int alloc_sws_context(FilterParam *f, int width, int height, unsigned int
> {
> SwsVector *vec;
> SwsFilter sws_filter;
> + int ret;
>
> - vec = sws_getGaussianVec(f->radius, f->quality);
> -
> - if (!vec)
> - return AVERROR(EINVAL);
> + ret = sws_get_gaussian_vec(&vec, f->radius, f->quality);
> + if (ret < 0)
> + return ret;
>
> sws_scaleVec(vec, f->strength);
> vec->coeff[vec->length / 2] += 1.0 - f->strength;
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index 96034af1e0..a315f37c6d 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -2365,24 +2365,20 @@ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
> if (!filter)
> return NULL;
>
> - if (lumaGBlur != 0.0) {
> - filter->lumH = sws_getGaussianVec(lumaGBlur, 3.0);
> - filter->lumV = sws_getGaussianVec(lumaGBlur, 3.0);
> - } else {
> - filter->lumH = sws_getIdentityVec();
> - filter->lumV = sws_getIdentityVec();
> - }
> -
> - if (chromaGBlur != 0.0) {
> - filter->chrH = sws_getGaussianVec(chromaGBlur, 3.0);
> - filter->chrV = sws_getGaussianVec(chromaGBlur, 3.0);
> - } else {
> - filter->chrH = sws_getIdentityVec();
> - filter->chrV = sws_getIdentityVec();
> - }
> -
> - if (!filter->lumH || !filter->lumV || !filter->chrH || !filter->chrV)
> - goto fail;
> +#define SET_FILTER_VECTOR(name_, standard_deviation_, quality_) \
> + if (standard_deviation_ != 0.0) { \
> + sws_get_gaussian_vec(&filter->name_, \
> + standard_deviation_, quality_); \
> + } else { \
> + filter->name_ = sws_getIdentityVec(); \
> + } \
> + if (!filter->name_) \
> + goto fail; \
> +
> + SET_FILTER_VECTOR(lumH, lumaGBlur, 3.0);
> + SET_FILTER_VECTOR(lumV, lumaGBlur, 3.0);
> + SET_FILTER_VECTOR(chrH, chromaGBlur, 3.0);
> + SET_FILTER_VECTOR(chrV, chromaGBlur, 3.0);
This will check lumaGBlur/chromaGBlur twice.
>
> if (chromaSharpen != 0.0) {
> SwsVector *id = sws_getIdentityVec();
More information about the ffmpeg-devel
mailing list