Show a patch.

GET /api/1.1/patches/24126/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 24126,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/24126/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24126/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20250815102945.1602071-17-stefan.klug@ideasonboard.com>",
    "date": "2025-08-15T10:29:36",
    "name": "[v3,16/19] libipa: agc_mean_luminance: Add support for additional constraints",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4249eb6a74ef61297ba3bf867cfae528a41cde10",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24126/mbox/",
    "series": [
        {
            "id": 5382,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5382/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5382",
            "date": "2025-08-15T10:29:20",
            "name": "Implement WDR algorithm",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/5382/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24126/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24126/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 A9D51BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Aug 2025 10:30:43 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5F1256926A;\n\tFri, 15 Aug 2025 12:30:43 +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 A42C46926D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Aug 2025 12:30:40 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:83d1:ae5d:93a6:6837])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id A399F19E5; \n\tFri, 15 Aug 2025 12:29:45 +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=\"jR9eb4oB\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755253785;\n\tbh=rvYLu+sse6RTu8xpvp2r74SR5Ehd1XYkA9eT8aVfSTM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=jR9eb4oBAv1RHrDWWL5w+k5l+lNOygzIGfmkVzoNYGJeSIEEMT8S3wzt7UiVjiftf\n\tBxlNgLr7PO/3Z8ob43K3/cItaP4dLw4gJJd+uD1FOR9aNAISEsXmgiFxJnabm3MEWg\n\t65xYHdcxgKq0j9/SXiXh7D3qubVSUO7QCKMKkasc=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v3 16/19] libipa: agc_mean_luminance: Add support for\n\tadditional constraints",
        "Date": "Fri, 15 Aug 2025 12:29:36 +0200",
        "Message-ID": "<20250815102945.1602071-17-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.48.1",
        "In-Reply-To": "<20250815102945.1602071-1-stefan.klug@ideasonboard.com>",
        "References": "<20250815102945.1602071-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": "Add support for additional constraints added at runtime. This is for\nexample useful for WDR use cases where you want to add a upper\nconstraint to limit the amount of saturated pixels.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v3:\n- Added this patch\n---\n src/ipa/ipu3/algorithms/agc.cpp       |  2 +-\n src/ipa/libipa/agc_mean_luminance.cpp | 16 ++++++++++++----\n src/ipa/libipa/agc_mean_luminance.h   |  3 ++-\n src/ipa/mali-c55/algorithms/agc.cpp   |  3 ++-\n src/ipa/rkisp1/algorithms/agc.cpp     |  4 ++--\n 5 files changed, 19 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex da045640d569..b0d89541da85 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -117,7 +117,7 @@ int Agc::configure(IPAContext &context,\n \n \t/* \\todo Run this again when FrameDurationLimits is passed in */\n \tsetLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_,\n-\t\t  maxAnalogueGain_);\n+\t\t  maxAnalogueGain_, {});\n \tresetFrameCount();\n \n \treturn 0;\ndiff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 2bfafe9b2d02..5cd5d9ad2012 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -7,6 +7,7 @@\n \n #include \"agc_mean_luminance.h\"\n \n+#include <algorithm>\n #include <cmath>\n \n #include <libcamera/base/log.h>\n@@ -414,10 +415,13 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)\n  */\n void AgcMeanLuminance::setLimits(utils::Duration minExposureTime,\n \t\t\t\t utils::Duration maxExposureTime,\n-\t\t\t\t double minGain, double maxGain)\n+\t\t\t\t double minGain, double maxGain,\n+\t\t\t\t std::vector<AgcMeanLuminance::AgcConstraint> constraints)\n {\n \tfor (auto &[id, helper] : exposureModeHelpers_)\n \t\thelper->setLimits(minExposureTime, maxExposureTime, minGain, maxGain);\n+\n+\tadditionalConstraints_ = std::move(constraints);\n }\n \n /**\n@@ -495,8 +499,7 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t\t     const Histogram &hist,\n \t\t\t\t\t     double gain)\n {\n-\tstd::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n-\tfor (const AgcConstraint &constraint : constraints) {\n+\tauto applyConstraint = [&gain, &hist](const AgcConstraint &constraint) {\n \t\tdouble newGain = constraint.yTarget * hist.bins() /\n \t\t\t\t hist.interQuantileMean(constraint.qLo, constraint.qHi);\n \n@@ -515,7 +518,12 @@ double AgcMeanLuminance::constraintClampGain(uint32_t constraintModeIndex,\n \t\t\t\t<< newGain;\n \t\t\tgain = newGain;\n \t\t}\n-\t}\n+\t};\n+\n+\tstd::vector<AgcConstraint> &constraints = constraintModes_[constraintModeIndex];\n+\tstd::for_each(constraints.begin(), constraints.end(), applyConstraint);\n+\n+\tstd::for_each(additionalConstraints_.begin(), additionalConstraints_.end(), applyConstraint);\n \n \treturn gain;\n }\ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex 950b7b893754..d7ec548e3e58 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -51,7 +51,7 @@ public:\n \t}\n \n \tvoid setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,\n-\t\t       double minGain, double maxGain);\n+\t\t       double minGain, double maxGain, std::vector<AgcConstraint> constraints);\n \n \tstd::map<int32_t, std::vector<AgcConstraint>> constraintModes()\n \t{\n@@ -97,6 +97,7 @@ private:\n \tutils::Duration filteredExposure_;\n \tdouble relativeLuminanceTarget_;\n \n+\tstd::vector<AgcConstraint> additionalConstraints_;\n \tstd::map<int32_t, std::vector<AgcConstraint>> constraintModes_;\n \tstd::map<int32_t, std::shared_ptr<ExposureModeHelper>> exposureModeHelpers_;\n \tControlInfoMap::Map controls_;\ndiff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp\nindex 88f8664c9823..f60fddac3f04 100644\n--- a/src/ipa/mali-c55/algorithms/agc.cpp\n+++ b/src/ipa/mali-c55/algorithms/agc.cpp\n@@ -173,7 +173,8 @@ int Agc::configure(IPAContext &context,\n \tsetLimits(context.configuration.agc.minShutterSpeed,\n \t\t  context.configuration.agc.maxShutterSpeed,\n \t\t  context.configuration.agc.minAnalogueGain,\n-\t\t  context.configuration.agc.maxAnalogueGain);\n+\t\t  context.configuration.agc.maxAnalogueGain,\n+\t\t  {});\n \n \tresetFrameCount();\n \ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex ba617a4e6e0c..d566a3fbef4a 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -205,7 +205,7 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n \tsetLimits(context.configuration.sensor.minExposureTime,\n \t\t  context.configuration.sensor.maxExposureTime,\n \t\t  context.configuration.sensor.minAnalogueGain,\n-\t\t  context.configuration.sensor.maxAnalogueGain);\n+\t\t  context.configuration.sensor.maxAnalogueGain, {});\n \n \tresetFrameCount();\n \n@@ -589,7 +589,7 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\tmaxAnalogueGain = frameContext.agc.gain;\n \t}\n \n-\tsetLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain);\n+\tsetLimits(minExposureTime, maxExposureTime, minAnalogueGain, maxAnalogueGain, {});\n \n \t/*\n \t * The Agc algorithm needs to know the effective exposure value that was\n",
    "prefixes": [
        "v3",
        "16/19"
    ]
}