From patchwork Wed Jun 22 16:02:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16331 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8C712BE173 for ; Wed, 22 Jun 2022 16:02:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E38565638; Wed, 22 Jun 2022 18:02:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655913756; bh=umbAvJ+mJc/5H63Q0fkoDq0s/JH1kYGUFdCBefPsgOo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HE3f1cbnHKJ0XTtLerM/kNUo0zT4RVEuvUfcEDQrAjqZVxQJnRso1XrLL15skagMx qWbaW94R9i4ar8KBwcCJSnTh4K8PxRub3cGHyGM7MUnIxxJUK+pFHsRs5yagmeyTVb oh7hercfbD5wnNxb4bJDC7uuoTTJN/EpjvcQ1cmNOWPJ2soqA086988362bomi+JLV rfzuJJY1NiOJVGaxxR2SmHexQ02mPo/C8dZ5wgeyGoIsWN130jrYBBba8f6QzYEvWT 3X0u71S+cArcw5YO+X9LBEXG1U9ELwctYpElS952NP0LBYxKxDPHYBZpvF3w3w07kX 1QeG2Qo+BKSzg== Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 68A6A633A7 for ; Wed, 22 Jun 2022 18:02:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="I3cQ0yEa"; dkim-atps=neutral Received: by mail-ej1-x631.google.com with SMTP id pk21so12129986ejb.2 for ; Wed, 22 Jun 2022 09:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cDMo3oLicSQlHOs00dO80PeMozGfIbpUlXHfTDJEJfc=; b=I3cQ0yEa7cw/KM7v960nLS+cOXzJPbSIu/Q50kdasRTBM1G9Rsnc3f6nlz+knbkdKX R5MlczhAkCAPg3XL72pSVzC/1Cic4267GBwXGqls+ubEtC9gBM0uZMFYLIi9XlMNakCJ BE8JmsqILlIKEopNxw1gF1TqMEUQNREZ8t5H8DTY0SrbjkdFH6A8f9IzTOsS0MSCnn+s Z9RAdPN9QIoBmlK3bdm9MDfRXVt3JorwmG1TnhO+G//IKlNsVrchV+drRBO++/ofEWo3 C6Z8Em1q/2uQ8LUtki8FqHFiIyleteVS8T3Cs/VZAwa7X9Q33TtKmjd+36RWccLetgjz m5LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cDMo3oLicSQlHOs00dO80PeMozGfIbpUlXHfTDJEJfc=; b=T+D4/th9UBMP886qQAKcYL4kSCiXyyaimdVVMgItRVQX2ohxfzA2SMj3naYpHnnqXg 6WLCuyUGXzrS4xI3gUNem19AQ0Wskv5Z9xXvZ4FflbNhdxwlIsexfbtw9csKh977DltB pbrBnyVxR+JUzjKA7bdBIj9gca59OcSs3pr1AtBqiKKLXivFQLxnam8Jqk6MhASk3HUe R3hIodkFfxzXMzvjF+TBU6Utb+dqxpON+pBLT65vvNgoGLqoDYLKL/NilSki/gZP8hdL YwZpGfRcYV2IGFs2SJpmKtYFGClAFDFiqjhQ6YOsx1EZ3+scYK1b1oxvaSDeMyK8LS/H 9mYA== X-Gm-Message-State: AJIora+AwmOhtLJBk8QleUUpPAil2GoMiKb43C63wOVySxBx+16FOpF8 bkjc+/BAe42AjSqXOctcioqumIVj4sZBsA== X-Google-Smtp-Source: AGRyM1t2QRy85RI28eo4JGqMitFT+NE+dxeF9fxq9U9NLn1NVqChe0W5IEbdcCs8TGtWeUtSRzMPqA== X-Received: by 2002:a17:907:2d86:b0:711:da8b:b579 with SMTP id gt6-20020a1709072d8600b00711da8bb579mr3901203ejc.67.1655913753659; Wed, 22 Jun 2022 09:02:33 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id q3-20020a056402248300b004356894a3f8sm11651350eda.89.2022.06.22.09.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 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 Subject: [libcamera-devel] [PATCH 1/1] cam: Add Rectangle type parsing in capture script X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This change is required for AfWindows control from capture script. Parser expects array of arrays of parameters, so it is possible to specify multiple rectangles. --- src/cam/capture_script.cpp | 104 +++++++++++++++++++++++++++++++++---- src/cam/capture_script.h | 9 +++- 2 files changed, 102 insertions(+), 11 deletions(-) diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp index 9f22d5f7..ff620abd 100644 --- a/src/cam/capture_script.cpp +++ b/src/cam/capture_script.cpp @@ -232,12 +232,19 @@ int CaptureScript::parseControl(EventPtr event, ControlList &controls) return -EINVAL; } - std::string value = parseScalar(); - if (value.empty()) - return -EINVAL; - const ControlId *controlId = it->second; - ControlValue val = unpackControl(controlId, value); + ControlValue val; + + if (controlId->type() == ControlTypeRectangle) { + int result = parseRectangles(val); + if (result) + return result; + } else { + int result = parseBasicType(controlId, val); + if (result) + return result; + } + controls.set(controlId->id(), val); return 0; @@ -252,6 +259,77 @@ std::string CaptureScript::parseScalar() return eventScalarValue(event); } +int CaptureScript::parseBasicType(const ControlId *id, ControlValue &controlValue) +{ + std::string value = parseScalar(); + if (value.empty()) + return -EINVAL; + + controlValue = unpackBasicType(id, value); + + return 0; +} + +int CaptureScript::parseRectangles(libcamera::ControlValue &controlValue) +{ + std::vector rectangles; + + EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT); + if (!event) + return -EINVAL; + + while (1) { + event = nextEvent(); + if (!event) + return -EINVAL; + + if (event->type == YAML_SEQUENCE_END_EVENT) { + break; + } + + if (event->type != YAML_SEQUENCE_START_EVENT) { + return -EINVAL; + } + + std::vector values = parseArray(); + if (values.size() != 4) { + std::cerr << "Error parsing Rectangle: " + << "expected array with 4 parameters" + << std::endl; + return -EINVAL; + } + + Rectangle rect = unpackRectangle(values); + rectangles.push_back(rect); + } + + controlValue.set(Span(rectangles)); + + return 0; +} + +std::vector CaptureScript::parseArray() +{ + std::vector values; + + while (1) { + EventPtr event = nextEvent(); + if (!event) + break; + + if (event->type != YAML_SCALAR_EVENT) { + break; + } + + std::string value = eventScalarValue(event); + values.push_back(value); + if (value.empty()) + break; + } + + return values; +} + void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) { static const std::map typeNames = { @@ -277,7 +355,7 @@ void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) << typeName << " control " << id->name() << std::endl; } -ControlValue CaptureScript::unpackControl(const ControlId *id, +ControlValue CaptureScript::unpackBasicType(const ControlId *id, const std::string &repr) { ControlValue value{}; @@ -325,12 +403,20 @@ ControlValue CaptureScript::unpackControl(const ControlId *id, break; } case ControlTypeRectangle: - /* \todo Parse rectangles. */ - break; case ControlTypeSize: - /* \todo Parse Sizes. */ + unpackFailure(id, repr); break; } return value; } + +libcamera::Rectangle CaptureScript::unpackRectangle(const std::vector &strVec) +{ + int x = strtol(strVec[0].c_str(), NULL, 10); + int y = strtol(strVec[1].c_str(), NULL, 10); + unsigned int width = strtoul(strVec[2].c_str(), NULL, 10); + unsigned int height = strtoul(strVec[3].c_str(), NULL, 10); + + return Rectangle(x, y, width, height); +} diff --git a/src/cam/capture_script.h b/src/cam/capture_script.h index 8b4f8f62..73b7e101 100644 --- a/src/cam/capture_script.h +++ b/src/cam/capture_script.h @@ -52,11 +52,16 @@ private: int parseFrames(); int parseFrame(EventPtr event); int parseControl(EventPtr event, libcamera::ControlList &controls); + int parseBasicType(const libcamera::ControlId *id, + libcamera::ControlValue &controlValue); + int parseRectangles(libcamera::ControlValue &controlValue); std::string parseScalar(); + std::vector parseArray(); void unpackFailure(const libcamera::ControlId *id, const std::string &repr); - libcamera::ControlValue unpackControl(const libcamera::ControlId *id, - const std::string &repr); + libcamera::ControlValue unpackBasicType(const libcamera::ControlId *id, + const std::string &repr); + libcamera::Rectangle unpackRectangle(const std::vector &strVec); };