Show a patch.

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

{
    "id": 16368,
    "url": "https://patchwork.libcamera.org/api/patches/16368/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16368/",
    "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": "<20220624130523.41535-2-dse@thaumatec.com>",
    "date": "2022-06-24T13:05:22",
    "name": "[libcamera-devel,v2,1/2] cam: Add Rectangle type parsing in capture script",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "a29c086c94e334260bacd9778473b2fc535861f2",
    "submitter": {
        "id": 126,
        "url": "https://patchwork.libcamera.org/api/people/126/?format=api",
        "name": "Daniel Semkowicz",
        "email": "dse@thaumatec.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16368/mbox/",
    "series": [
        {
            "id": 3218,
            "url": "https://patchwork.libcamera.org/api/series/3218/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3218",
            "date": "2022-06-24T13:05:21",
            "name": "cam: Add Rectangle type parsing in capture script",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3218/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16368/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16368/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 694A9BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Jun 2022 13:05:34 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1226A65638;\n\tFri, 24 Jun 2022 15:05:34 +0200 (CEST)",
            "from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com\n\t[IPv6:2a00:1450:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B1C47600EC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jun 2022 15:05:31 +0200 (CEST)",
            "by mail-wr1-x42b.google.com with SMTP id o16so3076725wra.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Jun 2022 06:05:31 -0700 (PDT)",
            "from localhost.localdomain (ip092042140082.rev.nessus.at.\n\t[92.42.140.82]) by smtp.gmail.com with ESMTPSA id\n\tm20-20020a05600c4f5400b0039747cf8354sm2889703wmq.39.2022.06.24.06.05.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 24 Jun 2022 06:05:30 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656075934;\n\tbh=mL2GIIl2nI+t0hBRePdSEvhCg7DsQ3bc8M4AvUQ1Csc=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=eatp6eXtjwuYxApJZkvbjV6PbfJq0eV89BdPlow4pJCjL4nK9IkSxGOWl1gnWLrZG\n\twXkq9qGV3wIswWgdZr1LsJiz1D6//mR9WoqB1rBVB6MNhMML/E5bQ9USz2d83rFA7B\n\tDC+Gjh8I15HsJ29qVfwsOkHBCqJ+KvdN3C2UaTLOwv6iY8FLK7Fi45hB2r5gn8EB1I\n\tYoNUI2jTA/iNGZu0bN3uNnarTkIzLh9Ki9+UWvdyTLoxI8XU60YNtpvtGFWNa+WdT9\n\t2tLwVNCsyqiYv4pd83x+UGwrhNjMtoxudP+kDuI0EhVdPwSxSOSojujJkyTVZ/4qgX\n\tHWHnz0uqPnegw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=thaumatec-com.20210112.gappssmtp.com; s=20210112;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=LBLYdcs1v00veNkngHKefOHuUxWmmPL1iLmxWUnpo7c=;\n\tb=BPPoOkFyEMEOk2pQZHw85/XXNJNLwyZnnqFiuraQEKfE4uH9aa8twgXQJm+XDTMtEO\n\tpqZ17yBho05lCvZIT/t5MtwkkaTskrywYuNRoPHyZsV2bV06tMs7d6+YBXlDzRcKDKkT\n\t/f7yoMqCFi0OILkRtmfsWVQlDx+7q8Df1kc+MGBk71XaKWu7WKesaHb/6D1sj3fg3tMj\n\tezzwcfLVpHEGKw2xXOsM5y2vl4VMHdeSqMqj7GrVkgRDxuYbehJ0tuAe0fftFk90Fh8c\n\t6CLWekvYuwjdFoqjNSPikj+Je8rrF3DwDJiFSeQH7e5YGktRCY5Gqd/Uwq+tVvdLQIjD\n\twN+Q=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=thaumatec-com.20210112.gappssmtp.com\n\theader.i=@thaumatec-com.20210112.gappssmtp.com header.b=\"BPPoOkFy\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=LBLYdcs1v00veNkngHKefOHuUxWmmPL1iLmxWUnpo7c=;\n\tb=zqYzpIKxl/LJ9wxu8SL1xYrOpfzYqHjEuRS2yq/RVt4qSH1RrRgvfS4MV8ZcVfeXyr\n\tThBLcRWEAoJLPOCbMFFQ0M7RrGuookylTnt+/y1UGcPOlX16nL/JMMLFdYxKw6BiERW2\n\t0qUEU74R//VZ+WdvZ99iPreLi9GclnsYfCNDw7m4wDFhrFfzBTN1P6orG/Ho/lC5vUtb\n\tNDDW7XctSB63gOQjxuX7s/2FzYy45GQy9jzQYvtc1rhmDi5MZi1B1swZ7o7ZDXqw36iL\n\toA1q9Ygqbwicy5GdQPfqvBArFvrxnrdm2c9vxpOBfXhvWgOOF4ZCu9e03/TxzhBwBuon\n\tsx9A==",
        "X-Gm-Message-State": "AJIora81UoIOluUyA40Y+ZMfc7khG3X8hB1keYrBmZnbYA5q44sH2dNH\n\tNo7SW2yftakhL/IgX8r9UuuijRyLvoSsxacV",
        "X-Google-Smtp-Source": "AGRyM1tFVcn4Td73z2s0MuzT+wzkKDhXhyrvfnNfnbirJQhsqCNrZ65rkE7Iqc+1au10y14glPXKjw==",
        "X-Received": "by 2002:a05:6000:10c5:b0:21b:9aed:47e3 with SMTP id\n\tb5-20020a05600010c500b0021b9aed47e3mr13496370wrx.570.1656075931289; \n\tFri, 24 Jun 2022 06:05:31 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 24 Jun 2022 15:05:22 +0200",
        "Message-Id": "<20220624130523.41535-2-dse@thaumatec.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220624130523.41535-1-dse@thaumatec.com>",
        "References": "<20220624130523.41535-1-dse@thaumatec.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 1/2] cam: Add Rectangle type parsing in\n\tcapture script",
        "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>",
        "From": "Daniel Semkowicz via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Daniel Semkowicz <dse@thaumatec.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "This change is required for AfWindows control from capture script.\nParser expects array of arrays of parameters, so it is possible to\nspecify multiple rectangles.\n\nSigned-off-by: Daniel Semkowicz <dse@thaumatec.com>\n---\n src/cam/capture_script.cpp | 109 +++++++++++++++++++++++++++++++++----\n src/cam/capture_script.h   |   6 +-\n 2 files changed, 102 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp\nindex 9f22d5f7..5812b122 100644\n--- a/src/cam/capture_script.cpp\n+++ b/src/cam/capture_script.cpp\n@@ -232,12 +232,15 @@ int CaptureScript::parseControl(EventPtr event, ControlList &controls)\n \t\treturn -EINVAL;\n \t}\n \n-\tstd::string value = parseScalar();\n-\tif (value.empty())\n+\tconst ControlId *controlId = it->second;\n+\n+\tControlValue val = unpackControl(controlId);\n+\tif (val.isNone()) {\n+\t\tstd::cerr << \"Error unpacking control '\" << name << \"'\"\n+\t\t\t  << std::endl;\n \t\treturn -EINVAL;\n+\t}\n \n-\tconst ControlId *controlId = it->second;\n-\tControlValue val = unpackControl(controlId, value);\n \tcontrols.set(controlId->id(), val);\n \n \treturn 0;\n@@ -252,6 +255,68 @@ std::string CaptureScript::parseScalar()\n \treturn eventScalarValue(event);\n }\n \n+ControlValue CaptureScript::parseRectangles()\n+{\n+\tEventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT);\n+\tif (!event)\n+\t\treturn {};\n+\n+\tstd::vector<libcamera::Rectangle> rectangles;\n+\n+\twhile (1) {\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn {};\n+\n+\t\tswitch (event->type) {\n+\t\tcase YAML_SEQUENCE_START_EVENT: {\n+\t\t\tstd::vector<std::string> values = parseArray();\n+\t\t\tif (values.size() != 4) {\n+\t\t\t\tstd::cerr << \"Error parsing Rectangle: expected \"\n+\t\t\t\t\t     \"array with 4 parameters\" << std::endl;\n+\t\t\t\treturn {};\n+\t\t\t}\n+\n+\t\t\tRectangle rect = unpackRectangle(values);\n+\t\t\trectangles.push_back(rect);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase YAML_SEQUENCE_END_EVENT: {\n+\t\t\tControlValue controlValue;\n+\t\t\tcontrolValue.set(Span<const Rectangle>(rectangles));\n+\t\t\treturn controlValue;\n+\t\t}\n+\t\tdefault:\n+\t\t\treturn {};\n+\t\t}\n+\t}\n+}\n+\n+std::vector<std::string> CaptureScript::parseArray()\n+{\n+\tstd::vector<std::string> values;\n+\n+\twhile (1) {\n+\t\tEventPtr event = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn {};\n+\n+\t\tswitch (event->type) {\n+\t\tcase YAML_SCALAR_EVENT: {\n+\t\t\tstd::string value = eventScalarValue(event);\n+\t\t\tif (value.empty())\n+\t\t\t\treturn {};\n+\t\t\tvalues.push_back(value);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase YAML_SEQUENCE_END_EVENT:\n+\t\t\treturn values;\n+\t\tdefault:\n+\t\t\treturn {};\n+\t\t}\n+\t}\n+}\n+\n void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr)\n {\n \tstatic const std::map<unsigned int, const char *> typeNames = {\n@@ -277,9 +342,24 @@ void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr)\n \t\t  << typeName << \" control \" << id->name() << std::endl;\n }\n \n-ControlValue CaptureScript::unpackControl(const ControlId *id,\n-\t\t\t\t\t  const std::string &repr)\n+ControlValue CaptureScript::unpackControl(const ControlId *id)\n {\n+\t/* Parse complex types */\n+\tswitch (id->type()) {\n+\tcase ControlTypeRectangle:\n+\t\treturn parseRectangles();\n+\tcase ControlTypeSize:\n+\t\t/* \\todo Parse Sizes. */\n+\t\treturn {};\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\t/* Parse basic types represented by a single scalar */\n+\tconst std::string repr = parseScalar();\n+\tif (repr.empty())\n+\t\treturn {};\n+\n \tControlValue value{};\n \n \tswitch (id->type()) {\n@@ -324,13 +404,20 @@ ControlValue CaptureScript::unpackControl(const ControlId *id,\n \t\tvalue.set<std::string>(repr);\n \t\tbreak;\n \t}\n-\tcase ControlTypeRectangle:\n-\t\t/* \\todo Parse rectangles. */\n-\t\tbreak;\n-\tcase ControlTypeSize:\n-\t\t/* \\todo Parse Sizes. */\n+\tdefault:\n+\t\tstd::cerr << \"Unsupported control type\" << std::endl;\n \t\tbreak;\n \t}\n \n \treturn value;\n }\n+\n+libcamera::Rectangle CaptureScript::unpackRectangle(const std::vector<std::string> &strVec)\n+{\n+\tint x = strtol(strVec[0].c_str(), NULL, 10);\n+\tint y = strtol(strVec[1].c_str(), NULL, 10);\n+\tunsigned int width = strtoul(strVec[2].c_str(), NULL, 10);\n+\tunsigned int height = strtoul(strVec[3].c_str(), NULL, 10);\n+\n+\treturn Rectangle(x, y, width, height);\n+}\ndiff --git a/src/cam/capture_script.h b/src/cam/capture_script.h\nindex 8b4f8f62..130872b4 100644\n--- a/src/cam/capture_script.h\n+++ b/src/cam/capture_script.h\n@@ -54,9 +54,11 @@ private:\n \tint parseControl(EventPtr event, libcamera::ControlList &controls);\n \n \tstd::string parseScalar();\n+\tlibcamera::ControlValue parseRectangles();\n+\tstd::vector<std::string> parseArray();\n \n \tvoid unpackFailure(const libcamera::ControlId *id,\n \t\t\t   const std::string &repr);\n-\tlibcamera::ControlValue unpackControl(const libcamera::ControlId *id,\n-\t\t\t\t\t      const std::string &repr);\n+\tlibcamera::ControlValue unpackControl(const libcamera::ControlId *id);\n+\tlibcamera::Rectangle unpackRectangle(const std::vector<std::string> &strVec);\n };\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "1/2"
    ]
}