{"id":25932,"url":"https://patchwork.libcamera.org/api/1.1/patches/25932/?format=json","web_url":"https://patchwork.libcamera.org/patch/25932/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20260122161935.208562-7-mzamazal@redhat.com>","date":"2026-01-22T16:19:26","name":"[v4,06/15] libcamera: ipa: simple: Initialise the general correction matrix","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7be9c111b1ca4b300b8b2084767c80b7d3cd8761","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/1.1/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25932/mbox/","series":[{"id":5733,"url":"https://patchwork.libcamera.org/api/1.1/series/5733/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5733","date":"2026-01-22T16:19:20","name":"Simple pipeline IPA cleanup","version":4,"mbox":"https://patchwork.libcamera.org/series/5733/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25932/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25932/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 6CC1FBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Jan 2026 16:20:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0C2A661FD6;\n\tThu, 22 Jan 2026 17:20:29 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 52F9D61FD6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 Jan 2026 17:20:27 +0100 (CET)","from mx-prod-mc-08.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-658--UyLs7OSMGWdOajm0RKPpw-1;\n\tThu, 22 Jan 2026 11:20:22 -0500","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.111])\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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id EB6D41800359; Thu, 22 Jan 2026 16:20:21 +0000 (UTC)","from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.97])\n\tby mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id EFDB61801A45; Thu, 22 Jan 2026 16:20:19 +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=\"gpc6cyyp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1769098826;\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=+wgL+P6kMkDZ81o4zsJ9WkocXgMiqwVZYegIbyGVed4=;\n\tb=gpc6cyypXVL4cpeeLhQVEe/EJp/QZSYXQoJ2TpD7OygKAE4MVd943iMe71xK4zwMmOrUTe\n\tVG+YopHGiB1XsRn8/qKjCGF5QLNYaEY7wH7BKE0kqpImPy86jkZcRGwsVP9t/iqLlCAhl8\n\tm2ncTNq2Tixiv3cmNJlSCuMM/SryVoE=","X-MC-Unique":"-UyLs7OSMGWdOajm0RKPpw-1","X-Mimecast-MFC-AGG-ID":"-UyLs7OSMGWdOajm0RKPpw_1769098822","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 v4 06/15] libcamera: ipa: simple: Initialise the general\n\tcorrection matrix","Date":"Thu, 22 Jan 2026 17:19:26 +0100","Message-ID":"<20260122161935.208562-7-mzamazal@redhat.com>","In-Reply-To":"<20260122161935.208562-1-mzamazal@redhat.com>","References":"<20260122161935.208562-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"pwDJSZR47NBlO6JZ1pSMr2PnbgYnC55T6epLo1i85Fo_1769098822","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 combined matrix must be reset to the initial value before each frame\nis prepared.  This must be done outside algorithms because any of the\nalgorithms may be disabled while the matrix must be always initialised.\n\nLet's initialise the combined matrix to the identity matrix (which keeps\nthe pixel values unchanged) in software ISP just before calling\n`prepare' on the algorithms.\n\nMatrix updates can no longer be skipped in ccm.cpp, otherwise the CCM\nwon't be applied if there is no temperature or saturation change.  We\nexplicitly track whether the CCM has been set up completely rather than\nrelying on the frame number, to avoid missing the initialisation in case\nthe first frame is skipped due to some error.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/ipa/simple/algorithms/ccm.cpp | 29 +++++++++++++----------------\n src/ipa/simple/algorithms/ccm.h   |  3 ++-\n src/ipa/simple/ipa_context.h      |  1 -\n src/ipa/simple/soft_simple.cpp    |  2 ++\n 4 files changed, 17 insertions(+), 18 deletions(-)","diff":"diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp\nindex a3e8cd6c4..85643645b 100644\n--- a/src/ipa/simple/algorithms/ccm.cpp\n+++ b/src/ipa/simple/algorithms/ccm.cpp\n@@ -83,7 +83,7 @@ void Ccm::applySaturation(Matrix<float, 3, 3> &ccm, float saturation)\n \tccm = ycbcr2rgb * saturationMatrix * rgb2ycbcr * ccm;\n }\n \n-void Ccm::prepare(IPAContext &context, const uint32_t frame,\n+void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\t  IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)\n {\n \tauto &saturation = context.activeState.knobs.saturation;\n@@ -91,24 +91,21 @@ void Ccm::prepare(IPAContext &context, const uint32_t frame,\n \tconst unsigned int ct = context.activeState.awb.temperatureK;\n \n \t/* Change CCM only on saturation or bigger temperature changes. */\n-\tif (frame > 0 &&\n-\t    utils::abs_diff(ct, lastCt_) < kTemperatureThreshold &&\n-\t    saturation == lastSaturation_) {\n-\t\tframeContext.ccm = context.activeState.ccm;\n-\t\treturn;\n+\tif (!currentCcm_ ||\n+\t    utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold ||\n+\t    saturation != lastSaturation_) {\n+\t\tcurrentCcm_ = ccm_.getInterpolated(ct);\n+\t\tif (saturation)\n+\t\t\tapplySaturation(currentCcm_.value(), saturation.value());\n+\t\tlastCt_ = ct;\n+\t\tlastSaturation_ = saturation;\n+\t\tcontext.activeState.matrixChanged = true;\n \t}\n \n-\tlastCt_ = ct;\n-\tlastSaturation_ = saturation;\n-\tMatrix<float, 3, 3> ccm = ccm_.getInterpolated(ct);\n-\tif (saturation)\n-\t\tapplySaturation(ccm, saturation.value());\n-\n-\tcontext.activeState.combinedMatrix = ccm;\n-\tcontext.activeState.ccm = ccm;\n+\tcontext.activeState.combinedMatrix =\n+\t\tcurrentCcm_.value() * context.activeState.combinedMatrix;\n \tframeContext.saturation = saturation;\n-\tcontext.activeState.matrixChanged = true;\n-\tframeContext.ccm = ccm;\n+\tframeContext.ccm = currentCcm_.value();\n }\n \n void Ccm::process([[maybe_unused]] IPAContext &context,\ndiff --git a/src/ipa/simple/algorithms/ccm.h b/src/ipa/simple/algorithms/ccm.h\nindex 8279a3d59..867a680c3 100644\n--- a/src/ipa/simple/algorithms/ccm.h\n+++ b/src/ipa/simple/algorithms/ccm.h\n@@ -1,6 +1,6 @@\n /* SPDX-License-Identifier: LGPL-2.1-or-later */\n /*\n- * Copyright (C) 2024-2025, Red Hat Inc.\n+ * Copyright (C) 2024-2026, Red Hat Inc.\n  *\n  * Color correction matrix\n  */\n@@ -47,6 +47,7 @@ private:\n \tunsigned int lastCt_;\n \tstd::optional<float> lastSaturation_;\n \tInterpolator<Matrix<float, 3, 3>> ccm_;\n+\tstd::optional<Matrix<float, 3, 3>> currentCcm_;\n };\n \n } /* namespace ipa::soft::algorithms */\ndiff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\nindex 58dcad290..a3ff3d038 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -62,7 +62,6 @@ struct IPAActiveState {\n \t\tdouble contrastExp;\n \t} gamma;\n \n-\tMatrix<float, 3, 3> ccm;\n \tMatrix<float, 3, 3> combinedMatrix;\n \tbool matrixChanged = false;\n \ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex 57836c73c..732e82510 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -282,6 +282,8 @@ 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+\n \tIPAFrameContext &frameContext = context_.frameContexts.get(frame);\n \tfor (auto const &algo : algorithms())\n \t\talgo->prepare(context_, frame, frameContext, params_);\n","prefixes":["v4","06/15"]}