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 545274A531 for ; Tue, 19 Aug 2025 14:25:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1C7BA68D4EB; Tue, 19 Aug 2025 17:25:14 +0300 (EEST) Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id D5C5868D0D8 for ; Tue, 19 Aug 2025 17:25:07 +0300 (EEST) Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-70a9f534976so174402876d6.2 for ; Tue, 19 Aug 2025 07:25:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755613506; x=1756218306; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l2gXQM6vjmzXCXylOxXG3iRm6hjskRuTq7V6SeXp7WE=; b=bwLl36uCdsroEexrynBpherPQKiWpj8sLeyXRvEHcW9O1IR/ICnQvlUvU3XVCaX4Ro FfnMx1M6elAIZRjmEuf8lw6VRJJQdDUsf7MFzed5jV9oxrtkZYau3iOlrhZzHcJaggIN DVVUpOu3g3MiP6UPAZyffRH0rKss54EBATkkDxaRHdl23cg+NVGpH1jYlRf9WejMVIKR LM8XSPEwhsPj3emqL2pL4xkA3i4S7RwkK8+2Xx9JS763Y6b+lb5eS7SK7alaa5UUQcX7 Lzovvj+sOLs4dzW5bY9UQZafYuxYWyRZfnLejfnMGqvWeTmo92MWNCr3Honrq2fJdbyu vHdA== X-Gm-Message-State: AOJu0YwjqejvKF1RS9/g81Lo1elWOwBW5y5z9mRvAXqaEfqs3INT7btb 6tNZIcra3m0Ch2qt9FeCqnAHtug363ZEqrTHlBb/zVFkAlMdpUcOW4IhAF6xfWuFZwMEc0G81jW yzXlUd/shiz5XFv4vq5d658mTzIa15yifnHpdL2/9GlsdKPQSp7wklKAOjPeTQPSFJL7kqr64CG PmuxECeS5Ax3oaFw/gr8rpCIaFZm3aW7mpD3g/a9yTHA8= X-Google-Smtp-Source: AGHT+IGCnbXiJ+UE3OwddUUkX1Gb8YecBFIGgSLtcKKB0/Rp75Nowf7XpYIQybTwfLsvwnIX4P9mFDtPzY81 X-Received: from qkph2.prod.google.com ([2002:a05:620a:2842:b0:7e9:ec41:463]) (user=asdunne job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:5e0c:b0:4b2:8e3b:c105 with SMTP id d75a77b69052e-4b28e3bc800mr6337791cf.26.1755613028027; Tue, 19 Aug 2025 07:17:08 -0700 (PDT) Date: Tue, 19 Aug 2025 14:17:05 +0000 In-Reply-To: <347845> Mime-Version: 1.0 References: <347845> X-Mailer: git-send-email 2.51.0.rc1.167.g924127e9c0-goog Message-ID: <20250819141705.665193-1-asdunne@google.com> To: ffmpeg-devel@ffmpeg.org Subject: [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: , From: Drew Dunne via ffmpeg-devel 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: 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. Sorry about sending this multiple times, my comments outside my commit message kept being removed from the patch for some reason. I was trying to respond to the comment on confirming no additional time added. I ran "time" with a command running just this filter on YUV frames and confirmed that no significant time was adding with this patch. They both averaged to the same time to the hundredth second. Signed-off-by: Drew Dunne --- doc/filters.texi | 3 +++ libavfilter/vf_colorspace.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 908c98a3cf..cb09d73f62 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10403,6 +10403,9 @@ von Kries whitepoint adaptation identity whitepoint adaptation (i.e. no whitepoint adaptation) @end table +@item clamptrc +Clamps the linear and delinear transfer characteristics LUT values to the [0, 1] represented range. + @item iall Override all input properties at once. Same accepted values as @ref{all}. diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c index e1f4725f63..15b4858b24 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 clamp_trc; 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)); + long d_rounded = lrint(d * 28672.0); + s->delin_lut[n] = s->clamp_trc ? av_clip64(d_rounded, 0, 28672) + : av_clip_int16(d_rounded); // 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)); + long l_rounded = lrint(l * 28672.0); + s->lin_lut[n] = s->clamp_trc ? av_clip64(l_rounded, 0, 28672) + : av_clip_int16(l_rounded); } return 0; @@ -1000,6 +1005,11 @@ static const AVOption colorspace_options[] = { ENUM("vonkries", WP_ADAPT_VON_KRIES, "wpadapt"), ENUM("identity", WP_ADAPT_IDENTITY, "wpadapt"), + { "clamptrc", + "Clamps the linear and delinear LUT output values to the range [0, 1].", + OFFSET(clamp_trc), 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" }, -- 2.51.0.rc1.167.g924127e9c0-goog _______________________________________________ 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".