Patch Detail
Show a patch.
GET /api/1.1/patches/14666/?format=api
{ "id": 14666, "url": "https://patchwork.libcamera.org/api/1.1/patches/14666/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14666/", "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": "<20211119210239.18540-5-laurent.pinchart@ideasonboard.com>", "date": "2021-11-19T21:02:38", "name": "[libcamera-devel,v2,4/5] ipa: ipu3: agc: Return the inter-quantile mean from measureBrightness()", "commit_ref": "a2b4975a1ca0ec122227d5c8c2ef6a6aa28803e5", "pull_url": null, "state": "accepted", "archived": false, "hash": "51ae56aa7efee54c20094dec141d282815aa778c", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14666/mbox/", "series": [ { "id": 2738, "url": "https://patchwork.libcamera.org/api/1.1/series/2738/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2738", "date": "2021-11-19T21:02:34", "name": "ipa: ipu3: agc: Misc improvements", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2738/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14666/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14666/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 985EFC324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 19 Nov 2021 21:03:13 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 363D960233;\n\tFri, 19 Nov 2021 22:03:13 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3875160233\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 22:03:07 +0100 (CET)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CD17F1C19\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 22:03:06 +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=\"pCj5iZ1E\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637355787;\n\tbh=J/w+5W1Ntpsm6t1s3Dz4YCs6l0nmODQheND9T1MKP2I=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=pCj5iZ1EjtzTcGZhD7TOx8txbjp+Ojm2t/6IV/eAcgEeQQkZuu67gx+IsEE6KiuEh\n\tSH2wwQkLDbq26pXpInC+LxLx48pvjGnpFoN2vRNHRZO943LfVnxkY7f1uLaAFZf7qh\n\tUh8EQSRvlHMSTncNos0Pg32DzUeB07JbKWcDypMI=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 19 Nov 2021 23:02:38 +0200", "Message-Id": "<20211119210239.18540-5-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.32.0", "In-Reply-To": "<20211119210239.18540-1-laurent.pinchart@ideasonboard.com>", "References": "<20211119210239.18540-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 4/5] ipa: ipu3: agc: Return the\n\tinter-quantile mean from measureBrightness()", "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": "The inter-quantile mean is a value that is computed as part of the AGC\nrun. It doesn't need to be stored in a member variable. Return it from\nmeasureBrightness(), which makes the flow of data easier to follow.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp | 53 ++++++++++++++++++---------------\n src/ipa/ipu3/algorithms/agc.h | 9 +++---\n 2 files changed, 33 insertions(+), 29 deletions(-)", "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 2d196fd63c7e..c39e213f1dac 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -70,7 +70,7 @@ static constexpr uint32_t kNumStartupFrames = 10;\n static constexpr double kRelativeLuminanceTarget = 0.16;\n \n Agc::Agc()\n-\t: frameCount_(0), iqMean_(0.0), lineDuration_(0s), minShutterSpeed_(0s),\n+\t: frameCount_(0), lineDuration_(0s), minShutterSpeed_(0s),\n \t maxShutterSpeed_(0s), filteredExposure_(0s), currentExposure_(0s)\n {\n }\n@@ -108,9 +108,10 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n * \\brief Estimate the mean value of the top 2% of the histogram\n * \\param[in] stats The statistics computed by the ImgU\n * \\param[in] grid The grid used to store the statistics in the IPU3\n+ * \\return The mean value of the top 2% of the histogram\n */\n-void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n-\t\t\t const ipu3_uapi_grid_config &grid)\n+double Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n+\t\t\t const ipu3_uapi_grid_config &grid) const\n {\n \t/* Initialise the histogram array */\n \tuint32_t hist[knumHistogramBins] = { 0 };\n@@ -135,8 +136,8 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n \t\t}\n \t}\n \n-\t/* Estimate the quantile mean of the top 2% of the histogram */\n-\tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n+\t/* Estimate the quantile mean of the top 2% of the histogram. */\n+\treturn Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n }\n \n /**\n@@ -174,28 +175,22 @@ void Agc::filterExposure()\n * \\brief Estimate the new exposure and gain values\n * \\param[inout] frameContext The shared IPA frame Context\n * \\param[in] yGain The gain calculated based on the relative luminance target\n+ * \\param[in] iqMeanGain The gain calculated based on the relative luminance target\n */\n-void Agc::computeExposure(IPAFrameContext &frameContext, double yGain)\n+void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n+\t\t\t double iqMeanGain)\n {\n \t/* Get the effective exposure and gain applied on the sensor. */\n \tuint32_t exposure = frameContext.sensor.exposure;\n \tdouble analogueGain = frameContext.sensor.gain;\n \n-\t/*\n-\t * Estimate the gain needed to have the proportion of pixels in a given\n-\t * desired range. iqMean_ returns the mean value of the top 2% of the\n-\t * cumulative histogram, and we want it to be as close as possible to a\n-\t * configured target.\n-\t */\n-\tdouble evGain = kEvGainTarget * knumHistogramBins / iqMean_;\n-\n-\tif (evGain < yGain)\n-\t\tevGain = yGain;\n+\t/* Use the highest of the two gain estimates. */\n+\tdouble evGain = std::max(yGain, iqMeanGain);\n \n \t/* Consider within 1% of the target as correctly exposed */\n \tif (std::abs(evGain - 1.0) < 0.01)\n-\t\tLOG(IPU3Agc, Debug) << \"We are well exposed (iqMean = \"\n-\t\t\t\t << iqMean_ << \")\";\n+\t\tLOG(IPU3Agc, Debug) << \"We are well exposed (evGain = \"\n+\t\t\t\t << evGain << \")\";\n \n \t/* extracted from Rpi::Agc::computeTargetExposure */\n \n@@ -308,15 +303,25 @@ double Agc::estimateLuminance(IPAFrameContext &frameContext,\n */\n void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n {\n-\tmeasureBrightness(stats, context.configuration.grid.bdsGrid);\n+\t/*\n+\t * Estimate the gain needed to have the proportion of pixels in a given\n+\t * desired range. iqMean is the mean value of the top 2% of the\n+\t * cumulative histogram, and we want it to be as close as possible to a\n+\t * configured target.\n+\t */\n+\tdouble iqMean = measureBrightness(stats, context.configuration.grid.bdsGrid);\n+\tdouble iqMeanGain = kEvGainTarget * knumHistogramBins / iqMean;\n \n+\t/*\n+\t * Estimate the gain needed to achieve a relative luminance target. To\n+\t * account for non-linearity caused by saturation, the value needs to be\n+\t * estimated in an iterative process, as multiplying by a gain will not\n+\t * increase the relative luminance by the same factor if some image\n+\t * regions are saturated.\n+\t */\n \tdouble yGain = 1.0;\n \tdouble yTarget = kRelativeLuminanceTarget;\n \n-\t/*\n-\t * Do this calculation a few times as brightness increase can be\n-\t * non-linear when there are saturated regions.\n-\t */\n \tfor (unsigned int i = 0; i < 8; i++) {\n \t\tdouble yValue = estimateLuminance(context.frameContext,\n \t\t\t\t\t\t context.configuration.grid.bdsGrid,\n@@ -331,7 +336,7 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n \t\t\tbreak;\n \t}\n \n-\tcomputeExposure(context.frameContext, yGain);\n+\tcomputeExposure(context.frameContext, yGain, iqMeanGain);\n \tframeCount_++;\n }\n \ndiff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h\nindex 0c868d6737f1..a04a81fb8eae 100644\n--- a/src/ipa/ipu3/algorithms/agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -31,10 +31,11 @@ public:\n \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n \n private:\n-\tvoid measureBrightness(const ipu3_uapi_stats_3a *stats,\n-\t\t\t const ipu3_uapi_grid_config &grid);\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-\tvoid computeExposure(IPAFrameContext &frameContext, double yGain);\n+\tvoid computeExposure(IPAFrameContext &frameContext, double yGain,\n+\t\t\t double iqMeanGain);\n \tdouble estimateLuminance(IPAFrameContext &frameContext,\n \t\t\t\t const ipu3_uapi_grid_config &grid,\n \t\t\t\t const ipu3_uapi_stats_3a *stats,\n@@ -42,8 +43,6 @@ private:\n \n \tuint64_t frameCount_;\n \n-\tdouble iqMean_;\n-\n \tutils::Duration lineDuration_;\n \tutils::Duration minShutterSpeed_;\n \tutils::Duration maxShutterSpeed_;\n", "prefixes": [ "libcamera-devel", "v2", "4/5" ] }