Patch Detail
Show a patch.
GET /api/patches/25778/?format=api
{ "id": 25778, "url": "https://patchwork.libcamera.org/api/patches/25778/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25778/", "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": "<20260114113016.25162-14-mzamazal@redhat.com>", "date": "2026-01-14T11:30:15", "name": "[v3,13/14] libcamera: ipa: simple: Remove Lut algorithm", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "201594fe9fe2cc36f3381dd77844c13799c1345a", "submitter": { "id": 177, "url": "https://patchwork.libcamera.org/api/people/177/?format=api", "name": "Milan Zamazal", "email": "mzamazal@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/25778/mbox/", "series": [ { "id": 5706, "url": "https://patchwork.libcamera.org/api/series/5706/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5706", "date": "2026-01-14T11:30:02", "name": "Simple pipeline IPA cleanup", "version": 3, "mbox": "https://patchwork.libcamera.org/series/5706/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25778/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25778/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 A8CE4C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Jan 2026 11:31:12 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 30B5961FD8;\n\tWed, 14 Jan 2026 12:31:12 +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 2413661FC6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Jan 2026 12:31:09 +0100 (CET)", "from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-633-wWPPd8eDPCqwWQ_vOMP8mg-1;\n\tWed, 14 Jan 2026 06:31:06 -0500", "from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.93])\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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id B4BBB1800378; Wed, 14 Jan 2026 11:31:05 +0000 (UTC)", "from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.217])\n\tby mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 4E4511800665; Wed, 14 Jan 2026 11:31:03 +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=\"OEQ8ngQX\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1768390268;\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=9f3NWipm0WF5lD8vhDbSLyE7PPWkwzCvLusYOLJoplM=;\n\tb=OEQ8ngQXOuxKSjNsKkk3MJ2vXYEUob3+gZz7sFjDM2UJnqS87eqlBMh2y7kflkO6uaevs2\n\tpMXb63XEYDRrSaYe8Fm/7ua9AE2MnTAD63LB62d0VGl9hvhosx9t+vGE44NGKU1UjJlY85\n\tmZCVOPxjN05d9BOHmWWXkcq6FokHS3A=", "X-MC-Unique": "wWPPd8eDPCqwWQ_vOMP8mg-1", "X-Mimecast-MFC-AGG-ID": "wWPPd8eDPCqwWQ_vOMP8mg_1768390265", "From": "Milan Zamazal <mzamazal@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>", "Subject": "[PATCH v3 13/14] libcamera: ipa: simple: Remove Lut algorithm", "Date": "Wed, 14 Jan 2026 12:30:15 +0100", "Message-ID": "<20260114113016.25162-14-mzamazal@redhat.com>", "In-Reply-To": "<20260114113016.25162-1-mzamazal@redhat.com>", "References": "<20260114113016.25162-1-mzamazal@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.93", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "wPxU0SKsEmEQPVenI0jOdKzEZpO9CQxXSIU1bewiY60_1768390265", "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\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../internal/software_isp/debayer_params.h | 43 +----\n src/ipa/simple/algorithms/adjust.cpp | 20 +-\n src/ipa/simple/algorithms/adjust.h | 2 -\n src/ipa/simple/algorithms/awb.cpp | 7 +-\n src/ipa/simple/algorithms/ccm.cpp | 4 +-\n src/ipa/simple/algorithms/lut.cpp | 141 --------------\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 | 10 -\n src/ipa/simple/soft_simple.cpp | 10 +-\n src/libcamera/software_isp/debayer.cpp | 172 +-----------------\n src/libcamera/software_isp/debayer.h | 8 -\n src/libcamera/software_isp/debayer_cpu.cpp | 141 ++++++++++++--\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 | 17 --\n 17 files changed, 195 insertions(+), 465 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/src/ipa/simple/algorithms/adjust.cpp b/src/ipa/simple/algorithms/adjust.cpp\nindex 60a191380..8e2230164 100644\n--- a/src/ipa/simple/algorithms/adjust.cpp\n+++ b/src/ipa/simple/algorithms/adjust.cpp\n@@ -1,7 +1,7 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n * Copyright (C) 2024, Ideas On Board\n- * Copyright (C) 2024-2025, Red Hat Inc.\n+ * Copyright (C) 2024-2026, Red Hat Inc.\n *\n * Common image adjustments\n */\n@@ -92,22 +92,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.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.value_or(kDefaultGamma);\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+\tparams->combinedMatrix = context.activeState.combinedMatrix;\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 11d8297ca..02e469a50 100644\n--- a/src/ipa/simple/algorithms/adjust.h\n+++ b/src/ipa/simple/algorithms/adjust.h\n@@ -47,8 +47,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 4d2f1df15..d361cd6c5 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,12 @@ 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+\tparams->combinedMatrix = context.activeState.combinedMatrix;\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 1b2c6eb3a..aa06b5274 100644\n--- a/src/ipa/simple/algorithms/ccm.cpp\n+++ b/src/ipa/simple/algorithms/ccm.cpp\n@@ -42,7 +42,7 @@ int Ccm::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData\n }\n \n void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n-\t\t IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)\n+\t\t IPAFrameContext &frameContext, DebayerParams *params)\n {\n \tconst unsigned int ct = context.activeState.awb.temperatureK;\n \n@@ -52,13 +52,13 @@ void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\tcurrentCcm_ = ccm_.getInterpolated(ct);\n \t\tccmAssigned_ = true;\n \t\tlastCt_ = ct;\n-\t\tcontext.activeState.matrixChanged = true;\n \t}\n \n \tcontext.activeState.combinedMatrix =\n \t\tcurrentCcm_ * context.activeState.combinedMatrix;\n \tcontext.activeState.ccm = currentCcm_;\n \tframeContext.ccm = currentCcm_;\n+\tparams->combinedMatrix = context.activeState.combinedMatrix;\n }\n \n void Ccm::process([[maybe_unused]] IPAContext &context,\ndiff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\ndeleted file mode 100644\nindex f31a7e631..000000000\n--- a/src/ipa/simple/algorithms/lut.cpp\n+++ /dev/null\n@@ -1,141 +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 =\n-\t\t1.0 / context.activeState.knobs.gamma.value_or(kDefaultGamma);\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 85455bbfa..aec864d02 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -53,18 +53,8 @@ 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> ccm;\n \tMatrix<float, 3, 3> combinedMatrix;\n-\tbool matrixChanged = false;\n \n \tstruct {\n \t\tstd::optional<float> gamma;\ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex 732e82510..b85e09501 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@@ -161,6 +162,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@@ -282,7 +288,9 @@ void IPASoftSimple::queueRequest(const uint32_t frame, const ControlList &contro\n \n void IPASoftSimple::computeParams(const uint32_t frame)\n {\n-\tcontext_.activeState.combinedMatrix = Matrix<float, 3, 3>::identity();\n+\tMatrix<float, 3, 3> combinedMatrix = Matrix<float, 3, 3>::identity();\n+\tcontext_.activeState.combinedMatrix = combinedMatrix;\n+\tparams_->combinedMatrix = combinedMatrix;\n \n \tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \tfor (auto const &algo : algorithms())\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 ¶ms)\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 ¶ms)\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 ¶ms)\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 ¶ms);\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..dcd931d2d 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,103 @@ void DebayerCpu::process4(uint32_t frame, const uint8_t *src, uint8_t *dst)\n \t}\n }\n \n+void DebayerCpu::updateGammaTable(DebayerParams ¶ms)\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 ¶ms)\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 = [](Matrix<float, 3, 3> m1, Matrix<float, 3, 3> m2) -> bool {\n+\t\tfor (unsigned int i = 0; i < 3; i++)\n+\t\t\tfor (unsigned int j = 0; j < 3; j++)\n+\t\t\t\tif (m1[i][j] != m2[i][j])\n+\t\t\t\t\treturn true;\n+\t\treturn false;\n+\t};\n+\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 +855,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 ¶ms);\n+\tvoid updateLookupTables(DebayerParams ¶ms);\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 8e0890323..ddf03ad4b 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 ¶ms)\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..ebdf5b2c6 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", "prefixes": [ "v3", "13/14" ] }