From patchwork Wed Jul 27 12:57:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16846 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 B9A58BE173 for ; Wed, 27 Jul 2022 12:58:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1898E63311; Wed, 27 Jul 2022 14:58:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658926686; bh=elg+cfcb0P6ERHIMe8vzKA9Pf7F3JP7/LP9iOfUVXgc=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QgYDsZMiN7bTKaAyEbNWRKmnRPXXqSBhak4RZ7RgpxMWC5hWXnFl2OUVht/h0XuwP Y9BTRm6WRi1+inC7c3SniQnG+iVavvauUtXgBrO4Ge3WWyJz7NfacmvNJPCuxlUa5Z c3UmdCNF6AsuvPHmUJ1q0he/k+EIDHRahQA2lQGmew65vaDNxWAr9+RPdqOvd5S7ts ClFzI09fgL4Pq5QvsipYr2YP7AQl46sz8yfewScWiaDZJ3uszt4WQbDACXCQ+/7Iry n3ct/1Zf+gDXYkNb2hqvyDOtcx82JYtrRzLmGbQir7dDhq7WalaNiUqzE95QXV2oa0 5JX6rTLhIzlKA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9809563309 for ; Wed, 27 Jul 2022 14:58:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aos+HcC0"; 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 32A62835; Wed, 27 Jul 2022 14:58:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658926684; bh=elg+cfcb0P6ERHIMe8vzKA9Pf7F3JP7/LP9iOfUVXgc=; h=From:To:Cc:Subject:Date:From; b=aos+HcC0Sp1LQ7keutIrQy0WfVY0uWbcLNYiOcb4sFM+Vgb8QcffmOX5dMXJU1At3 z1dyHzEVFo5xx0RGnHF87dsvOajnKYr01+IAHuZ9LiSaa0yiBf4WQ5DSyeTU1ByZk+ KK5hZT4DPXvODBDzUVP/azW1PH02w6xYObnFzB0w= To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Jul 2022 21:57:54 +0900 Message-Id: <20220727125754.1109455-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] 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 --- 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..6421b6df 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 */ + + int pos = repr.find("x"); + if (pos == std::string::npos) { + unpackFailure(id, repr); + return Size{}; + } + + int32_t width = strtol(repr.substr(0, pos), NULL, 10); + int32_t height = strtol(repr.substr(pos), 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,