Patch Detail
Show a patch.
GET /api/patches/20029/?format=api
{ "id": 20029, "url": "https://patchwork.libcamera.org/api/patches/20029/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20029/", "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": "<20240509063059.2768323-1-paul.elder@ideasonboard.com>", "date": "2024-05-09T06:30:59", "name": "[v6] ipa: libipa: histogram: Add transform parameter to constructor", "commit_ref": "1dc01bc9e6c32a8fb776f31cb957a251305de7e5", "pull_url": null, "state": "accepted", "archived": false, "hash": "f173b8ea3d741dc57edad2005d06ef6b219a880b", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20029/mbox/", "series": [ { "id": 4302, "url": "https://patchwork.libcamera.org/api/series/4302/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4302", "date": "2024-05-09T06:30:59", "name": "[v6] ipa: libipa: histogram: Add transform parameter to constructor", "version": 6, "mbox": "https://patchwork.libcamera.org/series/4302/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20029/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20029/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 BDC92C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 9 May 2024 06:31:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D87706345F;\n\tThu, 9 May 2024 08:31:11 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4217E6345F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 9 May 2024 08:31:10 +0200 (CEST)", "from neptunite.hamster-moth.ts.net\n\t(h175-177-049-156.catv02.itscom.jp [175.177.49.156])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E2BFB0B;\n\tThu, 9 May 2024 08:31:04 +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=\"iKicoSEX\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1715236266;\n\tbh=JB6UDtntF02T3XIeJGbzjhx+HJ6W/9jd/e74LUJkFVQ=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=iKicoSEXcwUub7LDOiLxAKsWmmoqco1fjmtTBK1zJbnFPsqRabfNh6GujYqYTYqCR\n\t5AVFhQZKM2WAjanRmsjqXk34LUSifVJ5i/iz4X9AFuyB/6zOpIh7Txp9VmU6Xjs9fY\n\ti+TjiQSuFVDaE9SCCxrtT7HZHQIyzVfUq7WzpiFY=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>", "Subject": "[PATCH v6] ipa: libipa: histogram: Add transform parameter to\n\tconstructor", "Date": "Thu, 9 May 2024 15:30:59 +0900", "Message-Id": "<20240509063059.2768323-1-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.39.2", "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": "Add a parameter to the histogram constructor that takes a transformation\nfunction to apply to all the bins upon construction.\n\nThis is necessary notably for the rkisp1, as the values reported from\nthe hardware are 20 bits where the upper 16-bits are meaningful integer\nvalues and the lower 4 bits are fractional and meant to be discarded. As\nadding a right-shift parameter is probably too specialized, a generic\nfunction is added as a parameter instead.\n\nWhile at it, optimize the existing constructor to avoid push_back() into\na vector with a known final size.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v6:\n- mention the constructor optimization in the commit message for real\n\nChanges in v5:\n- mention the constructor optimization to the commit message\n- improve documentation of constructors\n- add missing #include\n\nChanges in v4:\n- fix compilation when called with no transform function\n\nChanges in v3:\n- make the transform function a template parameter, and optimize the\n constructor\n\nThis used to be \"ipa: libipa: histogram: Add rshift parameter to\nconstructor\"\n\nChanges in v2:\n- change rshift parameter to a function parameter\n---\n src/ipa/libipa/histogram.cpp | 16 +++++++++++-----\n src/ipa/libipa/histogram.h | 14 +++++++++++++-\n 2 files changed, 24 insertions(+), 6 deletions(-)", "diff": "diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp\nindex c1aac59b..13a7e44f 100644\n--- a/src/ipa/libipa/histogram.cpp\n+++ b/src/ipa/libipa/histogram.cpp\n@@ -39,16 +39,22 @@ namespace ipa {\n \n /**\n * \\brief Create a cumulative histogram\n- * \\param[in] data A pre-sorted histogram to be passed\n+ * \\param[in] data A (non-cumulative) histogram\n */\n Histogram::Histogram(Span<const uint32_t> data)\n {\n-\tcumulative_.reserve(data.size());\n-\tcumulative_.push_back(0);\n-\tfor (const uint32_t &value : data)\n-\t\tcumulative_.push_back(cumulative_.back() + value);\n+\tcumulative_.resize(data.size() + 1);\n+\tcumulative_[0] = 0;\n+\tfor (const auto &[i, value] : utils::enumerate(data))\n+\t\tcumulative_[i + 1] = cumulative_[i] + value;\n }\n \n+/**\n+ * \\brief Create a cumulative histogram\n+ * \\param[in] data A (non-cumulative) histogram\n+ * \\param[in] transform The transformation function to apply to every bin\n+ */\n+\n /**\n * \\fn Histogram::bins()\n * \\brief Retrieve the number of bins currently used by the Histogram\ndiff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h\nindex 54bb2a19..a57546f4 100644\n--- a/src/ipa/libipa/histogram.h\n+++ b/src/ipa/libipa/histogram.h\n@@ -10,10 +10,11 @@\n #include <assert.h>\n #include <limits.h>\n #include <stdint.h>\n-\n+#include <type_traits>\n #include <vector>\n \n #include <libcamera/base/span.h>\n+#include <libcamera/base/utils.h>\n \n namespace libcamera {\n \n@@ -24,6 +25,17 @@ class Histogram\n public:\n \tHistogram() { cumulative_.push_back(0); }\n \tHistogram(Span<const uint32_t> data);\n+\n+\ttemplate<typename Transform,\n+\t\t std::enable_if_t<std::is_invocable_v<Transform, uint32_t>> * = nullptr>\n+\tHistogram(Span<const uint32_t> data, Transform transform)\n+\t{\n+\t\tcumulative_.resize(data.size() + 1);\n+\t\tcumulative_[0] = 0;\n+\t\tfor (const auto &[i, value] : utils::enumerate(data))\n+\t\t\tcumulative_[i + 1] = cumulative_[i] + transform(value);\n+\t}\n+\n \tsize_t bins() const { return cumulative_.size() - 1; }\n \tuint64_t total() const { return cumulative_[cumulative_.size() - 1]; }\n \tuint64_t cumulativeFrequency(double bin) const;\n", "prefixes": [ "v6" ] }