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 CE9BE497CA for ; Mon, 18 Aug 2025 15:55:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id C0C1168D493; Mon, 18 Aug 2025 18:55:28 +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 2D1EF68D3FA for ; Mon, 18 Aug 2025 18:55:22 +0300 (EEST) Received: by mail-qv1-f74.google.com with SMTP id 6a1803df08f44-70a9f636685so147117356d6.3 for ; Mon, 18 Aug 2025 08:55:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755532521; x=1756137321; 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=p6w6IjMx6WSqZktteI/bbUS+4zkOwrntgyhMgUZe7hI=; b=dr+JNsPrxVYtkAFQ2pATH4w7ODFWLP0Yl649jX6parS1LWspI115CRGq9hwNFhjIZa tUl4mp/+YmBCS+F/8kVqxopItvGSudtR4sCzzBgPW8RGR9aKIMlEFqth3arGCn0JG6Nr 5zuESuemOczrjDLkDQw2SdszvuG1jE+L0C8OzL4/eCqjsgBR8Ar/agtnYiVgOFxgsrI7 5J5Tox4pOdAKiWSpdBXvA3uoLtDAv1+NbYfupjQclW3BQOMYkLXT+ZUyrk848ge0IJmo leKJOX/qm+YWf8B26f7CRcEe/UYdyYRg0fBJ3fQn/lGcdfHz/941FcVCzMcVM6Y3XGaI utmA== X-Gm-Message-State: AOJu0Yy/a61fcMJrjoSPRfTB3cSvfnKrvYwuscwpJxVdCAHPuCI0pBDd s2Y5aJbGC4r9jcnElfzMVuQuPru7fxjo273w4zIu11xg2NVEVPwvW9kOtHuQUSLziRffq31Pq7t RhwkTlmBwp9MIT/3hr2xadewizwK16KMo1KJqaDpD9Sgg/Bm0hz2TFRQJO7bKb1PnKFHAGb8bA6 jz37aH3xO/9WBz8s6ziEPgURd15ngmAsrIoZzihy9oLv8= X-Google-Smtp-Source: AGHT+IFD7FUezRc9WVHJ3WOkTEc1LYb2xDM/XiZJsljnk14fOioTcyfMG/2d8DZud3OwnvBy0EcwEJxbUIW9 X-Received: from qvbri20.prod.google.com ([2002:a05:6214:3314:b0:709:7382:fa16]) (user=asdunne job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6214:23ca:b0:70b:43c4:21f8 with SMTP id 6a1803df08f44-70bb063ee18mr94676636d6.43.1755532520200; Mon, 18 Aug 2025 08:55:20 -0700 (PDT) Date: Mon, 18 Aug 2025 15:55:14 +0000 In-Reply-To: <347789> Mime-Version: 1.0 References: <347789> X-Mailer: git-send-email 2.51.0.rc1.163.g2494970778-goog Message-ID: <20250818155514.2078553-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. 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.163.g2494970778-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".