{"id":16727,"url":"https://patchwork.libcamera.org/api/patches/16727/?format=json","web_url":"https://patchwork.libcamera.org/patch/16727/","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":"<20220721202106.208337-1-Rauch.Christian@gmx.de>","date":"2022-07-21T20:21:06","name":"[libcamera-devel,v11] libcamera: controls: Generate and use fixed-sized Span types","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c1aa437306dc626ade1a94637f9e68fb9c6b7bcf","submitter":{"id":111,"url":"https://patchwork.libcamera.org/api/people/111/?format=json","name":"Christian Rauch","email":"Rauch.Christian@gmx.de"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16727/mbox/","series":[{"id":3315,"url":"https://patchwork.libcamera.org/api/series/3315/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3315","date":"2022-07-21T20:21:06","name":"[libcamera-devel,v11] libcamera: controls: Generate and use fixed-sized Span types","version":11,"mbox":"https://patchwork.libcamera.org/series/3315/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16727/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16727/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 01445BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Jul 2022 20:21:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43C886330F;\n\tThu, 21 Jul 2022 22:21:14 +0200 (CEST)","from mout.gmx.net (mout.gmx.net [212.227.17.20])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8471E601B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Jul 2022 22:21:12 +0200 (CEST)","from voyager ([88.152.184.103]) by mail.gmx.net (mrgmx104\n\t[212.227.17.168]) with ESMTPSA (Nemesis) id 1MgNh1-1na3Fg3e4V-00htgY;\n\tThu, 21 Jul 2022 22:21:11 +0200"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658434874;\n\tbh=pnPK9HMjoeEKz2x3rnTD+N8E1aFVQlWz+P7UWW6CqHM=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=rpo03ALEryH+5W8L76ZzTcB8wTYp6ieN2Yds/0lHvKZ4NaR7HXpUmQJ9zDEQYOYeJ\n\tFnaVlp/wmTw9U/YPZ8L0lJ8skeg0Em4x8KhkYoTLb2ZV6XMWrfWrCKf8ITWkXBF9zk\n\t7BPMFZATzraKyNeku1v+aRIPH2YEOCZYxURsSr+K7B6/eYYQlfqeLUROhDOh74n3dx\n\tju2iBdYFw+/mXNR5M9BKqB+A5EzxD6VyukOmS0v0544//beD1S9CQ+oaMZy4foMy1+\n\tPrVzyENuX+WjCMBWBGicCfP9U08lgSIYsyZ2Dc2fANnrBAJxuhT25rJy9yK/UCNn+y\n\t92hpQyh+2cjjw==","v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;\n\ts=badeba3b8450; t=1658434872;\n\tbh=pnPK9HMjoeEKz2x3rnTD+N8E1aFVQlWz+P7UWW6CqHM=;\n\th=X-UI-Sender-Class:From:To:Cc:Subject:Date;\n\tb=jpuo3wsTscCfAAP9Hj3d7OSvfZAze2Sc7ZrUQ/T7PEoLHCiNWiIscVJFQvZ5OdPOK\n\t20uWWJy5sY25n36go5HZrr9R7QFw5G6QRBFNvHfDISaBN0YuD7lI2g1I+12J9mYxNL\n\t6TlzWCkjhGVqnwYQhCJFcHdr/Uo01TN+nu3IQBto="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=gmx.net header.i=@gmx.net\n\theader.b=\"jpuo3wsT\"; dkim-atps=neutral","X-UI-Sender-Class":"01bb95c1-4bf8-414a-932a-4f6e2808ef9c","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 21 Jul 2022 22:21:06 +0200","Message-Id":"<20220721202106.208337-1-Rauch.Christian@gmx.de>","X-Mailer":"git-send-email 2.34.1","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","X-Provags-ID":"V03:K1:svm6BJbz8+QX2SfBayBjKbS6wutauUWLHfB54fDYoZ6kGGlbynv\n\t9S/bYuVy0M8TuLxAyNpMEFAKO6xCqoHe7aA5Nt320RY0zMJT66lLQ36WmWmdM/pmEw6rL50\n\tRyPm5ikm1u5whSENkNlhV5CCYhGiFD+tONQSc2hyDtU+cv2yipkEcI+WZoT2Dmz2mwBRFNg\n\tUvp+IisydLLfLEc+Uwwdw==","X-Spam-Flag":"NO","X-UI-Out-Filterresults":"notjunk:1; V03:K0:22aZb8enAy0=:r3IW8q1MtOAT4ncFzYuFlS\n\tf70zPG23Jf4LhlTYG+H0PNGPfkgegefKFi+lNPwXp9tq8W0VofNvv6vCyf0unFquvF0SNa73a\n\t1iDzVL/AeyvCMK/3DcAog+Az7T2ezZQRNorpJXC5deUXgsyG4twBjuOSpmaWHtzUztsIE7lZ9\n\toOMneNcgloMWwyyu+AKKrrvwPFXSdXDqpQ57B3pV2MS4YP1bdTKSdJHqxsmzbj3T+8xT5/Kvd\n\tAwH1Mrjo+JY5/oQUJWprcrfvVP1g/XbYYlvo/bkKb4Ud6I1XEW7Q3UKxQqLW3uFYKQ4E/5E/Q\n\trTpNRAUQbf14XMM2cIdLgtC12WF1GvXZzEouV7eloCFVoeQMtE9vQG1x01r2E2mgAydqsjtEj\n\trCsKMRNHRdxmAEJZ5Myfvc9ugXOxmVm8uMIol2+vw+N9gfB21uNLYeV9ZdygCJf07UqSQqipe\n\trFgREl8ZanDagARBs7BO+IJ7CKbNCaR9QpR9kSs3XDhuikp7TircBv5TD1zJDtqRPTtQcQRH8\n\t2VkO3IlImdm8f9etupdMTvcYxf17HzfwwdF0Hn3GpCUkOUH6PsE8JzRxMig1Ot5Y/05BmEsOo\n\tg6A4yKR0wbgnzt3KzPx6M6yyCwPo0WjHqPb6VKm273M33IiNwpPE3YmxVnGCxbNhbpkFWGYaR\n\t/iudoWZ/U2e2ShDNsIfycvBz3Jap7jefZlCjXe8JxW5i8pjaJhATnb2LfpKLaV0qrX3AGySOu\n\tEPUfH9OpOzwV40/qVPjxDuJXmkqqUOxJ0pdA8oDHpYh8BLF5oL7mGk8017rsEKPNLqnlsDazT\n\ttWxxzyMhzJF6F8s9bTngv/Pzu7++MEvkDf5OPQIktk5o/ae9G/08MluAzjCTWX4PfAbBE+Gj/\n\tkH9zUk8a4nwVM8FevfqA3eq1LsxPf1gp6Vc0wbGQLDJJ+6/MightoUbbmj7pNwxFkOLXa2gnC\n\tGX+qu9YWvy2WeuIoXyo3Z3uQUP6IkzU4HirP0MtNF/k+XzjYVI0lwUM1FZF3WZz+Xf1vJW8sg\n\tGejtLNnjYLcaoQs+oW9BR1KZL9/n3GRK7wgyR3HglC9BMgjNTLnMm7P6atA800/QAdv1yejJC\n\tBMOErGaSsNnSy/Ui4xOB8vBFb+TgnK7C1sLqVNEc/43/+sTKJbQ5+lvHA==","Subject":"[libcamera-devel] [PATCH v11] libcamera: controls: Generate and use\n\tfixed-sized Span types","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":"Christian Rauch via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Christian Rauch <Rauch.Christian@gmx.de>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Define Span types explicitly as either variable- or fixed-sized. This\nintroduces a new convention for defining Span dimensions in the property\nand control value definitions and generates Span types as variable-sized\nSpan<T> or as fixed-sized Span<T,N>.\n\nSigned-off-by: Christian Rauch <Rauch.Christian@gmx.de>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/controls.h        |  2 +-\n src/ipa/raspberrypi/raspberrypi.cpp | 19 +++++++++--------\n src/libcamera/control_ids.yaml      |  4 ++--\n src/libcamera/property_ids.yaml     |  4 ++--\n src/qcam/dng_writer.cpp             |  2 +-\n utils/gen-controls.py               | 32 ++++++++++++++++++++---------\n 6 files changed, 38 insertions(+), 25 deletions(-)\n\n--\n2.34.1","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 7920abba..868e2432 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -168,7 +168,7 @@ public:\n\n \t\tusing V = typename T::value_type;\n \t\tconst V *value = reinterpret_cast<const V *>(data().data());\n-\t\treturn { value, numElements_ };\n+\t\treturn T{ value, numElements_ };\n \t}\n\n #ifndef __DOXYGEN__\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex c7492a77..baaa1e08 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -559,18 +559,19 @@ void IPARPi::reportMetadata()\n\n \tAwbStatus *awbStatus = rpiMetadata_.GetLocked<AwbStatus>(\"awb.status\");\n \tif (awbStatus) {\n-\t\tlibcameraMetadata_.set(controls::ColourGains, { static_cast<float>(awbStatus->gain_r),\n-\t\t\t\t\t\t\t\tstatic_cast<float>(awbStatus->gain_b) });\n+\t\tlibcameraMetadata_.set(controls::ColourGains,\n+\t\t\t\t       Span<const float, 2>({ static_cast<float>(awbStatus->gain_r),\n+\t\t\t\t\t\t\t      static_cast<float>(awbStatus->gain_b) }));\n \t\tlibcameraMetadata_.set(controls::ColourTemperature, awbStatus->temperature_K);\n \t}\n\n \tBlackLevelStatus *blackLevelStatus = rpiMetadata_.GetLocked<BlackLevelStatus>(\"black_level.status\");\n \tif (blackLevelStatus)\n \t\tlibcameraMetadata_.set(controls::SensorBlackLevels,\n-\t\t\t\t       { static_cast<int32_t>(blackLevelStatus->black_level_r),\n-\t\t\t\t\t static_cast<int32_t>(blackLevelStatus->black_level_g),\n-\t\t\t\t\t static_cast<int32_t>(blackLevelStatus->black_level_g),\n-\t\t\t\t\t static_cast<int32_t>(blackLevelStatus->black_level_b) });\n+\t\t\t\t       Span<const int32_t, 4>({ blackLevelStatus->black_level_r,\n+\t\t\t\t\t\t\t\tblackLevelStatus->black_level_g,\n+\t\t\t\t\t\t\t\tblackLevelStatus->black_level_g,\n+\t\t\t\t\t\t\t\tblackLevelStatus->black_level_b }));\n\n \tFocusStatus *focusStatus = rpiMetadata_.GetLocked<FocusStatus>(\"focus.status\");\n \tif (focusStatus && focusStatus->num == 12) {\n@@ -875,7 +876,7 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tif (gains[0] != 0.0f && gains[1] != 0.0f)\n \t\t\t\t/* A gain of 0.0f will switch back to auto mode. */\n \t\t\t\tlibcameraMetadata_.set(controls::ColourGains,\n-\t\t\t\t\t\t       { gains[0], gains[1] });\n+\t\t\t\t\t\t       Span<const float, 2>({ gains[0], gains[1] }));\n \t\t\tbreak;\n \t\t}\n\n@@ -1159,8 +1160,8 @@ void IPARPi::applyFrameDurations(Duration minFrameDuration, Duration maxFrameDur\n\n \t/* Return the validated limits via metadata. */\n \tlibcameraMetadata_.set(controls::FrameDurationLimits,\n-\t\t\t       { static_cast<int64_t>(minFrameDuration_.get<std::micro>()),\n-\t\t\t\t static_cast<int64_t>(maxFrameDuration_.get<std::micro>()) });\n+\t\t\t       Span<const int64_t, 2>({ static_cast<int64_t>(minFrameDuration_.get<std::micro>()),\n+\t\t\t\t\t\t\tstatic_cast<int64_t>(maxFrameDuration_.get<std::micro>()) }));\n\n \t/*\n \t * Calculate the maximum exposure time possible for the AGC to use.\ndiff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml\nindex ecab3ae9..5fa168c6 100644\n--- a/src/libcamera/control_ids.yaml\n+++ b/src/libcamera/control_ids.yaml\n@@ -291,7 +291,7 @@ controls:\n         transformation. The 3x3 matrix is stored in conventional reading\n         order in an array of 9 floating point values.\n\n-      size: [3x3]\n+      size: [3,3]\n\n   - ScalerCrop:\n       type: Rectangle\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]\n+      size: []\n\n   - AfTrigger:\n       type: int32_t\ndiff --git a/src/libcamera/property_ids.yaml b/src/libcamera/property_ids.yaml\nindex 11b7ebdc..a87485d7 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]\n+      size: []\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]\n+      size: []\n       description: |\n         The PixelArrayActiveAreas property defines the (possibly multiple and\n         overlapping) portions of the camera sensor readable pixel matrix\ndiff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp\nindex 5896485c..2e8bf0ca 100644\n--- a/src/qcam/dng_writer.cpp\n+++ b/src/qcam/dng_writer.cpp\n@@ -517,7 +517,7 @@ int DNGWriter::write(const char *filename, const Camera *camera,\n\n \tconst auto &blackLevels = metadata.get(controls::SensorBlackLevels);\n \tif (blackLevels) {\n-\t\tSpan<const int32_t> levels = *blackLevels;\n+\t\tSpan<const int32_t, 4> levels = *blackLevels;\n\n \t\t/*\n \t\t * The black levels control is specified in R, Gr, Gb, B order.\ndiff --git a/utils/gen-controls.py b/utils/gen-controls.py\nindex 3f99b5e2..46ba4394 100755\n--- a/utils/gen-controls.py\n+++ b/utils/gen-controls.py\n@@ -7,6 +7,8 @@\n # gen-controls.py - Generate control definitions from YAML\n\n import argparse\n+from functools import reduce\n+import operator\n import string\n import sys\n import yaml\n@@ -22,6 +24,24 @@ def format_description(description):\n     return '\\n'.join([(line and ' * ' or ' *') + line for line in description])\n\n\n+def get_ctrl_type(ctrl):\n+    ctrl_type = ctrl['type']\n+    ctrl_size_arr = ctrl.get('size')\n+\n+    if ctrl_type == 'string':\n+        return 'std::string'\n+    elif ctrl_size_arr is not None:\n+        if len(ctrl_size_arr) > 0:\n+            # fixed-sized Span\n+            ctrl_span_size = reduce(operator.mul, ctrl_size_arr)\n+            return f\"Span<const {ctrl_type}, {ctrl_span_size}>\"\n+        else:\n+            # variable-sized Span\n+            return f\"Span<const {ctrl_type}>\"\n+    else:\n+        return ctrl_type\n+\n+\n def generate_cpp(controls):\n     enum_doc_start_template = string.Template('''/**\n  * \\\\enum ${name}Enum\n@@ -50,11 +70,7 @@ ${description}\n         name, ctrl = ctrl.popitem()\n         id_name = snake_case(name).upper()\n\n-        ctrl_type = ctrl['type']\n-        if ctrl_type == 'string':\n-            ctrl_type = 'std::string'\n-        elif ctrl.get('size'):\n-            ctrl_type = 'Span<const %s>' % ctrl_type\n+        ctrl_type = get_ctrl_type(ctrl)\n\n         info = {\n             'name': name,\n@@ -135,11 +151,7 @@ def generate_h(controls):\n\n         ids.append('\\t' + id_name + ' = ' + str(id_value) + ',')\n\n-        ctrl_type = ctrl['type']\n-        if ctrl_type == 'string':\n-            ctrl_type = 'std::string'\n-        elif ctrl.get('size'):\n-            ctrl_type = 'Span<const %s>' % ctrl_type\n+        ctrl_type = get_ctrl_type(ctrl)\n\n         info = {\n             'name': name,\n","prefixes":["libcamera-devel","v11"]}