Show a patch.

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

{
    "id": 21785,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/21785/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21785/",
    "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": "<20241031094957.18471-5-naush@raspberrypi.com>",
    "date": "2024-10-31T09:49:54",
    "name": "[v4,4/7] pipeline: rpi: Introduce CameraData::CropParams",
    "commit_ref": "81afca4078974480f91f31d6c2d0c8ffd60ee9f1",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "8e6fb841e7ff4cf2ba3005cdeaa4e6656fe3f630",
    "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/21785/mbox/",
    "series": [
        {
            "id": 4760,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4760/?format=api",
            "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/21785/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21785/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 63B15C330B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Oct 2024 09:52:55 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E9F1C618BF;\n\tThu, 31 Oct 2024 10:52:49 +0100 (CET)",
            "from mail-wm1-x336.google.com (mail-wm1-x336.google.com\n\t[IPv6:2a00:1450:4864:20::336])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 53A71653AF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Oct 2024 10:52:45 +0100 (CET)",
            "by mail-wm1-x336.google.com with SMTP id\n\t5b1f17b1804b1-43158124a54so1109425e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Oct 2024 02:52:45 -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.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 31 Oct 2024 02:52:44 -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=\"J0USs6LM\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1730368364; x=1730973164;\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=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=;\n\tb=J0USs6LM3VriXFTAZUMOg0W8fg2vGZIfmV4fH9KhIyRQqjBUC2Tvqddej9ml7O/DGC\n\tl9GOIldKlfLv/Sc5bnmlcREz8Zmbs5zPMqqPDv2RoGMZVzKQ2zGFXbJzISUNLwIkuqoY\n\t4PXZIi0iCvQd/FGtY6y3eUwUJJ5+LwXuR970Y8nBmQuZ3SFHAkfxgTG5UD9gMUh5WMEK\n\touRPjzC+eYaScrSOcdUF6Hy7CqI1xySiq/mLWc3An4VOG9IYWK3WV78sjL4uuBSw3YB0\n\t4q65aei2wqDhmdS88Qz6PpsdPRkgJw99MfbcGN4RYDiqHi1RMH6Xn9x2v/v9WdaoHRAw\n\t6s1g==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1730368364; x=1730973164;\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=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=;\n\tb=Gbqe6Ph1dKm78CN0+mLWq+B+1XMiV+15z/PiUJFKUHjSJgqewg2uS7XovaR/9wYWPn\n\tuMFd78doydK5nW94KedC+mE343O8n5q7Eb6EYuep/799JO+fEGtMYWu+L1/7VrzI+r7D\n\t2OjUmdcrpcGsZHC1aQepFZ9LJlySt0dIUzbi9gn823fi/gM/2/LpKMKg9FDRoJmYrzVt\n\t9+PLgSmG+DGZ14LY84PH4PJJinDo1rPUe006Kj9pV8s61mgScGZQ+5t9bMu+yylPgTkQ\n\t/5xkCmSBrkX9TnJ1TN/Nl1hRzxRd2AMXPVJaNp/3t2SohLu8J9LO38ciBmy/A3EYNFB9\n\teUrQ==",
        "X-Gm-Message-State": "AOJu0YyWGB/6h5wo2/XjZW2SsQF/NtH/ZOpyYGaGXpJ5dtUHhW4VFiOx\n\t9PxfnPlIjg34Z3b7fXBISDp5alPzIM2ARa3Eq1R3zKNgFhRyxxb85ZB6pP0aksnH8A1U28bymK+\n\tk",
        "X-Google-Smtp-Source": "AGHT+IHPQqBn66fMpCnO4zjtz0GfR/XByTzzXoFTRA+zE20YJi2c9wq2b5TyhJoNRgaHiqNfbbNcXA==",
        "X-Received": "by 2002:a05:600c:190a:b0:431:4e73:a515 with SMTP id\n\t5b1f17b1804b1-4319ac9ad38mr69864535e9.3.1730368364380; \n\tThu, 31 Oct 2024 02:52:44 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Naushir Patuck <naush@raspberrypi.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Subject": "[PATCH v4 4/7] pipeline: rpi: Introduce CameraData::CropParams",
        "Date": "Thu, 31 Oct 2024 09:49:54 +0000",
        "Message-Id": "<20241031094957.18471-5-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": "In preparation for assigning separate crop windows for each stream, add\na new CropParams structure that stores the existing ispCrop_ and\nispMinCropSize_ as fields. Use a new std::map to store a CropParams\nstructure where the map key is the index of the stream configuration in\nthe CameraConfiguration vector.\n\nAt preset, only a single CropParams structure will be set at key == 0 to\npreserve the existing crop handling logic.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n .../pipeline/rpi/common/pipeline_base.cpp     | 28 +++++++++++++------\n .../pipeline/rpi/common/pipeline_base.h       | 17 +++++++++--\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 12 ++++++--\n 3 files changed, 43 insertions(+), 14 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\nindex 2de6111bacfd..220c7b962280 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n@@ -533,6 +533,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \t * Platform specific internal stream configuration. This also assigns\n \t * external streams which get configured below.\n \t */\n+\tdata->cropParams_.clear();\n \tret = data->platformConfigure(rpiConfig);\n \tif (ret)\n \t\treturn ret;\n@@ -561,10 +562,14 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n \tfor (auto const &c : result.controlInfo)\n \t\tctrlMap.emplace(c.first, c.second);\n \n-\t/* Add the ScalerCrop control limits based on the current mode. */\n-\tRectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_));\n-\tctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop,\n-\t\t\t\t\t\t     data->scaleIspCrop(data->ispCrop_));\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\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}\n \n \tdata->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap());\n \n@@ -1291,8 +1296,10 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n void CameraData::applyScalerCrop(const ControlList &controls)\n {\n \tconst auto &scalerCrop = controls.get<Rectangle>(controls::ScalerCrop);\n-\tif (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 \n \t\tif (!nativeCrop.width || !nativeCrop.height)\n \t\t\tnativeCrop = { 0, 0, 1, 1 };\n@@ -1308,12 +1315,12 @@ 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 = ispMinCropSize_.expandedToAspectRatio(nativeCrop.size());\n+\t\tSize minSize = cropParams.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 != ispCrop_) {\n-\t\t\tispCrop_ = ispCrop;\n+\t\tif (ispCrop != cropParams.ispCrop) {\n+\t\t\tcropParams.ispCrop = ispCrop;\n \t\t\tplatformSetIspCrop(ispCrop);\n \t\t}\n \t}\n@@ -1471,7 +1478,10 @@ 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-\trequest->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_));\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 }\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\nindex d65b695c30b5..88bd603193f4 100644\n--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n@@ -133,8 +133,21 @@ public:\n \n \t/* For handling digital zoom. */\n \tIPACameraSensorInfo sensorInfo_;\n-\tRectangle ispCrop_; /* crop in ISP (camera mode) pixels */\n-\tSize ispMinCropSize_;\n+\n+\tstruct CropParams {\n+\t\tCropParams(Rectangle ispCrop_, Size ispMinCropSize_)\n+\t\t\t: ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_)\n+\t\t{\n+\t\t}\n+\n+\t\t/* Crop in ISP (camera mode) pixels */\n+\t\tRectangle ispCrop;\n+\t\t/* Minimum crop size in ISP output pixels */\n+\t\tSize ispMinCropSize;\n+\t};\n+\n+\t/* Mapping of CropParams keyed by the output stream order in CameraConfiguration */\n+\tstd::map<unsigned int, CropParams> cropParams_;\n \n \tunsigned int dropFrameCount_;\n \ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 0ea032293bc9..8080f55a1cf4 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -702,13 +702,19 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi\n \t/* Figure out the smallest selection the ISP will allow. */\n \tRectangle testCrop(0, 0, 1, 1);\n \tisp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop);\n-\tispMinCropSize_ = testCrop.size();\n \n \t/* Adjust aspect ratio by providing crops on the input image. */\n \tSize size = unicamFormat.size.boundedToAspectRatio(maxSize);\n-\tispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center());\n+\tRectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center());\n \n-\tplatformSetIspCrop(ispCrop_);\n+\tplatformSetIspCrop(ispCrop);\n+\t/*\n+\t * Set the scaler crop to the value we are using (scaled to native sensor\n+\t * coordinates).\n+\t */\n+\tcropParams_.emplace(std::piecewise_construct,\n+\t\t\t    std::forward_as_tuple(0),\n+\t\t\t    std::forward_as_tuple(ispCrop, testCrop.size()));\n \n \treturn 0;\n }\n",
    "prefixes": [
        "v4",
        "4/7"
    ]
}