From patchwork Fri Oct 22 07:32:49 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: 14250 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 96CDFBF415 for ; Fri, 22 Oct 2021 07:33:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40DC668F65; Fri, 22 Oct 2021 09:33:10 +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="qHWUY568"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0543A68F69 for ; Fri, 22 Oct 2021 09:32:57 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:22cc:3af6:5ccb:8367]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0C5851D; Fri, 22 Oct 2021 09:32:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634887976; bh=AkwM/bbwVrcAmX7XtfmikA5MEkZF6SJiOIk/rB4RiVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qHWUY568POA1/9rD8KrqTrnF/grDA1iVaLP/34XO6ydEoNvek25thXUTE4v5DdM1R xvhFW1SYyMeMcGmJYRN4yHeLotyeEIi+EAs3DWjI79mmrpnVYMiB8LeXqYTf4rAakh KS7a3GXFJWc86qWBXxfEoySo5swdcyhDp1uhFIEI= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Oct 2021 09:32:49 +0200 Message-Id: <20211022073249.35084-15-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211022073249.35084-1-jeanmichel.hautbois@ideasonboard.com> References: <20211022073249.35084-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 14/14] ipa: ipu3: Use sensor limits for analogue 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" Instead of using constants for the analogue gains limits, use the minimum and maximum from the configured sensor. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 19 ++++++++++--------- src/ipa/ipu3/algorithms/agc.h | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 74e94544..6c151232 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -30,10 +30,9 @@ static constexpr uint32_t kInitialFrameMinAECount = 4; /* Number of frames to wait between new gain/exposure estimations */ static constexpr uint32_t kFrameSkipCount = 6; -/* Maximum analogue gain value - * \todo grab it from a camera helper */ -static constexpr double kMinGain = 1.0; -static constexpr double kMaxGain = 8.0; +/* Limits for analogue gain values */ +static constexpr double kMinAnalogueGain = 1.0; +static constexpr double kMaxAnalogueGain = 8.0; /* Histogram constants */ static constexpr uint32_t knumHistogramBins = 256; @@ -57,9 +56,11 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) minExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_; maxExposureLines_ = context.configuration.agc.maxShutterSpeed / lineDuration_; + minAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain); + maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain); + /* Configure the default exposure and gain. */ - context.frameContext.agc.gain = - context.configuration.agc.minAnalogueGain; + context.frameContext.agc.gain = minAnalogueGain_; context.frameContext.agc.exposure = minExposureLines_; prevExposureValue_ = context.frameContext.agc.gain @@ -148,7 +149,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_; utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; - utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; + utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ << ", maximum is " << maxTotalExposure; @@ -163,10 +164,10 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) * Push the shutter time up to the maximum first, and only then * increase the gain. */ - shutterTime = std::clamp(exposureValue / kMinGain, + shutterTime = std::clamp(exposureValue / minAnalogueGain_, minShutterSpeed, maxShutterSpeed); double stepGain = std::clamp(exposureValue / shutterTime, - kMinGain, kMaxGain); + minAnalogueGain_, maxAnalogueGain_); LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " << shutterTime << " and " << stepGain; diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index ad133b98..1840205b 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -45,6 +45,9 @@ private: uint32_t minExposureLines_; uint32_t maxExposureLines_; + double minAnalogueGain_; + double maxAnalogueGain_; + utils::Duration filteredExposure_; utils::Duration currentExposure_; utils::Duration prevExposureValue_;