File 0001-libcamera-software_isp-Clarify-SwStatsCpu-setWindow-.patch of Package libcamera

From b5a01e2c62347f6815569cb16ce9ccbb85d6cb19 Mon Sep 17 00:00:00 2001
From: Milan Zamazal <mzamazal@redhat.com>
Date: Thu, 21 Aug 2025 15:41:37 +0200
Subject: [PATCH 01/17] libcamera: software_isp: Clarify SwStatsCpu::setWindow
 use

The window coordinates passed to SwStatsCpu::setWindow are confusing.
Let's clarify what the coordinates should be.

A source of confusion is that the specified window is relative to the
processed area.  Debayering adjusts line pointers for its processed area
and this is what's also passed to stats processing.  The window passed
to SwStatsCpu::setWindow should either specify the size of the whole
processed (not image) area, or its cropping in case the stats shouldn't
be gathered over the whole processed area.  This patch should clarify
this in the code.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/libcamera/software_isp/debayer_cpu.cpp |  6 +++++-
 src/libcamera/software_isp/swstats_cpu.cpp | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
index 66f6038c1..bcc847ae6 100644
--- a/src/libcamera/software_isp/debayer_cpu.cpp
+++ b/src/libcamera/software_isp/debayer_cpu.cpp
@@ -541,7 +541,11 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,
 	window_.width = outputCfg.size.width;
 	window_.height = outputCfg.size.height;
 
-	/* Don't pass x,y since process() already adjusts src before passing it */
+	/*
+	 * Set the stats window to the whole processed window. Its coordinates are
+	 * relative to the debayered area since debayering passes only the part of
+	 * data to be processed to the stats; see SwStatsCpu::setWindow.
+	 */
 	stats_->setWindow(Rectangle(window_.size()));
 
 	/* pad with patternSize.Width on both left and right side */
diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp
index 4b77b3600..72aa88b69 100644
--- a/src/libcamera/software_isp/swstats_cpu.cpp
+++ b/src/libcamera/software_isp/swstats_cpu.cpp
@@ -416,6 +416,22 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)
 /**
  * \brief Specify window coordinates over which to gather statistics
  * \param[in] window The window object.
+ *
+ * This method specifies the image area over which to gather the statistics.
+ * It must be called to set the area, otherwise the default zero-sized
+ * \a Rectangle is used and no statistics is gathered.
+ *
+ * The specified \a window is relative to what is passed to processLine*
+ * methods. Typically, this means processLine* methods get only data from the
+ * processed area and \a window is \a Rectangle with (0, 0) top-left point and
+ * of the same size as the processed area. But if statistics is gathered only
+ * from some part of the image, e.g. its centre, \a window should specify such a
+ * restriction accordingly.
+ *
+ * The method may adjust the window slightly if it is not aligned according to
+ * the bayer pattern determined in \a SwStatsCpu::configure(). Such an
+ * adjustment is guaranteed to not exceed the bounds of
+ * Rectangle(0, 0, window.width, window.height).
  */
 void SwStatsCpu::setWindow(const Rectangle &window)
 {
-- 
2.50.1

openSUSE Build Service is sponsored by