diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
index e1d3c164..5e168554 100644
--- a/src/libcamera/software_isp/debayer_cpu.cpp
+++ b/src/libcamera/software_isp/debayer_cpu.cpp
@@ -437,6 +437,11 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat,
 		return invalidFmt();
 	}
 
+	if (inputConfig_.patternSize.height == 2)
+		processInner_ = &DebayerCpu::process2;
+	else
+		processInner_ = &DebayerCpu::process4;
+
 	if ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10 || bayerFormat.bitDepth == 12) &&
 	    bayerFormat.packing == BayerFormat::Packing::None &&
 	    isStandardBayerOrder(bayerFormat.order)) {
@@ -890,10 +895,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output
 
 	threadData_[0].yStart = 0;
 	threadData_[0].yEnd = window_.height;
-	if (inputConfig_.patternSize.height == 2)
-		process2(frame, in.planes()[0].data(), out.planes()[0].data(), &threadData_[0]);
-	else
-		process4(frame, in.planes()[0].data(), out.planes()[0].data(), &threadData_[0]);
+	(this->*processInner_)(frame, in.planes()[0].data(), out.planes()[0].data(), &threadData_[0]);
 
 	metadata.planes()[0].bytesused = out.planes()[0].size();
 
diff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h
index a54418dc..b85dd11c 100644
--- a/src/libcamera/software_isp/debayer_cpu.h
+++ b/src/libcamera/software_isp/debayer_cpu.h
@@ -87,6 +87,9 @@ private:
 		bool processLastLinesSeperately;
 	};
 
+	using processFn = void (DebayerCpu::*)(uint32_t frame, const uint8_t *src, uint8_t *dst,
+					       DebayerCpuThreadData *threadData);
+
 	/* 8-bit raw bayer format */
 	template<bool addAlphaByte, bool ccmEnabled>
 	void debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
@@ -164,6 +167,7 @@ private:
 	unsigned int threadCount_;
 	bool ccmEnabled_;
 	DebayerParams params_;
+	processFn processInner_;
 };
 
 } /* namespace libcamera */
