From patchwork Thu Nov 25 10:21:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 14777 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 8EB2CC324F for ; Thu, 25 Nov 2021 10:21:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 23E04603CB; Thu, 25 Nov 2021 11:21:55 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="T5o0JqYE"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 889C060233 for ; Thu, 25 Nov 2021 11:21:50 +0100 (CET) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:d9a5:5e40:3323:d95]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D0A3881; Thu, 25 Nov 2021 11:21:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1637835710; bh=+p6Q+oNDzc66MYHrz3PXThSVnjr2guOD/Us7w582AYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5o0JqYE/6mW3Fr8IUEH1vY9HnmjeENtDfrwrWplpvtGqVFRqrrlZph0MFrRjVU9S aDLx6lOCk50sF4hmWBBHR6wVvnQHOmRGd3Md2CG+HtvdG9DE/L2EIGVwXyJ91isL6R fSwAGXrl7hDE0+iM5OuYFMVe0CcmCz6U993txxHc= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 25 Nov 2021 11:21:42 +0100 Message-Id: <20211125102143.52556-4-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211125102143.52556-1-jeanmichel.hautbois@ideasonboard.com> References: <20211125102143.52556-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] ipa: ipu3: Remove local cached limits for shutter speed and gain 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" The limits for shutter speed and analogue gain are stored locally while those are only used in computeExposure(). Remove those local variables, and use the IPASessionConfiguration values directly. While at it, set default analogue gain and shutter speed. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 42 ++++++++++++++++++--------------- src/ipa/ipu3/algorithms/agc.h | 8 +------ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 2945a138..b822c79b 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -70,8 +70,7 @@ static constexpr uint32_t kNumStartupFrames = 10; static constexpr double kRelativeLuminanceTarget = 0.16; Agc::Agc() - : frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s), - maxShutterSpeed_(0s), filteredExposure_(0s) + : frameCount_(0), lineDuration_(0s), filteredExposure_(0s) { } @@ -90,16 +89,10 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s / configInfo.sensorInfo.pixelRate; - minShutterSpeed_ = context.configuration.agc.minShutterSpeed; - maxShutterSpeed_ = std::min(context.configuration.agc.maxShutterSpeed, - kMaxShutterSpeed); - - minAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain); - maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain); - /* Configure the default exposure and gain. */ - context.frameContext.agc.gain = minAnalogueGain_; - context.frameContext.agc.exposure = minShutterSpeed_ / lineDuration_; + context.frameContext.agc.gain = + std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain); + context.frameContext.agc.exposure = 10ms / lineDuration_; return 0; } @@ -174,17 +167,28 @@ utils::Duration Agc::filterExposure(utils::Duration currentExposure) /** * \brief Estimate the new exposure and gain values - * \param[inout] frameContext The shared IPA frame Context + * \param[inout] context The shared IPA Context * \param[in] yGain The gain calculated based on the relative luminance target * \param[in] iqMeanGain The gain calculated based on the relative luminance target */ -void Agc::computeExposure(IPAFrameContext &frameContext, double yGain, - double iqMeanGain) +void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain) { + IPASessionConfiguration &configuration = context.configuration; + IPAFrameContext &frameContext = context.frameContext; + /* Get the effective exposure and gain applied on the sensor. */ uint32_t exposure = frameContext.sensor.exposure; double analogueGain = frameContext.sensor.gain; + utils::Duration minShutterSpeed = configuration.agc.minShutterSpeed; + utils::Duration maxShutterSpeed = std::min(configuration.agc.maxShutterSpeed, + kMaxShutterSpeed); + + double minAnalogueGain = std::max(configuration.agc.minAnalogueGain, + kMinAnalogueGain); + double maxAnalogueGain = std::min(configuration.agc.maxAnalogueGain, + kMaxAnalogueGain); + /* Use the highest of the two gain estimates. */ double evGain = std::max(yGain, iqMeanGain); @@ -216,7 +220,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain, utils::Duration currentExposure = effectiveExposureValue * evGain; /* Clamp the exposure value to the min and max authorized */ - utils::Duration maxTotalExposure = maxShutterSpeed_ * maxAnalogueGain_; + utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain; currentExposure = std::min(currentExposure, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure << ", maximum is " << maxTotalExposure; @@ -232,10 +236,10 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain, * Push the shutter time up to the maximum first, and only then * increase the gain. */ - shutterTime = std::clamp(exposureValue / minAnalogueGain_, - minShutterSpeed_, maxShutterSpeed_); + shutterTime = std::clamp(exposureValue / minAnalogueGain, + minShutterSpeed, maxShutterSpeed); double stepGain = std::clamp(exposureValue / shutterTime, - minAnalogueGain_, maxAnalogueGain_); + minAnalogueGain, maxAnalogueGain); LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " << shutterTime << " and " << stepGain; @@ -348,7 +352,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) break; } - computeExposure(context.frameContext, yGain, iqMeanGain); + computeExposure(context, yGain, iqMeanGain); frameCount_++; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 84bfe045..d9f17e6f 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -34,8 +34,7 @@ private: double measureBrightness(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid) const; utils::Duration filterExposure(utils::Duration currentExposure); - void computeExposure(IPAFrameContext &frameContext, double yGain, - double iqMeanGain); + void computeExposure(IPAContext &context, double yGain, double iqMeanGain); double estimateLuminance(IPAFrameContext &frameContext, const ipu3_uapi_grid_config &grid, const ipu3_uapi_stats_3a *stats, @@ -44,11 +43,6 @@ private: uint64_t frameCount_; utils::Duration lineDuration_; - utils::Duration minShutterSpeed_; - utils::Duration maxShutterSpeed_; - - double minAnalogueGain_; - double maxAnalogueGain_; utils::Duration filteredExposure_;