[{"id":32784,"web_url":"https://patchwork.libcamera.org/comment/32784/","msgid":"<lxcxqh6xvqjcnvm67467fw6mojri3fviybv3lbydtu3hilcglq@ushg243an7wg>","date":"2024-12-16T18:37:30","subject":"Re: [PATCH v4 19/20] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Stefan\n\nOn Mon, Dec 16, 2024 at 04:40:59PM +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> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n>\n> ---\n>\n> Changes in v4:\n> - Collected tags\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 F1673C32F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 18:37:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5193767FA7;\n\tMon, 16 Dec 2024 19:37:35 +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 0E20F67F93\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 19:37:34 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D62182A;\n\tMon, 16 Dec 2024 19:36:57 +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=\"DVK25fmu\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734374217;\n\tbh=EyxhBxbWoKOKdHGN9EKiCdmfpxX5g97fz7DD+drMd50=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DVK25fmuvIOmWWncpUoYVSY2ow9+U/QMT0UyAXOP7NvKukUwyMez9iv1qlRm3d3VB\n\tD77Wh1kkk1oE3mO7Eh5XC76fNSL+kuxvXcbGm2B/1ZPGkXNGouv+enLmB75VqNhDWc\n\tCG2mYYKD8kMNkPH1MP99tmzpXEuz0sOiWA0GipJI=","Date":"Mon, 16 Dec 2024 19:37:30 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v4 19/20] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","Message-ID":"<lxcxqh6xvqjcnvm67467fw6mojri3fviybv3lbydtu3hilcglq@ushg243an7wg>","References":"<20241216154124.203650-1-stefan.klug@ideasonboard.com>\n\t<20241216154124.203650-20-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241216154124.203650-20-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>"}},{"id":32853,"web_url":"https://patchwork.libcamera.org/comment/32853/","msgid":"<20241217210531.GH23470@pendragon.ideasonboard.com>","date":"2024-12-17T21:05:31","subject":"Re: [PATCH v4 19/20] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Dec 16, 2024 at 04:40:59PM +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> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> \n> Changes in v4:\n> - Collected tags\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\nThis feels like a bit of a hack. That's fine for now, the CameraSensor\nAPI is made of hacks. We'll clean it up later.\n\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>","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 DEE28C3301\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 17 Dec 2024 21:05:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 00AFA68000;\n\tTue, 17 Dec 2024 22:05:36 +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 6145C67FD3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 17 Dec 2024 22:05:34 +0100 (CET)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 837C63E;\n\tTue, 17 Dec 2024 22:04:56 +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=\"O5jwU2cm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734469496;\n\tbh=YLkpyUspc8ccK50lvyMl+58x/DpNlzq4H8AHmC2vZ8o=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=O5jwU2cmoazQe1f10/4XgV8T3CKdv50kCpDGe9n6KNoVIaxxG8e3k28cEwtc1ggY/\n\t7IKP7QMZkNA/DDPnlqtSeRYD5ZtXJTkPglc18DQWk/HrL3t9p2sSHaC7mJsxEga8Dz\n\tcWVZflY40Xo4FIHOtJBAlDazsbB9A+TQUyPJ1YWY=","Date":"Tue, 17 Dec 2024 23:05:31 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v4 19/20] libcamera: camera_sensor: Add parameter to\n\tlimit returned sensor size","Message-ID":"<20241217210531.GH23470@pendragon.ideasonboard.com>","References":"<20241216154124.203650-1-stefan.klug@ideasonboard.com>\n\t<20241216154124.203650-20-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241216154124.203650-20-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>"}}]