From patchwork Tue Sep 23 19:06:56 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: 24443 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 DE000C3332 for ; Tue, 23 Sep 2025 19:07:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 39BB56B611; Tue, 23 Sep 2025 21:07:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="SIft1GSQ"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [IPv6:2600:3c04:e001:324:0:1991:8:25]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E80B6B5FE for ; Tue, 23 Sep 2025 21:07:07 +0200 (CEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 3CD416027D for ; Tue, 23 Sep 2025 19:07:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 198CEC113D0; Tue, 23 Sep 2025 19:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758654425; bh=Vx/0xvt89XCCFLMy+c+hKznTAYPnX+/TgEK9P5I19Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SIft1GSQMVoxaxoPjxT0URWNwUq1trgMiQObknjqkRl1mp/8Ae/Z29qXEGp6LVHIa 1kil9OT6B026XSqRMLQu1wooxyvGufkn56i2R2+o8+JhMRVobpmJhGPQH99tbYKHOO +goOwdM3rvco8DlyMm/95+Br67HkQjXP/W6HLTbWt24uUpAM6zU8TxPgvc0iNRkg0m YnLhkW2hEbHF+Pxviw7P/xjopfHvMB7qR6QhYAU+Yj+6EzJAIKzgt+nvcz86ILDKl4 OCOG0fUvvxYth1VHGiwneLyGmV5tvmYspz1mmU/SoTcsd63t0Ig03JGdU2sGoPyQ7N BMMZx7nHw2NUg== From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Hans de Goede Subject: [PATCH 4/5] ipa: software_isp: AGC: Only use integers for exposure calculations Date: Tue, 23 Sep 2025 21:06:56 +0200 Message-ID: <20250923190657.21453-5-hansg@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250923190657.21453-1-hansg@kernel.org> References: <20250923190657.21453-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. Signed-off-by: Hans de Goede Reviewed-by: Milan Zamazal Reviewed-by: Isaac Scott --- 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 230616e62..cdde56ba2 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.againDef) { - 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