Show a patch.

GET /api/1.1/patches/20838/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20838,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20838/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20838/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240808102346.13065-8-naush@raspberrypi.com>",
    "date": "2024-08-08T10:23:46",
    "name": "[v1,7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "dade8db3fdda349cf620c8afadba650661ae2022",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20838/mbox/",
    "series": [
        {
            "id": 4501,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4501/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4501",
            "date": "2024-08-08T10:23:39",
            "name": "Raspberry Pi: Add controls::rpi::ScalerCrops",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4501/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20838/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20838/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 ADBCBC324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  8 Aug 2024 10:24:05 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 79E1D633C4;\n\tThu,  8 Aug 2024 12:24:03 +0200 (CEST)",
            "from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 71479633B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Aug 2024 12:23:51 +0200 (CEST)",
            "by mail-wr1-x436.google.com with SMTP id\n\tffacd0b85a97d-369f68f63b1so420101f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 08 Aug 2024 03:23:51 -0700 (PDT)",
            "from naush-laptop.pitowers.org ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-36d272290c2sm1404234f8f.92.2024.08.08.03.23.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 08 Aug 2024 03:23:50 -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=\"B5BEjglt\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1723112631; x=1723717431;\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=FutAzOzdno63Zw2uUf3aHTsbgoCwqzcG1+IrkzQMZCA=;\n\tb=B5BEjglti5iYCcxCEvcfT/HjN5KGQzQBvzuHRQLkTOmQ6THpiZ3vC/H8K+gk06h2kR\n\t5AsX5j5z8+qDFjKr+udrISZuQJVvgkYHGINGzAJ2GI5z2FjH2ZK/NOqIm5ukNf/1OKeZ\n\tN5lZaIJFU4w7Xn/0sXAiXa1WqTh0au1pnncfH5gzdm8ylDtgHQ+lyZANRMn/LACcBqwh\n\tJwYySHWSoUHq0D7O+ezvvjgdyrvJSURbsJlFS5YDI2r2gJiEV5LkcWg4zxFsvr5DlXKV\n\txyieGFxrCoTFjT/qVHFYh8gwMD+nLPhK/er6XTnaTNucUlnarUINFFhUvvkdZDDOFrt3\n\tadAA==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1723112631; x=1723717431;\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=FutAzOzdno63Zw2uUf3aHTsbgoCwqzcG1+IrkzQMZCA=;\n\tb=ftjNY/09a/AbgWhq0qKVuYwCQlySe0Ux6EfJsKrpgo13bkO4tt4ywM8WNZiQYrw2se\n\tYuch6p1YVkdFFGPi7s7xTldZOrUBb9aQsEJwUpRTZIfeAu3pcLFQUaLisTkB0sMDOoC0\n\tkdX9+XeVtxeD8X7xaue9ocZr8k9AU584YM7zYmFT3Eahj3rvoBXDtPYJld0Tmny3PZlO\n\t4W+tXUyrJMmFN6Un7ekPrkH9EBncZjXQB2U7qLzo2QpJxsWNSp8Mda0WVhpDrc1Z4pp4\n\tMdJfI+f2tJ04LB8K+FsDlh04ESaiValWLV1wjGjssubS7ZU9uU3VwxCYYFimzPcWsgfU\n\tqcuQ==",
        "X-Gm-Message-State": "AOJu0YyApFtdPz237lJsnXXapFCVvhSk0hAGPuMBZbK1TqZ1ttVavI0N\n\tqyfJsoXZ9nBMSvbEQnwnZ/v8hesu/l8DTkFVZvETtGLpVRiemDEA6UP4m6Z0hWVWFhb+s9GMNBi\n\tR",
        "X-Google-Smtp-Source": "AGHT+IHf8KONfa8fzGhfky3HDVP/MfpyOgsmFt+8bcW9H+Sewrl2QhY7uqNebMA2jCdxvpVzR7i1bw==",
        "X-Received": "by 2002:adf:cf05:0:b0:36b:a3c8:12aa with SMTP id\n\tffacd0b85a97d-36d274dcc2fmr931558f8f.26.1723112630516; \n\tThu, 08 Aug 2024 03:23:50 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Naushir Patuck <naush@raspberrypi.com>",
        "Subject": "[PATCH v1 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops",
        "Date": "Thu,  8 Aug 2024 11:23:46 +0100",
        "Message-Id": "<20240808102346.13065-8-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",
        "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     | 69 +++++++++++++++----\n 1 file changed, 56 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex a6ea4e9c47dd..b9759b682f0d 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -561,11 +561,28 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \tfor (auto const &c : result.controlInfo)\n \t\tctrlMap.emplace(c.first, c.second);\n \n-\tif (data->cropParams_.count(0)) {\n-\t\t/* Add the ScalerCrop control limits based on the current mode. */\n+\tif (data->cropParams_.size()) {\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(data->cropParams_[0].ispMinCropSize));\n \t\tctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop,\n \t\t\t\t\t\t\t     data->scaleIspCrop(data->cropParams_[0].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} else {\n+\t\t\t/* Match the same ControlInfo for rpi::ScalerCrops. */\n+\t\t\tctrlMap[&controls::rpi::ScalerCrops] = ctrlMap[&controls::ScalerCrop];\n+\t\t}\n \t}\n \n \tdata->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap());\n@@ -1292,10 +1309,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-\tif (scalerCrop && cropParams_.count(0)) {\n-\t\tCropParams &cropParams = cropParams_[0];\n-\t\tRectangle nativeCrop = *scalerCrop;\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@@ -1311,13 +1347,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@@ -1474,9 +1510,16 @@ 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-\tif (cropParams_.count(0))\n-\t\trequest->metadata().set(controls::ScalerCrop,\n-\t\t\t\t\tscaleIspCrop(cropParams_[0].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\trequest->metadata().set(controls::rpi::ScalerCrops,\n+\t\t\t\t\tSpan<const Rectangle>(crops.data(), crops.size()));\n+\t}\n }\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "v1",
        "7/7"
    ]
}