[{"id":22866,"web_url":"https://patchwork.libcamera.org/comment/22866/","msgid":"<YnQPh3pagDGDAqNT@pendragon.ideasonboard.com>","date":"2022-05-05T17:55:19","subject":"Re: [libcamera-devel] [PATCH v7 08/13] py: support setting\n\tarray-controls","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Thu, May 05, 2022 at 01:40:59PM +0300, Tomi Valkeinen wrote:\n> Improve PyToControlValue() to convert python lists and tuples to a\n> ControlValue with a Span<> value.\n> \n> Original version from David Plowman <david.plowman@raspberrypi.com>.\n\nAssuming the original version has David's SoB, please keep it here. I\nwould also keep David as the author of the patch.\n\nSame for the remaining patches in the series.\n\n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/py/libcamera/pymain.cpp | 19 +++++++++++++++----\n>  1 file changed, 15 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp\n> index 81d48a20..db9d90ab 100644\n> --- a/src/py/libcamera/pymain.cpp\n> +++ b/src/py/libcamera/pymain.cpp\n> @@ -75,19 +75,30 @@ static py::object ControlValueToPy(const ControlValue &cv)\n>  \t}\n>  }\n>  \n> +template<typename T>\n> +static ControlValue ControlValueMaybeArray(const py::object &ob)\n> +{\n> +\tif (py::isinstance<py::list>(ob) || py::isinstance<py::tuple>(ob)) {\n> +\t\tstd::vector<T> vec = ob.cast<std::vector<T>>();\n> +\t\treturn ControlValue(Span<const T>(vec));\n> +\t}\n> +\n> +\treturn ControlValue(ob.cast<T>());\n> +}\n> +\n>  static ControlValue PyToControlValue(const py::object &ob, ControlType type)\n>  {\n>  \tswitch (type) {\n>  \tcase ControlTypeBool:\n>  \t\treturn ControlValue(ob.cast<bool>());\n>  \tcase ControlTypeByte:\n> -\t\treturn ControlValue(ob.cast<uint8_t>());\n> +\t\treturn ControlValueMaybeArray<uint8_t>(ob);\n>  \tcase ControlTypeInteger32:\n> -\t\treturn ControlValue(ob.cast<int32_t>());\n> +\t\treturn ControlValueMaybeArray<int32_t>(ob);\n>  \tcase ControlTypeInteger64:\n> -\t\treturn ControlValue(ob.cast<int64_t>());\n> +\t\treturn ControlValueMaybeArray<int64_t>(ob);\n>  \tcase ControlTypeFloat:\n> -\t\treturn ControlValue(ob.cast<float>());\n> +\t\treturn ControlValueMaybeArray<float>(ob);\n>  \tcase ControlTypeString:\n>  \t\treturn ControlValue(ob.cast<string>());\n>  \tcase ControlTypeRectangle:","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 C314CC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 May 2022 17:55:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 30C1965643;\n\tThu,  5 May 2022 19:55:25 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F35A9603AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 May 2022 19:55:23 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2864F492;\n\tThu,  5 May 2022 19:55:23 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651773325;\n\tbh=DwsVC1zmWs0baIGvsH8a95AL1F2PgiyNiSq6ddverFI=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=GDrfyDbN1B3UdyUFx3wt2K+wf3zdqtczLL9Y4WWSeHRzJrtpTKpIwcgBhwQhLma7C\n\tbM04UhfkAtzo2wTvwlmNg3/NBwvMcT6cxIbRnS2WhKlkqeQSUluywTR3Sm2M+nKpDy\n\tjkFJuWYeu6jjoZB031LIE/MywO2nUsFqqm1Mw9hWhILVhwRQK3tMhZVKXWsT74axtY\n\tsBVN+kqQ/TVugzJAjzABr8fOpj1poa6g43bxC3qK8d9A/vIcbnQ2BtNB1hScMvy+7y\n\tKPg9sb/pvxAQKQS5mySXXq3swMampTyhEp6605MAlf2RrCX37LliwMjj+86MQyF169\n\tOGKpJXgEvhH/Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651773323;\n\tbh=DwsVC1zmWs0baIGvsH8a95AL1F2PgiyNiSq6ddverFI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=M+SNL7SEIW7SCyf2OsjP6zw/b978TEdCYwkd94jhpw66/gTK9GARBKfRaJMcr9l0U\n\tST+yUG0+DY/prMWvawsOLmDsTyanENI+45t//OotjLKr/JVq2FQcj/qPKiWgiCVElP\n\tuEEImpDB+irwLFAOOhv20DqVajjE0N4YDIYp9Yuk="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"M+SNL7SE\"; dkim-atps=neutral","Date":"Thu, 5 May 2022 20:55:19 +0300","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<YnQPh3pagDGDAqNT@pendragon.ideasonboard.com>","References":"<20220505104104.70841-1-tomi.valkeinen@ideasonboard.com>\n\t<20220505104104.70841-9-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220505104104.70841-9-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v7 08/13] py: support setting\n\tarray-controls","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]