Loading...
Searching...
No Matches
agc_mean_luminance.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2024 Ideas on Board Oy
*
agc_mean_luminance.h - Base class for mean luminance AGC algorithms
*/
#pragma once
#include <map>
#include <memory>
#include <tuple>
#include <vector>
#include <libcamera/base/utils.h>
#include <libcamera/controls.h>
#include "libcamera/internal/yaml_parser.h"
#include "exposure_mode_helper.h"
#include "histogram.h"
#include "pwl.h"
namespace libcamera {
namespace ipa {
class AgcMeanLuminance
{
public:
AgcMeanLuminance();
virtual ~AgcMeanLuminance();
struct AgcConstraint {
enum class Bound {
Lower = 0,
Upper = 1
};
Bound bound;
double qLo;
double qHi;
Pwl yTarget;
};
void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);
int parseTuningData(const YamlObject &tuningData);
void setExposureCompensation(double gain)
{
exposureCompensation_ = gain;
}
void setLux(unsigned int lux)
{
lux_ = lux;
}
void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
double minGain, double maxGain, std::vector<AgcConstraint> constraints);
const std::map<int32_t, std::vector<AgcConstraint>> &constraintModes() const
{
return constraintModes_;
}
const std::map<int32_t, std::shared_ptr<ExposureModeHelper>> &exposureModeHelpers() const
{
return exposureModeHelpers_;
}
ControlInfoMap::Map controls()
{
return controls_;
}
std::tuple<utils::Duration, double, double, double>
calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex,
const Histogram &yHist, utils::Duration effectiveExposureValue);
double effectiveYTarget() const;
void resetFrameCount()
{
frameCount_ = 0;
}
private:
virtual double estimateLuminance(const double gain) const = 0;
int parseRelativeLuminanceTarget(const YamlObject &tuningData);
int parseConstraint(const YamlObject &modeDict, int32_t id);
int parseConstraintModes(const YamlObject &tuningData);
int parseExposureModes(const YamlObject &tuningData);
double estimateInitialGain() const;
double constraintClampGain(uint32_t constraintModeIndex,
const Histogram &hist,
double gain);
utils::Duration filterExposure(utils::Duration exposureValue);
utils::Duration filteredExposure_;
mutable bool luxWarningEnabled_;
double exposureCompensation_;
Pwl relativeLuminanceTarget_;
uint64_t frameCount_;
unsigned int lux_;
std::vector<AgcConstraint> additionalConstraints_;
std::map<int32_t, std::vector<AgcConstraint>> constraintModes_;
std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;
ControlInfoMap::Map controls_;
};
} /* namespace ipa */
} /* namespace libcamera */
libcamera::ControlInfoMap::Map
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition controls.h:367
libcamera::YamlObject
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:28
libcamera::ipa::AgcMeanLuminance::constraintModes
const std::map< int32_t, std::vector< AgcConstraint > > & constraintModes() const
Get the constraint modes that have been parsed from tuning data.
Definition agc_mean_luminance.h:62
libcamera::ipa::AgcMeanLuminance::configure
void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper)
Configure the exposure mode helpers.
Definition agc_mean_luminance.cpp:353
libcamera::ipa::AgcMeanLuminance::setExposureCompensation
void setExposureCompensation(double gain)
Set the exposure compensation value.
Definition agc_mean_luminance.h:49
libcamera::ipa::AgcMeanLuminance::resetFrameCount
void resetFrameCount()
Reset the frame counter.
Definition agc_mean_luminance.h:83
libcamera::ipa::AgcMeanLuminance::setLimits
void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, double minGain, double maxGain, std::vector< AgcConstraint > constraints)
Set the ExposureModeHelper limits for this class.
Definition agc_mean_luminance.cpp:462
libcamera::ipa::AgcMeanLuminance::controls
ControlInfoMap::Map controls()
Get the controls that have been generated after parsing tuning data.
Definition agc_mean_luminance.h:72
libcamera::ipa::AgcMeanLuminance::parseTuningData
int parseTuningData(const YamlObject &tuningData)
Parse tuning data for AeConstraintMode and AeExposureMode controls.
Definition agc_mean_luminance.cpp:417
libcamera::ipa::AgcMeanLuminance::setLux
void setLux(unsigned int lux)
Set the lux level.
Definition agc_mean_luminance.h:54
libcamera::ipa::AgcMeanLuminance::calculateNewEv
std::tuple< utils::Duration, double, double, double > calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex, const Histogram &yHist, utils::Duration effectiveExposureValue)
Calculate the new exposure value and splut it between exposure time and gain.
Definition agc_mean_luminance.cpp:673
libcamera::ipa::AgcMeanLuminance::effectiveYTarget
double effectiveYTarget() const
Get the currently effective y target.
Definition agc_mean_luminance.cpp:591
libcamera::ipa::AgcMeanLuminance::exposureModeHelpers
const std::map< int32_t, std::shared_ptr< ExposureModeHelper > > & exposureModeHelpers() const
Get the ExposureModeHelpers that have been parsed from tuning data.
Definition agc_mean_luminance.h:67
libcamera::ipa::CameraSensorHelper
Base class for computing sensor tuning parameters using sensor-specific constants.
Definition camera_sensor_helper.h:24
libcamera::ipa::Histogram
The base class for creating histograms.
Definition histogram.h:23
libcamera::ipa::Pwl
Describe a univariate piecewise linear function in two-dimensional real space.
Definition pwl.h:22
libcamera::utils::Duration
Helper class from std::chrono::duration that represents a time duration in nanoseconds with double pr...
Definition utils.h:322
controls.h
Framework to manage controls related to an object.
exposure_mode_helper.h
Helper class that performs computations relating to exposure.
histogram.h
Class to represent Histograms and manipulate them.
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
pwl.h
Piecewise linear functions.
libcamera::ipa::AgcMeanLuminance::AgcConstraint
The boundaries and target for an AeConstraintMode constraint.
Definition agc_mean_luminance.h:35
libcamera::ipa::AgcMeanLuminance::AgcConstraint::qHi
double qHi
The upper quantile to use for the constraint.
Definition agc_mean_luminance.h:42
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound
Bound
Specify whether the constraint defines a lower or upper bound.
Definition agc_mean_luminance.h:36
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound::Upper
@ Upper
The constraint defines an upper bound.
Definition agc_mean_luminance.h:38
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound::Lower
@ Lower
The constraint defines a lower bound.
Definition agc_mean_luminance.h:37
libcamera::ipa::AgcMeanLuminance::AgcConstraint::bound
Bound bound
The type of constraint bound.
Definition agc_mean_luminance.h:40
libcamera::ipa::AgcMeanLuminance::AgcConstraint::yTarget
Pwl yTarget
The luminance target for the constraint.
Definition agc_mean_luminance.h:43
libcamera::ipa::AgcMeanLuminance::AgcConstraint::qLo
double qLo
The lower quantile to use for the constraint.
Definition agc_mean_luminance.h:41
utils.h
Miscellaneous utility functions.
yaml_parser.h
A YAML parser helper.