From patchwork Tue Sep 30 15:04:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 24537 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 8A755C328C for ; Tue, 30 Sep 2025 15:04:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 29E206B621; Tue, 30 Sep 2025 17:04:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="Uqh+aJVk"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DDAEF6B5FB for ; Tue, 30 Sep 2025 17:04:41 +0200 (CEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 1548B43D82; Tue, 30 Sep 2025 15:04:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C6A1C116C6; Tue, 30 Sep 2025 15:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759244679; bh=EJWoEApCSoUNGJ78tbGabNYw6JtT8v2fsDNctWXc/2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uqh+aJVkjTQT234V5BOXLTYh0texLpotbyjja0rt3pRCeJbcw0vb1ZhbjRJr/Zpm4 8sLADo4f3z4vX5J1ux62hOwBn2kZvA3krGmixGBViep0UmkGwvBMmEOhF41sycO1sM F3uJ+spfKBmfsEL2I1v6KwSTZZ4QBaFmgUtxbn2CMb0egXPfnQzgINhOhjezE5TKBr b3vNxIrrfcBUmmeWMB8NHUdLHUx/YTVBBxW8HaE2glpAAfU0wU72XXS+w23zuTpzyn Rbt+qAD1X8c+W4G7NlUOzW/xVBI1lVZRyQUpMx/f1nYKNW8uw1/i/3SXNlywlfC3DH M7pn3ew7h5Wkg== From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Hans de Goede , Milan Zamazal , Isaac Scott , Kieran Bingham Subject: [PATCH v4 4/6] ipa: software_isp: AGC: Only use integers for exposure calculations Date: Tue, 30 Sep 2025 17:04:26 +0200 Message-ID: <20250930150428.11101-5-hansg@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930150428.11101-1-hansg@kernel.org> References: <20250930150428.11101-1-hansg@kernel.org> 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" Exposure is an integer, instead of re-using the "double next" used for again calculations, doing intermediate calculations with double precision, use a local next variable of an integer type. Reviewed-by: Milan Zamazal Reviewed-by: Isaac Scott Tested-by: Milan Zamazal Tested-by: Kieran Bingham Signed-off-by: Hans de Goede --- src/ipa/simple/algorithms/agc.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp index f7f734514..3471cc881 100644 --- a/src/ipa/simple/algorithms/agc.cpp +++ b/src/ipa/simple/algorithms/agc.cpp @@ -51,19 +51,18 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou static constexpr uint8_t kExpNumeratorUp = kExpDenominator + 1; static constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1; - double next; int32_t &exposure = frameContext.sensor.exposure; double &again = frameContext.sensor.gain; if (exposureMSV < kExposureOptimal - kExposureSatisfactory) { if (exposure < context.configuration.agc.exposureMax) { - next = exposure * kExpNumeratorUp / kExpDenominator; + int32_t next = exposure * kExpNumeratorUp / kExpDenominator; if (next - exposure < 1) exposure += 1; else exposure = next; } else { - next = again * kExpNumeratorUp / kExpDenominator; + double next = again * kExpNumeratorUp / kExpDenominator; if (next - again < context.configuration.agc.againMinStep) again += context.configuration.agc.againMinStep; else @@ -73,13 +72,13 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou if (exposureMSV > kExposureOptimal + kExposureSatisfactory) { if (again > context.configuration.agc.again10) { - next = again * kExpNumeratorDown / kExpDenominator; + double next = again * kExpNumeratorDown / kExpDenominator; if (again - next < context.configuration.agc.againMinStep) again -= context.configuration.agc.againMinStep; else again = next; } else { - next = exposure * kExpNumeratorDown / kExpDenominator; + int32_t next = exposure * kExpNumeratorDown / kExpDenominator; if (exposure - next < 1) exposure -= 1; else