[PATCH 03/16] libcamera: software_isp: Separate allocation of the parameters buffer

Milan Zamazal mzamazal at redhat.com
Mon Aug 12 13:49:52 CEST 2024


There will be some additions to that code in followup patches and let's
not blow the code in SoftwareIsp constructor even more.

Signed-off-by: Milan Zamazal <mzamazal at redhat.com>
---
 .../internal/software_isp/software_isp.h      |  1 +
 src/libcamera/software_isp/software_isp.cpp   | 51 +++++++++++--------
 2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h
index d2b47ecc..fc9200dd 100644
--- a/include/libcamera/internal/software_isp/software_isp.h
+++ b/include/libcamera/internal/software_isp/software_isp.h
@@ -95,6 +95,7 @@ private:
 	Thread ispWorkerThread_;
 	SharedMemObject<DebayerParams> sharedParams_;
 	DebayerParams debayerParams_;
+	bool allocateParamsBuffers();
 	DmaBufAllocator dmaHeap_;
 
 	std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;
diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp
index 0412b401..3f41b71d 100644
--- a/src/libcamera/software_isp/software_isp.cpp
+++ b/src/libcamera/software_isp/software_isp.cpp
@@ -68,33 +68,12 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)
 		   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |
 		   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)
 {
-	/*
-	 * debayerParams_ must be initialized because the initial value is used for
-	 * the first two frames, i.e. until stats processing starts providing its
-	 * own parameters.
-	 *
-	 * \todo This should be handled in the same place as the related
-	 * operations, in the IPA module.
-	 */
-	std::array<uint8_t, 256> gammaTable;
-	for (unsigned int i = 0; i < 256; i++)
-		gammaTable[i] = UINT8_MAX * std::pow(i / 256.0, 0.5);
-	for (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {
-		debayerParams_.red[i] = gammaTable[i];
-		debayerParams_.green[i] = gammaTable[i];
-		debayerParams_.blue[i] = gammaTable[i];
-	}
-
 	if (!dmaHeap_.isValid()) {
 		LOG(SoftwareIsp, Error) << "Failed to create DmaBufAllocator object";
 		return;
 	}
-
-	sharedParams_ = SharedMemObject<DebayerParams>("softIsp_params");
-	if (!sharedParams_) {
-		LOG(SoftwareIsp, Error) << "Failed to create shared memory for parameters";
+	if (!allocateParamsBuffers())
 		return;
-	}
 
 	auto stats = std::make_unique<SwStatsCpu>();
 	if (!stats->isValid()) {
@@ -145,6 +124,34 @@ SoftwareIsp::~SoftwareIsp()
 	debayer_.reset();
 }
 
+bool SoftwareIsp::allocateParamsBuffers()
+{
+	/*
+	 * DebayerParams must be initialized because the initial value is used for
+	 * the first two frames, i.e. until stats processing starts providing its
+	 * own parameters.
+	 *
+	 * \todo This should be handled in the same place as the related
+	 * operations, in the IPA module.
+	 */
+	std::array<uint8_t, 256> gammaTable;
+	for (unsigned int i = 0; i < 256; i++)
+		gammaTable[i] = UINT8_MAX * std::pow(i / 256.0, 0.5);
+	for (unsigned int j = 0; j < DebayerParams::kRGBLookupSize; j++) {
+		debayerParams_.red[j] = gammaTable[j];
+		debayerParams_.green[j] = gammaTable[j];
+		debayerParams_.blue[j] = gammaTable[j];
+	}
+
+	sharedParams_ = SharedMemObject<DebayerParams>("softIsp_params");
+	if (!sharedParams_) {
+		LOG(SoftwareIsp, Error) << "Failed to create shared memory for parameters";
+		return false;
+	}
+
+	return true;
+}
+
 /**
  * \fn int SoftwareIsp::loadConfiguration([[maybe_unused]] const std::string &filename)
  * \brief Load a configuration from a file
-- 
2.44.1



More information about the libcamera-devel mailing list