From patchwork Thu Nov 25 10:21:40 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: 14775 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 55698BF415 for ; Thu, 25 Nov 2021 10:21:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 69A12603C2; Thu, 25 Nov 2021 11:21:53 +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="fQQJ5/O0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3F4276022D 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 E8F4FA24; Thu, 25 Nov 2021 11:21:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1637835710; bh=odbSNMF41jmEwJRGqx2a7AQ2XBy3u5vnDgJyRvTyIUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fQQJ5/O0Uwe6OxKuq5KohJ3Nh7kjv7nNMPb3l/zTmr5E2wdSpHrW6WKom2fAEn/m5 fBHUvFfc+cFChMxqqZ+6M2GbFju/YANmZthT5IPIilE0MzVV6y8BMaOvgKGqQgcLcP 0s6djhN3g4DiEWoq+pkpVfr1HiogudL3Yk56VSDg= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 25 Nov 2021 11:21:40 +0100 Message-Id: <20211125102143.52556-2-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 1/4] ipa: ipu3: Return filtered value 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" When the current exposure value is calculated, it is cached and used by filterExposure(). Use private filteredExposure_ and pass currentExposure as a member variable. In order to limit the use of filteredExposure_, return the value from filterExposure(). While at it, remove a stale comment. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 31 ++++++++++++++++--------------- src/ipa/ipu3/algorithms/agc.h | 3 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 582f0ae1..2945a138 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -71,7 +71,7 @@ static constexpr double kRelativeLuminanceTarget = 0.16; Agc::Agc() : frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s), - maxShutterSpeed_(0s), filteredExposure_(0s), currentExposure_(0s) + maxShutterSpeed_(0s), filteredExposure_(0s) { } @@ -143,7 +143,7 @@ double Agc::measureBrightness(const ipu3_uapi_stats_3a *stats, /** * \brief Apply a filter on the exposure value to limit the speed of changes */ -void Agc::filterExposure() +utils::Duration Agc::filterExposure(utils::Duration currentExposure) { double speed = 0.2; @@ -152,23 +152,24 @@ void Agc::filterExposure() speed = 1.0; if (filteredExposure_ == 0s) { - /* DG stands for digital gain.*/ - filteredExposure_ = currentExposure_; + filteredExposure_ = currentExposure; } else { /* * If we are close to the desired result, go faster to avoid making * multiple micro-adjustments. * \todo Make this customisable? */ - if (filteredExposure_ < 1.2 * currentExposure_ && - filteredExposure_ > 0.8 * currentExposure_) + if (filteredExposure_ < 1.2 * currentExposure && + filteredExposure_ > 0.8 * currentExposure) speed = sqrt(speed); - filteredExposure_ = speed * currentExposure_ + + filteredExposure_ = speed * currentExposure + filteredExposure_ * (1.0 - speed); } LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << filteredExposure_; + + return filteredExposure_; } /** @@ -212,19 +213,19 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain, * Calculate the current exposure value for the scene as the latest * exposure value applied multiplied by the new estimated gain. */ - currentExposure_ = effectiveExposureValue * evGain; + utils::Duration currentExposure = effectiveExposureValue * evGain; /* Clamp the exposure value to the min and max authorized */ utils::Duration maxTotalExposure = maxShutterSpeed_ * maxAnalogueGain_; - currentExposure_ = std::min(currentExposure_, maxTotalExposure); - LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ + currentExposure = std::min(currentExposure, maxTotalExposure); + LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure << ", maximum is " << maxTotalExposure; - /* \todo: estimate if we need to desaturate */ - filterExposure(); - - /* Divide the exposure value as new exposure and gain values */ - utils::Duration exposureValue = filteredExposure_; + /* + * Divide the exposure value as new exposure and gain values + * \todo: estimate if we need to desaturate + */ + utils::Duration exposureValue = filterExposure(currentExposure); utils::Duration shutterTime; /* diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 96ec7005..84bfe045 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -33,7 +33,7 @@ public: private: double measureBrightness(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid) const; - void filterExposure(); + utils::Duration filterExposure(utils::Duration currentExposure); void computeExposure(IPAFrameContext &frameContext, double yGain, double iqMeanGain); double estimateLuminance(IPAFrameContext &frameContext, @@ -51,7 +51,6 @@ private: double maxAnalogueGain_; utils::Duration filteredExposure_; - utils::Duration currentExposure_; uint32_t stride_; }; From patchwork Thu Nov 25 10:21:41 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: 14776 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 8C279BF415 for ; Thu, 25 Nov 2021 10:21:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DCAF603C9; Thu, 25 Nov 2021 11:21:54 +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="qJY/tV+6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F28360231 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 20BBA1010; 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=jpUVGZ7rMVRGdRlfoMYP9OxLWCk9bqXOUVIYudE8zLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJY/tV+6JTtc8x9lewKF5XxK7FCuIFqx2UIIIFGSjCR9yEUejUk9vSEFiIHn03ub5 lLqJ2JLZoPUS3/NYwbZDm0uTlAw81i+Oj3z1CV1G0zcjN48EM/gc63mE6s2aodyTK1 G2xNv8V8IVUwKi+Wi0R/TXTmG/lvv2Wl9VbPnerg= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 25 Nov 2021 11:21:41 +0100 Message-Id: <20211125102143.52556-3-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 2/4] ipa: ipu3: Shorten exposure and gain lines 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" When the effective sensor values are stored during the EventStatReady event, the lines are long. Fix it. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/ipu3.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index b0c75541..7a010019 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -547,8 +547,10 @@ void IPAIPU3::processEvent(const IPU3Event &event) const ipu3_uapi_stats_3a *stats = reinterpret_cast(mem.data()); - context_.frameContext.sensor.exposure = event.sensorControls.get(V4L2_CID_EXPOSURE).get(); - context_.frameContext.sensor.gain = camHelper_->gain(event.sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); + context_.frameContext.sensor.exposure = + event.sensorControls.get(V4L2_CID_EXPOSURE).get(); + context_.frameContext.sensor.gain = + camHelper_->gain(event.sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); parseStatistics(event.frame, event.frameTimestamp, stats); break; 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_; From patchwork Thu Nov 25 10:21:43 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: 14778 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 39709BF415 for ; Thu, 25 Nov 2021 10:21:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 26ED46039C; Thu, 25 Nov 2021 11:21:56 +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="tgahZpf2"; 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 B59C860371 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 79673A24; 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=i91M8ZVYHdDjblJkzN8tjO0Med4zbFKX9hwcVD9EPa0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgahZpf2NmwQbbPe81TT7EqybmbvjOUq/Dipkl7HNX4zzp7d8ODUWDMb6//dxXlhW 7UbIg2zUBeD553It/R/JJa67HTFFTk22A2O4aKOrfi1oHi0Ar9fHEfHpo0uf/v/OuT p6CtcjgfNbZopVQI4ExA4z5eqodD8beMG8xMGeCw= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 25 Nov 2021 11:21:43 +0100 Message-Id: <20211125102143.52556-5-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 4/4] ipa: ipu3: agc: Introduce lineDuration in IPASessionConfiguration 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" Instead of having a local cached value for line duration, store it in the IPASessionConfiguration::agc structure. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/agc.cpp | 20 +++++++++++--------- src/ipa/ipu3/algorithms/agc.h | 2 -- src/ipa/ipu3/ipa_context.cpp | 3 +++ src/ipa/ipu3/ipa_context.h | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index b822c79b..c463e688 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -70,7 +70,7 @@ static constexpr uint32_t kNumStartupFrames = 10; static constexpr double kRelativeLuminanceTarget = 0.16; Agc::Agc() - : frameCount_(0), lineDuration_(0s), filteredExposure_(0s) + : frameCount_(0), filteredExposure_(0s) { } @@ -83,16 +83,18 @@ Agc::Agc() */ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) { - stride_ = context.configuration.grid.stride; + IPASessionConfiguration &configuration = context.configuration; + IPAFrameContext &frameContext = context.frameContext; + + stride_ = configuration.grid.stride; /* \todo use the IPAContext to provide the limits */ - lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s - / configInfo.sensorInfo.pixelRate; + configuration.agc.lineDuration = configInfo.sensorInfo.lineLength * 1.0s + / configInfo.sensorInfo.pixelRate; /* Configure the default exposure and gain. */ - context.frameContext.agc.gain = - std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain); - context.frameContext.agc.exposure = 10ms / lineDuration_; + frameContext.agc.gain = std::max(configuration.agc.minAnalogueGain, kMinAnalogueGain); + frameContext.agc.exposure = 10ms / configuration.agc.lineDuration; return 0; } @@ -200,7 +202,7 @@ void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain) /* extracted from Rpi::Agc::computeTargetExposure */ /* Calculate the shutter time in seconds */ - utils::Duration currentShutter = exposure * lineDuration_; + utils::Duration currentShutter = exposure * configuration.agc.lineDuration; /* * Update the exposure value for the next computation using the values @@ -245,7 +247,7 @@ void Agc::computeExposure(IPAContext &context, double yGain, double iqMeanGain) << stepGain; /* Update the estimated exposure and gain. */ - frameContext.agc.exposure = shutterTime / lineDuration_; + frameContext.agc.exposure = shutterTime / configuration.agc.lineDuration; frameContext.agc.gain = stepGain; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index d9f17e6f..ed997e67 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -42,8 +42,6 @@ private: uint64_t frameCount_; - utils::Duration lineDuration_; - utils::Duration filteredExposure_; uint32_t stride_; diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index 86794ac1..ace9c66f 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -84,6 +84,9 @@ namespace libcamera::ipa::ipu3 { * * \var IPASessionConfiguration::agc.maxAnalogueGain * \brief Maximum analogue gain supported with the configured sensor + * + * \var IPASessionConfiguration::agc.lineDuration + * \brief Line duration in microseconds */ /** diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index c6dc0814..7696fd14 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -30,6 +30,7 @@ struct IPASessionConfiguration { utils::Duration maxShutterSpeed; double minAnalogueGain; double maxAnalogueGain; + utils::Duration lineDuration; } agc; };