From patchwork Thu Oct 29 15:20:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28711 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 5BBEFC324C for ; Thu, 29 Oct 2026 15:22:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 05A16690DF; Thu, 29 Oct 2026 16:22:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ISJWkngm"; dkim-atps=neutral Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9820A690A0 for ; Thu, 29 Oct 2026 16:22:01 +0100 (CET) Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-980c4258105so1210104241.2 for ; Thu, 29 Oct 2026 08:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793287320; x=1793892120; 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=ISJWkngmhhV/+xPdlw/bvT8PYFfTmTAXxN4+bdcgN8AAYcNF5K+T4+5h5jGKQQdX4n EUXainRLo+KODYaQvwPG+mjsnpiBOZ5mpkrKoPaOHdbReil4wnJxLU9YEXu8jkUkZBTL 2ENlsyPV7rgkCwk8liSjWzOc00qXe5dWxHyCHUZxoAisl/ZRBnedNebeM7Fzx89T596s xpuYtJojDMGVfQ6n3sqKklLoPXuFxzcddu5iExn+NSKeV+RMk9s66/ttaf6kwo9l2Lkr maYmv296B41VLwxQY7UnIMs2/Sz5hqmWa5IfJXroSkdCD2xB+Y1+K/6ZALgm82NSlPR8 bQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793287320; x=1793892120; 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=hzD6kEhtI59qxC19recqk3Zta8P98Nr8zgfCEAcgNi5tEUviQcVwCPUiuVW66ew/6+ ntqqLM0PWL1W+j21OMEYZ7OiqRjZbbnA5jakYGRf8XLMtIv6Mgnawc+n/atMsuXnpUAM c6DWqc+P16MCi7RBbjoCDyVeTJLFGe0lr0eMj9qRds4i62CMm9dcKKgIo8e+C11QN3sP dmkzxNbCgIQ4ad/j223Xk79lGT0rGeM8fyjbsi2FChxH6vu6JbfEtmdYZKgyojKXlTwX tdBHozj+Q+DXTls+gBWuVIavoxEDI/Q1Uxy0re4vI9eUPZfKQyyfuDoWzupA0y/tXbV8 wJmQ== X-Gm-Message-State: AFq9FYIhgqIB3jvuu2RGA2frRhYHDMew0OYDBLHvYF5C4dJdkKuAP4sH ShGerQHEZs7YebPvAAzp3gc3INdpI0AZsuIoXW44cdsdD1hKC9XUtIhV/oaWPj7VWdE= X-Gm-Gg: AYBFou36DIiIISV77PFCawzZOGRw4bpOAI/pavssyVaNm0qlsdZrdjjWJALCQ5l5jIr SlFY26mjrovR4/Vgv53jDjIHe0bw9j/pp4wNiDsCw3AYcIVSVJvReq6PxJ17LTw0kO9PgogF9fU tuKQUHwX0dcH1oXDt9GkPsgLG6si2pAcU1ibp+iNEAFrHld7gv7IJvyHA3cdROcMXVcvRgjt3ld lGnuLDBQW0OKLiNHzVu4oYQqBjm0cKJgJkU7DQ+ZWblf9CK7UC+98WPOqTqK3T/YGDQy1d39aRs s9XtBI7FF+jchU/tDfIsjGSAqE2v+0sJ9TXP2amFBEBH8+M1IoZPpqpRUUV7zQXoo8Q098e0OoZ 5WlEtxMW3dGjGYusUEJothZpOMOa0rPfuOhEwywLkVROoCFeW7YHU6vZ/+1DVhTBRvFsIUPhPb7 YOdil3q4HS/gRTJLN4F9cOjVZT/wTgt9lSgKfqutSQnH4RViZmtE+fMr0CwaCm498pbY0p96hMh fGfbN227jdCMalpqxpFkRGxLTvzah47wfBChsQkmbSfo26hyUK7pXaSVz4bE1VmX6R6zX2dnYRS kpLFXtzfLDJPgKJ5LzcdHL8Md+ReaGqwrEhSJSYPzpW7orFx+Xd2Qxju X-Received: by 2002:a05:6102:f9c:b0:7cb:fd69:4155 with SMTP id ada2fe7eead31-7d03a1f60afmr2933017137.5.1793287320490; Thu, 29 Oct 2026 08:22:00 -0700 (PDT) Received: from localhost ([144.121.52.163]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-991f74e5e22sm206563241.4.2026.10.29.08.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2026 08:22:00 -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 v5 08/11] software-isp: Map input crops to native sensor coordinates Date: Thu, 29 Oct 2026 11:20:55 -0400 Message-ID: <20261029152058.896209-9-halfline@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261029152058.896209-1-halfline@gmail.com> References: <20261029152058.896209-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 */