{"id":21432,"url":"https://patchwork.libcamera.org/api/patches/21432/?format=json","web_url":"https://patchwork.libcamera.org/patch/21432/","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":"<20240930141415.8857-8-naush@raspberrypi.com>","date":"2024-09-30T14:14:15","name":"[v2,7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0ca5c5cde01da2c8539a4a86755629746bd17fa3","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/21432/mbox/","series":[{"id":4639,"url":"https://patchwork.libcamera.org/api/series/4639/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4639","date":"2024-09-30T14:14:08","name":"Raspberry Pi: Add controls::rpi::ScalerCrops","version":2,"mbox":"https://patchwork.libcamera.org/series/4639/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21432/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21432/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 52087C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 30 Sep 2024 14:14:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C09F263523;\n\tMon, 30 Sep 2024 16:14:15 +0200 (CEST)","from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com\n\t[IPv6:2a00:1450:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F9136351A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Sep 2024 16:14:04 +0200 (CEST)","by mail-wr1-x42b.google.com with SMTP id\n\tffacd0b85a97d-37cdc7bd941so145878f8f.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Sep 2024 07:14:04 -0700 (PDT)","from naush-laptop.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-37cd56e65c3sm9142524f8f.60.2024.09.30.07.14.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 30 Sep 2024 07:14:02 -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=\"dnYd0snh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1727705644; x=1728310444;\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=Td/TBRZGbHBx4CYqK/k1N9Zms1qp/+XMuth4qZeDX9k=;\n\tb=dnYd0snhGb3e/lnlkCPEDvS31/B3H552CCgJuoQAUXuV3abMQE1f1Qr1NZhSg8rKy+\n\tNbyPwSWrL4DvijqbC/aFMWt3PsjFLJ0J71MYRjXw2EozwF+54ze5gJeKtmIvK40JCQgq\n\tCqQGSr/Nls675ePPCk3FNq/li6Eh7r/HVRlK0zjtNWkxsMNcrKjeSw8EA87JBjLoKXsK\n\t5JQyfeAg37G+e4q3EUH8A09Y9qyh1eY5XPrkIvXd7z4nP/lhP5P8RwQhCf/TrJrbIVbM\n\tSV3e+Sz+Ak5TWViNpr4sKODnvMFiCT+HQVIhUE7QcNALcr3kZwiFDSWpaCZtTpm/Z0uY\n\tHZ7w==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727705644; x=1728310444;\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=Td/TBRZGbHBx4CYqK/k1N9Zms1qp/+XMuth4qZeDX9k=;\n\tb=SXFWcQyEOtRiHWoAgQBlsfxsukBncQLR15aa+Pgrov/3XZhWgRAmHg71zRr/OZBXaq\n\tevfaEjATt0trw7NKXqOzUYrCOQi0poGOM0GpEC7mdveGnQbdh5Tgmc9TEKJTzJVg0gnQ\n\tWlGUQEdBF9eTc0BndGwmtB9Fj6SiI0mVqR4rwji/xAN5fVWeTrFOe2NFtfpe+KpGUR0P\n\tmnsyBm6VxUvuZK1kA6Czw4qRxRQTRK2uRNyh3Bn/0WxGbXUTB71Cdd20KzfuyUXmIK8B\n\tf3LcisjsQxb7MCMCUgxEPE5t7Ti6G2YOlOtcmEHJUXtamSn07MN5eR5lVwtFQy9Z6Ymu\n\tBsww==","X-Gm-Message-State":"AOJu0YyCZLxb9LXX5K37g+7CJKiJzCg1ZNeCjaDgSVKzZMqrL2gRMYM0\n\ttGj4AKs5jxSC5GGWZn5FcO7oaoo0fs7/u8TjFHbSZxTGn2wSw1B4LKfo8b+l0Katb8l8r9H+s+f\n\tA","X-Google-Smtp-Source":"AGHT+IHQepeeSWAHIz4G/igmDNRsPs4UrioTef6jHOdIEA07eyPm1uy1VTif4T5vEVZeNCYmrNbdAA==","X-Received":"by 2002:a5d:6c6e:0:b0:374:cd01:8b72 with SMTP id\n\tffacd0b85a97d-37cde446cffmr2482820f8f.9.1727705643603; \n\tMon, 30 Sep 2024 07:14:03 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Naushir Patuck <naush@raspberrypi.com>","Subject":"[PATCH v2 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops","Date":"Mon, 30 Sep 2024 15:14:15 +0100","Message-Id":"<20240930141415.8857-8-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","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 former takes\npriority over the latter, and if present, will apply the same scaler\ncrop 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>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     | 76 ++++++++++++++-----\n 1 file changed, 59 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..9393e79ae4c7 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_[0].ispCrop),\n+\t\t\t\t\t    data->scaleIspCrop(data->cropParams_[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,29 @@ 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::ScalerCrop is present, apply the same crop to all ISP output\n+\t * streams. Otherwise if controls::rpi::ScalerCrops, apply the given crops\n+\t * to the ISP output streams, indexed by the same order in which they had\n+\t * been configured. This is not the same as the ISP output index.\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 +1349,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_[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_[i].ispCrop) {\n+\t\t\tcropParams_[i].ispCrop = ispCrop;\n+\t\t\tplatformSetIspCrop(cropParams_[i].ispIndex, ispCrop);\n \t\t}\n \t}\n }\n@@ -1478,10 +1512,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":["v2","7/7"]}