[{"id":32703,"web_url":"https://patchwork.libcamera.org/comment/32703/","msgid":"<Z1rTqWx-5m8QXZEQ@pyrite.rasen.tech>","date":"2024-12-12T12:14:33","subject":"Re: [PATCH v3 16/17] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Fri, Dec 06, 2024 at 11:13:38AM +0100, Stefan Klug wrote:\n> The getFormat function takes the aspect ratio and the area of the\n> requested size into account when choosing the best sensor size. In case\n> the sensor is connected to an rkisp1 the maximum supported frame size of\n> the ISP is another constraining factor for the selection of the best\n> format. Add a maxSize parameter to support such a constraint.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n> Changes 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(-)\n> \n> diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\n> index 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;\n> diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp\n> index 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.\n> diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp\n> index 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> -- \n> 2.43.0\n>","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 05226BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Dec 2024 12:14:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B10EA67ED8;\n\tThu, 12 Dec 2024 13:14:41 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D6F2467EC7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Dec 2024 13:14:39 +0100 (CET)","from pyrite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:39eb:989c:b016:217b])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B715316;\n\tThu, 12 Dec 2024 13: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=\"uXxAyO+K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734005646;\n\tbh=KYS2rOWE0kTDZvXjiI8PHbGw9PTil1zJXTFSjmFKQU0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=uXxAyO+KJzN8OL7ix2BAST8WpiWt0HFZqpvM5RS0g/g9j3zPZHv8PDTIJNmKXoZKz\n\tux9zzm2qqLxfdxUciNkq3sGOVan+ldbHcOom5+bahRAhU0HRiKp6If0BijmE+eq3qh\n\tE2i+YhRXQLyUB01qRaqLC/pMSowzSSONtC5tpq9M=","Date":"Thu, 12 Dec 2024 21:14:33 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"Re: [PATCH v3 16/17] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","Message-ID":"<Z1rTqWx-5m8QXZEQ@pyrite.rasen.tech>","References":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>\n\t<20241206101344.767170-17-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20241206101344.767170-17-stefan.klug@ideasonboard.com>","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>"}}]