Show a patch.

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

{
    "id": 22028,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/22028/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22028/",
    "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": "<20241120085753.1993436-7-stefan.klug@ideasonboard.com>",
    "date": "2024-11-20T08:57:45",
    "name": "[6/7] pipeline: rkisp1: Fix ScalerCrop to be in sensor coordinates",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "eca69bfec0a430d581cba43cbe52c79e6b067215",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22028/mbox/",
    "series": [
        {
            "id": 4807,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4807/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4807",
            "date": "2024-11-20T08:57:39",
            "name": "rkisp1: Fix aspect ratio and ScalerCrop",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4807/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22028/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22028/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 9F73AC330C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Nov 2024 08:58:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1FD3B65F4B;\n\tWed, 20 Nov 2024 09:58:20 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B9D1665F40\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Nov 2024 09:58:14 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:bbd:82cc:f3f3:e12e])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C494A75A;\n\tWed, 20 Nov 2024 09:57:56 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"R0FvuOse\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1732093076;\n\tbh=xPhnwj2ouJPX8A8sMaZGYgdC+NbcDE6V0SSmFlfMdeo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=R0FvuOseKNmcghl6yCcH4nu977/LNYn3L/F4/menvIvkrlM2jvf+oUJvvLk06OBUw\n\tjXMEXreaJj1eR1MkiSJYChy2ueT8F8gw6F6WpNylgFz1GeA4gI6Y8PL75M0CHvk+oR\n\t82Y1ljOcNdgzN2p8MFIzThvrjFpJdEro/Tirzr6c=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH 6/7] pipeline: rkisp1: Fix ScalerCrop to be in sensor\n\tcoordinates",
        "Date": "Wed, 20 Nov 2024 09:57:45 +0100",
        "Message-ID": "<20241120085753.1993436-7-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241120085753.1993436-1-stefan.klug@ideasonboard.com>",
        "References": "<20241120085753.1993436-1-stefan.klug@ideasonboard.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": "ScalerCrop is specified as beeing in sensor coordinates. The current\ndewarper implementation on the imx8mp handles ScalerCrop in dewarper\ncoordinates. This leads to unexpected results and a unusable ScalerCrop\ncontrol in camshark. Fix that by transforming back and forth between\nsensor coordinates and dewarper coordinates.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 49 +++++++++++++++++++-----\n 1 file changed, 40 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 4a226d9b809f..c2ce38b1c253 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -204,6 +204,7 @@ private:\n \tRkISP1SelfPath selfPath_;\n \n \tstd::unique_ptr<V4L2M2MConverter> dewarper_;\n+\tRectangle dewarperSensorCrop_;\n \tbool useDewarper_;\n \n \tstd::optional<Rectangle> activeCrop_;\n@@ -862,6 +863,14 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \t\t\t\toutputCfgs.push_back(const_cast<StreamConfiguration &>(cfg));\n \t\t\t\tret = dewarper_->configure(cfg, outputCfgs);\n \t\t\t\tuseDewarper_ = ret ? false : true;\n+\n+\t\t\t\t/*\n+\t\t\t\t * Calculate the crop rectangle of the data\n+\t\t\t\t * flowing into the dewarper in sensor\n+\t\t\t\t * coordinates.\n+\t\t\t\t */\n+\t\t\t\tdewarperSensorCrop_ = outputCrop.mappedBetween(inputCrop,\n+\t\t\t\t\t\t\t\t\t       ipaConfig.sensorInfo.analogCrop);\n \t\t\t}\n \t\t} else if (hasSelfPath_) {\n \t\t\tret = selfPath_.configure(cfg, format);\n@@ -1224,10 +1233,21 @@ int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)\n \t\tstd::pair<Rectangle, Rectangle> cropLimits =\n \t\t\tdewarper_->inputCropBounds(&data->mainPathStream_);\n \n-\t\tcontrols[&controls::ScalerCrop] = ControlInfo(cropLimits.first,\n-\t\t\t\t\t\t\t      cropLimits.second,\n-\t\t\t\t\t\t\t      cropLimits.second);\n-\t\tactiveCrop_ = cropLimits.second;\n+\t\t/*\n+\t\t * ScalerCrop is specified to be in Sensor coordinates.\n+\t\t * So we need to transform the limits to sensor coordinates.\n+\t\t * We can safely assume that the maximum crop limit contains the\n+\t\t * full fov of the dewarper.\n+\t\t */\n+\t\tRectangle min = cropLimits.first.mappedBetween(cropLimits.second,\n+\t\t\t\t\t\t\t       dewarperSensorCrop_);\n+\t\tRectangle max = cropLimits.second.mappedBetween(cropLimits.second,\n+\t\t\t\t\t\t\t\tdewarperSensorCrop_);\n+\n+\t\tcontrols[&controls::ScalerCrop] = ControlInfo(min,\n+\t\t\t\t\t\t\t      max,\n+\t\t\t\t\t\t\t      max);\n+\t\tactiveCrop_ = max;\n \t}\n \n \t/* Add the IPA registered controls to list of camera controls. */\n@@ -1478,22 +1498,33 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)\n \t/* Handle scaler crop control. */\n \tconst auto &crop = request->controls().get(controls::ScalerCrop);\n \tif (crop) {\n-\t\tRectangle appliedRect = crop.value();\n+\t\tRectangle rect = crop.value();\n+\n+\t\t/*\n+\t\t * ScalerCrop is specified to be in Sensor coordinates.\n+\t\t * So we need to transform it into dewarper coordinates.\n+\t\t * We can safely assume that the maximum crop limit contains the\n+\t\t * full fov of the dewarper.\n+\t\t */\n+\t\tstd::pair<Rectangle, Rectangle> cropLimits =\n+\t\t\tdewarper_->inputCropBounds(&data->mainPathStream_);\n \n+\t\trect = rect.mappedBetween(dewarperSensorCrop_, cropLimits.second);\n \t\tint ret = dewarper_->setInputCrop(&data->mainPathStream_,\n-\t\t\t\t\t\t  &appliedRect);\n-\t\tif (!ret && appliedRect != crop.value()) {\n+\t\t\t\t\t\t  &rect);\n+\t\trect = rect.mappedBetween(cropLimits.second, dewarperSensorCrop_);\n+\t\tif (!ret && rect != crop.value()) {\n \t\t\t/*\n \t\t\t * If the rectangle is changed by setInputCrop on the\n \t\t\t * dewarper, log a debug message and cache the actual\n \t\t\t * applied rectangle for metadata reporting.\n \t\t\t */\n \t\t\tLOG(RkISP1, Debug)\n-\t\t\t\t<< \"Applied rectangle \" << appliedRect.toString()\n+\t\t\t\t<< \"Applied rectangle \" << rect.toString()\n \t\t\t\t<< \" differs from requested \" << crop.value().toString();\n \t\t}\n \n-\t\tactiveCrop_ = appliedRect;\n+\t\tactiveCrop_ = rect;\n \t}\n \n \t/*\n",
    "prefixes": [
        "6/7"
    ]
}