[libcamera-devel] [PATCH 1/2] libipa: Round gain code before returning the value
Kieran Bingham
kieran.bingham at ideasonboard.com
Fri Nov 19 12:11:09 CET 2021
Quoting Jean-Michel Hautbois (2021-11-19 10:25:58)
> We can have the case where the gain is very close to 1, as coded in
> double, and after gainCode() returns, the value as an uint32_t is 0. In
> order to avoid that, always round the value halfway cases away from zero
> before returning.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois at ideasonboard.com>
This seems to make sense.
Are there any issues with other values being rounded? I presume not.
Is there any requirement to further protect or warn if gainCode is
returned as zero? or can that still be valid in some situations?
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> src/ipa/libipa/camera_sensor_helper.cpp | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
> index 0b0eb503..67cf6913 100644
> --- a/src/ipa/libipa/camera_sensor_helper.cpp
> +++ b/src/ipa/libipa/camera_sensor_helper.cpp
> @@ -7,6 +7,8 @@
> */
> #include "camera_sensor_helper.h"
>
> +#include <cmath>
> +
> #include <libcamera/base/log.h>
>
> /**
> @@ -61,8 +63,8 @@ uint32_t CameraSensorHelper::gainCode(double gain) const
> ASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0);
> ASSERT(analogueGainConstants_.type == AnalogueGainLinear);
>
> - return (analogueGainConstants_.c0 - analogueGainConstants_.c1 * gain) /
> - (analogueGainConstants_.m1 * gain - analogueGainConstants_.m0);
> + return std::round((analogueGainConstants_.c0 - analogueGainConstants_.c1 * gain) /
> + (analogueGainConstants_.m1 * gain - analogueGainConstants_.m0));
> }
>
> /**
> --
> 2.32.0
>
More information about the libcamera-devel
mailing list