From patchwork Tue Jun 6 10:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18710 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 EC227C328F for ; Tue, 6 Jun 2023 10:33:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CF0C46289A; Tue, 6 Jun 2023 12:33:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686047634; bh=UUdgzZH/1qvNoEwm+TL4mobgxIZ/Ya5LcSZ8En1dbus=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DSPRTwwQxymJBkcMBitXKJGpzCMMOafqcEJqmOmF+ZEAW5qFaIq2SFr4ySj+x8bz8 /wE+G++wOearZEDBuZtEVneqPp/zQggNA8A7JYGCMPU+2Ytz/dyOpyKbjjgQ7D3Fy7 udPImgdZrs9dgn/OUSM5c3byhJNMtO3JadG6VNJ0dzcf6DrZaOHBXflbREl3dVFswV wIlN7JdmfYdf9xDMQypj5h9nXDTNT/3H2fuYUvJqKoQahoFSRbn9iAodRuzr62d5Xe CyuPT/c8HDmM4tGdOFMGxdVx6CBgRADris40RFv56ZVhgkNrDEdZiIkBNJagIXfQHo rWlUUAW2bJSUw== 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 DA19062722 for ; Tue, 6 Jun 2023 12:33:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YXufvZSJ"; dkim-atps=neutral Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 692497EC; Tue, 6 Jun 2023 12:33:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686047607; bh=UUdgzZH/1qvNoEwm+TL4mobgxIZ/Ya5LcSZ8En1dbus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YXufvZSJ/NQBb2r50VnOD5NiDWTelvDBXQMdJBz5ZRTtxobKLh5786wOcMYTsgdN8 JYiGHM+w2/4ZDy5LHUyYFBHDmcPAEmpskc9iGEtRonqMnPI9QuGnf4DtGr4u2P1KGg 8K2u14zS5Y31Qg4MRk8c2xWbdFq2YFVvptZ9Dhb8= To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Jun 2023 12:33:34 +0200 Message-Id: <20230606103336.17782-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230606103336.17782-1-jacopo.mondi@ideasonboard.com> References: <20230606103336.17782-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/4] libcamera: rkisp1: Crop on ISP before downscaling 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi , libcamera@luigi311.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Crop on the resizer sink pad before downscaling to the aspect ratio of the desired output size. Cropping the input frame to the output aspect ratio allows to maintain the correct picture proportions, as otherwise downscaling would change the image geometry. Signed-off-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart Tested-by: Umang Jain --- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 5079b268c464..0f728cea72b7 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -314,7 +314,18 @@ int RkISP1Path::configure(const StreamConfiguration &config, if (ret < 0) return ret; - Rectangle rect(0, 0, ispFormat.size); + /* + * Crop on the resizer input to maintain FOV before downscaling. + * + * \todo The alignment to a multiple of 2 pixels is required but may + * change the aspect ratio very slightly. A more advanced algorithm to + * compute the resizer input crop rectangle is needed, and it should + * also take into account the need to crop away the edge pixels affected + * by the ISP processing blocks. + */ + Size ispCrop = inputFormat.size.boundedToAspectRatio(config.size) + .alignedUpTo(2, 2); + Rectangle rect = ispCrop.centeredTo(Rectangle(inputFormat.size).center()); ret = resizer_->setSelection(0, V4L2_SEL_TGT_CROP, &rect); if (ret < 0) return ret;