From patchwork Fri Oct 16 20:28:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28479 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 48A03C3307 for ; Fri, 16 Oct 2026 20:28:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFEFA68E53; Fri, 16 Oct 2026 22:28:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nU5dzNAV"; 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 2A21068E4B for ; Fri, 16 Oct 2026 22:28:37 +0200 (CEST) Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-5ea93a316aaso164352e0c.0 for ; Fri, 16 Oct 2026 13:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792182516; x=1792787316; 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=tjB8EtehsH4sXU3Tzol5ve5WZoGk4eiS1O7HWeLNpIk=; b=nU5dzNAVnt6hEB2+Cpi7hcTJ/UTNwFeaX3QmY9lfyhF9P1d58BLSKRxntBkiSLeQjy zuPh1L4AJAEefxwZdmYCod23Dcq5UJb7UyXOim+BN+8g5s7ViRK4O7S8sVySdZV+3Kl7 32JwBtHIvqE9CJdxJlJycrSDUw/v3RYF25L5zCq/lWIf9F2eRXNU/U0pLvd1C3Er4WIc jnNJz4PkMsE/TSLMtjJ4v0CkJyH1xiF2Mu8/Erjl9PpzYcu+OFxw7uCOI4hcw2qg/v5h g0mku6tRo5PshlfL2f4/fJmCETCNkmPgBrk2JOR1l7sGfBCrp47nTmIQQOC6tGO8EB2z Au2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792182516; x=1792787316; 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=tjB8EtehsH4sXU3Tzol5ve5WZoGk4eiS1O7HWeLNpIk=; b=SW+0TRP3/FFgUf+V/VRG/msZbpIH53Le3slOcMjNaUsCQjOm095gSglt4+rJWK1hPI d0ZdsSitgw7sub8wgYX3ZHRbRStK82XHKjdczAjtLDjP5ZB3but4a5cQ32/3iNnKAja2 KTCSJFLoRfPELYe8aPibr+wJq4b54puCnOxkr0iRxvNggE/GDa+5UX1JUIwa9gdyr1KH b6VG+7+r6IPEnmOaRRjPw2y/KJsYEM9A9mOd0xONdyWdFA0M7YscUc1CAmCXTWJW7RNp zifMaybygirTZi4VRhCcUThwE/ac4Xw7wtX9ae7fjfjtNo+sBuSlyu5f/6ecIT0U5MNY 3C1Q== X-Gm-Message-State: AFq9FYJuOy/XKEHjrT1Or6oLsvYqPVjMaXvzsIKZLjMlAuYjiGuqR1YJ IZnrB7YV/OQZkqZEX/OZIQNQLpdP2OD7rBsAQ0ikgrx/dZ91I2TPjLbrtcglmbOWcdc= X-Gm-Gg: AYBFou1rwLlzhOEOoGO/XnasDmvbxEn5EgrNrMnupDtNU/nAslcIzPXQkahys1t1Yrj gXYm7Jl15bo2NSh2agqeUDEoCjKHAYGw4QB+6uNTbb6PQ6GJUduyCcKEFTsKtJL2PCIEl7cHLnu nYxsQKaKBKozof7WUvc3RKkjlrXAhxHVulvpPBL4l/9ejUYmRzdI/Gz4ZfQ3uxlj+kPFbwSucNM QRiWaIOSeoNNC9+VD7sOO1J3rc/XSz6rGRG8GvSFSyAeG4n1WxJSseQueNgq0gOUL6ih+Awfb8O oC6D5jZaYgs/cZGzfZ8v6gq01FLjSn5rXmPihITJZTi7EgbDcyz/5H0v7QpGduO0CDkW3dyCHNM GWEtFSIVF2cdINSAf/E7ybAcpp+qAvIrUr/YCnz0nYH9H3en3YWkkEOkmUQL0Iq+pcjTs14YKch ZH+2zlPQ737lhy5EDPMk4tNBQSibQmPXozG8S3YkLRgV+wuLaEAHTaxUGqSJ3ZynelkZaw3Ws/s iP3+rtN0ddG8u6UtB4IK9NSJPeZZjscLrKM+I8= X-Received: by 2002:a05:6122:1984:b0:5c9:c60e:3a40 with SMTP id 71dfb90a1353d-5eaaa678586mr546977e0c.18.1792182515963; Fri, 16 Oct 2026 13:28:35 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2026 13:28:35 -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 07/11] software-isp: Map input crops to native sensor coordinates Date: Fri, 16 Oct 2026 16:28:14 -0400 Message-ID: <20261016202818.1405645-8-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 adds the coordinate conversion needed to report a debayer crop as ScalerCrop metadata. Debayer crops use captured-buffer pixels. ScalerCrop uses native sensor pixels relative to the active array, so sensor binning, analogue crop offsets and sensor transforms must be accounted for. The conversion reverses the sensor transform, maps the input rectangle into the analogue crop and subtracts the active-array origin. Integer coordinates and dimensions follow the truncation used by the existing rectangle transformation. Signed-off-by: Ray Strode --- .../internal/software_isp/debayer_geometry.h | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/libcamera/internal/software_isp/debayer_geometry.h b/include/libcamera/internal/software_isp/debayer_geometry.h index 46721753..8409fd09 100644 --- a/include/libcamera/internal/software_isp/debayer_geometry.h +++ b/include/libcamera/internal/software_isp/debayer_geometry.h @@ -9,8 +9,10 @@ #include #include +#include #include +#include namespace libcamera { @@ -48,4 +50,29 @@ inline Rectangle debayerCrop(const Size &inputSize, const Size &nativeSize, return visibleSize.centeredTo(Rectangle(inputSize).center()); } +/* + * Map an image crop to native sensor pixels relative to the active array. + * The input must cover the whole analogue crop. Undo the sensor transform + * before accounting for binning and the analogue crop offset. Integer + * coordinates and dimensions are truncated as in transformedBetween(). + */ +inline Rectangle debayerCropToSensor(Rectangle crop, Size inputSize, + const Rectangle &analogCrop, + const Rectangle &activeArea, + Transform transform) +{ + if (!!(transform & Transform::Transpose)) { + std::swap(crop.x, crop.y); + std::swap(crop.width, crop.height); + std::swap(inputSize.width, inputSize.height); + } + if (!!(transform & Transform::HFlip)) + crop.x = inputSize.width - crop.x - crop.width; + if (!!(transform & Transform::VFlip)) + crop.y = inputSize.height - crop.y - crop.height; + + return crop.transformedBetween(Rectangle(inputSize), analogCrop) + .translatedBy(-activeArea.topLeft()); +} + } /* namespace libcamera */