[libcamera-devel,v1,2/2] ipa: ipu3: awb: remove local storage of the grid
diff mbox series

Message ID 20210820121149.85859-3-jeanmichel.hautbois@ideasonboard.com
State Accepted
Headers show
Series
  • Remove local storage of the grid in algorithms
Related show

Commit Message

Jean-Michel Hautbois Aug. 20, 2021, 12:11 p.m. UTC
The IPASessionConfiguration now has the grid configuration stored. Use
it it at prepare() and process() calls in AWB and pass it as a reference
to the private functions when needed.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/awb.cpp | 29 ++++++++++++++++-------------
 src/ipa/ipu3/algorithms/awb.h   |  8 ++++----
 2 files changed, 20 insertions(+), 17 deletions(-)

Comments

Laurent Pinchart Aug. 20, 2021, 1:08 p.m. UTC | #1
Hi Jean-Michel,

Thank you for the patch.

On Fri, Aug 20, 2021 at 02:11:49PM +0200, Jean-Michel Hautbois wrote:
> The IPASessionConfiguration now has the grid configuration stored. Use
> it it at prepare() and process() calls in AWB and pass it as a reference
> to the private functions when needed.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  src/ipa/ipu3/algorithms/awb.cpp | 29 ++++++++++++++++-------------
>  src/ipa/ipu3/algorithms/awb.h   |  8 ++++----
>  2 files changed, 20 insertions(+), 17 deletions(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> index e15f7406..72ec5f88 100644
> --- a/src/ipa/ipu3/algorithms/awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -175,20 +175,21 @@ void Awb::generateZones(std::vector<RGB> &zones)
>  }
>  
>  /* Translate the IPU3 statistics into the default statistics region array */
> -void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
> +void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
> +			   struct ipu3_uapi_grid_config &grid)

This should be const.

>  {
> -	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
> -	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
> +	uint32_t regionWidth = round(grid.width / static_cast<double>(kAwbStatsSizeX));
> +	uint32_t regionHeight = round(grid.height / static_cast<double>(kAwbStatsSizeY));
>  
>  	/*
>  	 * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is
> -	 * (awbGrid_.width x awbGrid_.height).
> +	 * (grid.width x grid.height).
>  	 */
>  	for (unsigned int j = 0; j < kAwbStatsSizeY * regionHeight; j++) {
>  		for (unsigned int i = 0; i < kAwbStatsSizeX * regionWidth; i++) {
> -			uint32_t cellPosition = j * awbGrid_.width + i;
> +			uint32_t cellPosition = j * grid.width + i;
>  			uint32_t cellX = (cellPosition / regionWidth) % kAwbStatsSizeX;
> -			uint32_t cellY = ((cellPosition / awbGrid_.width) / regionHeight) % kAwbStatsSizeY;
> +			uint32_t cellY = ((cellPosition / grid.width) / regionHeight) % kAwbStatsSizeY;
>  
>  			uint32_t awbRegionPosition = cellY * kAwbStatsSizeX + cellX;
>  			cellPosition *= 8;
> @@ -258,12 +259,13 @@ void Awb::awbGreyWorld()
>  	asyncResults_.blueGain = blueGain;
>  }
>  
> -void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
> +void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats,
> +			   struct ipu3_uapi_grid_config &grid)

Here too.

>  {
>  	ASSERT(stats->stats_3a_status.awb_en);
>  	zones_.clear();
>  	clearAwbStats();
> -	generateAwbStats(stats);
> +	generateAwbStats(stats, grid);
>  	generateZones(zones_);
>  	LOG(IPU3Awb, Debug) << "Valid zones: " << zones_.size();
>  	if (zones_.size() > 10) {
> @@ -275,7 +277,8 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>  
>  void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>  {
> -	calculateWBGains(stats);
> +	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;
> +	calculateWBGains(stats, grid);
>  
>  	/*
>  	 * Gains are only recalculated if enough zones were detected.
> @@ -296,9 +299,9 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
>  					       | IPU3_UAPI_AWB_RGBS_THR_B_EN
>  					       | 8191;
>  
> -	awbGrid_ = context.configuration.grid.bdsGrid;
> +	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;

Why do you need to make a copy of the grid ?

>  
> -	params->acc_param.awb.config.grid = context.configuration.grid.bdsGrid;
> +	params->acc_param.awb.config.grid = grid;

This doesn't seem needed.

>  
>  	/*
>  	 * Optical center is column start (respectively row start) of the
> @@ -310,8 +313,8 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
>  	params->acc_param.bnr = imguCssBnrDefaults;
>  	Size &bdsOutputSize = context.configuration.grid.bdsOutputSize;
>  	params->acc_param.bnr.column_size = bdsOutputSize.width;
> -	params->acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2);
> -	params->acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2);
> +	params->acc_param.bnr.opt_center.x_reset = grid.x_start - (bdsOutputSize.width / 2);
> +	params->acc_param.bnr.opt_center.y_reset = grid.y_start - (bdsOutputSize.height / 2);
>  	params->acc_param.bnr.opt_center_sqr.x_sqr_reset = params->acc_param.bnr.opt_center.x_reset
>  							* params->acc_param.bnr.opt_center.x_reset;
>  	params->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset
> diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
> index fac54e45..3807cc14 100644
> --- a/src/ipa/ipu3/algorithms/awb.h
> +++ b/src/ipa/ipu3/algorithms/awb.h
> @@ -71,15 +71,15 @@ public:
>  	};
>  
>  private:
> -	void calculateWBGains(const ipu3_uapi_stats_3a *stats);
> +	void calculateWBGains(const ipu3_uapi_stats_3a *stats,
> +			      struct ipu3_uapi_grid_config &grid);
>  	void generateZones(std::vector<RGB> &zones);
> -	void generateAwbStats(const ipu3_uapi_stats_3a *stats);
> +	void generateAwbStats(const ipu3_uapi_stats_3a *stats,
> +			      struct ipu3_uapi_grid_config &grid);
>  	void clearAwbStats();
>  	void awbGreyWorld();
>  	uint32_t estimateCCT(double red, double green, double blue);
>  
> -	struct ipu3_uapi_grid_config awbGrid_;
> -
>  	std::vector<RGB> zones_;
>  	IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
>  	AwbStatus asyncResults_;
Jean-Michel Hautbois Aug. 20, 2021, 2:07 p.m. UTC | #2
On 20/08/2021 15:08, Laurent Pinchart wrote:
> Hi Jean-Michel,
> 
> Thank you for the patch.
> 
> On Fri, Aug 20, 2021 at 02:11:49PM +0200, Jean-Michel Hautbois wrote:
>> The IPASessionConfiguration now has the grid configuration stored. Use
>> it it at prepare() and process() calls in AWB and pass it as a reference
>> to the private functions when needed.
>>
>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>> ---
>>  src/ipa/ipu3/algorithms/awb.cpp | 29 ++++++++++++++++-------------
>>  src/ipa/ipu3/algorithms/awb.h   |  8 ++++----
>>  2 files changed, 20 insertions(+), 17 deletions(-)
>>
>> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
>> index e15f7406..72ec5f88 100644
>> --- a/src/ipa/ipu3/algorithms/awb.cpp
>> +++ b/src/ipa/ipu3/algorithms/awb.cpp
>> @@ -175,20 +175,21 @@ void Awb::generateZones(std::vector<RGB> &zones)
>>  }
>>  
>>  /* Translate the IPU3 statistics into the default statistics region array */
>> -void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
>> +void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
>> +			   struct ipu3_uapi_grid_config &grid)
> 
> This should be const.
> 
>>  {
>> -	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
>> -	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
>> +	uint32_t regionWidth = round(grid.width / static_cast<double>(kAwbStatsSizeX));
>> +	uint32_t regionHeight = round(grid.height / static_cast<double>(kAwbStatsSizeY));
>>  
>>  	/*
>>  	 * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is
>> -	 * (awbGrid_.width x awbGrid_.height).
>> +	 * (grid.width x grid.height).
>>  	 */
>>  	for (unsigned int j = 0; j < kAwbStatsSizeY * regionHeight; j++) {
>>  		for (unsigned int i = 0; i < kAwbStatsSizeX * regionWidth; i++) {
>> -			uint32_t cellPosition = j * awbGrid_.width + i;
>> +			uint32_t cellPosition = j * grid.width + i;
>>  			uint32_t cellX = (cellPosition / regionWidth) % kAwbStatsSizeX;
>> -			uint32_t cellY = ((cellPosition / awbGrid_.width) / regionHeight) % kAwbStatsSizeY;
>> +			uint32_t cellY = ((cellPosition / grid.width) / regionHeight) % kAwbStatsSizeY;
>>  
>>  			uint32_t awbRegionPosition = cellY * kAwbStatsSizeX + cellX;
>>  			cellPosition *= 8;
>> @@ -258,12 +259,13 @@ void Awb::awbGreyWorld()
>>  	asyncResults_.blueGain = blueGain;
>>  }
>>  
>> -void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>> +void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats,
>> +			   struct ipu3_uapi_grid_config &grid)
> 
> Here too.
> 
>>  {
>>  	ASSERT(stats->stats_3a_status.awb_en);
>>  	zones_.clear();
>>  	clearAwbStats();
>> -	generateAwbStats(stats);
>> +	generateAwbStats(stats, grid);
>>  	generateZones(zones_);
>>  	LOG(IPU3Awb, Debug) << "Valid zones: " << zones_.size();
>>  	if (zones_.size() > 10) {
>> @@ -275,7 +277,8 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
>>  
>>  void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
>>  {
>> -	calculateWBGains(stats);
>> +	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;
>> +	calculateWBGains(stats, grid);
>>  
>>  	/*
>>  	 * Gains are only recalculated if enough zones were detected.
>> @@ -296,9 +299,9 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
>>  					       | IPU3_UAPI_AWB_RGBS_THR_B_EN
>>  					       | 8191;
>>  
>> -	awbGrid_ = context.configuration.grid.bdsGrid;
>> +	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;
> 
> Why do you need to make a copy of the grid ?
> 
>>  
>> -	params->acc_param.awb.config.grid = context.configuration.grid.bdsGrid;
>> +	params->acc_param.awb.config.grid = grid;
> 
> This doesn't seem needed.

The hunk you mean ? Because I need to copy the grid :-) but only in params.

>>  
>>  	/*
>>  	 * Optical center is column start (respectively row start) of the
>> @@ -310,8 +313,8 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
>>  	params->acc_param.bnr = imguCssBnrDefaults;
>>  	Size &bdsOutputSize = context.configuration.grid.bdsOutputSize;
>>  	params->acc_param.bnr.column_size = bdsOutputSize.width;
>> -	params->acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2);
>> -	params->acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2);
>> +	params->acc_param.bnr.opt_center.x_reset = grid.x_start - (bdsOutputSize.width / 2);
>> +	params->acc_param.bnr.opt_center.y_reset = grid.y_start - (bdsOutputSize.height / 2);
>>  	params->acc_param.bnr.opt_center_sqr.x_sqr_reset = params->acc_param.bnr.opt_center.x_reset
>>  							* params->acc_param.bnr.opt_center.x_reset;
>>  	params->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset
>> diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
>> index fac54e45..3807cc14 100644
>> --- a/src/ipa/ipu3/algorithms/awb.h
>> +++ b/src/ipa/ipu3/algorithms/awb.h
>> @@ -71,15 +71,15 @@ public:
>>  	};
>>  
>>  private:
>> -	void calculateWBGains(const ipu3_uapi_stats_3a *stats);
>> +	void calculateWBGains(const ipu3_uapi_stats_3a *stats,
>> +			      struct ipu3_uapi_grid_config &grid);
>>  	void generateZones(std::vector<RGB> &zones);
>> -	void generateAwbStats(const ipu3_uapi_stats_3a *stats);
>> +	void generateAwbStats(const ipu3_uapi_stats_3a *stats,
>> +			      struct ipu3_uapi_grid_config &grid);
>>  	void clearAwbStats();
>>  	void awbGreyWorld();
>>  	uint32_t estimateCCT(double red, double green, double blue);
>>  
>> -	struct ipu3_uapi_grid_config awbGrid_;
>> -
>>  	std::vector<RGB> zones_;
>>  	IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
>>  	AwbStatus asyncResults_;
>

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
index e15f7406..72ec5f88 100644
--- a/src/ipa/ipu3/algorithms/awb.cpp
+++ b/src/ipa/ipu3/algorithms/awb.cpp
@@ -175,20 +175,21 @@  void Awb::generateZones(std::vector<RGB> &zones)
 }
 
 /* Translate the IPU3 statistics into the default statistics region array */
-void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)
+void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
+			   struct ipu3_uapi_grid_config &grid)
 {
-	uint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));
-	uint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));
+	uint32_t regionWidth = round(grid.width / static_cast<double>(kAwbStatsSizeX));
+	uint32_t regionHeight = round(grid.height / static_cast<double>(kAwbStatsSizeY));
 
 	/*
 	 * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is
-	 * (awbGrid_.width x awbGrid_.height).
+	 * (grid.width x grid.height).
 	 */
 	for (unsigned int j = 0; j < kAwbStatsSizeY * regionHeight; j++) {
 		for (unsigned int i = 0; i < kAwbStatsSizeX * regionWidth; i++) {
-			uint32_t cellPosition = j * awbGrid_.width + i;
+			uint32_t cellPosition = j * grid.width + i;
 			uint32_t cellX = (cellPosition / regionWidth) % kAwbStatsSizeX;
-			uint32_t cellY = ((cellPosition / awbGrid_.width) / regionHeight) % kAwbStatsSizeY;
+			uint32_t cellY = ((cellPosition / grid.width) / regionHeight) % kAwbStatsSizeY;
 
 			uint32_t awbRegionPosition = cellY * kAwbStatsSizeX + cellX;
 			cellPosition *= 8;
@@ -258,12 +259,13 @@  void Awb::awbGreyWorld()
 	asyncResults_.blueGain = blueGain;
 }
 
-void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
+void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats,
+			   struct ipu3_uapi_grid_config &grid)
 {
 	ASSERT(stats->stats_3a_status.awb_en);
 	zones_.clear();
 	clearAwbStats();
-	generateAwbStats(stats);
+	generateAwbStats(stats, grid);
 	generateZones(zones_);
 	LOG(IPU3Awb, Debug) << "Valid zones: " << zones_.size();
 	if (zones_.size() > 10) {
@@ -275,7 +277,8 @@  void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)
 
 void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)
 {
-	calculateWBGains(stats);
+	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;
+	calculateWBGains(stats, grid);
 
 	/*
 	 * Gains are only recalculated if enough zones were detected.
@@ -296,9 +299,9 @@  void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
 					       | IPU3_UAPI_AWB_RGBS_THR_B_EN
 					       | 8191;
 
-	awbGrid_ = context.configuration.grid.bdsGrid;
+	struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid;
 
-	params->acc_param.awb.config.grid = context.configuration.grid.bdsGrid;
+	params->acc_param.awb.config.grid = grid;
 
 	/*
 	 * Optical center is column start (respectively row start) of the
@@ -310,8 +313,8 @@  void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)
 	params->acc_param.bnr = imguCssBnrDefaults;
 	Size &bdsOutputSize = context.configuration.grid.bdsOutputSize;
 	params->acc_param.bnr.column_size = bdsOutputSize.width;
-	params->acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2);
-	params->acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2);
+	params->acc_param.bnr.opt_center.x_reset = grid.x_start - (bdsOutputSize.width / 2);
+	params->acc_param.bnr.opt_center.y_reset = grid.y_start - (bdsOutputSize.height / 2);
 	params->acc_param.bnr.opt_center_sqr.x_sqr_reset = params->acc_param.bnr.opt_center.x_reset
 							* params->acc_param.bnr.opt_center.x_reset;
 	params->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset
diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
index fac54e45..3807cc14 100644
--- a/src/ipa/ipu3/algorithms/awb.h
+++ b/src/ipa/ipu3/algorithms/awb.h
@@ -71,15 +71,15 @@  public:
 	};
 
 private:
-	void calculateWBGains(const ipu3_uapi_stats_3a *stats);
+	void calculateWBGains(const ipu3_uapi_stats_3a *stats,
+			      struct ipu3_uapi_grid_config &grid);
 	void generateZones(std::vector<RGB> &zones);
-	void generateAwbStats(const ipu3_uapi_stats_3a *stats);
+	void generateAwbStats(const ipu3_uapi_stats_3a *stats,
+			      struct ipu3_uapi_grid_config &grid);
 	void clearAwbStats();
 	void awbGreyWorld();
 	uint32_t estimateCCT(double red, double green, double blue);
 
-	struct ipu3_uapi_grid_config awbGrid_;
-
 	std::vector<RGB> zones_;
 	IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];
 	AwbStatus asyncResults_;