From patchwork Tue Mar 2 19:49:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11468 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 4C656BD1F1 for ; Tue, 2 Mar 2021 19:50:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF61768A98; Tue, 2 Mar 2021 20:50:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Z21T0qFH"; 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 4A19260106 for ; Tue, 2 Mar 2021 20:50:21 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A1CC745D; Tue, 2 Mar 2021 20:50:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614714620; bh=LC/3XUM84SBeHWL+CsAv50A8K6JMvnEhZAxL07sBKNY=; h=From:To:Cc:Subject:Date:From; b=Z21T0qFHfiyXcNES35b9FeuwHRvVYt4Ba6ou7BfLS4L3MbDY/huaZM4NWN9Pz8MvI paJH0AoaUySdsbiwU+k35nNDa/KQNO0XF0MoRHyAz8YycTDnerZWb6Zpy7/11i5Axr nuytE8VSBpGujh7naxSF8tUCouCUvQN8saXJjv90= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Mar 2021 21:49:48 +0200 Message-Id: <20210302194948.20396-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: camera_sensor: Use active area size as resolution 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" When a sensor can upscale the image, the native sensor resolution isn't equal to the largest size reported by the sensor. Use the active area size instead, and default it to the largest enumerated size if the crop rectangle targets are not supported. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- Changes since v1: - Don't set default pixelArraySize_ to override it later Note how this causes the pixelArraySize_ = sizes_.back() assignment to be duplicated in CameraSensor::validateSensorDriver() and CameraSensor::initVimcDefaultProperties(). Jacopo, do you prefer v1 or v2 ? --- include/libcamera/internal/camera_sensor.h | 3 +-- src/libcamera/camera_sensor.cpp | 23 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index f22ffbfe9f97..71d012f795fe 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_; } - const Size &resolution() const { return resolution_; } + Size resolution() const { return activeArea_.size(); } V4L2SubdeviceFormat getFormat(const std::vector &mbusCodes, const Size &size) const; @@ -87,7 +87,6 @@ private: std::string id_; V4L2Subdevice::Formats formats_; - Size resolution_; std::vector mbusCodes_; std::vector sizes_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 8a1b9bd277df..8db6e8974a8d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -233,12 +233,6 @@ int CameraSensor::init() auto last = std::unique(sizes_.begin(), sizes_.end()); sizes_.erase(last, sizes_.end()); - /* - * The sizes_ vector is sorted in ascending order, the resolution is - * thus the last element of the vector. - */ - resolution_ = sizes_.back(); - /* * VIMC is a bit special, as it does not yet support all the mandatory * requirements regular sensors have to respect. @@ -324,14 +318,20 @@ int CameraSensor::validateSensorDriver() Rectangle rect; int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_BOUNDS, &rect); if (ret) { - rect = Rectangle(resolution()); + /* + * Default the pixel array size to the largest size supported + * by the sensor. The sizes_ vector is sorted in ascending + * order, the largest size is thus the last element. + */ + pixelArraySize_ = sizes_.back(); + LOG(CameraSensor, Warning) << "The PixelArraySize property has been defaulted to " - << rect.toString(); + << pixelArraySize_.toString(); err = -EINVAL; + } else { + pixelArraySize_ = rect.size(); } - pixelArraySize_.width = rect.width; - pixelArraySize_.height = rect.height; ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &activeArea_); if (ret) { @@ -397,7 +397,8 @@ int CameraSensor::validateSensorDriver() */ void CameraSensor::initVimcDefaultProperties() { - pixelArraySize_ = resolution(); + /* Use the largest supported size. */ + pixelArraySize_ = sizes_.back(); activeArea_ = Rectangle(pixelArraySize_); }