Show a patch.

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

{
    "id": 19323,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/19323/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19323/",
    "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": "<20231214121350.206015-9-hdegoede@redhat.com>",
    "date": "2023-12-14T12:13:46",
    "name": "[libcamera-devel,08/11] libcamera: ipa: Soft IPA: add a Simple Soft IPA implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "63a4b34d13eb204f32c0099304327d739ffe5f9d",
    "submitter": {
        "id": 102,
        "url": "https://patchwork.libcamera.org/api/1.1/people/102/?format=api",
        "name": "Hans de Goede",
        "email": "hdegoede@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19323/mbox/",
    "series": [
        {
            "id": 4117,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4117/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4117",
            "date": "2023-12-14T12:13:38",
            "name": "libcamera: introduce Software ISP and Software IPA",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4117/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19323/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19323/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 B2F0EC32BD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 14 Dec 2023 12:14:11 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6087B62B5F;\n\tThu, 14 Dec 2023 13:14:11 +0100 (CET)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B223362B3E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 14 Dec 2023 13:14:09 +0100 (CET)",
            "from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-623-RwPYhJi0NCiHur_fSx645A-1;\n\tThu, 14 Dec 2023 07:14:05 -0500",
            "from smtp.corp.redhat.com\n\t(int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ACFA3869143;\n\tThu, 14 Dec 2023 12:14:04 +0000 (UTC)",
            "from shalem.redhat.com (unknown [10.39.194.72])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 465B71121306;\n\tThu, 14 Dec 2023 12:14:03 +0000 (UTC)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1702556051;\n\tbh=cIwGSZBqCcMUmmZYG3IdVhUd/YqG/nRQW8zhG3I+T/0=;\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:Cc:\n\tFrom;\n\tb=BAqlFqwxev+GunrHEqOJMBFyUAr1alUdRBhbyHzSoF1V0sPYBIa2Isf6WDlpDG++I\n\teCbDPxVW2yy6UxhaPMoIkXE9PHq3GHSin35dnx96sG1EW9jMiJ0hWcnmOtVh+vVEjY\n\teXdLaSdzPBUmvnYUEKEInvkQJy01Whvy4Hm4jXMsuqahyuFskzLXOV1ifpSoEIxd9F\n\turyWLdlEG1yJhNmccTE0zOmoLa4hS5m2suI7uyC2m1FeUbtVawsJkvXjZ756vw1MnY\n\t2hfe56kRrZ+XG5h9mhpVeSUKZGbz1LFt9WXuYAMM3MTjcNhOd98fL1nDiMxcnEOxmO\n\tJShqRCKKxYC2w==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1702556048;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=cf2qmq/dunTCI05CWmbCUZkFsIFiXs+iFv8ck+8fkuI=;\n\tb=foubqEjNJYT+pNsPgsm8/RF2B/lIxPwrzMSZJu7vSWneUhbTtVgpdVynErFbw0PJKOOFCr\n\tXrTaLPXtQFY0otgDfl4dsxgNHUO4h+W8hX39FspFcRwvjsB7rIi/EvsmmnRCx+zm1xaZWq\n\tGRVTouNoV2iwC0whmGqmMGBjF/D9GU8="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"foubqEjN\"; \n\tdkim-atps=neutral",
        "X-MC-Unique": "RwPYhJi0NCiHur_fSx645A-1",
        "To": "libcamera-devel@lists.libcamera.org,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>",
        "Date": "Thu, 14 Dec 2023 13:13:46 +0100",
        "Message-ID": "<20231214121350.206015-9-hdegoede@redhat.com>",
        "In-Reply-To": "<20231214121350.206015-1-hdegoede@redhat.com>",
        "References": "<20231214121350.206015-1-hdegoede@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.3",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "Subject": "[libcamera-devel] [PATCH 08/11] libcamera: ipa: Soft IPA: add a\n\tSimple Soft IPA implementation",
        "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": "Hans de Goede via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Hans de Goede <hdegoede@redhat.com>",
        "Cc": "Maxime Ripard <mripard@redhat.com>, g.martti@gmail.com,\n\tt.langendam@gmail.com, srinivas.kandagatla@linaro.org,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>, admin@dennisbonke.com",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "From: Andrey Konovalov <andrey.konovalov@linaro.org>\n\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\n---\n meson_options.txt                      |   3 +-\n src/ipa/simple/meson.build             |   9 ++\n src/ipa/simple/simple/data/meson.build |   9 ++\n src/ipa/simple/simple/data/soft.conf   |   3 +\n src/ipa/simple/simple/meson.build      |  26 +++\n src/ipa/simple/simple/soft_simple.cpp  | 210 +++++++++++++++++++++++++\n 6 files changed, 259 insertions(+), 1 deletion(-)\n create mode 100644 src/ipa/simple/simple/data/meson.build\n create mode 100644 src/ipa/simple/simple/data/soft.conf\n create mode 100644 src/ipa/simple/simple/meson.build\n create mode 100644 src/ipa/simple/simple/soft_simple.cpp",
    "diff": "diff --git a/meson_options.txt b/meson_options.txt\nindex 5fdc7be8..8ec08658 100644\n--- a/meson_options.txt\n+++ b/meson_options.txt\n@@ -27,7 +27,7 @@ option('gstreamer',\n \n option('ipas',\n         type : 'array',\n-        choices : ['ipu3', 'rkisp1', 'rpi/vc4', 'vimc'],\n+        choices : ['ipu3', 'rkisp1', 'rpi/vc4', 'simple/simple', 'vimc'],\n         description : 'Select which IPA modules to build')\n \n option('lc-compliance',\n@@ -46,6 +46,7 @@ option('pipelines',\n             'rkisp1',\n             'rpi/vc4',\n             'simple',\n+            'simple/simple',\n             'uvcvideo',\n             'vimc'\n         ],\ndiff --git a/src/ipa/simple/meson.build b/src/ipa/simple/meson.build\nindex 9688bbdb..14be5dc2 100644\n--- a/src/ipa/simple/meson.build\n+++ b/src/ipa/simple/meson.build\n@@ -1,3 +1,12 @@\n # SPDX-License-Identifier: CC0-1.0\n \n subdir('common')\n+\n+foreach pipeline : pipelines\n+    pipeline = pipeline.split('/')\n+    if pipeline.length() < 2 or pipeline[0] != 'simple'\n+        continue\n+    endif\n+\n+    subdir(pipeline[1])\n+endforeach\ndiff --git a/src/ipa/simple/simple/data/meson.build b/src/ipa/simple/simple/data/meson.build\nnew file mode 100644\nindex 00000000..33548cc6\n--- /dev/null\n+++ b/src/ipa/simple/simple/data/meson.build\n@@ -0,0 +1,9 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+conf_files = files([\n+    'soft.conf',\n+])\n+\n+install_data(conf_files,\n+             install_dir : ipa_data_dir / 'soft',\n+             install_tag : 'runtime')\ndiff --git a/src/ipa/simple/simple/data/soft.conf b/src/ipa/simple/simple/data/soft.conf\nnew file mode 100644\nindex 00000000..0c70e7c0\n--- /dev/null\n+++ b/src/ipa/simple/simple/data/soft.conf\n@@ -0,0 +1,3 @@\n+# SPDX-License-Identifier: LGPL-2.1-or-later\n+#\n+# Dummy configuration file for the soft IPA.\ndiff --git a/src/ipa/simple/simple/meson.build b/src/ipa/simple/simple/meson.build\nnew file mode 100644\nindex 00000000..8b5d76b5\n--- /dev/null\n+++ b/src/ipa/simple/simple/meson.build\n@@ -0,0 +1,26 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+ipa_name = 'ipa_soft_simple'\n+\n+mod = shared_module(ipa_name,\n+                    ['soft_simple.cpp', libcamera_generated_ipa_headers],\n+                    name_prefix : '',\n+                    include_directories : [ipa_includes, libipa_includes, '..'],\n+                    dependencies : libcamera_private,\n+                    link_with : libipa,\n+                    link_whole : soft_ipa_common_lib,\n+                    install : true,\n+                    install_dir : ipa_install_dir)\n+\n+if ipa_sign_module\n+    custom_target(ipa_name + '.so.sign',\n+                  input : mod,\n+                  output : ipa_name + '.so.sign',\n+                  command : [ipa_sign, ipa_priv_key, '@INPUT@', '@OUTPUT@'],\n+                  install : false,\n+                  build_by_default : true)\n+endif\n+\n+subdir('data')\n+\n+ipa_names += ipa_name\ndiff --git a/src/ipa/simple/simple/soft_simple.cpp b/src/ipa/simple/simple/soft_simple.cpp\nnew file mode 100644\nindex 00000000..77be4f91\n--- /dev/null\n+++ b/src/ipa/simple/simple/soft_simple.cpp\n@@ -0,0 +1,210 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2023, Linaro Ltd\n+ *\n+ * soft_simple.cpp - Simple Software Image Processing Algorithm module\n+ */\n+\n+#include <sys/mman.h>\n+\n+#include <libcamera/base/file.h>\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/control_ids.h>\n+\n+#include <libcamera/ipa/ipa_interface.h>\n+#include <libcamera/ipa/ipa_module_info.h>\n+\n+#include \"libcamera/internal/camera_sensor.h\"\n+#include \"libcamera/internal/software_isp/swisp_stats.h\"\n+\n+#include \"common/soft_base.h\"\n+\n+namespace libcamera {\n+\n+LOG_DECLARE_CATEGORY(IPASoft)\n+\n+namespace ipa::soft {\n+\n+class IPASoftSimple final : public IPASoftBase\n+{\n+public:\n+\tIPASoftSimple()\n+\t\t: IPASoftBase(), ignore_updates_(0)\n+\t{\n+\t}\n+\n+\t~IPASoftSimple()\n+\t{\n+\t\tif (stats_)\n+\t\t\tmunmap(stats_, sizeof(SwIspStats));\n+\t}\n+\n+\tint platformInit(const ControlInfoMap &sensorInfoMap) override;\n+\tint platformConfigure(const ControlInfoMap &sensorInfoMap) override;\n+\tint platformStart() override;\n+\tvoid platformStop() override;\n+\tvoid platformProcessStats(const ControlList &sensorControls) override;\n+\n+private:\n+\tvoid update_exposure(double ev_adjustment);\n+\n+\tSwIspStats *stats_;\n+\tint exposure_min_, exposure_max_;\n+\tint again_min_, again_max_;\n+\tint again_, exposure_;\n+\tint ignore_updates_;\n+};\n+\n+int IPASoftSimple::platformInit(const ControlInfoMap &sensorInfoMap)\n+{\n+\tstats_ = static_cast<SwIspStats *>(mmap(nullptr, sizeof(SwIspStats),\n+\t\t\t\t\t\tPROT_READ | PROT_WRITE, MAP_SHARED,\n+\t\t\t\t\t\tfdStats_.get(), 0));\n+\tif (!stats_) {\n+\t\tLOG(IPASoft, Error) << \"Unable to map Statistics\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tif (sensorInfoMap.find(V4L2_CID_EXPOSURE) == sensorInfoMap.end()) {\n+\t\tLOG(IPASoft, Error) << \"Don't have exposure control\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (sensorInfoMap.find(V4L2_CID_ANALOGUE_GAIN) == sensorInfoMap.end()) {\n+\t\tLOG(IPASoft, Error) << \"Don't have gain control\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int IPASoftSimple::platformConfigure(const ControlInfoMap &sensorInfoMap)\n+{\n+\tconst ControlInfo &exposure_info = sensorInfoMap.find(V4L2_CID_EXPOSURE)->second;\n+\tconst ControlInfo &gain_info = sensorInfoMap.find(V4L2_CID_ANALOGUE_GAIN)->second;\n+\n+\texposure_min_ = exposure_info.min().get<int>();\n+\tif (!exposure_min_) {\n+\t\tLOG(IPASoft, Warning) << \"Minimum exposure is zero, that can't be linear\";\n+\t\texposure_min_ = 1;\n+\t}\n+\texposure_max_ = exposure_info.max().get<int>();\n+\tagain_min_ = gain_info.min().get<int>();\n+\tif (!again_min_) {\n+\t\tLOG(IPASoft, Warning) << \"Minimum gain is zero, that can't be linear\";\n+\t\tagain_min_ = 100;\n+\t}\n+\tagain_max_ = gain_info.max().get<int>();\n+\n+\tLOG(IPASoft, Info) << \"Exposure \" << exposure_min_ << \"-\" << exposure_max_\n+\t\t\t   << \", gain \" << again_min_ << \"-\" << again_max_;\n+\n+\treturn 0;\n+}\n+\n+int IPASoftSimple::platformStart()\n+{\n+\treturn 0;\n+}\n+\n+void IPASoftSimple::platformStop()\n+{\n+}\n+\n+void IPASoftSimple::platformProcessStats(const ControlList &sensorControls)\n+{\n+\tdouble ev_adjustment = 0.0;\n+\tControlList ctrls(sensorControls);\n+\n+\t/*\n+\t * Use 2 frames delay to make sure that the exposure and the gain set\n+\t * have applied to the camera sensor\n+\t */\n+\tif (ignore_updates_ > 0) {\n+\t\tLOG(IPASoft, Debug) << \"Skipping exposure update: \"\n+\t\t\t\t    << ignore_updates_;\n+\t\t--ignore_updates_;\n+\t\treturn;\n+\t}\n+\n+\tif (stats_->bright_ratio < 0.01)\n+\t\tev_adjustment = 1.1;\n+\tif (stats_->too_bright_ratio > 0.04)\n+\t\tev_adjustment = 0.9;\n+\n+\tif (ev_adjustment != 0.0) {\n+\t\t/* sanity check */\n+\t\tif (!sensorControls.contains(V4L2_CID_EXPOSURE) ||\n+\t\t    !sensorControls.contains(V4L2_CID_ANALOGUE_GAIN)) {\n+\t\t\tLOG(IPASoft, Error) << \"Control(s) missing\";\n+\t\t\treturn;\n+\t\t}\n+\n+\t\texposure_ = ctrls.get(V4L2_CID_EXPOSURE).get<int>();\n+\t\tagain_ = ctrls.get(V4L2_CID_ANALOGUE_GAIN).get<int>();\n+\n+\t\tupdate_exposure(ev_adjustment);\n+\n+\t\tctrls.set(V4L2_CID_EXPOSURE, exposure_);\n+\t\tctrls.set(V4L2_CID_ANALOGUE_GAIN, again_);\n+\n+\t\tignore_updates_ = 2;\n+\n+\t\tsetSensorControls.emit(ctrls);\n+\t}\n+}\n+\n+void IPASoftSimple::update_exposure(double ev_adjustment)\n+{\n+\tdouble exp = (double)exposure_;\n+\tdouble gain = (double)again_;\n+\tdouble ev = ev_adjustment * exp * gain;\n+\n+\t/*\n+\t * Try to use the minimal possible analogue gain.\n+\t * The exposure can be any value from exposure_min_ to exposure_max_,\n+\t * and normally this should keep the frame rate intact.\n+\t */\n+\n+\texp = ev / again_min_;\n+\tif (exp > exposure_max_)\n+\t\texposure_ = exposure_max_;\n+\telse if (exp < exposure_min_)\n+\t\texposure_ = exposure_min_;\n+\telse\n+\t\texposure_ = (int)exp;\n+\n+\tgain = ev / exposure_;\n+\tif (gain > again_max_)\n+\t\tagain_ = again_max_;\n+\telse if (gain < again_min_)\n+\t\tagain_ = again_min_;\n+\telse\n+\t\tagain_ = (int)gain;\n+\n+\tLOG(IPASoft, Debug) << \"Desired EV = \" << ev\n+\t\t\t    << \", real EV = \" << (double)again_ * exposure_;\n+}\n+\n+} /* namespace ipa::soft */\n+\n+/*\n+ * External IPA module interface\n+ */\n+extern \"C\" {\n+const struct IPAModuleInfo ipaModuleInfo = {\n+\tIPA_MODULE_API_VERSION,\n+\t0,\n+\t\"SimplePipelineHandler\",\n+\t\"soft/simple\",\n+};\n+\n+IPAInterface *ipaCreate()\n+{\n+\treturn new ipa::soft::IPASoftSimple();\n+}\n+\n+} /* extern \"C\" */\n+\n+} /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "08/11"
    ]
}