about summary refs log tree commit diff
path: root/users/flokli/ipu6-softisp/libcamera/0007-libcamera-software_isp-Add-Debayer-base-class.patch
blob: 7c7170989666452fe3e597e530a3ad04f5f3da7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
From 25e6893e46bd2174f6913eea79817988d9280706 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Mon, 11 Mar 2024 15:15:11 +0100
Subject: [PATCH 07/21] libcamera: software_isp: Add Debayer base class

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.

Doxygen documentation by Dennis Bonke.

Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s
Tested-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Pavel Machek <pavel@ucw.cz>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Co-developed-by: Dennis Bonke <admin@dennisbonke.com>
Signed-off-by: Dennis Bonke <admin@dennisbonke.com>
Co-developed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../internal/software_isp/debayer_params.h    |  48 ++++++++
 .../internal/software_isp/meson.build         |   1 +
 src/libcamera/software_isp/debayer.cpp        |  29 +++++
 src/libcamera/software_isp/debayer.h          | 104 ++++++++++++++++++
 src/libcamera/software_isp/meson.build        |   1 +
 5 files changed, 183 insertions(+)
 create mode 100644 include/libcamera/internal/software_isp/debayer_params.h
 create mode 100644 src/libcamera/software_isp/debayer.cpp
 create mode 100644 src/libcamera/software_isp/debayer.h

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..98965fa1
--- /dev/null
+++ b/include/libcamera/internal/software_isp/debayer_params.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ *
+ * debayer_params.h - DebayerParams header
+ */
+
+#pragma once
+
+namespace libcamera {
+
+/**
+ * \brief Struct to hold the debayer parameters.
+ */
+struct DebayerParams {
+	/**
+	 * \brief const value for 1.0 gain
+	 */
+	static constexpr unsigned int kGain10 = 256;
+
+	/**
+	 * \brief Red Gain
+	 *
+	 * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc.
+	 */
+	unsigned int gainR;
+	/**
+	 * \brief Green Gain
+	 *
+	 * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc.
+	 */
+	unsigned int gainG;
+	/**
+	 * \brief Blue Gain
+	 *
+	 * 128 = 0.5, 256 = 1.0, 512 = 2.0, etc.
+	 */
+	unsigned int gainB;
+	/**
+	 * \brief 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 66c9c3fb..a620e16d 100644
--- a/include/libcamera/internal/software_isp/meson.build
+++ b/include/libcamera/internal/software_isp/meson.build
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: CC0-1.0
 
 libcamera_internal_headers += files([
+    'debayer_params.h',
     'swisp_stats.h',
 ])
diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp
new file mode 100644
index 00000000..64f0b5a0
--- /dev/null
+++ b/src/libcamera/software_isp/debayer.cpp
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Linaro Ltd
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@redhat.com>
+ *
+ * debayer.cpp - debayer base class
+ */
+
+#include "debayer.h"
+
+namespace libcamera {
+
+/**
+ * \class Debayer
+ * \brief Base debayering class
+ *
+ * Base class that provides functions for setting up the debayering process.
+ */
+
+LOG_DEFINE_CATEGORY(Debayer)
+
+Debayer::~Debayer()
+{
+}
+
+} /* namespace libcamera */
diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h
new file mode 100644
index 00000000..8880ff99
--- /dev/null
+++ b/src/libcamera/software_isp/debayer.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Linaro Ltd
+ * Copyright (C) 2023, Red Hat Inc.
+ *
+ * Authors:
+ * Hans de Goede <hdegoede@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;
+
+	/**
+	 * \brief Configure the debayer object according to the passed in parameters.
+	 * \param[in] inputCfg The input configuration.
+	 * \param[in] outputCfgs The output configurations.
+	 *
+	 * \return 0 on success, a negative errno on failure.
+	 */
+	virtual int configure(const StreamConfiguration &inputCfg,
+			      const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
+
+	/**
+	 * \brief Get the width and height at which the bayer pattern repeats.
+	 * \param[in] inputFormat The input format.
+	 *
+	 * Valid sizes are: 2x2, 4x2 or 4x4.
+	 *
+	 * \return pattern size or an empty size for unsupported inputFormats.
+	 */
+	virtual Size patternSize(PixelFormat inputFormat) = 0;
+
+	/**
+	 * \brief Get the supported output formats.
+	 * \param[in] inputFormat The input format.
+	 *
+	 * \return all supported output formats or an empty vector if there are none.
+	 */
+	virtual std::vector<PixelFormat> formats(PixelFormat inputFormat) = 0;
+
+	/**
+	 * \brief Get the stride and the frame size.
+	 * \param[in] outputFormat The output format.
+	 * \param[in] size The output size.
+	 *
+	 * \return a tuple of the stride and the frame size, or a tuple with 0,0 if there is no valid output config.
+	 */
+	virtual std::tuple<unsigned int, unsigned int>
+	strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) = 0;
+
+	/**
+	 * \brief Process the bayer data into the requested format.
+	 * \param[in] input The input buffer.
+	 * \param[in] output The output buffer.
+	 * \param[in] params The parameters to be used in debayering.
+	 *
+	 * \note DebayerParams is passed by value deliberately so that a copy is passed
+	 * when this is run in another thread by invokeMethod().
+	 */
+	virtual void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params) = 0;
+
+	/**
+	 * \brief Get the supported output sizes for the given input format and size.
+	 * \param[in] inputFormat The input format.
+	 * \param[in] inputSize The input size.
+	 *
+	 * \return The valid size ranges or an empty range if there are none.
+	 */
+	virtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0;
+
+	/**
+	 * \brief Signals when the input buffer is ready.
+	 */
+	Signal<FrameBuffer *> inputBufferReady;
+
+	/**
+	 * \brief Signals when the output buffer is ready.
+	 */
+	Signal<FrameBuffer *> outputBufferReady;
+};
+
+} /* namespace libcamera */
diff --git a/src/libcamera/software_isp/meson.build b/src/libcamera/software_isp/meson.build
index fcfff74a..62095f61 100644
--- a/src/libcamera/software_isp/meson.build
+++ b/src/libcamera/software_isp/meson.build
@@ -8,5 +8,6 @@ if not (softisp_enabled)
 endif
 
 libcamera_sources += files([
+    'debayer.cpp',
     'swstats_cpu.cpp',
 ])
-- 
2.43.2