summaryrefslogtreecommitdiff
path: root/src/ipa/libipa
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-02-24 21:55:44 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-04-01 14:29:05 +0300
commita9d43c4710ba0db092c2abbf7d3423f4ac58352a (patch)
tree74292a9b73918b6c7e19da9f1dfe5ed09f0016ac /src/ipa/libipa
parentf9e2df951969f10f1ee1e46fb806942a27db8aca (diff)
libipa: camera_sensor_helper: Reorganize gain constants
To prepare for other gain models than the linear model, store the gain constants in a union with per-model members. Due to the lack of designated initializer support in gcc with C++17, initializing a single complex structure that includes a union will be difficult. Split the gain model type to a separate variable to work around this issue. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src/ipa/libipa')
-rw-r--r--src/ipa/libipa/camera_sensor_helper.cpp96
-rw-r--r--src/ipa/libipa/camera_sensor_helper.h10
2 files changed, 62 insertions, 44 deletions
diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
index c953def0..714cd86f 100644
--- a/src/ipa/libipa/camera_sensor_helper.cpp
+++ b/src/ipa/libipa/camera_sensor_helper.cpp
@@ -58,11 +58,13 @@ namespace ipa {
*/
uint32_t CameraSensorHelper::gainCode(double gain) const
{
- ASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0);
- ASSERT(analogueGainConstants_.type == AnalogueGainLinear);
+ const AnalogueGainConstants &k = gainConstants_;
- return (analogueGainConstants_.c0 - analogueGainConstants_.c1 * gain) /
- (analogueGainConstants_.m1 * gain - analogueGainConstants_.m0);
+ ASSERT(gainType_ == AnalogueGainLinear);
+ ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);
+
+ return (k.linear.c0 - k.linear.c1 * gain) /
+ (k.linear.m1 * gain - k.linear.m0);
}
/**
@@ -80,11 +82,13 @@ uint32_t CameraSensorHelper::gainCode(double gain) const
*/
double CameraSensorHelper::gain(uint32_t gainCode) const
{
- ASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0);
- ASSERT(analogueGainConstants_.type == AnalogueGainLinear);
+ const AnalogueGainConstants &k = gainConstants_;
+
+ ASSERT(gainType_ == AnalogueGainLinear);
+ ASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);
- return (analogueGainConstants_.m0 * static_cast<double>(gainCode) + analogueGainConstants_.c0) /
- (analogueGainConstants_.m1 * static_cast<double>(gainCode) + analogueGainConstants_.c1);
+ return (k.linear.m0 * static_cast<double>(gainCode) + k.linear.c0) /
+ (k.linear.m1 * static_cast<double>(gainCode) + k.linear.c1);
}
/**
@@ -128,41 +132,44 @@ double CameraSensorHelper::gain(uint32_t gainCode) const
*/
/**
- * \struct CameraSensorHelper::AnalogueGainConstants
- * \brief Analogue gain constants used for gain calculation
- */
-
-/**
- * \var CameraSensorHelper::AnalogueGainConstants::type
- * \brief Analogue gain calculation mode
- */
-
-/**
- * \var CameraSensorHelper::AnalogueGainConstants::m0
- * \brief Constant used in the analogue Gain coding/decoding
+ * \struct CameraSensorHelper::AnalogueGainLinearConstants
+ * \brief Analogue gain constants for the linear gain model
+ *
+ * \var CameraSensorHelper::AnalogueGainLinearConstants::m0
+ * \brief Constant used in the linear gain coding/decoding
*
* \note Either m0 or m1 shall be zero.
+ *
+ * \var CameraSensorHelper::AnalogueGainLinearConstants::c0
+ * \brief Constant used in the linear gain coding/decoding
+ *
+ * \var CameraSensorHelper::AnalogueGainLinearConstants::m1
+ * \brief Constant used in the linear gain coding/decoding
+ *
+ * \note Either m0 or m1 shall be zero.
+ *
+ * \var CameraSensorHelper::AnalogueGainLinearConstants::c1
+ * \brief Constant used in the linear gain coding/decoding
*/
/**
- * \var CameraSensorHelper::AnalogueGainConstants::c0
- * \brief Constant used in the analogue gain coding/decoding
- */
-
-/**
- * \var CameraSensorHelper::AnalogueGainConstants::m1
- * \brief Constant used in the analogue gain coding/decoding
+ * \struct CameraSensorHelper::AnalogueGainConstants
+ * \brief Analogue gain model constants
*
- * \note Either m0 or m1 shall be zero.
+ * This union stores the constants used to calculate the analogue gain. The
+ * CameraSensorHelper::gainType_ variable selects which union member is valid.
+ *
+ * \var CameraSensorHelper::AnalogueGainConstants::linear
+ * \brief Constants for the linear gain model
*/
/**
- * \var CameraSensorHelper::AnalogueGainConstants::c1
- * \brief Constant used in the analogue gain coding/decoding
+ * \var CameraSensorHelper::gainType_
+ * \brief The analogue gain model type
*/
/**
- * \var CameraSensorHelper::analogueGainConstants_
+ * \var CameraSensorHelper::gainConstants_
* \brief The analogue gain parameters used for calculation
*
* The analogue gain is calculated through a formula, and its parameters are
@@ -290,7 +297,8 @@ class CameraSensorHelperImx219 : public CameraSensorHelper
public:
CameraSensorHelperImx219()
{
- analogueGainConstants_ = { AnalogueGainLinear, 0, 256, -1, 256 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 0, 256, -1, 256 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("imx219", CameraSensorHelperImx219)
@@ -298,10 +306,11 @@ REGISTER_CAMERA_SENSOR_HELPER("imx219", CameraSensorHelperImx219)
class CameraSensorHelperImx258 : public CameraSensorHelper
{
public:
- CameraSensorHelperImx258()
- {
- analogueGainConstants_ = { AnalogueGainLinear, 0, 512, -1, 512 };
- }
+ CameraSensorHelperImx258()
+ {
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 0, 512, -1, 512 };
+ }
};
REGISTER_CAMERA_SENSOR_HELPER("imx258", CameraSensorHelperImx258)
@@ -310,7 +319,8 @@ class CameraSensorHelperOv2740 : public CameraSensorHelper
public:
CameraSensorHelperOv2740()
{
- analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 1, 0, 0, 128 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("ov2740", CameraSensorHelperOv2740)
@@ -320,7 +330,8 @@ class CameraSensorHelperOv5670 : public CameraSensorHelper
public:
CameraSensorHelperOv5670()
{
- analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 1, 0, 0, 128 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("ov5670", CameraSensorHelperOv5670)
@@ -330,7 +341,8 @@ class CameraSensorHelperOv5693 : public CameraSensorHelper
public:
CameraSensorHelperOv5693()
{
- analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 16 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 1, 0, 0, 16 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693)
@@ -340,7 +352,8 @@ class CameraSensorHelperOv8865 : public CameraSensorHelper
public:
CameraSensorHelperOv8865()
{
- analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 1, 0, 0, 128 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("ov8865", CameraSensorHelperOv8865)
@@ -350,7 +363,8 @@ class CameraSensorHelperOv13858 : public CameraSensorHelper
public:
CameraSensorHelperOv13858()
{
- analogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };
+ gainType_ = AnalogueGainLinear;
+ gainConstants_.linear = { 1, 0, 0, 128 };
}
};
REGISTER_CAMERA_SENSOR_HELPER("ov13858", CameraSensorHelperOv13858)
diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h
index 26adfcb5..6b96520b 100644
--- a/src/ipa/libipa/camera_sensor_helper.h
+++ b/src/ipa/libipa/camera_sensor_helper.h
@@ -34,15 +34,19 @@ protected:
AnalogueGainExponential,
};
- struct AnalogueGainConstants {
- AnalogueGainType type;
+ struct AnalogueGainLinearConstants {
int16_t m0;
int16_t c0;
int16_t m1;
int16_t c1;
};
- AnalogueGainConstants analogueGainConstants_;
+ union AnalogueGainConstants {
+ AnalogueGainLinearConstants linear;
+ };
+
+ AnalogueGainType gainType_;
+ AnalogueGainConstants gainConstants_;
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)