libcamera: src/ipa/libipa/camera_sensor_helper.h Source File

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