summaryrefslogtreecommitdiff
path: root/src/ipa/libipa/camera_sensor_helper.h
diff options
context:
space:
mode:
authorJean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>2021-06-07 14:05:44 +0200
committerJean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>2021-06-28 10:48:33 +0200
commit32677e122008f1c06d1712a5e869d355a57067d9 (patch)
tree433debec975e4100b4ac3ecf2c524209d412e6be /src/ipa/libipa/camera_sensor_helper.h
parent1684c3f930b2a27884037bc38856477b80cddd50 (diff)
ipa: Create a camera sensor helper class
For various sensor operations, it may be needed to do sensor specific computations, like analogue gain or vertical blanking. This commit introduces a new camera sensor helper in libipa which aims to solve this specific issue. It is based on the MIPI alliance Specification for Camera Command Set and implements, for now, only the analogue "Global gain" mode. Setting analogue gain for a specific sensor is not a straightforward operation, as one needs to know how the gain is calculated for it. Three helpers are created in this patch: imx219, ov5670 and ov5693. Adding a new sensor is pretty straightforward as one only needs to implement the sub-class for it and register that class to the CameraSensorHelperFactory. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src/ipa/libipa/camera_sensor_helper.h')
-rw-r--r--src/ipa/libipa/camera_sensor_helper.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h
new file mode 100644
index 00000000..1c47e8d5
--- /dev/null
+++ b/src/ipa/libipa/camera_sensor_helper.h
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021, Google Inc.
+ *
+ * camera_sensor_helper.h - Helper class that performs sensor-specific parameter computations
+ */
+#ifndef __LIBCAMERA_IPA_LIBIPA_CAMERA_SENSOR_HELPER_H__
+#define __LIBCAMERA_IPA_LIBIPA_CAMERA_SENSOR_HELPER_H__
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <libcamera/base/class.h>
+
+namespace libcamera {
+
+namespace ipa {
+
+class CameraSensorHelper
+{
+public:
+ CameraSensorHelper() = default;
+ virtual ~CameraSensorHelper() = default;
+
+ virtual uint32_t gainCode(double gain) const;
+ virtual double gain(uint32_t gainCode) const;
+
+protected:
+ enum AnalogueGainType {
+ AnalogueGainLinear = 0,
+ AnalogueGainExponential = 2,
+ };
+
+ struct AnalogueGainConstants {
+ AnalogueGainType type;
+ int16_t m0;
+ int16_t c0;
+ int16_t m1;
+ int16_t c1;
+ };
+
+ AnalogueGainConstants analogueGainConstants_;
+
+private:
+ LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
+};
+
+class CameraSensorHelperFactory
+{
+public:
+ CameraSensorHelperFactory(const std::string name);
+ virtual ~CameraSensorHelperFactory() = default;
+
+ static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
+
+ static void registerType(CameraSensorHelperFactory *factory);
+ static std::vector<CameraSensorHelperFactory *> &factories();
+
+protected:
+ LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactory)
+ virtual CameraSensorHelper *createInstance() = 0;
+
+ std::string name_;
+};
+
+#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
+class helper##Factory final : public CameraSensorHelperFactory \
+{ \
+public: \
+ helper##Factory() : CameraSensorHelperFactory(name) {} \
+ \
+private: \
+ CameraSensorHelper *createInstance() \
+ { \
+ return new helper(); \
+ } \
+}; \
+static helper##Factory global_##helper##Factory;
+
+} /* namespace ipa */
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_IPA_LIBIPA_CAMERA_SENSOR_HELPER_H__ */