From patchwork Wed Jun 23 12:36:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 12695 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 3BBE8C321B for ; Wed, 23 Jun 2021 12:37:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A971E68933; Wed, 23 Jun 2021 14:37:06 +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="HdtCoLI5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 726F668932 for ; Wed, 23 Jun 2021 14:37:05 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.162]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DCC8949A; Wed, 23 Jun 2021 14:37:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1624451825; bh=BPVPNlly+c+LFh52s4gJ0m7WPqcNA7LbSQNL/1x6/XY=; h=From:To:Cc:Subject:Date:From; b=HdtCoLI5/yQ7LexkWFKLqHZ8bWoPODkrwA6QW+t41Pd+TrEAOTxol1DGE4SssAl6B 37gefN8P07fcqeHlwJCpdQ7QvvjDE3j9sjcoHbWzfRWw8wEAxxQbqBsSGEpoOsKdWP 5NX3mUhbdtd3GNpj+Y9ka0+os7VaF1SWKY8CjuaQ= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jun 2021 18:06:57 +0530 Message-Id: <20210623123657.58776-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] ipa: ipu3: Use libcamera::utils::Duration helper class for durations 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" std::chrono::Duration is provided quite conveniently by libcamera::utils::Duration wrapper. Port IPAIPU3 to use that for duration-type entities (such as exposure time), such that it becomes consistent with rest of the codebase. The commit doesn't introduce any functional changes. Signed-off-by: Umang Jain Reviewed-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/ipu3_agc.cpp | 19 ++++++++++--------- src/ipa/ipu3/ipu3_agc.h | 16 ++++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/ipu3_agc.cpp index 8ca95013..c476a60d 100644 --- a/src/ipa/ipu3/ipu3_agc.cpp +++ b/src/ipa/ipu3/ipu3_agc.cpp @@ -19,6 +19,8 @@ namespace libcamera { +using namespace std::literals::chrono_literals; + namespace ipa::ipu3 { LOG_DEFINE_CATEGORY(IPU3Agc) @@ -51,9 +53,9 @@ 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) + lineDuration_(0s), maxExposureTime_(0s), + prevExposure_(0s), prevExposureNoDg_(0s), + currentExposure_(0s), currentExposureNoDg_(0s) { } @@ -61,8 +63,7 @@ void IPU3Agc::initialise(struct ipu3_uapi_grid_config &bdsGrid, const IPACameraS { aeGrid_ = bdsGrid; - /* line duration in microseconds */ - lineDuration_ = sensorInfo.lineLength * 1000000ULL / static_cast(sensorInfo.pixelRate); + lineDuration_ = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate; maxExposureTime_ = kMaxExposure * lineDuration_; } @@ -113,7 +114,7 @@ void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats) void IPU3Agc::filterExposure() { double speed = 0.2; - if (prevExposure_ == 0.0) { + if (prevExposure_ == 0s) { /* DG stands for digital gain.*/ prevExposure_ = currentExposure_; prevExposureNoDg_ = currentExposureNoDg_; @@ -162,20 +163,20 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, uint32_t &gain) double newGain = kEvGainTarget * knumHistogramBins / iqMean_; /* extracted from Rpi::Agc::computeTargetExposure */ - double currentShutter = exposure * lineDuration_; + libcamera::utils::Duration currentShutter = exposure * lineDuration_; currentExposureNoDg_ = currentShutter * gain; LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ << " Shutter speed " << currentShutter << " Gain " << gain; currentExposure_ = currentExposureNoDg_ * newGain; - double maxTotalExposure = maxExposureTime_ * kMaxGain; + libcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_; /* \todo: estimate if we need to desaturate */ filterExposure(); - double newExposure = 0.0; + libcamera::utils::Duration newExposure = 0.0s; if (currentShutter < maxExposureTime_) { exposure = std::clamp(static_cast(exposure * currentExposure_ / currentExposureNoDg_), kMinExposure, kMaxExposure); newExposure = currentExposure_ / exposure; diff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/ipu3_agc.h index f3d40557..a5a78233 100644 --- a/src/ipa/ipu3/ipu3_agc.h +++ b/src/ipa/ipu3/ipu3_agc.h @@ -14,6 +14,8 @@ #include +#include "libcamera/internal/utils.h" + #include "libipa/algorithm.h" namespace libcamera { @@ -22,6 +24,8 @@ struct IPACameraSensorInfo; namespace ipa::ipu3 { +using utils::Duration; + class IPU3Agc : public Algorithm { public: @@ -51,13 +55,13 @@ private: double iqMean_; double gamma_; - double lineDuration_; - double maxExposureTime_; + Duration lineDuration_; + Duration maxExposureTime_; - double prevExposure_; - double prevExposureNoDg_; - double currentExposure_; - double currentExposureNoDg_; + Duration prevExposure_; + Duration prevExposureNoDg_; + Duration currentExposure_; + Duration currentExposureNoDg_; }; } /* namespace ipa::ipu3 */