[libcamera-devel] [PATCH 1/2] libipa: Round gain code before returning the value
Jean-Michel Hautbois
jeanmichel.hautbois at ideasonboard.com
Fri Nov 19 11:25:58 CET 2021
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>
---
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