{"id":26007,"url":"https://patchwork.libcamera.org/api/patches/26007/?format=json","web_url":"https://patchwork.libcamera.org/patch/26007/","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":"<20260128114402.31570-15-mzamazal@redhat.com>","date":"2026-01-28T11:44:01","name":"[v5,14/15] libcamera: ipa: simple: Remove Lut algorithm","commit_ref":"3ffaa4c0e29a7ece2dcce4e94d3447932f7a3a65","pull_url":null,"state":"accepted","archived":false,"hash":"e1c9eb22c0ee75dfd74b7be687cb0f05868b6b83","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26007/mbox/","series":[{"id":5748,"url":"https://patchwork.libcamera.org/api/series/5748/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5748","date":"2026-01-28T11:43:47","name":"Simple pipeline IPA cleanup","version":5,"mbox":"https://patchwork.libcamera.org/series/5748/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26007/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26007/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 9AC79C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 11:44:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4FE4261FE4;\n\tWed, 28 Jan 2026 12:44:54 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E303561FFB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 12:44:46 +0100 (CET)","from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-425-TsbViuJJP6evFxi1I6Nyiw-1;\n\tWed, 28 Jan 2026 06:44:43 -0500","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.12])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 8BD27194510A; Wed, 28 Jan 2026 11:44:42 +0000 (UTC)","from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.34.236])\n\tby mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 646FC19560B2; Wed, 28 Jan 2026 11:44:40 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"ALKQHCFw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1769600685;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=k+iCQjV2NUF1iF+ojwzfN+nc3aZP+GAJTW2/8L9QxWo=;\n\tb=ALKQHCFwQc9W7Hj5V1qaOtrrPDOLXuY9oAAwYkFhakup2x/alWmRStfi7bxRC4+zvJjNj2\n\t0A3rSQ8htbei0u26qE2mHB/wibkTKBHpYPe135gLuhNzO6lshf26OBwmzKcPUhsitqyeVW\n\tAKM+AMIN+KbPv9nJB+nwO4O4g2mb4AA=","X-MC-Unique":"TsbViuJJP6evFxi1I6Nyiw-1","X-Mimecast-MFC-AGG-ID":"TsbViuJJP6evFxi1I6Nyiw_1769600682","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tRobert Mader <robert.mader@collabora.com>","Subject":"[PATCH v5 14/15] libcamera: ipa: simple: Remove Lut algorithm","Date":"Wed, 28 Jan 2026 12:44:01 +0100","Message-ID":"<20260128114402.31570-15-mzamazal@redhat.com>","In-Reply-To":"<20260128114402.31570-1-mzamazal@redhat.com>","References":"<20260128114402.31570-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"mejhFOHA_x0JOlDxeVCNau4hUgyWLNwwHKNQiobrEaU_1769600682","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=\"US-ASCII\"; x-default=true","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":"The Lut algorithm is not really an algorithm.  Moreover, algorithms may\nbe enabled or disabled but with Lut disabled, nothing will work.\n\nLet's move the construction of lookup tables to CPU debayering, where it\nis used.  The implied and related changes are:\n\n- DebayerParams is changed to contain the real params rather than lookup\n  tables.\n- contrastExp parameter introduced by GPU ISP is used for CPU ISP too.\n- The params must be initialised so that debayering gets meaningful\n  parameter values even when some algorithms are disabled.\n- combinedMatrix must be put to params everywhere where it is modified.\n- Matrix changes needn't be tracked in the algorithms any more.\n- CPU debayering must watch for changes of the corresponding parameters\n  to update the lookup tables when and only when needed.\n- Swapping red and blue is integrated into lookup table constructions.\n- gpuIspEnabled flags are removed as they are not needed any more.\n\nReviewed-by: Robert Mader <robert.mader@collabora.com>\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../internal/software_isp/debayer_params.h    |  43 +----\n include/libcamera/ipa/soft.mojom              |   3 +-\n src/ipa/simple/algorithms/adjust.cpp          |  17 +-\n src/ipa/simple/algorithms/adjust.h            |   4 -\n src/ipa/simple/algorithms/awb.cpp             |   6 +-\n src/ipa/simple/algorithms/ccm.cpp             |   1 -\n src/ipa/simple/algorithms/lut.cpp             | 140 --------------\n src/ipa/simple/algorithms/lut.h               |  35 ----\n src/ipa/simple/algorithms/meson.build         |   1 -\n src/ipa/simple/data/uncalibrated.yaml         |   1 -\n src/ipa/simple/ipa_context.h                  |  11 --\n src/ipa/simple/soft_simple.cpp                |  11 +-\n src/libcamera/software_isp/debayer.cpp        | 172 +-----------------\n src/libcamera/software_isp/debayer.h          |   8 -\n src/libcamera/software_isp/debayer_cpu.cpp    | 136 ++++++++++++--\n src/libcamera/software_isp/debayer_cpu.h      |  26 ++-\n src/libcamera/software_isp/debayer_egl.cpp    |  22 +--\n src/libcamera/software_isp/software_isp.cpp   |  29 +--\n 18 files changed, 188 insertions(+), 478 deletions(-)\n delete mode 100644 src/ipa/simple/algorithms/lut.cpp\n delete mode 100644 src/ipa/simple/algorithms/lut.h","diff":"diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h\nindex 2d69bd295..1c0412d75 100644\n--- a/include/libcamera/internal/software_isp/debayer_params.h\n+++ b/include/libcamera/internal/software_isp/debayer_params.h\n@@ -1,6 +1,6 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n- * Copyright (C) 2023-2025 Red Hat Inc.\n+ * Copyright (C) 2023-2026 Red Hat Inc.\n  *\n  * Authors:\n  * Hans de Goede <hdegoede@redhat.com>\n@@ -10,7 +10,6 @@\n \n #pragma once\n \n-#include <array>\n #include <stdint.h>\n \n #include \"libcamera/internal/matrix.h\"\n@@ -19,47 +18,11 @@\n namespace libcamera {\n \n struct DebayerParams {\n-\tstatic constexpr unsigned int kRGBLookupSize = 256;\n-\n-\tstruct CcmColumn {\n-\t\tint16_t r;\n-\t\tint16_t g;\n-\t\tint16_t b;\n-\t};\n-\n-\tusing LookupTable = std::array<uint8_t, kRGBLookupSize>;\n-\tusing CcmLookupTable = std::array<CcmColumn, kRGBLookupSize>;\n-\n-\t/*\n-\t * Color lookup tables when CCM is not used.\n-\t *\n-\t * Each color of a debayered pixel is amended by the corresponding\n-\t * value in the given table.\n-\t */\n-\tLookupTable red;\n-\tLookupTable green;\n-\tLookupTable blue;\n-\n-\t/*\n-\t * Color and gamma lookup tables when CCM is used.\n-\t *\n-\t * Each of the CcmLookupTable's corresponds to a CCM column; together they\n-\t * make a complete 3x3 CCM lookup table. The CCM is applied on debayered\n-\t * pixels and then the gamma lookup table is used to set the resulting\n-\t * values of all the three colors.\n-\t */\n-\tCcmLookupTable redCcm;\n-\tCcmLookupTable greenCcm;\n-\tCcmLookupTable blueCcm;\n-\tLookupTable gammaLut;\n-\n-\t/*\n-\t * Per frame corrections as calculated by the IPA\n-\t */\n-\tMatrix<float, 3, 3> ccm;\n+\tMatrix<float, 3, 3> combinedMatrix;\n \tRGB<float> blackLevel;\n \tfloat gamma;\n \tfloat contrastExp;\n+\tRGB<float> gains;\n };\n \n } /* namespace libcamera */\ndiff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom\nindex aff8fcbd3..77328c5fd 100644\n--- a/include/libcamera/ipa/soft.mojom\n+++ b/include/libcamera/ipa/soft.mojom\n@@ -17,8 +17,7 @@ interface IPASoftInterface {\n \t     libcamera.SharedFD fdStats,\n \t     libcamera.SharedFD fdParams,\n \t     libcamera.IPACameraSensorInfo sensorInfo,\n-\t     libcamera.ControlInfoMap sensorControls,\n-\t     bool gpuIspEnabled)\n+\t     libcamera.ControlInfoMap sensorControls)\n \t\t=> (int32 ret, libcamera.ControlInfoMap ipaControls, bool ccmEnabled);\n \tstart() => (int32 ret);\n \tstop();\ndiff --git a/src/ipa/simple/algorithms/adjust.cpp b/src/ipa/simple/algorithms/adjust.cpp\nindex acdd3f741..068e98404 100644\n--- a/src/ipa/simple/algorithms/adjust.cpp\n+++ b/src/ipa/simple/algorithms/adjust.cpp\n@@ -95,23 +95,20 @@ void Adjust::applySaturation(Matrix<float, 3, 3> &matrix, float saturation)\n void Adjust::prepare(IPAContext &context,\n \t\t     [[maybe_unused]] const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n-\t\t     [[maybe_unused]] DebayerParams *params)\n+\t\t     DebayerParams *params)\n {\n \tframeContext.gamma = context.activeState.knobs.gamma;\n \tframeContext.contrast = context.activeState.knobs.contrast;\n \n-\tif (!context.ccmEnabled)\n-\t\treturn;\n-\n \tauto &saturation = context.activeState.knobs.saturation;\n-\tframeContext.saturation = saturation;\n-\tif (saturation)\n+\tif (context.ccmEnabled && saturation) {\n \t\tapplySaturation(context.activeState.combinedMatrix, saturation.value());\n-\n-\tif (saturation != lastSaturation_) {\n-\t\tcontext.activeState.matrixChanged = true;\n-\t\tlastSaturation_ = saturation;\n+\t\tframeContext.saturation = saturation;\n \t}\n+\n+\tparams->gamma = 1.0 / context.activeState.knobs.gamma;\n+\tconst float contrast = context.activeState.knobs.contrast.value_or(kDefaultContrast);\n+\tparams->contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n }\n \n void Adjust::process([[maybe_unused]] IPAContext &context,\ndiff --git a/src/ipa/simple/algorithms/adjust.h b/src/ipa/simple/algorithms/adjust.h\nindex 7644138ff..fb133b140 100644\n--- a/src/ipa/simple/algorithms/adjust.h\n+++ b/src/ipa/simple/algorithms/adjust.h\n@@ -7,8 +7,6 @@\n \n #pragma once\n \n-#include <optional>\n-\n #include \"libcamera/internal/matrix.h\"\n \n #include <libipa/interpolator.h>\n@@ -45,8 +43,6 @@ public:\n \n private:\n \tvoid applySaturation(Matrix<float, 3, 3> &ccm, float saturation);\n-\n-\tstd::optional<float> lastSaturation_;\n };\n \n } /* namespace ipa::soft::algorithms */\ndiff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp\nindex 31726658a..6fdaacaba 100644\n--- a/src/ipa/simple/algorithms/awb.cpp\n+++ b/src/ipa/simple/algorithms/awb.cpp\n@@ -37,7 +37,7 @@ int Awb::configure(IPAContext &context,\n void Awb::prepare(IPAContext &context,\n \t\t  [[maybe_unused]] const uint32_t frame,\n \t\t  IPAFrameContext &frameContext,\n-\t\t  [[maybe_unused]] DebayerParams *params)\n+\t\t  DebayerParams *params)\n {\n \tauto &gains = context.activeState.awb.gains;\n \tMatrix<float, 3, 3> gainMatrix = { { gains.r(), 0, 0,\n@@ -45,9 +45,11 @@ void Awb::prepare(IPAContext &context,\n \t\t\t\t\t     0, 0, gains.b() } };\n \tcontext.activeState.combinedMatrix =\n \t\tcontext.activeState.combinedMatrix * gainMatrix;\n-\t/* Just report, the gains are applied in LUT algorithm. */\n+\n \tframeContext.gains.red = gains.r();\n \tframeContext.gains.blue = gains.b();\n+\n+\tparams->gains = gains;\n }\n \n void Awb::process(IPAContext &context,\ndiff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp\nindex 5576a301f..911a5af2c 100644\n--- a/src/ipa/simple/algorithms/ccm.cpp\n+++ b/src/ipa/simple/algorithms/ccm.cpp\n@@ -51,7 +51,6 @@ void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t    utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold) {\n \t\tcurrentCcm_ = ccm_.getInterpolated(ct);\n \t\tlastCt_ = ct;\n-\t\tcontext.activeState.matrixChanged = true;\n \t}\n \n \tcontext.activeState.combinedMatrix =\ndiff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\ndeleted file mode 100644\nindex fd442259a..000000000\n--- a/src/ipa/simple/algorithms/lut.cpp\n+++ /dev/null\n@@ -1,140 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2024-2026, Red Hat Inc.\n- *\n- * Color lookup tables construction\n- */\n-\n-#include \"lut.h\"\n-\n-#include <algorithm>\n-#include <cmath>\n-#include <optional>\n-#include <stdint.h>\n-\n-#include <libcamera/base/log.h>\n-\n-#include <libcamera/control_ids.h>\n-\n-#include \"simple/ipa_context.h\"\n-\n-#include \"adjust.h\"\n-\n-namespace libcamera {\n-\n-LOG_DEFINE_CATEGORY(IPASoftLut)\n-\n-namespace ipa::soft::algorithms {\n-\n-int Lut::configure(IPAContext &context,\n-\t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n-{\n-\tupdateGammaTable(context);\n-\n-\treturn 0;\n-}\n-\n-void Lut::updateGammaTable(IPAContext &context)\n-{\n-\tconst auto blackLevel = context.activeState.blc.level;\n-\tconst auto gamma = 1.0 / context.activeState.knobs.gamma;\n-\tconst auto contrast = context.activeState.knobs.contrast.value_or(1.0);\n-\t/* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */\n-\tfloat contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n-\n-\tif (!context.gpuIspEnabled) {\n-\t\tauto &gammaTable = context.activeState.gamma.gammaTable;\n-\t\tconst unsigned int blackIndex = blackLevel * gammaTable.size() / 256;\n-\t\tconst float divisor = gammaTable.size() - blackIndex - 1.0;\n-\t\tfor (unsigned int i = blackIndex; i < gammaTable.size(); i++) {\n-\t\t\tdouble normalized = (i - blackIndex) / divisor;\n-\t\t\t/* Apply simple S-curve */\n-\t\t\tif (normalized < 0.5)\n-\t\t\t\tnormalized = 0.5 * std::pow(normalized / 0.5, contrastExp);\n-\t\t\telse\n-\t\t\t\tnormalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp);\n-\t\t\tgammaTable[i] = UINT8_MAX * std::pow(normalized, gamma);\n-\t\t}\n-\t\t/*\n-\t\t * Due to CCM operations, the table lookup may reach indices below the black\n-\t\t * level. Let's set the table values below black level to the minimum\n-\t\t * non-black value to prevent problems when the minimum value is\n-\t\t * significantly non-zero (for example, when the image should be all grey).\n-\t\t */\n-\t\tstd::fill(gammaTable.begin(), gammaTable.begin() + blackIndex,\n-\t\t\t  gammaTable[blackIndex]);\n-\t}\n-\n-\tcontext.activeState.gamma.gamma = gamma;\n-\tcontext.activeState.gamma.blackLevel = blackLevel;\n-\tcontext.activeState.gamma.contrastExp = contrastExp;\n-}\n-\n-int16_t Lut::matrixValue(unsigned int i, float ccm) const\n-{\n-\treturn std::round(i * ccm);\n-}\n-\n-void Lut::prepare(IPAContext &context,\n-\t\t  [[maybe_unused]] const uint32_t frame,\n-\t\t  [[maybe_unused]] IPAFrameContext &frameContext,\n-\t\t  DebayerParams *params)\n-{\n-\t/*\n-\t * Update the gamma table if needed. This means if black level changes\n-\t * and since the black level gets updated only if a lower value is\n-\t * observed, it's not permanently prone to minor fluctuations or\n-\t * rounding errors.\n-\t */\n-\tconst bool gammaUpdateNeeded =\n-\t\tcontext.activeState.gamma.blackLevel != context.activeState.blc.level ||\n-\t\tcontext.activeState.gamma.contrast != context.activeState.knobs.contrast;\n-\tif (gammaUpdateNeeded)\n-\t\tupdateGammaTable(context);\n-\n-\tauto &gains = context.activeState.awb.gains;\n-\tauto &gammaTable = context.activeState.gamma.gammaTable;\n-\tconst unsigned int gammaTableSize = gammaTable.size();\n-\tconst double div = static_cast<double>(DebayerParams::kRGBLookupSize) /\n-\t\t\t   gammaTableSize;\n-\n-\tif (!context.ccmEnabled) {\n-\t\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n-\t\t\t/* Apply gamma after gain! */\n-\t\t\tconst RGB<float> lutGains = (gains * i / div).min(gammaTableSize - 1);\n-\t\t\tparams->red[i] = gammaTable[static_cast<unsigned int>(lutGains.r())];\n-\t\t\tparams->green[i] = gammaTable[static_cast<unsigned int>(lutGains.g())];\n-\t\t\tparams->blue[i] = gammaTable[static_cast<unsigned int>(lutGains.b())];\n-\t\t}\n-\t} else if (context.activeState.matrixChanged || gammaUpdateNeeded) {\n-\t\tauto &matrix = context.activeState.combinedMatrix;\n-\t\tauto &red = params->redCcm;\n-\t\tauto &green = params->greenCcm;\n-\t\tauto &blue = params->blueCcm;\n-\t\tparams->ccm = matrix;\n-\t\tif (!context.gpuIspEnabled) {\n-\t\t\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n-\t\t\t\tred[i].r = matrixValue(i, matrix[0][0]);\n-\t\t\t\tred[i].g = matrixValue(i, matrix[1][0]);\n-\t\t\t\tred[i].b = matrixValue(i, matrix[2][0]);\n-\t\t\t\tgreen[i].r = matrixValue(i, matrix[0][1]);\n-\t\t\t\tgreen[i].g = matrixValue(i, matrix[1][1]);\n-\t\t\t\tgreen[i].b = matrixValue(i, matrix[2][1]);\n-\t\t\t\tblue[i].r = matrixValue(i, matrix[0][2]);\n-\t\t\t\tblue[i].g = matrixValue(i, matrix[1][2]);\n-\t\t\t\tblue[i].b = matrixValue(i, matrix[2][2]);\n-\t\t\t\tparams->gammaLut[i] = gammaTable[i / div];\n-\t\t\t}\n-\t\t}\n-\t\tcontext.activeState.matrixChanged = false;\n-\t}\n-\n-\tparams->gamma = context.activeState.gamma.gamma;\n-\tparams->contrastExp = context.activeState.gamma.contrastExp;\n-}\n-\n-REGISTER_IPA_ALGORITHM(Lut, \"Lut\")\n-\n-} /* namespace ipa::soft::algorithms */\n-\n-} /* namespace libcamera */\ndiff --git a/src/ipa/simple/algorithms/lut.h b/src/ipa/simple/algorithms/lut.h\ndeleted file mode 100644\nindex ad16d1e8e..000000000\n--- a/src/ipa/simple/algorithms/lut.h\n+++ /dev/null\n@@ -1,35 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2024, Red Hat Inc.\n- *\n- * Color lookup tables construction\n- */\n-\n-#pragma once\n-\n-#include \"algorithm.h\"\n-\n-namespace libcamera {\n-\n-namespace ipa::soft::algorithms {\n-\n-class Lut : public Algorithm\n-{\n-public:\n-\tLut() = default;\n-\t~Lut() = default;\n-\n-\tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n-\tvoid prepare(IPAContext &context,\n-\t\t     const uint32_t frame,\n-\t\t     IPAFrameContext &frameContext,\n-\t\t     DebayerParams *params) override;\n-\n-private:\n-\tvoid updateGammaTable(IPAContext &context);\n-\tint16_t matrixValue(unsigned int i, float ccm) const;\n-};\n-\n-} /* namespace ipa::soft::algorithms */\n-\n-} /* namespace libcamera */\ndiff --git a/src/ipa/simple/algorithms/meson.build b/src/ipa/simple/algorithms/meson.build\nindex ebe9f20dd..73c637220 100644\n--- a/src/ipa/simple/algorithms/meson.build\n+++ b/src/ipa/simple/algorithms/meson.build\n@@ -6,5 +6,4 @@ soft_simple_ipa_algorithms = files([\n     'agc.cpp',\n     'blc.cpp',\n     'ccm.cpp',\n-    'lut.cpp',\n ])\ndiff --git a/src/ipa/simple/data/uncalibrated.yaml b/src/ipa/simple/data/uncalibrated.yaml\nindex e389e0588..c6feda36d 100644\n--- a/src/ipa/simple/data/uncalibrated.yaml\n+++ b/src/ipa/simple/data/uncalibrated.yaml\n@@ -15,6 +15,5 @@ algorithms:\n                  0, 1, 0,\n                  0, 0, 1]\n   - Adjust:\n-  - Lut:\n   - Agc:\n ...\ndiff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\nindex 293e35b71..34f7403a4 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -53,17 +53,7 @@ struct IPAActiveState {\n \t\tunsigned int temperatureK;\n \t} awb;\n \n-\tstatic constexpr unsigned int kGammaLookupSize = 1024;\n-\tstruct {\n-\t\tstd::array<double, kGammaLookupSize> gammaTable;\n-\t\tuint8_t blackLevel;\n-\t\tfloat gamma;\n-\t\tfloat contrast;\n-\t\tfloat contrastExp;\n-\t} gamma;\n-\n \tMatrix<float, 3, 3> combinedMatrix;\n-\tbool matrixChanged = false;\n \n \tstruct {\n \t\tfloat gamma;\n@@ -103,7 +93,6 @@ struct IPAContext {\n \tFCQueue<IPAFrameContext> frameContexts;\n \tControlInfoMap::Map ctrlMap;\n \tbool ccmEnabled = false;\n-\tbool gpuIspEnabled = false;\n };\n \n } /* namespace ipa::soft */\ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex 732e82510..6bef597c8 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -26,6 +26,7 @@\n #include \"libcamera/internal/software_isp/swisp_stats.h\"\n #include \"libcamera/internal/yaml_parser.h\"\n \n+#include \"algorithms/adjust.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n #include \"module.h\"\n@@ -55,7 +56,6 @@ public:\n \t\t const SharedFD &fdParams,\n \t\t const IPACameraSensorInfo &sensorInfo,\n \t\t const ControlInfoMap &sensorControls,\n-\t\t bool gpuIspEnabled,\n \t\t ControlInfoMap *ipaControls,\n \t\t bool *ccmEnabled) override;\n \tint configure(const IPAConfigInfo &configInfo) override;\n@@ -96,7 +96,6 @@ int IPASoftSimple::init(const IPASettings &settings,\n \t\t\tconst SharedFD &fdParams,\n \t\t\tconst IPACameraSensorInfo &sensorInfo,\n \t\t\tconst ControlInfoMap &sensorControls,\n-\t\t\tbool gpuIspEnabled,\n \t\t\tControlInfoMap *ipaControls,\n \t\t\tbool *ccmEnabled)\n {\n@@ -108,7 +107,6 @@ int IPASoftSimple::init(const IPASettings &settings,\n \t}\n \n \tcontext_.sensorInfo = sensorInfo;\n-\tcontext_.gpuIspEnabled = gpuIspEnabled;\n \n \t/* Load the tuning data file */\n \tFile file(settings.configurationFile);\n@@ -161,6 +159,11 @@ int IPASoftSimple::init(const IPASettings &settings,\n \t\t}\n \n \t\tparams_ = static_cast<DebayerParams *>(mem);\n+\t\tparams_->blackLevel = { { 0.0, 0.0, 0.0 } };\n+\t\tparams_->gamma = 1.0 / algorithms::kDefaultGamma;\n+\t\tparams_->contrastExp = 1.0;\n+\t\tparams_->gains = { { 1.0, 1.0, 1.0 } };\n+\t\t/* combinedMatrix is reset for each frame. */\n \t}\n \n \t{\n@@ -287,6 +290,8 @@ void IPASoftSimple::computeParams(const uint32_t frame)\n \tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \tfor (auto const &algo : algorithms())\n \t\talgo->prepare(context_, frame, frameContext, params_);\n+\tparams_->combinedMatrix = context_.activeState.combinedMatrix;\n+\n \tsetIspParams.emit();\n }\n \ndiff --git a/src/libcamera/software_isp/debayer.cpp b/src/libcamera/software_isp/debayer.cpp\nindex 65a1762dd..dccdd86b4 100644\n--- a/src/libcamera/software_isp/debayer.cpp\n+++ b/src/libcamera/software_isp/debayer.cpp\n@@ -1,7 +1,7 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n  * Copyright (C) 2023, Linaro Ltd\n- * Copyright (C) 2023-2025 Red Hat Inc.\n+ * Copyright (C) 2023-2026 Red Hat Inc.\n  *\n  * Authors:\n  * Hans de Goede <hdegoede@redhat.com>\n@@ -25,99 +25,28 @@ namespace libcamera {\n  */\n \n /**\n- * \\var DebayerParams::kRGBLookupSize\n- * \\brief Size of a color lookup table\n+ * \\var DebayerParams::gains\n+ * \\brief Colour channel gains\n  */\n \n /**\n- * \\struct DebayerParams::CcmColumn\n- * \\brief Type of a single column of a color correction matrix (CCM)\n- *\n- * When multiplying an input pixel, columns in the CCM correspond to the red,\n- * green or blue component of input pixel values, while rows correspond to the\n- * red, green or blue components of the output pixel values. The members of the\n- * CcmColumn structure are named after the colour components of the output pixel\n- * values they correspond to.\n- */\n-\n-/**\n- * \\var DebayerParams::CcmColumn::r\n- * \\brief Red (first) component of a CCM column\n- */\n-\n-/**\n- * \\var DebayerParams::CcmColumn::g\n- * \\brief Green (second) component of a CCM column\n- */\n-\n-/**\n- * \\var DebayerParams::CcmColumn::b\n- * \\brief Blue (third) component of a CCM column\n- */\n-\n-/**\n- * \\typedef DebayerParams::LookupTable\n- * \\brief Type of the lookup tables for single lookup values\n- */\n-\n-/**\n- * \\typedef DebayerParams::CcmLookupTable\n- * \\brief Type of the CCM lookup tables for red, green, blue values\n- */\n-\n-/**\n- * \\var DebayerParams::red\n- * \\brief Lookup table for red color, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::green\n- * \\brief Lookup table for green color, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::blue\n- * \\brief Lookup table for blue color, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::redCcm\n- * \\brief Lookup table for the CCM red column, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::greenCcm\n- * \\brief Lookup table for the CCM green column, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::blueCcm\n- * \\brief Lookup table for the CCM blue column, mapping input values to output values\n- */\n-\n-/**\n- * \\var DebayerParams::gammaLut\n- * \\brief Gamma lookup table used with color correction matrix\n- */\n-\n-/**\n- * \\var DebayerParams::ccm\n- * \\brief Per frame colour correction matrix for GPUISP\n+ * \\var DebayerParams::combinedMatrix\n+ * \\brief Colour correction matrix, including other adjustments\n  */\n \n /**\n  * \\var DebayerParams::blackLevel\n- * \\brief Blacklevel gains for the GPUISP\n+ * \\brief Black level values\n  */\n \n /**\n  * \\var DebayerParams::gamma\n- * \\brief Gamma value for the GPUISP\n+ * \\brief Gamma value, e.g. 1/2.2\n  */\n \n /**\n  * \\var DebayerParams::contrastExp\n- * \\brief Contrast value for GPUISP\n+ * \\brief Contrast value to be used as an exponent\n  */\n \n /**\n@@ -131,13 +60,6 @@ LOG_DEFINE_CATEGORY(Debayer)\n \n Debayer::Debayer(const GlobalConfiguration &configuration) : bench_(configuration)\n {\n-\t/* Initialize color lookup tables */\n-\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n-\t\tred_[i] = green_[i] = blue_[i] = i;\n-\t\tredCcm_[i] = { static_cast<int16_t>(i), 0, 0 };\n-\t\tgreenCcm_[i] = { 0, static_cast<int16_t>(i), 0 };\n-\t\tblueCcm_[i] = { 0, 0, static_cast<int16_t>(i) };\n-\t}\n }\n \n Debayer::~Debayer()\n@@ -305,56 +227,6 @@ Debayer::~Debayer()\n  * \\brief Output size object\n  */\n \n-/**\n- * \\var Debayer::red_\n- * \\brief Lookup table for red channel gain and correction values\n- *\n- * This table provides precomputed per-pixel or per-intensity\n- * correction values for the red color channel used during debayering.\n- */\n-\n-/**\n- * \\var Debayer::green_\n- * \\brief Lookup table for green channel gain and correction values\n- *\n- * This table provides precomputed per-pixel or per-intensity\n- * correction values for the green color channel used during debayering.\n- */\n-\n-/**\n- * \\var Debayer::blue_\n- * \\brief Lookup table for blue channel gain and correction values\n- *\n- * This table provides precomputed per-pixel or per-intensity\n- * correction values for the blue color channel used during debayering.\n- */\n-\n-/**\n- * \\var Debayer::redCcm_\n- * \\brief Red channel Color Correction Matrix (CCM) lookup table\n- *\n- * Contains coefficients for green channel color correction.\n- */\n-\n-/**\n- * \\var Debayer::greenCcm_\n- * \\brief Green channel Color Correction Matrix (CCM) lookup table\n- *\n- * Contains coefficients for green channel color correction.\n- */\n-\n-/**\n- * \\var Debayer::blueCcm_\n- * \\brief Blue channel Color Correction Matrix (CCM) lookup table\n- *\n- * Contains coefficients for blue channel color correction.\n- */\n-\n-/**\n- * \\var Debayer::gammaLut_\n- * \\brief Gamma correction lookup table\n- */\n-\n /**\n  * \\var Debayer::swapRedBlueGains_\n  * \\brief Flag indicating whether red and blue channel gains should be swapped\n@@ -396,34 +268,6 @@ Debayer::~Debayer()\n  * DebayerEGL::start.\n  */\n \n-/**\n- * \\fn void Debayer::setParams(DebayerParams &params)\n- * \\brief Select the bayer params to use for the next frame debayer\n- * \\param[in] params The parameters to be used in debayering\n- */\n-void Debayer::setParams(DebayerParams &params)\n-{\n-\tgreen_ = params.green;\n-\tgreenCcm_ = params.greenCcm;\n-\tif (swapRedBlueGains_) {\n-\t\tred_ = params.blue;\n-\t\tblue_ = params.red;\n-\t\tredCcm_ = params.blueCcm;\n-\t\tblueCcm_ = params.redCcm;\n-\t\tfor (unsigned int i = 0; i < 256; i++) {\n-\t\t\tstd::swap(redCcm_[i].r, redCcm_[i].b);\n-\t\t\tstd::swap(greenCcm_[i].r, greenCcm_[i].b);\n-\t\t\tstd::swap(blueCcm_[i].r, blueCcm_[i].b);\n-\t\t}\n-\t} else {\n-\t\tred_ = params.red;\n-\t\tblue_ = params.blue;\n-\t\tredCcm_ = params.redCcm;\n-\t\tblueCcm_ = params.blueCcm;\n-\t}\n-\tgammaLut_ = params.gammaLut;\n-}\n-\n /**\n  * \\fn void Debayer::dmaSyncBegin(DebayerParams &params)\n  * \\brief Common CPU/GPU Dma Sync Buffer begin\ndiff --git a/src/libcamera/software_isp/debayer.h b/src/libcamera/software_isp/debayer.h\nindex cd2db9930..652cff4cc 100644\n--- a/src/libcamera/software_isp/debayer.h\n+++ b/src/libcamera/software_isp/debayer.h\n@@ -78,13 +78,6 @@ public:\n \tSize outputSize_;\n \tPixelFormat inputPixelFormat_;\n \tPixelFormat outputPixelFormat_;\n-\tDebayerParams::LookupTable red_;\n-\tDebayerParams::LookupTable green_;\n-\tDebayerParams::LookupTable blue_;\n-\tDebayerParams::CcmLookupTable redCcm_;\n-\tDebayerParams::CcmLookupTable greenCcm_;\n-\tDebayerParams::CcmLookupTable blueCcm_;\n-\tDebayerParams::LookupTable gammaLut_;\n \tbool swapRedBlueGains_;\n \tBenchmark bench_;\n \n@@ -92,7 +85,6 @@ private:\n \tvirtual Size patternSize(PixelFormat inputFormat) = 0;\n \n protected:\n-\tvoid setParams(DebayerParams &params);\n \tvoid dmaSyncBegin(std::vector<DmaSyncer> &dmaSyncers, FrameBuffer *input, FrameBuffer *output);\n \tstatic bool isStandardBayerOrder(BayerFormat::Order order);\n };\ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex 00738c56b..af7af0a8d 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -1,7 +1,7 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n  * Copyright (C) 2023, Linaro Ltd\n- * Copyright (C) 2023-2025 Red Hat Inc.\n+ * Copyright (C) 2023-2026 Red Hat Inc.\n  *\n  * Authors:\n  * Hans de Goede <hdegoede@redhat.com>\n@@ -68,21 +68,21 @@ DebayerCpu::~DebayerCpu() = default;\n #define GAMMA(value) \\\n \t*dst++ = gammaLut_[std::clamp(value, 0, static_cast<int>(gammaLut_.size()) - 1)]\n \n-#define STORE_PIXEL(b_, g_, r_)                                        \\\n-\tif constexpr (ccmEnabled) {                                    \\\n-\t\tconst DebayerParams::CcmColumn &blue = blueCcm_[b_];   \\\n-\t\tconst DebayerParams::CcmColumn &green = greenCcm_[g_]; \\\n-\t\tconst DebayerParams::CcmColumn &red = redCcm_[r_];     \\\n-\t\tGAMMA(blue.b + green.b + red.b);                       \\\n-\t\tGAMMA(blue.g + green.g + red.g);                       \\\n-\t\tGAMMA(blue.r + green.r + red.r);                       \\\n-\t} else {                                                       \\\n-\t\t*dst++ = blue_[b_];                                    \\\n-\t\t*dst++ = green_[g_];                                   \\\n-\t\t*dst++ = red_[r_];                                     \\\n-\t}                                                              \\\n-\tif constexpr (addAlphaByte)                                    \\\n-\t\t*dst++ = 255;                                          \\\n+#define STORE_PIXEL(b_, g_, r_)                         \\\n+\tif constexpr (ccmEnabled) {                     \\\n+\t\tconst CcmColumn &blue = blueCcm_[b_];   \\\n+\t\tconst CcmColumn &green = greenCcm_[g_]; \\\n+\t\tconst CcmColumn &red = redCcm_[r_];     \\\n+\t\tGAMMA(blue.b + green.b + red.b);        \\\n+\t\tGAMMA(blue.g + green.g + red.g);        \\\n+\t\tGAMMA(blue.r + green.r + red.r);        \\\n+\t} else {                                        \\\n+\t\t*dst++ = blue_[b_];                     \\\n+\t\t*dst++ = green_[g_];                    \\\n+\t\t*dst++ = red_[r_];                      \\\n+\t}                                               \\\n+\tif constexpr (addAlphaByte)                     \\\n+\t\t*dst++ = 255;                           \\\n \tx++;\n \n /*\n@@ -525,6 +525,16 @@ int DebayerCpu::configure(const StreamConfiguration &inputCfg,\n \tif (ret != 0)\n \t\treturn -EINVAL;\n \n+\tccmEnabled_ = ccmEnabled;\n+\n+\t/*\n+\t * Lookup tables must be initialized because the initial value is used for\n+\t * the first two frames, i.e. until stats processing starts providing its\n+\t * own parameters. Let's enforce recomputing lookup tables by setting the\n+\t * stored last used gamma to an out-of-range value.\n+\t */\n+\tparams_.gamma = 1.0;\n+\n \twindow_.x = ((inputCfg.size.width - outputCfg.size.width) / 2) &\n \t\t    ~(inputConfig_.patternSize.width - 1);\n \twindow_.y = ((inputCfg.size.height - outputCfg.size.height) / 2) &\n@@ -740,6 +750,98 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n \t}\n }\n \n+void DebayerCpu::updateGammaTable(DebayerParams &params)\n+{\n+\tconst RGB<float> blackLevel = params.blackLevel;\n+\t/* Take let's say the green channel black level */\n+\tconst unsigned int blackIndex = blackLevel[1] * gammaTable_.size();\n+\tconst float gamma = params.gamma;\n+\tconst float contrastExp = params.contrastExp;\n+\n+\tconst float divisor = gammaTable_.size() - blackIndex - 1.0;\n+\tfor (unsigned int i = blackIndex; i < gammaTable_.size(); i++) {\n+\t\tfloat normalized = (i - blackIndex) / divisor;\n+\t\t/* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */\n+\t\t/* Apply simple S-curve */\n+\t\tif (normalized < 0.5)\n+\t\t\tnormalized = 0.5 * std::pow(normalized / 0.5, contrastExp);\n+\t\telse\n+\t\t\tnormalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp);\n+\t\tgammaTable_[i] = UINT8_MAX *\n+\t\t\t\t std::pow(normalized, gamma);\n+\t}\n+\t/*\n+\t * Due to CCM operations, the table lookup may reach indices below the black\n+\t * level. Let's set the table values below black level to the minimum\n+\t * non-black value to prevent problems when the minimum value is\n+\t * significantly non-zero (for example, when the image should be all grey).\n+\t */\n+\tstd::fill(gammaTable_.begin(), gammaTable_.begin() + blackIndex,\n+\t\t  gammaTable_[blackIndex]);\n+}\n+\n+void DebayerCpu::updateLookupTables(DebayerParams &params)\n+{\n+\tconst bool gammaUpdateNeeded =\n+\t\tparams.gamma != params_.gamma ||\n+\t\tparams.blackLevel != params_.blackLevel ||\n+\t\tparams.contrastExp != params_.contrastExp;\n+\tif (gammaUpdateNeeded)\n+\t\tupdateGammaTable(params);\n+\n+\tauto matrixChanged = [](const Matrix<float, 3, 3> &m1, const Matrix<float, 3, 3> &m2) -> bool {\n+\t\treturn !std::equal(m1.data().begin(), m1.data().end(), m2.data().begin());\n+\t};\n+\tconst unsigned int gammaTableSize = gammaTable_.size();\n+\tconst double div = static_cast<double>(kRGBLookupSize) / gammaTableSize;\n+\tif (ccmEnabled_) {\n+\t\tif (gammaUpdateNeeded ||\n+\t\t    matrixChanged(params.combinedMatrix, params_.combinedMatrix)) {\n+\t\t\tauto &red = swapRedBlueGains_ ? blueCcm_ : redCcm_;\n+\t\t\tauto &green = greenCcm_;\n+\t\t\tauto &blue = swapRedBlueGains_ ? redCcm_ : blueCcm_;\n+\t\t\tconst unsigned int redIndex = swapRedBlueGains_ ? 2 : 0;\n+\t\t\tconst unsigned int greenIndex = 1;\n+\t\t\tconst unsigned int blueIndex = swapRedBlueGains_ ? 0 : 2;\n+\t\t\tfor (unsigned int i = 0; i < kRGBLookupSize; i++) {\n+\t\t\t\tred[i].r = std::round(i * params.combinedMatrix[redIndex][0]);\n+\t\t\t\tred[i].g = std::round(i * params.combinedMatrix[greenIndex][0]);\n+\t\t\t\tred[i].b = std::round(i * params.combinedMatrix[blueIndex][0]);\n+\t\t\t\tgreen[i].r = std::round(i * params.combinedMatrix[redIndex][1]);\n+\t\t\t\tgreen[i].g = std::round(i * params.combinedMatrix[greenIndex][1]);\n+\t\t\t\tgreen[i].b = std::round(i * params.combinedMatrix[blueIndex][1]);\n+\t\t\t\tblue[i].r = std::round(i * params.combinedMatrix[redIndex][2]);\n+\t\t\t\tblue[i].g = std::round(i * params.combinedMatrix[greenIndex][2]);\n+\t\t\t\tblue[i].b = std::round(i * params.combinedMatrix[blueIndex][2]);\n+\t\t\t\tgammaLut_[i] = gammaTable_[i / div];\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tif (gammaUpdateNeeded || params.gains != params_.gains) {\n+\t\t\tauto &gains = params.gains;\n+\t\t\tauto &red = swapRedBlueGains_ ? blue_ : red_;\n+\t\t\tauto &green = green_;\n+\t\t\tauto &blue = swapRedBlueGains_ ? red_ : blue_;\n+\t\t\tfor (unsigned int i = 0; i < kRGBLookupSize; i++) {\n+\t\t\t\t/* Apply gamma after gain! */\n+\t\t\t\tconst RGB<float> lutGains = (gains * i / div).min(gammaTableSize - 1);\n+\t\t\t\tred[i] = gammaTable_[static_cast<unsigned int>(lutGains.r())];\n+\t\t\t\tgreen[i] = gammaTable_[static_cast<unsigned int>(lutGains.g())];\n+\t\t\t\tblue[i] = gammaTable_[static_cast<unsigned int>(lutGains.b())];\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tLOG(Debayer, Debug)\n+\t\t<< \"Debayer parameters: blackLevel=\" << params.blackLevel\n+\t\t<< \"; gamma=\" << params.gamma\n+\t\t<< \"; contrastExp=\" << params.contrastExp\n+\t\t<< \"; gains=\" << params.gains\n+\t\t<< \"; matrix=\" << params.combinedMatrix;\n+\n+\tparams_ = params;\n+}\n+\n void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params)\n {\n \tbench_.startFrame();\n@@ -748,7 +850,7 @@ void DebayerCpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \n \tdmaSyncBegin(dmaSyncers, input, output);\n \n-\tsetParams(params);\n+\tupdateLookupTables(params);\n \n \t/* Copy metadata from the input buffer */\n \tFrameMetadata &metadata = output->_d()->metadata();\ndiff --git a/src/libcamera/software_isp/debayer_cpu.h b/src/libcamera/software_isp/debayer_cpu.h\nindex 67df2b93a..b5cbb5bd2 100644\n--- a/src/libcamera/software_isp/debayer_cpu.h\n+++ b/src/libcamera/software_isp/debayer_cpu.h\n@@ -1,7 +1,7 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n  * Copyright (C) 2023, Linaro Ltd\n- * Copyright (C) 2023-2025 Red Hat Inc.\n+ * Copyright (C) 2023-2026 Red Hat Inc.\n  *\n  * Authors:\n  * Hans de Goede <hdegoede@redhat.com>\n@@ -18,6 +18,8 @@\n #include <libcamera/base/object.h>\n \n #include \"libcamera/internal/bayer_format.h\"\n+#include \"libcamera/internal/global_configuration.h\"\n+#include \"libcamera/internal/software_isp/debayer_params.h\"\n #include \"libcamera/internal/software_isp/swstats_cpu.h\"\n \n #include \"debayer.h\"\n@@ -108,10 +110,32 @@ private:\n \tvoid memcpyNextLine(const uint8_t *linePointers[]);\n \tvoid process2(uint32_t frame, const uint8_t *src, uint8_t *dst);\n \tvoid process4(uint32_t frame, const uint8_t *src, uint8_t *dst);\n+\tvoid updateGammaTable(DebayerParams &params);\n+\tvoid updateLookupTables(DebayerParams &params);\n \n \t/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */\n \tstatic constexpr unsigned int kMaxLineBuffers = 5;\n \n+\tstatic constexpr unsigned int kRGBLookupSize = 256;\n+\tstatic constexpr unsigned int kGammaLookupSize = 1024;\n+\tstruct CcmColumn {\n+\t\tint16_t r;\n+\t\tint16_t g;\n+\t\tint16_t b;\n+\t};\n+\tusing LookupTable = std::array<uint8_t, kRGBLookupSize>;\n+\tusing CcmLookupTable = std::array<CcmColumn, kRGBLookupSize>;\n+\tLookupTable red_;\n+\tLookupTable green_;\n+\tLookupTable blue_;\n+\tCcmLookupTable redCcm_;\n+\tCcmLookupTable greenCcm_;\n+\tCcmLookupTable blueCcm_;\n+\tstd::array<double, kGammaLookupSize> gammaTable_;\n+\tLookupTable gammaLut_;\n+\tbool ccmEnabled_;\n+\tDebayerParams params_;\n+\n \tdebayerFn debayer0_;\n \tdebayerFn debayer1_;\n \tdebayerFn debayer2_;\ndiff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp\nindex 37c44e8b1..722778103 100644\n--- a/src/libcamera/software_isp/debayer_egl.cpp\n+++ b/src/libcamera/software_isp/debayer_egl.cpp\n@@ -475,18 +475,18 @@ void DebayerEGL::setShaderVariableValues(DebayerParams &params)\n \t\t\t    << \" textureUniformProjMatrix_ \" << textureUniformProjMatrix_;\n \n \tGLfloat ccm[9] = {\n-\t\tparams.ccm[0][0],\n-\t\tparams.ccm[0][1],\n-\t\tparams.ccm[0][2],\n-\t\tparams.ccm[1][0],\n-\t\tparams.ccm[1][1],\n-\t\tparams.ccm[1][2],\n-\t\tparams.ccm[2][0],\n-\t\tparams.ccm[2][1],\n-\t\tparams.ccm[2][2],\n+\t\tparams.combinedMatrix[0][0],\n+\t\tparams.combinedMatrix[0][1],\n+\t\tparams.combinedMatrix[0][2],\n+\t\tparams.combinedMatrix[1][0],\n+\t\tparams.combinedMatrix[1][1],\n+\t\tparams.combinedMatrix[1][2],\n+\t\tparams.combinedMatrix[2][0],\n+\t\tparams.combinedMatrix[2][1],\n+\t\tparams.combinedMatrix[2][2],\n \t};\n \tglUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm);\n-\tLOG(Debayer, Debug) << \" ccmUniformDataIn_ \" << ccmUniformDataIn_ << \" data \" << params.ccm;\n+\tLOG(Debayer, Debug) << \" ccmUniformDataIn_ \" << ccmUniformDataIn_ << \" data \" << params.combinedMatrix;\n \n \t/*\n \t * 0 = Red, 1 = Green, 2 = Blue\n@@ -544,8 +544,6 @@ void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output\n \n \tdmaSyncBegin(dmaSyncers, input, nullptr);\n \n-\tsetParams(params);\n-\n \t/* Copy metadata from the input buffer */\n \tFrameMetadata &metadata = output->_d()->metadata();\n \tmetadata.status = input->metadata().status;\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 7ad3511db..a83986b78 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -84,23 +84,6 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n \t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n {\n-\t/*\n-\t * debayerParams_ must be initialized because the initial value is used for\n-\t * the first two frames, i.e. until stats processing starts providing its\n-\t * own parameters.\n-\t *\n-\t * \\todo This should be handled in the same place as the related\n-\t * operations, in the IPA module.\n-\t */\n-\tstd::array<uint8_t, 256> gammaTable;\n-\tfor (unsigned int i = 0; i < 256; i++)\n-\t\tgammaTable[i] = UINT8_MAX * std::pow(i / 256.0, 0.5);\n-\tfor (unsigned int i = 0; i < DebayerParams::kRGBLookupSize; i++) {\n-\t\tdebayerParams_.red[i] = gammaTable[i];\n-\t\tdebayerParams_.green[i] = gammaTable[i];\n-\t\tdebayerParams_.blue[i] = gammaTable[i];\n-\t}\n-\n \tif (!dmaHeap_.isValid()) {\n \t\tLOG(SoftwareIsp, Error) << \"Failed to create DmaBufAllocator object\";\n \t\treturn;\n@@ -121,8 +104,6 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t}\n \tstats->statsReady.connect(this, &SoftwareIsp::statsReady);\n \n-\tbool gpuIspEnabled;\n-\n #if HAVE_DEBAYER_EGL\n \tstd::optional<std::string> softISPMode = configuration.envOption(\"LIBCAMERA_SOFTISP_MODE\", { \"software_isp\", \"mode\" });\n \tif (softISPMode) {\n@@ -133,15 +114,12 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t\t}\n \t}\n \n-\tif (!softISPMode || softISPMode == \"gpu\") {\n+\tif (!softISPMode || softISPMode == \"gpu\")\n \t\tdebayer_ = std::make_unique<DebayerEGL>(std::move(stats), configuration);\n-\t\tgpuIspEnabled = true;\n-\t}\n+\n #endif\n-\tif (!debayer_) {\n+\tif (!debayer_)\n \t\tdebayer_ = std::make_unique<DebayerCpu>(std::move(stats), configuration);\n-\t\tgpuIspEnabled = false;\n-\t}\n \n \tdebayer_->inputBufferReady.connect(this, &SoftwareIsp::inputReady);\n \tdebayer_->outputBufferReady.connect(this, &SoftwareIsp::outputReady);\n@@ -173,7 +151,6 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n \t\t\t sharedParams_.fd(),\n \t\t\t sensorInfo,\n \t\t\t sensor->controls(),\n-\t\t\t gpuIspEnabled,\n \t\t\t ipaControls,\n \t\t\t &ccmEnabled_);\n \tif (ret) {\n","prefixes":["v5","14/15"]}