From patchwork Thu Oct 21 16:43:59 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: 14232 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 61B2DC324E for ; Thu, 21 Oct 2021 16:44:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 19DFD68F6F; Thu, 21 Oct 2021 18:44:19 +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="DDBrpRbS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D259168F59 for ; Thu, 21 Oct 2021 18:44:07 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:f9d:5926:ad90:4996]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 878581BF9; Thu, 21 Oct 2021 18:44:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634834647; bh=u4QrSlBw8RRNyogIi79NoUHOvwIRMulp/WW640l/xjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDBrpRbSSoZgFd5RXO5D571EBlBqFl0Q/lh2g9hTzKGTnvleSnj2MiesqieGorrnC IzNizPUyR0ABUJaSk50czTa+ViPfEqp5xdCXjIzcxARWXdWqtBFvUrrbZoRnCyso82 QhfGVZKWZ07ysVxnYb7uce9SXtMPC1Vlh+XV3Gbw= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Oct 2021 18:43:59 +0200 Message-Id: <20211021164401.110033-13-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211021164401.110033-1-jeanmichel.hautbois@ideasonboard.com> References: <20211021164401.110033-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/14] ipa: ipu3: agc: Refactor 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" Until now, we can't know when the exposure and gains applied in the IPAIPU3::setControls() are really applied (it can be several frames). We don't want to use the values calculated as if they are already applied, and this is done by testing the frame number. When the exposure is estimated, we verify if it changed enough for exposure and gain to be updated. Keep the indentation level removal and simply return when the change is so small there is no need to apply the newly calculated value. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 91 ++++++++++++++++----------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 43ef89df..7ff3029b 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -138,60 +138,59 @@ 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_; + if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) + return; - /* extracted from Rpi::Agc::computeTargetExposure */ - utils::Duration currentShutter = exposure * lineDuration_; - currentExposureNoDg_ = currentShutter * analogueGain; - LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ - << " Shutter speed " << currentShutter - << " Gain " << analogueGain - << " Needed ev gain " << evGain; + double evGain = kEvGainTarget * knumHistogramBins / iqMean_; - currentExposure_ = prevExposureValue_ * evGain; - utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_; - utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; + /* extracted from Rpi::Agc::computeTargetExposure */ + utils::Duration currentShutter = exposure * lineDuration_; + currentExposureNoDg_ = currentShutter * analogueGain; + LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ + << " Shutter speed " << currentShutter + << " Gain " << analogueGain + << " Needed ev gain " << evGain; - utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; - currentExposure_ = std::min(currentExposure_, maxTotalExposure); - LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ - << ", maximum is " << maxTotalExposure; + currentExposure_ = prevExposureValue_ * evGain; + utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_; + utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; - /* \todo: estimate if we need to desaturate */ - filterExposure(); + utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; + currentExposure_ = std::min(currentExposure_, maxTotalExposure); + LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ + << ", maximum is " << maxTotalExposure; - utils::Duration exposureValue = filteredExposure_; - utils::Duration shutterTime = minShutterSpeed; + /* \todo: estimate if we need to desaturate */ + filterExposure(); - /* - * Push the shutter time up to the maximum first, and only then - * increase the gain. - */ - shutterTime = std::clamp(exposureValue / kMinGain, - minShutterSpeed, maxShutterSpeed); - double stepGain = std::clamp(exposureValue / shutterTime, - kMinGain, kMaxGain); - LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " - << shutterTime << " and " - << stepGain; + utils::Duration exposureValue = filteredExposure_; + utils::Duration shutterTime = minShutterSpeed; - exposure = shutterTime / lineDuration_; - analogueGain = stepGain; + /* + * Push the shutter time up to the maximum first, and only then + * increase the gain. + */ + shutterTime = std::clamp(exposureValue / kMinGain, + minShutterSpeed, maxShutterSpeed); + double stepGain = std::clamp(exposureValue / shutterTime, + kMinGain, kMaxGain); + LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " + << shutterTime << " and " + << stepGain; + + exposure = shutterTime / lineDuration_; + analogueGain = stepGain; + + /* + * Update the exposure value for the next process call. + * + * \todo Obtain the values of the exposure time and analog gain + * that were actually used by the sensor, either from embedded + * data when available, or from the delayed controls + * infrastructure in case a slow down caused a mismatch. + */ + prevExposureValue_ = shutterTime * analogueGain; - /* - * Update the exposure value for the next process call. - * - * \todo Obtain the values of the exposure time and analog gain - * that were actually used by the sensor, either from embedded - * data when available, or from the delayed controls - * infrastructure in case a slow down caused a mismatch. - */ - prevExposureValue_ = shutterTime * analogueGain; - } lastFrame_ = frameCount_; }