Show a patch.

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

{
    "id": 19636,
    "url": "https://patchwork.libcamera.org/api/patches/19636/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19636/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20240307102738.55324-1-stefan.klug@ideasonboard.com>",
    "date": "2024-03-07T10:27:38",
    "name": "[v3] libcamera: controls: Add policy parameter to ControlList::merge()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "6a3a6ca1130b707d7da20490592afb3a0a681334",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19636/mbox/",
    "series": [
        {
            "id": 4204,
            "url": "https://patchwork.libcamera.org/api/series/4204/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4204",
            "date": "2024-03-07T10:27:38",
            "name": "[v3] libcamera: controls: Add policy parameter to ControlList::merge()",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4204/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19636/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19636/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 C6D1AC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  7 Mar 2024 10:27:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 193E36286F;\n\tThu,  7 Mar 2024 11:27:46 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D5DC61C87\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 Mar 2024 11:27:44 +0100 (CET)",
            "from jasper.fritz.box (unknown\n\t[IPv6:2a00:6020:448c:6c00:f22b:8202:cf41:4cec])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CF0842B3;\n\tThu,  7 Mar 2024 11:27:25 +0100 (CET)"
        ],
        "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=\"mfSGzdeJ\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1709807246;\n\tbh=4Qo93dHgNsjem+3JitTxiJxb+Cbr43l9ixFm4ekKBAg=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=mfSGzdeJ2kyehR3hDXX2VjFmtjdt1UGcrjQAw4PsSZudhbprmf8JmZ4PG/jLmxhkP\n\t34F0gVmuSV/oj5hTA9B7Ii46YYfUyONc8YQzNJ/UI9Rvz5kG0hMOqsXJK8A3GjyuDr\n\t2tc9Sp6UIuOVR0FCGRZwlPQojoIJ5+NQvptHOEa8=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v3] libcamera: controls: Add policy parameter to\n\tControlList::merge()",
        "Date": "Thu,  7 Mar 2024 11:27:38 +0100",
        "Message-Id": "<20240307102738.55324-1-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.40.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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": "This is useful in many cases although not included in the stl.\n\nNote: This is an ABI incompatible change.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n---\nChanges in v2:\n - Added unittest and fixes doxygen docs.\nChanges in v3:\n - Replace boolean param by enum for better readability\n - Added note on ABI breakage\n\n include/libcamera/controls.h   |  7 ++++-\n src/libcamera/controls.cpp     | 20 ++++++++++++--\n test/controls/control_list.cpp | 50 ++++++++++++++++++++++++++++++++++\n 3 files changed, 73 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex cf942055..82b95599 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -352,6 +352,11 @@ private:\n \tusing ControlListMap = std::unordered_map<unsigned int, ControlValue>;\n \n public:\n+\tenum class MergePolicy {\n+\t\tKeepExisting = 0,\n+\t\tOverwriteExisting,\n+\t};\n+\n \tControlList();\n \tControlList(const ControlIdMap &idmap, const ControlValidator *validator = nullptr);\n \tControlList(const ControlInfoMap &infoMap, const ControlValidator *validator = nullptr);\n@@ -368,7 +373,7 @@ public:\n \tstd::size_t size() const { return controls_.size(); }\n \n \tvoid clear() { controls_.clear(); }\n-\tvoid merge(const ControlList &source);\n+\tvoid merge(const ControlList &source, MergePolicy policy = MergePolicy::KeepExisting);\n \n \tbool contains(unsigned int id) const;\n \ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex b808116c..16d3547c 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -907,13 +907,27 @@ ControlList::ControlList(const ControlInfoMap &infoMap,\n  * \\brief Removes all controls from the list\n  */\n \n+/**\n+ * \\enum ControlList::MergePolicy\n+ * \\brief The policy used by the merge function\n+ *\n+ * \\var ControlList::MergePolicy::KeepExisting\n+ * \\brief Existing controls in the target list are kept\n+ *\n+ * \\var ControlList::MergePolicy::OverwriteExisting\n+ * \\brief Existing controls in the target list are updated\n+ */\n+\n /**\n  * \\brief Merge the \\a source into the ControlList\n  * \\param[in] source The ControlList to merge into this object\n+ * \\param[in] policy Controls if existing elements in *this shall be\n+ * overwritten\n  *\n  * Merging two control lists copies elements from the \\a source and inserts\n  * them in *this. If the \\a source contains elements whose key is already\n- * present in *this, then those elements are not overwritten.\n+ * present in *this, then those elements are only overwritten if\n+ * \\a policy is MergePolicy::OverwriteExisting.\n  *\n  * Only control lists created from the same ControlIdMap or ControlInfoMap may\n  * be merged. Attempting to do otherwise results in undefined behaviour.\n@@ -921,7 +935,7 @@ ControlList::ControlList(const ControlInfoMap &infoMap,\n  * \\todo Reimplement or implement an overloaded version which internally uses\n  * std::unordered_map::merge() and accepts a non-const argument.\n  */\n-void ControlList::merge(const ControlList &source)\n+void ControlList::merge(const ControlList &source, MergePolicy policy)\n {\n \t/**\n \t * \\todo ASSERT that the current and source ControlList are derived\n@@ -936,7 +950,7 @@ void ControlList::merge(const ControlList &source)\n \t */\n \n \tfor (const auto &ctrl : source) {\n-\t\tif (contains(ctrl.first)) {\n+\t\tif (policy == MergePolicy::KeepExisting && contains(ctrl.first)) {\n \t\t\tconst ControlId *id = idmap_->at(ctrl.first);\n \t\t\tLOG(Controls, Warning)\n \t\t\t\t<< \"Control \" << id->name() << \" not overwritten\";\ndiff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\nindex c03f230e..e86df49f 100644\n--- a/test/controls/control_list.cpp\n+++ b/test/controls/control_list.cpp\n@@ -196,6 +196,56 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n+\t\t/*\n+\t\t * Create two lists with overlapping controls. Merge them with\n+\t\t * overwriteExisting = true, verifying that the existing control\n+\t\t * values *get* overwritten.\n+\t\t */\n+\t\tmergeList.clear();\n+\t\tmergeList.set(controls::Brightness, 0.7f);\n+\t\tmergeList.set(controls::Saturation, 0.4f);\n+\n+\t\tlist.clear();\n+\t\tlist.set(controls::Brightness, 0.5f);\n+\t\tlist.set(controls::Contrast, 1.1f);\n+\n+\t\tmergeList.merge(list, ControlList::MergePolicy::OverwriteExisting);\n+\t\tif (mergeList.size() != 3) {\n+\t\t\tcout << \"Merged list should contain three elements\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (list.size() != 2) {\n+\t\t\tcout << \"The list to merge should contain two elements\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!mergeList.get(controls::Brightness) ||\n+\t\t    !mergeList.get(controls::Contrast) ||\n+\t\t    !mergeList.get(controls::Saturation)) {\n+\t\t\tcout << \"Merged list does not contain all controls\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (mergeList.get(controls::Brightness) != 0.5f) {\n+\t\t\tcout << \"Brightness control value did not change after merging lists\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (mergeList.get(controls::Contrast) != 1.1f) {\n+\t\t\tcout << \"Contrast control value did not change after merging lists\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (mergeList.get(controls::Saturation) != 0.4f) {\n+\t\t\tcout << \"Saturation control value changed after merging lists\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\treturn TestPass;\n \t}\n };\n",
    "prefixes": [
        "v3"
    ]
}