[v1,02/16] ipa: rkisp1: algorithms: add Denoise ISO helpers
diff mbox series

Message ID 20251028170847.2673396-2-rui.wang@ideasonboard.com
State New
Headers show
Series
  • [v1,01/16] ipa: rkisp1: algorithms: add Denoise base class shell
Related show

Commit Message

Rui Wang Oct. 28, 2025, 5:08 p.m. UTC
Provide reusable ISO computation and band selection helpers. computeIso
derives an effective ISO value from the AGC gain (approx ISO = gain * 100).
selectIsoBand searches the tuning ISO level table for the appropriate band
given the current ISO, falling back to the last band if ISO exceeds all
defined ranges.

Signed-off-by: Rui Wang <rui.wang@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/denoise.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h
index 8f109db4..d97301f0 100644
--- a/src/ipa/rkisp1/algorithms/denoise.h
+++ b/src/ipa/rkisp1/algorithms/denoise.h
@@ -7,6 +7,8 @@ 
 
 #pragma once
 
+#include "../ipa_context.h"
+
 #include "algorithm.h"
 
 namespace libcamera {
@@ -27,8 +29,34 @@  class DenoiseBaseAlgorithm : public ipa::rkisp1::Algorithm
 protected:
 	DenoiseBaseAlgorithm() = default;
 	~DenoiseBaseAlgorithm() = default;
+
+	unsigned computeIso(const IPAContext &context,
+			    const IPAFrameContext &frameContext) const;
+	template<typename LevelContainer>
+	int selectIsoBand(unsigned iso, const LevelContainer &levels) const;
 };
 
+inline unsigned DenoiseBaseAlgorithm::computeIso(const IPAContext &context,
+						 const IPAFrameContext &frameContext) const
+{
+	double ag = frameContext.agc.gain ? frameContext.agc.gain
+					  : context.activeState.agc.automatic.gain;
+	return static_cast<unsigned>(ag * 100.0 + 0.5);
+}
+
+template<typename LevelContainer>
+int DenoiseBaseAlgorithm::selectIsoBand(unsigned iso, const LevelContainer &levels) const
+{
+	if (levels.empty())
+		return -1;
+	int idx = 0;
+	while (idx < static_cast<int>(levels.size()) && iso > levels[idx].maxIso)
+		++idx;
+	if (idx >= static_cast<int>(levels.size()))
+		idx = static_cast<int>(levels.size()) - 1;
+	return idx;
+}
+
 } /* namespace ipa::rkisp1::algorithms */
 
 } /* namespace libcamera */