Show a patch.

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

{
    "id": 20083,
    "url": "https://patchwork.libcamera.org/api/patches/20083/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20083/",
    "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": "<20240522145438.436688-2-stefan.klug@ideasonboard.com>",
    "date": "2024-05-22T14:54:35",
    "name": "[v2,1/4] ipa: rkisp1: Add gamma algorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "e729419c7558f25e95685f9378e67f4494226931",
    "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/20083/mbox/",
    "series": [
        {
            "id": 4321,
            "url": "https://patchwork.libcamera.org/api/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/20083/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20083/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 EA106BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 May 2024 14:55:00 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC33263488;\n\tWed, 22 May 2024 16:55:00 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 42FEB6347E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 May 2024 16:54:58 +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 80F78ABE;\n\tWed, 22 May 2024 16:54:45 +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=\"K4xG6vq7\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716389685;\n\tbh=vU50ZsFgInLrlSla/2zLTIVrqgC7JylGxZgiT52A1ZA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=K4xG6vq7J6osOPnfK95y+bNc/05pyuNRVEogHrc27H2wZthBjv+5beKM80tFs1XN1\n\tXNthsoHzvndCvBrhoQKR0sZ38QDBV84rc3jpdjzfHruM3+w4VenGoBnNBCQ/l15fD7\n\tV1jN5KBldzpxTJMZz0qMj+VMMEPlqkOv3G4T/IEQ=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v2 1/4] ipa: rkisp1: Add gamma algorithm",
        "Date": "Wed, 22 May 2024 16:54:35 +0200",
        "Message-Id": "<20240522145438.436688-2-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 a gamma algorithm for the rkisp1. It defaults to a gamma of 2.2 which\nclosely resembles sRGB.  No seperate sRGB mode was implemented because the pwl\nthat models the gamma curve is so coarse that there is basically no difference\nbetween srgb and gamma=2.2\n\nThe gamma algorithm is not enabled by default. This will be done in future\ntuning file updates.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n\nNote:\n\nThis patch breaks the naming conventions. It is implemented inside goc.h/cpp\nbecause the hardware block and params inside the rkisp1 are called \"goc\". The\nclass itself is called Gamma, and the algorithm is registered with the name\n\"Gamma\". The idea was that similar functionalities should be named the same\ninside the tuning files (even among multipe isps).  It still feels a bit\nawkward. So thoughts are welcome :-)\n\n\nv1 -> v2:\n- fixed some style issues\n- fail in case of a V12 isp\n\n src/ipa/rkisp1/algorithms/goc.cpp     | 100 ++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/goc.h       |  32 +++++++++\n src/ipa/rkisp1/algorithms/meson.build |   1 +\n 3 files changed, 133 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/goc.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/goc.h",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp\nnew file mode 100644\nindex 00000000..6f313820\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/goc.cpp\n@@ -0,0 +1,100 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * RkISP1 Gamma out control\n+ */\n+#include \"goc.h\"\n+\n+#include <cmath>\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+#include \"linux/rkisp1-config.h\"\n+\n+/**\n+ * \\file goc.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class Gamma\n+ * \\brief RkISP1 Gamma out control\n+ *\n+ * This algorithm implements the gamma out curve for the RkISP1.\n+ * It defaults to a gamma value of 2.2\n+ * As gamma is internally represented as a piecewise linear function with only\n+ * 16 knots, the difference between gamma=2.2 and sRGB gamma is minimal.\n+ * Therefore sRGB gamma was not implemented as special case.\n+ *\n+ * Useful links:\n+ * https://www.cambridgeincolour.com/tutorials/gamma-correction.htm\n+ * https://en.wikipedia.org/wiki/SRGB\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Gamma)\n+\n+Gamma::Gamma()\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int Gamma::init([[maybe_unused]] IPAContext &context,\n+\t\t[[maybe_unused]] const YamlObject &tuningData)\n+{\n+\tif (context.hw->numGammaOutSamples !=\n+\t    RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10) {\n+\t\tLOG(RkISP1Gamma, Error)\n+\t\t\t<< \"Gamma is not implemented for RkISP1 V12\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Gamma::prepare([[maybe_unused]] IPAContext &context,\n+\t\t    const uint32_t frame,\n+\t\t    [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t    rkisp1_params_cfg *params)\n+{\n+\t/* The logarithmic segments as specified in the reference.\n+\t * Plus an additional 0 to make the loop easier\n+\t */\n+\tint segments[] = { 64, 64, 64, 64, 128, 128, 128, 128, 256, 256, 256,\n+\t\t\t   512, 512, 512, 512, 512, 0 };\n+\tauto gamma_y = params->others.goc_config.gamma_y;\n+\n+\tASSERT(context.hw->numGammaOutSamples ==\n+\t       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10);\n+\n+\tif (frame > 0)\n+\t\treturn;\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}\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+\n+REGISTER_IPA_ALGORITHM(Gamma, \"Gamma\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/goc.h b/src/ipa/rkisp1/algorithms/goc.h\nnew file mode 100644\nindex 00000000..fe7caba3\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/goc.h\n@@ -0,0 +1,32 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * RkISP1 Gamma out control\n+ */\n+\n+#pragma once\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class Gamma : public Algorithm\n+{\n+public:\n+\tGamma();\n+\t~Gamma() = default;\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     rkisp1_params_cfg *params) override;\n+\n+private:\n+\tfloat gamma_ = 2.2;\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 93a48329..6ee71a9b 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -8,6 +8,7 @@ rkisp1_ipa_algorithms = files([\n     'dpcc.cpp',\n     'dpf.cpp',\n     'filter.cpp',\n+    'goc.cpp',\n     'gsl.cpp',\n     'lsc.cpp',\n ])\n",
    "prefixes": [
        "v2",
        "1/4"
    ]
}