From patchwork Tue Aug 3 13:32:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13181 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 38AEBC3235 for ; Tue, 3 Aug 2021 13:32:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9BBF687DE; Tue, 3 Aug 2021 15:32:34 +0200 (CEST) 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="Qk62e1az"; 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 BB5E2687CE for ; Tue, 3 Aug 2021 15:32:33 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.238.109.12]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B492D3F0; Tue, 3 Aug 2021 15:32:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627997553; bh=8RpSljUB7bb7AR22UrEoMo0xiz6QWPZswzKxRCnSPjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qk62e1azlA70n32aO4ElGiTo/dyaH1eQLArMK1fRR90SC/s8Ylb2y5vqA9jD0+900 SlgAXmx0PrDTyJWlNqgXyN4RvvTk/F2FgmwvChgEhd4atFyluC+BL9BQKfQf+o0w/P Tmg7wyM7/JhzikV+0U0+jZEMSTa4dAOCPy27AJHs= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 3 Aug 2021 19:02:05 +0530 Message-Id: <20210803133205.6599-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803133205.6599-1-umang.jain@ideasonboard.com> References: <20210803133205.6599-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] ipu3: cio2: Tweak sensor size selection policy 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" Do not compare higher precision of the ratios, as it might lead to absurd selection of sensor size for a relatively low requested resolution size. For example: The imx258 driver supports the following sensor resolutions: - 4208x3118 = 1.349583066 - 2104x1560 = 1.348717949 - 1048x780 = 1.343589744 It can be inferred that, that the aspect ratio only differs by a small factor with each other. It does not makes sense to select a 4208x3118 for a requested size of say 640x480 or 1280x720, which is what is happening currently. ($) cam -c1 -swidth=640,height=480,role=raw - CIO2 configuration: 4208x3118-SGRBG10_IPU3 In order to address this constraint, only compare the ratio with single precision to make a better decision on the sensor resolution policy selection. ($) cam -c1 -srole=raw,width=640,height=480 - CIO2 configuration: 1048x780-SGRBG10_IPU3 Signed-off-by: Umang Jain --- src/libcamera/pipeline/ipu3/cio2.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 9980b8bd..887b850d 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -281,6 +281,13 @@ V4L2SubdeviceFormat CIO2Device::getSensorFormat(const std::vector continue; float ratio = static_cast(sz.width) / sz.height; + /* + * Comparing ratios with a single precision is enough. + * This avoids the selection of a frame size which is + * 2x or 3x than the requested size, having a slightly + * better ratio w.r.t native resolution ratio. + */ + ratio = static_cast(ratio * 10) / 10.0; float ratioDiff = fabsf(ratio - desiredRatio); unsigned int area = sz.width * sz.height; unsigned int areaDiff = area - desiredArea;