From patchwork Sat Jun 20 23:00:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 27000 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 41EE9C3305 for ; Sat, 20 Jun 2026 23:00:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DE45656EB; Sun, 21 Jun 2026 01:00:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FHfKSjj2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A565656DF for ; Sun, 21 Jun 2026 01:00:36 +0200 (CEST) Received: from [192.168.0.240] (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A5A9145C; Sun, 21 Jun 2026 00:59:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1781996399; bh=1Dsd99PDsCvYk3wseluybJJFhnPM+XvVCmzr+tTgNsc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FHfKSjj2RNDxoDIaLdZQg/tAEpMoNtLz25m082TPAQPUTaRYFknlDVDUnim+rfeX3 hPPl29sqa5hKC3gxJwoReoNHlyQ66fHdWTHXh2VnOwbvqCdU5FUvCukBSeV3ZZgcFR 19lxlhkKsWh8kmvbJXjNlPJkM3B7hEc9SMdHI9uE= From: Kieran Bingham Date: Sun, 21 Jun 2026 00:00:31 +0100 Subject: [PATCH 4/7] libcamera: software_isp: Fix black level application in GPU ISP MIME-Version: 1.0 Message-Id: <20260621-kbingham-awb-saturation-v1-4-b91ea59c6cfb@ideasonboard.com> References: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> In-Reply-To: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Milan Zamazal , Bryan O'Donoghue X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1781996434; l=2107; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=HO351AQHr9+o9JwpNlbZtGFYAw5B+ZtR08q33yD8XDY=; b=ym43Y/VEniUySN+wjKKPYTwnM+Cq+4G5XHRhUqMzTvq3i3NYtfTb4w5nMqPyjCiNIDf5tNz4s p4f2FVb5iSVAjmA+BH7S4l0WzVnwS6Zm2byy6GrrUvJN+suMQtrJ9vb X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY= 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" From: Milan Zamazal 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 Signed-off-by: Kieran Bingham --- src/libcamera/shaders/bayer_1x_packed.frag | 6 +++++- src/libcamera/shaders/bayer_unpacked.frag | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libcamera/shaders/bayer_1x_packed.frag b/src/libcamera/shaders/bayer_1x_packed.frag index 23747f78a6313503a46b61ed5bae6e7c178c5745..fbd15b32e5b3b510ba0dd5a75704f9ff3942e00c 100644 --- a/src/libcamera/shaders/bayer_1x_packed.frag +++ b/src/libcamera/shaders/bayer_1x_packed.frag @@ -225,7 +225,11 @@ void main(void) vec3(patterns.y, C, patterns.x) : vec3(patterns.wz, C)); - rgb = rgb - blacklevel; + /* + * \todo: Black level normalising, AWB and digital gain could be + * reworked into a single multiplication. + */ + 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 1b85196ae16130670eb3d1c077ab4884119ae63c..0f85e9a4ded7f43ce4fdabf1e045275ae2bc8f53 100644 --- a/src/libcamera/shaders/bayer_unpacked.frag +++ b/src/libcamera/shaders/bayer_unpacked.frag @@ -128,7 +128,11 @@ void main(void) { vec3(PATTERN.w, C, PATTERN.z) : vec3(PATTERN.yx, C)); - rgb = rgb - blacklevel; + /* + * \todo: Black level normalising, AWB and digital gain could be + * reworked into a single multiplication. + */ + rgb = (rgb - blacklevel) / (1.0 - blacklevel); /* * CCM is a 3x3 in the format