[v1,33/35] libipa: agc_mean_luminance: Make startup frames and regulations speed configurable
diff mbox series

Message ID 20251024085130.995967-34-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • rkisp1: pipeline rework for PFC
Related show

Commit Message

Stefan Klug Oct. 24, 2025, 8:50 a.m. UTC
The rkisp1 has now a good synchronization between sensor settings/isp
params and stats.  It can therefore benefit from a faster regulation. To
do that without breaking others IPAs that use AgcMeanLuminance, move
regulation speed and startup frames into member variables that can be
set at runtime.

As this requires the introduction of a protected access modifier. This
was added, so that most of the previously public functions are now also
protected, because public visibility is not needed.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/libipa/agc_mean_luminance.cpp | 25 +++++++++++++++++++++----
 src/ipa/libipa/agc_mean_luminance.h   |  4 ++++
 2 files changed, 25 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp
index 64f36bd75dd2..0cd3fbee99e8 100644
--- a/src/ipa/libipa/agc_mean_luminance.cpp
+++ b/src/ipa/libipa/agc_mean_luminance.cpp
@@ -34,7 +34,7 @@  namespace ipa {
  * Number of frames for which to run the algorithm at full speed, before slowing
  * down to prevent large and jarring changes in exposure from frame to frame.
  */
-static constexpr uint32_t kNumStartupFrames = 10;
+static constexpr uint32_t kDefaultNumStartupFrames = 10;
 
 /*
  * Default relative luminance target
@@ -144,7 +144,8 @@  static constexpr double kMaxRelativeLuminanceTarget = 0.95;
  */
 
 AgcMeanLuminance::AgcMeanLuminance()
-	: exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),
+	: numStartupFrames_(kDefaultNumStartupFrames), regulationSpeed_(0.2),
+	  exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),
 	  relativeLuminanceTarget_(0)
 {
 }
@@ -554,10 +555,10 @@  double AgcMeanLuminance::effectiveYTarget() const
  */
 utils::Duration AgcMeanLuminance::filterExposure(utils::Duration exposureValue)
 {
-	double speed = 0.2;
+	double speed = regulationSpeed_;
 
 	/* Adapt instantly if we are in startup phase. */
-	if (frameCount_ < kNumStartupFrames)
+	if (frameCount_ < numStartupFrames_)
 		speed = 1.0;
 
 	/*
@@ -649,6 +650,22 @@  AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,
  * their configure() function.
  */
 
+/**
+ * \var AgcMeanLuminance::numStartupFrames_
+ * \brief The number of startup frames
+ *
+ * During this number of frames after startup, the regulation is very aggressive
+ * to reach the target value within one or two cycles.
+ *
+ * \var AgcMeanLuminance::regulationSpeed_
+ * The regulation speed. This controls the speed at which new target values are
+ * applied. The new target value is calculated as:
+ *
+ * \code{.unparsed}
+ * value = target * speed + oldValue * (1.0 - speed)
+ * \endcode
+ */
+
 } /* namespace ipa */
 
 } /* namespace libcamera */
diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h
index d7ec548e3e58..b176c3e28410 100644
--- a/src/ipa/libipa/agc_mean_luminance.h
+++ b/src/ipa/libipa/agc_mean_luminance.h
@@ -42,6 +42,7 @@  public:
 		double yTarget;
 	};
 
+protected:
 	void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);
 	int parseTuningData(const YamlObject &tuningData);
 
@@ -79,6 +80,9 @@  public:
 		frameCount_ = 0;
 	}
 
+	uint32_t numStartupFrames_;
+	double regulationSpeed_;
+
 private:
 	virtual double estimateLuminance(const double gain) const = 0;