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 12A45474A2 for ; Thu, 14 Aug 2025 15:24:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 240D368D144; Thu, 14 Aug 2025 18:23:58 +0300 (EEST) Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id A6ABD688146 for ; Thu, 14 Aug 2025 18:23:51 +0300 (EEST) Received: by mail-qk1-f201.google.com with SMTP id af79cd13be357-7e87031d3e5so239120785a.0 for ; Thu, 14 Aug 2025 08:23:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755185030; x=1755789830; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uHqxOsnsuWFLhJ7sPWsnkLFCz1MzAJBr4hkGe9sGJxc=; b=t1RK0BFf811hFrmMR+NosZ2TB7VO8KrT69AgQ8MLmWf43+Pdq9JsiKfkKdimsd8TAg UovHctuskNK+wt8yVkcVMcrBhhxGwQeDWnKnoXjg4PgsrCAUluOBX8gVTCSIeyHO7m+j A32wN27Z/G2Fu/7PimSVHtWoZ03z5pUvU4hQbkLUv5pacUb1xBBCEugV1jkKidcnQKhc 5hFULe3Jlh2OhqAiNxRD8TyoISpvd7oB1+BvmHyslx2K4qOWCmNcxNjHCK+qQHuMUYcV iIaTRDGZXNuDsX1ReRd5Zrhso8hVPFUo+AiphneoTXzYDr855hEoGNfqbASDiIMRamN3 BYPw== X-Gm-Message-State: AOJu0YzB+UMvpaLNy0bX8/12B30ukqqvyHRyV+cNWXSqiqIK+1kDW1DI BLB5qglt729t5OTUWkBRZ7AJOYpkChtmEGBgmPQhQUWA+ybzWipni4ftL770ig4Vgl1S65EdXhQ noAq5hC8i1jOERgU35wouhNeNUnv8EbZBAFGuUnysu504+L0UCQZUy4fVbhi/huVMIgecglFOZW TAsx4SQnCWiyvvRPPV7rocDvHvsYjIW1a8IfzPfAffwrw= X-Google-Smtp-Source: AGHT+IHQQMAWzVdI4RqAaxcUidKFl7fvZUh2b+bxw9rSRqGl+N3Mm4hWwcm7EIoRPTjIDi8AhwGTWXlxWoNi X-Received: from qknqf8.prod.google.com ([2002:a05:620a:6608:b0:7e7:e2de:8358]) (user=asdunne job=prod-delivery.src-stubby-dispatcher) by 2002:a05:620a:4513:b0:7e8:50ee:615 with SMTP id af79cd13be357-7e870584943mr431445785a.51.1755185029669; Thu, 14 Aug 2025 08:23:49 -0700 (PDT) Date: Thu, 14 Aug 2025 15:23:25 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.51.0.rc1.167.g924127e9c0-goog Message-ID: <20250814152325.201238-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 --- libavfilter/vf_colorspace.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; 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; // 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; } 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" }, -- 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".