[v1,01/11] ipa: rkisp1: algorithms: Add exposure index computation helpers
diff mbox series

Message ID 20251125000848.4103786-2-rui.wang@ideasonboard.com
State New
Headers show
Series
  • ipa: rkisp1: DPF refactor and tuning improvements
Related show

Commit Message

Rui Wang Nov. 25, 2025, 12:08 a.m. UTC
Introduce computeExposureIndex() to derive an exposure index value from
the AGC gain (approximately exposureIndex = gain * 100), and
selectExposureIndexBand() to search through a container of exposure index
levels and select the appropriate tuning band for the current exposure
index.

These helpers provide reusable functionality for exposure-index-banded
tuning in denoising algorithms, enabling more precise algorithm
configuration based on lighting conditions.

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

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h
new file mode 100644
index 00000000..8907dc4e
--- /dev/null
+++ b/src/ipa/rkisp1/algorithms/denoise.h
@@ -0,0 +1,55 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2025, Ideas On Board
+ *
+ * RkISP1 Denoising Algorithms Base Class
+ */
+
+#pragma once
+
+#include "../ipa_context.h"
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::rkisp1::algorithms {
+
+class DenoiseBaseAlgorithm : public ipa::rkisp1::Algorithm
+{
+protected:
+	DenoiseBaseAlgorithm() = default;
+	~DenoiseBaseAlgorithm() = default;
+
+	virtual uint32_t computeExposureIndex(const IPAContext &context,
+					      const IPAFrameContext &frameContext) const;
+	template<typename LevelContainer>
+	uint32_t selectExposureIndexBand(unsigned exposureIndex,
+					 const LevelContainer &levels) const;
+};
+
+inline unsigned DenoiseBaseAlgorithm::computeExposureIndex(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>
+uint32_t DenoiseBaseAlgorithm::selectExposureIndexBand(unsigned exposureIndex,
+						       const LevelContainer &levels) const
+{
+	if (levels.empty())
+		return -1;
+	uint32_t idx = 0;
+	while (idx < static_cast<uint32_t>(levels.size()) && exposureIndex > levels[idx].maxExposureIndex)
+		++idx;
+	if (idx >= static_cast<uint32_t>(levels.size()))
+		idx = static_cast<uint32_t>(levels.size()) - 1;
+	return idx;
+}
+
+} /* namespace ipa::rkisp1::algorithms */
+
+} /* namespace libcamera */