Show a patch.

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

{
    "id": 20086,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20086/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20086/",
    "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": "<20240522145438.436688-5-stefan.klug@ideasonboard.com>",
    "date": "2024-05-22T14:54:38",
    "name": "[v2,4/4] pipeline: rkisp1: Implement gamma control",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "a7b83709d9c8b9034c3b4c78c9f386741f4f17b6",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20086/mbox/",
    "series": [
        {
            "id": 4321,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4321/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4321",
            "date": "2024-05-22T14:54:34",
            "name": "libcamera: Add gamma control for rkisp1",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4321/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20086/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20086/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 69AA2BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 May 2024 14:55:10 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D57AF6349D;\n\tWed, 22 May 2024 16:55:09 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 54BDF6349B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 May 2024 16:55:06 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9beb:c30d:4413:8c99])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A3B1C67;\n\tWed, 22 May 2024 16:54:53 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tQBjLyA4\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716389693;\n\tbh=l5fwIaw1q7mA3XvKAgkgqaFQ8wKVZWbfA1pzzivnB0U=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=tQBjLyA44PN/Nk8NXrjj4nPJkOwiKBugSutcnNbNereCCnxgH1xQbyprxF9TKx3Uo\n\tpWG5hym81NuRJ5DcbQPps2cJX5fzviJjA7Q31fy5HrDU4gjx6DHfBatPWlaJM7G2JO\n\t8a1uzEIYWtcla/KdQgRSMtG8Z6FhyfkC0pttSJuE=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v2 4/4] pipeline: rkisp1: Implement gamma control",
        "Date": "Wed, 22 May 2024 16:54:38 +0200",
        "Message-Id": "<20240522145438.436688-5-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.40.1",
        "In-Reply-To": "<20240522145438.436688-1-stefan.klug@ideasonboard.com>",
        "References": "<20240522145438.436688-1-stefan.klug@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 support for the gamma control on the rkisp1. This was tested on\nan imx8mp.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/goc.cpp | 77 +++++++++++++++++++++++++++----\n src/ipa/rkisp1/algorithms/goc.h   | 11 ++++-\n src/ipa/rkisp1/ipa_context.h      |  4 ++\n 3 files changed, 81 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp\nindex 6f313820..0b312e7a 100644\n--- a/src/ipa/rkisp1/algorithms/goc.cpp\n+++ b/src/ipa/rkisp1/algorithms/goc.cpp\n@@ -11,6 +11,8 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n+#include <libcamera/control_ids.h>\n+\n #include \"libcamera/internal/yaml_parser.h\"\n \n #include \"linux/rkisp1-config.h\"\n@@ -41,6 +43,7 @@ namespace ipa::rkisp1::algorithms {\n LOG_DEFINE_CATEGORY(RkISP1Gamma)\n \n Gamma::Gamma()\n+\t: gamma_(0)\n {\n }\n \n@@ -50,6 +53,8 @@ Gamma::Gamma()\n int Gamma::init([[maybe_unused]] IPAContext &context,\n \t\t[[maybe_unused]] const YamlObject &tuningData)\n {\n+\tcontext.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, 2.2f);\n+\n \tif (context.hw->numGammaOutSamples !=\n \t    RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10) {\n \t\tLOG(RkISP1Gamma, Error)\n@@ -60,6 +65,41 @@ int Gamma::init([[maybe_unused]] IPAContext &context,\n \treturn 0;\n }\n \n+/**\n+ * \\brief Configure the Gamma given a configInfo\n+ * \\param[in] context The shared IPA context\n+ * \\param[in] configInfo The IPA configuration data\n+ *\n+ * \\return 0\n+ */\n+int Gamma::configure(IPAContext &context,\n+\t\t     [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\tcontext.activeState.gamma = 2.2;\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Gamma::queueRequest([[maybe_unused]] IPAContext &context,\n+\t\t\t [[maybe_unused]] const uint32_t frame,\n+\t\t\t IPAFrameContext &frameContext,\n+\t\t\t const ControlList &controls)\n+{\n+\tconst auto &gamma = controls.get(controls::Gamma);\n+\tif (gamma) {\n+\t\t/* \\todo This is not correct as it updates the current state with a\n+\t\t * future value. But it does no harm at the moment an allows us to\n+\t\t * track the last active gamma\n+\t\t */\n+\t\tcontext.activeState.gamma = *gamma;\n+\t\tLOG(RkISP1Gamma, Debug) << \"Set gamma to \" << *gamma;\n+\t}\n+\n+\tframeContext.gamma = context.activeState.gamma;\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::prepare\n  */\n@@ -78,19 +118,36 @@ void Gamma::prepare([[maybe_unused]] IPAContext &context,\n \tASSERT(context.hw->numGammaOutSamples ==\n \t       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10);\n \n-\tif (frame > 0)\n-\t\treturn;\n+\tif (frame == 0 || std::fabs(frameContext.gamma - gamma_) > 0.001) {\n+\t\tgamma_ = frameContext.gamma;\n+\n+\t\tint x = 0;\n+\t\tfor (unsigned i = 0; i < context.hw->numGammaOutSamples; i++) {\n+\t\t\tgamma_y[i] = std::pow(x / 4096.0, 1.0 / gamma_) * 1023.0;\n+\t\t\tx += segments[i];\n+\t\t}\n \n-\tint x = 0;\n-\tfor (unsigned i = 0; i < context.hw->numGammaOutSamples; i++) {\n-\t\tgamma_y[i] = std::pow(x / 4096.0, 1.0 / gamma_) * 1023.0;\n-\t\tx += segments[i];\n+\t\tparams->others.goc_config.mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC;\n+\t\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_GOC;\n+\n+\t\t/* It is unclear why these bits need to be set more than once.\n+\t\t * Setting them only on frame 0 didn't apply gamma.\n+\t\t */\n+\t\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_GOC;\n+\t\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_GOC;\n \t}\n+}\n \n-\tparams->others.goc_config.mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC;\n-\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_GOC;\n-\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_GOC;\n-\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_GOC;\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::process\n+ */\n+void Gamma::process([[maybe_unused]] IPAContext &context,\n+\t\t    [[maybe_unused]] const uint32_t frame,\n+\t\t    IPAFrameContext &frameContext,\n+\t\t    [[maybe_unused]] const rkisp1_stat_buffer *stats,\n+\t\t    ControlList &metadata)\n+{\n+\tmetadata.set(controls::Gamma, frameContext.gamma);\n }\n \n REGISTER_IPA_ALGORITHM(Gamma, \"Gamma\")\ndiff --git a/src/ipa/rkisp1/algorithms/goc.h b/src/ipa/rkisp1/algorithms/goc.h\nindex fe7caba3..f2142b55 100644\n--- a/src/ipa/rkisp1/algorithms/goc.h\n+++ b/src/ipa/rkisp1/algorithms/goc.h\n@@ -20,12 +20,21 @@ public:\n \t~Gamma() = default;\n \n \tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tint configure(IPAContext &context, const IPACameraSensorInfo &configInfo) override;\n+\tvoid queueRequest(IPAContext &context,\n+\t\t\t  const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n \tvoid prepare(IPAContext &context, const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     rkisp1_params_cfg *params) 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-\tfloat gamma_ = 2.2;\n+\tfloat gamma_;\n };\n \n } /* namespace ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex bd02a7a2..5252e222 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -104,6 +104,8 @@ struct IPAActiveState {\n \t\tuint8_t denoise;\n \t\tuint8_t sharpness;\n \t} filter;\n+\n+\tdouble gamma;\n };\n \n struct IPAFrameContext : public FrameContext {\n@@ -146,6 +148,8 @@ struct IPAFrameContext : public FrameContext {\n \t\tuint32_t exposure;\n \t\tdouble gain;\n \t} sensor;\n+\n+\tdouble gamma;\n };\n \n struct IPAContext {\n",
    "prefixes": [
        "v2",
        "4/4"
    ]
}