Patch Detail
Show a patch.
GET /api/1.1/patches/15385/?format=api
{ "id": 15385, "url": "https://patchwork.libcamera.org/api/1.1/patches/15385/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15385/", "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": "<20220224151113.109858-2-jeanmichel.hautbois@ideasonboard.com>", "date": "2022-02-24T15:11:10", "name": "[libcamera-devel,v4,1/4] ipa: ipu3: Return filtered value", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "d8d5b884feadf9bc768f1e68bf4e2109af379302", "submitter": { "id": 75, "url": "https://patchwork.libcamera.org/api/1.1/people/75/?format=api", "name": "Jean-Michel Hautbois", "email": "jeanmichel.hautbois@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15385/mbox/", "series": [ { "id": 2940, "url": "https://patchwork.libcamera.org/api/1.1/series/2940/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2940", "date": "2022-02-24T15:11:09", "name": "ipa: ipu3: Misc clean up", "version": 4, "mbox": "https://patchwork.libcamera.org/series/2940/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15385/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15385/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 259AEBE08A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Feb 2022 15:11:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6E2DB6116B;\n\tThu, 24 Feb 2022 16:11:21 +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 098BE610F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Feb 2022 16:11:19 +0100 (CET)", "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:ce74:6df2:4b76:b230])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 95813484;\n\tThu, 24 Feb 2022 16:11:18 +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=\"Yxa6vKwC\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1645715478;\n\tbh=z1Qs1WSEcAbn5T1b4eUCbDKEh5hHF8+OExTPMAF16CA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Yxa6vKwCmB87VIWurGxVhrfmduTOAMxT5NjjSvQzxRAe4Jdn1vrXz5OyvNw9acpFT\n\t3vn98J6PMTtjqxL6wz/d6/XitlN4gf3p2nW8PTj+bzecQARLLj7qxrxLS3lQDDIZs8\n\t2i3iX/S2Iu/hdpw0W2NOqWEGa/5PzRRrSOGZGiyk=", "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 24 Feb 2022 16:11:10 +0100", "Message-Id": "<20220224151113.109858-2-jeanmichel.hautbois@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20220224151113.109858-1-jeanmichel.hautbois@ideasonboard.com>", "References": "<20220224151113.109858-1-jeanmichel.hautbois@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 1/4] 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", "v4", "1/4" ] }