Show a patch.

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

{
    "id": 20304,
    "url": "https://patchwork.libcamera.org/api/patches/20304/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20304/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240613155949.1041061-4-dan.scally@ideasonboard.com>",
    "date": "2024-06-13T15:59:45",
    "name": "[3/7] mali-c55: implement support for ScalerCrop",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4195cc81e3cecf038914f8da17a4dde9cf393d9c",
    "submitter": {
        "id": 156,
        "url": "https://patchwork.libcamera.org/api/people/156/?format=api",
        "name": "Dan Scally",
        "email": "dan.scally@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20304/mbox/",
    "series": [
        {
            "id": 4391,
            "url": "https://patchwork.libcamera.org/api/series/4391/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4391",
            "date": "2024-06-13T15:59:42",
            "name": "Miscellaneous Mali-C55 Pipeline Fixes",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4391/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20304/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20304/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 D9E06C3293\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Jun 2024 16:00:09 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43C496548B;\n\tThu, 13 Jun 2024 18:00:05 +0200 (CEST)",
            "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 CBE3C6548F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 17:59:58 +0200 (CEST)",
            "from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B12E6743;\n\tThu, 13 Jun 2024 17:59:44 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bxym8vJF\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718294384;\n\tbh=1iWYFCieWPMNPFcy1olANHrGgtPY6vZsacZpalExAm4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=bxym8vJFiBoRIueKYMRaZNqbvYyqrAIiCHRAwI/9z8gzROPtm5W70whbI6X1BFIOv\n\tYZ8u6G8g6e2ZXiEYw7rsMZku8uU6WwAfD9xeo7hFsY4v5KgFE9eJ7ftv011GajJNb4\n\t3k/9qp//YhSHciB5aT1pZ3x2QE6HC0moM0IzxSsE=",
        "From": "Daniel Scally <dan.scally@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>",
        "Subject": "[PATCH 3/7] mali-c55: implement support for ScalerCrop",
        "Date": "Thu, 13 Jun 2024 16:59:45 +0100",
        "Message-Id": "<20240613155949.1041061-4-dan.scally@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20240613155949.1041061-1-dan.scally@ideasonboard.com>",
        "References": "<20240613155949.1041061-1-dan.scally@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": "From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nImplement support for the ScalerCrop control that allows to apply a\ndigital zoom to the captured streams.\n\nInitialize the camera controls at camera registration time and update\nthem at configure time as the sensor's analogue crop size might change\ndepending on the desired Camera configuration.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/libcamera/pipeline/mali-c55/mali-c55.cpp | 138 ++++++++++++++++++-\n 1 file changed, 137 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\nindex c4f1afbc..2c34f3e9 100644\n--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp\n@@ -100,6 +100,8 @@ public:\n \n \tPixelFormat bestRawFormat() const;\n \n+\tvoid updateControls();\n+\n \tPixelFormat adjustRawFormat(const PixelFormat &pixFmt) const;\n \tSize adjustRawSizes(const PixelFormat &pixFmt, const Size &rawSize) const;\n \n@@ -245,6 +247,27 @@ PixelFormat MaliC55CameraData::bestRawFormat() const\n \treturn rawFormat;\n }\n \n+void MaliC55CameraData::updateControls()\n+{\n+\tif (!sensor_)\n+\t\treturn;\n+\n+\tIPACameraSensorInfo sensorInfo;\n+\tint ret = sensor_->sensorInfo(&sensorInfo);\n+\tif (ret) {\n+\t\tLOG(MaliC55, Error) << \"Failed to retrieve sensor info\";\n+\t\treturn;\n+\t}\n+\n+\tControlInfoMap::Map controls;\n+\tRectangle ispMinCrop{ 0, 0, 640, 480 };\n+\tcontrols[&controls::ScalerCrop] =\n+\t\tControlInfo(ispMinCrop, sensorInfo.analogCrop,\n+\t\t\t    sensorInfo.analogCrop);\n+\n+\tcontrolInfo_ = ControlInfoMap(std::move(controls), controls::controls);\n+}\n+\n /*\n  * Make sure the provided raw pixel format is supported and adjust it to\n  * one of the supported ones if it's not.\n@@ -515,6 +538,8 @@ private:\n \t\t\t\t     const StreamConfiguration &config,\n \t\t\t\t     V4L2SubdeviceFormat &subdevFormat);\n \n+\tvoid applyScalerCrop(Camera *camera, const ControlList &controls);\n+\n \tvoid registerMaliCamera(std::unique_ptr<MaliC55CameraData> data,\n \t\t\t\tconst std::string &name);\n \tbool registerTPGCamera(MediaLink *link);\n@@ -828,6 +853,8 @@ int PipelineHandlerMaliC55::configure(Camera *camera,\n \t\tpipe->stream = stream;\n \t}\n \n+\tdata->updateControls();\n+\n \treturn 0;\n }\n \n@@ -875,6 +902,104 @@ void PipelineHandlerMaliC55::stopDevice([[maybe_unused]] Camera *camera)\n \t}\n }\n \n+void PipelineHandlerMaliC55::applyScalerCrop(Camera *camera,\n+\t\t\t\t\t     const ControlList &controls)\n+{\n+\tMaliC55CameraData *data = cameraData(camera);\n+\n+\tconst auto &scalerCrop = controls.get<Rectangle>(controls::ScalerCrop);\n+\tif (!scalerCrop)\n+\t\treturn;\n+\n+\tif (!data->sensor_) {\n+\t\tLOG(MaliC55, Error) << \"ScalerCrop not supported for TPG\";\n+\t\treturn;\n+\t}\n+\n+\tRectangle nativeCrop = *scalerCrop;\n+\n+\tIPACameraSensorInfo sensorInfo;\n+\tint ret = data->sensor_->sensorInfo(&sensorInfo);\n+\tif (ret) {\n+\t\tLOG(MaliC55, Error) << \"Failed to retrieve sensor info\";\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * The ScalerCrop rectangle re-scaling in the ISP crop rectangle\n+\t * comes straight from the RPi pipeline handler.\n+\t *\n+\t * Create a version of the crop rectangle aligned to the analogue crop\n+\t * rectangle top-left coordinates and scaled in the [analogue crop to\n+\t * output frame] ratio to take into account binning/skipping on the\n+\t * sensor.\n+\t */\n+\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo.analogCrop\n+\t\t\t\t\t\t\t       .topLeft());\n+\tispCrop.scaleBy(sensorInfo.outputSize, sensorInfo.analogCrop.size());\n+\n+\t/*\n+\t * The crop rectangle should be:\n+\t * 1. At least as big as ispMinCropSize_, once that's been\n+\t *    enlarged to the same aspect ratio.\n+\t * 2. With the same mid-point, if possible.\n+\t * 3. But it can't go outside the sensor area.\n+\t */\n+\tRectangle ispMinCrop{ 0, 0, 640, 480 };\n+\tSize minSize = ispMinCrop.size().expandedToAspectRatio(nativeCrop.size());\n+\tSize size = ispCrop.size().expandedTo(minSize);\n+\tispCrop = size.centeredTo(ispCrop.center())\n+\t\t      .enclosedIn(Rectangle(sensorInfo.outputSize));\n+\n+\t/*\n+\t * As the resizer can't upscale, the crop rectangle has to be larger\n+\t * than the larger stream output size.\n+\t */\n+\tSize maxYuvSize;\n+\tfor (MaliC55Pipe &pipe : pipes_) {\n+\n+\t\tif (!pipe.stream)\n+\t\t\tcontinue;\n+\n+\t\tconst StreamConfiguration &config = pipe.stream->configuration();\n+\t\tif (isFormatRaw(config.pixelFormat)) {\n+\t\t\tLOG(MaliC55, Debug) << \"Cannot crop with a RAW stream\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tSize streamSize = config.size;\n+\t\tif (streamSize.width > maxYuvSize.width)\n+\t\t\tmaxYuvSize.width = streamSize.width;\n+\t\tif (streamSize.height > maxYuvSize.height)\n+\t\t\tmaxYuvSize.height = streamSize.height;\n+\t}\n+\n+\tispCrop.size().expandTo(maxYuvSize);\n+\n+\t/*\n+\t * Now apply the scaler crop to each enabled output. This overrides the\n+\t * crop configuration performed at configure() time and can cause\n+\t * square pixels if the crop rectangle and scaler output FOV ratio are\n+\t * different.\n+\t */\n+\tfor (MaliC55Pipe &pipe : pipes_) {\n+\n+\t\tif (!pipe.stream)\n+\t\t\tcontinue;\n+\n+\t\t/* Create a copy to avoid setSelection() to modify ispCrop. */\n+\t\tRectangle pipeCrop = ispCrop;\n+\t\tret = pipe.resizer->setSelection(0, V4L2_SEL_TGT_CROP, &pipeCrop);\n+\t\tif (ret) {\n+\t\t\tLOG(MaliC55, Error)\n+\t\t\t\t<< \"Failed to apply crop to \"\n+\t\t\t\t<< (pipe.stream == &data->frStream_ ?\n+\t\t\t\t    \"FR\" : \"DS\") << \" pipe\";\n+\t\t\treturn;\n+\t\t}\n+\t}\n+}\n+\n int PipelineHandlerMaliC55::queueRequestDevice(Camera *camera, Request *request)\n {\n \tint ret;\n@@ -887,6 +1012,15 @@ int PipelineHandlerMaliC55::queueRequestDevice(Camera *camera, Request *request)\n \t\t\treturn ret;\n \t}\n \n+\t/*\n+\t * Some controls need to be applied immediately, as in example,\n+\t * the ScalerCrop one.\n+\t *\n+\t * \\todo Move it buffer queue time (likely after the IPA has filled in\n+\t * the parameters buffer) once we have plumbed the IPA loop in.\n+\t */\n+\tapplyScalerCrop(camera, request->controls());\n+\n \treturn 0;\n }\n \n@@ -965,7 +1099,9 @@ bool PipelineHandlerMaliC55::registerSensorCamera(MediaLink *ispLink)\n \t\tif (data->init())\n \t\t\treturn false;\n \n-\t\t/* \\todo: Init properties and controls. */\n+\t\t/* \\todo: Init properties. */\n+\n+\t\tdata->updateControls();\n \n \t\tregisterMaliCamera(std::move(data), sensor->name());\n \t}\n",
    "prefixes": [
        "3/7"
    ]
}