From patchwork Wed Mar 19 16:11:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22995 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 8FE72C32FE for ; Wed, 19 Mar 2025 16:12:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4D2A968967; Wed, 19 Mar 2025 17:12:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JQ+bZB6q"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BAEC68967 for ; Wed, 19 Mar 2025 17:12:47 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:760:e5ca:4814:99c7]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 840408FA; Wed, 19 Mar 2025 17:11:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742400664; bh=NKZRysVlMDp+4JBntlGKrY42fUrM7otHIIeC2HGtXyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JQ+bZB6qAlIX9lsMjjg36YoJpDnny6MTF7SAiaJE0VHS+XwE/QVaM2nxvnGJIPrxu Yu51q6runL0pQXQvOwUVNcEgVO7CR05CWGNccKuOAq3UyJAediHlUt5VhOoVqZm0Qi +QqlN9UJmJPXqe75o2QI1RCn+7PUaxRBYYJgStVQ= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v2 17/17] ipa: rkisp1: awb: Avoid division by zero Date: Wed, 19 Mar 2025 17:11:22 +0100 Message-ID: <20250319161152.63625-18-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250319161152.63625-1-stefan.klug@ideasonboard.com> References: <20250319161152.63625-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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" As the gains can also be specified manually, the regulation can run into numeric instabilities by dividing by near zero. Mitigate that by applying a small minium value. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v2: - Collected tag --- src/ipa/rkisp1/algorithms/awb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index e8b04d03748d..eb4545439ae3 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -421,9 +421,9 @@ RGB Awb::calculateRgbMeans(const IPAFrameContext &frameContext, const rk /* * The ISP computes the AWB means after applying the colour gains, * divide by the gains that were used to get the raw means from the - * sensor. + * sensor. Apply a minimum value to avoid divisions by near-zero. */ - rgbMeans /= frameContext.awb.gains; + rgbMeans /= frameContext.awb.gains.max(0.01); return rgbMeans; }