From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C588C4720C for ; Thu, 31 Aug 2023 17:16:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8209C68C7D5; Thu, 31 Aug 2023 20:16:29 +0300 (EEST) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB95768C799 for ; Thu, 31 Aug 2023 20:16:23 +0300 (EEST) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-401b3ea0656so10319335e9.0 for ; Thu, 31 Aug 2023 10:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693502182; x=1694106982; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=asoi448khxuh8dtIQD5GtQKMBcf7ThASOMc6rkNNTts=; b=cw/SWo0a0M+WKbM8vPHtaJbpjVlTg+YSXGnOYvmp1U+F5DSjhvlvDtbzAssRlmJRn2 r2nQqPGuORT3SPrHIBBdahJqv5LHXimkusdMinJRCoiPIamuVn2sHqBdzCKBGpChAddY 7ckzVzFxNO9fgBFbM0hQ4sUJ2X7+p0LQgnJtkr+cdrXvCHYGH2xrYssQqatItVoVwSvu ShoPWy99VOHmmziUvJLaSPS7mZTOw/gEBRAMy9FMCVti6kL4CWlaW4ODm0oWajOYtUNb QVCKDI72uOzIEgs66vGHuOrNLusZd+kC9xepSgV3n8WsMXAuSbdkUXxAYlCtFKoPstUc 5SBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693502182; x=1694106982; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=asoi448khxuh8dtIQD5GtQKMBcf7ThASOMc6rkNNTts=; b=dzfjrkbPWitycat99FjH/usTKWGWmZQHrrN44LjYPvL1dgsMtUB8GTMQjO1TaTX+5U hYktD9hATtm7IpTYM5PrAji33bObDBv2xYO9LGbZD5QV2acVrLAqicF1TTkLRuuQLNkd CNjB2tFzdtvExhGwxD8EdVok7C3dWtWD/P+OJm/x4b0NX0e/pdBN4sdiWIs+g+MWERxi mGFDGZp2hziQqOSD32z3I5WY6ClEDFfRNYavHO/fQAKYftlq+rRfKTKm+dTn/nrf0EPB lFlbrcFakB0V+jtVciiiq2PPEu8aUDerGBmy5xPD+mSiOgxMrLuIffrk92RRzOwjlPyN twow== X-Gm-Message-State: AOJu0YwCGbXkTwaxANq5bwHfru/hMTg5ltb5+e57O/QKt7S0/IMltcxl /l3pXzldzclXEnx4O0+BnGlihVs0Dq8= X-Google-Smtp-Source: AGHT+IHxHblcXSjauQopnD4/iC4JwNuFD/QWLFw/usGU1Ya1obiB1dmRezlaM5NXOj3goNYkYS7E1A== X-Received: by 2002:a05:600c:214d:b0:401:bd95:2e02 with SMTP id v13-20020a05600c214d00b00401bd952e02mr4515850wml.39.1693502182326; Thu, 31 Aug 2023 10:16:22 -0700 (PDT) Received: from mariano ([82.84.194.139]) by smtp.gmail.com with ESMTPSA id g18-20020adfa492000000b003143cb109d5sm193292wrb.14.2023.08.31.10.16.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 10:16:21 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 97361BFCDA; Thu, 31 Aug 2023 19:16:20 +0200 (CEST) Date: Thu, 31 Aug 2023 19:16:20 +0200 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20230826122328.95416-1-stefasab@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wsJhScYf4PN6IHF2" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH] lsws/swscale.h: introduce sws_get_gaussian_vec X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --wsJhScYf4PN6IHF2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On date Thursday 2023-08-31 18:51:52 +0200, Andreas Rheinhardt wrote: > Stefano Sabatini: > > +int sws_get_gaussian_vec(SwsVector **vecp, > > + AVClass *log_ctx, > > + double standard_deviation, double quality); > > > > Seriously? A pointer to an AVClass as log_ctx? It is actually AVClass** > (the logcontext must have a pointer to an AVClass as its first member), > but we always use NULL. Sorry, sloppy editing on my side. > Apart from that: I am not really convinced that the improvement is worth > the hassle. This is not a high-profile function (probably it's never used outside lavfi) and provides an opportunity to move the API to the correct direction. --wsJhScYf4PN6IHF2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-lsws-swscale.h-introduce-sws_get_gaussian_vec.patch" >From 69c33f62e15de3d199d54187d38c0856418f0981 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 26 Aug 2023 14:20:35 +0200 Subject: [PATCH 1/2] lsws/swscale.h: introduce sws_get_gaussian_vec Use in place of sws_getGaussianVec. The new function enable better error handling, and provide better naming for the variance variable, now named standard_deviation to reflect the meaning of the parameter. --- doc/APIchanges | 3 +++ libswscale/swscale.h | 27 +++++++++++++++++++++++- libswscale/utils.c | 42 ++++++++++++++++++++++++++++++-------- libswscale/version.h | 2 +- libswscale/version_major.h | 4 ++++ 5 files changed, 67 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..55f2fc4a48 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -355,11 +355,36 @@ 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. + * @deprecated use sws_get_gaussian_vector() */ +attribute_deprecated SwsVector *sws_getGaussianVec(double variance, double quality); +#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. + * @param log_ctx a pointer to an arbitrary struct of which the first + * field is a pointer to an AVClass struct (used for av_log) + * used for logging, can be NULL + * + * @return a negative error code on error, non negative otherwise + */ +int sws_get_gaussian_vec(SwsVector **vecp, + double standard_deviation, double quality, + void *log_ctx); /** * Scale all the coefficients of a by the scalar value. diff --git a/libswscale/utils.c b/libswscale/utils.c index 8e74c6603e..fd9b2d33d0 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2139,31 +2139,55 @@ 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, + void *log_ctx) { - 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(log_ctx, 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(log_ctx, 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, NULL); + 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 */ -- 2.34.1 --wsJhScYf4PN6IHF2 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --wsJhScYf4PN6IHF2--