[libcamera-devel,v1,4/6] ipa: rpi: vc4: Move denoise control handling into the VC4 derived IPA
diff mbox series

Message ID 20231020084002.30665-5-naush@raspberrypi.com
State Accepted
Commit 4e7c26b19724ffc1174bb131de2b56d85e83127f
Headers show
Series
  • Raspberry Pi: Preliminary PiSP support (round 2)
Related show

Commit Message

Naushir Patuck Oct. 20, 2023, 8:40 a.m. UTC
Since noise control handling differs between the VC4 and PiSP IPAs,
move the current denoise control handler from ipa base into the vc4 IPA
derived class.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/rpi/common/ipa_base.cpp | 41 ++++-----------------------------
 src/ipa/rpi/vc4/vc4.cpp         | 35 ++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 39 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp
index f28eb36b7a44..2583c6226f44 100644
--- a/src/ipa/rpi/common/ipa_base.cpp
+++ b/src/ipa/rpi/common/ipa_base.cpp
@@ -643,14 +643,6 @@  static const std::map<int32_t, std::string> AwbModeTable = {
 	{ controls::AwbCustom, "custom" },
 };
 
-static const std::map<int32_t, RPiController::DenoiseMode> DenoiseModeTable = {
-	{ controls::draft::NoiseReductionModeOff, RPiController::DenoiseMode::Off },
-	{ controls::draft::NoiseReductionModeFast, RPiController::DenoiseMode::ColourFast },
-	{ controls::draft::NoiseReductionModeHighQuality, RPiController::DenoiseMode::ColourHighQuality },
-	{ controls::draft::NoiseReductionModeMinimal, RPiController::DenoiseMode::ColourOff },
-	{ controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::ColourHighQuality },
-};
-
 static const std::map<int32_t, RPiController::AfAlgorithm::AfMode> AfModeTable = {
 	{ controls::AfModeManual, RPiController::AfAlgorithm::AfModeManual },
 	{ controls::AfModeAuto, RPiController::AfAlgorithm::AfModeAuto },
@@ -1032,36 +1024,11 @@  void IpaBase::applyControls(const ControlList &controls)
 			break;
 		}
 
-		case controls::NOISE_REDUCTION_MODE: {
-			RPiController::DenoiseAlgorithm *sdn = dynamic_cast<RPiController::DenoiseAlgorithm *>(
-				controller_.getAlgorithm("SDN"));
-			/* Some platforms may have a combined "denoise" algorithm instead. */
-			if (!sdn)
-				sdn = dynamic_cast<RPiController::DenoiseAlgorithm *>(
-				controller_.getAlgorithm("denoise"));
-			if (!sdn) {
-				LOG(IPARPI, Warning)
-					<< "Could not set NOISE_REDUCTION_MODE - no SDN algorithm";
-				break;
-			}
-
-			int32_t idx = ctrl.second.get<int32_t>();
-			auto mode = DenoiseModeTable.find(idx);
-			if (mode != DenoiseModeTable.end()) {
-				sdn->setMode(mode->second);
-
-				/*
-				 * \todo If the colour denoise is not going to run due to an
-				 * analysis image resolution or format mismatch, we should
-				 * report the status correctly in the metadata.
-				 */
-				libcameraMetadata_.set(controls::draft::NoiseReductionMode, idx);
-			} else {
-				LOG(IPARPI, Error) << "Noise reduction mode " << idx
-						   << " not recognised";
-			}
+		case controls::NOISE_REDUCTION_MODE:
+			/* Handled below in handleControls() */
+			libcameraMetadata_.set(controls::draft::NoiseReductionMode,
+					       ctrl.second.get<int32_t>());
 			break;
-		}
 
 		case controls::AF_MODE:
 			break; /* We already handled this one above */
diff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp
index 4a4d720ce7dd..354b901bb796 100644
--- a/src/ipa/rpi/vc4/vc4.cpp
+++ b/src/ipa/rpi/vc4/vc4.cpp
@@ -11,6 +11,7 @@ 
 #include <linux/bcm2835-isp.h>
 
 #include <libcamera/base/log.h>
+#include <libcamera/control_ids.h>
 #include <libcamera/ipa/ipa_module_info.h>
 
 #include "common/ipa_base.h"
@@ -247,9 +248,39 @@  RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span<uint8_t> mem)
 	return statistics;
 }
 
-void IpaVc4::handleControls([[maybe_unused]] const ControlList &controls)
+void IpaVc4::handleControls(const ControlList &controls)
 {
-	/* No controls require any special updates to the hardware configuration. */
+	static const std::map<int32_t, RPiController::DenoiseMode> DenoiseModeTable = {
+		{ controls::draft::NoiseReductionModeOff, RPiController::DenoiseMode::Off },
+		{ controls::draft::NoiseReductionModeFast, RPiController::DenoiseMode::ColourFast },
+		{ controls::draft::NoiseReductionModeHighQuality, RPiController::DenoiseMode::ColourHighQuality },
+		{ controls::draft::NoiseReductionModeMinimal, RPiController::DenoiseMode::ColourOff },
+		{ controls::draft::NoiseReductionModeZSL, RPiController::DenoiseMode::ColourHighQuality },
+	};
+
+	for (auto const &ctrl : controls) {
+		switch (ctrl.first) {
+		case controls::NOISE_REDUCTION_MODE: {
+			RPiController::DenoiseAlgorithm *sdn = dynamic_cast<RPiController::DenoiseAlgorithm *>(
+				controller_.getAlgorithm("SDN"));
+			/* Some platforms may have a combined "denoise" algorithm instead. */
+			if (!sdn)
+				sdn = dynamic_cast<RPiController::DenoiseAlgorithm *>(
+				controller_.getAlgorithm("denoise"));
+			if (!sdn) {
+				LOG(IPARPI, Warning)
+					<< "Could not set NOISE_REDUCTION_MODE - no SDN algorithm";
+				return;
+			}
+
+			int32_t idx = ctrl.second.get<int32_t>();
+			auto mode = DenoiseModeTable.find(idx);
+			if (mode != DenoiseModeTable.end())
+				sdn->setMode(mode->second);
+			break;
+		}
+		}
+	}
 }
 
 bool IpaVc4::validateIspControls()