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.

Reviewed-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Reviewed-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Tested-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Milan Zamazal
2025-09-29 22:19:19 +02:00
committed by Kieran Bingham
parent e79cec02fb
commit 4ec1d75fdd
2 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -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 */
@@ -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);