[libcamera-devel,3/8] ipa: rkisp1: Add AF algorithm basing on common AfHillClimbing class
diff mbox series

Message ID 20220630143543.39599-4-dse@thaumatec.com
State Superseded
Headers show
Series
  • ipa: rkisp1: Add autofocus algorithm
Related show

Commit Message

Daniel Semkowicz June 30, 2022, 2:35 p.m. UTC
Rockchip ISP AF block allows calculation of sharpness and luminance
in up to three user defined windows. If no windows are set, there are
some default settings applied for the first window and exposed through
the driver. For each frame, use the sharpness value calculated for this
default window and feed the hill climbing algorithm with them. Then set
the lens position to value calculated by the algorithm.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
---
 src/ipa/rkisp1/algorithms/af.cpp      | 70 +++++++++++++++++++++++++++
 src/ipa/rkisp1/algorithms/af.h        | 32 ++++++++++++
 src/ipa/rkisp1/algorithms/meson.build |  1 +
 3 files changed, 103 insertions(+)
 create mode 100644 src/ipa/rkisp1/algorithms/af.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/af.h

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/af.cpp b/src/ipa/rkisp1/algorithms/af.cpp
new file mode 100644
index 00000000..8da970e3
--- /dev/null
+++ b/src/ipa/rkisp1/algorithms/af.cpp
@@ -0,0 +1,70 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Theobroma Systems
+ *
+ * af.cpp - AF control algorithm
+ */
+
+#include "af.h"
+
+/**
+ * \file af.h
+ */
+
+namespace libcamera::ipa::rkisp1::algorithms {
+
+/**
+ * \class Af
+ * \brief AF control algorithm
+ */
+
+LOG_DEFINE_CATEGORY(RkISP1Af)
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::configure
+ */
+int Af::configure([[maybe_unused]] IPAContext &context,
+		  [[maybe_unused]] const IPACameraSensorInfo &configInfo)
+{
+	return 0;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void Af::prepare([[maybe_unused]] IPAContext &context, [[maybe_unused]] rkisp1_params_cfg *params)
+{
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::process
+ */
+void Af::process(IPAContext &context,
+		 [[maybe_unused]] IPAFrameContext *frameCtx,
+		 const rkisp1_stat_buffer *stats)
+{
+	uint32_t sharpness = stats->params.af.window[0].sum;
+	uint32_t luminance = stats->params.af.window[0].lum;
+
+	LOG(RkISP1Af, Debug) << "lensPosition: " << context.frameContext.af.focus
+			     << ", Sharpness: " << sharpness
+			     << ", Luminance: " << luminance;
+
+	uint32_t lensPosition = processAutofocus(sharpness);
+
+	context.frameContext.af.focus = lensPosition;
+}
+
+void Af::setMetering([[maybe_unused]] controls::AfMeteringEnum metering)
+{
+	LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!";
+}
+
+void Af::setWindows([[maybe_unused]] Span<const Rectangle> windows)
+{
+	LOG(RkISP1Af, Error) << __FUNCTION__ << " not implemented!";
+}
+
+REGISTER_IPA_ALGORITHM(Af, "Af")
+
+} /* namespace libcamera::ipa::rkisp1::algorithms */
diff --git a/src/ipa/rkisp1/algorithms/af.h b/src/ipa/rkisp1/algorithms/af.h
new file mode 100644
index 00000000..c470c9b2
--- /dev/null
+++ b/src/ipa/rkisp1/algorithms/af.h
@@ -0,0 +1,32 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2022, Theobroma Systems
+ *
+ * af.h - AF control algorithm
+ */
+
+#pragma once
+
+#include <linux/rkisp1-config.h>
+
+#include "libipa/algorithms/af_hill_climbing.h"
+#include "module.h"
+
+namespace libcamera::ipa::rkisp1::algorithms {
+
+class Af : public ipa::common::algorithms::AfHillClimbing<Module>
+{
+public:
+	Af() = default;
+	~Af() = default;
+
+	int configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override;
+	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
+	void process(IPAContext &context, IPAFrameContext *frameCtx,
+		     const rkisp1_stat_buffer *stats) override;
+
+	void setMetering(controls::AfMeteringEnum metering) override;
+	void setWindows(Span<const Rectangle> windows) override;
+};
+
+} /* namespace libcamera::ipa::rkisp1::algorithms */
diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build
index 7ec53d89..81addcc9 100644
--- a/src/ipa/rkisp1/algorithms/meson.build
+++ b/src/ipa/rkisp1/algorithms/meson.build
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: CC0-1.0
 
 rkisp1_ipa_algorithms = files([
+    'af.cpp',
     'agc.cpp',
     'awb.cpp',
     'blc.cpp',