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

libcamera v0.5.0 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/yaml_parser.h"
20
21#include "exposure_mode_helper.h"
22#include "histogram.h"
23
24namespace libcamera {
25
26namespace ipa {
27
28 class AgcMeanLuminance
29{
30public:
31 AgcMeanLuminance();
32 virtual ~AgcMeanLuminance();
33
34 struct AgcConstraint {
35 enum class Bound {
36 Lower = 0,
37 Upper = 1
38 };
39 Bound bound;
40 double qLo;
41 double qHi;
42 double yTarget;
43 };
44
45 int parseTuningData(const YamlObject &tuningData);
46
47 void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
48 double minGain, double maxGain);
49
50 std::map<int32_t, std::vector<AgcConstraint>> constraintModes()
51 {
52 return constraintModes_;
53 }
54
55 std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers()
56 {
57 return exposureModeHelpers_;
58 }
59
60 ControlInfoMap::Map controls()
61 {
62 return controls_;
63 }
64
65 std::tuple<utils::Duration, double, double>
66 calculateNewEv(uint32_t constraintModeIndex, uint32_t exposureModeIndex,
67 const Histogram &yHist, utils::Duration effectiveExposureValue);
68
69 void resetFrameCount()
70 {
71 frameCount_ = 0;
72 }
73
74private:
75 virtual double estimateLuminance(const double gain) const = 0;
76
77 void parseRelativeLuminanceTarget(const YamlObject &tuningData);
78 void parseConstraint(const YamlObject &modeDict, int32_t id);
79 int parseConstraintModes(const YamlObject &tuningData);
80 int parseExposureModes(const YamlObject &tuningData);
81 double estimateInitialGain() const;
82 double constraintClampGain(uint32_t constraintModeIndex,
83 const Histogram &hist,
84 double gain);
85 utils::Duration filterExposure(utils::Duration exposureValue);
86
87 uint64_t frameCount_;
88 utils::Duration filteredExposure_;
89 double relativeLuminanceTarget_;
90
91 std::map<int32_t, std::vector<AgcConstraint>> constraintModes_;
92 std::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;
93 ControlInfoMap::Map controls_;
94};
95
96} /* namespace ipa */
97
98} /* namespace libcamera */
libcamera::ControlInfoMap::Map
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition controls.h:369
libcamera::YamlObject
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:28
libcamera::ipa::AgcMeanLuminance::setLimits
void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime, double minGain, double maxGain)
Set the ExposureModeHelper limits for this class.
Definition agc_mean_luminance.cpp:382
libcamera::ipa::AgcMeanLuminance::resetFrameCount
void resetFrameCount()
Reset the frame counter.
Definition agc_mean_luminance.h:69
libcamera::ipa::AgcMeanLuminance::constraintModes
std::map< int32_t, std::vector< AgcConstraint > > constraintModes()
Get the constraint modes that have been parsed from tuning data.
Definition agc_mean_luminance.h:50
libcamera::ipa::AgcMeanLuminance::exposureModeHelpers
std::map< int32_t, std::shared_ptr< ExposureModeHelper > > exposureModeHelpers()
Get the ExposureModeHelpers that have been parsed from tuning data.
Definition agc_mean_luminance.h:55
libcamera::ipa::AgcMeanLuminance::controls
ControlInfoMap::Map controls()
Get the controls that have been generated after parsing tuning data.
Definition agc_mean_luminance.h:60
libcamera::ipa::AgcMeanLuminance::parseTuningData
int parseTuningData(const YamlObject &tuningData)
Parse tuning data for AeConstraintMode and AeExposureMode controls.
Definition agc_mean_luminance.cpp:359
libcamera::ipa::AgcMeanLuminance::calculateNewEv
std::tuple< utils::Duration, 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:532
libcamera::ipa::Histogram
The base class for creating histograms.
Definition histogram.h:23
libcamera::utils::Duration
Helper class from std::chrono::duration that represents a time duration in nanoseconds with double pr...
Definition utils.h:371
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
libcamera::ipa::AgcMeanLuminance::AgcConstraint
The boundaries and target for an AeConstraintMode constraint.
Definition agc_mean_luminance.h:34
libcamera::ipa::AgcMeanLuminance::AgcConstraint::yTarget
double yTarget
The luminance target for the constraint.
Definition agc_mean_luminance.h:42
libcamera::ipa::AgcMeanLuminance::AgcConstraint::qHi
double qHi
The upper quantile to use for the constraint.
Definition agc_mean_luminance.h:41
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound
Bound
Specify whether the constraint defines a lower or upper bound.
Definition agc_mean_luminance.h:35
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound::Upper
@ Upper
The constraint defines an upper bound.
Definition agc_mean_luminance.h:37
libcamera::ipa::AgcMeanLuminance::AgcConstraint::Bound::Lower
@ Lower
The constraint defines a lower bound.
Definition agc_mean_luminance.h:36
libcamera::ipa::AgcMeanLuminance::AgcConstraint::bound
Bound bound
The type of constraint bound.
Definition agc_mean_luminance.h:39
libcamera::ipa::AgcMeanLuminance::AgcConstraint::qLo
double qLo
The lower quantile to use for the constraint.
Definition agc_mean_luminance.h:40
utils.h
Miscellaneous utility functions.
yaml_parser.h
A YAML parser helper.