[libcamera-devel] [PATCH v2 2/3] ipa: rkisp1: Fill AGC and AWB metadata

paul.elder at ideasonboard.com paul.elder at ideasonboard.com
Fri Oct 21 09:04:39 CEST 2022


On Wed, Oct 19, 2022 at 11:56:13PM +0300, Laurent Pinchart via libcamera-devel wrote:
> Fill the frame metadata in the AGC and AWB algorithm's prepare()

s/prepare/process/

> function. Additional metadata for other algorithms will be addressed
> later.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>

Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>

> ---
> Changes since v1:
> 
> - Report the ColourTemperature and FrameDuration controls as well
> ---
>  src/ipa/rkisp1/algorithms/agc.cpp | 15 ++++++++++++++-
>  src/ipa/rkisp1/algorithms/awb.cpp |  9 ++++++++-
>  src/ipa/rkisp1/ipa_context.cpp    |  3 +++
>  src/ipa/rkisp1/ipa_context.h      |  1 +
>  src/ipa/rkisp1/rkisp1.cpp         |  2 ++
>  5 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp
> index 37cd10f9b302..b4fc7aed4d9d 100644
> --- a/src/ipa/rkisp1/algorithms/agc.cpp
> +++ b/src/ipa/rkisp1/algorithms/agc.cpp
> @@ -14,6 +14,7 @@
>  #include <libcamera/base/log.h>
>  #include <libcamera/base/utils.h>
>  
> +#include <libcamera/control_ids.h>
>  #include <libcamera/ipa/core_ipa_interface.h>
>  
>  #include "libipa/histogram.h"
> @@ -290,7 +291,7 @@ double Agc::measureBrightness(const rkisp1_cif_isp_hist_stat *hist) const
>   */
>  void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
>  		  IPAFrameContext &frameContext, const rkisp1_stat_buffer *stats,
> -		  [[maybe_unused]] ControlList &metadata)
> +		  ControlList &metadata)
>  {
>  	/*
>  	 * \todo Verify that the exposure and gain applied by the sensor for
> @@ -333,6 +334,18 @@ 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>());
>  }
>  
>  /**
> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
> index f597ded800c2..083c2d982c52 100644
> --- a/src/ipa/rkisp1/algorithms/awb.cpp
> +++ b/src/ipa/rkisp1/algorithms/awb.cpp
> @@ -209,7 +209,7 @@ void Awb::process(IPAContext &context,
>  		  [[maybe_unused]] const uint32_t frame,
>  		  IPAFrameContext &frameContext,
>  		  const rkisp1_stat_buffer *stats,
> -		  [[maybe_unused]] ControlList &metadata)
> +		  ControlList &metadata)
>  {
>  	const rkisp1_cif_isp_stat *params = &stats->params;
>  	const rkisp1_cif_isp_awb_stat *awb = &params->awb;
> @@ -307,6 +307,13 @@ void Awb::process(IPAContext &context,
>  
>  	frameContext.awb.temperatureK = activeState.awb.temperatureK;
>  
> +	metadata.set(controls::AwbEnable, frameContext.awb.autoEnabled);
> +	metadata.set(controls::ColourGains, {
> +			static_cast<float>(frameContext.awb.gains.red),
> +			static_cast<float>(frameContext.awb.gains.blue)
> +		});
> +	metadata.set(controls::ColourTemperature, frameContext.awb.temperatureK);
> +
>  	LOG(RkISP1Awb, Debug) << std::showpoint
>  		<< "Means [" << redMean << ", " << greenMean << ", " << blueMean
>  		<< "], gains [" << activeState.awb.gains.automatic.red << ", "
> diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp
> index b00dc29c1713..3c14cf3476ce 100644
> --- a/src/ipa/rkisp1/ipa_context.cpp
> +++ b/src/ipa/rkisp1/ipa_context.cpp
> @@ -77,6 +77,9 @@ namespace libcamera::ipa::rkisp1 {
>   * \var IPASessionConfiguration::sensor
>   * \brief Sensor-specific configuration of the IPA
>   *
> + * \var IPASessionConfiguration::sensor.defVBlank
> + * \brief The default vblank value of the sensor
> + *
>   * \var IPASessionConfiguration::sensor.lineDuration
>   * \brief Line duration in microseconds
>   *
> diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h
> index c85d8abeca71..60e8a7e11196 100644
> --- a/src/ipa/rkisp1/ipa_context.h
> +++ b/src/ipa/rkisp1/ipa_context.h
> @@ -39,6 +39,7 @@ struct IPASessionConfiguration {
>  	} lsc;
>  
>  	struct {
> +		int32_t defVBlank;
>  		utils::Duration lineDuration;
>  		Size size;
>  	} sensor;
> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
> index 494d8c891509..069c901bb141 100644
> --- a/src/ipa/rkisp1/rkisp1.cpp
> +++ b/src/ipa/rkisp1/rkisp1.cpp
> @@ -244,6 +244,8 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info,
>  	/* Set the hardware revision for the algorithms. */
>  	context_.configuration.hw.revision = hwRevision_;
>  
> +	const ControlInfo vBlank = ctrls_.find(V4L2_CID_VBLANK)->second;
> +	context_.configuration.sensor.defVBlank = vBlank.def().get<int32_t>();
>  	context_.configuration.sensor.size = info.outputSize;
>  	context_.configuration.sensor.lineDuration = info.minLineLength * 1.0s / info.pixelRate;
>  


More information about the libcamera-devel mailing list