From patchwork Mon Nov 2 16:50:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 28764 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 D172AC3358 for ; Mon, 2 Nov 2026 16:50:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B28FE6933A; Mon, 2 Nov 2026 17:50:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H6OZ8uN8"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5CCD269214 for ; Mon, 2 Nov 2026 17:50:37 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:440f:c6d2:4304:87e4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 38345BE; Mon, 2 Nov 2026 17:48:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1793638100; bh=3tKzMz3F3Lq9Pu0bwKK0QGN+Pxli4ALFb6q2l5i5ahM=; h=From:To:Cc:Subject:Date:From; b=H6OZ8uN8ohF+Fl893ZNQUVD7NElLbY7OUQAWPeQ9YSS5ISg81LUazoycqopzIOOfA lpcdSWmuxnVVYx96iWWb3eRGiLktTCqr34ZCWfJqTtNkD1QxhnFOzKXSirDxSn8Dx+ ubKaw4WDMkOYqS+EEfI/zIvO+T+yvyiqjSH1n1k4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH] libipa: agc_mean_luminance: Improve inital gain estimation Date: Mon, 2 Nov 2026 17:50:16 +0100 Message-ID: <20261102165032.3921934-1-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.53.0 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" In AgcMeanLuminance::estimateInitialGain() a constant value of 0.001 is added to yValue. This is there to prevent division by 0 in cases where yValue is 0. This offset produces a noticeable error in the gain calculation (Which is especially annoying when doing hand calculations to check the correct inner workings of the algorithms). Fix that by replacing the fixed offset by a max() function. Reorder the parameters to the outer min() for better readability. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Daniel Scally --- src/ipa/libipa/agc_mean_luminance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index cdfca47a3485..5b0a6e259433 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -527,7 +527,8 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge */ for (unsigned int i = 0; i < 8; i++) { double yValue = traits.estimateLuminance(yGain); - double extra_gain = std::min(10.0, yTarget / (yValue + .001)); + double extra_gain = std::min(yTarget / std::max(yValue, 0.001), + 10.0); yGain *= extra_gain; LOG(AgcMeanLuminance, Debug) << "Y value: " << yValue