From patchwork Mon Sep 30 14:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21429 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 9505FC32D4 for ; Mon, 30 Sep 2024 14:14:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 371A46351A; Mon, 30 Sep 2024 16:14:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="N5uYPbGV"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D80106351E for ; Mon, 30 Sep 2024 16:14:01 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42ca4e0014dso5941945e9.2 for ; Mon, 30 Sep 2024 07:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727705641; x=1728310441; 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=hK15FfCcZU6znAebgYoIiMQvQPDECUqm2aTM2ldSG6M=; b=N5uYPbGVG3ZWSQiw8aZbUp17yEm+yOnX8HjRDlycI527JTQsMzR6j9cNs0iILtRusG 1Bs+GTRBEVcWxh9/jOKskO3Q0xaWswlpfNTjP3Wyj5VKjt/J188RI0vkB8uW2SiBttmo w/9odMvRu9MAboZPJUVSWT1M5a67aSTUkyEWjSu6dA1ddHiX3z1Y7ZmpOGU2Bx3/xqVl Im3svhujvWEnPgciV5ABP2dlPHNlEfiNvegocYxUca9oPP6YrwWsTQtE9N92mVHtGzTO luNu7/v7qn5GATOLPNBbv58VUBmGyhRZTLaMZiBR50ma0MoiSM5wx8D98v3GOuNmydjQ kLig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727705641; x=1728310441; 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=hK15FfCcZU6znAebgYoIiMQvQPDECUqm2aTM2ldSG6M=; b=kigMtu/6vG61ry6NJ9ePx4w46EkNYtM+hgRiXsjSkQjeHeqvTdc10sJ3IHg2gilRsj 8PjqFDYPEK+y4kB9aNh+yEL2vsvJon5TtxGB/81uDha/O+VEBaWlGN4x8Uae9tAZeUCq 5YZ5tyfV8JVXmsO0FMHVtFoInfEcfLzllhfGNHmEiMEHAyC15P+MBWF7C+YHoKHL0oTq Xm3hMsw2u5NUjqHz3urD/edXdWeRulc/JFQtdmQ2wou+bnuV8empFFM709w/ihw2iXds bIxkXeD6TkeiJhmOuYoYb24wzkcGh2DEZS5RHheoduXpTYIEGaLLyEG2jzM7zVUBB+ye /aKg== X-Gm-Message-State: AOJu0YyQ9p6h4BIPN8xvqYGt5DWG1D6vFjyqkhgoNukLky5EiqIESczn 7LrP8Q/BQYReo3U1GbO0hHdLYjUGw090iI0uZV2cgfi6wkgytPZCAWU8wGOoUqSwSUb51oMbrnw c X-Google-Smtp-Source: AGHT+IHRboinuZhNHPCEwmpLBlTA0FJ1mV/iVvWbbwypghPBAOh7gs3/obqDDr2RfMU3wj50OiZ+OA== X-Received: by 2002:a05:600c:3145:b0:42c:df54:18f6 with SMTP id 5b1f17b1804b1-42f5e38b8d9mr28227495e9.3.1727705640924; Mon, 30 Sep 2024 07:14:00 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 07:14:00 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart Subject: [PATCH v2 4/7] pipeline: rpi: Introduce CameraData::CropParams Date: Mon, 30 Sep 2024 15:14:12 +0100 Message-Id: <20240930141415.8857-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930141415.8857-1-naush@raspberrypi.com> References: <20240930141415.8857-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 Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 28 +++++++++++++------ .../pipeline/rpi/common/pipeline_base.h | 21 ++++++++++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 12 ++++++-- 3 files changed, 47 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..220c7b962280 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -533,6 +533,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) * Platform specific internal stream configuration. This also assigns * external streams which get configured below. */ + data->cropParams_.clear(); ret = data->platformConfigure(rpiConfig); if (ret) return ret; @@ -561,10 +562,14 @@ 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_)); + const auto cropParamsIt = data->cropParams_.find(0); + if (cropParamsIt != data->cropParams_.end()) { + const CameraData::CropParams &cropParams = cropParamsIt->second; + /* Add the ScalerCrop control limits based on the current mode. */ + Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize)); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(cropParams.ispCrop)); + } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1291,8 +1296,10 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { const auto &scalerCrop = controls.get(controls::ScalerCrop); - if (scalerCrop) { + const auto cropParamsIt = cropParams_.find(0); + if (scalerCrop && cropParamsIt != cropParams_.end()) { Rectangle nativeCrop = *scalerCrop; + CropParams &cropParams = cropParamsIt->second; if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -1308,12 +1315,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 +1478,10 @@ 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_)); + const auto cropParamsIt = cropParams_.find(0); + if (cropParamsIt != cropParams_.end()) + request->metadata().set(controls::ScalerCrop, + scaleIspCrop(cropParamsIt->second.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..75babbe17f31 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 output stream order 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..8080f55a1cf4 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -702,13 +702,19 @@ 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_.emplace(std::piecewise_construct, + std::forward_as_tuple(0), + std::forward_as_tuple(ispCrop, testCrop.size())); return 0; }