[v6,11/16] ipa: mali-c55: Reduce AWB calculations to float precision
diff mbox series

Message ID 20260121173737.376113-12-kieran.bingham@ideasonboard.com
State New
Headers show
Series
  • libipa: Introduce a Quantized type
Related show

Commit Message

Kieran Bingham Jan. 21, 2026, 5:37 p.m. UTC
The AWB calculations are determined using double precision, and then
will be soon stored in a quantized float.

Use float types for the intermediate types after the sums have been
converted to an average to remove static cast assignments.

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

---
v5:
 - New in v5

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Stefan Klug Jan. 23, 2026, 2:18 p.m. UTC | #1
Quoting Kieran Bingham (2026-01-21 18:37:30)
> The AWB calculations are determined using double precision, and then
> will be soon stored in a quantized float.
> 
> Use float types for the intermediate types after the sums have been
> converted to an average to remove static cast assignments.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> ---
> v5:
>  - New in v5
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/ipa/mali-c55/algorithms/awb.cpp | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp
> index 964e810882a9..b179dd7f0c1c 100644
> --- a/src/ipa/mali-c55/algorithms/awb.cpp
> +++ b/src/ipa/mali-c55/algorithms/awb.cpp
> @@ -159,7 +159,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,
>          * Sometimes the first frame's statistics have no valid pixels, in which
>          * case we'll just assume a grey world until they say otherwise.
>          */
> -       double rgAvg, bgAvg;
> +       float rgAvg, bgAvg;
>         if (!counted_zones) {
>                 rgAvg = 1.0;
>                 bgAvg = 1.0;
> @@ -174,15 +174,15 @@ void Awb::process(IPAContext &context, const uint32_t frame,
>          * figure by the gains that were applied when the statistics for this
>          * frame were generated.
>          */
> -       double rRatio = rgAvg / frameContext.awb.rGain;
> -       double bRatio = bgAvg / frameContext.awb.bGain;
> +       float rRatio = rgAvg / frameContext.awb.rGain;
> +       float bRatio = bgAvg / frameContext.awb.bGain;
>  
>         /*
>          * And then we can simply invert the ratio to find the gain we should
>          * apply.
>          */
> -       double rGain = 1 / rRatio;
> -       double bGain = 1 / bRatio;
> +       float rGain = 1 / rRatio;
> +       float bGain = 1 / bRatio;
>  
>         /*
>          * Running at full speed, this algorithm results in oscillations in the
> @@ -190,7 +190,7 @@ void Awb::process(IPAContext &context, const uint32_t frame,
>          * changes in gain, unless we're in the startup phase in which case we
>          * want to fix the miscolouring as quickly as possible.
>          */
> -       double speed = frame < kNumStartupFrames ? 1.0 : 0.2;
> +       float speed = frame < kNumStartupFrames ? 1.0 : 0.2;
>         rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);
>         bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);

Precision wise this should all be fine. So

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>

Cheers,
Stefan

>  
> -- 
> 2.52.0
>

Patch
diff mbox series

diff --git a/src/ipa/mali-c55/algorithms/awb.cpp b/src/ipa/mali-c55/algorithms/awb.cpp
index 964e810882a9..b179dd7f0c1c 100644
--- a/src/ipa/mali-c55/algorithms/awb.cpp
+++ b/src/ipa/mali-c55/algorithms/awb.cpp
@@ -159,7 +159,7 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * Sometimes the first frame's statistics have no valid pixels, in which
 	 * case we'll just assume a grey world until they say otherwise.
 	 */
-	double rgAvg, bgAvg;
+	float rgAvg, bgAvg;
 	if (!counted_zones) {
 		rgAvg = 1.0;
 		bgAvg = 1.0;
@@ -174,15 +174,15 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * figure by the gains that were applied when the statistics for this
 	 * frame were generated.
 	 */
-	double rRatio = rgAvg / frameContext.awb.rGain;
-	double bRatio = bgAvg / frameContext.awb.bGain;
+	float rRatio = rgAvg / frameContext.awb.rGain;
+	float bRatio = bgAvg / frameContext.awb.bGain;
 
 	/*
 	 * And then we can simply invert the ratio to find the gain we should
 	 * apply.
 	 */
-	double rGain = 1 / rRatio;
-	double bGain = 1 / bRatio;
+	float rGain = 1 / rRatio;
+	float bGain = 1 / bRatio;
 
 	/*
 	 * Running at full speed, this algorithm results in oscillations in the
@@ -190,7 +190,7 @@  void Awb::process(IPAContext &context, const uint32_t frame,
 	 * changes in gain, unless we're in the startup phase in which case we
 	 * want to fix the miscolouring as quickly as possible.
 	 */
-	double speed = frame < kNumStartupFrames ? 1.0 : 0.2;
+	float speed = frame < kNumStartupFrames ? 1.0 : 0.2;
 	rGain = speed * rGain + context.activeState.awb.rGain * (1.0 - speed);
 	bGain = speed * bGain + context.activeState.awb.bGain * (1.0 - speed);