[libcamera-devel,v4,5/9] ipa: rkisp1: agc: Support raw capture
diff mbox series

Message ID 20221124025133.17875-6-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Add Bayer format support for RkISP1
Related show

Commit Message

Laurent Pinchart Nov. 24, 2022, 2:51 a.m. UTC
Support raw capture by allowing manual control of the exposure time and
analogue gain.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
---
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(-)

Comments

Jacopo Mondi Nov. 24, 2022, 12:25 p.m. UTC | #1
Hi Laurent

On Thu, Nov 24, 2022 at 04:51:29AM +0200, Laurent Pinchart via libcamera-devel wrote:
> Support raw capture by allowing manual control of the exposure time and
> analogue gain.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

LGTM
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> ---
> 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<std::micro>());
> +
> +	/* \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<std::micro>());
> +}
> +
>  /**
>   * \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<std::micro>());
> -
> -	/* \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<std::micro>());
> +	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_;
>
> --
> Regards,
>
> Laurent Pinchart
>

Patch
diff mbox series

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<std::micro>());
+
+	/* \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<std::micro>());
+}
+
 /**
  * \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<std::micro>());
-
-	/* \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<std::micro>());
+	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_;