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 37B3047296 for ; Sun, 3 Sep 2023 16:34:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7EF3068C691; Sun, 3 Sep 2023 19:34:14 +0300 (EEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AF8B68C62B for ; Sun, 3 Sep 2023 19:34:08 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6D6BE240002 for ; Sun, 3 Sep 2023 16:34:07 +0000 (UTC) Date: Sun, 3 Sep 2023 18:34:06 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230903163406.GE8640@pb2> References: <20230826122328.95416-1-stefasab@gmail.com> <20230901165440.GA7802@pb2> <20230902200753.GB8640@pb2> MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc 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 Content-Type: multipart/mixed; boundary="===============8184684303543569124==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8184684303543569124== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OZkY3AIuv2LYvjdk" Content-Disposition: inline --OZkY3AIuv2LYvjdk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 03, 2023 at 02:25:07AM +0200, Stefano Sabatini wrote: > On date Saturday 2023-09-02 22:07:53 +0200, Michael Niedermayer wrote: > > On Fri, Sep 01, 2023 at 08:38:26PM +0200, Stefano Sabatini wrote: > > > On date Friday 2023-09-01 18:54:40 +0200, Michael Niedermayer wrote: > > > > On Thu, Aug 31, 2023 at 07:16:20PM +0200, Stefano Sabatini wrote: > > > [...] > > > > > +/** > > > > > + * 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 gene= rate > > > > > + * 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_l= og) > > > > > + * 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 quali= ty, > > > > > + void *log_ctx); > > > >=20 > > > > which of the two do you consider better? > > > >=20 > > > > First, here the central part we return is the vector > > > >=20 > > > > SwsVector *gaus_vec =3D sws_getGaussianVec(NULL, 1, 2); > > > > SwsVector *temp_vec =3D sws_ConvolveVec(NULL, in_vec, gaus_vec); > > > > sws_averageVec(temp_vec, temp_vec, in_vec); > > > >=20 > > > > av_free(gaus_vec); > > > > return temp_vec; // Error checking here happens by temp_vec being N= ULL in all cases of error > > > >=20 > > > > vs. > > > >=20 > > > > Second, here the central part we return is the error code > > > >=20 > > > > SwsVector *gaus_vec =3D NULL; > > > > SwsVector *temp_vec =3D NULL; > > > > int err =3D sws_getGaussianVec(&gaus_vec, 1, 2); > > > > if (err<0) > > > > goto fail; > > > >=20 > > > > err =3D sws_ConvolveVec(&temp_vec, in_vec, gaus_vec); > > > > if (err<0) > > > > goto fail; > > > >=20 > > > > err =3D sws_averageVec(&temp_vec, temp_vec, in_vec); > > > > if (err<0) > > > > goto fail; > > >=20 > > > The latter pattern enables differentiation between error codes (ENOMEM > > > or EINVAL) and provides feedback in the log message. With the former > > > you only know if it fails, but you don't know why (relevant in case > > > e.g. we make the parameter tunable by a filter and we don't want to > > > add additional validation and logging at the filter level). > >=20 >=20 > > can the API be designed so that optionally the user could choose to > > only check the error code after several steps ? > > (this would avoid the need for 1 check per call where the fine grained > > information is not needed) > > I mean similar to the concept of NAN in floating point so that a failure > > can be propagated and only at the end checked. >=20 > Well, with the new approach you can do: >=20 > SwsVector *gaus_vec, *temp_vec, *avg_vec; >=20 > sws_get_gaussian_vec(&gaus_vec, 1, 2); > sws_get_convolution_vec(&temp_vec, in_vec, gaus_vec); > sws_get_average_vec(&avg_vec, temp_vec, in_vec); > =20 > av_free(gaus_vec); > av_free(temp_vec); > return avg_vec; // Error checking here happens by avg_vec being NULL in a= ll cases of error ok >=20 > If you want to disable the log we could add a log_ctx_offset parameter. as long as theres a pointer to a log context that should be enough. A log context can modify the log level passing a seperate and mandatory level offset per call would be a bit ugly thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Any man who breaks a law that conscience tells him is unjust and willingly= =20 accepts the penalty by staying in jail in order to arouse the conscience of= =20 the community on the injustice of the law is at that moment expressing the= =20 very highest respect for law. - Martin Luther King Jr --OZkY3AIuv2LYvjdk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZPS1egAKCRBhHseHBAsP q5azAJ9YSyWQT87z3FJ8IFJsW5m8FgFf4ACfXjf8EIMjRbauZdhQYpp2VfUJ6HQ= =ej7x -----END PGP SIGNATURE----- --OZkY3AIuv2LYvjdk-- --===============8184684303543569124== 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". --===============8184684303543569124==--