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

libcamera v0.7.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 <variant>
15#include <vector>
16
17#include <libcamera/base/class.h>
18
19namespace libcamera {
20
21namespace ipa {
22
23 class CameraSensorHelper
24{
25public:
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 double quantizeGain(double gain, double *quantizationGain) const;
33
34protected:
35 struct AnalogueGainLinear {
36 int16_t m0;
37 int16_t c0;
38 int16_t m1;
39 int16_t c1;
40 };
41
42 struct AnalogueGainExp {
43 double a;
44 double m;
45 };
46
47 std::optional<int16_t> blackLevel_;
48 std::variant<std::monostate, AnalogueGainLinear, AnalogueGainExp> gain_;
49
50private:
51 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
52};
53
54 class CameraSensorHelperFactoryBase
55{
56public:
57 CameraSensorHelperFactoryBase(const std::string name);
58 virtual ~CameraSensorHelperFactoryBase() = default;
59
60 static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
61
62 static std::vector<CameraSensorHelperFactoryBase *> &factories();
63
64private:
65 LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase)
66
67 static void registerType(CameraSensorHelperFactoryBase *factory);
68
69 virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
70
71 std::string name_;
72};
73
74template<typename _Helper>
75 class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase
76{
77public:
78 CameraSensorHelperFactory(const char *name)
79 : CameraSensorHelperFactoryBase(name)
80 {
81 }
82
83private:
84 std::unique_ptr<CameraSensorHelper> createInstance() const override
85 {
86 return std::make_unique<_Helper>();
87 }
88};
89
90#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
91static CameraSensorHelperFactory<helper> global_##helper##Factory(name);
92
93} /* namespace ipa */
94
95} /* 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::CameraSensorHelperFactoryBase
CameraSensorHelperFactoryBase(const std::string name)
Construct a camera sensor helper factory base.
Definition camera_sensor_helper.cpp:251
libcamera::ipa::CameraSensorHelperFactoryBase::factories
static std::vector< CameraSensorHelperFactoryBase * > & factories()
Retrieve the list of all camera sensor helper factories.
Definition camera_sensor_helper.cpp:300
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:266
libcamera::ipa::CameraSensorHelperFactory::CameraSensorHelperFactory
CameraSensorHelperFactory(const char *name)
Construct a camera sensor helper factory.
Definition camera_sensor_helper.h:78
libcamera::ipa::CameraSensorHelper::quantizeGain
double quantizeGain(double gain, double *quantizationGain) const
Quantize the given gain value.
Definition camera_sensor_helper.cpp:149
libcamera::ipa::CameraSensorHelper::blackLevel
std::optional< int16_t > blackLevel() const
Fetch the black level of the sensor.
Definition camera_sensor_helper.h:29
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::blackLevel_
std::optional< int16_t > blackLevel_
The black level of the sensor.
Definition camera_sensor_helper.h:47
libcamera::ipa::CameraSensorHelper::gain_
std::variant< std::monostate, AnalogueGainLinear, AnalogueGainExp > gain_
The analogue gain parameters used for calculation.
Definition camera_sensor_helper.h:48
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:115
libcamera::ipa::CameraSensorHelper::CameraSensorHelper
CameraSensorHelper()=default
Construct a CameraSensorHelper instance.
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::ipa::CameraSensorHelper::AnalogueGainExp
Analogue gain constants for the exponential gain model.
Definition camera_sensor_helper.h:42
libcamera::ipa::CameraSensorHelper::AnalogueGainExp::m
double m
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:44
libcamera::ipa::CameraSensorHelper::AnalogueGainExp::a
double a
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:43
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear
Analogue gain constants for the linear gain model.
Definition camera_sensor_helper.h:35
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear::m1
int16_t m1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:38
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear::m0
int16_t m0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:36
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear::c0
int16_t c0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:37
libcamera::ipa::CameraSensorHelper::AnalogueGainLinear::c1
int16_t c1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:39