From patchwork Fri Apr 19 05:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 19908 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 6AC80C3200 for ; Fri, 19 Apr 2024 05:53:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53078633F3; Fri, 19 Apr 2024 07:53:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FXV6LeMO"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 796F061B17 for ; Fri, 19 Apr 2024 07:53:52 +0200 (CEST) Received: from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 21FDA8D0; Fri, 19 Apr 2024 07:53:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1713505984; bh=EJDZsG74AzYlR577ccVh7kBT/0AqMRZlc2M+Z3Gio2U=; h=From:To:Cc:Subject:Date:From; b=FXV6LeMOG82G6Ex6ByKNj2EBMgUzO0FSGQkltreuwdvPVOq7aLuKiD1a+nvVwbaOB BZ6OD1qHooAndJdJxcmLBOawUVSxd/EyVBJxk4hPSD4GrA9sK9FF5MOtdgcnWEcdTj KvRgrSNpoDfy/9RQbBKS2mDtiRJUKWCet6/M9cFA= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH v2] ipa: libipa: histogram: Add transform parameter to constructor Date: Fri, 19 Apr 2024 14:53:36 +0900 Message-Id: <20240419055336.1070164-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. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Daniel Scally --- 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 | 6 ++++-- src/ipa/libipa/histogram.h | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp index c1aac59b..2a4095f4 100644 --- a/src/ipa/libipa/histogram.cpp +++ b/src/ipa/libipa/histogram.cpp @@ -40,13 +40,15 @@ namespace ipa { /** * \brief Create a cumulative histogram * \param[in] data A pre-sorted histogram to be passed + * \param[in] transform The transformation function to apply to every bin */ -Histogram::Histogram(Span data) +Histogram::Histogram(Span data, + std::function transform) { cumulative_.reserve(data.size()); cumulative_.push_back(0); for (const uint32_t &value : data) - cumulative_.push_back(cumulative_.back() + value); + cumulative_.push_back(cumulative_.back() + transform(value)); } /** diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h index 54bb2a19..89a6b550 100644 --- a/src/ipa/libipa/histogram.h +++ b/src/ipa/libipa/histogram.h @@ -8,9 +8,9 @@ #pragma once #include +#include #include #include - #include #include @@ -23,7 +23,9 @@ class Histogram { public: Histogram() { cumulative_.push_back(0); } - Histogram(Span data); + Histogram(Span data, + std::function transform = + [](uint32_t x) { return x; }); size_t bins() const { return cumulative_.size() - 1; } uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } uint64_t cumulativeFrequency(double bin) const;