Show a patch.

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

{
    "id": 27069,
    "url": "https://patchwork.libcamera.org/api/patches/27069/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/27069/",
    "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": "<20260626-ipu3-libipa-rework-v2-9-41546e23de3e@ideasonboard.com>",
    "date": "2026-06-26T13:05:56",
    "name": "[v2,09/12] ipa: rkisp1: goc: Re-work to use GammaAlgorithm class",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "97faa9b3beb7679d97f7f66d6ec4875e7c778419",
    "submitter": {
        "id": 156,
        "url": "https://patchwork.libcamera.org/api/people/156/?format=api",
        "name": "Dan Scally",
        "email": "dan.scally@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/27069/mbox/",
    "series": [
        {
            "id": 6022,
            "url": "https://patchwork.libcamera.org/api/series/6022/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=6022",
            "date": "2026-06-26T13:05:47",
            "name": "libipa: Re-work IPU3 IPA to use libipa algorithms",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/6022/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/27069/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/27069/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 0CAC5C330A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Jun 2026 13:06:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B842D65F11;\n\tFri, 26 Jun 2026 15:06:19 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F7ED65EF6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2026 15:06:07 +0200 (CEST)",
            "from [127.0.1.1]\n\t(chfd-03-b2-v4wan-176392-cust229.vm15.cable.virginm.net\n\t[82.19.20.230])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6AA2219EC;\n\tFri, 26 Jun 2026 15:05:26 +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=\"ama2Y2HT\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782479126;\n\tbh=msbC9/WWRfcIej2bHzjxQUvbu1GUuXBibfEkb53E2ao=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=ama2Y2HTYSEmuZMLJtnipxwOu+c/Oo+HVFqJtuxUwLzoeK8U3JQPn8CHjoTWTPvuE\n\tIP4Pza9IQV/KQUPWN+YvfqTnSvNvvUktfPjhdwRLTlL9I+qgaAlrREaYjSQaQaCFGL\n\tXjekcFaiS+EpIIaBAXwjhoRpgThR36cDVUr+2kvo=",
        "From": "Daniel Scally <dan.scally@ideasonboard.com>",
        "Date": "Fri, 26 Jun 2026 14:05:56 +0100",
        "Subject": "[PATCH v2 09/12] ipa: rkisp1: goc: Re-work to use GammaAlgorithm\n\tclass",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "7bit",
        "Message-Id": "<20260626-ipu3-libipa-rework-v2-9-41546e23de3e@ideasonboard.com>",
        "References": "<20260626-ipu3-libipa-rework-v2-0-41546e23de3e@ideasonboard.com>",
        "In-Reply-To": "<20260626-ipu3-libipa-rework-v2-0-41546e23de3e@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Daniel Scally <dan.scally@ideasonboard.com>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>",
        "X-Mailer": "b4 0.14.2",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=6650;\n\ti=dan.scally@ideasonboard.com; h=from:subject:message-id;\n\tbh=msbC9/WWRfcIej2bHzjxQUvbu1GUuXBibfEkb53E2ao=;\n\tb=owEBbQKS/ZANAwAKAchJV3psRXUyAcsmYgBqPnk7nRGYoCySX05TI85PcWA/fffVeyeTyXbQ8\n\t7RkqUyuz3yJAjMEAAEKAB0WIQQqyuwyDnZdb+mxmm/ISVd6bEV1MgUCaj55OwAKCRDISVd6bEV1\n\tMgDFEACMXlfBgcu++uMkLg4FfvjVSUw1wtNmQcXrSVKcbfYp802NFUq5kk8X6XL/pxY55/mtjU9\n\tPXikAsoirw7vU26g9+PUhSCUCz8/ZD/wp/BJ1LpxMCNoB4ackQyMCWoQypmQ/R7TRID4Pihv/9I\n\tbYcZjSOKkm76UMNlPrTWO0RkFSnEUXf7Y4WofvR4cfwfdCwxvAqqtDuFerpzZo/Bha2eahcD/5q\n\tLWFkfCvz28yZZmhzI2HYAPp195G/klul6minBV7H3QgV8c44hjcAGfbdA6i+P6oACtHP6+xfTDS\n\twS2QkG7Eku68zd5pPbpdfeIBxGRsytWbadqRPVqCwBLd/zdar9onjlNPFqxrvFmxXGKjVf1k0bd\n\t+pEKjDoDh/EmFuJjefHOy7tRrrCvfp3cMbr7qXlRFTCMYV1+Bv6ilfvU9djeqpxtVCgn57Im8dd\n\tTxnoVg5CnO2h702dw0B3RpV04p+lhHZ4M3HL4uNbTirgW1MZQg6rwGpFlOeysZJla4n1qW3ELTv\n\tmU1u2B5meaUc+EW6bUqqhURofPFaLDnnu4Bija0NqKgTkdl65pxpzNXr8xT6YucF+RJ8XPghwaO\n\tTyDJr8U9O9T7XoLy6cZQOrr1dotHpI5GQMaUkTYblguJLrGnhSyxP8fTI2OnngKhAohinIrqDUJ\n\tMONHazMMs9P2b/A==",
        "X-Developer-Key": "i=dan.scally@ideasonboard.com; a=openpgp;\n\tfpr=EEC699ACA1B7CB5D31330C0BBD501C2A3546CCF6",
        "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": "Re-work the RkISP1 Gamma Out Correction algorithm to use the new\nGammaAlgorithm class from libipa, which allows us to share an\nimplementation with the other IPAs.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\nChanges in v2:\n\n        - Fixed includes\n\t- Dropped the comment explaining how gamma correction is\n\t  implemented - it's on libipa gamma now\n\t- Dropped unused variable kDefaultGamma\n---\n src/ipa/rkisp1/algorithms/goc.cpp | 63 +++++++++++----------------------------\n src/ipa/rkisp1/algorithms/goc.h   |  7 ++++-\n src/ipa/rkisp1/ipa_context.h      | 10 ++-----\n 3 files changed, 26 insertions(+), 54 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp\nindex e8f64bf3d5e028c2013d37b7ef9fe90b737fad5f..e3bea4bbef186dde28fdd5a3aa14b7662a9ffe69 100644\n--- a/src/ipa/rkisp1/algorithms/goc.cpp\n+++ b/src/ipa/rkisp1/algorithms/goc.cpp\n@@ -6,10 +6,11 @@\n  */\n #include \"goc.h\"\n \n+#include <array>\n #include <cmath>\n \n #include <libcamera/base/log.h>\n-#include <libcamera/base/utils.h>\n+#include <libcamera/base/span.h>\n \n #include <libcamera/control_ids.h>\n \n@@ -29,21 +30,13 @@ namespace ipa::rkisp1::algorithms {\n  * \\class GammaOutCorrection\n  * \\brief RkISP1 Gamma out correction\n  *\n- * This algorithm implements the gamma out curve for the RkISP1. It defaults to\n- * a gamma value of 2.2.\n- *\n- * As gamma is internally represented as a piecewise linear function with only\n- * 17 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+ * This algorithm implements the gamma out curve for the RkISP1 using the\n+ * libipa GammaAlgorithm class.\n  */\n \n LOG_DEFINE_CATEGORY(RkISP1Gamma)\n \n-const float kDefaultGamma = 2.2f;\n+static constexpr unsigned int kNumLutSegments = RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 - 1;\n \n /**\n  * \\copydoc libcamera::ipa::Algorithm::init\n@@ -57,10 +50,12 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData)\n \t\treturn -EINVAL;\n \t}\n \n-\tdefaultGamma_ = tuningData[\"gamma\"].get<double>(kDefaultGamma);\n-\tcontext.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, defaultGamma_);\n+\tstd::array<unsigned int, kNumLutSegments> segments = {\n+\t\t 64,  64,  64,  64, 128, 128, 128, 128,\n+\t\t256, 256, 256, 512, 512, 512, 512, 512\n+\t};\n \n-\treturn 0;\n+\treturn gammaAlgo_.init(context.ctrlMap, tuningData, segments);\n }\n \n /**\n@@ -69,7 +64,7 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData)\n int GammaOutCorrection::configure(IPAContext &context,\n \t\t\t\t  [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n {\n-\tcontext.activeState.goc.gamma = defaultGamma_;\n+\tgammaAlgo_.configure(context.activeState.gamma);\n \treturn 0;\n }\n \n@@ -80,17 +75,8 @@ void GammaOutCorrection::queueRequest(IPAContext &context, const uint32_t frame,\n \t\t\t\t      IPAFrameContext &frameContext,\n \t\t\t\t      const ControlList &controls)\n {\n-\tif (frame == 0)\n-\t\tframeContext.goc.update = true;\n-\n-\tconst auto &gamma = controls.get(controls::Gamma);\n-\tif (gamma) {\n-\t\tcontext.activeState.goc.gamma = *gamma;\n-\t\tframeContext.goc.update = true;\n-\t\tLOG(RkISP1Gamma, Debug) << \"Set gamma to \" << *gamma;\n-\t}\n-\n-\tframeContext.goc.gamma = context.activeState.goc.gamma;\n+\tgammaAlgo_.queueRequest(context.activeState.gamma, frame,\n+\t\t\t\tframeContext.gamma, controls);\n }\n \n /**\n@@ -104,29 +90,14 @@ void GammaOutCorrection::prepare(IPAContext &context,\n \tASSERT(context.hw.numGammaOutSamples ==\n \t       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10);\n \n-\tif (!frameContext.goc.update)\n+\tif (!frameContext.gamma.update)\n \t\treturn;\n \n-\t/*\n-\t * The logarithmic segments as specified in the reference.\n-\t * Plus an additional 0 to make the loop easier\n-\t */\n-\tstatic constexpr std::array<unsigned int, RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10> segments = {\n-\t\t64, 64, 64, 64, 128, 128, 128, 128, 256,\n-\t\t256, 256, 512, 512, 512, 512, 512, 0\n-\t};\n-\n \tauto config = params->block<BlockType::Goc>();\n \tconfig.setEnabled(true);\n \n-\t__u16 *gamma_y = config->gamma_y;\n-\n-\tunsigned x = 0;\n-\tfor (const auto [i, size] : utils::enumerate(segments)) {\n-\t\tgamma_y[i] = std::pow(x / 4096.0, 1.0 / frameContext.goc.gamma) * 1023.0;\n-\t\tx += size;\n-\t}\n-\n+\tSpan<uint16_t> lut{ config->gamma_y };\n+\tgammaAlgo_.prepare(frameContext.gamma, lut);\n \tconfig->mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC;\n }\n \n@@ -139,7 +110,7 @@ void GammaOutCorrection::process([[maybe_unused]] IPAContext &context,\n \t\t\t\t [[maybe_unused]] const rkisp1_stat_buffer *stats,\n \t\t\t\t ControlList &metadata)\n {\n-\tmetadata.set(controls::Gamma, frameContext.goc.gamma);\n+\tgammaAlgo_.process(frameContext.gamma, metadata);\n }\n \n REGISTER_IPA_ALGORITHM(GammaOutCorrection, \"GammaOutCorrection\")\ndiff --git a/src/ipa/rkisp1/algorithms/goc.h b/src/ipa/rkisp1/algorithms/goc.h\nindex bd79fe19cc86b8aefa2603e98e9d7130b44105d9..767d707b2758a89db286ab62d8f20d7a01912a2a 100644\n--- a/src/ipa/rkisp1/algorithms/goc.h\n+++ b/src/ipa/rkisp1/algorithms/goc.h\n@@ -9,6 +9,11 @@\n \n #include \"algorithm.h\"\n \n+#include <linux/rkisp1-config.h>\n+\n+#include <libipa/fixedpoint.h>\n+#include <libipa/gamma.h>\n+\n namespace libcamera {\n \n namespace ipa::rkisp1::algorithms {\n@@ -35,7 +40,7 @@ public:\n \t\t     ControlList &metadata) override;\n \n private:\n-\tfloat defaultGamma_;\n+\tGammaAlgorithm<RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10, UQ<0, 10>> gammaAlgo_;\n };\n \n } /* namespace ipa::rkisp1::algorithms */\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 7b4346c54ed2b8850ed147b0ce2b8a20155b80cf..8011c353c4eaade85d0a0007b44de8af7beaa9d6 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -30,6 +30,7 @@\n #include \"libipa/ccm.h\"\n #include \"libipa/fc_queue.h\"\n #include \"libipa/fixedpoint.h\"\n+#include \"libipa/gamma.h\"\n #include \"libipa/lsc.h\"\n \n namespace libcamera {\n@@ -127,9 +128,7 @@ struct IPAActiveState {\n \t\tuint8_t sharpness;\n \t} filter;\n \n-\tstruct {\n-\t\tdouble gamma;\n-\t} goc;\n+\tipa::gamma::ActiveState gamma;\n \n \tstruct {\n \t\tdouble lux;\n@@ -194,10 +193,7 @@ struct IPAFrameContext : public FrameContext {\n \t\tbool update;\n \t} filter;\n \n-\tstruct {\n-\t\tdouble gamma;\n-\t\tbool update;\n-\t} goc;\n+\tipa::gamma::FrameContext gamma;\n \n \tstruct {\n \t\tuint32_t exposure;\n",
    "prefixes": [
        "v2",
        "09/12"
    ]
}