[v3,04/11] tests: Validate the visible sensor crop
diff mbox series

Message ID 20261016202818.1405645-5-halfline@gmail.com
State New
Headers show
Series
  • software-isp: Align crops, statistics and metadata
Related show

Commit Message

Ray Strode Oct. 16, 2026, 8:28 p.m. UTC
From: Ray Strode <rstrode@redhat.com>

The GPU debayer path selects its statistics window from the visible sensor
crop. The geometry unit test checks the projection used for rendering.

The project lacks a direct check that the sensor crop remains centered and
follows the output aspect ratio without shrinking to the output resolution.

This commit extends the geometry unit test with expected sensor rectangles
for native, downscaled, wider, narrower, and portrait outputs. It also
checks integer rounding that leaves an odd top coordinate before Bayer
alignment.

Signed-off-by: Ray Strode <rstrode@redhat.com>
---
 test/debayer-geometry.cpp | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/test/debayer-geometry.cpp b/test/debayer-geometry.cpp
index 27458aa1..86d4248f 100644
--- a/test/debayer-geometry.cpp
+++ b/test/debayer-geometry.cpp
@@ -2,7 +2,7 @@ 
 /*
  * Copyright (C) 2026, Red Hat Inc.
  *
- * Debayer projection tests
+ * Debayer projection and sensor crop tests
  */
 
 #include <array>
@@ -23,7 +23,7 @@  class DebayerGeometryTest : public Test
 protected:
 	int run() override
 	{
-		if (testProjection())
+		if (testProjection() || testCrop())
 			return TestFail;
 
 		return TestPass;
@@ -91,6 +91,38 @@  private:
 
 		return TestPass;
 	}
+
+	int testCrop()
+	{
+		static const struct {
+			Size input;
+			Size native;
+			Size output;
+			Rectangle expected;
+		} cases[] = {
+			{ { 1920, 1080 }, { 1920, 1080 }, { 1920, 1080 }, { 0, 0, 1920, 1080 } },
+			{ { 1928, 1092 }, { 1920, 1092 }, { 1920, 1092 }, { 4, 0, 1920, 1092 } },
+			/* Output resolution changes must not shrink the sensor window. */
+			{ { 1928, 1092 }, { 1920, 1092 }, { 1920, 1080 }, { 4, 6, 1920, 1080 } },
+			{ { 1928, 1092 }, { 1920, 1092 }, { 1280, 720 }, { 4, 6, 1920, 1080 } },
+			{ { 1928, 1092 }, { 1920, 1092 }, { 640, 480 }, { 236, 0, 1456, 1092 } },
+			{ { 1928, 1092 }, { 1920, 1092 }, { 512, 768 }, { 600, 0, 728, 1092 } },
+			{ { 1928, 1092 }, { 1920, 1092 }, { 1280, 640 }, { 4, 66, 1920, 960 } },
+			/* A smaller Bayer border leaves an odd top coordinate. */
+			{ { 1928, 1092 }, { 1924, 1092 }, { 1280, 720 }, { 2, 5, 1924, 1082 } },
+		};
+
+		for (const auto &entry : cases) {
+			Rectangle crop = debayerCrop(entry.input, entry.native, entry.output);
+			if (crop != entry.expected) {
+				std::cerr << "Crop " << entry.input << " -> " << entry.output
+					  << " is " << crop << ", expected " << entry.expected << std::endl;
+				return TestFail;
+			}
+		}
+
+		return TestPass;
+	}
 };
 
 TEST_REGISTER(DebayerGeometryTest)