Show a patch.

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

{
    "id": 22390,
    "url": "https://patchwork.libcamera.org/api/patches/22390/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/22390/",
    "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": "<20241218074601.3552093-3-paul.elder@ideasonboard.com>",
    "date": "2024-12-18T07:46:01",
    "name": "[v3,2/2] ipa: rkisp1: Add Lux algorithm module",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "6f6d7cb528521b5fd69011e93b0d021ac8986a75",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/22390/mbox/",
    "series": [
        {
            "id": 4909,
            "url": "https://patchwork.libcamera.org/api/series/4909/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4909",
            "date": "2024-12-18T07:45:59",
            "name": "ipa: rkisp1: Add lux estimation",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/4909/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/22390/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/22390/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 A3FF3C3301\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Dec 2024 07:46:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 563DF6808F;\n\tWed, 18 Dec 2024 08:46:29 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BF25868087\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Dec 2024 08:46:24 +0100 (CET)",
            "from neptunite.hamster-moth.ts.net (unknown\n\t[IPv6:2404:7a81:160:2100:6d4:c4ff:fe49:f0b3])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C22534D;\n\tWed, 18 Dec 2024 08:45:45 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"pysREpFw\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734507947;\n\tbh=2oaId2rbD8SZH/CsaKO7kqww85mU9sprEf53Ie62oyc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=pysREpFwtwvn5oqSWdqyU3yT7FCeJI0voKNnqS9DnPYPiLBavYlsZOjiMKVymmRob\n\tOuQX2qJew7HtDYUT5Rj86YuBA6RvwjMoonazobw+HzpLUWiIzVa5AbceS40doh0BjP\n\tb4/jIrS+k0LL+5XGkIPCqQB+cQXVLVque9BtJgu8=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com, \n\tstefan.klug@ideasonboard.com",
        "Cc": "Paul Elder <paul.elder@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>",
        "Subject": "[PATCH v3 2/2] ipa: rkisp1: Add Lux algorithm module",
        "Date": "Wed, 18 Dec 2024 16:46:01 +0900",
        "Message-Id": "<20241218074601.3552093-3-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.39.2",
        "In-Reply-To": "<20241218074601.3552093-1-paul.elder@ideasonboard.com>",
        "References": "<20241218074601.3552093-1-paul.elder@ideasonboard.com>",
        "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": "Add a lux algorithm module to rkisp1 IPA for estimating the lux level of\nan image. This is reported in metadata, as well as saved in the frame\ncontext so that other algorithms (mainly AGC) can use its value. It does\nnot set any controls.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nChanges in v3:\n- remove unnecessary includes\n- replace ipa::Lux::bitSize() with ipa::Lux::Lux()\n- move frameContext.agc.lux to frameContext.lux.lux\n\nChanges in v2:\n- fix bitrot\n- fixes corresponding to changes in the previous patch\n---\n src/ipa/rkisp1/algorithms/lux.cpp     | 80 +++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/lux.h       | 36 ++++++++++++\n src/ipa/rkisp1/algorithms/meson.build |  1 +\n src/ipa/rkisp1/ipa_context.h          |  4 ++\n 4 files changed, 121 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/lux.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/lux.h",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/lux.cpp b/src/ipa/rkisp1/algorithms/lux.cpp\nnew file mode 100644\nindex 000000000000..a1e3f36b75cb\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/lux.cpp\n@@ -0,0 +1,80 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * lux.cpp - RkISP1 Lux control\n+ */\n+\n+#include \"lux.h\"\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/control_ids.h>\n+\n+#include \"libipa/histogram.h\"\n+#include \"libipa/lux.h\"\n+\n+/**\n+ * \\file lux.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class Lux\n+ * \\brief RkISP1 Lux control\n+ *\n+ * The Lux algorithm is responsible for estimating the lux level of the image.\n+ * It doesn't take or generate any controls, but it provides a lux level for\n+ * other algorithms (such as AGC) to use.\n+ */\n+\n+/**\n+ * \\brief Construct an rkisp1 Lux algo module\n+ *\n+ * The Lux helper is initialized to 65535 as that is the max bin count on the\n+ * rkisp1.\n+ */\n+Lux::Lux()\n+\t: lux_(65535)\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int Lux::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData)\n+{\n+\treturn lux_.parseTuningData(tuningData);\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::process\n+ */\n+void Lux::process(IPAContext &context,\n+\t\t  [[maybe_unused]] const uint32_t frame,\n+\t\t  IPAFrameContext &frameContext,\n+\t\t  const rkisp1_stat_buffer *stats,\n+\t\t  ControlList &metadata)\n+{\n+\tutils::Duration exposureTime = context.configuration.sensor.lineDuration\n+\t\t\t\t       * frameContext.sensor.exposure;\n+\tdouble gain = frameContext.sensor.gain;\n+\n+\t/* \\todo Deduplicate the histogram calculation from AGC */\n+\tconst rkisp1_cif_isp_stat *params = &stats->params;\n+\tHistogram yHist({ params->hist.hist_bins, context.hw->numHistogramBins },\n+\t\t\t[](uint32_t x) { return x >> 4; });\n+\n+\tdouble lux = lux_.estimateLux(exposureTime, gain, 1.0, yHist);\n+\tframeContext.lux.lux = lux;\n+\tmetadata.set(controls::Lux, lux);\n+}\n+\n+REGISTER_IPA_ALGORITHM(Lux, \"Lux\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/lux.h b/src/ipa/rkisp1/algorithms/lux.h\nnew file mode 100644\nindex 000000000000..8a90de55b8ff\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/lux.h\n@@ -0,0 +1,36 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * lux.h - RkISP1 Lux control\n+ */\n+\n+#pragma once\n+\n+#include <sys/types.h>\n+\n+#include \"libipa/lux.h\"\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class Lux : public Algorithm\n+{\n+public:\n+\tLux();\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tvoid process(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     const rkisp1_stat_buffer *stats,\n+\t\t     ControlList &metadata) override;\n+\n+private:\n+\tipa::Lux lux_;\n+};\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nindex 1734a6675f78..c66b0b70b82f 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -12,4 +12,5 @@ rkisp1_ipa_algorithms = files([\n     'goc.cpp',\n     'gsl.cpp',\n     'lsc.cpp',\n+    'lux.cpp',\n ])\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex deb8c196f1b8..65ba45151611 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -168,6 +168,10 @@ struct IPAFrameContext : public FrameContext {\n \tstruct {\n \t\tMatrix<float, 3, 3> ccm;\n \t} ccm;\n+\n+\tstruct {\n+\t\tdouble lux;\n+\t} lux;\n };\n \n struct IPAContext {\n",
    "prefixes": [
        "v3",
        "2/2"
    ]
}