{"id":22208,"url":"https://patchwork.libcamera.org/api/1.1/patches/22208/?format=json","web_url":"https://patchwork.libcamera.org/patch/22208/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241206101344.767170-17-stefan.klug@ideasonboard.com>","date":"2024-12-06T10:13:38","name":"[v3,16/17] libcamera: camera_sensor: Add parameter to limit returned sensor size","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"8fb52286100ecf0c67a0ca06de62553327af7200","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/users/17/?format=json","username":"epaul","first_name":"Paul","last_name":"Elder","email":"paul.elder@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/22208/mbox/","series":[{"id":4854,"url":"https://patchwork.libcamera.org/api/1.1/series/4854/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4854","date":"2024-12-06T10:13:22","name":"rkisp1: Fix aspect ratio and ScalerCrop","version":3,"mbox":"https://patchwork.libcamera.org/series/4854/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22208/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22208/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2710CBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Dec 2024 10:14:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C7C8666160;\n\tFri,  6 Dec 2024 11:14:35 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D1E26614E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Dec 2024 11:14:33 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:3543:aebe:e043:ef86])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1C8C1FEF;\n\tFri,  6 Dec 2024 11:14:04 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"eE6FyvHr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1733480044;\n\tbh=vGNNqTgfLWPEDfm0GWkfBDh0tk2UWublFjvscvtM8T4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=eE6FyvHrjJhR+CpO5QCwyvff3FdnXJ1U70+Tu3QWteCEwXV7GkivMSgHPRtzDyW/C\n\tttGtjNM/VcbbIYT4J0RLWhVItIojsYvepM7i+IyeGG1gN6wAkNAjTaQG+JF2++xlSy\n\t0aQaWznDoHwTOgn3/qPPLZCQcYleHdKZ7YQcqYwo=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"[PATCH v3 16/17] libcamera: camera_sensor: Add parameter to limit\n\treturned sensor size","Date":"Fri,  6 Dec 2024 11:13:38 +0100","Message-ID":"<20241206101344.767170-17-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>","References":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The getFormat function takes the aspect ratio and the area of the\nrequested size into account when choosing the best sensor size. In case\nthe sensor is connected to an rkisp1 the maximum supported frame size of\nthe ISP is another constraining factor for the selection of the best\nformat. Add a maxSize parameter to support such a constraint.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\nChanges in v3:\n- Added this patch\n---\n include/libcamera/internal/camera_sensor.h    | 2 +-\n src/libcamera/sensor/camera_sensor.cpp        | 3 +++\n src/libcamera/sensor/camera_sensor_legacy.cpp | 9 +++++++--\n 3 files changed, 11 insertions(+), 3 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex d030e254a552..605ea8136900 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -53,7 +53,7 @@ public:\n \n \tvirtual V4L2SubdeviceFormat\n \tgetFormat(const std::vector<unsigned int> &mbusCodes,\n-\t\t  const Size &size) const = 0;\n+\t\t  const Size &size, const Size maxSize = Size()) const = 0;\n \tvirtual int setFormat(V4L2SubdeviceFormat *format,\n \t\t\t      Transform transform = Transform::Identity) = 0;\n \tvirtual int tryFormat(V4L2SubdeviceFormat *format) const = 0;\ndiff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp\nindex 208a1603cb32..a131ac224ec0 100644\n--- a/src/libcamera/sensor/camera_sensor.cpp\n+++ b/src/libcamera/sensor/camera_sensor.cpp\n@@ -116,6 +116,7 @@ CameraSensor::~CameraSensor() = default;\n  * \\brief Retrieve the best sensor format for a desired output\n  * \\param[in] mbusCodes The list of acceptable media bus codes\n  * \\param[in] size The desired size\n+ * \\param[in] maxSize The maximum size\n  *\n  * Media bus codes are selected from \\a mbusCodes, which lists all acceptable\n  * codes in decreasing order of preference. Media bus codes supported by the\n@@ -134,6 +135,8 @@ CameraSensor::~CameraSensor() = default;\n  *   bandwidth.\n  * - The desired \\a size shall be supported by one of the media bus code listed\n  *   in \\a mbusCodes.\n+ * - The desired \\a size shall fit into the maximum size \\a maxSize if it is not\n+ *   null.\n  *\n  * When multiple media bus codes can produce the same size, the code at the\n  * lowest position in \\a mbusCodes is selected.\ndiff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp\nindex 17d6fa680e39..32989c19c019 100644\n--- a/src/libcamera/sensor/camera_sensor_legacy.cpp\n+++ b/src/libcamera/sensor/camera_sensor_legacy.cpp\n@@ -74,7 +74,8 @@ public:\n \tSize resolution() const override;\n \n \tV4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,\n-\t\t\t\t      const Size &size) const override;\n+\t\t\t\t      const Size &size,\n+\t\t\t\t      const Size maxSize) const override;\n \tint setFormat(V4L2SubdeviceFormat *format,\n \t\t      Transform transform = Transform::Identity) override;\n \tint tryFormat(V4L2SubdeviceFormat *format) const override;\n@@ -699,7 +700,7 @@ Size CameraSensorLegacy::resolution() const\n \n V4L2SubdeviceFormat\n CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,\n-\t\t\t      const Size &size) const\n+\t\t\t      const Size &size, Size maxSize) const\n {\n \tunsigned int desiredArea = size.width * size.height;\n \tunsigned int bestArea = UINT_MAX;\n@@ -716,6 +717,10 @@ CameraSensorLegacy::getFormat(const std::vector<unsigned int> &mbusCodes,\n \t\tfor (const SizeRange &range : formats->second) {\n \t\t\tconst Size &sz = range.max;\n \n+\t\t\tif (!maxSize.isNull() &&\n+\t\t\t    (sz.width > maxSize.width || sz.height > maxSize.height))\n+\t\t\t\tcontinue;\n+\n \t\t\tif (sz.width < size.width || sz.height < size.height)\n \t\t\t\tcontinue;\n \n","prefixes":["v3","16/17"]}