[09/22] libcamera: software_isp: Move useful items from DebayerCpu to Debayer base class
diff mbox series

Message ID 20251120232019.3590-10-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • GPUISP precursor series
Related show

Commit Message

Bryan O'Donoghue Nov. 20, 2025, 11:20 p.m. UTC
The DebayerCpu class has a number of variables, embedded structures and
methods which are useful to DebayerGpu implementation.

Move relevant variables and methods to base class.

Since we want to call setParams() from the GPUISP and reuse the code in
the existing CPUISP as a first step, we need to move all of the
dependent variables in DebayerCPU to the Debayer base class including
LookupTable and redCcm_.

The DebayerEGL class will ultimately be able to consume both the CCM and
non-CCM data.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 src/libcamera/software_isp/debayer.cpp     |  6 +++
 src/libcamera/software_isp/debayer.h       | 63 +++++++++++++++++++++-
 src/libcamera/software_isp/debayer_cpu.cpp |  2 +-
 src/libcamera/software_isp/debayer_cpu.h   | 41 +-------------
 4 files changed, 70 insertions(+), 42 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp
index e9e18c488..e9130df1e 100644
--- a/src/libcamera/software_isp/debayer.cpp
+++ b/src/libcamera/software_isp/debayer.cpp
@@ -18,6 +18,12 @@  namespace libcamera {
  * \brief Struct to hold the debayer parameters.
  */
 
+/**
+ * \fn Debayer::Debayer(const GlobalConfiguration &configuration)
+ * \brief Construct a Debayer object
+ * \param[in] configuration Global configuration reference
+ */
+
 /**
  * \var DebayerParams::kRGBLookupSize
  * \brief Size of a color lookup table
diff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h
index ba033d440..578535b20 100644
--- a/src/libcamera/software_isp/debayer.h
+++ b/src/libcamera/software_isp/debayer.h
@@ -14,11 +14,14 @@ 
 #include <stdint.h>
 
 #include <libcamera/base/log.h>
+#include <libcamera/base/object.h>
 #include <libcamera/base/signal.h>
 
 #include <libcamera/geometry.h>
 #include <libcamera/stream.h>
 
+#include "libcamera/internal/global_configuration.h"
+#include "libcamera/internal/software_isp/benchmark.h"
 #include "libcamera/internal/software_isp/debayer_params.h"
 
 namespace libcamera {
@@ -27,9 +30,10 @@  class FrameBuffer;
 
 LOG_DECLARE_CATEGORY(Debayer)
 
-class Debayer
+class Debayer : public Object
 {
 public:
+	Debayer (const GlobalConfiguration &configuration) : bench_(configuration) {};
 	virtual ~Debayer() = 0;
 
 	virtual int configure(const StreamConfiguration &inputCfg,
@@ -45,10 +49,67 @@  public:
 
 	virtual SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) = 0;
 
+	/**
+	 * \brief Get the file descriptor for the statistics
+	 *
+	 * \return the file descriptor pointing to the statistics
+	 */
+	virtual const SharedFD &getStatsFD() = 0;
+
+	/**
+	 * \brief Get the output frame size
+	 *
+	 * \return The output frame size
+	 */
+	unsigned int frameSize() { return outputConfig_.frameSize; }
+
 	Signal<FrameBuffer *> inputBufferReady;
 	Signal<FrameBuffer *> outputBufferReady;
 
+	/**
+	 * struct DebayerInputConfig
+	 *
+	 * Structure to describe the incoming Bayer parameters.
+	 */
+	struct DebayerInputConfig {
+		Size patternSize;			/**< patternSize size of the Bayer pattern in pixels */
+		unsigned int bpp;			/**< bpp Memory used per pixel, not precision */
+		unsigned int stride;			/**< stride Line stride in bytes */
+		std::vector<PixelFormat> outputFormats;	/**< outputFormats List of supported output pixel formats */
+	};
+
+	/**
+	 * struct DebayerOutputConfig
+	 *
+	 * Structure to describe the output pattern requested to the Debayer logic.
+	 */
+	struct DebayerOutputConfig {
+		unsigned int bpp;			/**< bpp Memory used per pixel, not precision */
+		unsigned int stride;			/**< stride Line stride in bytes */
+		unsigned int frameSize;			/**< framesize Total frame size in bytes */
+	};
+
+	DebayerInputConfig inputConfig_;		/**< inputConfig_ debayer input config params */
+	DebayerOutputConfig outputConfig_;		/**< outputConfig_ debayer output config data */
+	DebayerParams::LookupTable red_;		/**< red_ DebayerParams red_ lookup table */
+	DebayerParams::LookupTable green_;		/**< green_ DebayerParams green_ lookup table */
+	DebayerParams::LookupTable blue_;		/**< blue_ DebayerParams blue_ lookup table */
+	DebayerParams::CcmLookupTable redCcm_;		/**< redCcm_ Red Colour Correction matrix lookup table */
+	DebayerParams::CcmLookupTable greenCcm_;	/**< greenCcm_ Green Colour Correction matrix lookup table */
+	DebayerParams::CcmLookupTable blueCcm_;		/**< blueCcm_ Blue Colour Correction matrix lookup table */
+	DebayerParams::LookupTable gammaLut_;		/**< gammaLut_ Gamma Lut lookup table */
+	bool swapRedBlueGains_;				/**< swapRedBlueGains_ bool to indicate swapping of red/blue gains */
+	Benchmark bench_;				/**< bench_ an instance of the Benchmark class */
+
 private:
+	/**
+	 * \fn patternSize(PixelFormat inputFormat)
+	 * \var DebayerInputConfig::patternSize
+	 * \brief Size of the Bayer pattern in pixels
+	 *
+	 * The width and height of the Bayer color filter array pattern. For standard
+	 * Bayer formats (BGGR, GRBG, GBRG, RGGB) this is typically 2x2 pixels.
+	 */
 	virtual Size patternSize(PixelFormat inputFormat) = 0;
 };
 
diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
index b92c6a904..e55599f09 100644
--- a/src/libcamera/software_isp/debayer_cpu.cpp
+++ b/src/libcamera/software_isp/debayer_cpu.cpp
@@ -42,7 +42,7 @@  namespace libcamera {
  * \param[in] configuration The global configuration
  */
 DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration)
-	: stats_(std::move(stats)), bench_(configuration)
+	: Debayer(configuration), stats_(std::move(stats))
 {
 	/*
 	 * Reading from uncached buffers may be very slow.
diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h
index aff32491e..ecc4f9dd0 100644
--- a/src/libcamera/software_isp/debayer_cpu.h
+++ b/src/libcamera/software_isp/debayer_cpu.h
@@ -17,16 +17,14 @@ 
 
 #include <libcamera/base/object.h>
 
-#include "libcamera/internal/software_isp/benchmark.h"
 #include "libcamera/internal/bayer_format.h"
-#include "libcamera/internal/global_configuration.h"
 #include "libcamera/internal/software_isp/swstats_cpu.h"
 
 #include "debayer.h"
 
 namespace libcamera {
 
-class DebayerCpu : public Debayer, public Object
+class DebayerCpu : public Debayer
 {
 public:
 	DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
@@ -41,21 +39,8 @@  public:
 	strideAndFrameSize(const PixelFormat &outputFormat, const Size &size);
 	void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params);
 	SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
-
-	/**
-	 * \brief Get the file descriptor for the statistics
-	 *
-	 * \return the file descriptor pointing to the statistics
-	 */
 	const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
 
-	/**
-	 * \brief Get the output frame size
-	 *
-	 * \return The output frame size
-	 */
-	unsigned int frameSize() { return outputConfig_.frameSize; }
-
 private:
 	/**
 	 * \brief Called to debayer 1 line of Bayer input data to output format
@@ -112,19 +97,6 @@  private:
 	template<bool addAlphaByte, bool ccmEnabled>
 	void debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]);
 
-	struct DebayerInputConfig {
-		Size patternSize;
-		unsigned int bpp; /* Memory used per pixel, not precision */
-		unsigned int stride;
-		std::vector<PixelFormat> outputFormats;
-	};
-
-	struct DebayerOutputConfig {
-		unsigned int bpp; /* Memory used per pixel, not precision */
-		unsigned int stride;
-		unsigned int frameSize;
-	};
-
 	int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
 	int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
 	int setupStandardBayerOrder(BayerFormat::Order order);
@@ -140,20 +112,11 @@  private:
 	/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */
 	static constexpr unsigned int kMaxLineBuffers = 5;
 
-	DebayerParams::LookupTable red_;
-	DebayerParams::LookupTable green_;
-	DebayerParams::LookupTable blue_;
-	DebayerParams::CcmLookupTable redCcm_;
-	DebayerParams::CcmLookupTable greenCcm_;
-	DebayerParams::CcmLookupTable blueCcm_;
-	DebayerParams::LookupTable gammaLut_;
 	debayerFn debayer0_;
 	debayerFn debayer1_;
 	debayerFn debayer2_;
 	debayerFn debayer3_;
 	Rectangle window_;
-	DebayerInputConfig inputConfig_;
-	DebayerOutputConfig outputConfig_;
 	std::unique_ptr<SwStatsCpu> stats_;
 	std::vector<uint8_t> lineBuffers_[kMaxLineBuffers];
 	unsigned int lineBufferLength_;
@@ -161,8 +124,6 @@  private:
 	unsigned int lineBufferIndex_;
 	unsigned int xShift_; /* Offset of 0/1 applied to window_.x */
 	bool enableInputMemcpy_;
-	bool swapRedBlueGains_;
-	Benchmark bench_;
 };
 
 } /* namespace libcamera */