From patchwork Thu Nov 24 02:51:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17856 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 B31B7BDE6B for ; Thu, 24 Nov 2022 02:52:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5FBFF6332C; Thu, 24 Nov 2022 03:52:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669258320; bh=hR1H2XvPxMz/AJJBPZvPmizY8AIaDb20Qff5SjK4wkM=; 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=nzdnS980dXPpf3/M/P529KG8nDem98AcgXJKRaunFx491HQd3DMbOi6vGxW0xRrza NG0K0WMx7ulMpweCWcVwIkst/6aLLMrQZiGEF5xNGs5Cd+ODyHW6lRCTRZ4TcLQ79+ HLa5O+5nxo8qjT0AhSfBbR0F8+zAT4evOSE6nnC7WbdmAaGKAzlXvy5eddDwrsFbeW TDl+VfXEU7Fak/9btjxpi+bBjjT2M21NRVfWgGo2p0T1JKA2rpQvVvD6d3MQl4MQ5D E2CRCwmAK4CDrqq+okqihTsPkBgn4ak7ecFJwMobKBkXFztoRRimsAT9rNUQ6nNKeS FF3g/823MZK1Q== 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 3762B63325 for ; Thu, 24 Nov 2022 03:51:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="O+M5r1Hx"; 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 AEA3A496 for ; Thu, 24 Nov 2022 03:51:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1669258316; bh=hR1H2XvPxMz/AJJBPZvPmizY8AIaDb20Qff5SjK4wkM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=O+M5r1HxTPR/dG6umaMUgvun92sd6gYX0yPI7kXWn7fN+K7YMtT1yn93tSRRVGNfK Ec/ecEN5a34xs4f+DustC8IMZHUO12k8UQ6TXgvIHZ9CyKm5AYEG71vQlWwIr34yT4 zkx+AWaqHplO1nX7oWN+KmLgdWtFVIDChc+EVFxQ= To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Nov 2022 04:51:29 +0200 Message-Id: <20221124025133.17875-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221124025133.17875-1-laurent.pinchart@ideasonboard.com> References: <20221124025133.17875-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/9] 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 Reviewed-by: Jacopo Mondi --- Changes since v3: - Drop unneeded params null check --- src/ipa/rkisp1/algorithms/agc.cpp | 49 ++++++++++++++++++++----------- src/ipa/rkisp1/algorithms/agc.h | 2 ++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index ccbcd4a9583d..6bf92743f4cf 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,15 @@ 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) - << (agc.autoEnabled ? "Enabling" : "Disabling") << " AGC"; + LOG(RkISP1Agc, Debug) + << (agc.autoEnabled ? "Enabling" : "Disabling") + << " AGC"; + } } const auto &exposure = controls.get(controls::ExposureTime); @@ -368,6 +372,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 @@ -383,6 +403,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 @@ -425,17 +450,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_;