From 4ec1d75fdda93cdcfb1e5c0d50734e0e0a13d984 Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Mon, 29 Sep 2025 22:19:19 +0200 Subject: [PATCH] libcamera: software_isp: Clarify SwStatsCpu::setWindow use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Reviewed-by: Maciej S. Szmigiero Reviewed-by: Hans de Goede Signed-off-by: Milan Zamazal Reviewed-by: Barnabás Pőcze Tested-by: Hans de Goede Signed-off-by: Kieran Bingham --- src/libcamera/software_isp/debayer_cpu.cpp | 6 +++++- src/libcamera/software_isp/swstats_cpu.cpp | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp index d5fd0ae7..9af146e6 100644 --- a/src/libcamera/software_isp/debayer_cpu.cpp +++ b/src/libcamera/software_isp/debayer_cpu.cpp @@ -554,7 +554,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 43d8d79e..4f7bdd23 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -428,9 +428,33 @@ 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 the processLine* + * methods. For example, if statistics are to be gathered from the entire + * processed area, then \a window should be a rectangle with the top-left corner + * of (0,0) and the same size as the processed area. If only a part of the + * processed area (e.g. its centre) is to be considered for statistics, then + * \a window should specify such a restriction accordingly. + * + * It is the responsibility of the callers to provide sensible \a window values, + * most notably not exceeding the original image boundaries. This means, among + * other, that neither coordinate of the top-left corner shall be negative. + * + * Due to limitations of the implementation, the method may adjust the window + * slightly if it is not aligned according to the bayer pattern determined in + * \a SwStatsCpu::configure(). In that case the window will be modified such that + * the sides are no larger than the original, and that the new bottom-left + * corner will be no further from (0,0) (along either axis) than the original + * was. */ void SwStatsCpu::setWindow(const Rectangle &window) { + ASSERT(window.x >= 0 && window.y >= 0); + window_ = window; window_.x &= ~(patternSize_.width - 1);