From patchwork Wed Oct 13 15:41:13 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: 14116 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 3E418BDC71 for ; Wed, 13 Oct 2021 15:41:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E0C0468F5B; Wed, 13 Oct 2021 17:41:32 +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="nk2BkoZF"; 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 872B268F4B for ; Wed, 13 Oct 2021 17:41:31 +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 8504CFD2; Wed, 13 Oct 2021 17:41:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634139690; bh=HaU6ToiP+F/GS3g82cTg6FONqzCVXh4xnPo3K3fQ89o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nk2BkoZFtAWLRG7if2BDJ92ev/00VZAKhWyPiV2PX7vGxeO79vTfJ6K05qmpT7/qU i0l0DbLf46T6mTacjJrebm13wi1k996HB3ZvjzzxtF5AOPGyfJDmteC5cj4qcvk/Ep OWUpNVjuiFh+ZmuOOZe1pN8iAEO2ETh/CYFxeiQ0= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:13 +0200 Message-Id: <20211013154125.133419-2-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 01/13] ipa: ipu3: awb: Set a threshold for the green saturation 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 can have a saturation ratio per cell, giving the percentage of pixels over a threshold within a cell where 100% is set to 0xff. The parameter structure 'ipu3_uapi_awb_config_s' contains four fields to set the threshold, one per channel. The blue field is also used to configure the ImgU and make it calculate the saturation ratio or not. Set a green value saturated when it is more than 230 (90% of the maximum value 255, coded as 8191). Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/awb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index e2b18336..5574bd44 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -326,9 +326,9 @@ void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) { - params->acc_param.awb.config.rgbs_thr_gr = 8191; + params->acc_param.awb.config.rgbs_thr_gr = (90 * 8191 / 100); params->acc_param.awb.config.rgbs_thr_r = 8191; - params->acc_param.awb.config.rgbs_thr_gb = 8191; + params->acc_param.awb.config.rgbs_thr_gb = (90 * 8191 / 100); params->acc_param.awb.config.rgbs_thr_b = IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT | IPU3_UAPI_AWB_RGBS_THR_B_EN | 8191; From patchwork Wed Oct 13 15:41:14 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: 14119 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 B4D35BDC71 for ; Wed, 13 Oct 2021 15:41:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 16E7968F62; Wed, 13 Oct 2021 17:41:36 +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="Voe2MHU+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4F3368F4F for ; Wed, 13 Oct 2021 17:41:31 +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 B0F7B18FF; Wed, 13 Oct 2021 17:41:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634139690; bh=XiYzNXia0eiQ8xHtBJmGlClhrSYiO0knVTEcOglOfcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Voe2MHU+JR9N8AGIzs5foz5al1gHBlLK0tAJ7nJ0okEEECpqOQS5l9V6lrftu6j4B +7ZB66VrMGMCLTdZZYLyGNIQ0cmDRJUSZgbyif7RJBzChwVO+78J3HHHkpyhXq8VF2 Vrqg0+idZ6+uU+5vF6xQ+gjj0LoDaVS4HX7TYZW8= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:14 +0200 Message-Id: <20211013154125.133419-3-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 02/13] ipa: ipu3: set frameContext before controls 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" Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/ipu3.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 6d9bbf39..e54fbab5 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -415,6 +415,9 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo) return ret; } + context_.frameContext.agc.gain = camHelper_->gain(gain_); + context_.frameContext.agc.exposure = exposure_; + return 0; } From patchwork Wed Oct 13 15:41:15 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: 14118 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 52E85BDC71 for ; Wed, 13 Oct 2021 15:41:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 46ED768F50; Wed, 13 Oct 2021 17:41:35 +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="t0UgIWyq"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C077268F4D for ; Wed, 13 Oct 2021 17:41:31 +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 EF58F1AD5; Wed, 13 Oct 2021 17:41:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634139691; bh=xokkq0ekTi9QtBWu4LBC3344e28mdbAlCMJDoIeAaDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t0UgIWyqzQjQsInCAc6lhEI0YH5o/wZT0Gvv1BueJlw++eBxAI4pXNH1PTzc+eBxw Xcxr9OwBew+WRqSDAwcdNEziH05h8wdp5trKdtC6Ven3kWLi8VABt6IJ9oUpS59VEI kOaOGRv6IhTkTI6eMphgZicAdD14HDEbr0hxOYwE= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:15 +0200 Message-Id: <20211013154125.133419-4-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 03/13] ipa: ipu3: awb: Use saturation under 90% 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" The AWB grey world algorithm tries to find a grey value and it can't do it on over-exposed images. To exclude those, the saturation ratio is used for each cell, and the cell is included only if this ratio is 0. Now that we have changed the threshold, more cells may be considered as partially saturated and excluded, making the algorithm to not run. Change that behaviour, and consider 90% as a good enough ratio. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/awb.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 5574bd44..30693923 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -161,6 +161,7 @@ int Awb::configure(IPAContext &context, * \todo This proportion could be configured. */ cellsPerZoneThreshold_ = cellsPerZoneX_ * cellsPerZoneY_ * 80 / 100; + LOG(IPU3Awb, Debug) << "Threshold for AWB is set to " << cellsPerZoneThreshold_; return 0; } @@ -232,7 +233,7 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats) reinterpret_cast( &stats->awb_raw_buffer.meta_data[cellPosition] ); - if (currentCell->sat_ratio == 0) { + if (currentCell->sat_ratio <= 255 * 90 / 100) { /* The cell is not saturated, use the current cell */ awbStats_[awbZonePosition].counted++; uint32_t greenValue = currentCell->Gr_avg + currentCell->Gb_avg; From patchwork Wed Oct 13 15:41:16 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: 14120 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 CEB28BDC71 for ; Wed, 13 Oct 2021 15:41:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D5CDE68F69; Wed, 13 Oct 2021 17:41:36 +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="hUI/xH4o"; 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 0136168F50 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 2756F1B4D; 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=Xo5pyqmaQHBMNzCCpoSxQ6BAemMpHgSuBhOPMijpnhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUI/xH4o66Fi4ER2WTNUjFB2iPf3Kl+F3YMi7zLwZSImFlCisnaPLU/VTpX201aXS pUwmlfWFJTZIk/M6R45G6U38CqKlDLZmuxw+ziW1nObtysrBrx6D9S6HHL2jaLpqxB Vq2uUXq5/TLlZaOMW8zIOl4ooxKkl44aMjnr+yXQ= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:16 +0200 Message-Id: <20211013154125.133419-5-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 04/13] ipa: ipu3: awb: Change minimal green threshold value 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 zones are used for the grey world algorithm, we need a minimal number of zones to make it relevant, and we want the green values to be at least 32 today (with a maximum of 255). This value is a bit high, as we now are correcting the black levels, and a sudden change of colors can be visible for the end user when the gains are applied. Lower the value to 16. Signed-off-by: Jean-Michel Hautbois Acked-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/awb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 30693923..b18874a3 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -17,7 +17,7 @@ namespace ipa::ipu3::algorithms { LOG_DEFINE_CATEGORY(IPU3Awb) -static constexpr uint32_t kMinGreenLevelInZone = 32; +static constexpr uint32_t kMinGreenLevelInZone = 16; /** * \struct Accumulator From patchwork Wed Oct 13 15:41:17 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: 14122 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 F3594C3243 for ; Wed, 13 Oct 2021 15:41:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 605A168F53; Wed, 13 Oct 2021 17:41:40 +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="Lb/6NcZc"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2647468F51 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 538411B62; 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=/B3sE+6+nHTFOwpqaIst/wNO4ZQBoPr4Ge7qdqmV7Xo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lb/6NcZcH3kdjx255q2rOClq8LH3R5dQ87fMSe7us7qf0htVY2nsZtkR6XJFbSVj3 dqwuYFwHplgtnCqqEZ8h90asarJaJDBK1lolCz6+730Gnd+cGkoQwH6rCKX9UrN6q8 /KfKvk9ov02OklWCd1vYzB3snFxh/l05Jhmy3DFk= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:17 +0200 Message-Id: <20211013154125.133419-6-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 05/13] ipa: ipu3: agc: Rename exposure values properly 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" The exposure value is filtered in filterExposure() using the currentExposure_ and setting a prevExposure_ variable. This is misnamed as it is not the previous exposure, but a filtered value. Rename it accordingly. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 28 ++++++++++++++-------------- src/ipa/ipu3/algorithms/agc.h | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 5eafe82c..7c2d4201 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -49,7 +49,7 @@ static constexpr double kEvGainTarget = 0.5; Agc::Agc() : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s), - maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s), + maxExposureTime_(0s), filteredExposure_(0s), filteredExposureNoDg_(0s), currentExposure_(0s), currentExposureNoDg_(0s) { } @@ -94,24 +94,24 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats, void Agc::filterExposure() { double speed = 0.2; - if (prevExposure_ == 0s) { + if (filteredExposure_ == 0s) { /* DG stands for digital gain.*/ - prevExposure_ = currentExposure_; - prevExposureNoDg_ = currentExposureNoDg_; + filteredExposure_ = currentExposure_; + filteredExposureNoDg_ = currentExposureNoDg_; } else { /* * If we are close to the desired result, go faster to avoid making * multiple micro-adjustments. * \ todo: Make this customisable? */ - if (prevExposure_ < 1.2 * currentExposure_ && - prevExposure_ > 0.8 * currentExposure_) + if (filteredExposure_ < 1.2 * currentExposure_ && + filteredExposure_ > 0.8 * currentExposure_) speed = sqrt(speed); - prevExposure_ = speed * currentExposure_ + - prevExposure_ * (1.0 - speed); - prevExposureNoDg_ = speed * currentExposureNoDg_ + - prevExposureNoDg_ * (1.0 - speed); + filteredExposure_ = speed * currentExposure_ + + filteredExposure_ * (1.0 - speed); + filteredExposureNoDg_ = speed * currentExposureNoDg_ + + filteredExposureNoDg_ * (1.0 - speed); } /* * We can't let the no_dg exposure deviate too far below the @@ -119,10 +119,10 @@ void Agc::filterExposure() * in the ISP to hide it (which will cause nasty oscillation). */ double fastReduceThreshold = 0.4; - if (prevExposureNoDg_ < - prevExposure_ * fastReduceThreshold) - prevExposureNoDg_ = prevExposure_ * fastReduceThreshold; - LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << prevExposure_; + if (filteredExposureNoDg_ < + filteredExposure_ * fastReduceThreshold) + filteredExposureNoDg_ = filteredExposure_ * fastReduceThreshold; + LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << filteredExposure_; } void Agc::lockExposureGain(uint32_t &exposure, double &gain) diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 64b71c65..cd4d4855 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -46,8 +46,8 @@ private: Duration lineDuration_; Duration maxExposureTime_; - Duration prevExposure_; - Duration prevExposureNoDg_; + Duration filteredExposure_; + Duration filteredExposureNoDg_; Duration currentExposure_; Duration currentExposureNoDg_; From patchwork Wed Oct 13 15:41:18 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: 14123 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 384E8BDC71 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 4DDDF68F68; 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="G5FOkj9q"; 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 3A60868F52 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 7F5661BBB; 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=5LRqVWrGiH7gY/p5UwWfMxC8tcwuXUWzrgm0RHlf9w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G5FOkj9qV3MpZQ24BbxmofKBq7DrPZ7zQ/vEw1M10aWSsv1u/oP8atmQgtZef7buB r8HzlcZPZyGJYFQZOvQDfRki24LKZ3eETIItqoMm+MDDcjS+kMJir1twJNc1nyFcg1 BJoqpOZaCMJMOTr7wXGneI8XsTtz53RRROEK0UQU= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:18 +0200 Message-Id: <20211013154125.133419-7-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 06/13] ipa: ipu3: agc: Change exposure limits 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" The exposure limits are set for one sensor until now, in a number of lines. We should not use those, but exposure limits in a time unit. Introduce default limits which with a default minimum of 20ms. This value should be given by the IPAIPU3. Use cached values expressed as a number of lines in the configure() call. Adapt the process() call accordingly. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 30 +++++++++++++++++------------- src/ipa/ipu3/algorithms/agc.h | 3 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 7c2d4201..2dd5c5c1 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -40,8 +40,8 @@ static constexpr uint32_t kMinGain = kMinISO / 100; static constexpr uint32_t kMaxGain = kMaxISO / 100; /* \todo use calculated value based on sensor */ -static constexpr uint32_t kMinExposure = 1; -static constexpr uint32_t kMaxExposure = 1976; +static constexpr libcamera::utils::Duration kMinShutterSpeed = 100us; +static constexpr libcamera::utils::Duration kMaxShutterSpeed = 20ms; /* Histogram constants */ static constexpr uint32_t knumHistogramBins = 256; @@ -49,8 +49,8 @@ static constexpr double kEvGainTarget = 0.5; Agc::Agc() : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s), - maxExposureTime_(0s), filteredExposure_(0s), filteredExposureNoDg_(0s), - currentExposure_(0s), currentExposureNoDg_(0s) + minExposureLines_(0), maxExposureLines_(0), filteredExposure_(0s), + filteredExposureNoDg_(0s), currentExposure_(0s), currentExposureNoDg_(0s) { } @@ -60,7 +60,9 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s / configInfo.sensorInfo.pixelRate; - maxExposureTime_ = kMaxExposure * lineDuration_; + + minExposureLines_ = kMinShutterSpeed / lineDuration_; + maxExposureLines_ = kMaxShutterSpeed / lineDuration_; return 0; } @@ -140,28 +142,30 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) double newGain = kEvGainTarget * knumHistogramBins / iqMean_; /* extracted from Rpi::Agc::computeTargetExposure */ - libcamera::utils::Duration currentShutter = exposure * lineDuration_; + Duration currentShutter = exposure * lineDuration_; currentExposureNoDg_ = currentShutter * gain; LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ << " Shutter speed " << currentShutter << " Gain " << gain; + currentExposure_ = currentExposureNoDg_ * newGain; - libcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain; + Duration maxTotalExposure = kMaxShutterSpeed * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); - LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_; + LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ + << " maximum is " << maxTotalExposure; /* \todo: estimate if we need to desaturate */ filterExposure(); - libcamera::utils::Duration newExposure = 0.0s; - if (currentShutter < maxExposureTime_) { - exposure = std::clamp(static_cast(exposure * currentExposure_ / currentExposureNoDg_), kMinExposure, kMaxExposure); + 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 >= maxExposureTime_) { + } 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), kMinExposure, kMaxExposure); + exposure = std::clamp(static_cast(exposure * currentExposure_ / newExposure), minExposureLines_, maxExposureLines_); } LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index cd4d4855..7605ab39 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -44,7 +44,8 @@ private: double iqMean_; Duration lineDuration_; - Duration maxExposureTime_; + uint32_t minExposureLines_; + uint32_t maxExposureLines_; Duration filteredExposure_; Duration filteredExposureNoDg_; From patchwork Wed Oct 13 15:41:19 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: 14121 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 867DDBDC71 for ; Wed, 13 Oct 2021 15:41:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5A9F968F6E; Wed, 13 Oct 2021 17:41:39 +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="wWZbLqN2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5417E68F53 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 AD8A78F0; 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=76pHpTufHn/MDxGa481kxcF9E3rrQGstEC8Gq0FYF1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wWZbLqN2mKkZug3smVM2ht6jDuMikWDiGxwgvgR912mh1TGygLg+jBwYbEsNU0KXL B5e7U2lQxvoFxle7c6zJHWaYfGjwyQ96ITiVGG4kgwI1XfmdOrKUbkckDCVsWmLDEi dRKoYqcm/H7ieqi/X+yuH1ytEnk9b69I4T9SKsoI= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:19 +0200 Message-Id: <20211013154125.133419-8-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 07/13] ipa: ipu3: agc: Change analogue gain limits 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" The gains is currently set as a uint32_t while the analogue gain is passed as a double. We also have a default maximum analogue gain of 15 which is quite high for a number of sensors. Use a maximum value of 8 which should really be configured by the IPA and not fixed as it is now. While at it make it a double. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 2dd5c5c1..e58a8a8d 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -30,14 +30,10 @@ static constexpr uint32_t kInitialFrameMinAECount = 4; /* Number of frames to wait between new gain/exposure estimations */ static constexpr uint32_t kFrameSkipCount = 6; -/* Maximum ISO value for analogue gain */ -static constexpr uint32_t kMinISO = 100; -static constexpr uint32_t kMaxISO = 1500; - /* Maximum analogue gain value * \todo grab it from a camera helper */ -static constexpr uint32_t kMinGain = kMinISO / 100; -static constexpr uint32_t kMaxGain = kMaxISO / 100; +static constexpr double kMinGain = 1.0; +static constexpr double kMaxGain = 8.0; /* \todo use calculated value based on sensor */ static constexpr libcamera::utils::Duration kMinShutterSpeed = 100us; @@ -161,9 +157,9 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) 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); + gain = std::clamp(static_cast(gain * currentExposure_ / newExposure), kMinGain, kMaxGain); } else if (currentShutter >= kMaxShutterSpeed) { - gain = std::clamp(static_cast(gain * currentExposure_ / currentExposureNoDg_), kMinGain, kMaxGain); + gain = std::clamp(static_cast(gain * currentExposure_ / currentExposureNoDg_), kMinGain, kMaxGain); newExposure = currentExposure_ / gain; exposure = std::clamp(static_cast(exposure * currentExposure_ / newExposure), minExposureLines_, maxExposureLines_); } 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_; } From patchwork Wed Oct 13 15:41:21 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: 14125 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 ADCBEC3243 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 55A4168F66; Wed, 13 Oct 2021 17:41:43 +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="Wu5mkaFL"; 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 89FA660501 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 11E2918FF; 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=tT+3e4I6PPVlDiKUoAVYAZdJS5Kymi2iN6FL5iK6F4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wu5mkaFL9RswjApjSaHKzsoL3c3VSblt4YkSSvMalbyoNRbk4+Jq7UbmG7Yfhfbob x5I+J11HtkIqvmUYAhnfyFdJxj52O0lSSNtKQWgqOAismVg34GdsXExFP+Y4XMSou1 cI/1AYHGElZjZsiQameYA94DnfPqK6jHHfozQw7U= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:21 +0200 Message-Id: <20211013154125.133419-10-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 09/13] ipa: ipu3: agc: Rename gains properly 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 have mixed terms between gain, analogue gain and the exposure value gain. Makes it clear when we are using the analogue gain from the sensor, and when we are using the calculated gain to be applied to the exposure value to reach the target. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 3ec1c60c..bd28998a 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -123,7 +123,7 @@ void Agc::filterExposure() LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << filteredExposure_; } -void Agc::lockExposureGain(uint32_t &exposure, double &gain) +void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) { /* Algorithm initialization should wait for first valid frames */ /* \todo - have a number of frames given by DelayedControls ? @@ -135,16 +135,17 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) { LOG(IPU3Agc, Debug) << "!!! Good exposure with iqMean = " << iqMean_; } else { - double newGain = kEvGainTarget * knumHistogramBins / iqMean_; + double evGain = kEvGainTarget * knumHistogramBins / iqMean_; /* extracted from Rpi::Agc::computeTargetExposure */ Duration currentShutter = exposure * lineDuration_; - currentExposureNoDg_ = currentShutter * gain; + currentExposureNoDg_ = currentShutter * analogueGain; LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ << " Shutter speed " << currentShutter - << " Gain " << gain; + << " Gain " << analogueGain + << " Needed ev gain " << evGain; - currentExposure_ = currentExposureNoDg_ * newGain; + currentExposure_ = currentExposureNoDg_ * evGain; Duration maxTotalExposure = kMaxShutterSpeed * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ @@ -180,7 +181,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) << stepGain; exposure = shutterTime / lineDuration_; - gain = stepGain; + analogueGain = stepGain; } lastFrame_ = frameCount_; } @@ -188,9 +189,9 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { uint32_t &exposure = context.frameContext.agc.exposure; - double &gain = context.frameContext.agc.gain; + double &analogueGain = context.frameContext.agc.gain; processBrightness(stats, context.configuration.grid.bdsGrid); - lockExposureGain(exposure, gain); + lockExposureGain(exposure, analogueGain); frameCount_++; } From patchwork Wed Oct 13 15:41:22 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: 14126 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 6A28ABDC71 for ; Wed, 13 Oct 2021 15:41:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2AACF68F5F; Wed, 13 Oct 2021 17:41:44 +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="fpGqkOI2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D54068F4B 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 3E2FD1AD5; 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=kVqzedrZRQ6Fc9v5wRPlD02jnMR+kecn3jojmTD75Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fpGqkOI2fKaJidNvyVqrG0TzKQarB5MjMYBuE9rdC6H2CZORbrQZ6CK+FrCNnPvG6 +JPSPKCXL0qudMsL9H5NDPt3zcqC01iGkXSqLCmUHYeejIElsHDyfAKXT083sqysCg Zzaabs7GgW6tEfacRw2wKZukcnt96PoP3lkMB+sk= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:22 +0200 Message-Id: <20211013154125.133419-11-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 10/13] ipa: ipu3: agc: Introduce previous exposure value 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 need to calculate the gain on the previous exposure value calculated. This value needs to be updated after each process call, initialised to 0s. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 8 ++++++-- src/ipa/ipu3/algorithms/agc.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index bd28998a..7efe0907 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -46,7 +46,8 @@ static constexpr double kEvGainTarget = 0.5; Agc::Agc() : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s), minExposureLines_(0), maxExposureLines_(0), filteredExposure_(0s), - filteredExposureNoDg_(0s), currentExposure_(0s), currentExposureNoDg_(0s) + filteredExposureNoDg_(0s), currentExposure_(0s), + currentExposureNoDg_(0s), prevExposureValue(0s) { } @@ -145,7 +146,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) << " Gain " << analogueGain << " Needed ev gain " << evGain; - currentExposure_ = currentExposureNoDg_ * evGain; + currentExposure_ = prevExposureValue * evGain; Duration maxTotalExposure = kMaxShutterSpeed * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ @@ -182,6 +183,9 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) exposure = shutterTime / lineDuration_; analogueGain = stepGain; + + /* Update the exposure value for the next process call */ + prevExposureValue = shutterTime * analogueGain; } lastFrame_ = frameCount_; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 7605ab39..32817c4f 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -51,6 +51,7 @@ private: Duration filteredExposureNoDg_; Duration currentExposure_; Duration currentExposureNoDg_; + Duration prevExposureValue; uint32_t stride_; }; 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_; } From patchwork Wed Oct 13 15:41:24 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: 14127 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 32BA1BDC71 for ; Wed, 13 Oct 2021 15:41:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DE5C768F73; Wed, 13 Oct 2021 17:41:44 +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="roR9MIDW"; 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 15ECC68F5D for ; Wed, 13 Oct 2021 17:41:33 +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 96B05FD2; 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=6zcNx9MSE/bvPxJ59kkO76G+2vXCsEivNRUKYV4n2Mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roR9MIDWXkauRF4tfX775W2s7s9+B1Vn7rqnLIihZ55gnJfhb5YbLQywzAjhTRkmN p5WDAc4jj+aIazAcqny78squyjCmjuWVVfibeX6HU+79jLylSIY8Vt4Uvquq4ozaYR eZaiFGN3IbdCzluosT59wVHVlh3XMbkuVkzhG0yI= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:24 +0200 Message-Id: <20211013154125.133419-13-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 12/13] ipa: ipu3: agc: Increase IIR filter speed 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" The filter used is an infinite response filter which is controlled by the speed variable. It is used to limit the gap between two exposure values, and avoid nasty oscillations. The higher the speed, the less the result oscillates. As we are only calculating the exposure every 6 frames, as controled by the 'kFrameSkipCount' constant, we can increase the speed, to avoid a slow response (it can be more than 1 second to get a stable enough output). Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index b922bcdf..81eaf436 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -92,7 +92,7 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats, void Agc::filterExposure() { - double speed = 0.2; + double speed = 0.9; if (filteredExposure_ == 0s) { /* DG stands for digital gain.*/ filteredExposure_ = currentExposure_; From patchwork Wed Oct 13 15:41:25 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: 14128 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 E085EBDC71 for ; Wed, 13 Oct 2021 15:41:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A431268F5C; Wed, 13 Oct 2021 17:41:45 +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="BmnegxZv"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4209F68F5F for ; Wed, 13 Oct 2021 17:41:33 +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 C299E18FF; 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=aq8KohAFBHd3KTwqBHD1wtWzCRFutqLeVPvKI/v7WeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BmnegxZvD7SzApYctQQO54dcJbNwUhb144HfsglEV1ZwEXFubMCN6dlFBOi9I72Nk 1D8k6ePalmzAhrMhPtnbnG4tn1Mw7jO07mBa+tPt/N0SiF1xCByS6ys8WhRVjLd5+Z tsMU3OD4tIQnW717EeV53KIQs02nf02cewb1Aro8= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Wed, 13 Oct 2021 17:41:25 +0200 Message-Id: <20211013154125.133419-14-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 13/13] ipa: ipu3: agc: Remove unused variables 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 currently control the exposure value by the shutter speed and the analogue gain. We can't use the digital gain to have more than the maximum exposure value calculated because we are not controlling it. Remove unused code associated with this digital gain. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 19 +++---------------- src/ipa/ipu3/algorithms/agc.h | 2 -- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 81eaf436..0177bb92 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -46,8 +46,7 @@ static constexpr double kEvGainTarget = 0.5; Agc::Agc() : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s), minExposureLines_(0), maxExposureLines_(0), filteredExposure_(0s), - filteredExposureNoDg_(0s), currentExposure_(0s), - currentExposureNoDg_(0s), prevExposureValue(0s) + currentExposure_(0s), prevExposureValue(0s) { } @@ -96,7 +95,6 @@ void Agc::filterExposure() if (filteredExposure_ == 0s) { /* DG stands for digital gain.*/ filteredExposure_ = currentExposure_; - filteredExposureNoDg_ = currentExposureNoDg_; } else { /* * If we are close to the desired result, go faster to avoid making @@ -109,18 +107,8 @@ void Agc::filterExposure() filteredExposure_ = speed * currentExposure_ + filteredExposure_ * (1.0 - speed); - filteredExposureNoDg_ = speed * currentExposureNoDg_ + - filteredExposureNoDg_ * (1.0 - speed); } - /* - * We can't let the no_dg exposure deviate too far below the - * total exposure, as there might not be enough digital gain available - * in the ISP to hide it (which will cause nasty oscillation). - */ - double fastReduceThreshold = 0.4; - if (filteredExposureNoDg_ < - filteredExposure_ * fastReduceThreshold) - filteredExposureNoDg_ = filteredExposure_ * fastReduceThreshold; + LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << filteredExposure_; } @@ -136,8 +124,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain) /* extracted from Rpi::Agc::computeTargetExposure */ Duration currentShutter = exposure * lineDuration_; - currentExposureNoDg_ = currentShutter * analogueGain; - LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ + LOG(IPU3Agc, Debug) << "Actual total exposure " << currentShutter * analogueGain << " Shutter speed " << currentShutter << " Gain " << analogueGain << " Needed ev gain " << evGain; diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 32817c4f..5b34c013 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -48,9 +48,7 @@ private: uint32_t maxExposureLines_; Duration filteredExposure_; - Duration filteredExposureNoDg_; Duration currentExposure_; - Duration currentExposureNoDg_; Duration prevExposureValue; uint32_t stride_;