Show a patch.

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

{
    "id": 24982,
    "url": "https://patchwork.libcamera.org/api/patches/24982/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24982/",
    "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": "<20251106164239.460738-3-stefan.klug@ideasonboard.com>",
    "date": "2025-11-06T16:42:26",
    "name": "[v2,2/3] ipa: libipa: agc_mean_luminance: Change luminance target to piecewise linear function",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "fc5bd7daf69cad3cc2188cdff892eb7736916de1",
    "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/24982/mbox/",
    "series": [
        {
            "id": 5567,
            "url": "https://patchwork.libcamera.org/api/series/5567/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5567",
            "date": "2025-11-06T16:42:24",
            "name": "libipa: agc: Fix constraints yTarget handling and add PWL support",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5567/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24982/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24982/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 36E8ABDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Nov 2025 16:42:51 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E308E60A8B;\n\tThu,  6 Nov 2025 17:42:50 +0100 (CET)",
            "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 BA19D609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Nov 2025 17:42:49 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:1d00:3bae:f27:7601])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 9A0097CE;\n\tThu,  6 Nov 2025 17:40:54 +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=\"R0zgdBP0\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762447254;\n\tbh=M6KX1O2mGKCVZ/D1uI2P+saU7mWUPYtGNeFPiJTo+ME=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=R0zgdBP0Fx2kF6PSbRsSKb+cV6qrmnyL5vK5VkLXNuI4/3ptVIFKG70VVJnVSGzMb\n\tZ+BoR4okER0u1sA5wkGPWeiWoaJxIMryBuK7Is6qDs7jp5ssdgRADxB1Hlh30Ta9mn\n\th4baPLopfddtJzxss+XtT5r0WIHV1zz9f++J73TU=",
        "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 v2 2/3] ipa: libipa: agc_mean_luminance: Change luminance\n\ttarget to piecewise linear function",
        "Date": "Thu,  6 Nov 2025 17:42:26 +0100",
        "Message-ID": "<20251106164239.460738-3-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.51.0",
        "In-Reply-To": "<20251106164239.460738-1-stefan.klug@ideasonboard.com>",
        "References": "<20251106164239.460738-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. As the PWL loading code loads a plain value as single\npoint PWL, backwards compatibility to existing tuning files is ensured.\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>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n---\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 | 51 +++++++++++++++++++++++----\n src/ipa/libipa/agc_mean_luminance.h   | 11 ++++--\n src/ipa/rkisp1/algorithms/agc.cpp     |  1 +\n 3 files changed, 55 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 64f36bd75dd2..b80af92a2c0f 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,24 @@ 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+\tauto &target = tuningData[\"relativeLuminanceTarget\"];\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@@ -385,7 +401,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 +421,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 +566,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": [
        "v2",
        "2/3"
    ]
}