Show a patch.

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

{
    "id": 19626,
    "url": "https://patchwork.libcamera.org/api/patches/19626/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19626/",
    "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": "<20240304155852.105079-1-stefan.klug@ideasonboard.com>",
    "date": "2024-03-04T15:58:53",
    "name": "[v2] libcamera: controls: Add overwriteExisting parameter to ControlList::merge",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2ff08d5ea4bec30391f28e890d7ff632a58f0b3a",
    "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/19626/mbox/",
    "series": [
        {
            "id": 4200,
            "url": "https://patchwork.libcamera.org/api/series/4200/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4200",
            "date": "2024-03-04T15:58:53",
            "name": "[v2] libcamera: controls: Add overwriteExisting parameter to ControlList::merge",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4200/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19626/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19626/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 6183CBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Mar 2024 15:59:53 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AEA2162871;\n\tMon,  4 Mar 2024 16:59:52 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E688627FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Mar 2024 16:59:51 +0100 (CET)",
            "from jasper.fritz.box (unknown\n\t[IPv6:2a00:6020:448c:6c00:560e:6da1:ef9c:32d0])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D95B5BD1;\n\tMon,  4 Mar 2024 16:59:34 +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=\"UPhvwLJP\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1709567975;\n\tbh=SglA9aiI2Su6hhoph3V88Ysn4XsICmsO7oEeQxlAmKo=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=UPhvwLJPUoBFx28nYCNTS1kyqtsUmFVrDM6SWSD3+iPnl7gD8KknNKW3pgY/L5/S3\n\tYeJ5nGL5J0Er2bXmQ4p+JjwI3PgnhBpcGBXhNNA/fraVEu5eWsfltWazpQ70HipoOG\n\t5fLj2i08GO/AqTow3zyz1Sm5gVsSwjVEHBjNvr9o=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v2] libcamera: controls: Add overwriteExisting parameter to\n\tControlList::merge",
        "Date": "Mon,  4 Mar 2024 16:58:53 +0100",
        "Message-Id": "<20240304155852.105079-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\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n\nThis version adds a unittest and fixes a doxygen doc.\n\n include/libcamera/controls.h   |  2 +-\n src/libcamera/controls.cpp     |  9 ++++--\n test/controls/control_list.cpp | 50 ++++++++++++++++++++++++++++++++++\n 3 files changed, 57 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex cf942055..0bf778d8 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -368,7 +368,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, bool overwriteExisting = false);\n \n \tbool contains(unsigned int id) const;\n \ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex b808116c..93ce4efe 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -910,10 +910,13 @@ ControlList::ControlList(const ControlInfoMap &infoMap,\n /**\n  * \\brief Merge the \\a source into the ControlList\n  * \\param[in] source The ControlList to merge into this object\n+ * \\param[in] overwriteExisting Control 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 overwriteExisting is true.\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 +924,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, bool overwriteExisting)\n {\n \t/**\n \t * \\todo ASSERT that the current and source ControlList are derived\n@@ -936,7 +939,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 (!overwriteExisting && 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..304cabfc 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, true);\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": [
        "v2"
    ]
}