From patchwork Wed Feb 11 13:17:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26131 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 87C86BDE6B for ; Wed, 11 Feb 2026 13:17:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2923D621AB; Wed, 11 Feb 2026 14:17:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="gpJ6NpyY"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A5F7621A3 for ; Wed, 11 Feb 2026 14:17:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770815867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WPk1K/IdOSge/OcmzVdWPq8Ni5XtNG11l5wnfhNyd8M=; b=gpJ6NpyYPRtyPGGwdnIbcVVSk9dilWs97HsBhzvdY9NDBdXVYc57NQSlFFnw8maRybQAQw WeHbUlfqqfEwcKvmKDkwE6iL9t0lVBzDC0TsOrVp+6Lfto5LhXmzAX0qUQkg5f25XC2Att ilWRQhWlYWZQLjFpcARiljRi3+Xjpsc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-R7OVeE5nPtu2bWCe4fdxzQ-1; Wed, 11 Feb 2026 08:17:45 -0500 X-MC-Unique: R7OVeE5nPtu2bWCe4fdxzQ-1 X-Mimecast-MFC-AGG-ID: R7OVeE5nPtu2bWCe4fdxzQ_1770815864 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6193B195609F; Wed, 11 Feb 2026 13:17:44 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.226.74]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 520D019560A3; Wed, 11 Feb 2026 13:17:42 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Kieran Bingham , Bryan O'Donoghue Subject: [PATCH 1/2] ipa: simple: Limit the black level value Date: Wed, 11 Feb 2026 14:17:27 +0100 Message-ID: <20260211131728.96413-2-mzamazal@redhat.com> In-Reply-To: <20260211131728.96413-1-mzamazal@redhat.com> References: <20260211131728.96413-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 29MFmCD8UmfZsCKL-lVM5nUxiq-J8PXARyPKbG__eho_1770815864 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The black level value is passed to image processing, where it's used in pixel value computations. To avoid troubles with weird black level values (which are mostly theoretical but we should be still safe against e.g. crazy values in testing tuning files) like division by zero, let's make sure the black level passed to the image processing is lower than the maximum pixel value. Signed-off-by: Milan Zamazal Reviewed-by: Bryan O'Donoghue --- src/ipa/simple/algorithms/blc.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp index 464e43c27..b318d0354 100644 --- a/src/ipa/simple/algorithms/blc.cpp +++ b/src/ipa/simple/algorithms/blc.cpp @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* - * Copyright (C) 2024-2025, Red Hat Inc. + * Copyright (C) 2024-2026, Red Hat Inc. * * Black level handling */ @@ -52,8 +52,9 @@ void BlackLevel::prepare(IPAContext &context, [[maybe_unused]] IPAFrameContext &frameContext, DebayerParams *params) { - /* Latch the blacklevel gain so GPUISP can apply. */ - params->blackLevel = RGB(context.activeState.blc.level / 255.0f); + /* Make sure the black level is sane, i.e. below maximum pixel value. */ + params->blackLevel = RGB(context.activeState.blc.level / 255.0f) + .min(0.99); } void BlackLevel::process(IPAContext &context, From patchwork Wed Feb 11 13:17:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 26132 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2C8ADBDE6B for ; Wed, 11 Feb 2026 13:17:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CDE1B621B8; Wed, 11 Feb 2026 14:17:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="S6YdA+uk"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 838EF621A3 for ; Wed, 11 Feb 2026 14:17:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770815872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=63ssZNW64TKNF2J3VStxrqh3P1OnX3XVYMKB/7MzO4w=; b=S6YdA+ukh9A04pkazDLmM9v8BW8WZmlqHIYxUsZRnZirSHzbAkY0Dn+woh2Ct5JVuXbkFP bkcOZFnNnfSqwPv4lZemcCli/rLzJnh6oFxGs44YMLsmYME5qae2xNL5ofCgczCXZitDID k34fLNYQXS5rFw9vz91d/cuLVs8osVc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-fupWz5erPDuLWJIMKhwY9A-1; Wed, 11 Feb 2026 08:17:48 -0500 X-MC-Unique: fupWz5erPDuLWJIMKhwY9A-1 X-Mimecast-MFC-AGG-ID: fupWz5erPDuLWJIMKhwY9A_1770815867 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 74AAC1956053; Wed, 11 Feb 2026 13:17:47 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.226.74]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8BA5419560A3; Wed, 11 Feb 2026 13:17:45 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Kieran Bingham , Bryan O'Donoghue Subject: [PATCH 2/2] libcamera: software_isp: Fix black level application in GPU ISP Date: Wed, 11 Feb 2026 14:17:28 +0100 Message-ID: <20260211131728.96413-3-mzamazal@redhat.com> In-Reply-To: <20260211131728.96413-1-mzamazal@redhat.com> References: <20260211131728.96413-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pRhNPUPcz98_IecSN3vPiTzQV8uFkJz63HyKeKCq56c_1770815867 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In GPU ISP fragment shaders, the black level is simply subtracted from the pixel value. This means the highest pixel values can never be reached, possibly resulting in wrong brightness or colour shifts. Fix this by spreading the resulting value to the whole 0.0..1.0 range. The preceding simple pipeline IPA patch ensures `blacklevel' is less than 1.0, preventing division by zero here. Signed-off-by: Milan Zamazal Reviewed-by: Bryan O'Donoghue --- src/libcamera/shaders/bayer_1x_packed.frag | 2 +- src/libcamera/shaders/bayer_unpacked.frag | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 23747f78a..06ddc040b 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -225,7 +225,7 @@ void main(void) vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); - rgb = rgb - blacklevel; + rgb = (rgb - blacklevel) / (1.0 - blacklevel); /* * CCM is a 3x3 in the format diff --git a/src/libcamera/shaders/bayer_unpacked.frag b/src/libcamera/shaders/bayer_unpacked.frag index 1b85196ae..98dea512c 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -128,7 +128,7 @@ void main(void) { vec3(PATTERN.w, C, PATTERN.z) : vec3(PATTERN.yx, C)); - rgb = rgb - blacklevel; + rgb = (rgb - blacklevel) / (1.0 - blacklevel); /* * CCM is a 3x3 in the format