{"id":17557,"url":"https://patchwork.libcamera.org/api/patches/17557/?format=json","web_url":"https://patchwork.libcamera.org/patch/17557/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221006230747.11688-3-laurent.pinchart@ideasonboard.com>","date":"2022-10-06T23:07:45","name":"[libcamera-devel,v2,2/4] utils: gen-controls: Improve YAML notation for variable-size array controls","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f46c2585e7bdf7a8ffa6097ecb02391c3c21dbf5","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17557/mbox/","series":[{"id":3541,"url":"https://patchwork.libcamera.org/api/series/3541/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3541","date":"2022-10-06T23:07:43","name":"libcamera: Improve handling of fixed-size array controls","version":2,"mbox":"https://patchwork.libcamera.org/series/3541/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17557/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17557/checks/","tags":{},"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 D721BBD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  6 Oct 2022 23:07:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8375862D0E;\n\tFri,  7 Oct 2022 01:07:58 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FE6C62D0A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  7 Oct 2022 01:07:57 +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 9F5006D6;\n\tFri,  7 Oct 2022 01:07:56 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1665097678;\n\tbh=6IrpVGQne4DhF/cufG8P66+LI9YMJNAkfFU83KhVHRM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Do4ZiE5INMD1o+u5yrVof0Ot3yFo02FkTLXWq8V8RzWfEzN+hSGob1swc5tQTCKYo\n\tA6AGGQ/42YmSrlWkeyHUVJwEZErQpDtUoor4N4R+iQ0p4kyoPpJ7ZUusPrF/3W9QFJ\n\tA1i7QZBbINspHnC3Bz32kZKfM3hcXv9SYEbMfXH07EbTBlPADWpha0oeSylXudSWa2\n\tGhGjUAFWB+hS9YKZZ2tpz9pii+vV0XRxKmeha3oVtJITCkNa4Nw59WxcfPjuFCJJUJ\n\tU0MWc2+XkZzDHQQAgXE/hH5gFnviXu5/dHBEquNdLoUT5rY8S+123rBbgzyqdYY6Ax\n\tXhb8spQkEJ5EQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1665097676;\n\tbh=6IrpVGQne4DhF/cufG8P66+LI9YMJNAkfFU83KhVHRM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=jtO8B/0aZ2EIg9Pbn17l9FG52YxKa3ZneS++KeR+8+mZMfSbFFMmAQx+1wlZLuoFs\n\t3o86PMYE69rEivWWUyqmMMXPH1efPtk6yx9oDUkt9A+LK5uTNHuKYLZblSMRQNmg3d\n\tEXIw4eIIq2iwC8t0Q8l560nraROIi0VeKyPmjHsk="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jtO8B/0a\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  7 Oct 2022 02:07:45 +0300","Message-Id":"<20221006230747.11688-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20221006230747.11688-1-laurent.pinchart@ideasonboard.com>","References":"<20221006230747.11688-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 2/4] utils: gen-controls: Improve YAML\n\tnotation for variable-size array 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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Array controls specify the array size through the YAML 'size' element,\nwhich stores a list of values, one per dimension. Variable-size arrays\ncurrently use an empty 'size' list, which prevents describing the number\nof dimensions of the array.\n\nImprove this by using the same notation for fixed-size and variable-size\narray controls. Dimensions that are not fixed are described as a string\ninstead of an integer, such as [n], [n,3] or [w,h]. The strings have\ncurrently no special meaning, this may change in the future.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/control_ids.yaml  |  2 +-\n src/libcamera/property_ids.yaml |  4 ++--\n utils/gen-controls.py           | 31 +++++++++++++++++++++++++------\n 3 files changed, 28 insertions(+), 9 deletions(-)","diff":"diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml\nindex c93f362463dd..a456e6c0358f 100644\n--- a/src/libcamera/control_ids.yaml\n+++ b/src/libcamera/control_ids.yaml\n@@ -525,7 +525,7 @@ controls:\n         the window where the focal distance for the objects shown in that part\n         of the image are closest to the camera.\n \n-      size: []\n+      size: [n]\n \n   - AfTrigger:\n       type: int32_t\ndiff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml\nindex 960e254495b7..cb55e0ed2283 100644\n--- a/src/libcamera/property_ids.yaml\n+++ b/src/libcamera/property_ids.yaml\n@@ -497,7 +497,7 @@ controls:\n \n   - PixelArrayOpticalBlackRectangles:\n       type: Rectangle\n-      size: []\n+      size: [n]\n       description: |\n         The pixel array region(s) which contain optical black pixels\n         considered valid for calibration purposes.\n@@ -592,7 +592,7 @@ controls:\n \n   - PixelArrayActiveAreas:\n       type: Rectangle\n-      size: []\n+      size: [n]\n       description: |\n         The PixelArrayActiveAreas property defines the (possibly multiple and\n         overlapping) portions of the camera sensor readable pixel matrix\ndiff --git a/utils/gen-controls.py b/utils/gen-controls.py\nindex d6b4e30001b2..45b7081e6b1d 100755\n--- a/utils/gen-controls.py\n+++ b/utils/gen-controls.py\n@@ -39,11 +39,33 @@ class Control(object):\n         self.__name = name\n         self.__data = data\n         self.__enum_values = None\n+        self.__size = None\n \n         enum_values = data.get('enum')\n         if enum_values is not None:\n             self.__enum_values = [ControlEnum(enum) for enum in enum_values]\n \n+        size = self.__data.get('size')\n+        if size is not None:\n+            if len(size) == 0:\n+                raise RuntimeError(f'Control `{self.__name}` size must have at least one dimension')\n+\n+            # Compute the total number of elemens in the array. If any of the\n+            # array dimension is a string, the array is variable-sized.\n+            num_elems = 1\n+            for dim in size:\n+                if type(dim) is str:\n+                    num_elems = 0\n+                    break\n+\n+                dim = int(dim)\n+                if dim <= 0:\n+                    raise RuntimeError(f'Control `{self.__name}` size must have positive values only')\n+\n+                num_elems *= dim\n+\n+            self.__size = num_elems\n+\n     @property\n     def description(self):\n         \"\"\"The control description\"\"\"\n@@ -86,15 +108,12 @@ class Control(object):\n         if typ == 'string':\n             return 'std::string'\n \n-        if size is None:\n+        if self.__size is None:\n             return typ\n \n-        if len(size) > 0:\n-            # fixed-sized Span\n-            span_size = reduce(operator.mul, size)\n-            return f\"Span<const {typ}, {span_size}>\"\n+        if self.__size:\n+            return f\"Span<const {typ}, {self.__size}>\"\n         else:\n-            # variable-sized Span\n             return f\"Span<const {typ}>\"\n \n \n","prefixes":["libcamera-devel","v2","2/4"]}