From patchwork Thu Aug 8 10:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 20836 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 0CE6BC32D6 for ; Thu, 8 Aug 2024 10:24:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 80789633B4; Thu, 8 Aug 2024 12:24:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="EKQdKb7p"; dkim-atps=neutral Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F3E90633B3 for ; Thu, 8 Aug 2024 12:23:49 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-52f01b8738dso615477e87.1 for ; Thu, 08 Aug 2024 03:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1723112629; x=1723717429; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=udLn4pl0gbPuXta+jTkKmxnNGVbdVMnTNow0Ki0JMVw=; b=EKQdKb7pibM9yyiE1WwDgzIM+J1Wrr3GXF1LhLMpPtXT88ev3hqaPwkeKqCW903jWI BEm2wVXcGHCASScx1lDodxHj8tG8YOj6v04q+Nx+jtH5hXjH8iDP8pW5Oed0gmCjuRvz Cddh/QD/VMgRDL9CUSn1JlYhQ1aXzhkjOYpFZll+kdfV4qWWjtOn1+OiQg4CyVrrwYo9 eVGK7hWhouNj0xkku3wEw7VU1SwtQqCPY8ner3UVvqMuWu9C25ooclmnhKenI9OmIPwI HWGo8CjJ5O1hUXQO4ejHAZbbh/E72FgMRpzw54oZzy4DtO/BHungT01mHooDmPKHXtOs 3Lgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723112629; x=1723717429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=udLn4pl0gbPuXta+jTkKmxnNGVbdVMnTNow0Ki0JMVw=; b=JOC6XKRNXvo0ywAfaTuh5WkEAUYQf9OZTdDqWOMvnBudnB8rv4Cu4Dan82vnR0i6JK NagOQqV7Awy9yHvefFOu8pRS9tuJvZaO5GjNL7zjxv6mDL46qHqiTSjneDibP/mnv1tz R3OqbiYB0Ec5ofJEkju4Jjk1lHkWKI1Q/jgSqTSWjQEUfZeGB1jLJWA3EpJ6nEzjRm7C cG1fLH9NLKeK/aKknX2rH+3wFr3Y29LvkcA4uXJSK1xZD+If11jH+y+59inPTQTo0LMS /yPTaCMI2Ave4sNiJU1QkkStzyCU7BAAi0F24MZYxarUwnLtn9NkzpCRwffYGVbSHccR cVXA== X-Gm-Message-State: AOJu0YzkMtN2ZcJkwFGWDMFrKzl0O4VIQZ2Np09p49KcM0Uh7uGmURGt Llv7MEwtthl2LcflYC1B4Bra1ytlo4ch/GUaJx1iFz1SOIrXTV3KJXLyv4FgjcItli2Im3a1r+u x X-Google-Smtp-Source: AGHT+IEz8y4uHvVJv+XWKKqm0330tldGJlTx+mcpbOx/p3BYhOKpZU/t2NzjsFM5pJfs3+i0cvnKjA== X-Received: by 2002:a05:6512:3e0d:b0:52c:df6d:e52e with SMTP id 2adb3069b0e04-530e582d6acmr1140484e87.16.1723112628283; Thu, 08 Aug 2024 03:23:48 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36d272290c2sm1404234f8f.92.2024.08.08.03.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 03:23:47 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck Subject: [PATCH v1 4/7] pipeline: rpi: Introduce CameraData::CropParams Date: Thu, 8 Aug 2024 11:23:43 +0100 Message-Id: <20240808102346.13065-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808102346.13065-1-naush@raspberrypi.com> References: <20240808102346.13065-1-naush@raspberrypi.com> MIME-Version: 1.0 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" In preparation for assigning separate crop windows for each stream, add a new CropParams structure that stores the existing ispCrop_ and ispMinCropSize_ as fields. Use a new std::map to store a CropParams structure where the map key is the index of the stream configuration in the CameraConfiguration vector. At preset, only a single CropParams structure will be set at key == 0 to preserve the existing crop handling logic. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- .../pipeline/rpi/common/pipeline_base.cpp | 23 +++++++++++-------- .../pipeline/rpi/common/pipeline_base.h | 21 +++++++++++++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 13 ++++++++--- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 2de6111bacfd..412e71648231 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -561,10 +561,12 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) for (auto const &c : result.controlInfo) ctrlMap.emplace(c.first, c.second); - /* Add the ScalerCrop control limits based on the current mode. */ - Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_)); - ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, - data->scaleIspCrop(data->ispCrop_)); + if (data->cropParams_.count(0)) { + /* Add the ScalerCrop control limits based on the current mode. */ + Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->cropParams_[0].ispMinCropSize)); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(data->cropParams_[0].ispCrop)); + } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1291,7 +1293,8 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { const auto &scalerCrop = controls.get(controls::ScalerCrop); - if (scalerCrop) { + if (scalerCrop && cropParams_.count(0)) { + CropParams &cropParams = cropParams_[0]; Rectangle nativeCrop = *scalerCrop; if (!nativeCrop.width || !nativeCrop.height) @@ -1308,12 +1311,12 @@ void CameraData::applyScalerCrop(const ControlList &controls) * 2. With the same mid-point, if possible. * 3. But it can't go outside the sensor area. */ - Size minSize = ispMinCropSize_.expandedToAspectRatio(nativeCrop.size()); + Size minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); Size size = ispCrop.size().expandedTo(minSize); ispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize)); - if (ispCrop != ispCrop_) { - ispCrop_ = ispCrop; + if (ispCrop != cropParams.ispCrop) { + cropParams.ispCrop = ispCrop; platformSetIspCrop(ispCrop); } } @@ -1471,7 +1474,9 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - request->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_)); + if (cropParams_.count(0)) + request->metadata().set(controls::ScalerCrop, + scaleIspCrop(cropParams_[0].ispCrop)); } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index d65b695c30b5..2bed905178bc 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -133,8 +133,25 @@ public: /* For handling digital zoom. */ IPACameraSensorInfo sensorInfo_; - Rectangle ispCrop_; /* crop in ISP (camera mode) pixels */ - Size ispMinCropSize_; + + struct CropParams { + CropParams(Rectangle ispCrop_, Size ispMinCropSize_) + : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_) + { + } + + CropParams() + { + } + + /* Crop in ISP (camera mode) pixels */ + Rectangle ispCrop; + /* Minimum crop size in ISP output pixels */ + Size ispMinCropSize; + }; + + /* Mapping of CropParams keyed by the stream index in CameraConfiguration */ + std::map cropParams_; unsigned int dropFrameCount_; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 0ea032293bc9..d118252f02dd 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -702,13 +702,20 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi /* Figure out the smallest selection the ISP will allow. */ Rectangle testCrop(0, 0, 1, 1); isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop); - ispMinCropSize_ = testCrop.size(); /* Adjust aspect ratio by providing crops on the input image. */ Size size = unicamFormat.size.boundedToAspectRatio(maxSize); - ispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center()); + Rectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(ispCrop_); + platformSetIspCrop(ispCrop); + /* + * Set the scaler crop to the value we are using (scaled to native sensor + * coordinates). + */ + cropParams_.clear(); + cropParams_.emplace(std::piecewise_construct, + std::forward_as_tuple(0), + std::forward_as_tuple(scaleIspCrop(ispCrop), testCrop.size())); return 0; }