libcamera  v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
camera_sensor_helper.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2021, Google Inc.
4  *
5  * Helper class that performs sensor-specific parameter computations
6  */
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <optional>
14 #include <string>
15 #include <vector>
16 
17 #include <libcamera/base/class.h>
18 
19 namespace libcamera {
20 
21 namespace ipa {
22 
24 {
25 public:
26  CameraSensorHelper() = default;
27  virtual ~CameraSensorHelper() = default;
28 
29  std::optional<int16_t> blackLevel() const { return blackLevel_; }
30  virtual uint32_t gainCode(double gain) const;
31  virtual double gain(uint32_t gainCode) const;
32 
33 protected:
37  };
38 
40  int16_t m0;
41  int16_t c0;
42  int16_t m1;
43  int16_t c1;
44  };
45 
47  double a;
48  double m;
49  };
50 
54  };
55 
56  std::optional<int16_t> blackLevel_;
59 
60 private:
62 };
63 
65 {
66 public:
67  CameraSensorHelperFactoryBase(const std::string name);
68  virtual ~CameraSensorHelperFactoryBase() = default;
69 
70  static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
71 
72  static std::vector<CameraSensorHelperFactoryBase *> &factories();
73 
74 private:
76 
77  static void registerType(CameraSensorHelperFactoryBase *factory);
78 
79  virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
80 
81  std::string name_;
82 };
83 
84 template<typename _Helper>
86 {
87 public:
88  CameraSensorHelperFactory(const char *name)
90  {
91  }
92 
93 private:
94  std::unique_ptr<CameraSensorHelper> createInstance() const override
95  {
96  return std::make_unique<_Helper>();
97  }
98 };
99 
100 #define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
101 static CameraSensorHelperFactory<helper> global_##helper##Factory(name);
102 
103 } /* namespace ipa */
104 
105 } /* namespace libcamera */
Registration of CameraSensorHelperFactory classes and creation of instances.
Definition: camera_sensor_helper.h:85
Base class for computing sensor tuning parameters using sensor-specific constants.
Definition: camera_sensor_helper.h:23
virtual double gain(uint32_t gainCode) const
Compute the real gain from the V4L2 subdev control gain code.
Definition: camera_sensor_helper.cpp:119
Utilities to help constructing class interfaces.
AnalogueGainConstants gainConstants_
The analogue gain parameters used for calculation.
Definition: camera_sensor_helper.h:58
double m
Constant used in the exponential gain coding/decoding.
Definition: camera_sensor_helper.h:48
int16_t c1
Constant used in the linear gain coding/decoding.
Definition: camera_sensor_helper.h:43
Base class for camera sensor helper factories.
Definition: camera_sensor_helper.h:64
int16_t m0
Constant used in the linear gain coding/decoding.
Definition: camera_sensor_helper.h:40
Top-level libcamera namespace.
Definition: backtrace.h:17
AnalogueGainType
The gain calculation modes as defined by the MIPI CCS.
Definition: camera_sensor_helper.h:34
int16_t c0
Constant used in the linear gain coding/decoding.
Definition: camera_sensor_helper.h:41
AnalogueGainLinearConstants linear
Constants for the linear gain model.
Definition: camera_sensor_helper.h:52
AnalogueGainExpConstants exp
Constants for the exponential gain model.
Definition: camera_sensor_helper.h:53
CameraSensorHelperFactory(const char *name)
Construct a camera sensor helper factory.
Definition: camera_sensor_helper.h:88
Gain is expressed using an exponential model.
Definition: camera_sensor_helper.h:36
Analogue gain model constants.
Definition: camera_sensor_helper.h:51
Analogue gain constants for the exponential gain model.
Definition: camera_sensor_helper.h:46
virtual uint32_t gainCode(double gain) const
Compute gain code from the analogue gain absolute value.
Definition: camera_sensor_helper.cpp:87
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
int16_t m1
Constant used in the linear gain coding/decoding.
Definition: camera_sensor_helper.h:42
double a
Constant used in the exponential gain coding/decoding.
Definition: camera_sensor_helper.h:47
AnalogueGainType gainType_
The analogue gain model type.
Definition: camera_sensor_helper.h:57
Gain is computed using linear gain estimation.
Definition: camera_sensor_helper.h:35
std::optional< int16_t > blackLevel_
The black level of the sensor.
Definition: camera_sensor_helper.h:56
std::optional< int16_t > blackLevel() const
Construct a CameraSensorHelper instance.
Definition: camera_sensor_helper.h:29
Analogue gain constants for the linear gain model.
Definition: camera_sensor_helper.h:39