[PATCH v4 3/6] ipa: rkisp1: awb: Implement ColourTemperature control

Paul Elder paul.elder at ideasonboard.com
Wed Aug 28 09:14:54 CEST 2024


On Tue, Aug 13, 2024 at 10:44:20AM +0200, Stefan Klug wrote:
> There are many use-cases (tuning-validation, working in static
> environments) where a manual ColourTemperature control is helpful.
> Implement that by interpolating and applying the white balance gains
> from the tuning file according to the requested colour temperature. If
> colour gains are provided on the same request, they take precedence. As
> the colour temperature reported in the metadata is always based on the
> measurements, we don't have to touch that.
> 
> Note that in the automatic case, the colour gains are still based on the
> gray world model and the ones from the tuning file get ignored.
> 
> Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>

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

> ---
>  src/ipa/rkisp1/algorithms/awb.cpp | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
> index c23f749c192b..d482eda5b541 100644
> --- a/src/ipa/rkisp1/algorithms/awb.cpp
> +++ b/src/ipa/rkisp1/algorithms/awb.cpp
> @@ -31,6 +31,10 @@ namespace ipa::rkisp1::algorithms {
>  
>  LOG_DEFINE_CATEGORY(RkISP1Awb)
>  
> +constexpr int32_t kMinColourTemperature = 2500;
> +constexpr int32_t kMaxColourTemperature = 10000;
> +constexpr int32_t kDefaultColourTemperature = 6500;
> +
>  /* Minimum mean value below which AWB can't operate. */
>  constexpr double kMeanMinThreshold = 2.0;
>  
> @@ -42,8 +46,13 @@ Awb::Awb()
>  /**
>   * \copydoc libcamera::ipa::Algorithm::init
>   */
> -int Awb::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
> +int Awb::init(IPAContext &context, const YamlObject &tuningData)
>  {
> +	auto &cmap = context.ctrlMap;
> +	cmap[&controls::ColourTemperature] = ControlInfo(kMinColourTemperature,
> +							 kMaxColourTemperature,
> +							 kDefaultColourTemperature);
> +
>  	MatrixInterpolator<double, 2, 1> gains;
>  	int ret = gains.readYaml(tuningData["gains"], "ct", "gains");
>  	if (ret < 0)
> @@ -113,6 +122,17 @@ void Awb::queueRequest(IPAContext &context,
>  			<< ", blue: " << awb.gains.manual.blue;
>  	}
>  
> +	const auto &colourTemperature = controls.get(controls::ColourTemperature);
> +	if (colourTemperature && !awb.autoEnabled && gains_ && !colourGains) {
> +		Matrix<double, 2, 1> gains = gains_->get(*colourTemperature);
> +		awb.gains.manual.red = gains[0][0];
> +		awb.gains.manual.blue = gains[1][0];
> +
> +		LOG(RkISP1Awb, Debug)
> +			<< "Set colour gains to red: " << awb.gains.manual.red
> +			<< ", blue: " << awb.gains.manual.blue;
> +	}
> +
>  	frameContext.awb.autoEnabled = awb.autoEnabled;
>  
>  	if (!awb.autoEnabled) {
> -- 
> 2.43.0
> 


More information about the libcamera-devel mailing list