From patchwork Thu May 5 10:40:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15791 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 F04DDC0F2A for ; Thu, 5 May 2022 10:41:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4465658; Thu, 5 May 2022 12:41:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651747295; bh=PVAyCaitM3siiYv1k27wm6GStBa71P4ZGo3rLLegKjY=; 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=iGDRsb5Y5O3D6kTTnHgBT9yvP1nFLUDrlvsja+nTywMY+c9gLRTbyNK1CNh+Ilr51 EZkls9U2unVGHiZbT+ZCAZ4Cm3nEe/3c8KrJVX2AoPc2VU+I011VXLxK1kOKx7cGe/ Xgbulhlj8ICsND5sPGZvOi4cFAVNfmHbtkLIlorR0hNpBVd3J2OIyaFp/pXBEpRpMm tw6rD87dACKUopyO5KPc7Z/ISL+FbhIeGZ5sjX/UMN9ycKtBVh6jq+CluInfjTrFbn PA536hn7LVQIGvi/JHHCFRYRLHIMxoF+3+q7QXjAonKLi9CEkBlfwVPt3b2W4JQHHG 4kHdSvk4s+tvg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EBCA165658 for ; Thu, 5 May 2022 12:41:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hrJEj6PI"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E5414A8; Thu, 5 May 2022 12:41:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651747289; bh=PVAyCaitM3siiYv1k27wm6GStBa71P4ZGo3rLLegKjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hrJEj6PIlgG6oVEO5I3Lq1HZGCQ/ygE5SDfH9dyX4Xhkwm3X+tzqDs6+zkRS+JZAC 8nv/by9B5zVgzyYaGLtNzSqM3Mvm6/cMEAJW/Xkkbv4ElV8RSeSBasamDKMv6BhD/I cfhy338eRCxwFrIuGsJeqCKIRK9cXqFFOsbaS94Y= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Thu, 5 May 2022 13:40:59 +0300 Message-Id: <20220505104104.70841-9-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> References: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 08/13] py: support setting array-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: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Improve PyToControlValue() to convert python lists and tuples to a ControlValue with a Span<> value. Original version from David Plowman . Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/pymain.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index 81d48a20..db9d90ab 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -75,19 +75,30 @@ static py::object ControlValueToPy(const ControlValue &cv) } } +template +static ControlValue ControlValueMaybeArray(const py::object &ob) +{ + if (py::isinstance(ob) || py::isinstance(ob)) { + std::vector vec = ob.cast>(); + return ControlValue(Span(vec)); + } + + return ControlValue(ob.cast()); +} + static ControlValue PyToControlValue(const py::object &ob, ControlType type) { switch (type) { case ControlTypeBool: return ControlValue(ob.cast()); case ControlTypeByte: - return ControlValue(ob.cast()); + return ControlValueMaybeArray(ob); case ControlTypeInteger32: - return ControlValue(ob.cast()); + return ControlValueMaybeArray(ob); case ControlTypeInteger64: - return ControlValue(ob.cast()); + return ControlValueMaybeArray(ob); case ControlTypeFloat: - return ControlValue(ob.cast()); + return ControlValueMaybeArray(ob); case ControlTypeString: return ControlValue(ob.cast()); case ControlTypeRectangle: