From patchwork Mon Oct 19 18:45:11 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: 28511 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 3B063C324C for ; Mon, 19 Oct 2026 18:45:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 007A568EEB; Mon, 19 Oct 2026 20:45:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IfZM8UtQ"; 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 0908168E44 for ; Mon, 19 Oct 2026 20:45:32 +0200 (CEST) Received: from pb-laptop.local (185.221.141.235.nat.pool.zt.hu [185.221.141.235]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B2328593 for ; Mon, 19 Oct 2026 20:43:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1792435405; bh=bHhtrUvoiPIBUDSS5JcRzWTJXJESTeQnPQJx4/Wu50g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IfZM8UtQXoX0YNbNC/PVoe8dBnnzdu54piMV5wXvMo6Gsl/0jnK0VArLiZURrDOwb fSqMwmjpG5M7LhYfx3XFy+Xvp71/p6yZQx29V7Hvx2XHY5LyahChpbRKfdRUm7Qx+h 9CHYUCbGg6FeeKnYOGp8NzRtszVjOQlcL3mrsfYM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v3 04/19] ipa: libipa: exposure_mode_helper: Move `stageGain` variable Date: Mon, 19 Oct 2026 20:45:11 +0200 Message-ID: <20261019184526.252977-5-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261019184526.252977-1-barnabas.pocze@ideasonboard.com> References: <20261019184526.252977-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 --- 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 380edee825..51f4be98e2 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;