From patchwork Thu May 9 06:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20029 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BDC92C3226 for ; Thu, 9 May 2024 06:31:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D87706345F; Thu, 9 May 2024 08:31:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iKicoSEX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4217E6345F for ; Thu, 9 May 2024 08:31:10 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0E2BFB0B; Thu, 9 May 2024 08:31:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1715236266; bh=JB6UDtntF02T3XIeJGbzjhx+HJ6W/9jd/e74LUJkFVQ=; h=From:To:Cc:Subject:Date:From; b=iKicoSEXcwUub7LDOiLxAKsWmmoqco1fjmtTBK1zJbnFPsqRabfNh6GujYqYTYqCR 5AVFhQZKM2WAjanRmsjqXk34LUSifVJ5i/iz4X9AFuyB/6zOpIh7Txp9VmU6Xjs9fY i+TjiQSuFVDaE9SCCxrtT7HZHQIyzVfUq7WzpiFY= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Kieran Bingham , Daniel Scally , Laurent Pinchart Subject: [PATCH v6] ipa: libipa: histogram: Add transform parameter to constructor 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a parameter to the histogram constructor that takes a transformation function to apply to all the bins upon construction. This is necessary notably for the rkisp1, as the values reported from the hardware are 20 bits where the upper 16-bits are meaningful integer values and the lower 4 bits are fractional and meant to be discarded. As adding a right-shift parameter is probably too specialized, a generic function is added as a parameter instead. While at it, optimize the existing constructor to avoid push_back() into a vector with a known final size. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Daniel Scally Reviewed-by: Laurent Pinchart --- Changes in v6: - mention the constructor optimization in the commit message for real Changes in v5: - mention the constructor optimization to the commit message - improve documentation of constructors - add missing #include Changes in v4: - fix compilation when called with no transform function Changes in v3: - make the transform function a template parameter, and optimize the constructor This used to be "ipa: libipa: histogram: Add rshift parameter to constructor" Changes in v2: - change rshift parameter to a function parameter --- src/ipa/libipa/histogram.cpp | 16 +++++++++++----- src/ipa/libipa/histogram.h | 14 +++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp index c1aac59b..13a7e44f 100644 --- a/src/ipa/libipa/histogram.cpp +++ b/src/ipa/libipa/histogram.cpp @@ -39,16 +39,22 @@ namespace ipa { /** * \brief Create a cumulative histogram - * \param[in] data A pre-sorted histogram to be passed + * \param[in] data A (non-cumulative) histogram */ Histogram::Histogram(Span data) { - cumulative_.reserve(data.size()); - cumulative_.push_back(0); - for (const uint32_t &value : data) - cumulative_.push_back(cumulative_.back() + value); + cumulative_.resize(data.size() + 1); + cumulative_[0] = 0; + for (const auto &[i, value] : utils::enumerate(data)) + cumulative_[i + 1] = cumulative_[i] + value; } +/** + * \brief Create a cumulative histogram + * \param[in] data A (non-cumulative) histogram + * \param[in] transform The transformation function to apply to every bin + */ + /** * \fn Histogram::bins() * \brief Retrieve the number of bins currently used by the Histogram diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h index 54bb2a19..a57546f4 100644 --- a/src/ipa/libipa/histogram.h +++ b/src/ipa/libipa/histogram.h @@ -10,10 +10,11 @@ #include #include #include - +#include #include #include +#include namespace libcamera { @@ -24,6 +25,17 @@ class Histogram public: Histogram() { cumulative_.push_back(0); } Histogram(Span data); + + template> * = nullptr> + Histogram(Span data, Transform transform) + { + cumulative_.resize(data.size() + 1); + cumulative_[0] = 0; + for (const auto &[i, value] : utils::enumerate(data)) + cumulative_[i + 1] = cumulative_[i] + transform(value); + } + size_t bins() const { return cumulative_.size() - 1; } uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } uint64_t cumulativeFrequency(double bin) const;