From patchwork Thu Apr 3 15:49:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23132 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 092F0C327D for ; Thu, 3 Apr 2025 15:50:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B8D5368AB7; Thu, 3 Apr 2025 17:50:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="X7vsoyFA"; 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 CAAF268AB5 for ; Thu, 3 Apr 2025 17:50:22 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 22A7F1624; Thu, 3 Apr 2025 17:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743695309; bh=kQ2fDfNpxKxYjPice0bjRindnmwA0nJ8zzwa8VIAV4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X7vsoyFANVJHc1BXsOT+ZA/txtmTuM9U2U9rynLwP9mlOMZxv1YOOLclhxhU3P3Jj 0N4PQHrV9y4oW47gETH7Mbl9zk6eL6Ry0EW6ANYFPfL0HqwHbijL4OHUg8n7ngwjne Vm/WN2xa1gh7Lnpvtujpuh2Z3xD/2Tf7eRTnJZEY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v3 16/16] ipa: rkisp1: awb: Avoid division by zero Date: Thu, 3 Apr 2025 17:49:21 +0200 Message-ID: <20250403154925.382973-17-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403154925.382973-1-stefan.klug@ideasonboard.com> References: <20250403154925.382973-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 03449e87e1a0..84aa1d29419d 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -406,9 +406,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; }