From patchwork Thu Jul 28 07:23:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16858 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 E0140BE173 for ; Thu, 28 Jul 2022 07:23:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E5F963311; Thu, 28 Jul 2022 09:23:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658993004; bh=hZmuHNvutpvWrqKpXGrOkUdnB2GNsWaPrsjvOURRfwo=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HnQTmFmZdC3gSiwDK+nbglPGSQOh3tNTJ0v5pLAN/esl9BxR9PrKhs1hHZ02EWLwd xauo98GYdivHId35gf1F7eBrthGV6Idwd/DVvtXfoc/1Ti3AJsLsFIwhXAomecHlB0 5ldxxjNexu/1+ngydIYwTZB6yxzsl5Bl2Xk+MeJoyFebrjbZXU8LnOPHbV00yWqQVE OT4KsFTGfR7ErkCXv1qUKJiV+qnn7PGoq5cowTogK5aT3FoBiSflS4vcPshbY5qhKa GPeIDqGX0FbX9SEx61u7CZUQF3UYZ+CLsSeBXqlo9pri2u+5FWG84xftlCP5THtDPT n6+x01JNlVB1Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 612E3603EB for ; Thu, 28 Jul 2022 09:23:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="j2pX2EuT"; dkim-atps=neutral Received: from pyrite.rasen.tech (h175-177-042-159.catv02.itscom.jp [175.177.42.159]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 068F06D4; Thu, 28 Jul 2022 09:23:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658993003; bh=hZmuHNvutpvWrqKpXGrOkUdnB2GNsWaPrsjvOURRfwo=; h=From:To:Cc:Subject:Date:From; b=j2pX2EuTGLo8UHpFohu9rbudnKnrLpDTgfSMRMrl4nimWKwCQJAai15v3T1ORUfiW NjQDvzZhu1JuP/RCei9xujoee+7bqdGidRruPYrlLHIJIXNbL+77XbjogkxcK8T/vQ a72gVzF+Y4lUSyldiDVJD+3NVYn35vwi1A/fQztY= To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Jul 2022 16:23:11 +0900 Message-Id: <20220728072311.808238-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] cam: capture_script: Add support for Rectangle and Size controls 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for Rectangle and Size control values in the capture script parser. Signed-off-by: Paul Elder --- Changes in v2: - fix compilation error for the Size parser --- src/cam/capture_script.cpp | 61 +++++++++++++++++++++++++++++++++++--- src/cam/capture_script.h | 4 +++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp index 9f22d5f7..07b14613 100644 --- a/src/cam/capture_script.cpp +++ b/src/cam/capture_script.cpp @@ -252,6 +252,53 @@ std::string CaptureScript::parseScalar() return eventScalarValue(event); } +Rectangle CaptureScript::unpackRectangle(const ControlId *id, + const std::string &repr) +{ + /* Format: (,)/x */ + + std::map delims = { { '(', -1 }, + { ')', -1 }, + { ',', -1 }, + { '/', -1 }, + { 'x', -1 } }; + + for (unsigned int i = 0; i < repr.size(); i++) + if (delims.count(repr[i])) + delims[repr[i]] = i; + + for (auto &pair : delims) { + if (pair.second == -1) { + unpackFailure(id, repr); + return Rectangle{}; + } + } + + int32_t left = strtol(repr.substr(delims['('] + 1, delims[',']).c_str(), NULL, 10); + int32_t top = strtol(repr.substr(delims[','] + 1, delims[')']).c_str(), NULL, 10); + int32_t width = strtol(repr.substr(delims['/'] + 1, delims['x']).c_str(), NULL, 10); + int32_t height = strtol(repr.substr(delims['x'] + 1).c_str(), NULL, 10); + + return Rectangle(left, top, width, height); +} + +Size CaptureScript::unpackSize(const ControlId *id, + const std::string &repr) +{ + /* Format: x */ + + unsigned int pos = repr.find("x"); + if (pos == std::string::npos) { + unpackFailure(id, repr); + return Size{}; + } + + int32_t width = strtol(repr.substr(0, pos).c_str(), NULL, 10); + int32_t height = strtol(repr.substr(pos).c_str(), NULL, 10); + + return Size(width, height); +} + void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) { static const std::map typeNames = { @@ -281,6 +328,8 @@ ControlValue CaptureScript::unpackControl(const ControlId *id, const std::string &repr) { ControlValue value{}; + Rectangle rect; + Size size; switch (id->type()) { case ControlTypeNone: @@ -324,13 +373,17 @@ ControlValue CaptureScript::unpackControl(const ControlId *id, value.set(repr); break; } - case ControlTypeRectangle: - /* \todo Parse rectangles. */ + case ControlTypeRectangle: { + rect = unpackRectangle(id, repr); + value.set(rect); break; - case ControlTypeSize: - /* \todo Parse Sizes. */ + } + case ControlTypeSize: { + size = unpackSize(id, repr); + value.set(size); break; } + } return value; } diff --git a/src/cam/capture_script.h b/src/cam/capture_script.h index 8b4f8f62..f2dbfdf8 100644 --- a/src/cam/capture_script.h +++ b/src/cam/capture_script.h @@ -55,6 +55,10 @@ private: std::string parseScalar(); + libcamera::Rectangle unpackRectangle(const libcamera::ControlId *id, + const std::string &repr); + libcamera::Size unpackSize(const libcamera::ControlId *id, + const std::string &repr); void unpackFailure(const libcamera::ControlId *id, const std::string &repr); libcamera::ControlValue unpackControl(const libcamera::ControlId *id,