Patch Detail
Show a patch.
GET /api/patches/25083/?format=api
{ "id": 25083, "url": "https://patchwork.libcamera.org/api/patches/25083/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25083/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20251119132221.2088013-4-stefan.klug@ideasonboard.com>", "date": "2025-11-19T13:22:12", "name": "[v3,3/4] ipa: libipa: agc_mean_luminance: Change luminance target to piecewise linear function", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "ad8f6db8bb9db32465eb756ab8fbfb83d08245ab", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/25083/mbox/", "series": [ { "id": 5595, "url": "https://patchwork.libcamera.org/api/series/5595/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5595", "date": "2025-11-19T13:22:09", "name": "libipa: agc: Fix constraints yTarget handling and add PWL support", "version": 3, "mbox": "https://patchwork.libcamera.org/series/5595/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25083/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25083/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 B680CBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 Nov 2025 13:22:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64CA260A8A;\n\tWed, 19 Nov 2025 14:22:35 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D2D7460AA6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Nov 2025 14:22:33 +0100 (CET)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:5419:7bb:83a3:3d7a])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 586BA195E; \n\tWed, 19 Nov 2025 14:20:29 +0100 (CET)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vvVs+p2j\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763558429;\n\tbh=Nu7ekdtDTkFc9AlZtqRWG3n4bm6C+ZbPzmrwgSzVUUk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=vvVs+p2jjc2q7Eo/VlpfFrc/m+r9RDJQdt0eSDBQkE0RVUXReZd5tMifLApQGjnUy\n\thPzTCYsfXRUUHraMOb20UKEJHhdlfADcIRGpKMeadMs5X9CBPdbxfC9nS/mCPf0Mgz\n\tGTBjrAx8LCbCDNI7K71mZ0deGtl74/vB8IKSUPVE=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>", "Subject": "[PATCH v3 3/4] ipa: libipa: agc_mean_luminance: Change luminance\n\ttarget to piecewise linear function", "Date": "Wed, 19 Nov 2025 14:22:12 +0100", "Message-ID": "<20251119132221.2088013-4-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.51.0", "In-Reply-To": "<20251119132221.2088013-1-stefan.klug@ideasonboard.com>", "References": "<20251119132221.2088013-1-stefan.klug@ideasonboard.com>", "MIME-Version": "1.0", "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": "In some situations it is necessary to specify the target brightness\nvalue depending on the overall lux level. Replace the float\nrelativeLuminanceTraget by a PWL. As the PWL loading code loads a plain\nvalue as single point PWL, backwards compatibility to existing tuning\nfiles is ensured.\n\nWhile at it, order the class members in reverse xmas tree notation.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n---\n\nChanges in v3:\n- Dropped reference to original patch from commit message. For the\n record, the old patch was https://patchwork.libcamera.org/patch/20231/\n- Ordered member variables in reverse xmas tree order\n- Fallback to kDefaultRelativeLuminanceTarget if relativeLuminanceTraget\n is missing in the tuning file\n- Warn once if lux level is not available after a few frames\n\nChanges in v2:\n- Collected tags\n- Dropped special handling of plain values, as this is now part of the\n yaml PWL loader.\n---\n src/ipa/libipa/agc_mean_luminance.cpp | 67 ++++++++++++++++++++++++---\n src/ipa/libipa/agc_mean_luminance.h | 14 ++++--\n src/ipa/rkisp1/algorithms/agc.cpp | 1 +\n 3 files changed, 72 insertions(+), 10 deletions(-)", "diff": "diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 64f36bd75dd2..4f2b5fad2082 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -54,6 +54,14 @@ static constexpr double kDefaultRelativeLuminanceTarget = 0.16;\n */\n static constexpr double kMaxRelativeLuminanceTarget = 0.95;\n \n+/*\n+ * Default lux level\n+ *\n+ * If no lux level or a zero lux level is specified, but PWLs are used to\n+ * specify luminance targets, this default level is used.\n+ */\n+static constexpr unsigned int kDefaultLuxLevel = 500;\n+\n /**\n * \\struct AgcMeanLuminance::AgcConstraint\n * \\brief The boundaries and target for an AeConstraintMode constraint\n@@ -144,17 +152,30 @@ static constexpr double kMaxRelativeLuminanceTarget = 0.95;\n */\n \n AgcMeanLuminance::AgcMeanLuminance()\n-\t: exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),\n-\t relativeLuminanceTarget_(0)\n+\t: filteredExposure_(0s), luxWarningEnabled_(true),\n+\t exposureCompensation_(1.0), frameCount_(0), lux_(0)\n {\n }\n \n AgcMeanLuminance::~AgcMeanLuminance() = default;\n \n-void AgcMeanLuminance::parseRelativeLuminanceTarget(const YamlObject &tuningData)\n+int AgcMeanLuminance::parseRelativeLuminanceTarget(const YamlObject &tuningData)\n {\n-\trelativeLuminanceTarget_ =\n-\t\ttuningData[\"relativeLuminanceTarget\"].get<double>(kDefaultRelativeLuminanceTarget);\n+\tauto &target = tuningData[\"relativeLuminanceTarget\"];\n+\tif (!target) {\n+\t\trelativeLuminanceTarget_ = { { { { 0.0, kDefaultRelativeLuminanceTarget } } } };\n+\t\treturn 0;\n+\t}\n+\n+\tauto pwl = target.get<Pwl>();\n+\tif (!pwl) {\n+\t\tLOG(AgcMeanLuminance, Error)\n+\t\t\t<< \"Failed to load relative luminance target.\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\trelativeLuminanceTarget_ = std::move(*pwl);\n+\treturn 0;\n }\n \n void AgcMeanLuminance::parseConstraint(const YamlObject &modeDict, int32_t id)\n@@ -325,6 +346,8 @@ void AgcMeanLuminance::configure(utils::Duration lineDuration,\n {\n \tfor (auto &[id, helper] : exposureModeHelpers_)\n \t\thelper->configure(lineDuration, sensorHelper);\n+\n+\tluxWarningEnabled_ = true;\n }\n \n /**\n@@ -385,7 +408,9 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)\n {\n \tint ret;\n \n-\tparseRelativeLuminanceTarget(tuningData);\n+\tret = parseRelativeLuminanceTarget(tuningData);\n+\tif (ret)\n+\t\treturn ret;\n \n \tret = parseConstraintModes(tuningData);\n \tif (ret)\n@@ -403,6 +428,16 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)\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@@ -538,7 +573,25 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n */\n double AgcMeanLuminance::effectiveYTarget() const\n {\n-\treturn std::min(relativeLuminanceTarget_ * exposureCompensation_,\n+\tdouble lux = lux_;\n+\tif (relativeLuminanceTarget_.size() > 1 && lux_ == 0) {\n+\t\tif (frameCount_ > 10 && luxWarningEnabled_) {\n+\t\t\tluxWarningEnabled_ = false;\n+\t\t\tLOG(AgcMeanLuminance, Warning)\n+\t\t\t\t<< \"Missing lux value for luminance target \"\n+\t\t\t\t \"calculation, default to \"\n+\t\t\t\t<< kDefaultLuxLevel\n+\t\t\t\t<< \". Note that the Lux algorithm must be \"\n+\t\t\t\t \"included before the Agc algorithm.\";\n+\t\t}\n+\n+\t\tlux = kDefaultLuxLevel;\n+\t}\n+\n+\tdouble luminanceTarget = relativeLuminanceTarget_.eval(\n+\t\trelativeLuminanceTarget_.domain().clamp(lux));\n+\n+\treturn std::min(luminanceTarget * exposureCompensation_,\n \t\t\tkMaxRelativeLuminanceTarget);\n }\n \ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex e5f164c3186b..746b97b16ffe 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -20,6 +20,7 @@\n \n #include \"exposure_mode_helper.h\"\n #include \"histogram.h\"\n+#include \"pwl.h\"\n \n namespace libcamera {\n \n@@ -50,6 +51,11 @@ public:\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@@ -82,7 +88,7 @@ public:\n private:\n \tvirtual double estimateLuminance(const double gain) const = 0;\n \n-\tvoid parseRelativeLuminanceTarget(const YamlObject &tuningData);\n+\tint parseRelativeLuminanceTarget(const YamlObject &tuningData);\n \tvoid parseConstraint(const YamlObject &modeDict, int32_t id);\n \tint parseConstraintModes(const YamlObject &tuningData);\n \tint parseExposureModes(const YamlObject &tuningData);\n@@ -92,10 +98,12 @@ private:\n \t\t\t\t double gain);\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-\tutils::Duration filteredExposure_;\n-\tdouble relativeLuminanceTarget_;\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 f5a3c917cb69..1ecaff680978 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -618,6 +618,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\teffectiveExposureValue *= frameContext.agc.quantizationGain;\n \n \tsetExposureCompensation(pow(2.0, frameContext.agc.exposureValue));\n+\tsetLux(frameContext.lux.lux);\n \n \tutils::Duration newExposureTime;\n \tdouble aGain, qGain, dGain;\n", "prefixes": [ "v3", "3/4" ] }