{"id":21788,"url":"https://patchwork.libcamera.org/api/patches/21788/?format=json","web_url":"https://patchwork.libcamera.org/patch/21788/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241031094957.18471-8-naush@raspberrypi.com>","date":"2024-10-31T09:49:57","name":"[v4,7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops","commit_ref":"58598f4dde9a3d4236ed52881da9b155443cbc50","pull_url":null,"state":"accepted","archived":false,"hash":"be7518e8a40139061bece9f5b4ef6a7ae4537bf2","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21788/mbox/","series":[{"id":4760,"url":"https://patchwork.libcamera.org/api/series/4760/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4760","date":"2024-10-31T09:49:50","name":"Raspberry Pi: Add controls::rpi::ScalerCrops","version":4,"mbox":"https://patchwork.libcamera.org/series/4760/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21788/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21788/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 72B8AC3292\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Oct 2024 09:52:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 981E6653AB;\n\tThu, 31 Oct 2024 10:52:57 +0100 (CET)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6759F653A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Oct 2024 10:52:47 +0100 (CET)","by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-4314e64eba4so422625e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Oct 2024 02:52:47 -0700 (PDT)","from naush-laptop.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-4327d6983c2sm19789835e9.42.2024.10.31.02.52.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 31 Oct 2024 02:52:46 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"O8hLKb+5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1730368367; x=1730973167;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=X/8CZh5p/MrzA7UDIgjfjtdpHXu5yfJKtsg4HkJ59cg=;\n\tb=O8hLKb+5Y7EerScYKo5vM51IlMJaKU0Mj770Oks+xzoJsXOc1A2CbbwTtcCXoVSdJ/\n\tkkh9wDhGLkYq+sUeCsD4/IveBP8iiHsn63eqfg0aWD8GFUQpEL5Z+TKsT25GQ7etoAoR\n\tlDDfWkaTqPu/5Bg5a1UFRn0XNLDyImfxJU2XVPAcGL361vNPUXVy7+c+ZLav28HANzis\n\tIx5H89pePuKJ5jCmip8at/CoU1VJCcxGt1A60uVhTab2d8MB3oi7GPZs1bXjE5wK2YbE\n\tNrMGn5CpNgnh04y07/Hiz3dnQYo5iAfwTkrilMTJ3Iy+jM4aSvSf+b4v8yWWeC12vQrV\n\tg5ow==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1730368367; x=1730973167;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=X/8CZh5p/MrzA7UDIgjfjtdpHXu5yfJKtsg4HkJ59cg=;\n\tb=Il7wJO/iwOeghDPk7fpLOABBnuKl3begi6cl9kOA+pBLqTS/NYDgK3NmnAOiNB1djU\n\tDq80ZhrM3nMndLBiCh9F67CfpVrGWs8OE1n30bmb7L17kMUErnL2StAfvKhJTepiz2yl\n\tYOQWtfgDB7AO6kA/XlZpXqOoHVSLnpt04oh02iJ/+EEQInwGy19a9jbxqy/KjoDdUCOv\n\tsKXcPnn7hpb+zJaBVWSzgqVFIj9sHaHasFnS5mbSaulCwPlx14s+a0cSC2Gy/2W+tAW7\n\tHFwOmQdG7SQyb9X0U5jT8k4kPo4DoJX64xY/OH1XnYRTHm3aJy4pzk0I9/zIGci9e+VM\n\tuBdQ==","X-Gm-Message-State":"AOJu0Yz3dNWWL1H5EknGA5BfndOpktxgtMjgr8lQhQlII/HmtO4eGSpx\n\tmqAL/Zi71+G7fcLmRTn8EWjgXio/hHQ/WKbu9w4RjYRan6/80cJE9DugXKKtqaEBjkbNfY0fPlO\n\tu","X-Google-Smtp-Source":"AGHT+IHN9Tr5riV7Xf/eKQ+hy/AFqibJtE81+OejXMClrP3o/L969b/O1/uXi2K08gokgEqvFGI5dQ==","X-Received":"by 2002:a05:600c:3b9e:b0:42c:b55f:f4f with SMTP id\n\t5b1f17b1804b1-4319ad4094emr72052595e9.6.1730368366594; \n\tThu, 31 Oct 2024 02:52:46 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Naushir Patuck <naush@raspberrypi.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"[PATCH v4 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops","Date":"Thu, 31 Oct 2024 09:49:57 +0000","Message-Id":"<20241031094957.18471-8-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20241031094957.18471-1-naush@raspberrypi.com>","References":"<20241031094957.18471-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Handle multiple scaler crops being set through the rpi::ScalerCrops\ncontrol. We now populate the cropParams_ map in the loop where we handle\nthe output stream configuration items. The key of this map is the index\nof the stream configuration structure set by the application. This will\nalso be the same index used to specify the crop rectangles through the\nScalerCrops control.\n\nCameraData::applyScalerCrop() has been adapted to look at either\ncontrols::ScalerCrop or controls::rpi::ScalerCrops. The latter takes\npriority over the former. If only controls::ScalerCrop is provided, the\npipeline handler will apply the same scaler crop to all output streams.\n\nFinally return all crops through the same ScalerCrops control via\nrequest metadata. The first configure stream's crop rectangle is also\nreturned via the ScalerCrop control in the request metadata.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     | 77 +++++++++++++++----\n 1 file changed, 60 insertions(+), 17 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 267e6bd9cd70..917c45b3f052 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -181,12 +181,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \n \trawStreams_.clear();\n \toutStreams_.clear();\n+\tunsigned int rawStreamIndex = 0;\n+\tunsigned int outStreamIndex = 0;\n \n-\tfor (const auto &[index, cfg] : utils::enumerate(config_)) {\n+\tfor (auto &cfg : config_) {\n \t\tif (PipelineHandlerBase::isRaw(cfg.pixelFormat))\n-\t\t\trawStreams_.emplace_back(index, &cfg);\n+\t\t\trawStreams_.emplace_back(rawStreamIndex++, &cfg);\n \t\telse\n-\t\t\toutStreams_.emplace_back(index, &cfg);\n+\t\t\toutStreams_.emplace_back(outStreamIndex++, &cfg);\n \t}\n \n \t/* Sort the streams so the highest resolution is first. */\n@@ -565,10 +567,24 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \tconst auto cropParamsIt = data->cropParams_.find(0);\n \tif (cropParamsIt != data->cropParams_.end()) {\n \t\tconst CameraData::CropParams &cropParams = cropParamsIt->second;\n-\t\t/* Add the ScalerCrop control limits based on the current mode. */\n+\t\t/*\n+\t\t * Add the ScalerCrop control limits based on the current mode and\n+\t\t * the first configured stream.\n+\t\t */\n \t\tRectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize));\n \t\tctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop,\n \t\t\t\t\t\t\t     data->scaleIspCrop(cropParams.ispCrop));\n+\t\tif (data->cropParams_.size() == 2) {\n+\t\t\t/*\n+\t\t\t * The control map for rpi::ScalerCrops has the min value\n+\t\t\t * as the default crop for stream 0, max value as the default\n+\t\t\t * value for stream 1.\n+\t\t\t */\n+\t\t\tctrlMap[&controls::rpi::ScalerCrops] =\n+\t\t\t\tControlInfo(data->scaleIspCrop(data->cropParams_.at(0).ispCrop),\n+\t\t\t\t\t    data->scaleIspCrop(data->cropParams_.at(1).ispCrop),\n+\t\t\t\t\t    ctrlMap[&controls::ScalerCrop].def());\n+\t\t}\n \t}\n \n \tdata->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap());\n@@ -1295,11 +1311,30 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n \n void CameraData::applyScalerCrop(const ControlList &controls)\n {\n-\tconst auto &scalerCrop = controls.get<Rectangle>(controls::ScalerCrop);\n-\tconst auto cropParamsIt = cropParams_.find(0);\n-\tif (scalerCrop && cropParamsIt != cropParams_.end()) {\n-\t\tRectangle nativeCrop = *scalerCrop;\n-\t\tCropParams &cropParams = cropParamsIt->second;\n+\tconst auto &scalerCropRPi = controls.get<Span<const Rectangle>>(controls::rpi::ScalerCrops);\n+\tconst auto &scalerCropCore = controls.get<Rectangle>(controls::ScalerCrop);\n+\tstd::vector<Rectangle> scalerCrops;\n+\n+\t/*\n+\t * First thing to do is create a vector of crops to apply to each ISP output\n+\t * based on either controls::ScalerCrop or controls::rpi::ScalerCrops if\n+\t * present.\n+\t *\n+\t * If controls::rpi::ScalerCrops is preset, apply the given crops to the\n+\t * ISP output streams, indexed by the same order in which they had been\n+\t * configured. This is not the same as the ISP output index. Otherwise\n+\t * if controls::ScalerCrop is present, apply the same crop to all ISP\n+\t * output streams.\n+\t */\n+\tfor (unsigned int i = 0; i < cropParams_.size(); i++) {\n+\t\tif (scalerCropRPi && i < scalerCropRPi->size())\n+\t\t\tscalerCrops.push_back(scalerCropRPi->data()[i]);\n+\t\telse if (scalerCropCore)\n+\t\t\tscalerCrops.push_back(*scalerCropCore);\n+\t}\n+\n+\tfor (auto const &[i, scalerCrop] : utils::enumerate(scalerCrops)) {\n+\t\tRectangle nativeCrop = scalerCrop;\n \n \t\tif (!nativeCrop.width || !nativeCrop.height)\n \t\t\tnativeCrop = { 0, 0, 1, 1 };\n@@ -1315,13 +1350,13 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n \t\t * 2. With the same mid-point, if possible.\n \t\t * 3. But it can't go outside the sensor area.\n \t\t */\n-\t\tSize minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size());\n+\t\tSize minSize = cropParams_.at(i).ispMinCropSize.expandedToAspectRatio(nativeCrop.size());\n \t\tSize size = ispCrop.size().expandedTo(minSize);\n \t\tispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize));\n \n-\t\tif (ispCrop != cropParams.ispCrop) {\n-\t\t\tcropParams.ispCrop = ispCrop;\n-\t\t\tplatformSetIspCrop(cropParams.ispIndex, ispCrop);\n+\t\tif (ispCrop != cropParams_.at(i).ispCrop) {\n+\t\t\tcropParams_.at(i).ispCrop = ispCrop;\n+\t\t\tplatformSetIspCrop(cropParams_.at(i).ispIndex, ispCrop);\n \t\t}\n \t}\n }\n@@ -1478,10 +1513,18 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request\n \trequest->metadata().set(controls::SensorTimestamp,\n \t\t\t\tbufferControls.get(controls::SensorTimestamp).value_or(0));\n \n-\tconst auto cropParamsIt = cropParams_.find(0);\n-\tif (cropParamsIt != cropParams_.end())\n-\t\trequest->metadata().set(controls::ScalerCrop,\n-\t\t\t\t\tscaleIspCrop(cropParamsIt->second.ispCrop));\n+\tif (cropParams_.size()) {\n+\t\tstd::vector<Rectangle> crops;\n+\n+\t\tfor (auto const &[k, v] : cropParams_)\n+\t\t\tcrops.push_back(scaleIspCrop(v.ispCrop));\n+\n+\t\trequest->metadata().set(controls::ScalerCrop, crops[0]);\n+\t\tif (crops.size() > 1) {\n+\t\t\trequest->metadata().set(controls::rpi::ScalerCrops,\n+\t\t\t\t\t\tSpan<const Rectangle>(crops.data(), crops.size()));\n+\t\t}\n+\t}\n }\n \n } /* namespace libcamera */\n","prefixes":["v4","7/7"]}