From patchwork Fri Oct 16 20:28:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28480 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1206CC324C for ; Fri, 16 Oct 2026 20:28:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B518268E57; Fri, 16 Oct 2026 22:28:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JF0qtYwk"; dkim-atps=neutral Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4752F68E49 for ; Fri, 16 Oct 2026 22:28:38 +0200 (CEST) Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-5e6b5794d26so407536e0c.1 for ; Fri, 16 Oct 2026 13:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792182517; x=1792787317; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kPk9fP17Si+US2rvmZRJP8Lf8z4Pdwsurlzlm3vopzI=; b=JF0qtYwkAJ2mAeqmpG3u6JizeipklT0tHE1HSI3aVmIlQk8rSH1oPgOCCgVFHq8X8O IJsTUEaWg7/Ztlqh5ThTDikxZ24q/mrLwktFrnL7OJZjOyWDcHTWeSfkHzUusYpMwghC GE50CTbXluOMhG9QM58UEU4AuKgYuwm0hBT7Kpqqc5F83snzLERkD5vMW3MkrcsgsmT1 99F2swpoJrGOAtRuWPM2aNttM0DfDRxSlRbgjJQz2TIeqEdWh8EW6aGBFCIKZk+HwxW9 FScaoTpvl1o76PHmJD/Oc3Fjdrqa3sqz4LZHzA/VZ2ws4e25Uy46I/mQSIXxTKxYzymS rlmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792182517; x=1792787317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=kPk9fP17Si+US2rvmZRJP8Lf8z4Pdwsurlzlm3vopzI=; b=W9t+J/IOnn6CE8JYBWplMD5tYeXZf/l1CkbkoHuYoc1uy0qYtvaMnlAfBhiSgfVLto Y3UlZXwcs0tAkTsqTPhc66/cl8xj4ZQf5OzOZpM7ye1n0IBqDQZJseeblNnOiKlK+6vr sOhSsWwrrm3CDYDBr7Npyp+i86aq9bZsEr9Mi3G5LcddQ+KOBNZWPNY7gH8x63OT97/P CAl8bLqGJ1jwlDRd2k3p8N7luIQaPVpqaa7nqctrpU4Cu/NZB4rw+ATsp2u3cEu+fRLN 1V75n9k4EoiHMdtm+URWLzLb4yZ8Et8LexQpSlD964l3bmQEUpkoF52Al6ayvChIGVId 7q8Q== X-Gm-Message-State: AFq9FYK1IY0UyMl3lGdr1GorG+7+WpWD/TTBEE53gV27T8/FpPYMvjmN MZlwGZxDYxJW+mc2Mp96rTl0mMWMjfMLDcaoNwDV4Z/IELAWkd4sX7NdNlgqrDPLmLE= X-Gm-Gg: AYBFou3WKHKyOOfwB4NBmUHrS9MbWiYr3pd8Jat1CO9HSbJcjYxjWwfaikzDnzZ/w3z m2rrHF+02927o0vd6LptIyLLl16KHaPV97rYETXoDawM9etTX388pIdhgreKjnJOkNc7hhliu6O VJiqjGEU/m4rF8NEHmgljB/50qxrxrNlzczV38izdRmCUOPcS9xZl2FfgMOMNTC0kRqIzzBTF09 K5YAeQAA0Rr8N6AZ83cg9eFKUiu72e06KnR1uSwG7pc+/2pYSHeEnLRgkRQYPC03RbOx5yZlmL9 1vLL8/BF13mMb5puD/VRWsc7TxewkNKVEPwC2ztZzXHtR1gz+l4HItRefhLKwoRuDvDUCmykJRr gVImWtgBrAzqTk/RrDBFtQZ2xsQHcSK7vloWI09f1c0wqAOiYoeaezMwn/XwVOOkrZuLQDBc6uA N4QS+gv/zFOkAMk4C4kxYx9Xo/1KrkMjoPvFOrrANN5pcpw0G+yPghTl+Qg7sBVlh4F+BQRiKNh 3qJV6dUB8D3LcGm9ZVJtGscpVd4h+oWvNHnZHw= X-Received: by 2002:a05:6122:4014:b0:5ce:fc2e:d0e9 with SMTP id 71dfb90a1353d-5ea9801d848mr1232804e0c.13.1792182517009; Fri, 16 Oct 2026 13:28:37 -0700 (PDT) Received: from localhost ([2601:19c:4a00:897d:3391:ed89:5571:41a8]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ea9b2fef79sm2422500e0c.1.2026.10.16.13.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2026 13:28:36 -0700 (PDT) From: Ray Strode To: libcamera-devel@lists.libcamera.org Cc: kieran.bingham@ideasonboard.com, bod.linux@nxsw.ie, laurent.pinchart@ideasonboard.com Subject: [PATCH v3 08/11] tests: Validate native sensor crop coordinates Date: Fri, 16 Oct 2026 16:28:15 -0400 Message-ID: <20261016202818.1405645-9-halfline@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261016202818.1405645-1-halfline@gmail.com> References: <20261015223604.311616-1-halfline@gmail.com> <20261016202818.1405645-1-halfline@gmail.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Ray Strode This commit checks the conversion from debayer crop rectangles to native sensor coordinates in the existing geometry unit test. The test currently verifies projection and crop selection in input-buffer coordinates. It does not check the coordinate system needed by ScalerCrop metadata. The new cases cover GPU and CPU crop sizes, sensor offsets, binning, flips, transposition and fractional coordinates. An odd image boundary checks that the conversion preserves image geometry before Bayer statistics alignment. Signed-off-by: Ray Strode --- test/debayer-geometry.cpp | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/debayer-geometry.cpp b/test/debayer-geometry.cpp index 86d4248f..1d96fce1 100644 --- a/test/debayer-geometry.cpp +++ b/test/debayer-geometry.cpp @@ -23,7 +23,7 @@ class DebayerGeometryTest : public Test protected: int run() override { - if (testProjection() || testCrop()) + if (testProjection() || testCrop() || testSensorCrop()) return TestFail; return TestPass; @@ -123,6 +123,48 @@ private: return TestPass; } + + int testSensorCrop() + { + static const struct { + Rectangle crop; + Size input; + Rectangle analog; + Rectangle active; + Transform transform; + Rectangle expected; + } cases[] = { + /* GPU scaling keeps the full visible sensor region. */ + { { 4, 6, 1920, 1080 }, { 1928, 1092 }, { 0, 0, 1928, 1092 }, { 0, 0, 1928, 1092 }, Transform::Identity, { 4, 6, 1920, 1080 } }, + /* Sensor crop offsets and 2x binning use native pixels. */ + { { 4, 6, 1920, 1080 }, { 1928, 1092 }, { 100, 200, 3856, 2184 }, { 8, 8, 4000, 3000 }, Transform::Identity, { 100, 204, 3840, 2160 } }, + /* CPU debayering crops to output size without scaling. */ + { { 324, 186, 1280, 720 }, { 1928, 1092 }, { 100, 200, 3856, 2184 }, { 8, 8, 4000, 3000 }, Transform::Identity, { 740, 564, 2560, 1440 } }, + /* Preserve an odd image boundary before statistics alignment. */ + { { 2, 5, 1924, 1082 }, { 1928, 1092 }, { 0, 0, 3856, 2184 }, { 0, 0, 3856, 2184 }, Transform::Identity, { 4, 10, 3848, 2164 } }, + /* Undo sensor flips before reporting the native rectangle. */ + { { 2, 4, 20, 10 }, { 100, 60 }, { 10, 20, 200, 120 }, { 2, 4, 300, 200 }, Transform::HFlip, { 164, 24, 40, 20 } }, + { { 2, 4, 20, 10 }, { 100, 60 }, { 10, 20, 200, 120 }, { 2, 4, 300, 200 }, Transform::VFlip, { 12, 108, 40, 20 } }, + { { 2, 4, 20, 10 }, { 100, 60 }, { 10, 20, 200, 120 }, { 2, 4, 300, 200 }, Transform::HVFlip, { 164, 108, 40, 20 } }, + /* Transposition is undone before the flip. */ + { { 4, 2, 10, 20 }, { 60, 100 }, { 10, 20, 200, 120 }, { 2, 4, 300, 200 }, Transform::Rot270, { 164, 24, 40, 20 } }, + /* Fractional native coordinates and sizes truncate independently. */ + { { 1, 1, 3, 3 }, { 8, 8 }, { 10, 20, 12, 12 }, { 2, 4, 30, 40 }, Transform::Identity, { 9, 17, 4, 4 } }, + }; + + for (const auto &entry : cases) { + Rectangle crop = debayerCropToSensor(entry.crop, entry.input, + entry.analog, entry.active, + entry.transform); + if (crop != entry.expected) { + std::cerr << "Sensor mapping of " << entry.crop << " in " << entry.input + << " is " << crop << ", expected " << entry.expected << std::endl; + return TestFail; + } + } + + return TestPass; + } }; TEST_REGISTER(DebayerGeometryTest)