Patch Detail
Show a patch.
GET /api/1.1/patches/16377/?format=api
{ "id": 16377, "url": "https://patchwork.libcamera.org/api/1.1/patches/16377/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16377/", "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": "<20220627122806.29586-2-dse@thaumatec.com>", "date": "2022-06-27T12:28:05", "name": "[libcamera-devel,v3,1/2] cam: Add Rectangle type parsing in capture script", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "4033ca7a0dbbc2a9dd811b21f3ecf356b95148ef", "submitter": { "id": 126, "url": "https://patchwork.libcamera.org/api/1.1/people/126/?format=api", "name": "Daniel Semkowicz", "email": "dse@thaumatec.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16377/mbox/", "series": [ { "id": 3222, "url": "https://patchwork.libcamera.org/api/1.1/series/3222/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3222", "date": "2022-06-27T12:28:04", "name": "cam: Add Rectangle type parsing in capture script", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3222/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16377/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16377/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 366F3BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Jun 2022 12:28:18 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E51CF6563A;\n\tMon, 27 Jun 2022 14:28:17 +0200 (CEST)", "from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 80D6B65635\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Jun 2022 14:28:15 +0200 (CEST)", "by mail-wr1-x436.google.com with SMTP id v14so12831211wra.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Jun 2022 05:28:15 -0700 (PDT)", "from localhost.localdomain (ip092042140082.rev.nessus.at.\n\t[92.42.140.82]) by smtp.gmail.com with ESMTPSA id\n\tm18-20020a05600c4f5200b0039748be12dbsm17836401wmq.47.2022.06.27.05.28.14\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Jun 2022 05:28:14 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656332897;\n\tbh=CQ9RMIxFQUOg3K/BFZMjNATowJhw/L2haohCUgYfEIk=;\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=IvCIlT9Entmw2GI23EQj382j0/TTLXCkdsVyv/KxIIUX1nNVNvuzbUDyjxtvVMkPb\n\t54Zq0saRvf95ZhGx7vKM4lIteyBSzL8QNBP8FZaNSn37szjkvDN/j2xW7CLHGkC21A\n\tZ5tg24o0OyCPgHTRXHKjJBchLOXGQUR3jJTXOPAx1QByDurxqKzzbv+qCraPonxUxJ\n\t5qwci5NAUmdEQSoEmQ4+brJDBfnFbed321g22Rw6YGAFR7MwELJhqSwWDXH3JNsHqR\n\tahwg1OBM+c5d1eXuYravcYEkFI0PYb0lJqxWDmoEShqAtI2ALLmcVALGAwg9SzYb3e\n\tUQn602q02LwvA==", "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=yWDJfTSEdTrKf2vV9jyi8eKOYzdjg03uXZ4gqhzX0Vo=;\n\tb=A1XGr4v00WbvdnMcrPxIQfnz4ik0r1zFbKOfsM39fZGcA7bN+XrgOZj0f1BnR5CE7+\n\tDQPjQSgSlaUg9q2E0zQy/JSJMgqOFyPW6mMNku5FP9hKqS+Bu/GDGc3QrHihmDbiP0DX\n\tLyYn0zT1cpzIXAaqy4pp11o/rCQV7QALgis01EvP5VVMSLOU6boZRqwpcxYGfHqrB6qX\n\tmNtnL60yaXbK85rpIBW64ZSmn7Iz5+H6PhBvqRQx1PAcs0UcoW+Rhs5Ru8Md+PGzTqfu\n\tVhLCByyKdvYMyzhch+FhkB0p8kLWKy6d9nHtS10NIIMAvgria4CkpJDjzwmd/tSwznMp\n\tyyqA==" ], "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=\"A1XGr4v0\"; \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=yWDJfTSEdTrKf2vV9jyi8eKOYzdjg03uXZ4gqhzX0Vo=;\n\tb=U6B6lnYs2dd2enNU+zFD0wrBgRW4KpIP1KYE0vbNfO0ejbleB5VybrYy/5PV4cYihs\n\t35DCznERvABf9NVYrXnxU1fGyg4jmWH5l/sbu31vyRPfYTdHIOk2V3txv1474IdoYrL0\n\ti3J/5XcUywXRTI4FPipy20mibS4c2OZYbU94W5HCdDuqqv+ogTaMVdBkz7/fgNlV9jcW\n\tWYwEOv2HRA0SuJjGwCiQ2gAv63nZz6O3/EK661abzPdF0yY0CWg//TqaSwzzK1RQkWqB\n\tIsr7OVrEDLDZJyGz68nTCc3oCGEGXYS/mr8N+mQI+ZlDWrArLeVGby0uDHLLXemvtqQU\n\tB2Ww==", "X-Gm-Message-State": "AJIora+Cm8962jJSUUlSc3Um0riSG43783q9HFjgQApgt5q5yR1za15T\n\tL/JWK77Z1YmaOBXt7bWXmSCsUja2DIIJkQ==", "X-Google-Smtp-Source": "AGRyM1swN+RQ697VE6ZdjHL7Ad7Ox+q3vEm3V2fmMH15DFnzo97zH/lulgoP4xWb9AtApRcMDvtl/A==", "X-Received": "by 2002:a5d:4c86:0:b0:21b:988f:20cf with SMTP id\n\tz6-20020a5d4c86000000b0021b988f20cfmr12401298wrs.299.1656332895205; \n\tMon, 27 Jun 2022 05:28:15 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 27 Jun 2022 14:28:05 +0200", "Message-Id": "<20220627122806.29586-2-dse@thaumatec.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20220627122806.29586-1-dse@thaumatec.com>", "References": "<20220627122806.29586-1-dse@thaumatec.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 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 | 145 ++++++++++++++++++++++++++++++++++---\n src/cam/capture_script.h | 7 +-\n 2 files changed, 139 insertions(+), 13 deletions(-)", "diff": "diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp\nindex 9f22d5f7..6278a152 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,104 @@ std::string CaptureScript::parseScalar()\n \treturn eventScalarValue(event);\n }\n \n+ControlValue CaptureScript::parseRectangles()\n+{\n+\tstd::vector<libcamera::Rectangle> rectangles;\n+\n+\tstd::vector<std::vector<std::string>> arrays = parseArrays();\n+\tif (arrays.empty())\n+\t\treturn {};\n+\n+\tfor (const std::vector<std::string> &values : arrays) {\n+\t\tif (values.size() != 4) {\n+\t\t\tstd::cerr << \"Error parsing Rectangle: expected \"\n+\t\t\t\t \"array with 4 parameters\" << std::endl;\n+\t\t\treturn {};\n+\t\t}\n+\n+\t\tRectangle rect = unpackRectangle(values);\n+\t\trectangles.push_back(rect);\n+\t}\n+\n+\tControlValue controlValue;\n+\tcontrolValue.set(Span<const Rectangle>(rectangles));\n+\n+\treturn controlValue;\n+}\n+\n+std::vector<std::vector<std::string>> CaptureScript::parseArrays()\n+{\n+\tEventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT);\n+\tif (!event)\n+\t\treturn {};\n+\n+\tevent = nextEvent();\n+\tif (!event)\n+\t\treturn {};\n+\n+\tstd::vector<std::vector<std::string>> valueArrays;\n+\n+\t/* Parse single array. */\n+\tif (event->type == YAML_SCALAR_EVENT) {\n+\t\tstd::string firstValue = eventScalarValue(event);\n+\t\tif (firstValue.empty())\n+\t\t\treturn {};\n+\n+\t\tstd::vector<std::string> remaining = parseSingleArray();\n+\n+\t\tstd::vector<std::string> values = { firstValue };\n+\t\tvalues.insert(std::end(values),\n+\t\t\t std::begin(remaining), std::end(remaining));\n+\t\tvalueArrays.push_back(values);\n+\n+\t\treturn valueArrays;\n+\t}\n+\n+\t/* Parse array of arrays. */\n+\twhile (1) {\n+\t\tswitch (event->type) {\n+\t\tcase YAML_SEQUENCE_START_EVENT: {\n+\t\t\tstd::vector<std::string> values = parseSingleArray();\n+\t\t\tvalueArrays.push_back(values);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase YAML_SEQUENCE_END_EVENT:\n+\t\t\treturn valueArrays;\n+\t\tdefault:\n+\t\t\treturn {};\n+\t\t}\n+\n+\t\tevent = nextEvent();\n+\t\tif (!event)\n+\t\t\treturn {};\n+\t}\n+}\n+\n+std::vector<std::string> CaptureScript::parseSingleArray()\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 +378,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 +440,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..fffe67e5 100644\n--- a/src/cam/capture_script.h\n+++ b/src/cam/capture_script.h\n@@ -54,9 +54,12 @@ private:\n \tint parseControl(EventPtr event, libcamera::ControlList &controls);\n \n \tstd::string parseScalar();\n+\tlibcamera::ControlValue parseRectangles();\n+\tstd::vector<std::vector<std::string>> parseArrays();\n+\tstd::vector<std::string> parseSingleArray();\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", "v3", "1/2" ] }