Show a patch.

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

{
    "id": 15359,
    "url": "https://patchwork.libcamera.org/api/patches/15359/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15359/",
    "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": "<20220210114316.1151170-2-jeanmichel.hautbois@ideasonboard.com>",
    "date": "2022-02-10T11:43:14",
    "name": "[libcamera-devel,v3,1/3] ipa: ipu3: Return filtered value",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d8d5b884feadf9bc768f1e68bf4e2109af379302",
    "submitter": {
        "id": 75,
        "url": "https://patchwork.libcamera.org/api/people/75/?format=api",
        "name": "Jean-Michel Hautbois",
        "email": "jeanmichel.hautbois@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15359/mbox/",
    "series": [
        {
            "id": 2928,
            "url": "https://patchwork.libcamera.org/api/series/2928/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2928",
            "date": "2022-02-10T11:43:13",
            "name": "ipa: ipu3: Misc clean up",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2928/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15359/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15359/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 98769BDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 10 Feb 2022 11:43:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 76F4860E70;\n\tThu, 10 Feb 2022 12:43:23 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A4FC5610A1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 10 Feb 2022 12:43:20 +0100 (CET)",
            "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:c44d:925d:d63:5b07])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 47C0A48B;\n\tThu, 10 Feb 2022 12:43:20 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"oYJy/tBr\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1644493400;\n\tbh=z1Qs1WSEcAbn5T1b4eUCbDKEh5hHF8+OExTPMAF16CA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=oYJy/tBraxWmmLm3RB4UAXSZvx7LYJBgoBFsQuXgIEzzu/HQoUZmK8PYlO9TbXl90\n\tmQMQ4WIJfsk6Baw0+KtUcLuctlKT+qk2km5xkAwwhx5qMLrq4kfcotc6L3gANyPMTT\n\t9z94S6TzDwzmkTK3LSFcR6lMKufVqBT/BHv2GmEA=",
        "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 10 Feb 2022 12:43:14 +0100",
        "Message-Id": "<20220210114316.1151170-2-jeanmichel.hautbois@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20220210114316.1151170-1-jeanmichel.hautbois@ideasonboard.com>",
        "References": "<20220210114316.1151170-1-jeanmichel.hautbois@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 1/3] ipa: ipu3: Return filtered value",
        "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": "When the current exposure value is calculated, it is cached and used by\nfilterExposure(). Use private filteredExposure_ and pass currentExposure\nas a parameter.\n\nIn order to limit the use of filteredExposure_, return the value from\nfilterExposure().\n\nWhile at it, remove a stale comment.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 74 ++++++++++++++++++---------------\n src/ipa/ipu3/algorithms/agc.h   |  3 +-\n 2 files changed, 41 insertions(+), 36 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 8d6f18f6..a929085c 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -72,7 +72,7 @@ static constexpr double kRelativeLuminanceTarget = 0.16;\n \n Agc::Agc()\n \t: frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s),\n-\t  maxShutterSpeed_(0s), filteredExposure_(0s), currentExposure_(0s)\n+\t  maxShutterSpeed_(0s), filteredExposure_(0s)\n {\n }\n \n@@ -143,33 +143,37 @@ double Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n \n /**\n  * \\brief Apply a filter on the exposure value to limit the speed of changes\n+ * \\param[in] exposureValue The target exposure from the AGC algorithm\n+ *\n+ * The speed of the filter is adaptive, and will produce the target quicker\n+ * during startup, or when the target exposure is within 20% of the most recent\n+ * filter output.\n+ *\n+ * \\return The filtered exposure\n  */\n-void Agc::filterExposure()\n+utils::Duration Agc::filterExposure(utils::Duration exposureValue)\n {\n \tdouble speed = 0.2;\n \n-\t/* Adapt instantly if we are in startup phase */\n+\t/* Adapt instantly if we are in startup phase. */\n \tif (frameCount_ < kNumStartupFrames)\n \t\tspeed = 1.0;\n \n-\tif (filteredExposure_ == 0s) {\n-\t\t/* DG stands for digital gain.*/\n-\t\tfilteredExposure_ = currentExposure_;\n-\t} else {\n-\t\t/*\n-\t\t * If we are close to the desired result, go faster to avoid making\n-\t\t * multiple micro-adjustments.\n-\t\t * \\todo Make this customisable?\n-\t\t */\n-\t\tif (filteredExposure_ < 1.2 * currentExposure_ &&\n-\t\t    filteredExposure_ > 0.8 * currentExposure_)\n-\t\t\tspeed = sqrt(speed);\n-\n-\t\tfilteredExposure_ = speed * currentExposure_ +\n-\t\t\t\tfilteredExposure_ * (1.0 - speed);\n-\t}\n+\t/*\n+\t * If we are close to the desired result, go faster to avoid making\n+\t * multiple micro-adjustments.\n+\t * \\todo Make this customisable?\n+\t */\n+\tif (filteredExposure_ < 1.2 * exposureValue &&\n+\t    filteredExposure_ > 0.8 * exposureValue)\n+\t\tspeed = sqrt(speed);\n+\n+\tfilteredExposure_ = speed * exposureValue +\n+\t\t\t    filteredExposure_ * (1.0 - speed);\n \n-\tLOG(IPU3Agc, Debug) << \"After filtering, total_exposure \" << filteredExposure_;\n+\tLOG(IPU3Agc, Debug) << \"After filtering, exposure \" << filteredExposure_;\n+\n+\treturn filteredExposure_;\n }\n \n /**\n@@ -213,27 +217,29 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n \t * Calculate the current exposure value for the scene as the latest\n \t * exposure value applied multiplied by the new estimated gain.\n \t */\n-\tcurrentExposure_ = effectiveExposureValue * evGain;\n+\tutils::Duration exposureValue = effectiveExposureValue * evGain;\n \n \t/* Clamp the exposure value to the min and max authorized */\n \tutils::Duration maxTotalExposure = maxShutterSpeed_ * maxAnalogueGain_;\n-\tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n-\tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_\n+\texposureValue = std::min(exposureValue, maxTotalExposure);\n+\tLOG(IPU3Agc, Debug) << \"Target total exposure \" << exposureValue\n \t\t\t    << \", maximum is \" << maxTotalExposure;\n \n-\t/* \\todo: estimate if we need to desaturate */\n-\tfilterExposure();\n-\n-\t/* Divide the exposure value as new exposure and gain values */\n-\tutils::Duration exposureValue = filteredExposure_;\n-\tutils::Duration shutterTime;\n+\t/*\n+\t * Filter the exposure.\n+\t * \\todo: estimate if we need to desaturate\n+\t */\n+\texposureValue = filterExposure(exposureValue);\n \n \t/*\n-\t* Push the shutter time up to the maximum first, and only then\n-\t* increase the gain.\n-\t*/\n-\tshutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n-\t\t\t\t\t\t  minShutterSpeed_, maxShutterSpeed_);\n+\t * Divide the exposure value as new exposure and gain values.\n+\t *\n+\t * Push the shutter time up to the maximum first, and only then\n+\t * increase the gain.\n+\t */\n+\tutils::Duration shutterTime =\n+\t\tstd::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n+\t\t\t\t\t    minShutterSpeed_, maxShutterSpeed_);\n \tdouble stepGain = std::clamp(exposureValue / shutterTime,\n \t\t\t\t     minAnalogueGain_, maxAnalogueGain_);\n \tLOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\nindex 96ec7005..84bfe045 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -33,7 +33,7 @@ public:\n private:\n \tdouble measureBrightness(const ipu3_uapi_stats_3a *stats,\n \t\t\t\t const ipu3_uapi_grid_config &grid) const;\n-\tvoid filterExposure();\n+\tutils::Duration filterExposure(utils::Duration currentExposure);\n \tvoid computeExposure(IPAFrameContext &frameContext, double yGain,\n \t\t\t     double iqMeanGain);\n \tdouble estimateLuminance(IPAFrameContext &frameContext,\n@@ -51,7 +51,6 @@ private:\n \tdouble maxAnalogueGain_;\n \n \tutils::Duration filteredExposure_;\n-\tutils::Duration currentExposure_;\n \n \tuint32_t stride_;\n };\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "1/3"
    ]
}