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