Show a patch.

GET /api/1.1/patches/13055/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13055,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13055/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13055/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210720101307.26010-7-paul.elder@ideasonboard.com>",
    "date": "2021-07-20T10:13:04",
    "name": "[libcamera-devel,v5,6/9] android: Add helpers for setting android metadata from libcamera controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "f3acfad9b6045e51e32a4753ddbe5ac495a82112",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13055/mbox/",
    "series": [
        {
            "id": 2258,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2258/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2258",
            "date": "2021-07-20T10:12:58",
            "name": "android: Support capability and hardware level detection",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/2258/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13055/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13055/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 2D490C0109\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 20 Jul 2021 10:13:33 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DADB76854A;\n\tTue, 20 Jul 2021 12:13:32 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BB29B68547\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Jul 2021 12:13:31 +0200 (CEST)",
            "from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 57439443;\n\tTue, 20 Jul 2021 12:13:30 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Ql6WQV4r\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1626776011;\n\tbh=d1X10EYGPM85ZodyM1tCiEIUhaOTFbIdzGP3+80v8Qw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ql6WQV4rVG3DMHGdzXCt7om0dds4IOCu1VM82Tg67HzeILUguK1hguZe0as4GovEX\n\typfn7i9mXhsCqBvP19aeItC1hi7/BnE4nu114DT0pS1LMJExrxjizq+XBOp2exBXN6\n\tEPgL1ZoykxS5vAv8z8JwABmfXNT4il+5Dx4a9kGQ=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 20 Jul 2021 19:13:04 +0900",
        "Message-Id": "<20210720101307.26010-7-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20210720101307.26010-1-paul.elder@ideasonboard.com>",
        "References": "<20210720101307.26010-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 6/9] android: Add helpers for setting\n\tandroid metadata from libcamera 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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add helpers for setting android metadata from libcamera controls.\n\nThere are two versions, for scalars and collections, both of which take\na default value to fill in the android control if the libcamera control\nis not found. A version for scalars exists for no default, to not set\nthe android control at all if it is not found in libcamera. The\nfunctions take two template parameters, the first for the android type,\nand the second for the libcamera type of the control. They can be\ndifferent, for example, if the former is an enum and the latter is a\nboolean, or if the former is an enum (uint8_t) and the latter is an enum\n(int32_t).\n\nThe versions that take a default value return the value that was set in\nthe android metadata.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v4:\n- remove vector copy from the vector setter\n\nChanges in v3:\n- setMetadata for collection only works with vectors\n- change enum to enum class\n- add two template parameters for android type and libcamera type\n- add docs\n\nNew in v2\n\nTODO: make ControlList versions so that we can use them in result\nmetadata\n---\n src/android/camera_capabilities.cpp | 137 ++++++++++++++++++++++++++++\n 1 file changed, 137 insertions(+)",
    "diff": "diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp\nindex c97a17e6..a8fa7ffe 100644\n--- a/src/android/camera_capabilities.cpp\n+++ b/src/android/camera_capabilities.cpp\n@@ -11,6 +11,7 @@\n #include <array>\n #include <cmath>\n #include <map>\n+#include <type_traits>\n \n #include <hardware/camera3.h>\n \n@@ -125,6 +126,142 @@ hwLevelStrings = {\n \t{ ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, \"EXTERNAL\" },\n };\n \n+enum class ControlRange {\n+\tMin,\n+\tDef,\n+\tMax,\n+};\n+\n+/**\n+ * \\brief Set android metadata from libcamera ControlInfo\n+ * \\tparam T Type of the control in android\n+ * \\tparam V Type of the control in libcamera\n+ * \\param[in] metadata Android metadata pack to add the control value to\n+ * \\param[in] tag Android metadata tag\n+ * \\param[in] controlsInfo libcamera ControlInfoMap from which to find the control info\n+ * \\param[in] control libcamera ControlId to find from \\a controlsInfo\n+ * \\param[in] controlRange Whether to use the min, def, or max value from the control info\n+ *\n+ * Set the android metadata entry in \\a metadata with tag \\a tag based on the\n+ * control info found for the libcamera control \\a control in the libcamera\n+ * ControlInfoMap \\a controlsInfo. If no libcamera ControlInfo is found, then\n+ * the function returns without modifying anything.\n+ *\n+ * This function is for scalar values.\n+ */\n+template<typename T,\n+\t std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr,\n+\t typename V>\n+void setMetadata(CameraMetadata *metadata, uint32_t tag,\n+\t\t const ControlInfoMap &controlsInfo, const ControlId *control,\n+\t\t enum ControlRange controlRange)\n+{\n+\tconst auto &info = controlsInfo.find(control);\n+\tif (info == controlsInfo.end())\n+\t\treturn;\n+\n+\tT ret;\n+\tswitch (controlRange) {\n+\tcase ControlRange::Min:\n+\t\tret = info->second.min().get<V>();\n+\t\tbreak;\n+\tcase ControlRange::Def:\n+\t\tret = info->second.def().get<V>();\n+\t\tbreak;\n+\tcase ControlRange::Max:\n+\t\tret = info->second.max().get<V>();\n+\t\tbreak;\n+\t}\n+\n+\tmetadata->addEntry(tag, ret);\n+\treturn;\n+}\n+\n+/**\n+ * \\brief Set android metadata from libcamera ControlInfo or a default value\n+ * \\tparam T Type of the control in android\n+ * \\tparam U Type of the control in libcamera\n+ * \\param[in] metadata Android metadata pack to add the control value to\n+ * \\param[in] tag Android metadata tag\n+ * \\param[in] controlsInfo libcamera ControlInfoMap from which to find the control info\n+ * \\param[in] control libcamera ControlId to find from \\a controlsInfo\n+ * \\param[in] controlRange Whether to use the min, def, or max value from the control info\n+ * \\param[in] defaultValue The value to set in \\a metadata if \\a control is not found\n+ *\n+ * Set the android metadata entry in \\a metadata with tag \\a tag based on the\n+ * control info found for the libcamera control \\a control in the libcamera\n+ * ControlInfoMap \\a controlsInfo. If no libcamera ControlInfo is found, then\n+ * the android metadata entry is set to \\a defaultValue.\n+ *\n+ * This function is for scalar values.\n+ */\n+template<typename T,\n+\t typename U,\n+\t typename V,\n+\t std::enable_if_t<std::is_arithmetic_v<V> ||\n+\t\t\t  std::is_enum_v<V>> * = nullptr>\n+T setMetadata(CameraMetadata *metadata, uint32_t tag,\n+\t      const ControlInfoMap &controlsInfo, const ControlId *control,\n+\t      enum ControlRange controlRange, const V defaultValue)\n+{\n+\tT ret = defaultValue;\n+\n+\tconst auto &info = controlsInfo.find(control);\n+\tif (info != controlsInfo.end()) {\n+\t\tswitch (controlRange) {\n+\t\tcase ControlRange::Min:\n+\t\t\tret = info->second.min().get<U>();\n+\t\t\tbreak;\n+\t\tcase ControlRange::Def:\n+\t\t\tret = info->second.def().get<U>();\n+\t\t\tbreak;\n+\t\tcase ControlRange::Max:\n+\t\t\tret = info->second.max().get<U>();\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tmetadata->addEntry(tag, ret);\n+\treturn ret;\n+}\n+\n+/**\n+ * \\brief Set android metadata from libcamera ControlInfo or a default value\n+ * \\tparam T Type of the control in android\n+ * \\tparam V Type of the control in libcamera\n+ * \\param[in] metadata Android metadata pack to add the control value to\n+ * \\param[in] tag Android metadata tag\n+ * \\param[in] controlsInfo libcamera ControlInfoMap from which to find the control info\n+ * \\param[in] control libcamera ControlId to find from \\a controlsInfo\n+ * \\param[in] defaultVector The value to set in \\a metadata if \\a control is not found\n+ *\n+ * Set the android metadata entry in \\a metadata with tag \\a tag based on the\n+ * control info found for the libcamera control \\a control in the libcamera\n+ * ControlInfoMap \\a controlsInfo. If no libcamera ControlInfo is found, then\n+ * the android metadata entry is set to \\a defaultVector.\n+ *\n+ * This function is for vector values.\n+ */\n+template<typename T, typename V>\n+std::vector<T> setMetadata(CameraMetadata *metadata, uint32_t tag,\n+\t\t\t   const ControlInfoMap &controlsInfo,\n+\t\t\t   const ControlId *control,\n+\t\t\t   const std::vector<T> &defaultVector)\n+{\n+\tconst auto &info = controlsInfo.find(control);\n+\tif (info == controlsInfo.end()) {\n+\t\tmetadata->addEntry(tag, defaultVector);\n+\t\treturn defaultVector;\n+\t}\n+\n+\tstd::vector<T> ret(info->second.values().size());\n+\tfor (const auto &value : info->second.values())\n+\t\tret.push_back(value.get<V>());\n+\tmetadata->addEntry(tag, ret);\n+\n+\treturn ret;\n+}\n+\n } /* namespace */\n \n bool CameraCapabilities::validateManualSensorCapability(const CameraMetadata *staticMetadata)\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "6/9"
    ]
}