From patchwork Wed Aug 5 12:30:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9221 X-Patchwork-Delegate: jacopo@jmondi.org 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 05F6ABD86F for ; Wed, 5 Aug 2020 12:26:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9585D60564; Wed, 5 Aug 2020 14:26:29 +0200 (CEST) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CC7A60492 for ; Wed, 5 Aug 2020 14:26:28 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id A59E41BF211; Wed, 5 Aug 2020 12:26:27 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 5 Aug 2020 14:30:04 +0200 Message-Id: <20200805123004.18794-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: camera_sensor: Match V4L2 specification 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" Adjust the top-left corner coordinates of the analogCrop rectangle to match the libcamera and V4L2 specification. As per the V4L2 selection API specification, all rectangles accessed using V4L2_SEL_TGT_* are defined relatively to the full pixel array, which is retrieved using the V4L2_SEL_TGT_NATIVE target. Libcamera defines the analogCrop rectangle to be defined relatively to the active pixel matrix rectangle. To compensate the difference in the reference rectangle between the two specification, subtract from the TGT_CROP rectangle top-left corner the offset of the active pixel array previously obtained with TGT_CROP_DEFAULT. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- This patch depends on the inclusion of the following patch in the Linux kernel: [PATCH 4/4] media: i2c: imx219: Selection compliance fixes --- src/libcamera/camera_sensor.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.27.0 diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 350f49accad9..8f09206ff635 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -508,6 +508,18 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const return ret; } + /* + * The top-left corner position of the selection rectangle returned by + * the V4L2_SEL_TGT_CROP target is defined relatively to the full pixel + * array, while libcamera's analogCrop is defined relatively to the + * active portion of the pixel matrix. + * + * Subtract from the top-left coordinates the offsets of the + * CROP_DEFAULT target rectangle to align the two. + */ + info->analogCrop.x -= rect.x; + info->analogCrop.y -= rect.y; + /* The bit depth and image size depend on the currently applied format. */ V4L2SubdeviceFormat format{}; ret = subdev_->getFormat(pad_, &format);