From patchwork Wed Oct 19 20:56:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17643 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 5B586C327C for ; Wed, 19 Oct 2022 20:56:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 071D762E69; Wed, 19 Oct 2022 22:56:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666213006; bh=outIGZNDFhfw+v/f0Xrt5Zk6YNJRbV269r4O/NHohC4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Ev7smDNZkK0Nof8ATP/4N6lf58A5d9/gOqYTAU8bvPokPaZWA4dKxiLZr+TsHjZHg XWeUON82MWinVhQh9W5CMfqy3RSxykZklK4V95LhnyJ6+nGKXI19Ra1dllU5m5Ma7Z DF8i3+Djd90fH67PSCdzLwJNCMZKcoYlR1GO2UDTdoxlIZXpHcoXmBbtnTUnH51oyj pGSD0qJk36LJrBLVMXPpkdBh1v8txR4vPJsfo5xlu9DQ1M4OFVScQp5XmbUsyGv0Bx jQoIHUuv60OzRCt2y5fl5TN1vJ/q5S/fEtHFR96Kl5hRoQayIJc7dZyv9wBRJ52djK TOWzUEVb8stDw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CFDF362E61 for ; Wed, 19 Oct 2022 22:56:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YpHCkjFM"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5FE13903 for ; Wed, 19 Oct 2022 22:56:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1666213002; bh=outIGZNDFhfw+v/f0Xrt5Zk6YNJRbV269r4O/NHohC4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YpHCkjFMa1e1JGIC2YxAbH0UswVSRS6y+X8efXZEWhDoRM3JuN8sQ0u0DypvQI4+5 cIs2Ibl3kUwL/KgIABbwne7FAL9O+QoFqkBSNR+msuX93QoBc9zAF3fiaXo+1fGl6w B7YgRCFx+JUa+fmPxWI4czkNs/6jp33EL8bDlMRY= To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Oct 2022 23:56:14 +0300 Message-Id: <20221019205614.25751-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019205614.25751-1-laurent.pinchart@ideasonboard.com> References: <20221019205614.25751-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] ipa: ipu3: Fill AGC and AWB metadata in algorithms 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Fill the frame metadata in the AGC and AWB algorithm's prepare() function. This removes the need to fill metadata manually in the IPA module's processStatsBuffer() function. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/agc.cpp | 16 +++++++++++++++- src/ipa/ipu3/algorithms/awb.cpp | 10 ++++++++++ src/ipa/ipu3/ipa_context.cpp | 3 +++ src/ipa/ipu3/ipa_context.h | 1 + src/ipa/ipu3/ipu3.cpp | 13 +------------ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index f4e559bf8b84..b5309bdbea25 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include "libipa/histogram.h" @@ -328,7 +329,7 @@ double Agc::estimateLuminance(IPAActiveState &activeState, void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, const ipu3_uapi_stats_3a *stats, - [[maybe_unused]] ControlList &metadata) + ControlList &metadata) { /* * Estimate the gain needed to have the proportion of pixels in a given @@ -365,6 +366,19 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, computeExposure(context, frameContext, yGain, iqMeanGain); frameCount_++; + + utils::Duration exposureTime = context.configuration.sensor.lineDuration + * frameContext.sensor.exposure; + metadata.set(controls::AnalogueGain, frameContext.sensor.gain); + metadata.set(controls::ExposureTime, exposureTime.get()); + + /* \todo Use VBlank value calculated from each frame exposure. */ + uint32_t vTotal = context.configuration.sensor.size.height + + context.configuration.sensor.defVBlank; + utils::Duration frameDuration = context.configuration.sensor.lineDuration + * vTotal; + metadata.set(controls::FrameDuration, frameDuration.get()); + } REGISTER_IPA_ALGORITHM(Agc, "Agc") diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 6452b6a1acd2..dd7ebc07c534 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -11,6 +11,8 @@ #include +#include + /** * \file awb.h */ @@ -403,6 +405,14 @@ void Awb::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, context.activeState.awb.gains.green = asyncResults_.greenGain; context.activeState.awb.gains.red = asyncResults_.redGain; context.activeState.awb.temperatureK = asyncResults_.temperatureK; + + metadata.set(controls::AwbEnable, true); + metadata.set(controls::ColourGains, { + static_cast(context.activeState.awb.gains.red), + static_cast(context.activeState.awb.gains.blue) + }); + metadata.set(controls::ColourTemperature, + context.activeState.awb.temperatureK); } constexpr uint16_t Awb::threshold(float value) diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index 68f017b04751..959f314f5452 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -111,6 +111,9 @@ namespace libcamera::ipa::ipu3 { * * \var IPASessionConfiguration::sensor.defVBlank * \brief The default vblank value of the sensor + * + * \var IPASessionConfiguration::sensor.size + * \brief Sensor output resolution */ /** diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index 36099353e9f2..e9a3863b1693 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -41,6 +41,7 @@ struct IPASessionConfiguration { struct { int32_t defVBlank; utils::Duration lineDuration; + Size size; } sensor; }; diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index bc0f6007baca..a9a2b49ca95b 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -502,6 +502,7 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, /* Initialise the sensor configuration. */ context_.configuration.sensor.lineDuration = sensorInfo_.minLineLength * 1.0s / sensorInfo_.pixelRate; + context_.configuration.sensor.size = sensorInfo_.outputSize; /* * Compute the sensor V4L2 controls to be used by the algorithms and @@ -628,8 +629,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); - double lineDuration = context_.configuration.sensor.lineDuration.get(); - int32_t vBlank = context_.configuration.sensor.defVBlank; ControlList metadata(controls::controls); for (auto const &algo : algorithms()) @@ -637,16 +636,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, setControls(frame); - /* \todo Use VBlank value calculated from each frame exposure. */ - int64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration; - metadata.set(controls::FrameDuration, frameDuration); - - metadata.set(controls::AnalogueGain, frameContext.sensor.gain); - - metadata.set(controls::ColourTemperature, context_.activeState.awb.temperatureK); - - metadata.set(controls::ExposureTime, frameContext.sensor.exposure * lineDuration); - /* * \todo The Metadata provides a path to getting extended data * out to the application. Further data such as a simplifed Histogram