Show a patch.

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

{
    "id": 16331,
    "url": "https://patchwork.libcamera.org/api/patches/16331/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16331/",
    "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": "<20220622160226.42220-2-dse@thaumatec.com>",
    "date": "2022-06-22T16:02:26",
    "name": "[libcamera-devel,1/1] cam: Add Rectangle type parsing in capture script",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "dc5460ee05452f1b0e2f9fc1196ccfd82dbc4aee",
    "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/16331/mbox/",
    "series": [
        {
            "id": 3209,
            "url": "https://patchwork.libcamera.org/api/series/3209/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3209",
            "date": "2022-06-22T16:02:25",
            "name": "cam: Add Rectangle type parsing in capture script",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3209/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16331/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16331/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 8C712BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Jun 2022 16:02:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E38565638;\n\tWed, 22 Jun 2022 18:02:36 +0200 (CEST)",
            "from mail-ej1-x631.google.com (mail-ej1-x631.google.com\n\t[IPv6:2a00:1450:4864:20::631])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 68A6A633A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 18:02:34 +0200 (CEST)",
            "by mail-ej1-x631.google.com with SMTP id pk21so12129986ejb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Jun 2022 09:02:34 -0700 (PDT)",
            "from localhost.localdomain (ip092042140082.rev.nessus.at.\n\t[92.42.140.82]) by smtp.gmail.com with ESMTPSA id\n\tq3-20020a056402248300b004356894a3f8sm11651350eda.89.2022.06.22.09.02.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 22 Jun 2022 09:02:33 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655913756;\n\tbh=umbAvJ+mJc/5H63Q0fkoDq0s/JH1kYGUFdCBefPsgOo=;\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=HE3f1cbnHKJ0XTtLerM/kNUo0zT4RVEuvUfcEDQrAjqZVxQJnRso1XrLL15skagMx\n\tqWbaW94R9i4ar8KBwcCJSnTh4K8PxRub3cGHyGM7MUnIxxJUK+pFHsRs5yagmeyTVb\n\toh7hercfbD5wnNxb4bJDC7uuoTTJN/EpjvcQ1cmNOWPJ2soqA086988362bomi+JLV\n\trfzuJJY1NiOJVGaxxR2SmHexQ02mPo/C8dZ5wgeyGoIsWN130jrYBBba8f6QzYEvWT\n\t3X0u71S+cArcw5YO+X9LBEXG1U9ELwctYpElS952NP0LBYxKxDPHYBZpvF3w3w07kX\n\t1QeG2Qo+BKSzg==",
            "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=cDMo3oLicSQlHOs00dO80PeMozGfIbpUlXHfTDJEJfc=;\n\tb=I3cQ0yEa7cw/KM7v960nLS+cOXzJPbSIu/Q50kdasRTBM1G9Rsnc3f6nlz+knbkdKX\n\tR5MlczhAkCAPg3XL72pSVzC/1Cic4267GBwXGqls+ubEtC9gBM0uZMFYLIi9XlMNakCJ\n\tBE8JmsqILlIKEopNxw1gF1TqMEUQNREZ8t5H8DTY0SrbjkdFH6A8f9IzTOsS0MSCnn+s\n\tZ9RAdPN9QIoBmlK3bdm9MDfRXVt3JorwmG1TnhO+G//IKlNsVrchV+drRBO++/ofEWo3\n\tC6Z8Em1q/2uQ8LUtki8FqHFiIyleteVS8T3Cs/VZAwa7X9Q33TtKmjd+36RWccLetgjz\n\tm5LA=="
        ],
        "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=\"I3cQ0yEa\"; \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=cDMo3oLicSQlHOs00dO80PeMozGfIbpUlXHfTDJEJfc=;\n\tb=T+D4/th9UBMP886qQAKcYL4kSCiXyyaimdVVMgItRVQX2ohxfzA2SMj3naYpHnnqXg\n\t6WLCuyUGXzrS4xI3gUNem19AQ0Wskv5Z9xXvZ4FflbNhdxwlIsexfbtw9csKh977DltB\n\tpbrBnyVxR+JUzjKA7bdBIj9gca59OcSs3pr1AtBqiKKLXivFQLxnam8Jqk6MhASk3HUe\n\tR3hIodkFfxzXMzvjF+TBU6Utb+dqxpON+pBLT65vvNgoGLqoDYLKL/NilSki/gZP8hdL\n\tYwZpGfRcYV2IGFs2SJpmKtYFGClAFDFiqjhQ6YOsx1EZ3+scYK1b1oxvaSDeMyK8LS/H\n\t9mYA==",
        "X-Gm-Message-State": "AJIora+AwmOhtLJBk8QleUUpPAil2GoMiKb43C63wOVySxBx+16FOpF8\n\tbkjc+/BAe42AjSqXOctcioqumIVj4sZBsA==",
        "X-Google-Smtp-Source": "AGRyM1t2QRy85RI28eo4JGqMitFT+NE+dxeF9fxq9U9NLn1NVqChe0W5IEbdcCs8TGtWeUtSRzMPqA==",
        "X-Received": "by 2002:a17:907:2d86:b0:711:da8b:b579 with SMTP id\n\tgt6-20020a1709072d8600b00711da8bb579mr3901203ejc.67.1655913753659; \n\tWed, 22 Jun 2022 09:02:33 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 22 Jun 2022 18:02:26 +0200",
        "Message-Id": "<20220622160226.42220-2-dse@thaumatec.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220622160226.42220-1-dse@thaumatec.com>",
        "References": "<20220622160226.42220-1-dse@thaumatec.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 1/1] 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---\n src/cam/capture_script.cpp | 104 +++++++++++++++++++++++++++++++++----\n src/cam/capture_script.h   |   9 +++-\n 2 files changed, 102 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp\nindex 9f22d5f7..ff620abd 100644\n--- a/src/cam/capture_script.cpp\n+++ b/src/cam/capture_script.cpp\n@@ -232,12 +232,19 @@ int CaptureScript::parseControl(EventPtr event, ControlList &controls)\n \t\treturn -EINVAL;\n \t}\n \n-\tstd::string value = parseScalar();\n-\tif (value.empty())\n-\t\treturn -EINVAL;\n-\n \tconst ControlId *controlId = it->second;\n-\tControlValue val = unpackControl(controlId, value);\n+\tControlValue val;\n+\n+\tif (controlId->type() == ControlTypeRectangle) {\n+\t\tint result = parseRectangles(val);\n+\t\tif (result)\n+\t\t\treturn result;\n+\t} else {\n+\t\tint result = parseBasicType(controlId, val);\n+\t\tif (result)\n+\t\t\treturn result;\n+\t}\n+\n \tcontrols.set(controlId->id(), val);\n \n \treturn 0;\n@@ -252,6 +259,77 @@ std::string CaptureScript::parseScalar()\n \treturn eventScalarValue(event);\n }\n \n+int CaptureScript::parseBasicType(const ControlId *id, ControlValue &controlValue)\n+{\n+\tstd::string value = parseScalar();\n+\tif (value.empty())\n+\t\treturn -EINVAL;\n+\n+\tcontrolValue = unpackBasicType(id, value);\n+\n+\treturn 0;\n+}\n+\n+int CaptureScript::parseRectangles(libcamera::ControlValue &controlValue)\n+{\n+\tstd::vector<libcamera::Rectangle> rectangles;\n+\n+\tEventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT);\n+\tif (!event)\n+\t\treturn -EINVAL;\n+\n+\twhile (1) {\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn -EINVAL;\n+\n+\t\tif (event->type == YAML_SEQUENCE_END_EVENT) {\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (event->type != YAML_SEQUENCE_START_EVENT) {\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tstd::vector<std::string> values = parseArray();\n+\t\tif (values.size() != 4) {\n+\t\t\tstd::cerr << \"Error parsing Rectangle: \"\n+\t\t\t\t  << \"expected array with 4 parameters\"\n+\t\t\t\t  << std::endl;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tRectangle rect = unpackRectangle(values);\n+\t\trectangles.push_back(rect);\n+\t}\n+\n+\tcontrolValue.set(Span<const Rectangle>(rectangles));\n+\n+\treturn 0;\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\tbreak;\n+\n+\t\tif (event->type != YAML_SCALAR_EVENT) {\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tstd::string value = eventScalarValue(event);\n+\t\tvalues.push_back(value);\n+\t\tif (value.empty())\n+\t\t\tbreak;\n+\t}\n+\n+\treturn values;\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,7 +355,7 @@ 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+ControlValue CaptureScript::unpackBasicType(const ControlId *id,\n \t\t\t\t\t  const std::string &repr)\n {\n \tControlValue value{};\n@@ -325,12 +403,20 @@ ControlValue CaptureScript::unpackControl(const ControlId *id,\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+\t\tunpackFailure(id, repr);\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..73b7e101 100644\n--- a/src/cam/capture_script.h\n+++ b/src/cam/capture_script.h\n@@ -52,11 +52,16 @@ private:\n \tint parseFrames();\n \tint parseFrame(EventPtr event);\n \tint parseControl(EventPtr event, libcamera::ControlList &controls);\n+\tint parseBasicType(const libcamera::ControlId *id,\n+\t\t\t   libcamera::ControlValue &controlValue);\n+\tint parseRectangles(libcamera::ControlValue &controlValue);\n \n \tstd::string parseScalar();\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 unpackBasicType(const libcamera::ControlId *id,\n+\t\t\t\t\t\tconst std::string &repr);\n+\tlibcamera::Rectangle unpackRectangle(const std::vector<std::string> &strVec);\n };\n",
    "prefixes": [
        "libcamera-devel",
        "1/1"
    ]
}