[1/2] ipa: libipa: histogram: Add rshift parameter to constructor
diff mbox series

Message ID 20240319105403.4045592-2-paul.elder@ideasonboard.com
State New
Headers show
Series
  • ipa: rkisp1: Fix histogram
Related show

Commit Message

Paul Elder March 19, 2024, 10:54 a.m. UTC
Add an parameter for right-shifting the values during construction of
the histogram.

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.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/ipa/libipa/histogram.cpp | 5 +++--
 src/ipa/libipa/histogram.h   | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/histogram.cpp b/src/ipa/libipa/histogram.cpp
index 6b5cde8e..5cfbb720 100644
--- a/src/ipa/libipa/histogram.cpp
+++ b/src/ipa/libipa/histogram.cpp
@@ -31,13 +31,14 @@  namespace ipa {
 /**
  * \brief Create a cumulative histogram
  * \param[in] data A pre-sorted histogram to be passed
+ * \param[in] rshift Number of bits to right shift the values by
  */
-Histogram::Histogram(Span<const uint32_t> data)
+Histogram::Histogram(Span<const uint32_t> data, uint8_t rshift)
 {
 	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() + (value >> rshift));
 }
 
 /**
diff --git a/src/ipa/libipa/histogram.h b/src/ipa/libipa/histogram.h
index 05bb4b80..a82e623e 100644
--- a/src/ipa/libipa/histogram.h
+++ b/src/ipa/libipa/histogram.h
@@ -22,7 +22,7 @@  namespace ipa {
 class Histogram
 {
 public:
-	Histogram(Span<const uint32_t> data);
+	Histogram(Span<const uint32_t> data, uint8_t rshift = 0);
 	size_t bins() const { return cumulative_.size() - 1; }
 	uint64_t total() const { return cumulative_[cumulative_.size() - 1]; }
 	uint64_t cumulativeFrequency(double bin) const;