[libcamera-devel] ipa: ipu3: awb: Clamp gain values
diff mbox series

Message ID 20220311131929.506764-1-umang.jain@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] ipa: ipu3: awb: Clamp gain values
Related show

Commit Message

Umang Jain March 11, 2022, 1:19 p.m. UTC
From: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

The gain values are coded as u3.13 fixed point values, ie they can not
be more than 8. Clamp the values in order to avoid any off limits value
which could make the IPU3 behave in a weird manner.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/awb.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Nicolas Dufresne via libcamera-devel March 11, 2022, 1:21 p.m. UTC | #1
Hello,

On 3/11/22 18:49, Umang Jain wrote:
> From: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>
> The gain values are coded as u3.13 fixed point values, ie they can not
> be more than 8. Clamp the values in order to avoid any off limits value
> which could make the IPU3 behave in a weird manner.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>


Fixed up the (minor comments) and discussed with Kieran .

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   src/ipa/ipu3/algorithms/awb.cpp | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> index 1dc27fc9..dc25be81 100644
> --- a/src/ipa/ipu3/algorithms/awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -353,6 +353,14 @@ void Awb::awbGreyWorld()
>   
>   	/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */
>   	asyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);
> +
> +	/*
> +	 * Gain values are unsigned integer value, range 0 to 8 with 13 bit
> +	 * fractional part.
> +	 */
> +	redGain = std::clamp(redGain, 0.0, 65535.0 / 8192);
> +	blueGain = std::clamp(blueGain, 0.0, 65535.0 / 8192);
> +
>   	asyncResults_.redGain = redGain;
>   	/* Hardcode the green gain to 1.0. */
>   	asyncResults_.greenGain = 1.0;
Nicolas Dufresne via libcamera-devel March 11, 2022, 1:33 p.m. UTC | #2
On 3/11/22 18:49, Umang Jain wrote:
> From: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>
> The gain values are coded as u3.13 fixed point values, ie they can not
> be more than 8. Clamp the values in order to avoid any off limits value
> which could make the IPU3 behave in a weird manner.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   src/ipa/ipu3/algorithms/awb.cpp | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
> index 1dc27fc9..dc25be81 100644
> --- a/src/ipa/ipu3/algorithms/awb.cpp
> +++ b/src/ipa/ipu3/algorithms/awb.cpp
> @@ -353,6 +353,14 @@ void Awb::awbGreyWorld()
>   
>   	/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */
>   	asyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);
> +
> +	/*
> +	 * Gain values are unsigned integer value, range 0 to 8 with 13 bit
> +	 * fractional part.


Great, I forgot to squash the changes and re-group the commit :-/

sending again :(


> +	 */
> +	redGain = std::clamp(redGain, 0.0, 65535.0 / 8192);
> +	blueGain = std::clamp(blueGain, 0.0, 65535.0 / 8192);
> +
>   	asyncResults_.redGain = redGain;
>   	/* Hardcode the green gain to 1.0. */
>   	asyncResults_.greenGain = 1.0;

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp
index 1dc27fc9..dc25be81 100644
--- a/src/ipa/ipu3/algorithms/awb.cpp
+++ b/src/ipa/ipu3/algorithms/awb.cpp
@@ -353,6 +353,14 @@  void Awb::awbGreyWorld()
 
 	/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */
 	asyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);
+
+	/*
+	 * Gain values are unsigned integer value, range 0 to 8 with 13 bit
+	 * fractional part.
+	 */
+	redGain = std::clamp(redGain, 0.0, 65535.0 / 8192);
+	blueGain = std::clamp(blueGain, 0.0, 65535.0 / 8192);
+
 	asyncResults_.redGain = redGain;
 	/* Hardcode the green gain to 1.0. */
 	asyncResults_.greenGain = 1.0;