Patch Detail
Show a patch.
GET /api/1.1/patches/19492/?format=api
{ "id": 19492, "url": "https://patchwork.libcamera.org/api/1.1/patches/19492/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19492/", "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": "<20240214170122.60754-10-hdegoede@redhat.com>", "date": "2024-02-14T17:01:13", "name": "[v3,09/16] libcamera: ipa: add Soft IPA", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "426f99b7bb5bcd5aebed064f1bce16a3ea4ce9b2", "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/19492/mbox/", "series": [ { "id": 4167, "url": "https://patchwork.libcamera.org/api/1.1/series/4167/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4167", "date": "2024-02-14T17:01:04", "name": "libcamera: introduce Software ISP and Software IPA", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4167/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19492/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19492/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 53C41C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Feb 2024 17:01:53 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0E8F86281D;\n\tWed, 14 Feb 2024 18:01:53 +0100 (CET)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 650C06281D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Feb 2024 18:01:50 +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-90-YOvft-x6PcuOWdxW15C7VQ-1;\n\tWed, 14 Feb 2024 12:01:45 -0500", "from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6])\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 C42FC3812598;\n\tWed, 14 Feb 2024 17:01:44 +0000 (UTC)", "from localhost.localdomain (unknown [10.39.192.30])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 6578B2166B36;\n\tWed, 14 Feb 2024 17:01:43 +0000 (UTC)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"H4YXYq8z\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1707930109;\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=gIQhxW3w/53Ckvuk7cyWBxWVHyxt8StT+ZFP5d5nbUo=;\n\tb=H4YXYq8z2x0K6tsGR+fXs05PlIAi4DTeMdXgrKr/qWY+vEL4SFUooqvkcLcHrP4sIPhKqC\n\t2yb58QK0iPKkPfuP5mLI1NRlc1ygB3mB+FnhmyeDt20q851Tz3bAdlI2UTTeP9QvSfHB+c\n\tTVLTn+yHAR4INKr6oGapvRGBR7G6RNg=", "X-MC-Unique": "YOvft-x6PcuOWdxW15C7VQ-1", "From": "Hans de Goede <hdegoede@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v3 09/16] libcamera: ipa: add Soft IPA", "Date": "Wed, 14 Feb 2024 18:01:13 +0100", "Message-ID": "<20240214170122.60754-10-hdegoede@redhat.com>", "In-Reply-To": "<20240214170122.60754-1-hdegoede@redhat.com>", "References": "<20240214170122.60754-1-hdegoede@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.6", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true", "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>", "Cc": "Maxime Ripard <mripard@redhat.com>, Marttico <g.martti@gmail.com>,\n\tToon Langendam <t.langendam@gmail.com>, Pavel Machek <pavel@ucw.cz>, \n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tDennis Bonke <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\nDefine the Soft IPA main and event interfaces, add the Soft IPA\nimplementation.\n\nThe current src/ipa/meson.build assumes the IPA name to match the\npipeline name. For this reason \"-Dipas=simple\" is used for the\nSoft IPA module.\n\nAuto exposure/gain and AWB implementation by Dennis, Toon and Martti.\n\nAuto exposure/gain targets a Mean Sample Value of 2.5 following\nthe MSV calculation algorithm from:\nhttps://www.araa.asn.au/acra/acra2007/papers/paper84final.pdf\n\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\nReviewed-by: Pavel Machek <pavel@ucw.cz>\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nCo-developed-by: Dennis Bonke <admin@dennisbonke.com>\nSigned-off-by: Dennis Bonke <admin@dennisbonke.com>\nCo-developed-by: Marttico <g.martti@gmail.com>\nSigned-off-by: Marttico <g.martti@gmail.com>\nCo-developed-by: Toon Langendam <t.langendam@gmail.com>\nSigned-off-by: Toon Langendam <t.langendam@gmail.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\nChanges in v3:\n- Use new SwIspStats::kYHistogramSize constexpr and adjust\n the auto-exposure/-gain code so that it can deal with\n that having a different value then 16 (modify the loop\n to divide the histogram in 5 bins to not have hardcoded\n values)\n- Rename a few foo_bar symbols to fooBar\n---\n Documentation/Doxyfile.in | 1 +\n include/libcamera/ipa/meson.build | 1 +\n include/libcamera/ipa/soft.mojom | 28 +++\n meson_options.txt | 2 +-\n src/ipa/simple/data/meson.build | 9 +\n src/ipa/simple/data/soft.conf | 3 +\n src/ipa/simple/meson.build | 25 +++\n src/ipa/simple/soft_simple.cpp | 308 ++++++++++++++++++++++++++++++\n 8 files changed, 376 insertions(+), 1 deletion(-)\n create mode 100644 include/libcamera/ipa/soft.mojom\n create mode 100644 src/ipa/simple/data/meson.build\n create mode 100644 src/ipa/simple/data/soft.conf\n create mode 100644 src/ipa/simple/meson.build\n create mode 100644 src/ipa/simple/soft_simple.cpp", "diff": "diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in\nindex a86ea6c1..2be8d47b 100644\n--- a/Documentation/Doxyfile.in\n+++ b/Documentation/Doxyfile.in\n@@ -44,6 +44,7 @@ EXCLUDE = @TOP_SRCDIR@/include/libcamera/base/span.h \\\n @TOP_SRCDIR@/src/libcamera/pipeline/ \\\n @TOP_SRCDIR@/src/libcamera/tracepoints.cpp \\\n @TOP_BUILDDIR@/include/libcamera/internal/tracepoints.h \\\n+ @TOP_BUILDDIR@/include/libcamera/ipa/soft_ipa_interface.h \\\n @TOP_BUILDDIR@/src/libcamera/proxy/\n \n EXCLUDE_PATTERNS = @TOP_BUILDDIR@/include/libcamera/ipa/*_serializer.h \\\ndiff --git a/include/libcamera/ipa/meson.build b/include/libcamera/ipa/meson.build\nindex f3b4881c..3352d08f 100644\n--- a/include/libcamera/ipa/meson.build\n+++ b/include/libcamera/ipa/meson.build\n@@ -65,6 +65,7 @@ pipeline_ipa_mojom_mapping = {\n 'ipu3': 'ipu3.mojom',\n 'rkisp1': 'rkisp1.mojom',\n 'rpi/vc4': 'raspberrypi.mojom',\n+ 'simple': 'soft.mojom',\n 'vimc': 'vimc.mojom',\n }\n \ndiff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom\nnew file mode 100644\nindex 00000000..c249bd75\n--- /dev/null\n+++ b/include/libcamera/ipa/soft.mojom\n@@ -0,0 +1,28 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+\n+/*\n+ * \\todo Document the interface and remove the related EXCLUDE_PATTERNS entry.\n+ */\n+\n+module ipa.soft;\n+\n+import \"include/libcamera/ipa/core.mojom\";\n+\n+interface IPASoftInterface {\n+\tinit(libcamera.IPASettings settings,\n+\t libcamera.SharedFD fdStats,\n+\t libcamera.SharedFD fdParams,\n+\t libcamera.ControlInfoMap sensorCtrlInfoMap)\n+\t\t=> (int32 ret);\n+\tstart() => (int32 ret);\n+\tstop();\n+\tconfigure(libcamera.ControlInfoMap sensorCtrlInfoMap)\n+\t\t=> (int32 ret);\n+\n+\t[async] processStats(libcamera.ControlList sensorControls);\n+};\n+\n+interface IPASoftEventInterface {\n+\tsetSensorControls(libcamera.ControlList sensorControls);\n+\tsetIspParams(int32 dummy);\n+};\ndiff --git a/meson_options.txt b/meson_options.txt\nindex 5fdc7be8..94372e47 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', 'vimc'],\n description : 'Select which IPA modules to build')\n \n option('lc-compliance',\ndiff --git a/src/ipa/simple/data/meson.build b/src/ipa/simple/data/meson.build\nnew file mode 100644\nindex 00000000..33548cc6\n--- /dev/null\n+++ b/src/ipa/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/data/soft.conf b/src/ipa/simple/data/soft.conf\nnew file mode 100644\nindex 00000000..0c70e7c0\n--- /dev/null\n+++ b/src/ipa/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/meson.build b/src/ipa/simple/meson.build\nnew file mode 100644\nindex 00000000..3e863db7\n--- /dev/null\n+++ b/src/ipa/simple/meson.build\n@@ -0,0 +1,25 @@\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+ 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/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nnew file mode 100644\nindex 00000000..f7ac02f9\n--- /dev/null\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -0,0 +1,308 @@\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+#include <libcamera/base/shared_fd.h>\n+\n+#include <libcamera/control_ids.h>\n+#include <libcamera/controls.h>\n+\n+#include <libcamera/ipa/ipa_interface.h>\n+#include <libcamera/ipa/ipa_module_info.h>\n+#include <libcamera/ipa/soft_ipa_interface.h>\n+\n+#include \"libcamera/internal/camera_sensor.h\"\n+#include \"libcamera/internal/software_isp/debayer_params.h\"\n+#include \"libcamera/internal/software_isp/swisp_stats.h\"\n+\n+#define EXPOSURE_OPTIMAL_VALUE 2.5\n+#define EXPOSURE_SATISFACTORY_OFFSET 0.2\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(IPASoft)\n+\n+namespace ipa::soft {\n+\n+class IPASoftSimple : public ipa::soft::IPASoftInterface\n+{\n+public:\n+\tIPASoftSimple()\n+\t\t: 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\tif (params_)\n+\t\t\tmunmap(params_, sizeof(DebayerParams));\n+\t}\n+\n+\tint init(const IPASettings &settings,\n+\t\t const SharedFD &fdStats,\n+\t\t const SharedFD &fdParams,\n+\t\t const ControlInfoMap &sensorInfoMap) override;\n+\tint configure(const ControlInfoMap &sensorInfoMap) override;\n+\n+\tint start() override;\n+\tvoid stop() override;\n+\n+\tvoid processStats(const ControlList &sensorControls) override;\n+\n+private:\n+\tvoid updateExposure(double exposureMSV);\n+\n+\tSharedFD fdStats_;\n+\tSharedFD fdParams_;\n+\tDebayerParams *params_;\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::init([[maybe_unused]] const IPASettings &settings,\n+\t\t\tconst SharedFD &fdStats,\n+\t\t\tconst SharedFD &fdParams,\n+\t\t\tconst ControlInfoMap &sensorInfoMap)\n+{\n+\tfdStats_ = std::move(fdStats);\n+\tif (!fdStats_.isValid()) {\n+\t\tLOG(IPASoft, Error) << \"Invalid Statistics handle\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tfdParams_ = std::move(fdParams);\n+\tif (!fdParams_.isValid()) {\n+\t\tLOG(IPASoft, Error) << \"Invalid Parameters handle\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tparams_ = static_cast<DebayerParams *>(mmap(nullptr, sizeof(DebayerParams),\n+\t\t\t\t\t\t PROT_WRITE, MAP_SHARED,\n+\t\t\t\t\t\t fdParams_.get(), 0));\n+\tif (!params_) {\n+\t\tLOG(IPASoft, Error) << \"Unable to map Parameters\";\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tstats_ = static_cast<SwIspStats *>(mmap(nullptr, sizeof(SwIspStats),\n+\t\t\t\t\t\tPROT_READ, 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::configure(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::start()\n+{\n+\treturn 0;\n+}\n+\n+void IPASoftSimple::stop()\n+{\n+}\n+\n+void IPASoftSimple::processStats(const ControlList &sensorControls)\n+{\n+\t/*\n+\t * Calculate red and blue gains for AWB.\n+\t * Clamp max gain at 4.0, this also avoids 0 division.\n+\t */\n+\tif (stats_->sumR_ <= stats_->sumG_ / 4)\n+\t\tparams_->gainR = 1024;\n+\telse\n+\t\tparams_->gainR = 256 * stats_->sumG_ / stats_->sumR_;\n+\n+\tif (stats_->sumB_ <= stats_->sumG_ / 4)\n+\t\tparams_->gainB = 1024;\n+\telse\n+\t\tparams_->gainB = 256 * stats_->sumG_ / stats_->sumB_;\n+\n+\t/* Green gain and gamma values are fixed */\n+\tparams_->gainG = 256;\n+\tparams_->gamma = 0.5;\n+\n+\tsetIspParams.emit(0);\n+\n+\t/*\n+\t * AE / AGC, use 2 frames delay to make sure that the exposure and\n+\t * the gain set have applied to the camera sensor.\n+\t */\n+\tif (ignore_updates_ > 0) {\n+\t\t--ignore_updates_;\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Calculate Mean Sample Value (MSV) according to formula from:\n+\t * https://www.araa.asn.au/acra/acra2007/papers/paper84final.pdf\n+\t */\n+\tconstexpr unsigned int ExposureBinsCount = 5;\n+\tconstexpr unsigned int yHistValsPerBin =\n+\t\tSwIspStats::kYHistogramSize / ExposureBinsCount;\n+\tconstexpr unsigned int yHistValsPerBinMod =\n+\t\tSwIspStats::kYHistogramSize /\n+\t\t(SwIspStats::kYHistogramSize % ExposureBinsCount + 1);\n+\tint ExposureBins[ExposureBinsCount] = {};\n+\tunsigned int denom = 0;\n+\tunsigned int num = 0;\n+\n+\tfor (unsigned int i = 0; i < SwIspStats::kYHistogramSize; i++) {\n+\t\tunsigned int idx = (i - (i / yHistValsPerBinMod)) / yHistValsPerBin;\n+\t\tExposureBins[idx] += stats_->yHistogram[i];\n+\t}\n+\n+\tfor (unsigned int i = 0; i < ExposureBinsCount; i++) {\n+\t\tLOG(IPASoft, Debug) << i << \": \" << ExposureBins[i];\n+\t\tdenom += ExposureBins[i];\n+\t\tnum += ExposureBins[i] * (i + 1);\n+\t}\n+\n+\tfloat exposureMSV = (float)num / denom;\n+\n+\t/* sanity check */\n+\tif (!sensorControls.contains(V4L2_CID_EXPOSURE) ||\n+\t !sensorControls.contains(V4L2_CID_ANALOGUE_GAIN)) {\n+\t\tLOG(IPASoft, Error) << \"Control(s) missing\";\n+\t\treturn;\n+\t}\n+\n+\tControlList ctrls(sensorControls);\n+\n+\texposure_ = ctrls.get(V4L2_CID_EXPOSURE).get<int>();\n+\tagain_ = ctrls.get(V4L2_CID_ANALOGUE_GAIN).get<int>();\n+\n+\tupdateExposure(exposureMSV);\n+\n+\tctrls.set(V4L2_CID_EXPOSURE, exposure_);\n+\tctrls.set(V4L2_CID_ANALOGUE_GAIN, again_);\n+\n+\tignore_updates_ = 2;\n+\n+\tsetSensorControls.emit(ctrls);\n+\n+\tLOG(IPASoft, Debug) << \"exposureMSV \" << exposureMSV\n+\t\t\t << \" exp \" << exposure_ << \" again \" << again_\n+\t\t\t << \" gain R/B \" << params_->gainR << \"/\" << params_->gainB;\n+}\n+\n+/* DENOMINATOR of 10 gives ~10% increment/decrement; DENOMINATOR of 5 - about ~20% */\n+#define DENOMINATOR 10\n+#define UP_NUMERATOR (DENOMINATOR + 1)\n+#define DOWN_NUMERATOR (DENOMINATOR - 1)\n+\n+void IPASoftSimple::updateExposure(double exposureMSV)\n+{\n+\tint next;\n+\n+\tif (exposureMSV < EXPOSURE_OPTIMAL_VALUE - EXPOSURE_SATISFACTORY_OFFSET) {\n+\t\tnext = exposure_ * UP_NUMERATOR / DENOMINATOR;\n+\t\tif (next - exposure_ < 1)\n+\t\t\texposure_ += 1;\n+\t\telse\n+\t\t\texposure_ = next;\n+\t\tif (exposure_ >= exposure_max_) {\n+\t\t\tnext = again_ * UP_NUMERATOR / DENOMINATOR;\n+\t\t\tif (next - again_ < 1)\n+\t\t\t\tagain_ += 1;\n+\t\t\telse\n+\t\t\t\tagain_ = next;\n+\t\t}\n+\t}\n+\n+\tif (exposureMSV > EXPOSURE_OPTIMAL_VALUE + EXPOSURE_SATISFACTORY_OFFSET) {\n+\t\tif (exposure_ == exposure_max_ && again_ != again_min_) {\n+\t\t\tnext = again_ * DOWN_NUMERATOR / DENOMINATOR;\n+\t\t\tif (again_ - next < 1)\n+\t\t\t\tagain_ -= 1;\n+\t\t\telse\n+\t\t\t\tagain_ = next;\n+\t\t} else {\n+\t\t\tnext = exposure_ * DOWN_NUMERATOR / DENOMINATOR;\n+\t\t\tif (exposure_ - next < 1)\n+\t\t\t\texposure_ -= 1;\n+\t\t\telse\n+\t\t\t\texposure_ = next;\n+\t\t}\n+\t}\n+\n+\tif (exposure_ > exposure_max_)\n+\t\texposure_ = exposure_max_;\n+\telse if (exposure_ < exposure_min_)\n+\t\texposure_ = exposure_min_;\n+\n+\tif (again_ > again_max_)\n+\t\tagain_ = again_max_;\n+\telse if (again_ < again_min_)\n+\t\tagain_ = again_min_;\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\"simple\",\n+};\n+\n+IPAInterface *ipaCreate()\n+{\n+\treturn new ipa::soft::IPASoftSimple();\n+}\n+\n+} /* extern \"C\" */\n+\n+} /* namespace libcamera */\n", "prefixes": [ "v3", "09/16" ] }