{"id":27467,"url":"https://patchwork.libcamera.org/api/patches/27467/?format=json","web_url":"https://patchwork.libcamera.org/patch/27467/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260723154327.1357866-19-barnabas.pocze@ideasonboard.com>","date":"2026-07-23T15:43:01","name":"[RFC,v2,18/43] ipa: libipa: agc_mean_luminance: Remove persistent params","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"dc0433f2046dd7bf7e4c7eb4c33ae592f25316b7","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27467/mbox/","series":[{"id":6075,"url":"https://patchwork.libcamera.org/api/series/6075/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6075","date":"2026-07-23T15:42:43","name":"ipa: libipa: agc rework","version":2,"mbox":"https://patchwork.libcamera.org/series/6075/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27467/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27467/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id EBE82C3303\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jul 2026 15:43:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7873867F3C;\n\tThu, 23 Jul 2026 17:43:58 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E5FB467EE0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:43:34 +0200 (CEST)","from pb-laptop.local (185.182.215.156.nat.pool.zt.hu\n\t[185.182.215.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 10AB41C37\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:42:34 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kgoShcmT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1784821354;\n\tbh=2gBIBSGVZe6CFk459kjlDy3CLc4okzrbkmA9hkrsVDY=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kgoShcmTyS5HuuxbuHzzyAZ6RVX4Fm/Mm0GgjPVTkKyFPIOB9+Nkol6dZCSiV0zEW\n\trRoUkP2nlVf3vs/AKEvj52YMD/XW6wBsmaZZYH4O6XTVeTmu4ECUFE0KdGkT/adXpw\n\tKxFIXEmHHEyyeYHuEYZ2tnD2+FlGyoBVBNqQDRvU=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[RFC PATCH v2 18/43] ipa: libipa: agc_mean_luminance: Remove\n\tpersistent params","Date":"Thu, 23 Jul 2026 17:43:01 +0200","Message-ID":"<20260723154327.1357866-19-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.55.0","In-Reply-To":"<20260723154327.1357866-1-barnabas.pocze@ideasonboard.com>","References":"<20260723154327.1357866-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Remove `set{Lux,ExposureCompensation}()` and pass them via `Params`.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/libipa/agc_mean_luminance.cpp | 62 +++++++++++----------------\n src/ipa/libipa/agc_mean_luminance.h   | 20 ++-------\n src/ipa/rkisp1/algorithms/agc.cpp     |  7 ++-\n 3 files changed, 31 insertions(+), 58 deletions(-)","diff":"diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex d25b1e8322..38c9588e46 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -178,8 +178,7 @@ static constexpr unsigned int kDefaultLuxLevel = 500;\n  */\n \n AgcMeanLuminance::AgcMeanLuminance()\n-\t: filteredExposure_(0s), luxWarningEnabled_(true),\n-\t  exposureCompensation_(1.0), frameCount_(0), lux_(0)\n+\t: filteredExposure_(0s), luxWarningEnabled_(true), frameCount_(0)\n {\n }\n \n@@ -441,25 +440,6 @@ int AgcMeanLuminance::parseTuningData(const ValueNode &tuningData)\n \treturn parseExposureModes(tuningData);\n }\n \n-/**\n- * \\fn AgcMeanLuminance::setExposureCompensation()\n- * \\brief Set the exposure compensation value\n- * \\param[in] gain The exposure compensation gain\n- *\n- * This function sets the exposure compensation value to be used in the\n- * AGC calculations. It is expressed as gain instead of EV.\n- */\n-\n-/**\n- * \\fn AgcMeanLuminance::setLux(int lux)\n- * \\brief Set the lux level\n- * \\param[in] lux The lux level\n- *\n- * This function sets the lux level to be used in the AGC calculations. A value\n- * of 0 means no measurement and a default value of \\a kDefaultLuxLevel is used\n- * if necessary.\n- */\n-\n /**\n  * \\brief Set the ExposureModeHelper limits for this class\n  * \\param[in] minExposureTime Minimum exposure time to allow\n@@ -530,26 +510,23 @@ double AgcMeanLuminance::estimateInitialGain(const Traits &traits, double yTarge\n \n /**\n  * \\brief Clamp gain within the bounds of a defined constraint\n- * \\param[in] constraintModeIndex The index of the constraint to adhere to\n- * \\param[in] hist A histogram over which to calculate inter-quantile means\n+ * \\param[in] params The set of parameters for the calculation\n  * \\param[in] gain The gain to clamp\n  *\n  * \\return The gain clamped within the constraint bounds\n  */\n-double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n-\t\t\t\t\t     const Histogram &hist,\n-\t\t\t\t\t     double gain) const\n+double AgcMeanLuminance::constraintClampGain(const Params &params, double gain) const\n {\n-\tauto applyConstraint = [this, &gain, &hist](const AgcConstraint &constraint) {\n-\t\tdouble lux = lux_;\n+\tauto applyConstraint = [&](const AgcConstraint &constraint) {\n+\t\tdouble lux = params.lux;\n \n-\t\tif (relativeLuminanceTarget_.size() > 1 && lux_ == 0)\n+\t\tif (relativeLuminanceTarget_.size() > 1 && lux == 0)\n \t\t\tlux = kDefaultLuxLevel;\n \n \t\tdouble target = constraint.yTarget.eval(\n \t\t\tconstraint.yTarget.domain().clamp(lux));\n-\t\tdouble newGain = target * hist.bins() /\n-\t\t\t\t hist.interQuantileMean(constraint.qLo, constraint.qHi);\n+\t\tdouble newGain = target * params.yHist.bins() /\n+\t\t\t\t params.yHist.interQuantileMean(constraint.qLo, constraint.qHi);\n \n \t\tif (constraint.bound == AgcConstraint::Bound::Lower &&\n \t\t    newGain > gain) {\n@@ -568,7 +545,7 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t}\n \t};\n \n-\tconst std::vector<AgcConstraint> &constraints = constraintModes_.at(constraintModeIndex);\n+\tconst std::vector<AgcConstraint> &constraints = constraintModes_.at(params.constraintModeIndex);\n \tstd::for_each(constraints.begin(), constraints.end(), applyConstraint);\n \n \tstd::for_each(additionalConstraints_.begin(), additionalConstraints_.end(), applyConstraint);\n@@ -578,15 +555,16 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \n /**\n  * \\brief Get the currently effective y target\n+ * \\param[in] lux The effective lux value\n+ * \\param[in] exposureCompensation The exposure compensation value\n  *\n  * This function returns the current y target including exposure compensation.\n  *\n  * \\return The y target value\n  */\n-double AgcMeanLuminance::effectiveYTarget() const\n+double AgcMeanLuminance::effectiveYTarget(double lux, double exposureCompensation) const\n {\n-\tdouble lux = lux_;\n-\tif (relativeLuminanceTarget_.size() > 1 && lux_ == 0) {\n+\tif (relativeLuminanceTarget_.size() > 1 && lux == 0) {\n \t\t/*\n \t\t * Warn after a few frames if there is still no lux measurement\n \t\t * available. The number of 10 is chosen a bit arbitrarily. It\n@@ -610,7 +588,7 @@ double AgcMeanLuminance::effectiveYTarget() const\n \tdouble luminanceTarget = relativeLuminanceTarget_.eval(\n \t\trelativeLuminanceTarget_.domain().clamp(lux));\n \n-\treturn std::min(luminanceTarget * exposureCompensation_,\n+\treturn std::min(luminanceTarget * exposureCompensation,\n \t\t\tkMaxRelativeLuminanceTarget);\n }\n \n@@ -665,6 +643,14 @@ utils::Duration AgcMeanLuminance::filterExposure(utils::Duration exposureValue)\n  *\n  * \\var AgcMeanLuminance::Params::exposureModeIndex\n  * \\brief The index of the exposure mode to use\n+ *\n+ * \\var AgcMeanLuminance::Params::lux\n+ * \\brief The lux level to be used in the AGC calculations. A value of 0 means no\n+ * measurement and a default value of \\a kDefaultLuxLevel is used if necessary.\n+ *\n+ * \\var AgcMeanLuminance::Params::exposureCompensation\n+ * \\brief The exposure compensation value to be used in the AGC calculations.\n+ * It is expressed as gain instead of EV.\n  */\n \n /**\n@@ -696,7 +682,7 @@ AgcMeanLuminance::calculateNewEv(const Params &params)\n \t */\n \tExposureModeHelper &exposureModeHelper =\n \t\texposureModeHelpers_.at(params.exposureModeIndex);\n-\tdouble yTarget = effectiveYTarget();\n+\tdouble yTarget = effectiveYTarget(params.lux, params.exposureCompensation);\n \n \tif (params.effectiveExposureValue == 0s) {\n \t\tLOG(AgcMeanLuminance, Error)\n@@ -711,7 +697,7 @@ AgcMeanLuminance::calculateNewEv(const Params &params)\n \t}\n \n \tdouble gain = estimateInitialGain(params.traits, yTarget);\n-\tgain = constraintClampGain(params.constraintModeIndex, params.yHist, gain);\n+\tgain = constraintClampGain(params, gain);\n \n \t/*\n \t * We don't check whether we're already close to the target, because\ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex 6418fe2e65..5e986be008 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -50,16 +50,6 @@ public:\n \tvoid configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);\n \tint parseTuningData(const ValueNode &tuningData);\n \n-\tvoid setExposureCompensation(double gain)\n-\t{\n-\t\texposureCompensation_ = gain;\n-\t}\n-\n-\tvoid setLux(unsigned int lux)\n-\t{\n-\t\tlux_ = lux;\n-\t}\n-\n \tvoid setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,\n \t\t       double minGain, double maxGain, std::vector<AgcConstraint> constraints);\n \n@@ -84,6 +74,8 @@ public:\n \t\tutils::Duration effectiveExposureValue;\n \t\tuint32_t constraintModeIndex;\n \t\tuint32_t exposureModeIndex;\n+\t\tdouble lux = 0;\n+\t\tdouble exposureCompensation = 1;\n \t};\n \n \tstruct Result : ExposureModeHelper::Result {\n@@ -92,7 +84,7 @@ public:\n \n \t[[nodiscard]] Result calculateNewEv(const Params &params);\n \n-\tdouble effectiveYTarget() const;\n+\tdouble effectiveYTarget(double lux, double exposureCompensation) const;\n \n \tvoid resetFrameCount()\n \t{\n@@ -105,17 +97,13 @@ private:\n \tint parseConstraintModes(const ValueNode &tuningData);\n \tint parseExposureModes(const ValueNode &tuningData);\n \tdouble estimateInitialGain(const Traits &traits, double yTarget) const;\n-\tdouble constraintClampGain(uint32_t constraintModeIndex,\n-\t\t\t\t   const Histogram &hist,\n-\t\t\t\t   double gain) const;\n+\tdouble constraintClampGain(const Params &params, double gain) const;\n \tutils::Duration filterExposure(utils::Duration exposureValue);\n \n \tutils::Duration filteredExposure_;\n \tmutable bool luxWarningEnabled_;\n-\tdouble exposureCompensation_;\n \tPwl relativeLuminanceTarget_;\n \tuint64_t frameCount_;\n-\tunsigned int lux_;\n \n \tstd::vector<AgcConstraint> additionalConstraints_;\n \tstd::map<int32_t, std::vector<AgcConstraint>> constraintModes_;\ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 8ed9d7ea6d..fc228452c3 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -294,7 +294,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \t\t       context.configuration.sensor.minAnalogueGain,\n \t\t       context.configuration.sensor.maxAnalogueGain, {});\n \n-\tcontext.activeState.agc.automatic.yTarget = agc_.effectiveYTarget();\n+\tcontext.activeState.agc.automatic.yTarget = agc_.effectiveYTarget(0, 1);\n \n \tagc_.resetFrameCount();\n \n@@ -717,9 +717,6 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \tHistogram hist({ params->hist.hist_bins, context.hw.numHistogramBins },\n \t\t       [](uint32_t x) { return x >> 4; });\n \n-\tagc_.setExposureCompensation(pow(2.0, frameContext.agc.exposureValue));\n-\tagc_.setLux(frameContext.lux.lux);\n-\n \tconst auto &newEv = agc_.calculateNewEv({\n \t\t.traits = AgcTraits{\n \t\t\t{ params->ae.exp_mean, context.hw.numAeCells },\n@@ -729,6 +726,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\t.effectiveExposureValue = effectiveExposureValue,\n \t\t.constraintModeIndex = frameContext.agc.constraintMode,\n \t\t.exposureModeIndex = frameContext.agc.exposureMode,\n+\t\t.lux = frameContext.lux.lux,\n+\t\t.exposureCompensation = pow(2.0, frameContext.agc.exposureValue),\n \t});\n \n \tLOG(RkISP1Agc, Debug)\n","prefixes":["RFC","v2","18/43"]}