[libcamera-devel] [PATCH 4/4] ipa: rkisp1: Add support of ColorProcessing control

Florian Sylvestre fsylvestre at baylibre.com
Mon Jul 4 17:23:18 CEST 2022


Add ColorProcessing algorithm that is in charge to manage brightness, contrast
and saturation controls.
These controls are currently based on user controls.

Signed-off-by: Florian Sylvestre <fsylvestre at baylibre.com>
---
 .../rkisp1/algorithms/color_processing.cpp    | 101 ++++++++++++++++++
 src/ipa/rkisp1/algorithms/color_processing.h  |  38 +++++++
 src/ipa/rkisp1/algorithms/meson.build         |   1 +
 src/ipa/rkisp1/data/ov5640.yaml               |   1 +
 src/ipa/rkisp1/rkisp1.cpp                     |   1 +
 src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  12 +++
 6 files changed, 154 insertions(+)
 create mode 100644 src/ipa/rkisp1/algorithms/color_processing.cpp
 create mode 100644 src/ipa/rkisp1/algorithms/color_processing.h

diff --git a/src/ipa/rkisp1/algorithms/color_processing.cpp b/src/ipa/rkisp1/algorithms/color_processing.cpp
new file mode 100644
index 00000000..a7f2a470
--- /dev/null
+++ b/src/ipa/rkisp1/algorithms/color_processing.cpp
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021-2022, Ideas On Board
+ *
+ * lsc.cpp - RkISP1 Defect Pixel Cluster Correction control
+ */
+
+#include "color_processing.h"
+
+#include <libcamera/base/log.h>
+
+#include <libcamera/control_ids.h>
+
+#include "libcamera/internal/yaml_parser.h"
+#include "linux/rkisp1-config.h"
+
+/**
+ * \file color-processing.h
+ */
+
+namespace libcamera {
+
+namespace ipa::rkisp1::algorithms {
+
+/**
+ * \class ColorProcessing
+ * \brief RkISP1 Color Processing control
+ *
+ * The ColorProcessing algorithm is responsible to apply brightness, contrast
+ * and saturation corrections.
+ * The coefficient applied for brightness, contrast and saturation are directly
+ * provided by user controls.
+ */
+
+LOG_DEFINE_CATEGORY(RkISP1ColorProcessing)
+
+ColorProcessing::ColorProcessing()
+	: userBrightness_(0), userContrast_(0),
+	  userSaturation_(0), updateUserControls_(true)
+{
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::queueRequest
+ */
+void ColorProcessing::queueRequest([[maybe_unused]] IPAContext &context,
+				   [[maybe_unused]] const uint32_t frame,
+				   const ControlList &controls)
+{
+	for (auto const &ctrl : controls) {
+		if (ctrl.first == controls::BRIGHTNESS) {
+			userBrightness_ = ctrl.second.get<float>();
+			updateUserControls_ = true;
+
+			LOG(RkISP1ColorProcessing, Debug)
+				<< "Set brightness to: "
+				<< int(userBrightness_);
+		} else if (ctrl.first == controls::CONTRAST) {
+			userContrast_ = ctrl.second.get<float>();
+			updateUserControls_ = true;
+
+			LOG(RkISP1ColorProcessing, Debug)
+				<< "Set contrast to: "
+				<< int(userContrast_);
+		} else if (ctrl.first == controls::SATURATION) {
+			userSaturation_ = ctrl.second.get<float>();
+			updateUserControls_ = true;
+
+			LOG(RkISP1ColorProcessing, Debug)
+				<< "Set saturation to: "
+				<< int(userSaturation_);
+		}
+	}
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void ColorProcessing::prepare([[maybe_unused]] IPAContext &context,
+			      rkisp1_params_cfg *params)
+{
+	/* Check if the algorithm configuration has been updated. */
+	if (!updateUserControls_)
+		return;
+
+	updateUserControls_ = false;
+
+	params->others.cproc_config.brightness = userBrightness_;
+	params->others.cproc_config.contrast = userContrast_;
+	params->others.cproc_config.sat = userSaturation_;
+
+	params->module_en_update |= RKISP1_CIF_ISP_MODULE_CPROC;
+	params->module_ens |= RKISP1_CIF_ISP_MODULE_CPROC;
+	params->module_cfg_update |= RKISP1_CIF_ISP_MODULE_CPROC;
+}
+
+REGISTER_IPA_ALGORITHM(ColorProcessing, "ColorProcessing")
+
+} /* namespace ipa::rkisp1::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/rkisp1/algorithms/color_processing.h b/src/ipa/rkisp1/algorithms/color_processing.h
new file mode 100644
index 00000000..bdb40bd1
--- /dev/null
+++ b/src/ipa/rkisp1/algorithms/color_processing.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2021-2022, Ideas On Board
+ *
+ * dpcc.h - RkISP1 Color Processing control
+ */
+
+#pragma once
+
+#include <sys/types.h>
+#include <linux/rkisp1-config.h>
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+struct IPACameraSensorInfo;
+
+namespace ipa::rkisp1::algorithms {
+
+class ColorProcessing : public Algorithm
+{
+public:
+	ColorProcessing();
+	~ColorProcessing() = default;
+
+	void queueRequest(IPAContext &context, const uint32_t frame,
+			  const ControlList &controls) override;
+	void prepare(IPAContext &context, rkisp1_params_cfg *params) override;
+private:
+	uint32_t userBrightness_;
+	uint32_t userContrast_;
+	uint32_t userSaturation_;
+	bool updateUserControls_;
+};
+
+} /* namespace ipa::rkisp1::algorithms */
+} /* namespace libcamera */
diff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build
index 7e078b0d..7f9c3899 100644
--- a/src/ipa/rkisp1/algorithms/meson.build
+++ b/src/ipa/rkisp1/algorithms/meson.build
@@ -4,6 +4,7 @@ rkisp1_ipa_algorithms = files([
     'agc.cpp',
     'awb.cpp',
     'blc.cpp',
+    'color_processing.cpp',
     'demosaicing.cpp',
     'dpcc.cpp',
     'gsl.cpp',
diff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml
index 4ae0ffc0..331f9d2d 100644
--- a/src/ipa/rkisp1/data/ov5640.yaml
+++ b/src/ipa/rkisp1/data/ov5640.yaml
@@ -10,6 +10,7 @@ algorithms:
       Gr: 256
       Gb: 256
       B:  256
+  - ColorProcessing:
   - GammaSensorLinearization:
       x-intervals: [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]
       y:
diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
index 85a75070..d380c59b 100644
--- a/src/ipa/rkisp1/rkisp1.cpp
+++ b/src/ipa/rkisp1/rkisp1.cpp
@@ -31,6 +31,7 @@
 #include "algorithms/algorithm.h"
 #include "algorithms/awb.h"
 #include "algorithms/blc.h"
+#include "algorithms/color_processing.h"
 #include "algorithms/demosaicing.h"
 #include "algorithms/dpcc.h"
 #include "algorithms/gsl.h"
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 3d0075ee..4e82ab39 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -957,6 +957,18 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)
 		      std::forward_as_tuple(&controls::Sharpness),
 		      std::forward_as_tuple(0.0f, 10.0f, 1.0f));
 
+	ctrls.emplace(std::piecewise_construct,
+		      std::forward_as_tuple(&controls::Brightness),
+		      std::forward_as_tuple(-128.0f, 127.0f));
+
+	ctrls.emplace(std::piecewise_construct,
+		      std::forward_as_tuple(&controls::Contrast),
+		      std::forward_as_tuple(0.0f, 1.992f));
+
+	ctrls.emplace(std::piecewise_construct,
+		      std::forward_as_tuple(&controls::Saturation),
+		      std::forward_as_tuple(0.0f, 1.992f));
+
 	ctrls.emplace(std::piecewise_construct,
 		      std::forward_as_tuple(&controls::draft::NoiseReductionMode),
 		      std::forward_as_tuple(controls::draft::NoiseReductionModeValues));
-- 
2.34.1



More information about the libcamera-devel mailing list