From patchwork Mon Dec 16 15:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22365 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 ED60CC32F6 for ; Mon, 16 Dec 2024 15:42:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65ED267FA1; Mon, 16 Dec 2024 16:42:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RVbnb6PC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E9BA567F9A for ; Mon, 16 Dec 2024 16:42:38 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:bfdf:3a3c:e45:66e3]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 33DF182A; Mon, 16 Dec 2024 16:42:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1734363722; bh=4D69et1CbHfB2HVgM+731TlbSbrVJ4XG7A6AK7c5V+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RVbnb6PCwj0Ne9zJCeOHFjkHFAvJTZ9KEhoAxir81MpMbKzEqmOKIJ7e+qcBwCZdj zfBns7VRaz0Ue8/Lb1hlLfgrJQifMj1L6eD7L/rbdMIaAS3IUzXDOhCeICOjMcMA9n al0PTfVil+xsGBTYKEeL86MnhhkP2qWuajY0Ba1E= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Jacopo Mondi , Paul Elder Subject: [PATCH v4 19/20] libcamera: camera_sensor: Add parameter to limit returned sensor size Date: Mon, 16 Dec 2024 16:40:59 +0100 Message-ID: <20241216154124.203650-20-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216154124.203650-1-stefan.klug@ideasonboard.com> References: <20241216154124.203650-1-stefan.klug@ideasonboard.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" The getFormat function takes the aspect ratio and the area of the requested size into account when choosing the best sensor size. In case the sensor is connected to an rkisp1 the maximum supported frame size of the ISP is another constraining factor for the selection of the best format. Add a maxSize parameter to support such a constraint. Signed-off-by: Stefan Klug Signed-off-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Jacopo Mondi --- Changes in v4: - Collected tags Changes in v3: - Added this patch --- include/libcamera/internal/camera_sensor.h | 2 +- src/libcamera/sensor/camera_sensor.cpp | 3 +++ src/libcamera/sensor/camera_sensor_legacy.cpp | 9 +++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d030e254a552..605ea8136900 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -53,7 +53,7 @@ public: virtual V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, - const Size &size) const = 0; + const Size &size, const Size maxSize = Size()) const = 0; virtual int setFormat(V4L2SubdeviceFormat *format, Transform transform = Transform::Identity) = 0; virtual int tryFormat(V4L2SubdeviceFormat *format) const = 0; diff --git a/src/libcamera/sensor/camera_sensor.cpp b/src/libcamera/sensor/camera_sensor.cpp index 208a1603cb32..a131ac224ec0 100644 --- a/src/libcamera/sensor/camera_sensor.cpp +++ b/src/libcamera/sensor/camera_sensor.cpp @@ -116,6 +116,7 @@ CameraSensor::~CameraSensor() = default; * \brief Retrieve the best sensor format for a desired output * \param[in] mbusCodes The list of acceptable media bus codes * \param[in] size The desired size + * \param[in] maxSize The maximum size * * Media bus codes are selected from \a mbusCodes, which lists all acceptable * codes in decreasing order of preference. Media bus codes supported by the @@ -134,6 +135,8 @@ CameraSensor::~CameraSensor() = default; * bandwidth. * - The desired \a size shall be supported by one of the media bus code listed * in \a mbusCodes. + * - The desired \a size shall fit into the maximum size \a maxSize if it is not + * null. * * When multiple media bus codes can produce the same size, the code at the * lowest position in \a mbusCodes is selected. diff --git a/src/libcamera/sensor/camera_sensor_legacy.cpp b/src/libcamera/sensor/camera_sensor_legacy.cpp index 17d6fa680e39..32989c19c019 100644 --- a/src/libcamera/sensor/camera_sensor_legacy.cpp +++ b/src/libcamera/sensor/camera_sensor_legacy.cpp @@ -74,7 +74,8 @@ public: Size resolution() const override; V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, - const Size &size) const override; + const Size &size, + const Size maxSize) const override; int setFormat(V4L2SubdeviceFormat *format, Transform transform = Transform::Identity) override; int tryFormat(V4L2SubdeviceFormat *format) const override; @@ -699,7 +700,7 @@ Size CameraSensorLegacy::resolution() const V4L2SubdeviceFormat CameraSensorLegacy::getFormat(const std::vector &mbusCodes, - const Size &size) const + const Size &size, Size maxSize) const { unsigned int desiredArea = size.width * size.height; unsigned int bestArea = UINT_MAX; @@ -716,6 +717,10 @@ CameraSensorLegacy::getFormat(const std::vector &mbusCodes, for (const SizeRange &range : formats->second) { const Size &sz = range.max; + if (!maxSize.isNull() && + (sz.width > maxSize.width || sz.height > maxSize.height)) + continue; + if (sz.width < size.width || sz.height < size.height) continue;