From patchwork Mon Oct 26 13:20:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 28623 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 E570FC324C for ; Mon, 26 Oct 2026 13:21:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B44C69012; Mon, 26 Oct 2026 14:21:00 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qoKHN71e"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0AE2E68FEF for ; Mon, 26 Oct 2026 14:20:50 +0100 (CET) Received: from pb-laptop.local (185.221.143.99.nat.pool.zt.hu [185.221.143.99]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9D9AAD0; Mon, 26 Oct 2026 14:18:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1793020718; bh=jfD0L0K1+CFaBLvik38zSoxUkdqUxYH87dw1VnxLUPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qoKHN71eFqz0a5D6uVOYG+c+jrkf9ipvL6eseshcb0wfuGBQIZ3+zj6FOs0GzIZvW 7RKm8v4CFZ8eE/lHNZIxbdpFZil/sv5CZP08YY0A6EpBLeYZBw3PwIwR/QuuYAy4Lr HuExAgsVIRdiq79/UoyHXLk+ZcJeC/4TjcMjcdCU= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi Subject: [RFC PATCH v4 06/23] ipa: libipa: exposure_mode_helper: Move `stageGain` variable Date: Mon, 26 Oct 2026 14:20:28 +0100 Message-ID: <20261026132045.269007-7-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261026132045.269007-1-barnabas.pocze@ideasonboard.com> References: <20261026132045.269007-1-barnabas.pocze@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" After the loop, `stageGain == lastStageGain`, so use `lastStageGain` in the later calculation instead, and make `stageGain` "local" to the loop, just like `stageExposure` already is. And with that, also move the calculation a bit later, just before the value is actually used. Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi --- src/ipa/libipa/exposure_mode_helper.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp index 3e600a5c76..8a712c6da9 100644 --- a/src/ipa/libipa/exposure_mode_helper.cpp +++ b/src/ipa/libipa/exposure_mode_helper.cpp @@ -240,13 +240,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const exposure / (exposureTime * gain * quantGain) }; } - double stageGain = clampGain(1.0); - double lastStageGain = stageGain; + double lastStageGain = clampGain(1.0); for (const auto &stage : stages_) { utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime, &quantGain); - stageGain = clampGain(stage.gain); /* * We perform the clamping on both exposure time and gain in @@ -267,6 +265,8 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const } /* Clamp the exposureTime to stageExposureTime and regulate gain. */ + const double stageGain = clampGain(stage.gain); + if (stageExposureTime * stageGain >= exposure) { exposureTime = stageExposureTime; gain = clampGain(exposure / exposureTime, &quantGain2); @@ -283,10 +283,10 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const * From here on all we can do is max out the exposure time, followed by * the analogue gain. If we still haven't achieved the target we send * the rest of the exposure time to digital gain. If we were given no - * stages to use then the default stageGain of 1.0 is used so that - * exposure time is maxed before gain is touched at all. + * stages to use then the default gain of 1.0 is used so that exposure + * time is maxed before gain is touched at all. */ - exposureTime = clampExposureTime(exposure / stageGain, &quantGain); + exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain); gain = clampGain(exposure / exposureTime, &quantGain2); quantGain *= quantGain2;