{"id":26899,"url":"https://patchwork.libcamera.org/api/patches/26899/?format=json","web_url":"https://patchwork.libcamera.org/patch/26899/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260616-ipu3-libipa-rework-v1-8-d4448b54f1d8@ideasonboard.com>","date":"2026-06-16T06:41:42","name":"[08/10] ipa: rkisp1: goc: Re-work to use GammaAlgorithm class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"689cf5431614679ad60d5ecf00e0aa0f04f59914","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/?format=json","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26899/mbox/","series":[{"id":5995,"url":"https://patchwork.libcamera.org/api/series/5995/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5995","date":"2026-06-16T06:41:34","name":"libipa: Re-work IPU3 IPA to use libipa algorithms","version":1,"mbox":"https://patchwork.libcamera.org/series/5995/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26899/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26899/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 E7C1BC3303\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 Jun 2026 06:42:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 77239625B2;\n\tTue, 16 Jun 2026 08:41:59 +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 8D92961E76\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Jun 2026 08:41:50 +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 4E48D166C;\n\tTue, 16 Jun 2026 08:41:17 +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=\"Gc6e3V5I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1781592077;\n\tbh=ESK//rvtSLlKOvKdItZX6TsAh8BUgChpDfTIaQMnrjQ=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=Gc6e3V5IsVZZyDd0FK+Pg+uuO6a4yDy0I01HV3QIX35ZAXoLekQB/ER2EKY3E5IdB\n\tKSbpcQoTWSHMcfK0mqWhXHt+P2mE1lgJWpGX1VA7E8Yr5QKN0Wj/ut+T8dZTar2D9u\n\tn5Ccg/GK3QC/gadoX2SA6kTamA2GOMtw6IbV4PJU=","From":"Daniel Scally <dan.scally@ideasonboard.com>","Date":"Tue, 16 Jun 2026 07:41:42 +0100","Subject":"[PATCH 08/10] ipa: rkisp1: goc: Re-work to use GammaAlgorithm class","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","Message-Id":"<20260616-ipu3-libipa-rework-v1-8-d4448b54f1d8@ideasonboard.com>","References":"<20260616-ipu3-libipa-rework-v1-0-d4448b54f1d8@ideasonboard.com>","In-Reply-To":"<20260616-ipu3-libipa-rework-v1-0-d4448b54f1d8@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Daniel Scally <dan.scally@ideasonboard.com>","X-Mailer":"b4 0.14.2","X-Developer-Signature":"v=1; a=openpgp-sha256; l=5638;\n\ti=dan.scally@ideasonboard.com; h=from:subject:message-id;\n\tbh=ESK//rvtSLlKOvKdItZX6TsAh8BUgChpDfTIaQMnrjQ=;\n\tb=owEBbQKS/ZANAwAKAchJV3psRXUyAcsmYgBqMPAq4Nb9WiPbeVxnUeGsKmpurxIJ4586okxI9\n\tLDbidSvLyWJAjMEAAEKAB0WIQQqyuwyDnZdb+mxmm/ISVd6bEV1MgUCajDwKgAKCRDISVd6bEV1\n\tMvHPD/9nTmMvcZUxDlC5wAgSKSbcSj50YohnY4Ic2QefXn3IdEUjfn6Y1oQLIbLksm+fhWFOfkq\n\twZWbtVY/6DFqaY7GN321xFIZsQORxAJRMUj1I10VbXusdAo68yEgY4HYnP4UIdnpKIe3hZS69yR\n\tIIm0WlVaWBx3u7DZB6k+44KHCyo34MtWTI4TzPcQJfepZ8aSH8C7o/VYHCdikWOhRAtIGGI+20B\n\tciIOHOoZ+6L6sjza+0swff7DKQ+yt/sSmZbCPmhXcVGR9BWF80DS1UQ22F6DAAuhby+ODBNCnE+\n\tiXgXSQpltrIo9NhGOEMTyXM3EWTyxCoFG5gsgnOB6GAYxAH22pB0wqbJX7GF07gpI+L2oeEZHkc\n\tyNKhTc/qQ/8RPkAAv+rhxIw+OC23Tv2nRGyjvjpqQ9QMmpTzba9zeF3XbyMzuASNgLGkH33t11U\n\tQcM7WTBeRgKkMFsckZ1/ZJYSzvHA+NrOTfp+xO47vW4xH1MvT6oKrWxYVIAgk+wDHqtYZ9mvk+y\n\tMvnIX/aIap+1SsLZowKGrvFkyKV52Q5po4zchfrkSRsOs6HsKMER/gGF3dkucXOcF6iC+QQ9zKc\n\tNu1Lfuc0LPSdEEnH9KjuG6bSJzbxN13RdsCbgTqA1oTP+Gv9oTGzh+mfyUQ5QwyiyXMZgDd05iO\n\tjDb1++CMSES2URg==","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\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/goc.cpp | 49 +++++++++++----------------------------\n src/ipa/rkisp1/algorithms/goc.h   |  5 +++-\n src/ipa/rkisp1/ipa_context.h      | 10 +++-----\n 3 files changed, 21 insertions(+), 43 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp\nindex e8f64bf3d5e028c2013d37b7ef9fe90b737fad5f..1afd7fb9538d85f771c5b743b856a4963ec8665c 100644\n--- a/src/ipa/rkisp1/algorithms/goc.cpp\n+++ b/src/ipa/rkisp1/algorithms/goc.cpp\n@@ -9,7 +9,7 @@\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@@ -44,6 +44,7 @@ namespace ipa::rkisp1::algorithms {\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 +58,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 +72,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 +83,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 +98,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 +118,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..f7059d206c935fa72195f36091cf953e5f2413e1 100644\n--- a/src/ipa/rkisp1/algorithms/goc.h\n+++ b/src/ipa/rkisp1/algorithms/goc.h\n@@ -9,6 +9,9 @@\n \n #include \"algorithm.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 +38,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 005f4102b4f6d465fd370c20060331a4f3b3a943..03be79085052d5161ec57d97fe9600f4bf7e93c4 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@@ -124,9 +125,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@@ -190,10 +189,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":["08/10"]}