From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7CCB247FFE for ; Thu, 14 Aug 2025 17:25:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 7490168D181; Thu, 14 Aug 2025 20:25:21 +0300 (EEST) Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 831CC68B18F for ; Thu, 14 Aug 2025 20:25:15 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 57EHPEY9018935 ; Thu, 14 Aug 2025 19:25:14 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 878C92EFE3; Thu, 14 Aug 2025 19:25:14 +0200 (CEST) Date: Thu, 14 Aug 2025 19:25:14 +0200 From: Nicolas George To: FFmpeg development discussions and patches Message-ID: References: <20250814152325.201238-1-asdunne@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814152325.201238-1-asdunne@google.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 14 Aug 2025 19:25:14 +0200 (CEST) Subject: Re: [FFmpeg-devel] [PATCH] vf_colorspace: Add an option to clamp trc LUT output 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: Drew Dunne Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Drew Dunne via ffmpeg-devel (HE12025-08-14): > Add a new flag to the vf_colorspace filter which provides the user an > option to clamp the linear and delinear transfer characteristics LUT > values to the [0, 1] represented range. This helps constrain the > potential value range when converting between colorspaces. Hi. Thanks for the patch. This filter seems orphaned. I will go at it. > Signed-off-by: Drew Dunne > --- > libavfilter/vf_colorspace.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) Missing update to doc/filters.texi. > > diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c > index e1f4725f63..48aa267c07 100644 > --- a/libavfilter/vf_colorspace.c > +++ b/libavfilter/vf_colorspace.c > @@ -123,6 +123,7 @@ typedef struct ColorSpaceContext { > int fast_mode; > enum DitherMode dither; > enum WhitepointAdaptation wp_adapt; > + int clamplutoutput; Other members in the structure have morereadablenames; please use underscores. > > int16_t *rgb[3]; > ptrdiff_t rgb_stride; > @@ -215,7 +216,9 @@ static int fill_gamma_table(ColorSpaceContext *s) > } else { > d = out_alpha * pow(v, out_gamma) - (out_alpha - 1.0); > } > - s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0)); > + int d_int = av_clip_int16(lrint(d * 28672.0)); > + s->delin_lut[n] = > + s->clamplutoutput ? FFMIN(FFMAX(0, d_int), 28672) : d_int; Please use av_clip() instead of chaining FFMIN() and FFMAX(). Also, avoid chaining av_clip_int16() and clipping to a smaller interval. By the way, can you confirm it makes no significant difference in time? > > // linearize > if (v <= -in_beta * in_delta) { > @@ -225,7 +228,9 @@ static int fill_gamma_table(ColorSpaceContext *s) > } else { > l = pow((v + in_alpha - 1.0) * in_ialpha, in_igamma); > } > - s->lin_lut[n] = av_clip_int16(lrint(l * 28672.0)); > + int l_int = av_clip_int16(lrint(l * 28672.0)); > + s->lin_lut[n] = > + s->clamplutoutput ? FFMIN(FFMAX(0, l_int), 28672) : l_int; Same as above. > } > > return 0; > @@ -1000,6 +1005,11 @@ static const AVOption colorspace_options[] = { > ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"), > ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"), > > + { "clamplutoutput", > + "Clamps the linear and delinear LUT output values to the range [0, 1].", > + OFFSET(clamplutoutput), AV_OPT_TYPE_BOOL, { .i64 = 0 }, > + 0, 1, FLAGS }, > + > { "iall", "Set all input color properties together", > OFFSET(user_iall), AV_OPT_TYPE_INT, { .i64 = CS_UNSPECIFIED }, > CS_UNSPECIFIED, CS_NB - 1, FLAGS, .unit = "all" }, Regards, -- Nicolas George _______________________________________________ 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".