[v2,5/5] libipa: camera_sensor_helper: Add Mira016
diff mbox series

Message ID 20261112-b4-mira016-v2-5-c96443a745ce@ideasonboard.com
State New
Headers show
Series
  • libcamera: Add Mira016 support
Related show

Commit Message

Jacopo Mondi Nov. 12, 2026, 2:20 p.m. UTC
Add a camera sensor helper for the AMS-OSRAM Mira016 sensor.

The sensor black level has been measured by averaging the pixel values
while covering the lens.

The mira016 driver gain interface is index-based. The gain() and
gainCode() function use a lookup table that translates the desired
gain value to an index on the table (and viceversa).

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/camera_sensor_helper.cpp | 58 +++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

Comments

Barnabás Pőcze Nov. 12, 2026, 4:22 p.m. UTC | #1
2026. 11. 12. 15:20 keltezéssel, Jacopo Mondi írta:
> Add a camera sensor helper for the AMS-OSRAM Mira016 sensor.
> 
> The sensor black level has been measured by averaging the pixel values
> while covering the lens.
> 
> The mira016 driver gain interface is index-based. The gain() and
> gainCode() function use a lookup table that translates the desired
> gain value to an index on the table (and viceversa).
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>   src/ipa/libipa/camera_sensor_helper.cpp | 58 +++++++++++++++++++++++++++++++++
>   1 file changed, 58 insertions(+)
> 
> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
> index 608937d45ee2..b79d92a7b0f7 100644
> --- a/src/ipa/libipa/camera_sensor_helper.cpp
> +++ b/src/ipa/libipa/camera_sensor_helper.cpp
> @@ -782,6 +782,64 @@ public:
>   };
>   REGISTER_CAMERA_SENSOR_HELPER("ov08x40", CameraSensorHelperOv08x40)
>   
> +class CameraSensorHelperMira016 : public CameraSensorHelper
> +{
> +public:
> +	CameraSensorHelperMira016()
> +	{
> +		blackLevel_ = 2048;

Sorry, forgot to mention, but you could now set `exposureMargin_` as well.
Although as far as I understand it is unclear what the right value is.


> +	}
> +
> +	uint32_t gainCode(double gain) const override
> +	{
> +		uint32_t gainCode = 0;
> +
> +		while (gainCode < maxGainIndex) {
> +			if (gain < gainLut[gainCode + 1])
> +				break;
> +
> +			gainCode++;
> +		}

I was wondering if it might be useful to use binary search here
(e.g. `std::upper_bound()`), but it's only <100 elements, so probably
fine as is; might even be faster.


> +
> +		/*
> +		 * The V4L2_CID_ANALOGUE_GAIN control is 1-indexed while the
> +		 * lookup table is 0-indexed. Return index + 1 here, the driver
> +		 * adjusts it to its 0-indexed table.
> +		 */
> +		return gainCode + 1;
> +	}
> +
> +	double gain(uint32_t gainCode) const override
> +	{
> +		/*
> +		 * The V4L2_CID_ANALOGUE_GAIN control is 1-indexed while the lookup
> +		 * table is 0-indexed.
> +		 */
> +		ASSERT(gainCode > 0);
> +		gainCode = std::min(gainCode - 1, maxGainIndex);
> +
> +		return gainLut[gainCode];
> +	}
> +
> +private:
> +	static constexpr std::array gainLut{
> +		1.0, 1.018, 1.056, 1.075, 1.118, 1.14, 1.188, 1.213, 1.267,
> +		1.295, 1.326, 1.373, 1.425, 1.462, 1.5, 1.541, 1.583,
> +		1.652, 1.701, 1.727, 1.781, 1.839, 1.9, 1.966, 2.0,
> +		2.073, 2.151, 2.192, 2.28, 2.327, 2.426, 2.478, 2.533,
> +		2.651, 2.714, 2.78, 2.886, 2.961, 3.04, 3.167, 3.257,
> +		3.353, 3.455, 3.563, 3.619, 3.738, 3.864, 4.0, 4.071,
> +		4.222, 4.302, 4.471, 4.56, 4.75, 4.851, 5.067, 5.182,
> +		5.302, 5.494, 5.7, 5.846, 6.0, 6.247, 6.423, 6.609,
> +		6.806, 7.015, 7.238, 7.355, 7.6, 7.862, 8.143, 8.291,
> +		8.604, 8.769, 9.12, 9.306, 9.702, 9.913, 10.133, 10.605,
> +		10.857, 11.259, 11.544, 11.844, 12.324, 12.667, 13.029,
> +		13.412, 13.818, 14.25, 14.71, 14.951, 15.458, 16.0,

I assume this is straight from the data sheet? So no formula of any kind
is given, just a list of values?


> +	};
> +	static constexpr uint32_t maxGainIndex = gainLut.size() - 1;
> +};
> +REGISTER_CAMERA_SENSOR_HELPER("mira016", CameraSensorHelperMira016)
> +
>   class CameraSensorHelperMira220 : public CameraSensorHelper
>   {
>   public:
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
index 608937d45ee2..b79d92a7b0f7 100644
--- a/src/ipa/libipa/camera_sensor_helper.cpp
+++ b/src/ipa/libipa/camera_sensor_helper.cpp
@@ -782,6 +782,64 @@  public:
 };
 REGISTER_CAMERA_SENSOR_HELPER("ov08x40", CameraSensorHelperOv08x40)
 
+class CameraSensorHelperMira016 : public CameraSensorHelper
+{
+public:
+	CameraSensorHelperMira016()
+	{
+		blackLevel_ = 2048;
+	}
+
+	uint32_t gainCode(double gain) const override
+	{
+		uint32_t gainCode = 0;
+
+		while (gainCode < maxGainIndex) {
+			if (gain < gainLut[gainCode + 1])
+				break;
+
+			gainCode++;
+		}
+
+		/*
+		 * The V4L2_CID_ANALOGUE_GAIN control is 1-indexed while the
+		 * lookup table is 0-indexed. Return index + 1 here, the driver
+		 * adjusts it to its 0-indexed table.
+		 */
+		return gainCode + 1;
+	}
+
+	double gain(uint32_t gainCode) const override
+	{
+		/*
+		 * The V4L2_CID_ANALOGUE_GAIN control is 1-indexed while the lookup
+		 * table is 0-indexed.
+		 */
+		ASSERT(gainCode > 0);
+		gainCode = std::min(gainCode - 1, maxGainIndex);
+
+		return gainLut[gainCode];
+	}
+
+private:
+	static constexpr std::array gainLut{
+		1.0, 1.018, 1.056, 1.075, 1.118, 1.14, 1.188, 1.213, 1.267,
+		1.295, 1.326, 1.373, 1.425, 1.462, 1.5, 1.541, 1.583,
+		1.652, 1.701, 1.727, 1.781, 1.839, 1.9, 1.966, 2.0,
+		2.073, 2.151, 2.192, 2.28, 2.327, 2.426, 2.478, 2.533,
+		2.651, 2.714, 2.78, 2.886, 2.961, 3.04, 3.167, 3.257,
+		3.353, 3.455, 3.563, 3.619, 3.738, 3.864, 4.0, 4.071,
+		4.222, 4.302, 4.471, 4.56, 4.75, 4.851, 5.067, 5.182,
+		5.302, 5.494, 5.7, 5.846, 6.0, 6.247, 6.423, 6.609,
+		6.806, 7.015, 7.238, 7.355, 7.6, 7.862, 8.143, 8.291,
+		8.604, 8.769, 9.12, 9.306, 9.702, 9.913, 10.133, 10.605,
+		10.857, 11.259, 11.544, 11.844, 12.324, 12.667, 13.029,
+		13.412, 13.818, 14.25, 14.71, 14.951, 15.458, 16.0,
+	};
+	static constexpr uint32_t maxGainIndex = gainLut.size() - 1;
+};
+REGISTER_CAMERA_SENSOR_HELPER("mira016", CameraSensorHelperMira016)
+
 class CameraSensorHelperMira220 : public CameraSensorHelper
 {
 public: