[PATCH v2 3/3] libipa: camera_sensor_helper: Fix rounding of gainCode
Paul Elder
paul.elder at ideasonboard.com
Wed Mar 26 09:00:33 CET 2025
From: Kieran Bingham <kieran.bingham at ideasonboard.com>
The implementation of gainCode for both Exponential and Linear gain
models does not generate a gainCode that matches the result of the
reverse operation.
This can be seen by converting sequential gainCodes to a gain
and converting that back to the gainCode. The values do not
translate back due to rounding errors.
Correct the rounding error and ensure that gainCode translation
produces accurate bi-directional conversions from the perspective
of the gainCode.
This fixes the IMX290, IMX296, IMX327 and IMX335 which use the
Exponential gain model helpers, as well as IMX219 IMX258 and IMX477
which use the Linear gain model helpers.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
Changes in v2:
- recover from bitrot
---
src/ipa/libipa/camera_sensor_helper.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
index 7c66cd57d685..5645dd14fda3 100644
--- a/src/ipa/libipa/camera_sensor_helper.cpp
+++ b/src/ipa/libipa/camera_sensor_helper.cpp
@@ -90,12 +90,12 @@ uint32_t CameraSensorHelper::gainCode(double gain) const
if (auto *l = std::get_if<AnalogueGainLinear>(&gain_)) {
ASSERT(l->m0 == 0 || l->m1 == 0);
- return (l->c0 - l->c1 * gain) /
- (l->m1 * gain - l->m0);
+ return std::round((l->c0 - l->c1 * gain) /
+ (l->m1 * gain - l->m0));
} else if (auto *e = std::get_if<AnalogueGainExp>(&gain_)) {
ASSERT(e->a != 0 && e->m != 0);
- return std::log2(gain / e->a) / e->m;
+ return std::round(std::log2(gain / e->a) / e->m);
} else {
ASSERT(false);
return 0;
--
2.47.2
More information about the libcamera-devel
mailing list