From patchwork Wed Oct 13 15:41:23 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: 14129 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 B3779BDC71 for ; Wed, 13 Oct 2021 15:41:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5ECED68F50; Wed, 13 Oct 2021 17:41:46 +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="PkBfyJZh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BBACB68F55 for ; Wed, 13 Oct 2021 17:41:32 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:3857:aa01:4281:bd9f]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C7F28F0; Wed, 13 Oct 2021 17:41:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634139692; bh=YaIX7eIDzNTuC6Lj5yOn2vwdMF6osrYBdCwpuuDz/7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PkBfyJZhkK1u7/u8f9sg+0nsNVi8pPA8lO201k8ZLgeeSqlSQDPTKfTdwM4n5Bzue oDvmPT1BNRdBOsxRsVmC0VqR4Pduw/B6cPh45sdDI3M749O7XuAYly/TLwxX2b2cDk kv+hp3aVf6q8F8tGAvlE1zvk63z9UaOgDVZTQzuM= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:23 +0200 Message-Id: <20211013154125.133419-12-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211013154125.133419-1-jeanmichel.hautbois@ideasonboard.com> References: <20211013154125.133419-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/13] ipa: ipu3: agc: Remove condition on exposure correction 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 exposure is estimated, we verify if it changed enough for exposure and gain to be updated. There is no need for that because we are now filtering the value with the previous one correctly, so if the change is very small is won't change the exposure and analogue gain. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 96 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 7efe0907..b922bcdf 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -132,61 +132,57 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) if ((frameCount_ < kInitialFrameMinAECount) || (frameCount_ - lastFrame_ < kFrameSkipCount)) return; - /* Are we correctly exposed ? */ - if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) { - LOG(IPU3Agc, Debug) << "!!! Good exposure with iqMean = " << iqMean_; - } else { - double evGain = kEvGainTarget * knumHistogramBins / iqMean_; - - /* extracted from Rpi::Agc::computeTargetExposure */ - Duration currentShutter = exposure * lineDuration_; - currentExposureNoDg_ = currentShutter * analogueGain; - LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ - << " Shutter speed " << currentShutter - << " Gain " << analogueGain - << " Needed ev gain " << evGain; - - currentExposure_ = prevExposureValue * evGain; - Duration maxTotalExposure = kMaxShutterSpeed * kMaxGain; - currentExposure_ = std::min(currentExposure_, maxTotalExposure); - LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ - << " maximum is " << maxTotalExposure; - - /* \todo: estimate if we need to desaturate */ - filterExposure(); - - Duration exposureValue = filteredExposure_; - Duration shutterTime = kMinShutterSpeed; - double stepGain = kMinGain; - - if (shutterTime * stepGain < exposureValue) { - Duration maxShutterMinGain = kMaxShutterSpeed * stepGain; - if (maxShutterMinGain >= exposureValue) { - LOG(IPU3Agc, Debug) << "Setting shutterTime to " << shutterTime; - shutterTime = exposureValue / stepGain; - } else { - shutterTime = kMaxShutterSpeed; - } + double evGain = kEvGainTarget * knumHistogramBins / iqMean_; + + /* extracted from Rpi::Agc::computeTargetExposure */ + Duration currentShutter = exposure * lineDuration_; + currentExposureNoDg_ = currentShutter * analogueGain; + LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ + << " Shutter speed " << currentShutter + << " Gain " << analogueGain + << " Needed ev gain " << evGain; + + currentExposure_ = prevExposureValue * evGain; + Duration maxTotalExposure = kMaxShutterSpeed * kMaxGain; + currentExposure_ = std::min(currentExposure_, maxTotalExposure); + LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ + << " maximum is " << maxTotalExposure; + + /* \todo: estimate if we need to desaturate */ + filterExposure(); + + Duration exposureValue = filteredExposure_; + Duration shutterTime = kMinShutterSpeed; + double stepGain = kMinGain; + + if (shutterTime * stepGain < exposureValue) { + Duration maxShutterMinGain = kMaxShutterSpeed * stepGain; + if (maxShutterMinGain >= exposureValue) { + LOG(IPU3Agc, Debug) << "Setting shutterTime to " << shutterTime; + shutterTime = exposureValue / stepGain; + } else { + shutterTime = kMaxShutterSpeed; + } - Duration maxGainShutter = kMaxGain * shutterTime; - if (maxGainShutter >= exposureValue) { - stepGain = exposureValue / shutterTime; - LOG(IPU3Agc, Debug) << "Setting analogue gain to " << stepGain; - } else { - stepGain = kMaxGain; - } + Duration maxGainShutter = kMaxGain * shutterTime; + if (maxGainShutter >= exposureValue) { + stepGain = exposureValue / shutterTime; + LOG(IPU3Agc, Debug) << "Setting analogue gain to " << stepGain; + } else { + stepGain = kMaxGain; } + } - LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " - << shutterTime << " and " - << stepGain; + LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " + << shutterTime << " and " + << stepGain; - exposure = shutterTime / lineDuration_; - analogueGain = stepGain; + exposure = shutterTime / lineDuration_; + analogueGain = stepGain; + + /* Update the exposure value for the next process call */ + prevExposureValue = shutterTime * analogueGain; - /* Update the exposure value for the next process call */ - prevExposureValue = shutterTime * analogueGain; - } lastFrame_ = frameCount_; }