[libcamera-devel,4/4] ipa: ipu3: Change Accumulator structure layout
diff mbox series

Message ID 20210902083207.33976-5-jeanmichel.hautbois@ideasonboard.com
State Superseded
Headers show
Series
  • Move and improve AWB structures
Related show

Commit Message

Jean-Michel Hautbois Sept. 2, 2021, 8:32 a.m. UTC
The red, green and blue sums should follow the same philosophy as the
IPAFrameContext::awb structure. Change the red, green and blue sums to
uint64_t which is better as it does not depend on the architecture.

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

Comments

Kieran Bingham Sept. 2, 2021, 12:42 p.m. UTC | #1
On 02/09/2021 09:32, Jean-Michel Hautbois wrote:
> The red, green and blue sums should follow the same philosophy as the
> IPAFrameContext::awb structure.

"""
The pixel component sums for the Accumulator are inconsistent with other
similar structures such as the IPAFrameContext::awb::gains.
"""

> Change the red, green and blue sums to
> uint64_t which is better as it does not depend on the architecture.
"""
Group the red, green, and blue sums together in a struct and store them
as uint64_t to reduce potential architectural differences.
"""

Take anything you prefer.

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


> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  src/ipa/ipu3/algorithms/awb.cpp | 24 ++++++++++++------------
>  src/ipa/ipu3/algorithms/awb.h   |  8 +++++---
>  2 files changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> index 9b2cbba7..ea567f96 100644
> --- a/src/ipa/ipu3/algorithms/awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -41,13 +41,13 @@ static constexpr uint32_t kMinGreenLevelInZone = 32;
>   * \var Accumulator::total
>   * \brief Total number of regions in the zone
>   *
> - * \var Accumulator::rSum
> + * \var Accumulator::sum::red
>   * \brief Sum of the red values in the zone
>   *
> - * \var Accumulator::gSum
> + * \var Accumulator::sum::green
>   * \brief Sum of the green values in the zone
>   *
> - * \var Accumulator::bSum
> + * \var Accumulator::sum::blue
>   * \brief Sum of the blue values in the zone
>   */
>  
> @@ -172,10 +172,10 @@ void Awb::generateZones(std::vector<RGB> &zones)
>  		RGB zone;
>  		double counted = awbStats_[i].counted;
>  		if (counted >= kMinZonesCounted) {
> -			zone.G = awbStats_[i].gSum / counted;
> +			zone.G = awbStats_[i].sum.green / counted;
>  			if (zone.G >= kMinGreenLevelInZone) {
> -				zone.R = awbStats_[i].rSum / counted;
> -				zone.B = awbStats_[i].bSum / counted;
> +				zone.R = awbStats_[i].sum.red / counted;
> +				zone.B = awbStats_[i].sum.blue / counted;
>  				zones.push_back(zone);
>  			}
>  		}
> @@ -212,9 +212,9 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
>  				/* The cell is not saturated, use the current cell */
>  				awbStats_[awbRegionPosition].counted++;
>  				uint32_t greenValue = currentCell->greenRedAvg + currentCell->greenBlueAvg;
> -				awbStats_[awbRegionPosition].gSum += greenValue / 2;
> -				awbStats_[awbRegionPosition].rSum += currentCell->redAvg;
> -				awbStats_[awbRegionPosition].bSum += currentCell->blueAvg;
> +				awbStats_[awbRegionPosition].sum.green += greenValue / 2;
> +				awbStats_[awbRegionPosition].sum.red += currentCell->redAvg;
> +				awbStats_[awbRegionPosition].sum.blue += currentCell->blueAvg;
>  			}
>  		}
>  	}
> @@ -223,9 +223,9 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
>  void Awb::clearAwbStats()
>  {
>  	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
> -		awbStats_[i].bSum = 0;
> -		awbStats_[i].rSum = 0;
> -		awbStats_[i].gSum = 0;
> +		awbStats_[i].sum.blue = 0;
> +		awbStats_[i].sum.red = 0;
> +		awbStats_[i].sum.green = 0;
>  		awbStats_[i].counted = 0;
>  		awbStats_[i].total = 0;
>  	}
> diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
> index 13490b07..23f3e872 100644
> --- a/src/ipa/ipu3/algorithms/awb.h
> +++ b/src/ipa/ipu3/algorithms/awb.h
> @@ -36,9 +36,11 @@ struct Ipu3AwbCell {
>  struct Accumulator {
>  	unsigned int counted;
>  	unsigned int total;
> -	unsigned long long rSum;
> -	unsigned long long gSum;
> -	unsigned long long bSum;
> +	struct {
> +		uint64_t red;
> +		uint64_t green;
> +		uint64_t blue;
> +	} sum;
>  };
>  
>  class Awb : public Algorithm
>

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
index 9b2cbba7..ea567f96 100644
--- a/src/ipa/ipu3/algorithms/awb.cpp
+++ b/src/ipa/ipu3/algorithms/awb.cpp
@@ -41,13 +41,13 @@  static constexpr uint32_t kMinGreenLevelInZone = 32;
  * \var Accumulator::total
  * \brief Total number of regions in the zone
  *
- * \var Accumulator::rSum
+ * \var Accumulator::sum::red
  * \brief Sum of the red values in the zone
  *
- * \var Accumulator::gSum
+ * \var Accumulator::sum::green
  * \brief Sum of the green values in the zone
  *
- * \var Accumulator::bSum
+ * \var Accumulator::sum::blue
  * \brief Sum of the blue values in the zone
  */
 
@@ -172,10 +172,10 @@  void Awb::generateZones(std::vector<RGB> &zones)
 		RGB zone;
 		double counted = awbStats_[i].counted;
 		if (counted >= kMinZonesCounted) {
-			zone.G = awbStats_[i].gSum / counted;
+			zone.G = awbStats_[i].sum.green / counted;
 			if (zone.G >= kMinGreenLevelInZone) {
-				zone.R = awbStats_[i].rSum / counted;
-				zone.B = awbStats_[i].bSum / counted;
+				zone.R = awbStats_[i].sum.red / counted;
+				zone.B = awbStats_[i].sum.blue / counted;
 				zones.push_back(zone);
 			}
 		}
@@ -212,9 +212,9 @@  void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
 				/* The cell is not saturated, use the current cell */
 				awbStats_[awbRegionPosition].counted++;
 				uint32_t greenValue = currentCell->greenRedAvg + currentCell->greenBlueAvg;
-				awbStats_[awbRegionPosition].gSum += greenValue / 2;
-				awbStats_[awbRegionPosition].rSum += currentCell->redAvg;
-				awbStats_[awbRegionPosition].bSum += currentCell->blueAvg;
+				awbStats_[awbRegionPosition].sum.green += greenValue / 2;
+				awbStats_[awbRegionPosition].sum.red += currentCell->redAvg;
+				awbStats_[awbRegionPosition].sum.blue += currentCell->blueAvg;
 			}
 		}
 	}
@@ -223,9 +223,9 @@  void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,
 void Awb::clearAwbStats()
 {
 	for (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {
-		awbStats_[i].bSum = 0;
-		awbStats_[i].rSum = 0;
-		awbStats_[i].gSum = 0;
+		awbStats_[i].sum.blue = 0;
+		awbStats_[i].sum.red = 0;
+		awbStats_[i].sum.green = 0;
 		awbStats_[i].counted = 0;
 		awbStats_[i].total = 0;
 	}
diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
index 13490b07..23f3e872 100644
--- a/src/ipa/ipu3/algorithms/awb.h
+++ b/src/ipa/ipu3/algorithms/awb.h
@@ -36,9 +36,11 @@  struct Ipu3AwbCell {
 struct Accumulator {
 	unsigned int counted;
 	unsigned int total;
-	unsigned long long rSum;
-	unsigned long long gSum;
-	unsigned long long bSum;
+	struct {
+		uint64_t red;
+		uint64_t green;
+		uint64_t blue;
+	} sum;
 };
 
 class Awb : public Algorithm