From patchwork Tue Jun 8 07:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 12510 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 51EDCC320B for ; Tue, 8 Jun 2021 07:42:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 159546892E; Tue, 8 Jun 2021 09:42:40 +0200 (CEST) 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="cQecKwef"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8AEEF6892F for ; Tue, 8 Jun 2021 09:42:37 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 23FB23E6; Tue, 8 Jun 2021 09:42:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1623138157; bh=29JvRM1DAdnudqlIIoDguhKJwBRIl7s29++81r4K/ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQecKwefvlOMmgmPfVFb5yjCncOzQYAOuMvYst0vU88DrXofx4b2kZ8MjKO90S/GA K6mBSoxD31Z5TdxKbTDDhhMhtfRfmVVfwF3zE/lhPZlZx5OxpZbPP84gienoLNQrWQ XWP/SN7Ib/rs86DKel8OWqpZllmakpW5hQIh0Fac= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Jun 2021 13:12:23 +0530 Message-Id: <20210608074225.59862-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608074225.59862-1-umang.jain@ideasonboard.com> References: <20210608074225.59862-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] ipa: ipu3: Calculate line duration from IPACameraSensorInfo 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" Squash \todo by calculating line duration from IPACameraSensorInfo, now passed in, to IPU3Agc::initialise(). Since line duration is now calculated from real values, store it as a private member in IPU3Agc class. As a further step, replace the associated global constant, kMaxExposureTime, with a private IPU3Agc class member as well, and assign its value correspondingly in IPU3Agc::initialise(), similar to previous precedence. Signed-off-by: Umang Jain Tested-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- src/ipa/ipu3/ipu3.cpp | 2 +- src/ipa/ipu3/ipu3_agc.cpp | 24 +++++++++++++----------- src/ipa/ipu3/ipu3_agc.h | 7 ++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 700a5660..2496b0a0 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -174,7 +174,7 @@ void IPAIPU3::configure(const IPAConfigInfo &configInfo) awbAlgo_->initialise(params_, configInfo.bdsOutputSize, bdsGrid_); agcAlgo_ = std::make_unique(); - agcAlgo_->initialise(bdsGrid_); + agcAlgo_->initialise(bdsGrid_, configInfo.sensorInfo); } void IPAIPU3::mapBuffers(const std::vector &buffers) diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/ipu3_agc.cpp index 8bae423f..8ca95013 100644 --- a/src/ipa/ipu3/ipu3_agc.cpp +++ b/src/ipa/ipu3/ipu3_agc.cpp @@ -11,6 +11,8 @@ #include #include +#include + #include "libcamera/internal/log.h" #include "libipa/histogram.h" @@ -39,11 +41,6 @@ static constexpr uint32_t kMaxGain = kMaxISO / 100; static constexpr uint32_t kMinExposure = 1; static constexpr uint32_t kMaxExposure = 1976; -/* \todo those should be got from IPACameraSensorInfo ! */ -/* line duration in microseconds */ -static constexpr double kLineDuration = 16.8; -static constexpr double kMaxExposureTime = kMaxExposure * kLineDuration; - /* Histogram constants */ static constexpr uint32_t knumHistogramBins = 256; static constexpr double kEvGainTarget = 0.5; @@ -54,14 +51,19 @@ static constexpr uint8_t kCellSize = 8; IPU3Agc::IPU3Agc() : frameCount_(0), lastFrame_(0), converged_(false), updateControls_(false), iqMean_(0.0), gamma_(1.0), + lineDuration_(0.0), maxExposureTime_(0.0), prevExposure_(0.0), prevExposureNoDg_(0.0), currentExposure_(0.0), currentExposureNoDg_(0.0) { } -void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid) +void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraSensorInfo &sensorInfo) { aeGrid_ = bdsGrid; + + /* line duration in microseconds */ + lineDuration_ = sensorInfo.lineLength * 1000000ULL / static_cast(sensorInfo.pixelRate); + maxExposureTime_ = kMaxExposure * lineDuration_; } void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats) @@ -160,13 +162,13 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain) double newGain = kEvGainTarget * knumHistogramBins / iqMean_; /* extracted from Rpi::Agc::computeTargetExposure */ - double currentShutter = exposure * kLineDuration; + double currentShutter = exposure * lineDuration_; currentExposureNoDg_ = currentShutter * gain; LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ << " Shutter speed " << currentShutter << " Gain " << gain; currentExposure_ = currentExposureNoDg_ * newGain; - double maxTotalExposure = kMaxExposureTime * kMaxGain; + double maxTotalExposure = maxExposureTime_ * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_; @@ -174,18 +176,18 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain) filterExposure(); double newExposure = 0.0; - if (currentShutter < kMaxExposureTime) { + if (currentShutter < maxExposureTime_) { exposure = std::clamp(static_cast(exposure * currentExposure_ / currentExposureNoDg_), kMinExposure, kMaxExposure); newExposure = currentExposure_ / exposure; gain = std::clamp(static_cast(gain * currentExposure_ / newExposure), kMinGain, kMaxGain); updateControls_ = true; - } else if (currentShutter >= kMaxExposureTime) { + } else if (currentShutter >= maxExposureTime_) { gain = std::clamp(static_cast(gain * currentExposure_ / currentExposureNoDg_), kMinGain, kMaxGain); newExposure = currentExposure_ / gain; exposure = std::clamp(static_cast(exposure * currentExposure_ / newExposure), kMinExposure, kMaxExposure); updateControls_ = true; } - LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * kLineDuration << " and gain " << gain; + LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; } lastFrame_ = frameCount_; } diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h index bfdf45d1..99a582a9 100644 --- a/src/ipa/ipu3/ipu3_agc.h +++ b/src/ipa/ipu3/ipu3_agc.h @@ -18,6 +18,8 @@ namespace libcamera { +class IPACameraSensorInfo; + namespace ipa::ipu3 { class IPU3Agc : public Algorithm @@ -26,7 +28,7 @@ public: IPU3Agc(); ~IPU3Agc() = default; - void initialise(struct ipu3_uapi_grid_config &bdsGrid); + void initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraSensorInfo &sensorInfo); void process(const ipu3_uapi_stats_3a *stats, uint32_t &exposure, uint32_t &gain); bool converged() { return converged_; } bool updateControls() { return updateControls_; } @@ -49,6 +51,9 @@ private: double iqMean_; double gamma_; + double lineDuration_; + double maxExposureTime_; + double prevExposure_; double prevExposureNoDg_; double currentExposure_;