libcamera v0.8.0+1-3c8337a0-nvm
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
18
19namespace libcamera {
20
21namespace ipa {
22
24{
25public:
26 CameraSensorHelper() = default;
27 virtual ~CameraSensorHelper() = default;
28
29 std::optional<int16_t> blackLevel() const { return blackLevel_; }
30 std::optional<uint32_t> exposureMargin() const { return exposureMargin_; }
31 virtual uint32_t gainCode(double gain) const;
32 virtual double gain(uint32_t gainCode) const;
33 double quantizeGain(double gain, double *quantizationGain) const;
34
35protected:
37 int16_t m0;
38 int16_t c0;
39 int16_t m1;
40 int16_t c1;
41 };
42
44 double a;
45 double m;
46 };
47
48 std::optional<int16_t> blackLevel_;
49 std::variant<std::monostate, AnalogueGainLinear, AnalogueGainExp> gain_;
50 std::optional<uint32_t> exposureMargin_;
51
52private:
54};
55
57{
58public:
59 CameraSensorHelperFactoryBase(std::initializer_list<const char *> names);
60 virtual ~CameraSensorHelperFactoryBase() = default;
61
62 static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
63
64 static std::vector<CameraSensorHelperFactoryBase *> &factories();
65
66private:
68
69 static void registerType(CameraSensorHelperFactoryBase *factory);
70
71 virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
72
73 std::vector<std::string> names_;
74};
75
76template<typename _Helper>
78{
79public:
80 CameraSensorHelperFactory(std::initializer_list<const char *> names)
82 {
83 }
84
85private:
86 std::unique_ptr<CameraSensorHelper> createInstance() const override
87 {
88 return std::make_unique<_Helper>();
89 }
90};
91
92#define REGISTER_CAMERA_SENSOR_HELPER(helper, name, ...) \
93 static CameraSensorHelperFactory<helper> global_##helper##Factory({ name, __VA_ARGS__ });
94
95} /* namespace ipa */
96
97} /* namespace libcamera */
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
Base class for camera sensor helper factories.
Definition camera_sensor_helper.h:57
static std::vector< CameraSensorHelperFactoryBase * > & factories()
Retrieve the list of all camera sensor helper factories.
Definition camera_sensor_helper.cpp:317
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:282
Registration of CameraSensorHelperFactory classes and creation of instances.
Definition camera_sensor_helper.h:78
CameraSensorHelperFactory(std::initializer_list< const char * > names)
Construct a camera sensor helper factory.
Definition camera_sensor_helper.h:80
Base class for computing sensor tuning parameters using sensor-specific constants.
Definition camera_sensor_helper.h:24
std::optional< uint32_t > exposureMargin_
The smallest margin between the integration time and the frame length in lines.
Definition camera_sensor_helper.h:50
double quantizeGain(double gain, double *quantizationGain) const
Quantize the given gain value.
Definition camera_sensor_helper.cpp:159
std::variant< std::monostate, AnalogueGainLinear, AnalogueGainExp > gain_
The analogue gain parameters used for calculation.
Definition camera_sensor_helper.h:49
std::optional< int16_t > blackLevel_
The black level of the sensor.
Definition camera_sensor_helper.h:48
virtual uint32_t gainCode(double gain) const
Compute gain code from the analogue gain absolute value.
Definition camera_sensor_helper.cpp:98
std::optional< uint32_t > exposureMargin() const
Fetch the exposure margin of the sensor.
Definition camera_sensor_helper.h:30
std::optional< int16_t > blackLevel() const
Fetch the black level of the sensor.
Definition camera_sensor_helper.h:29
virtual double gain(uint32_t gainCode) const
Compute the real gain from the V4L2 subdev control gain code.
Definition camera_sensor_helper.cpp:125
CameraSensorHelper()=default
Construct a CameraSensorHelper instance.
Top-level libcamera namespace.
Definition backtrace.h:17
Analogue gain constants for the exponential gain model.
Definition camera_sensor_helper.h:43
double m
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:45
double a
Constant used in the exponential gain coding/decoding.
Definition camera_sensor_helper.h:44
Analogue gain constants for the linear gain model.
Definition camera_sensor_helper.h:36
int16_t m1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:39
int16_t c0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:38
int16_t c1
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:40
int16_t m0
Constant used in the linear gain coding/decoding.
Definition camera_sensor_helper.h:37