[libcamera-devel] [PATCH 05/11] libcamera: software_isp: Add Debayer base class
Hans de Goede
hdegoede at redhat.com
Thu Dec 14 13:13:43 CET 2023
Add a base class for debayer implementations. This is intended to be
suitable for both GPU (or otherwise) accelerated debayer implementations
as well as CPU based debayering.
Co-authored-by: Andrey Konovalov <andrey.konovalov at linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov at linaro.org>
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
.../libcamera/internal/software_isp/debayer.h | 90 +++++++++++++++++++
.../internal/software_isp/debayer_params.h | 24 +++++
.../internal/software_isp/meson.build | 2 +
src/libcamera/software_isp/debayer.cpp | 22 +++++
src/libcamera/software_isp/meson.build | 1 +
5 files changed, 139 insertions(+)
create mode 100644 include/libcamera/internal/software_isp/debayer.h
create mode 100644 include/libcamera/internal/software_isp/debayer_params.h
create mode 100644 src/libcamera/software_isp/debayer.cpp
diff --git a/include/libcamera/internal/software_isp/debayer.h b/include/libcamera/internal/software_isp/debayer.h
new file mode 100644
index 00000000..206bc2ac
--- /dev/null
+++ b/include/libcamera/internal/software_isp/debayer.h
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Linaro Ltd
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede at redhat.com>
+ *
+ * debayer.h - debayering base class
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include <libcamera/base/log.h>
+#include <libcamera/base/signal.h>
+
+#include <libcamera/geometry.h>
+#include <libcamera/stream.h>
+
+#include "libcamera/internal/software_isp/debayer_params.h"
+
+namespace libcamera {
+
+class FrameBuffer;
+
+LOG_DECLARE_CATEGORY(Debayer)
+
+class Debayer
+{
+public:
+ virtual ~Debayer() = 0;
+
+ /*
+ * Setup the Debayer object according to the passed in parameters.
+ * Return 0 on success, a negative errno value on failure
+ * (unsupported parameters).
+ */
+ virtual int configure(const StreamConfiguration &inputCfg,
+ const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
+
+ /*
+ * Get width and height at which the bayer-pattern repeats.
+ * Return pattern-size or an empty Size for an unsupported inputFormat.
+ */
+ virtual Size patternSize(PixelFormat inputFormat) = 0;
+
+ virtual std::vector<PixelFormat> formats(PixelFormat inputFormat) = 0;
+ virtual std::tuple<unsigned int, unsigned int>
+ strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) = 0;
+
+ /*
+ * Note DebayerParams is passed by value deliberately so that a copy is passed
+ * when this is run in another thread to invokeMethod.
+ */
+ virtual void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params) = 0;
+
+ /* sizes() - Get supported output sizes for given input fmt + size */
+ SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
+ {
+ Size pattern_size = patternSize(inputFormat);
+
+ if (pattern_size.isNull())
+ return {};
+
+ /*
+ * For debayer interpolation a border of pattern-height x pattern-width
+ * is kept around the entire image. Combined with a minimum-size of
+ * pattern-height x pattern-width this means the input-size needs to be
+ * at least (3 * pattern-height) x (3 * pattern-width).
+ */
+ if (inputSize.width < (3 * pattern_size.width) ||
+ inputSize.height < (3 * pattern_size.height)) {
+ LOG(Debayer, Warning)
+ << "Input format size too small: " << inputSize.toString();
+ return {};
+ }
+
+ return SizeRange(Size(pattern_size.width, pattern_size.height),
+ Size((inputSize.width - 2 * pattern_size.width) & ~(pattern_size.width - 1),
+ (inputSize.height - 2 * pattern_size.height) & ~(pattern_size.height - 1)),
+ pattern_size.width, pattern_size.height);
+ }
+
+ Signal<FrameBuffer *> inputBufferReady;
+ Signal<FrameBuffer *> outputBufferReady;
+};
+
+} /* namespace libcamera */
diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h
new file mode 100644
index 00000000..885d3605
--- /dev/null
+++ b/include/libcamera/internal/software_isp/debayer_params.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede at redhat.com>
+ *
+ * swstats.h - software statistics base class
+ */
+
+#pragma once
+
+namespace libcamera {
+
+struct DebayerParams {
+ /* Red Gain, 128 = 0.5, 256 = 1.0, 512 = 2.0, etc. */
+ unsigned int gainR;
+ /* Blue Gain, same range as Red Gain. */
+ unsigned int gainB;
+ /* Gamma correction, 1.0 is no correction. */
+ float gamma;
+};
+
+} /* namespace libcamera */
diff --git a/include/libcamera/internal/software_isp/meson.build b/include/libcamera/internal/software_isp/meson.build
index 1d9e4018..7e40925e 100644
--- a/include/libcamera/internal/software_isp/meson.build
+++ b/include/libcamera/internal/software_isp/meson.build
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: CC0-1.0
libcamera_internal_headers += files([
+ 'debayer.h',
+ 'debayer_params.h',
'swisp_stats.h',
'swstats.h',
'swstats_cpu.h',
diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp
new file mode 100644
index 00000000..442da1ac
--- /dev/null
+++ b/src/libcamera/software_isp/debayer.cpp
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Linaro Ltd
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede at redhat.com>
+ *
+ * debayer.cpp - debayer base class
+ */
+
+#include "libcamera/internal/software_isp/debayer.h"
+
+namespace libcamera {
+
+LOG_DEFINE_CATEGORY(Debayer)
+
+Debayer::~Debayer()
+{
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build
index d31c6217..d4ae5ac7 100644
--- a/src/libcamera/software_isp/meson.build
+++ b/src/libcamera/software_isp/meson.build
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: CC0-1.0
libcamera_sources += files([
+ 'debayer.cpp',
'swstats.cpp',
'swstats_cpu.cpp',
])
--
2.41.0
More information about the libcamera-devel
mailing list