Loading...
Searching...
No Matches
camera_sensor_helper.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2021, Google Inc.
*
* Helper class that performs sensor-specific parameter computations
*/
#pragma once
#include <memory>
#include <optional>
#include <stdint.h>
#include <string>
#include <variant>
#include <vector>
#include <libcamera/base/class.h>
namespace libcamera {
namespace ipa {
class CameraSensorHelper
{
public:
CameraSensorHelper() = default;
virtual ~CameraSensorHelper() = default;
std::optional<int16_t> blackLevel() const { return blackLevel_; }
virtual uint32_t gainCode(double gain) const;
virtual double gain(uint32_t gainCode) const;
double quantizeGain(double gain, double *quantizationGain) const;
protected:
struct AnalogueGainLinear {
int16_t m0;
int16_t c0;
int16_t m1;
int16_t c1;
};
struct AnalogueGainExp {
double a;
double m;
};
std::optional<int16_t> blackLevel_;
std::variant<std::monostate, AnalogueGainLinear, AnalogueGainExp> gain_;
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
};
class CameraSensorHelperFactoryBase
{
public:
CameraSensorHelperFactoryBase(const std::string name);
virtual ~CameraSensorHelperFactoryBase() = default;
static std::unique_ptr<CameraSensorHelper> create(const std::string &name);
static std::vector<CameraSensorHelperFactoryBase *> &factories();
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelperFactoryBase)
static void registerType(CameraSensorHelperFactoryBase *factory);
virtual std::unique_ptr<CameraSensorHelper> createInstance() const = 0;
std::string name_;
};
template<typename _Helper>
class CameraSensorHelperFactory final : public CameraSensorHelperFactoryBase
{
public:
CameraSensorHelperFactory(const char *name)
: CameraSensorHelperFactoryBase(name)
{
}
private:
std::unique_ptr<CameraSensorHelper> createInstance() const override
{
return std::make_unique<_Helper>();
}
};
#define REGISTER_CAMERA_SENSOR_HELPER(name, helper) \
static CameraSensorHelperFactory<helper> global_##helper##Factory(name);
} /* namespace ipa */
} /* 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