From patchwork Wed Oct 13 15:41:20 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: 14124 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 59D89C324C for ; Wed, 13 Oct 2021 15:41:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C521168F55; Wed, 13 Oct 2021 17:41:41 +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="nE0MY74+"; 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 708E568F56 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 D9F2EFD2; Wed, 13 Oct 2021 17:41:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634139691; bh=X36ki1ZFlNfuS3bFHEFOMnL+XUcH2ZXz6SHyBsfebGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nE0MY74+BvQCBn7/N2/EosW62OaioJs3f2chDubwYuMOiyODsZ0DVUFI8YTRVmwl/ t/CH0+l5Wux8/Jh9S0CyYz0MKv2H+rDME9OS70D9qoieOodUKsas6y0Hiif9++xQdj mEauerEWOv52uWIY5GrkgH/9bRiDl6lidZok7hoY= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:20 +0200 Message-Id: <20211013154125.133419-9-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 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" We are not using the filtered result from filterExposure() and we make complex assumptions when dividing the exposure and analogue gain values. Use the same mechanism as in RPiController::Agc::divideUpExposure() with the fixed limits defined previously. This simplifies the understanding, and corrects a bug in the analogue gain calculus. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/agc.cpp | 37 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index e58a8a8d..3ec1c60c 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -153,17 +153,34 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) /* \todo: estimate if we need to desaturate */ filterExposure(); - Duration newExposure = 0.0s; - if (currentShutter < kMaxShutterSpeed) { - exposure = std::clamp(static_cast(exposure * currentExposure_ / currentExposureNoDg_), minExposureLines_, maxExposureLines_); - newExposure = currentExposure_ / exposure; - gain = std::clamp(static_cast(gain * currentExposure_ / newExposure), kMinGain, kMaxGain); - } else if (currentShutter >= kMaxShutterSpeed) { - gain = std::clamp(static_cast(gain * currentExposure_ / currentExposureNoDg_), kMinGain, kMaxGain); - newExposure = currentExposure_ / gain; - exposure = std::clamp(static_cast(exposure * currentExposure_ / newExposure), minExposureLines_, maxExposureLines_); + 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; + } } - LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; + + LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " + << shutterTime << " and " + << stepGain; + + exposure = shutterTime / lineDuration_; + gain = stepGain; } lastFrame_ = frameCount_; }