From patchwork Thu Mar 3 12:11:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 15404 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 3B1BCBF415 for ; Thu, 3 Mar 2022 12:11:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B84B60475; Thu, 3 Mar 2022 13:11:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="GPPXUTsj"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E67DC601FF for ; Thu, 3 Mar 2022 13:11:27 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id o18-20020a05600c4fd200b003826701f847so4608850wmq.4 for ; Thu, 03 Mar 2022 04:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=V0xSEc0yJ/sm6L6Ol6shJ76H6eiG7BFG1w515hWqhIQ=; b=GPPXUTsj3JWuDkM+FDoNC4c9iQ/KfBlZGgeElvq3z/cfxiXimKN+TGqJGAfzmmfAXM R2RuCC/oCwtOoNr2qgMAZcyPKxwE4tU+0HegjEqYfuqdudcEokurI0e/9XUg1pwcUscE /PMPocGeD8iqbNPu+A8YvARz5tN8nWgOx6YETI1EpflgJbgVv9eudGPlEZ9IYWIXNeOQ ubwPlyop/idI3G5yHp4K688GS+Katc70VvdnCps7GcFDpfkaO0pD8R99LAdY/LdiF9Fg eY9t0Iy5uZsiuBau9+Hy0973K4WTGwtNe2kreWRTqHUY3SBeooG9LvDths+93EOoKyEt q6KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=V0xSEc0yJ/sm6L6Ol6shJ76H6eiG7BFG1w515hWqhIQ=; b=v2/ICXg7tRiXT9QIIaHzY+3n95u41jZ/nwfxja5vqH/IM7IL7DyP9pocdFYGWKS/7A 8oDa1afmaLwrkIp8xf1o8SUjB/WtNxhv4M+6cnuPm+LcrteIDz72W942xWIKlwH0GdgM nfa/nc7UaK0rrg1ylfdYmlenAS8l7q5zkrLNv4vnt82ByPDboG2AdQ7WKtHVAS3bcVqv Uk3XYcGXYuYDF3jPSNp9q3Qeejhua/cdkZcz6vc7k3M5QmKp5aQE9ZZsVf0IZp2gndRK Ne/mSqAZDykdmwfKxFzMya4X3Shr4GW6aQal5WeqqDBwDLjH2HvJWwQerthVwpnpPeoU m6aw== X-Gm-Message-State: AOAM532am8iK6zXM9G/X+Y/C5EbGfyzbAaMExZByKQhSdKDnExwRXRWw uSRuSTPmpyIxESPMUY2UMJ+W3plWA6tEkQ== X-Google-Smtp-Source: ABdhPJzO79DcC3FbZNu6IpEKm6UomH5gB3gagdftScHUl42Psjofp1UJBxSefI/cmhDYwJtXJX8p1w== X-Received: by 2002:a05:600c:4e48:b0:381:83d8:54f6 with SMTP id e8-20020a05600c4e4800b0038183d854f6mr3597720wmq.18.1646309487344; Thu, 03 Mar 2022 04:11:27 -0800 (PST) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id f18-20020a05600c155200b003816bac83f6sm2320821wmg.27.2022.03.03.04.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 04:11:26 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Mar 2022 12:11:13 +0000 Message-Id: <20220303121113.16839-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: pipeline: raspberrypi: Fix scaler crop when sensor is configured 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" We must calculate the initial scaler crop when the camera is configured, otherwise the metadata will report this rectangle as being all zeroes. Because the calculation is identical to that performed later in handling the scaler crop control, we factor it into a small helper function, RPiCameraData::scaleIspCrop. Signed-off-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- .../pipeline/raspberrypi/raspberrypi.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 29bff9d6..eede78e6 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -212,6 +212,7 @@ public: void handleStreamBuffer(FrameBuffer *buffer, RPi::Stream *stream); void handleExternalBuffer(FrameBuffer *buffer, RPi::Stream *stream); void handleState(); + Rectangle scaleIspCrop(const Rectangle &ispCrop) const; void applyScalerCrop(const ControlList &controls); std::unique_ptr ipa_; @@ -887,6 +888,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) if (ret) LOG(RPI, Error) << "Failed to configure the IPA: " << ret; + /* Set the scaler crop to the value we are using (scaled to native sensor coordinates). */ + data->scalerCrop_ = data->scaleIspCrop(data->ispCrop_); + /* * Configure the Unicam embedded data output format only if the sensor * supports it. @@ -1974,6 +1978,18 @@ void RPiCameraData::checkRequestCompleted() } } +Rectangle RPiCameraData::scaleIspCrop(const Rectangle &ispCrop) const +{ + /* + * Scale a crop rectangle defined in the ISP's coordinates into native sensor + * coordinates. + */ + Rectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(), + sensorInfo_.outputSize); + nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft()); + return nativeCrop; +} + void RPiCameraData::applyScalerCrop(const ControlList &controls) { if (controls.contains(controls::ScalerCrop)) { @@ -2006,9 +2022,7 @@ void RPiCameraData::applyScalerCrop(const ControlList &controls) * used. But we must first rescale that from ISP (camera mode) pixels * back into sensor native pixels. */ - scalerCrop_ = ispCrop_.scaledBy(sensorInfo_.analogCrop.size(), - sensorInfo_.outputSize); - scalerCrop_.translateBy(sensorInfo_.analogCrop.topLeft()); + scalerCrop_ = scaleIspCrop(ispCrop_); } } }