[v3,09/11] ipa: c3-isp: Add CSC Algorithm
diff mbox series

Message ID 20250227105733.187611-10-keke.li@amlogic.com
State New
Headers show
Series
  • Add Amlogic C3 ISP pipeline handler and IPA
Related show

Commit Message

Keke Li Feb. 27, 2025, 10:57 a.m. UTC
Add a new Colour Space Coversion algorithm.

Signed-off-by: Keke Li <keke.li@amlogic.com>
---
 src/ipa/c3-isp/algorithms/csc.cpp     | 66 +++++++++++++++++++++++++++
 src/ipa/c3-isp/algorithms/csc.h       | 32 +++++++++++++
 src/ipa/c3-isp/algorithms/meson.build |  1 +
 3 files changed, 99 insertions(+)
 create mode 100644 src/ipa/c3-isp/algorithms/csc.cpp
 create mode 100644 src/ipa/c3-isp/algorithms/csc.h

Patch
diff mbox series

diff --git a/src/ipa/c3-isp/algorithms/csc.cpp b/src/ipa/c3-isp/algorithms/csc.cpp
new file mode 100644
index 00000000..588b1e19
--- /dev/null
+++ b/src/ipa/c3-isp/algorithms/csc.cpp
@@ -0,0 +1,66 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Amlogic
+ *
+ * C3ISP Color Space Conversion control
+ */
+
+#include "csc.h"
+
+#include <libcamera/base/log.h>
+
+/**
+ * \file csc.h
+ */
+
+namespace libcamera {
+
+namespace ipa::c3isp::algorithms {
+
+/**
+ * \class Csc
+ * \brief Color Space Conversion algorithm
+ */
+
+LOG_DEFINE_CATEGORY(C3ISPCsc)
+
+Csc::Csc()
+{
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::init
+ */
+int Csc::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
+{
+	cscCoeff_ = tuningData["cscCoeff"].getList<int16_t>().value_or(std::vector<int16_t>{});
+	if (cscCoeff_.size() != 9) {
+		LOG(C3ISPCsc, Error) << "Invalid CSC coeff size";
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void Csc::prepare([[maybe_unused]] IPAContext &context,
+		  [[maybe_unused]] const uint32_t frame,
+		  [[maybe_unused]] IPAFrameContext &frameContext,
+		  C3ISPParams *params)
+{
+	auto CscCfg = params->block<BlockType::Csc>();
+	CscCfg.setEnabled(C3_ISP_PARAMS_BLOCK_FL_ENABLE);
+
+	for (unsigned int i = 0; i < 3; i++) {
+		for (unsigned int j = 0; j < 3; j++)
+			CscCfg->matrix[i][j] = cscCoeff_[i * 3 + j];
+	}
+}
+
+REGISTER_IPA_ALGORITHM(Csc, "Csc")
+
+} /* namespace ipa::c3isp::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/c3-isp/algorithms/csc.h b/src/ipa/c3-isp/algorithms/csc.h
new file mode 100644
index 00000000..ec082a41
--- /dev/null
+++ b/src/ipa/c3-isp/algorithms/csc.h
@@ -0,0 +1,32 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Amlogic
+ *
+ * C3ISP Color Space Conversion control
+ */
+
+#pragma once
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::c3isp::algorithms {
+
+class Csc : public Algorithm
+{
+public:
+	Csc();
+	~Csc() = default;
+
+	int init(IPAContext &context, const YamlObject &tuningData) override;
+	void prepare(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     C3ISPParams *params) override;
+private:
+	std::vector<int16_t> cscCoeff_;
+};
+
+} /* namespace ipa::c3isp::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/c3-isp/algorithms/meson.build b/src/ipa/c3-isp/algorithms/meson.build
index 591c2433..5e7e56db 100644
--- a/src/ipa/c3-isp/algorithms/meson.build
+++ b/src/ipa/c3-isp/algorithms/meson.build
@@ -5,4 +5,5 @@  c3isp_ipa_algorithms = files([
     'awb.cpp',
     'blc.cpp',
     'ccm.cpp',
+    'csc.cpp',
 ])