From patchwork Sat Aug 26 12:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 43328 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7194:b0:149:dfde:5c0a with SMTP id s20csp423628pzb; Sat, 26 Aug 2023 05:23:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFevNtwcPczMay6Z2jTau9esr8FqxdLxPWMHleodtZ8kZ0WjUBz4tDnsQlsX/E6E8DyuAzD X-Received: by 2002:a17:907:970f:b0:9a2:26fa:8752 with SMTP id jg15-20020a170907970f00b009a226fa8752mr5784049ejc.10.1693052624903; Sat, 26 Aug 2023 05:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693052624; cv=none; d=google.com; s=arc-20160816; b=Em05RMEyjZGbc6vnCEMZhfZ4/Ke/JAX/NmxO8IG3Hs5X4kjznL1ew7V+IZENg+UumX 8gbAAhAIhihF3by1+iBteZaplXms3Kcqg5KL15sNv9mNhnF3/Lob64JfiMFjvA3O/WnB 1ouOdyvJzeW3ay8mLZg/nj5NH/GH1I7xZ4YeZ5UC82DvURjas0tR3u1IGD+h73ewT9d/ EHaWo00e2y6fNqzycANKE4XX7+4Pfp7K52Azc8o9IvIP9TBMkL9WZNz51MoASfafgYdy kMM/I2NMOQnF+53cQxC0zqbLEWECemi9V3Dc4YZ0MBNK20zPMXKioHOUILtApy05VRgT sX+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=1s4bPsvZqh/aHHh6FoJ5BeVoCpg58PlwvTc6RrDBOKo=; fh=QdWxt2OToL83TTnLQn0lGhLakV7i1QyAJdC8te7qN0E=; b=GwJyaGSSB66mg39AFA9mKK22pMLvb7PY313lSK5ISjxeRCyOoZu09WAGu/72RZq0bi JnOBBNwUE2gtcn9BZlDBl1A2OpCSEetI0Jc7pyRRkRib6bhjzA4OBlJJgWQzUFNMY22R 7hAeo9MaXEkWF7aeB8oTyK97gfJD0CeUDQTjMiL5M5koOKZ5Lcvzc4RCsdXWzWbrvl56 PcNg36VvXDcJtxUXg98saZbq7y4KGkCAT945p/iaj77YCYOXijizBq5CW2JBseN9GhLE 8MYJsMbIHFYfFoy/jNIO97ZKBUUWwL4WhBavYf0DjfeVy9EGJoj5YKZ/ATNqnukqULqB HngA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=X7w+iu9h; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s26-20020a170906455a00b00988565fbf63si2126937ejq.437.2023.08.26.05.23.42; Sat, 26 Aug 2023 05:23:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=X7w+iu9h; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1604068A05D; Sat, 26 Aug 2023 15:23:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6557068C1D5 for ; Sat, 26 Aug 2023 15:23:32 +0300 (EEST) Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-31aec0a1a8bso1124453f8f.0 for ; Sat, 26 Aug 2023 05:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693052611; x=1693657411; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8uyIcEe5kX4wBg3CW+Ow3QWm+yFSknGehcL/z2eyk1Y=; b=X7w+iu9h7BRYZdBJ6LlU4AC/CC+f/4oubMmgkYkd0+h1CiHkkVhVkixFORxhHpSM88 Ox/2tRksn2O/UHpnzBV7PWk9T2GaItYJg+EtI9T81jqnlnazZO1KUV8hm/DxqxAEU/5L HR0w7lfg7uYp11EgP80raELZCVvJU15QHGW39c+3TIuP1L8K9n2soX2FB/qBsEjaEhL8 fKhY9KSI2CB8ZenfeL4ClJdWS9NhdYx7wuVBNNMxPmom01/Yj0rpF1wM5cuZTya/+pRR fD+DkYlpsjJppfpd2oFPm+4S9pFGLkMKBYbhZqyZ8KCnWHIKHDaIGFZ1WY1Rf3EVTPoY l7Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693052611; x=1693657411; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8uyIcEe5kX4wBg3CW+Ow3QWm+yFSknGehcL/z2eyk1Y=; b=j7pvxvqmqDcVc4iKoqsfyH6JsA1SCjxuMRJeyV6UwxXMgYwsVxufTFEyZZMwyWsV+7 P4tIDXLCuaQg9CnF84S75WzjJ+e/+os918mps4f2DY2caVwDi4tn4O+4zNJoSlHXziKR xE1elZ8UNCqiqvSzjjR4oSjBPyTau0hdw8cS37ZulkNb33TqMqP9jtqSOgVWYcIkP17g HkuT0/Z8Na0gEEberLFM0BayU9MoLhJ1SfHVCdE3UqLnrdqqBM8wb7KAbEi90ZKitMPC z4JmhVrJb4w1ktZXS7Kbnu8L7xm8u/YtrHXsZ/XIAfvh3GxH3a2Wa5PJXe+YJfw3trCe 7SXA== X-Gm-Message-State: AOJu0YyvjkQLqew1Xb0XbAILmGOi+NJz19x86BqaA0P6qKjWPX+Fyj6Z xvv5hMiH7YaEIcTjjScBfpKsCRqxSYc= X-Received: by 2002:a5d:5941:0:b0:318:720c:bb3 with SMTP id e1-20020a5d5941000000b00318720c0bb3mr17432160wri.20.1693052610627; Sat, 26 Aug 2023 05:23:30 -0700 (PDT) Received: from mariano ([82.84.194.139]) by smtp.gmail.com with ESMTPSA id o23-20020a5d58d7000000b0031980783d78sm4820602wrf.54.2023.08.26.05.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 05:23:29 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 78C76BFCDA; Sat, 26 Aug 2023 14:23:28 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sat, 26 Aug 2023 14:23:28 +0200 Message-Id: <20230826122328.95416-1-stefasab@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [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 Cc: Stefano Sabatini Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AV35Lll6whIr Use in place of sws_getGaussianVec. The new function enable better log 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 | 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); +#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 */