From patchwork Mon Oct 24 00:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17668 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 228DFBDB16 for ; Mon, 24 Oct 2022 00:04:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B28CD62EF6; Mon, 24 Oct 2022 02:04:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1666569873; bh=q4vlaDe9G9foCStqIT1WIl/viTRR4Z/iQiMqa/j9kDQ=; 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=rCfIUJsDQQmf1r+Rd1N97egH/R2zOqJuaa6H2XO+uyYr0ouMlPRU6RDEKxFZDZXI1 0oVSlq7yPtgKdnnbHSBiQUUdvkYdAKJZPewp3UZv5WN8usc0kbAzTSe+IsNwcsqpyc ZgGaGWqQ3ndDbu0qJDoNufXAUEsyWFg1fQ0GbtSvAnXaya5YsV48YAcEh9uaRxa4MC HU5cwgg7gkwklkUhccPALirJyilViGtdlyYwV9x8JgatkyHg7E58hYARP8Iz8hb5qr OVjXN1TO6v6OQu2q0yuQX3P0rwJMeA/8aGw2AzhVAUQnKFSBQkCdrkJOtnDALxILNS BSidV0fh7l+/Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9ED8562ED2 for ; Mon, 24 Oct 2022 02:04:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Frr44n+a"; 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 2AC1B471; Mon, 24 Oct 2022 02:04:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1666569868; bh=q4vlaDe9G9foCStqIT1WIl/viTRR4Z/iQiMqa/j9kDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Frr44n+alCuPJx1WCYYRZgEbkOnfGPLzeQvwPjdY6PnHTht/klXuZ2r16w0QM7cCt UvaGDoK+q+TicV+jTBD3nm3g2JuycV3a0Me0W3Muu3pg0mndoDZxUblbK6taQwpixL rum17DgQ5+waLWGXfkRZ4H6FUIS4/AiWgqHP/Aro= To: libcamera-devel@lists.libcamera.org Date: Mon, 24 Oct 2022 03:03:48 +0300 Message-Id: <20221024000356.29521-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221024000356.29521-1-laurent.pinchart@ideasonboard.com> References: <20221024000356.29521-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/13] ipa: rkisp1: agc: Support raw capture 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" Support raw capture by allowing manual control of the exposure time and analogue gain. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- src/ipa/rkisp1/algorithms/agc.cpp | 51 ++++++++++++++++++++----------- src/ipa/rkisp1/algorithms/agc.h | 2 ++ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 377a3e8a0efd..973965babed2 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -62,6 +62,7 @@ static constexpr double kRelativeLuminanceTarget = 0.4; Agc::Agc() : frameCount_(0), numCells_(0), numHistBins_(0), filteredExposure_(0s) { + supportsRaw_ = true; } /** @@ -81,7 +82,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) 10ms / context.configuration.sensor.lineDuration; context.activeState.agc.manual.gain = context.activeState.agc.automatic.gain; context.activeState.agc.manual.exposure = context.activeState.agc.automatic.exposure; - context.activeState.agc.autoEnabled = true; + context.activeState.agc.autoEnabled = !context.configuration.raw; /* * According to the RkISP1 documentation: @@ -123,12 +124,14 @@ void Agc::queueRequest(IPAContext &context, { auto &agc = context.activeState.agc; - const auto &agcEnable = controls.get(controls::AeEnable); - if (agcEnable && *agcEnable != agc.autoEnabled) { - agc.autoEnabled = *agcEnable; + if (!context.configuration.raw) { + const auto &agcEnable = controls.get(controls::AeEnable); + if (agcEnable && *agcEnable != agc.autoEnabled) { + agc.autoEnabled = *agcEnable; - LOG(RkISP1Agc, Debug) - << (*agcEnable ? "Enabling" : "Disabling") << " AGC"; + LOG(RkISP1Agc, Debug) + << (*agcEnable ? "Enabling" : "Disabling") << " AGC"; + } } const auto &exposure = controls.get(controls::ExposureTime); @@ -160,6 +163,9 @@ void Agc::queueRequest(IPAContext &context, void Agc::prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, rkisp1_params_cfg *params) { + if (!params) + return; + if (frameContext.agc.autoEnabled) { frameContext.agc.exposure = context.activeState.agc.automatic.exposure; frameContext.agc.gain = context.activeState.agc.automatic.gain; @@ -367,6 +373,22 @@ double Agc::measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const return histogram.interQuantileMean(0.98, 1.0); } +void Agc::fillMetadata(IPAContext &context, IPAFrameContext &frameContext, + ControlList &metadata) +{ + 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()); +} + /** * \brief Process RkISP1 statistics, and run AGC operations * \param[in] context The shared IPA context @@ -382,6 +404,11 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats, ControlList &metadata) { + if (!stats) { + fillMetadata(context, frameContext, metadata); + return; + } + /* * \todo Verify that the exposure and gain applied by the sensor for * this frame match what has been requested. This isn't a hard @@ -424,17 +451,7 @@ 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()); + fillMetadata(context, frameContext, metadata); } REGISTER_IPA_ALGORITHM(Agc, "Agc") diff --git a/src/ipa/rkisp1/algorithms/agc.h b/src/ipa/rkisp1/algorithms/agc.h index a228d0c37768..8a22263741b6 100644 --- a/src/ipa/rkisp1/algorithms/agc.h +++ b/src/ipa/rkisp1/algorithms/agc.h @@ -44,6 +44,8 @@ private: utils::Duration filterExposure(utils::Duration exposureValue); double estimateLuminance(const rkisp1_cif_isp_ae_stat *ae, double gain); double measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const; + void fillMetadata(IPAContext &context, IPAFrameContext &frameContext, + ControlList &metadata); uint64_t frameCount_;