[v3,10/11] ipa: c3-isp: Add Post Gamma Algorithm
diff mbox series

Message ID 20250227105733.187611-11-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 Post Gamma algorithm.

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

Patch
diff mbox series

diff --git a/src/ipa/c3-isp/algorithms/meson.build b/src/ipa/c3-isp/algorithms/meson.build
index 5e7e56db..57600f12 100644
--- a/src/ipa/c3-isp/algorithms/meson.build
+++ b/src/ipa/c3-isp/algorithms/meson.build
@@ -6,4 +6,5 @@  c3isp_ipa_algorithms = files([
     'blc.cpp',
     'ccm.cpp',
     'csc.cpp',
+    'post_gamma.cpp',
 ])
diff --git a/src/ipa/c3-isp/algorithms/post_gamma.cpp b/src/ipa/c3-isp/algorithms/post_gamma.cpp
new file mode 100644
index 00000000..f8c1a1da
--- /dev/null
+++ b/src/ipa/c3-isp/algorithms/post_gamma.cpp
@@ -0,0 +1,65 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Amlogic
+ *
+ * C3ISP Post Gamma control
+ */
+
+#include "post_gamma.h"
+
+#include <libcamera/base/log.h>
+
+/**
+ * \file post_gamma.h
+ */
+
+namespace libcamera {
+
+namespace ipa::c3isp::algorithms {
+
+/**
+ * \class PostGamma
+ * \brief A post gamma algorithm
+ */
+
+LOG_DEFINE_CATEGORY(C3ISPPostGamma)
+
+PostGamma::PostGamma()
+{
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::init
+ */
+int PostGamma::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)
+{
+	gammaLut_ = tuningData["gammaLut"].getList<uint16_t>().value_or(std::vector<uint16_t>{});
+	if (gammaLut_.size() != 129) {
+		LOG(C3ISPPostGamma, Error) << "Invalid gamma Look-up table size";
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void PostGamma::prepare([[maybe_unused]] IPAContext &context,
+			[[maybe_unused]] const uint32_t frame,
+			[[maybe_unused]] IPAFrameContext &frameContext,
+			C3ISPParams *params)
+{
+	auto PostGammaCfg = params->block<BlockType::PostGamma>();
+	PostGammaCfg.setEnabled(C3_ISP_PARAMS_BLOCK_FL_ENABLE);
+
+	for (unsigned int i = 0; i < 129; i++) {
+		PostGammaCfg->lut[i] = gammaLut_[i];
+	}
+}
+
+REGISTER_IPA_ALGORITHM(PostGamma, "PostGamma")
+
+} /* namespace ipa::c3isp::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/c3-isp/algorithms/post_gamma.h b/src/ipa/c3-isp/algorithms/post_gamma.h
new file mode 100644
index 00000000..44d8f9db
--- /dev/null
+++ b/src/ipa/c3-isp/algorithms/post_gamma.h
@@ -0,0 +1,33 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2024, Amlogic
+ *
+ * C3ISP Post Gamma control
+ */
+
+#pragma once
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::c3isp::algorithms {
+
+class PostGamma : public Algorithm
+{
+public:
+	PostGamma();
+	~PostGamma() = 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<uint16_t> gammaLut_;
+};
+
+} /* namespace ipa::c3isp::algorithms */
+
+} /* namespace libcamera */