Show a patch.

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

{
    "id": 27472,
    "url": "https://patchwork.libcamera.org/api/patches/27472/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27472/",
    "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": "<20260723154327.1357866-23-barnabas.pocze@ideasonboard.com>",
    "date": "2026-07-23T15:43:05",
    "name": "[RFC,v2,22/43] ipa: libipa: agc: Clamp exposure value",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "1ab20c7b9e34cdeb65d326df69891bf8cde9609c",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27472/mbox/",
    "series": [
        {
            "id": 6075,
            "url": "https://patchwork.libcamera.org/api/series/6075/?format=api",
            "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/27472/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27472/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 AF2BFC3308\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Jul 2026 15:44:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 468C867F1D;\n\tThu, 23 Jul 2026 17:44:07 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EEB0967EC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:43:35 +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 19DDC1C37\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Jul 2026 17:42:35 +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=\"aLtw0KBf\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1784821355;\n\tbh=r7fms7akk/zwjiuHiG6GIK0QnaIjwx2y4+nqZtRnBa0=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=aLtw0KBfP2ruDa9VtCeEq4d5CQDtK04I2K0TWomdy9Y4VBCUFqxSnhnqLVvlEOnuK\n\tj4pCnd4ycj2qQ0EbgVIuB7rQoK+/waRpmbrSvc9DxDbWibEx+ubdtGJUHY06eMo+Lk\n\t4A6eF6hZvmDXvpP3HGb1HQ8ZWTQGBefSvFsl2TlQ=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[RFC PATCH v2 22/43] ipa: libipa: agc: Clamp exposure value",
        "Date": "Thu, 23 Jul 2026 17:43:05 +0200",
        "Message-ID": "<20260723154327.1357866-23-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": "It is possible that the minimum exposure time in microseconds is not an\ninteger. In that case the minimum `ExposureTime` in the `ControlInfo` will\ntherefore be actually lower than the real minimum. This can cause issues:\nif the minimum published exposure time is set, the division when setting\n`agc.manual.exposure` might produce a value in [0;1), leading to the manual\nexposure being set to 0, leading to an assertion failure in\n`ExposureModeHelper::splitExposure()`.\n\nNote that this is theoretically possible even when the exposure time is\ndetermined automatically by `AgcMeanLuminance`.\n\nStore the true integer limits of the exposure as well, and ensure that\nthe exposure (time) -> exposure (line) conversions always clamp.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n src/ipa/libipa/agc.cpp | 27 ++++++++++++++++++++++++---\n src/ipa/libipa/agc.h   |  2 ++\n 2 files changed, 26 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/src/ipa/libipa/agc.cpp b/src/ipa/libipa/agc.cpp\nindex e16a02fdde..8a2525ec98 100644\n--- a/src/ipa/libipa/agc.cpp\n+++ b/src/ipa/libipa/agc.cpp\n@@ -38,6 +38,12 @@ LOG_DEFINE_CATEGORY(Agc)\n  * \\struct agc::Session\n  * \\brief Session configuration for AgcAlgorithm\n  *\n+ * \\var agc::Session::minExposure\n+ * \\brief Minimum exposure (in lines) supported with the configured sensor\n+ *\n+ * \\var agc::Session::maxExposure\n+ * \\brief Maximum exposure (in lines) supported with the configured sensor\n+ *\n  * \\var agc::Session::minExposureTime\n  * \\brief Minimum exposure time supported with the configured sensor\n  *\n@@ -223,6 +229,19 @@ LOG_DEFINE_CATEGORY(Agc)\n  * \\brief Effective lux value of the frame\n  */\n \n+namespace {\n+\n+[[nodiscard]] uint32_t clampExposure(utils::Duration exposureTime, const agc::Session &session)\n+{\n+\treturn std::clamp<uint32_t>(\n+\t\texposureTime / session.lineDuration,\n+\t\tsession.minExposure,\n+\t\tsession.maxExposure\n+\t);\n+}\n+\n+} /* namespace */\n+\n /**\n  * \\brief Load tuning data\n  */\n@@ -317,6 +336,8 @@ int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state, cons\n \t *\n \t * \\todo take VBLANK into account for maximum exposure time\n \t */\n+\tsession.minExposure = minExposure;\n+\tsession.maxExposure = maxExposure;\n \tsession.minExposureTime = minExposure * session.lineDuration;\n \tsession.maxExposureTime = maxExposure * session.lineDuration;\n \tsession.minAnalogueGain = minGain;\n@@ -331,7 +352,7 @@ int AgcAlgorithm::configure(agc::Session &session, agc::ActiveState &state, cons\n \t/* Configure the default exposure and gain. */\n \tstate = {};\n \tstate.automatic.gain = session.minAnalogueGain;\n-\tstate.automatic.exposure = 10ms / session.lineDuration;\n+\tstate.automatic.exposure = clampExposure(10ms, session);\n \tstate.automatic.quantizationGain = 1;\n \tstate.automatic.yTarget = impl_.effectiveYTarget(0, 1);\n \tstate.manual.gain = state.automatic.gain;\n@@ -437,7 +458,7 @@ void AgcAlgorithm::queueRequest(const agc::Session &session, agc::ActiveState &s\n \n \tconst auto &exposure = controls.get(controls::ExposureTime);\n \tif (exposure && !state.autoExposureEnabled) {\n-\t\tstate.manual.exposure = *exposure * 1.0us / session.lineDuration;\n+\t\tstate.manual.exposure = clampExposure(*exposure * 1us, session);\n \n \t\tLOG(Agc, Debug)\n \t\t\t<< \"Set exposure to \" << state.manual.exposure;\n@@ -599,7 +620,7 @@ void AgcAlgorithm::process(const agc::Session &session, agc::ActiveState &state,\n \t\t\t<< \", \" << newEv.quantizationGain << \" and \" << newEv.digitalGain;\n \n \t\t/* Update the estimated exposure and gain. */\n-\t\tstate.automatic.exposure = newEv.exposureTime / lineDuration;\n+\t\tstate.automatic.exposure = clampExposure(newEv.exposureTime, session);\n \t\tstate.automatic.gain = newEv.analogueGain;\n \t\tstate.automatic.quantizationGain = newEv.quantizationGain;\n \t\tstate.automatic.yTarget = newEv.yTarget;\ndiff --git a/src/ipa/libipa/agc.h b/src/ipa/libipa/agc.h\nindex 1eace12908..c11dbf80cd 100644\n--- a/src/ipa/libipa/agc.h\n+++ b/src/ipa/libipa/agc.h\n@@ -49,6 +49,8 @@ prepareControls(ControlList &controls, const CameraSensorHelper *sensor,\n }\n \n struct Session {\n+\tuint32_t minExposure;\n+\tuint32_t maxExposure;\n \tutils::Duration minExposureTime;\n \tutils::Duration maxExposureTime;\n \tdouble minAnalogueGain;\n",
    "prefixes": [
        "RFC",
        "v2",
        "22/43"
    ]
}