libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
agc_mean_luminance.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2024 Ideas on Board Oy
4 *
5 agc_mean_luminance.h - Base class for mean luminance AGC algorithms
6 */
7
8#pragma once
9
10#include <map>
11#include <memory>
12#include <tuple>
13#include <vector>
14
15#include <libcamera/base/utils.h>
16
17#include <libcamera/controls.h>
18
19#include "libcamera/internal/value_node.h"
20
21#include "exposure_mode_helper.h"
22#include "histogram.h"
23#include "pwl.h"
24
25 namespace libcamera {
26
27 namespace ipa {
28
29 class AgcMeanLuminance
30{
31 public:
32 AgcMeanLuminance();
33 virtual ~AgcMeanLuminance();
34
35 struct AgcConstraint {
36 enum class Bound {
37 Lower = 0,
38 Upper = 1
39 };
40 Bound bound;
41 double qLo;
42 double qHi;
43 Pwl yTarget;
44 };
45
46 void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);
47 int parseTuningData(const ValueNode &tuningData);
48
49 void setExposureCompensation(double gain)
50 {
51 exposureCompensation_ = gain;
52 }
53
54 void setLux(unsigned int lux)
55 {
56 lux_ = lux;
57 }
58
59 void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
60 double minGain, double maxGain, std::vector<AgcConstraint> constraints);
61
62 const std::map<int32_t, std::vector<AgcConstraint>> &constraintModes() const
63 {
64 return constraintModes_;
65 }
66
67 const std::map<int32_t, std::shared_ptr<ExposureModeHelper>> &exposureModeHelpers() const
68 {
69 return exposureModeHelpers_;
70 }
71
72 ControlInfoMap::Map controls()
73 {
74 return controls_;
75 }
76
77 std::tuple<utils::Duration, double, double, double>
78 calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex,
79 const Histogram &yHist, utils::Duration effectiveExposureValue);
80
81 double effectiveYTarget() const;
82
83 void resetFrameCount()
84 {
85 frameCount_ = 0;
86 }
87
88 private:
89 virtual double estimateLuminance(const double gain) const = 0;
90
91 int parseRelativeLuminanceTarget(const ValueNode &tuningData);
92 int parseConstraint(const ValueNode &modeDict, int32_t id);
93 int parseConstraintModes(const ValueNode &tuningData);
94 int parseExposureModes(const ValueNode &tuningData);
95 double estimateInitialGain() const;
96 double constraintClampGain(uint32_t constraintModeIndex,
97 const Histogram &hist,
98 double gain);
99 utils::Duration filterExposure(utils::Duration exposureValue);
100
101 utils::Duration filteredExposure_;
102 mutable bool luxWarningEnabled_;
103 double exposureCompensation_;
104 Pwl relativeLuminanceTarget_;
105 uint64_t frameCount_;
106 unsigned int lux_;
107
108 std::vector<AgcConstraint> additionalConstraints_;
109 std::map<int32_t, std::vector<AgcConstraint>> constraintModes_;
110 std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;
111 ControlInfoMap::Map controls_;
112};
113
114} /* namespace ipa */
115
116} /* namespace libcamera */
libcamera::ControlInfoMap::Map
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition controls.h:367
libcamera::ValueNode
A class representing a tree structure of values.
Definition value_node.h:27
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:355
libcamera::ipa::AgcMeanLuminance::setExposureCompensation
void setExposureCompensation(double gain)
Set the exposure compensation value.
Definition agc_mean_luminance.h:49
libcamera::ipa::AgcMeanLuminance::parseTuningData
int parseTuningData(const ValueNode &tuningData)
Parse tuning data for AeConstraintMode and AeExposureMode controls.
Definition agc_mean_luminance.cpp:419
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:464
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::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:675
libcamera::ipa::AgcMeanLuminance::effectiveYTarget
double effectiveYTarget() const
Get the currently effective y target.
Definition agc_mean_luminance.cpp:593
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:331
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
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.
value_node.h
Data structure to manage tree of values.