libcamera v0.3.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
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 <memory>
11#include <optional>
12#include <stdint.h>
13#include <string>
14#include <vector>
15
16#include <libcamera/base/class.h>
17
18 namespace libcamera {
19
20 namespace ipa {
21
22 class CameraSensorHelper
23{
24 public:
25 CameraSensorHelper() = default;
26 virtual ~CameraSensorHelper() = default;
27
28 std::optional<int16_t> blackLevel() const { return blackLevel_; }
29 virtual uint32_t gainCode(double gain) const;
30 virtual double gain(uint32_t gainCode) const;
31
32 protected:
33 enum AnalogueGainType {
34 AnalogueGainLinear,
35 AnalogueGainExponential,
36 };
37
38 struct AnalogueGainLinearConstants {
39 int16_t m0;
40 int16_t c0;
41 int16_t m1;
42 int16_t c1;
43 };
44
45 struct AnalogueGainExpConstants {
46 double a;
47 double m;
48 };
49
50 union AnalogueGainConstants {
51 AnalogueGainLinearConstants linear;
52 AnalogueGainExpConstants exp;
53 };
54
55 std::optional<int16_t> blackLevel_;
56 AnalogueGainType gainType_;
57 AnalogueGainConstants gainConstants_;
58
59 private:
60 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
61};
62
63 class CameraSensorHelperFactoryBase
64{
65 public:
66 CameraSensorHelperFactoryBase(const std::string name);
67 virtual ~CameraSensorHelperFactoryBase() = default;
68
69 static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
70
71 static std::vector<CameraSensorHelperFactoryBase *> &factories();
72
73 private:
74 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase)
75
76 static void registerType(CameraSensorHelperFactoryBase *factory);
77
78 virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
79
80 std::string name_;
81};
82
83 template<typename _Helper>
84 class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase
85{
86 public:
87 CameraSensorHelperFactory(const char *name)
88 : CameraSensorHelperFactoryBase(name)
89 {
90 }
91
92 private:
93 std::unique_ptr<CameraSensorHelper> createInstance() const override
94 {
95 return std::make_unique<_Helper>();
96 }
97};
98
99#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
100 static CameraSensorHelperFactory<helper> global_##helper##Factory(name);
101
102} /* namespace ipa */
103
104} /* namespace libcamera */
class.h
Utilities to help constructing class interfaces.
LIBCAMERA_DISABLE_COPY_AND_MOVE
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
libcamera::ipa::CameraSensorHelperFactoryBase
Base class for camera sensor helper factories.
Definition camera_sensor_helper.h:64
libcamera::ipa::CameraSensorHelperFactoryBase::CameraSensorHelperFactoryBase
CameraSensorHelperFactoryBase(const std::string name)
Construct a camera sensor helper factory base.
Definition camera_sensor_helper.cpp:274
libcamera::ipa::CameraSensorHelperFactoryBase::factories
static std::vector< CameraSensorHelperFactoryBase * > & factories()
Retrieve the list of all camera sensor helper factories.
Definition camera_sensor_helper.cpp:323
libcamera::ipa::CameraSensorHelperFactoryBase::create
static std::unique_ptr< CameraSensorHelper > create(const std::string &name)
Create an instance of the CameraSensorHelper corresponding to a named factory.
Definition camera_sensor_helper.cpp:289
libcamera::ipa::CameraSensorHelperFactory
Registration of CameraSensorHelperFactory classes and creation of instances.
Definition camera_sensor_helper.h:85
libcamera::ipa::CameraSensorHelperFactory::CameraSensorHelperFactory
CameraSensorHelperFactory(const char *name)
Construct a camera sensor helper factory.
Definition camera_sensor_helper.h:87
libcamera::ipa::CameraSensorHelper
Base class for computing sensor tuning parameters using sensor-specific constants.
Definition camera_sensor_helper.h:23
libcamera::ipa::CameraSensorHelper::gainType_
AnalogueGainType gainType_
The analogue gain model type.
Definition camera_sensor_helper.h:56
libcamera::ipa::CameraSensorHelper::blackLevel
std::optional< int16_t > blackLevel() const
Fetch the black level of the sensor.
Definition camera_sensor_helper.h:28
libcamera::ipa::CameraSensorHelper::gainCode
virtual uint32_t gainCode(double gain) const
Compute gain code from the analogue gain absolute value.
Definition camera_sensor_helper.cpp:88
libcamera::ipa::CameraSensorHelper::AnalogueGainType
AnalogueGainType
The gain calculation modes as defined by the MIPI CCS.
Definition camera_sensor_helper.h:33
libcamera::ipa::CameraSensorHelper::AnalogueGainExponential
@ AnalogueGainExponential
Gain is expressed using an exponential model.
Definition camera_sensor_helper.h:35
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear
@ AnalogueGainLinear
Gain is computed using linear gain estimation.
Definition camera_sensor_helper.h:34
libcamera::ipa::CameraSensorHelper::blackLevel_
std::optional< int16_t > blackLevel_
The black level of the sensor.
Definition camera_sensor_helper.h:55
libcamera::ipa::CameraSensorHelper::gain
virtual double gain(uint32_t gainCode) const
Compute the real gain from the V4L2 subdev control gain code.
Definition camera_sensor_helper.cpp:120
libcamera::ipa::CameraSensorHelper::CameraSensorHelper
CameraSensorHelper()=default
Construct a CameraSensorHelper instance.
libcamera::ipa::CameraSensorHelper::gainConstants_
AnalogueGainConstants gainConstants_
The analogue gain parameters used for calculation.
Definition camera_sensor_helper.h:57
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::ipa::CameraSensorHelper::AnalogueGainExpConstants
Analogue gain constants for the exponential gain model.
Definition camera_sensor_helper.h:45
libcamera::ipa::CameraSensorHelper::AnalogueGainExpConstants::a
double a
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:46
libcamera::ipa::CameraSensorHelper::AnalogueGainExpConstants::m
double m
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:47
libcamera::ipa::CameraSensorHelper::AnalogueGainLinearConstants
Analogue gain constants for the linear gain model.
Definition camera_sensor_helper.h:38
libcamera::ipa::CameraSensorHelper::AnalogueGainLinearConstants::m1
int16_t m1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:41
libcamera::ipa::CameraSensorHelper::AnalogueGainLinearConstants::m0
int16_t m0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:39
libcamera::ipa::CameraSensorHelper::AnalogueGainLinearConstants::c0
int16_t c0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:40
libcamera::ipa::CameraSensorHelper::AnalogueGainLinearConstants::c1
int16_t c1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:42
libcamera::ipa::CameraSensorHelper::AnalogueGainConstants
Analogue gain model constants.
Definition camera_sensor_helper.h:50
libcamera::ipa::CameraSensorHelper::AnalogueGainConstants::linear
AnalogueGainLinearConstants linear
Constants for the linear gain model.
Definition camera_sensor_helper.h:51
libcamera::ipa::CameraSensorHelper::AnalogueGainConstants::exp
AnalogueGainExpConstants exp
Constants for the exponential gain model.
Definition camera_sensor_helper.h:52