From patchwork Thu Oct 29 13:26:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28698 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 CE46EC3261 for ; Thu, 29 Oct 2026 13:27:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7FAA8690CB; Thu, 29 Oct 2026 14:27:19 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="msGHMP5C"; dkim-atps=neutral Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2856C690AD for ; Thu, 29 Oct 2026 14:27:17 +0100 (CET) Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-7cc2bb73cd9so611148137.3 for ; Thu, 29 Oct 2026 06:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793280436; x=1793885236; 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=wqVCNhP15UBhBTL2gpMDBx/KxYpGklVAZwaJOyunk3s=; b=msGHMP5CAVckOmqfDHu6LkVLlBi46SWU8KCw2erLKpjNR5Ntwtt0fLx9HdeIsTcwVy v1NC+pBMEAvk1MR8NH0R4QkEE/TMYZsLt3kshVZuzpiuBMAUNctLCH1b3sHEWyHy6WPc wUfsrJvQPAXMYnyWW9Ga3Tu4bwljivgnq/TLJQHZL1BfyggnhcyZ+/gHLUBDPDUP+0MT +eAamZdU1fL4STwCSQIF1+u6ayc/jGM529A/v3cbPjt9nd0gDmiY/JmqVBTuw2pyTC0x Y/kjIQNN1hsrAaEKdpzso1ACEZPhMd4ZanvU0ZNzomn3ih3Y5xIk3Nipxg5ez781Rdwt i+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793280436; x=1793885236; 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=wqVCNhP15UBhBTL2gpMDBx/KxYpGklVAZwaJOyunk3s=; b=NfiiyzdDGo6EGhBBdDUEzanlngka72UBCAEd9lzN5ULygHukhnZTDDupg0ygH8L9cS ZjlCl/usonNLlV7f0QsnLw6wFAushTP72shpaR2FkLTzdGW2xXIEJwFB9hzo/696vBB5 P8EaVN9Krv7bjKhWVMtiefuAJrycnWJjafhgOJNYAY5PSsUay7reAYo19jAeDsxvXrev B7lyLSfhqy7v4Mcu3uObAyqK07UTV148KWo0kUSdTP1VO8zh7o6D5yZdUfw61mgs1yQS ta7d6qgMDZzGklqroledPSL3v38H8M7VTPySVTi0dlMOy9nzwIDL8ujlHRmNaMWEcxNW xXvg== X-Gm-Message-State: AFq9FYLx9dqNUAExZxynyostnKxZq+3vpdFnPdkwlCTqZWsGCvHCnwYl KUHzZdJqdfepljNuRHNMdZXhYcLR7xIeC9IVvU3VYqbtqhde3U2EE5S1v8J4MsbK0V0= X-Gm-Gg: AYBFou1r66AO4+DSlRMmaKatZYVB1DCT4GD41iK3gXKvervycbYXywWZj76sA7lYFUR E3jeCjNa9BsATCymppHBIWJiQGhcwOUcApzgON8LudB5m9+li9pHGmA16zk/ahMOXe10hVniUR9 DWdgUmZ7F+xkHB16Fccg+88jADp0yb32nnacer9zFNOT4AtplXFssmka7xCobnW3eQCerSLuslA 5+TVuKdNsAy9IHIid8Gz+z01zr8sFXvbnBwy3ZriuUMgkoa3RAJ8khKyIOca8LZBibT30kBK30c NvHGPkEhXlrpjYFhlSxDTEv39esDHXdRiIF41HWLgFpqMQrFVeABLSxsd+QNzt/f9m2nika5Nu1 DMEDRdPgFje4B1AyqGx4OwvGxzLs3jH55XtQ7eksW9+PJZg2x7ovXpG9KsOa18pAWYICM20Saly JAXSysRc7RqXl833I2BAmYPK9w5DGh+Np3M4OKDd8fQv2Z+TXCyTx9RaJMMK3X0tzRtquMNjyfX cfCbBGFJEbwvv9AZO3Vj1c5iH0whvxKjg1z4eCLZudCdEg9L1kah6ypOhY2o1IWassUFHT7Svci RaWIN/yZQVmDpbGX+eGDH3xRQiSFciUoiU8lNPeJ7TXcp5THC0hXj7vGnhDgq4z8sxlfkYP2ZkY L3g== X-Received: by 2002:a05:6102:1499:b0:7b2:508e:3d57 with SMTP id ada2fe7eead31-7d03a289d03mr2359042137.4.1793280435831; Thu, 29 Oct 2026 06:27:15 -0700 (PDT) Received: from localhost ([144.121.52.163]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99125931983sm9476046241.2.2026.10.29.06.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 06:27:15 -0700 (PDT) From: Ray Strode To: libcamera-devel@lists.libcamera.org Cc: kieran.bingham@ideasonboard.com, bod.linux@nxsw.ie, laurent.pinchart@ideasonboard.com, stefan.klug@ideasonboard.com, martincarvalho@gmail.com Subject: [PATCH v4 6/9] software-isp: Map input crops to native sensor coordinates Date: Thu, 29 Oct 2026 09:26:28 -0400 Message-ID: <20261029132631.370507-7-halfline@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261029132631.370507-1-halfline@gmail.com> References: <20261016202818.1405645-1-halfline@gmail.com> <20261029132631.370507-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 physical pixel array coordinates in native sensor pixels, so sensor binning, analog crop offsets and sensor transforms must be accounted for. The conversion reverses the sensor transform and maps the input rectangle into the analog crop. Integer coordinates and dimensions follow the truncation used by the existing rectangle transformation. Signed-off-by: Ray Strode --- .../internal/software_isp/debayer_geometry.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/libcamera/internal/software_isp/debayer_geometry.h b/include/libcamera/internal/software_isp/debayer_geometry.h index 8812a3cf..bf6c6771 100644 --- a/include/libcamera/internal/software_isp/debayer_geometry.h +++ b/include/libcamera/internal/software_isp/debayer_geometry.h @@ -1,23 +1,48 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2026, Red Hat Inc. * * Geometry for scaling and cropping debayered images */ #pragma once +#include #include +#include namespace libcamera { /* Return the visible sensor rectangle, before statistics Bayer alignment. */ inline Rectangle debayerCrop(const Size &inputSize, const Size &nativeSize, const Size &outputSize) { const Size visibleSize = nativeSize.boundedToAspectRatio(outputSize); return visibleSize.centeredTo(Rectangle(inputSize).center()); } +/* + * Map an image crop to physical pixel-array coordinates in native sensor pixels. + * The input must cover the whole analog crop. Undo the sensor transform + * before accounting for binning and the analog crop offset. Integer + * coordinates and dimensions are truncated as in transformedBetween(). + */ +inline Rectangle debayerCropToSensor(Rectangle crop, Size inputSize, + const Rectangle &analogCrop, + 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); +} + } /* namespace libcamera */