Show a patch.

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

{
    "id": 24642,
    "url": "https://patchwork.libcamera.org/api/patches/24642/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24642/",
    "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": "<20251014142427.3107490-3-stefan.klug@ideasonboard.com>",
    "date": "2025-10-14T14:24:17",
    "name": "[v1,2/4] ipa: libipa: agc_mean_luminance: Change luminance target to piecewise linear function",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "fe965c1d80c80b05dc2b89b2a38154dcfe7c0a04",
    "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/24642/mbox/",
    "series": [
        {
            "id": 5502,
            "url": "https://patchwork.libcamera.org/api/series/5502/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5502",
            "date": "2025-10-14T14:24:15",
            "name": "libipa: agc: Fix constraints yTarget handling and add PWL support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5502/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24642/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24642/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 AC520BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Oct 2025 14:24:39 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 663E360600;\n\tTue, 14 Oct 2025 16:24:39 +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 A2D51605FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Oct 2025 16:24:37 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:61fb:8e55:ff1e:be62])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 49049E70;\n\tTue, 14 Oct 2025 16:22:59 +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=\"dE/+rTXi\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1760451779;\n\tbh=iuCCQkeQaqENPADjKbkX3uw3EpK81ZnZ2UFwEBdPKT0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=dE/+rTXijL5enoWqorZssd6jxV2rMJpyvsezJZZRWRppcPnNZnq5rLlVHKZjIp61X\n\tpa2zaNZukiDvqYukdGRJkTr/pyCEkgs5jEFB4PU+l49ULHpvB6JCckv6Ga9d0Wztk+\n\te6ygo9W6fojNZTRNNbv9hgEPM67Bp/a2sBy3FZLI=",
        "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>",
        "Subject": "[PATCH v1 2/4] ipa: libipa: agc_mean_luminance: Change luminance\n\ttarget to piecewise linear function",
        "Date": "Tue, 14 Oct 2025 16:24:17 +0200",
        "Message-ID": "<20251014142427.3107490-3-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.48.1",
        "In-Reply-To": "<20251014142427.3107490-1-stefan.klug@ideasonboard.com>",
        "References": "<20251014142427.3107490-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. This is a rework [1] to fit\ncurrent master.  For backwards compatibility of the tuning files and\neasier tuning file handling it is still allowed to specify the luminance\ntarget as plain value.\n\n[1] https://patchwork.libcamera.org/patch/20231/\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/libipa/agc_mean_luminance.cpp | 59 ++++++++++++++++++++++++---\n src/ipa/libipa/agc_mean_luminance.h   | 11 ++++-\n src/ipa/rkisp1/algorithms/agc.cpp     |  1 +\n 3 files changed, 63 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 64f36bd75dd2..62b1918a45a7 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@@ -145,16 +153,32 @@ static constexpr double kMaxRelativeLuminanceTarget = 0.95;\n \n AgcMeanLuminance::AgcMeanLuminance()\n \t: exposureCompensation_(1.0), frameCount_(0), filteredExposure_(0s),\n-\t  relativeLuminanceTarget_(0)\n+\t  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+\trelativeLuminanceTarget_.clear();\n+\n+\tauto &target = tuningData[\"relativeLuminanceTarget\"];\n+\tif (target.isValue()) {\n+\t\tdouble t = target.get<double>(kDefaultRelativeLuminanceTarget);\n+\t\trelativeLuminanceTarget_.append(0, t);\n+\t\treturn 0;\n+\t}\n+\n+\tstd::optional<Pwl> 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_.swap(*pwl);\n+\treturn 0;\n }\n \n void AgcMeanLuminance::parseConstraint(const YamlObject &modeDict, int32_t id)\n@@ -385,7 +409,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 +429,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 +574,18 @@ 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\tLOG(AgcMeanLuminance, Debug)\n+\t\t\t<< \"Missing lux value for luminance target calculation, default to \"\n+\t\t\t<< kDefaultLuxLevel;\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 d7ec548e3e58..1fbff304a72b 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@@ -81,8 +87,8 @@ public:\n \n private:\n \tvirtual double estimateLuminance(const double gain) const = 0;\n+\tint parseRelativeLuminanceTarget(const YamlObject &tuningData);\n \n-\tvoid 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@@ -95,7 +101,8 @@ private:\n \tdouble exposureCompensation_;\n \tuint64_t frameCount_;\n \tutils::Duration filteredExposure_;\n-\tdouble relativeLuminanceTarget_;\n+\tunsigned int lux_;\n+\tPwl relativeLuminanceTarget_;\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": [
        "v1",
        "2/4"
    ]
}