{"id":16544,"url":"https://patchwork.libcamera.org/api/patches/16544/?format=json","web_url":"https://patchwork.libcamera.org/patch/16544/","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":"<20220705095549.87466-3-Rauch.Christian@gmx.de>","date":"2022-07-05T09:55:49","name":"[libcamera-devel,v10,2/2] libcamera: controls: Generate and use fixed-sized Span types","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d48b705faf6eac0d4a7918bb1b6263b2f3835066","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/16544/mbox/","series":[{"id":3251,"url":"https://patchwork.libcamera.org/api/series/3251/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3251","date":"2022-07-05T09:55:47","name":"generate and use fixed-sized Span Control types","version":10,"mbox":"https://patchwork.libcamera.org/series/3251/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16544/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16544/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 C784ABD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Jul 2022 09:55:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D2CE63311;\n\tTue,  5 Jul 2022 11:55:56 +0200 (CEST)","from mout.gmx.net (mout.gmx.net [212.227.17.20])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EBCD66330E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Jul 2022 11:55:53 +0200 (CEST)","from localhost.localdomain ([92.18.80.244]) by mail.gmx.net\n\t(mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id\n\t1MZCfJ-1o4f5U1jFZ-00V6RV; Tue, 05 Jul 2022 11:55:53 +0200"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657014956;\n\tbh=An9X0i6Ef9+rRDe3oEn6t2yOn94uiNIubfSZdYN6cTw=;\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=3zV8UGdQ4aKCUxFKethwLMLEdPeXA8ipU102dcMuNFRTICuG03dOxHDuiKM/5DN/+\n\turSp8+3aEwgfkbcd/oI0LSj4p17sA7uk3bCvjGMlQIHlt9rTPbKoZ/xSYYdm7RN5ak\n\ttKDpBe6aC0T8QYST4TmUCDktGJNCdE09Tlr0byGxeKvqtBt2S5wGPnviV3uXwnySjq\n\tDS5M1I4yA+NXBtkwZaqGR6DE3YUrxvzdeqUQM+hRlpLf37NJdlKB3elpNNaibbdmrQ\n\tr2RYKjAqI0r8y3i52eY/E0smVWnAk/xipKgBGB6Cv0570pNBMb4itvrWi8kk2HCaSp\n\t+4j31WU/bKqvA==","v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;\n\ts=badeba3b8450; t=1657014953;\n\tbh=An9X0i6Ef9+rRDe3oEn6t2yOn94uiNIubfSZdYN6cTw=;\n\th=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References;\n\tb=d/txw2Jz9X5xJeQpSK/wNtqMrqH5YYyI1CXXW7p3EbyzEy20V+rl8JtzJAvMp6UgO\n\tPPTMokBIptbmKEj68j2uz4nPVzYe0jUY7HiYrLDZ6sMBTxpj6UC4DJCkHOdyfIidEv\n\tmwaIGg9ol+ExRMUcxTPv6lAB7LBsoNk7eSVCJECY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=gmx.net header.i=@gmx.net\n\theader.b=\"d/txw2Jz\"; dkim-atps=neutral","X-UI-Sender-Class":"01bb95c1-4bf8-414a-932a-4f6e2808ef9c","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  5 Jul 2022 10:55:49 +0100","Message-Id":"<20220705095549.87466-3-Rauch.Christian@gmx.de>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220705095549.87466-1-Rauch.Christian@gmx.de>","References":"<20220705095549.87466-1-Rauch.Christian@gmx.de>","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","X-Provags-ID":"V03:K1:OP7huhtyEozc/c8BuhVCpa+GlF04X43VU4VFbMNmEWoF3va3mcV\n\tW5gq5NCcQKj4GpFzsHUrsSYcIM7O/UVQiT/+W38uX8ZqL1O8LQwNXVtyK5cPDYtK0UgXqO8\n\tKb+XrAIA0aCzvXw0iy5UFJhZoCoC8VtEyYe0X9UBUVRzX7og1bp+dk6OSx1OrzMymQjDQbz\n\tBVYqWM1/KLIN1rCqRxBwg==","X-Spam-Flag":"NO","X-UI-Out-Filterresults":"notjunk:1; V03:K0:G2okjdK9dcc=:HPznW9YatiPXZYWmK942aO\n\t07vKilGjxysksVlGVbPNPgfjdsKYrz5+46R0zOAvN68a+/mzJkzweuKkGHJZ9PajYltP7WKGs\n\t474IALRQUEEgKkH4VCYsXza4mYBsPck8CQRI/GHNAQY+S3Li1XMJ4B/a6yW3PgA3FEJWVt5a5\n\tsK6xKGEEePb1KsT+vseNXLAd9D6mw0LejJugcOBGKWUPgpLaDoHXqRxPPawhTwMzvBHmPgUL/\n\t99P3762mP4frIVLpZPmUWbwPZW9+lDYzffJwwlI7tSPNLvXw/tMKgmNdaWsBWY3X7GulZgrRK\n\tH70QODjZFGzo3OEA+OIz8BuKB4LT7OMPv6rh/cjVJZ2YRDxNsl8DAK2dWJ/B3RmAqMAfIfx4Y\n\tl2qaaXp9Gj+6iYpOZg7g+8nNZ3djDkVoXbd4rl1wlX6xvMhgY94vmuFnFPefBX3Auyfi/++pb\n\tDcoae8buS3/GmLtR/jupacfVxhSBeDaPuDYcvHyMyxls4ZxgC+fd4Y5i2AWJLkutD167+YIQf\n\tDdm6yRx7Z0Um+Adc8mHYxG14n3XQNkqtVx5qY0QFGmwAraHbBDlF5ZyqZcaVZWCrJx+dA3BZR\n\tyY53uTH5gl6tdRBPe70Tgqq6hYTizqoRBI/9FbcnoT3HoJCEKHlN8rht5X8kFmM9fDnZkHLBE\n\t2m1qyNYhxoK8JL7Frp9l0r8MN7XRECb7jqR66LiABad1bjm6QcbSh1P7waxjHspeJHNgefeP+\n\tvL70vz5wNABGjPX8lnrgvJpvoeOuODXybqVqg6ddS3ZNOlm37ySlx+e9vB7x+u0mP34DBAdaO\n\tqOgtkGmm78mk8qwSirGXrxJqHz/7ipDqPWJh+yCQ8KT3aA6vYU58Fp3v5TLH7wIfNbOmm6Yy9\n\tDY4UJr7cWWbHQM5Egy7Fkp/hgtUg9LdEv5XzOcMt4W3hBgC56WX5Ma8QKJabEPg3ylyXZzHvk\n\tNWlhk0BOwQDKfg5LW8rC4zr13o4ZCJSDkCjNIPTr9h1/9CGPJsK9Tk9FN4VXS6qEjXla3ZEnW\n\ta6sHaazW27xvjNKN5JxxuF7MctGvOLj/j9pMNl42KknMdDwPQsOh4aAFj63WGzu6hl3UvLXvb\n\td7KMX1B8NpwG3Lm/E3VX7HNOtAOkGXNoVh6EXNO5Q7rXeYoW3PwYSYdeg==","Subject":"[libcamera-devel] [PATCH v10 2/2] libcamera: controls: Generate and\n\tuse fixed-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 .../pipeline/raspberrypi/raspberrypi.cpp      |  2 +-\n src/libcamera/property_ids.yaml               |  4 +--\n src/qcam/dng_writer.cpp                       |  2 +-\n utils/gen-controls.py                         | 32 +++++++++++++------\n 7 files changed, 39 insertions(+), 26 deletions(-)\n\n--\n2.34.1","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 192be784..a19f1845 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/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 28f054cb..d88aa256 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1717,7 +1717,7 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &\n \t * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).\n \t */\n \tif (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {\n-\t\tlibcamera::Span<const float> colourGains =\n+\t\tlibcamera::Span<const float, 2> colourGains =\n \t\t\t*controls.get(libcamera::controls::ColourGains);\n \t\t/* The control wants linear gains in the order B, Gb, Gr, R. */\n \t\tControlList ctrls(sensor_->controls());\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 4b5d8276..23612be0 100644\n--- a/src/qcam/dng_writer.cpp\n+++ b/src/qcam/dng_writer.cpp\n@@ -514,7 +514,7 @@ int DNGWriter::write(const char *filename, const Camera *camera,\n \tuint32_t whiteLevel = (1 << info->bitsPerSample) - 1;\n\n \tif (metadata.contains(controls::SensorBlackLevels)) {\n-\t\tSpan<const int32_t> levels =\n+\t\tSpan<const int32_t, 4> levels =\n \t\t\t*metadata.get(controls::SensorBlackLevels);\n\n \t\t/*\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","v10","2/2"]}