From patchwork Wed Oct 20 15:46:02 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: 14215 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 57CE9BDB1C for ; Wed, 20 Oct 2021 15:46:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D766068F7B; Wed, 20 Oct 2021 17:46:22 +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="v/UXFwCZ"; 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 C260968F5F for ; Wed, 20 Oct 2021 17:46:14 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:ce4b:1c5f:7302:b899]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D3103F6; Wed, 20 Oct 2021 17:46:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634744774; bh=toWzcZBpc4oJgr6YCZ0DAsAD/LTK7GTdpHYKEHtxRN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v/UXFwCZ7xtFqZVRR/A5UZ+4Np94r1raRU0MZDHhdaqly8BKJ5nrh0NaKEz6sfJf2 j+bwKge0DGkQR+lKCxVO9cYyR7sQHq4D5v7MynXO09zO9HpvbO/7z1dNFVfo2JWUPo 6D5ieNy0aOCsq7AN0aT0UtgsYwbLzrqpa0LeOs8Q= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Oct 2021 17:46:02 +0200 Message-Id: <20211020154607.180161-9-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com> References: <20211020154607.180161-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/13] ipa: ipu3: agc: Simplify division of exposure/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" Until now, the algorithm makes complex assumptions when dividing the exposure and analogue gain values. Instead, use a simpler clamping of the shutter speed first, and then of the analogue gain, based on the limits configured. While at it, correct a bug which makes the algorithm not use the filtered result from filterExposure(). Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 36 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 1bae1eb9..84e41834 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -146,7 +146,9 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) << " Gain " << gain; currentExposure_ = currentExposureNoDg_ * newGain; + utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_; utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; + utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ @@ -155,23 +157,23 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) /* \todo: estimate if we need to desaturate */ filterExposure(); - utils::Duration newExposure = 0.0s; - if (currentShutter < maxShutterSpeed) { - exposure = std::clamp(exposure * currentExposure_ / currentExposureNoDg_, - minExposureLines_, - maxExposureLines_); - newExposure = currentExposure_ / exposure; - gain = std::clamp(gain * currentExposure_ / newExposure, - kMinGain, kMaxGain); - } else if (currentShutter >= maxShutterSpeed) { - gain = std::clamp(gain * currentExposure_ / currentExposureNoDg_, - kMinGain, kMaxGain); - newExposure = currentExposure_ / gain; - exposure = std::clamp(exposure * currentExposure_ / newExposure, - minExposureLines_, - maxExposureLines_); - } - LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; + utils::Duration exposureValue = filteredExposure_; + utils::Duration shutterTime = minShutterSpeed; + + /* + * 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_; + gain = stepGain; } lastFrame_ = frameCount_; }