Show a patch.

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

{
    "id": 22353,
    "url": "https://patchwork.libcamera.org/api/patches/22353/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22353/",
    "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": "<20241216154124.203650-8-stefan.klug@ideasonboard.com>",
    "date": "2024-12-16T15:40:47",
    "name": "[v4,07/20] libcamera: converter_v4l2_m2m: Refactor get crop bounds code",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "f92892b324019c6b40d1679588b78cef7cd1eb62",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22353/mbox/",
    "series": [
        {
            "id": 4896,
            "url": "https://patchwork.libcamera.org/api/series/4896/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4896",
            "date": "2024-12-16T15:40:40",
            "name": "rkisp1: Fix aspect ratio and ScalerCrop",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/4896/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22353/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22353/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 5978AC32F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 15:42:10 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ED34567F84;\n\tMon, 16 Dec 2024 16:42:09 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DF3D67F82\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 16:42:06 +0100 (CET)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:bfdf:3a3c:e45:66e3])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 01C5C675;\n\tMon, 16 Dec 2024 16:41:29 +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=\"VIzl1Cog\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734363690;\n\tbh=Qp9v4uVEmgzrgQ1G3JWjCc4L7NADhMw2eBuHSQWMJXI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VIzl1Coga1ngd31S6wtezGFUwVvWj628kAcNacjyPT0riX80NXngDuPx870LH/S1q\n\tIpq7+ZeDeLwBNDgE5hsSt0ruA1d0R1h9prc67D+WrQoklmAJKSHlrtLQ3oluRZ7KZ/\n\tqG3AnScI3ImumQLM44UMJDecYaUobPhyXcTLfqqQ=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v4 07/20] libcamera: converter_v4l2_m2m: Refactor get crop\n\tbounds code",
        "Date": "Mon, 16 Dec 2024 16:40:47 +0100",
        "Message-ID": "<20241216154124.203650-8-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241216154124.203650-1-stefan.klug@ideasonboard.com>",
        "References": "<20241216154124.203650-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": "In an upcoming patch it is necessary to get the crop bounds on the\nconverter itself. The V4L2M2MConverter contains code that is very\nsimilar to the get crop bounds code in the V4L2M2MStream. Merge these\ncode blocks into a static function to be used from both classes.  This\npatch contains no functional changes.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v4:\n- Split patch from libcamera: converter_v4l2_m2m: Improve crop bounds\n  support\n---\n .../converter/converter_v4l2_m2m.cpp          | 106 +++++++++---------\n 1 file changed, 52 insertions(+), 54 deletions(-)",
    "diff": "diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp\nindex d63ef2f8028f..8c341fe199f6 100644\n--- a/src/libcamera/converter/converter_v4l2_m2m.cpp\n+++ b/src/libcamera/converter/converter_v4l2_m2m.cpp\n@@ -30,6 +30,52 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(Converter)\n \n+namespace {\n+\n+int getCropBounds(V4L2VideoDevice *device, Rectangle &minCrop,\n+\t\t  Rectangle &maxCrop)\n+{\n+\tRectangle minC;\n+\tRectangle maxC;\n+\n+\t/* Find crop bounds */\n+\tminC.width = 1;\n+\tminC.height = 1;\n+\tmaxC.width = UINT_MAX;\n+\tmaxC.height = UINT_MAX;\n+\n+\tint ret = device->setSelection(V4L2_SEL_TGT_CROP, &minC);\n+\tif (ret) {\n+\t\tLOG(Converter, Error)\n+\t\t\t<< \"Could not query minimum selection crop: \"\n+\t\t\t<< strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tret = device->getSelection(V4L2_SEL_TGT_CROP_BOUNDS, &maxC);\n+\tif (ret) {\n+\t\tLOG(Converter, Error)\n+\t\t\t<< \"Could not query maximum selection crop: \"\n+\t\t\t<< strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\t/* Reset the crop to its maximum */\n+\tret = device->setSelection(V4L2_SEL_TGT_CROP, &maxC);\n+\tif (ret) {\n+\t\tLOG(Converter, Error)\n+\t\t\t<< \"Could not reset selection crop: \"\n+\t\t\t<< strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tminCrop = minC;\n+\tmaxCrop = maxC;\n+\treturn 0;\n+}\n+\n+} /* namespace */\n+\n /* -----------------------------------------------------------------------------\n  * V4L2M2MConverter::V4L2M2MStream\n  */\n@@ -98,41 +144,10 @@ int V4L2M2MConverter::V4L2M2MStream::configure(const StreamConfiguration &inputC\n \toutputBufferCount_ = outputCfg.bufferCount;\n \n \tif (converter_->features() & Feature::InputCrop) {\n-\t\tRectangle minCrop;\n-\t\tRectangle maxCrop;\n-\n-\t\t/* Find crop bounds */\n-\t\tminCrop.width = 1;\n-\t\tminCrop.height = 1;\n-\t\tmaxCrop.width = UINT_MAX;\n-\t\tmaxCrop.height = UINT_MAX;\n-\n-\t\tret = setInputSelection(V4L2_SEL_TGT_CROP, &minCrop);\n-\t\tif (ret) {\n-\t\t\tLOG(Converter, Error)\n-\t\t\t\t<< \"Could not query minimum selection crop: \"\n-\t\t\t\t<< strerror(-ret);\n-\t\t\treturn ret;\n-\t\t}\n-\n-\t\tret = getInputSelection(V4L2_SEL_TGT_CROP_BOUNDS, &maxCrop);\n-\t\tif (ret) {\n-\t\t\tLOG(Converter, Error)\n-\t\t\t\t<< \"Could not query maximum selection crop: \"\n-\t\t\t\t<< strerror(-ret);\n+\t\tret = getCropBounds(m2m_->output(), inputCropBounds_.first,\n+\t\t\t\t    inputCropBounds_.second);\n+\t\tif (ret)\n \t\t\treturn ret;\n-\t\t}\n-\n-\t\t/* Reset the crop to its maximum */\n-\t\tret = setInputSelection(V4L2_SEL_TGT_CROP, &maxCrop);\n-\t\tif (ret) {\n-\t\t\tLOG(Converter, Error)\n-\t\t\t\t<< \"Could not reset selection crop: \"\n-\t\t\t\t<< strerror(-ret);\n-\t\t\treturn ret;\n-\t\t}\n-\n-\t\tinputCropBounds_ = { minCrop, maxCrop };\n \t}\n \n \treturn 0;\n@@ -258,27 +273,10 @@ V4L2M2MConverter::V4L2M2MConverter(MediaDevice *media)\n \t\treturn;\n \t}\n \n-\t/* Discover Feature::InputCrop */\n+\tRectangle minCrop;\n \tRectangle maxCrop;\n-\tmaxCrop.width = UINT_MAX;\n-\tmaxCrop.height = UINT_MAX;\n-\n-\tret = m2m_->output()->setSelection(V4L2_SEL_TGT_CROP, &maxCrop);\n-\tif (ret)\n-\t\treturn;\n-\n-\t/*\n-\t * Rectangles for cropping targets are defined even if the device\n-\t * does not support cropping. Their sizes and positions will be\n-\t * fixed in such cases.\n-\t *\n-\t * Set and inspect a crop equivalent to half of the maximum crop\n-\t * returned earlier. Use this to determine whether the crop on\n-\t * input is really supported.\n-\t */\n-\tRectangle halfCrop(maxCrop.size() / 2);\n-\tret = m2m_->output()->setSelection(V4L2_SEL_TGT_CROP, &halfCrop);\n-\tif (!ret && halfCrop != maxCrop) {\n+\tret = getCropBounds(m2m_->output(), minCrop, maxCrop);\n+\tif (!ret && minCrop != maxCrop) {\n \t\tfeatures_ |= Feature::InputCrop;\n \n \t\tLOG(Converter, Info)\n",
    "prefixes": [
        "v4",
        "07/20"
    ]
}