From patchwork Thu Mar 4 13:17:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11496 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 2A426BD1F1 for ; Thu, 4 Mar 2021 13:16:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8F05568A91; Thu, 4 Mar 2021 14:16:45 +0100 (CET) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD30D602ED for ; Thu, 4 Mar 2021 14:16:43 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 5EF7EE000D; Thu, 4 Mar 2021 13:16:43 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 4 Mar 2021 14:17:09 +0100 Message-Id: <20210304131709.981268-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: camera_sensor: Cap resolution to max frame size 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" Since commit 96aecfe36508 ("libcamera: camera_sensor: Use active area size as resolution") the CameraSensor::resolution() method returned the sensor's active pixel area size. As the CameraSensor::resolution() method is widely used in the library code base to retrieve the maximum frame size the sensor can produce, in case it is smaller than the pixel area size the returned size cannot be used to configure the sensor correctly. Fix this by returning the maximum frame resolution the sensor can produce, or the pixel area size in case the sensor embeds and ISP that can upscale and the supported maximum frame size is thus larger that the pixel array size. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Tested-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 2 +- src/libcamera/camera_sensor.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.30.0 diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 71d012f795fe..3e98f71b5e7f 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -53,7 +53,7 @@ public: const MediaEntity *entity() const { return entity_; } const std::vector &mbusCodes() const { return mbusCodes_; } const std::vector &sizes() const { return sizes_; } - Size resolution() const { return activeArea_.size(); } + Size resolution() const; V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a04982971616..edc2c27084ed 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -551,10 +551,22 @@ int CameraSensor::initProperties() */ /** - * \fn CameraSensor::resolution() * \brief Retrieve the camera sensor resolution + * + * The camera sensor resolution is the largest frame size the sensor can produce + * or, if the camera sensor embeds and ISP that can up-scale, the pixel area + * size. + * + * \todo Consider if it desirable to distinguish between the maximum resolution + * the sensor can produce (also including upscaled ones) and the actual pixel + * array size by splitting this method in two. + * * \return The camera sensor resolution in pixels */ +Size CameraSensor::resolution() const +{ + return std::min(sizes_.back(), activeArea_.size()); +} /** * \brief Retrieve the best sensor format for a desired output