[libcamera-devel,v2,09/10] ipa: ipu3: Move IPU3 awb into algorithms
diff mbox series

Message ID 20210812165243.276977-10-jeanmichel.hautbois@ideasonboard.com
State Superseded
Headers show
Series
  • IPU3: Introduce modularity for algorithms
Related show

Commit Message

Jean-Michel Hautbois Aug. 12, 2021, 4:52 p.m. UTC
Now that the interface is properly used by the AWB class, move it into
ipa::ipu3::algorithms and let the loops do the calls.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 .../ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} | 28 +++++++++----------
 src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} | 20 ++++++-------
 src/ipa/ipu3/algorithms/meson.build           |  1 +
 src/ipa/ipu3/ipu3.cpp                         | 12 ++------
 src/ipa/ipu3/meson.build                      |  1 -
 5 files changed, 28 insertions(+), 34 deletions(-)
 rename src/ipa/ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} (94%)
 rename src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} (84%)

Comments

Kieran Bingham Aug. 13, 2021, 10:11 a.m. UTC | #1
On 12/08/2021 17:52, Jean-Michel Hautbois wrote:
> Now that the interface is properly used by the AWB class, move it into
> ipa::ipu3::algorithms and let the loops do the calls.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  .../ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} | 28 +++++++++----------
>  src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} | 20 ++++++-------
>  src/ipa/ipu3/algorithms/meson.build           |  1 +
>  src/ipa/ipu3/ipu3.cpp                         | 12 ++------
>  src/ipa/ipu3/meson.build                      |  1 -
>  5 files changed, 28 insertions(+), 34 deletions(-)
>  rename src/ipa/ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} (94%)
>  rename src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} (84%)
> 
> diff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> similarity index 94%
> rename from src/ipa/ipu3/ipu3_awb.cpp
> rename to src/ipa/ipu3/algorithms/awb.cpp
> index b422b095..0f401d6d 100644
> --- a/src/ipa/ipu3/ipu3_awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -2,9 +2,9 @@
>  /*
>   * Copyright (C) 2021, Ideas On Board
>   *
> - * ipu3_awb.cpp - AWB control algorithm
> + * awb.cpp - AWB control algorithm
>   */
> -#include "ipu3_awb.h"
> +#include "awb.h"
>  
>  #include <algorithm>
>  #include <cmath>
> @@ -13,7 +13,7 @@
>  
>  namespace libcamera {
>  
> -namespace ipa::ipu3 {
> +namespace ipa::ipu3::algorithms {
>  
>  LOG_DEFINE_CATEGORY(IPU3Awb)
>  
> @@ -114,7 +114,7 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {
>  	0, 0, 8191, 0
>  };
>  
> -IPU3Awb::IPU3Awb()
> +Awb::Awb()
>  	: Algorithm()
>  {
>  	asyncResults_.blueGain = 1.0;
> @@ -125,7 +125,7 @@ IPU3Awb::IPU3Awb()
>  	zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);
>  }
>  
> -IPU3Awb::~IPU3Awb()
> +Awb::~Awb()
>  {
>  }
>  
> @@ -143,7 +143,7 @@ IPU3Awb::~IPU3Awb()
>   * More detailed information can be found in:
>   * https://en.wikipedia.org/wiki/Color_temperature#Approximation
>   */
> -uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
> +uint32_t Awb::estimateCCT(double red, double green, double blue)
>  {
>  	/* Convert the RGB values to CIE tristimulus values (XYZ) */
>  	double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue);
> @@ -160,7 +160,7 @@ uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
>  }
>  
>  /* Generate an RGB vector with the average values for each region */
> -void IPU3Awb::generateZones(std::vector<RGB> &zones)
> +void Awb::generateZones(std::vector<RGB> &zones)
>  {
>  	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
>  		RGB zone;
> @@ -177,7 +177,7 @@ void IPU3Awb::generateZones(std::vector<RGB> &zones)
>  }
>  
>  /* Translate the IPU3 statistics into the default statistics region array */
> -void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
> +void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
>  {
>  	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
>  	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
> @@ -209,7 +209,7 @@ void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
>  	}
>  }
>  
> -void IPU3Awb::clearAwbStats()
> +void Awb::clearAwbStats()
>  {
>  	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
>  		awbStats_[i].bSum = 0;
> @@ -220,7 +220,7 @@ void IPU3Awb::clearAwbStats()
>  	}
>  }
>  
> -void IPU3Awb::awbGreyWorld()
> +void Awb::awbGreyWorld()
>  {
>  	LOG(IPU3Awb, Debug) << "Grey world AWB";
>  	/*
> @@ -260,7 +260,7 @@ void IPU3Awb::awbGreyWorld()
>  	asyncResults_.blueGain = blueGain;
>  }
>  
> -void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
> +void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>  {
>  	ASSERT(stats->stats_3a_status.awb_en);
>  	zones_.clear();
> @@ -275,7 +275,7 @@ void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>  	}
>  }
>  
> -void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
> +void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>  {
>  	calculateWBGains(stats);
>  	context.frameContext.awb.gains.blueGain = asyncResults_.blueGain;
> @@ -283,7 +283,7 @@ void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>  	context.frameContext.awb.gains.redGain = asyncResults_.redGain;
>  }
>  
> -void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
> +void Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
>  {
>  	params.use.acc_awb = 1;
>  	params.acc_param.awb.config.rgbs_thr_gr = 8191;
> @@ -327,6 +327,6 @@ void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
>  	params.acc_param.ccm = imguCssCcmDefault;
>  }
>  
> -} /* namespace ipa::ipu3 */
> +} /* namespace ipa::ipu3::algorithms */
>  
>  } /* namespace libcamera */
> diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/algorithms/awb.h
> similarity index 84%
> rename from src/ipa/ipu3/ipu3_awb.h
> rename to src/ipa/ipu3/algorithms/awb.h
> index 4de3fae2..ad640521 100644
> --- a/src/ipa/ipu3/ipu3_awb.h
> +++ b/src/ipa/ipu3/algorithms/awb.h
> @@ -2,10 +2,10 @@
>  /*
>   * Copyright (C) 2021, Ideas On Board
>   *
> - * ipu3_awb.h - IPU3 AWB control algorithm
> + * awb.h - IPU3 AWB control algorithm
>   */
> -#ifndef __LIBCAMERA_IPU3_AWB_H__
> -#define __LIBCAMERA_IPU3_AWB_H__
> +#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
> +#define __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
>  
>  #include <vector>
>  
> @@ -13,21 +13,21 @@
>  
>  #include <libcamera/geometry.h>
>  
> -#include "algorithms/algorithm.h"
> +#include "algorithm.h"
>  
>  namespace libcamera {
>  
> -namespace ipa::ipu3 {
> +namespace ipa::ipu3::algorithms {
>  
>  /* Region size for the statistics generation algorithm */
>  static constexpr uint32_t kAwbStatsSizeX = 16;
>  static constexpr uint32_t kAwbStatsSizeY = 12;
>  
> -class IPU3Awb : public Algorithm
> +class Awb : public Algorithm
>  {
>  public:
> -	IPU3Awb();
> -	~IPU3Awb();
> +	Awb();
> +	~Awb();
>  
>  	void prepare(IPAContext &context, ipu3_uapi_params &params) override;
>  	void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;
> @@ -85,7 +85,7 @@ private:
>  	AwbStatus asyncResults_;
>  };
>  
> -} /* namespace ipa::ipu3 */
> +} /* namespace ipa::ipu3::algorithms */
>  
>  } /* namespace libcamera*/
> -#endif /* __LIBCAMERA_IPU3_AWB_H__ */
> +#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__ */
> diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build
> index 69a59096..9ef2dd41 100644
> --- a/src/ipa/ipu3/algorithms/meson.build
> +++ b/src/ipa/ipu3/algorithms/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  ipu3_ipa_algorithms = files([
> +    'awb.cpp',
>      'contrast.cpp',
>      'grid.cpp',
>  ])
> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> index 27765aa6..bea2a372 100644
> --- a/src/ipa/ipu3/ipu3.cpp
> +++ b/src/ipa/ipu3/ipu3.cpp
> @@ -30,10 +30,10 @@
>  #include "libcamera/internal/mapped_framebuffer.h"
>  
>  #include "algorithms/algorithm.h"
> +#include "algorithms/awb.h"
>  #include "algorithms/contrast.h"
>  #include "algorithms/grid.h"
>  #include "ipu3_agc.h"
> -#include "ipu3_awb.h"
>  #include "libipa/camera_sensor_helper.h"
>  
>  namespace libcamera {
> @@ -84,8 +84,6 @@ private:
>  	uint32_t minGain_;
>  	uint32_t maxGain_;
>  
> -	/* Interface to the AWB algorithm */
> -	std::unique_ptr<IPU3Awb> awbAlgo_;
>  	/* Interface to the AEC/AGC algorithm */
>  	std::unique_ptr<IPU3Agc> agcAlgo_;
>  	/* Interface to the Camera Helper */
> @@ -168,6 +166,8 @@ int IPAIPU3::init(const IPASettings &settings,
>  	*ipaControls = ControlInfoMap(std::move(controls), controls::controls);
>  	/* Construct our Algorithms */
>  	algorithms_.emplace_back(new algorithms::Grid());
> +	/* Grid needs to be prepared before AWB */

In the next patch, you add AGC in between grid and Awb ...

How about saying 'Grid configuration must be processed before other
algorithms' as a comment above Grid, ... (when Grid is added, in the
grid patch).


With that,

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> +	algorithms_.emplace_back(new algorithms::Awb());
>  	algorithms_.emplace_back(new algorithms::Contrast());
>  
>  	return 0;
> @@ -229,8 +229,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)
>  			return ret;
>  	}
>  
> -	awbAlgo_ = std::make_unique<IPU3Awb>();
> -
>  	agcAlgo_ = std::make_unique<IPU3Agc>();
>  	agcAlgo_->configure(context_, configInfo);
>  
> @@ -309,8 +307,6 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)
>  	for (auto const &algo : algorithms_)
>  		algo->prepare(context_, params_);
>  
> -	awbAlgo_->prepare(context_, params_);
> -
>  	*params = params_;
>  
>  	IPU3Action op;
> @@ -335,8 +331,6 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>  	gain = context_.frameContext.agc.gain;
>  	gain_ = camHelper_->gainCode(gain);
>  
> -	awbAlgo_->process(context_, stats);
> -
>  	setControls(frame);
>  
>  	/* \todo Use VBlank value calculated from each frame exposure. */
> diff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build
> index fcb27d68..d1126947 100644
> --- a/src/ipa/ipu3/meson.build
> +++ b/src/ipa/ipu3/meson.build
> @@ -7,7 +7,6 @@ ipa_name = 'ipa_ipu3'
>  ipu3_ipa_sources = files([
>      'ipu3.cpp',
>      'ipu3_agc.cpp',
> -    'ipu3_awb.cpp',
>  ])
>  
>  ipu3_ipa_sources += ipu3_ipa_algorithms
>
Laurent Pinchart Aug. 16, 2021, 12:05 a.m. UTC | #2
Hi Jean-Michel,

Thank you for the patch.

On Thu, Aug 12, 2021 at 06:52:42PM +0200, Jean-Michel Hautbois wrote:
> Now that the interface is properly used by the AWB class, move it into
> ipa::ipu3::algorithms and let the loops do the calls.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  .../ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} | 28 +++++++++----------
>  src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} | 20 ++++++-------
>  src/ipa/ipu3/algorithms/meson.build           |  1 +
>  src/ipa/ipu3/ipu3.cpp                         | 12 ++------
>  src/ipa/ipu3/meson.build                      |  1 -
>  5 files changed, 28 insertions(+), 34 deletions(-)
>  rename src/ipa/ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} (94%)
>  rename src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} (84%)
> 
> diff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> similarity index 94%
> rename from src/ipa/ipu3/ipu3_awb.cpp
> rename to src/ipa/ipu3/algorithms/awb.cpp
> index b422b095..0f401d6d 100644
> --- a/src/ipa/ipu3/ipu3_awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -2,9 +2,9 @@
>  /*
>   * Copyright (C) 2021, Ideas On Board
>   *
> - * ipu3_awb.cpp - AWB control algorithm
> + * awb.cpp - AWB control algorithm
>   */
> -#include "ipu3_awb.h"
> +#include "awb.h"
>  
>  #include <algorithm>
>  #include <cmath>
> @@ -13,7 +13,7 @@
>  
>  namespace libcamera {
>  
> -namespace ipa::ipu3 {
> +namespace ipa::ipu3::algorithms {
>  
>  LOG_DEFINE_CATEGORY(IPU3Awb)
>  
> @@ -114,7 +114,7 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {
>  	0, 0, 8191, 0
>  };
>  
> -IPU3Awb::IPU3Awb()
> +Awb::Awb()
>  	: Algorithm()
>  {
>  	asyncResults_.blueGain = 1.0;
> @@ -125,7 +125,7 @@ IPU3Awb::IPU3Awb()
>  	zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);
>  }
>  
> -IPU3Awb::~IPU3Awb()
> +Awb::~Awb()
>  {
>  }
>  
> @@ -143,7 +143,7 @@ IPU3Awb::~IPU3Awb()
>   * More detailed information can be found in:
>   * https://en.wikipedia.org/wiki/Color_temperature#Approximation
>   */
> -uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
> +uint32_t Awb::estimateCCT(double red, double green, double blue)
>  {
>  	/* Convert the RGB values to CIE tristimulus values (XYZ) */
>  	double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue);
> @@ -160,7 +160,7 @@ uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
>  }
>  
>  /* Generate an RGB vector with the average values for each region */
> -void IPU3Awb::generateZones(std::vector<RGB> &zones)
> +void Awb::generateZones(std::vector<RGB> &zones)
>  {
>  	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
>  		RGB zone;
> @@ -177,7 +177,7 @@ void IPU3Awb::generateZones(std::vector<RGB> &zones)
>  }
>  
>  /* Translate the IPU3 statistics into the default statistics region array */
> -void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
> +void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
>  {
>  	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
>  	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
> @@ -209,7 +209,7 @@ void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
>  	}
>  }
>  
> -void IPU3Awb::clearAwbStats()
> +void Awb::clearAwbStats()
>  {
>  	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
>  		awbStats_[i].bSum = 0;
> @@ -220,7 +220,7 @@ void IPU3Awb::clearAwbStats()
>  	}
>  }
>  
> -void IPU3Awb::awbGreyWorld()
> +void Awb::awbGreyWorld()
>  {
>  	LOG(IPU3Awb, Debug) << "Grey world AWB";
>  	/*
> @@ -260,7 +260,7 @@ void IPU3Awb::awbGreyWorld()
>  	asyncResults_.blueGain = blueGain;
>  }
>  
> -void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
> +void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>  {
>  	ASSERT(stats->stats_3a_status.awb_en);
>  	zones_.clear();
> @@ -275,7 +275,7 @@ void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>  	}
>  }
>  
> -void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
> +void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>  {
>  	calculateWBGains(stats);
>  	context.frameContext.awb.gains.blueGain = asyncResults_.blueGain;
> @@ -283,7 +283,7 @@ void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>  	context.frameContext.awb.gains.redGain = asyncResults_.redGain;
>  }
>  
> -void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
> +void Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
>  {
>  	params.use.acc_awb = 1;
>  	params.acc_param.awb.config.rgbs_thr_gr = 8191;
> @@ -327,6 +327,6 @@ void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
>  	params.acc_param.ccm = imguCssCcmDefault;
>  }
>  
> -} /* namespace ipa::ipu3 */
> +} /* namespace ipa::ipu3::algorithms */
>  
>  } /* namespace libcamera */
> diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/algorithms/awb.h
> similarity index 84%
> rename from src/ipa/ipu3/ipu3_awb.h
> rename to src/ipa/ipu3/algorithms/awb.h
> index 4de3fae2..ad640521 100644
> --- a/src/ipa/ipu3/ipu3_awb.h
> +++ b/src/ipa/ipu3/algorithms/awb.h
> @@ -2,10 +2,10 @@
>  /*
>   * Copyright (C) 2021, Ideas On Board
>   *
> - * ipu3_awb.h - IPU3 AWB control algorithm
> + * awb.h - IPU3 AWB control algorithm
>   */
> -#ifndef __LIBCAMERA_IPU3_AWB_H__
> -#define __LIBCAMERA_IPU3_AWB_H__
> +#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
> +#define __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
>  
>  #include <vector>
>  
> @@ -13,21 +13,21 @@
>  
>  #include <libcamera/geometry.h>
>  
> -#include "algorithms/algorithm.h"
> +#include "algorithm.h"
>  
>  namespace libcamera {
>  
> -namespace ipa::ipu3 {
> +namespace ipa::ipu3::algorithms {
>  
>  /* Region size for the statistics generation algorithm */
>  static constexpr uint32_t kAwbStatsSizeX = 16;
>  static constexpr uint32_t kAwbStatsSizeY = 12;
>  
> -class IPU3Awb : public Algorithm
> +class Awb : public Algorithm
>  {
>  public:
> -	IPU3Awb();
> -	~IPU3Awb();
> +	Awb();
> +	~Awb();
>  
>  	void prepare(IPAContext &context, ipu3_uapi_params &params) override;
>  	void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;
> @@ -85,7 +85,7 @@ private:
>  	AwbStatus asyncResults_;
>  };
>  
> -} /* namespace ipa::ipu3 */
> +} /* namespace ipa::ipu3::algorithms */
>  
>  } /* namespace libcamera*/
> -#endif /* __LIBCAMERA_IPU3_AWB_H__ */
> +#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__ */
> diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build
> index 69a59096..9ef2dd41 100644
> --- a/src/ipa/ipu3/algorithms/meson.build
> +++ b/src/ipa/ipu3/algorithms/meson.build
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: CC0-1.0
>  
>  ipu3_ipa_algorithms = files([
> +    'awb.cpp',
>      'contrast.cpp',
>      'grid.cpp',
>  ])
> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> index 27765aa6..bea2a372 100644
> --- a/src/ipa/ipu3/ipu3.cpp
> +++ b/src/ipa/ipu3/ipu3.cpp
> @@ -30,10 +30,10 @@
>  #include "libcamera/internal/mapped_framebuffer.h"
>  
>  #include "algorithms/algorithm.h"
> +#include "algorithms/awb.h"
>  #include "algorithms/contrast.h"
>  #include "algorithms/grid.h"
>  #include "ipu3_agc.h"
> -#include "ipu3_awb.h"
>  #include "libipa/camera_sensor_helper.h"
>  
>  namespace libcamera {
> @@ -84,8 +84,6 @@ private:
>  	uint32_t minGain_;
>  	uint32_t maxGain_;
>  
> -	/* Interface to the AWB algorithm */
> -	std::unique_ptr<IPU3Awb> awbAlgo_;
>  	/* Interface to the AEC/AGC algorithm */
>  	std::unique_ptr<IPU3Agc> agcAlgo_;
>  	/* Interface to the Camera Helper */
> @@ -168,6 +166,8 @@ int IPAIPU3::init(const IPASettings &settings,
>  	*ipaControls = ControlInfoMap(std::move(controls), controls::controls);
>  	/* Construct our Algorithms */
>  	algorithms_.emplace_back(new algorithms::Grid());
> +	/* Grid needs to be prepared before AWB */
> +	algorithms_.emplace_back(new algorithms::Awb());
>  	algorithms_.emplace_back(new algorithms::Contrast());
>  
>  	return 0;
> @@ -229,8 +229,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)
>  			return ret;
>  	}
>  
> -	awbAlgo_ = std::make_unique<IPU3Awb>();
> -
>  	agcAlgo_ = std::make_unique<IPU3Agc>();
>  	agcAlgo_->configure(context_, configInfo);
>  
> @@ -309,8 +307,6 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)
>  	for (auto const &algo : algorithms_)
>  		algo->prepare(context_, params_);
>  
> -	awbAlgo_->prepare(context_, params_);
> -
>  	*params = params_;
>  
>  	IPU3Action op;
> @@ -335,8 +331,6 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>  	gain = context_.frameContext.agc.gain;
>  	gain_ = camHelper_->gainCode(gain);
>  
> -	awbAlgo_->process(context_, stats);
> -
>  	setControls(frame);
>  
>  	/* \todo Use VBlank value calculated from each frame exposure. */
> diff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build
> index fcb27d68..d1126947 100644
> --- a/src/ipa/ipu3/meson.build
> +++ b/src/ipa/ipu3/meson.build
> @@ -7,7 +7,6 @@ ipa_name = 'ipa_ipu3'
>  ipu3_ipa_sources = files([
>      'ipu3.cpp',
>      'ipu3_agc.cpp',
> -    'ipu3_awb.cpp',
>  ])
>  
>  ipu3_ipa_sources += ipu3_ipa_algorithms

Patch
diff mbox series

diff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
similarity index 94%
rename from src/ipa/ipu3/ipu3_awb.cpp
rename to src/ipa/ipu3/algorithms/awb.cpp
index b422b095..0f401d6d 100644
--- a/src/ipa/ipu3/ipu3_awb.cpp
+++ b/src/ipa/ipu3/algorithms/awb.cpp
@@ -2,9 +2,9 @@ 
 /*
  * Copyright (C) 2021, Ideas On Board
  *
- * ipu3_awb.cpp - AWB control algorithm
+ * awb.cpp - AWB control algorithm
  */
-#include "ipu3_awb.h"
+#include "awb.h"
 
 #include <algorithm>
 #include <cmath>
@@ -13,7 +13,7 @@ 
 
 namespace libcamera {
 
-namespace ipa::ipu3 {
+namespace ipa::ipu3::algorithms {
 
 LOG_DEFINE_CATEGORY(IPU3Awb)
 
@@ -114,7 +114,7 @@  static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {
 	0, 0, 8191, 0
 };
 
-IPU3Awb::IPU3Awb()
+Awb::Awb()
 	: Algorithm()
 {
 	asyncResults_.blueGain = 1.0;
@@ -125,7 +125,7 @@  IPU3Awb::IPU3Awb()
 	zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);
 }
 
-IPU3Awb::~IPU3Awb()
+Awb::~Awb()
 {
 }
 
@@ -143,7 +143,7 @@  IPU3Awb::~IPU3Awb()
  * More detailed information can be found in:
  * https://en.wikipedia.org/wiki/Color_temperature#Approximation
  */
-uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
+uint32_t Awb::estimateCCT(double red, double green, double blue)
 {
 	/* Convert the RGB values to CIE tristimulus values (XYZ) */
 	double X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue);
@@ -160,7 +160,7 @@  uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)
 }
 
 /* Generate an RGB vector with the average values for each region */
-void IPU3Awb::generateZones(std::vector<RGB> &zones)
+void Awb::generateZones(std::vector<RGB> &zones)
 {
 	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
 		RGB zone;
@@ -177,7 +177,7 @@  void IPU3Awb::generateZones(std::vector<RGB> &zones)
 }
 
 /* Translate the IPU3 statistics into the default statistics region array */
-void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
+void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
 {
 	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
 	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
@@ -209,7 +209,7 @@  void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
 	}
 }
 
-void IPU3Awb::clearAwbStats()
+void Awb::clearAwbStats()
 {
 	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
 		awbStats_[i].bSum = 0;
@@ -220,7 +220,7 @@  void IPU3Awb::clearAwbStats()
 	}
 }
 
-void IPU3Awb::awbGreyWorld()
+void Awb::awbGreyWorld()
 {
 	LOG(IPU3Awb, Debug) << "Grey world AWB";
 	/*
@@ -260,7 +260,7 @@  void IPU3Awb::awbGreyWorld()
 	asyncResults_.blueGain = blueGain;
 }
 
-void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
+void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
 {
 	ASSERT(stats->stats_3a_status.awb_en);
 	zones_.clear();
@@ -275,7 +275,7 @@  void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
 	}
 }
 
-void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
+void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
 {
 	calculateWBGains(stats);
 	context.frameContext.awb.gains.blueGain = asyncResults_.blueGain;
@@ -283,7 +283,7 @@  void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
 	context.frameContext.awb.gains.redGain = asyncResults_.redGain;
 }
 
-void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
+void Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
 {
 	params.use.acc_awb = 1;
 	params.acc_param.awb.config.rgbs_thr_gr = 8191;
@@ -327,6 +327,6 @@  void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)
 	params.acc_param.ccm = imguCssCcmDefault;
 }
 
-} /* namespace ipa::ipu3 */
+} /* namespace ipa::ipu3::algorithms */
 
 } /* namespace libcamera */
diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/algorithms/awb.h
similarity index 84%
rename from src/ipa/ipu3/ipu3_awb.h
rename to src/ipa/ipu3/algorithms/awb.h
index 4de3fae2..ad640521 100644
--- a/src/ipa/ipu3/ipu3_awb.h
+++ b/src/ipa/ipu3/algorithms/awb.h
@@ -2,10 +2,10 @@ 
 /*
  * Copyright (C) 2021, Ideas On Board
  *
- * ipu3_awb.h - IPU3 AWB control algorithm
+ * awb.h - IPU3 AWB control algorithm
  */
-#ifndef __LIBCAMERA_IPU3_AWB_H__
-#define __LIBCAMERA_IPU3_AWB_H__
+#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
+#define __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
 
 #include <vector>
 
@@ -13,21 +13,21 @@ 
 
 #include <libcamera/geometry.h>
 
-#include "algorithms/algorithm.h"
+#include "algorithm.h"
 
 namespace libcamera {
 
-namespace ipa::ipu3 {
+namespace ipa::ipu3::algorithms {
 
 /* Region size for the statistics generation algorithm */
 static constexpr uint32_t kAwbStatsSizeX = 16;
 static constexpr uint32_t kAwbStatsSizeY = 12;
 
-class IPU3Awb : public Algorithm
+class Awb : public Algorithm
 {
 public:
-	IPU3Awb();
-	~IPU3Awb();
+	Awb();
+	~Awb();
 
 	void prepare(IPAContext &context, ipu3_uapi_params &params) override;
 	void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;
@@ -85,7 +85,7 @@  private:
 	AwbStatus asyncResults_;
 };
 
-} /* namespace ipa::ipu3 */
+} /* namespace ipa::ipu3::algorithms */
 
 } /* namespace libcamera*/
-#endif /* __LIBCAMERA_IPU3_AWB_H__ */
+#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__ */
diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build
index 69a59096..9ef2dd41 100644
--- a/src/ipa/ipu3/algorithms/meson.build
+++ b/src/ipa/ipu3/algorithms/meson.build
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: CC0-1.0
 
 ipu3_ipa_algorithms = files([
+    'awb.cpp',
     'contrast.cpp',
     'grid.cpp',
 ])
diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
index 27765aa6..bea2a372 100644
--- a/src/ipa/ipu3/ipu3.cpp
+++ b/src/ipa/ipu3/ipu3.cpp
@@ -30,10 +30,10 @@ 
 #include "libcamera/internal/mapped_framebuffer.h"
 
 #include "algorithms/algorithm.h"
+#include "algorithms/awb.h"
 #include "algorithms/contrast.h"
 #include "algorithms/grid.h"
 #include "ipu3_agc.h"
-#include "ipu3_awb.h"
 #include "libipa/camera_sensor_helper.h"
 
 namespace libcamera {
@@ -84,8 +84,6 @@  private:
 	uint32_t minGain_;
 	uint32_t maxGain_;
 
-	/* Interface to the AWB algorithm */
-	std::unique_ptr<IPU3Awb> awbAlgo_;
 	/* Interface to the AEC/AGC algorithm */
 	std::unique_ptr<IPU3Agc> agcAlgo_;
 	/* Interface to the Camera Helper */
@@ -168,6 +166,8 @@  int IPAIPU3::init(const IPASettings &settings,
 	*ipaControls = ControlInfoMap(std::move(controls), controls::controls);
 	/* Construct our Algorithms */
 	algorithms_.emplace_back(new algorithms::Grid());
+	/* Grid needs to be prepared before AWB */
+	algorithms_.emplace_back(new algorithms::Awb());
 	algorithms_.emplace_back(new algorithms::Contrast());
 
 	return 0;
@@ -229,8 +229,6 @@  int IPAIPU3::configure(const IPAConfigInfo &configInfo)
 			return ret;
 	}
 
-	awbAlgo_ = std::make_unique<IPU3Awb>();
-
 	agcAlgo_ = std::make_unique<IPU3Agc>();
 	agcAlgo_->configure(context_, configInfo);
 
@@ -309,8 +307,6 @@  void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)
 	for (auto const &algo : algorithms_)
 		algo->prepare(context_, params_);
 
-	awbAlgo_->prepare(context_, params_);
-
 	*params = params_;
 
 	IPU3Action op;
@@ -335,8 +331,6 @@  void IPAIPU3::parseStatistics(unsigned int frame,
 	gain = context_.frameContext.agc.gain;
 	gain_ = camHelper_->gainCode(gain);
 
-	awbAlgo_->process(context_, stats);
-
 	setControls(frame);
 
 	/* \todo Use VBlank value calculated from each frame exposure. */
diff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build
index fcb27d68..d1126947 100644
--- a/src/ipa/ipu3/meson.build
+++ b/src/ipa/ipu3/meson.build
@@ -7,7 +7,6 @@  ipa_name = 'ipa_ipu3'
 ipu3_ipa_sources = files([
     'ipu3.cpp',
     'ipu3_agc.cpp',
-    'ipu3_awb.cpp',
 ])
 
 ipu3_ipa_sources += ipu3_ipa_algorithms