{"id":25771,"url":"https://patchwork.libcamera.org/api/patches/25771/?format=json","web_url":"https://patchwork.libcamera.org/patch/25771/","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":"<20260114113016.25162-7-mzamazal@redhat.com>","date":"2026-01-14T11:30:08","name":"[v3,06/14] libcamera: ipa: simple: Initialise the general correction matrix","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9d5ef74d9296a3fe799b946a22926ea9a04e483a","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/25771/mbox/","series":[{"id":5706,"url":"https://patchwork.libcamera.org/api/series/5706/?format=json","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/25771/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25771/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 EB847C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Jan 2026 11:30:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9A81B61FCA;\n\tWed, 14 Jan 2026 12:30:57 +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 1846661FBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Jan 2026 12:30:56 +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-690-EeEqqUSLOc-O2tOBZioL5Q-1;\n\tWed, 14 Jan 2026 06:30:50 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 9E2C118003FC; Wed, 14 Jan 2026 11:30:49 +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 BF2B81800665; Wed, 14 Jan 2026 11:30:47 +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=\"aMpoibBb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1768390255;\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=JQLC/YW80//VznTjTZIJs0LSPXvvL2b3e4i8lkrNR9M=;\n\tb=aMpoibBbug/ZchcaCIEjBD/imyHyHo66kCPpVyTP2hCuJ6NlzgKkNH3kvmMsKlRpHPEy73\n\t+3KPjRQZURoFQKUR///Rbo3m6oVXYe5anNjhWQufaASf631dRctarHV4YEUYEAhn+hikbE\n\tdxXqSm5ta8bYjBPI7bbh3TXxkvtpJLI=","X-MC-Unique":"EeEqqUSLOc-O2tOBZioL5Q-1","X-Mimecast-MFC-AGG-ID":"EeEqqUSLOc-O2tOBZioL5Q_1768390249","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 06/14] libcamera: ipa: simple: Initialise the general\n\tcorrection matrix","Date":"Wed, 14 Jan 2026 12:30:08 +0100","Message-ID":"<20260114113016.25162-7-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":"t4Wwr0S26gOIB7Ke5Dofzaj_m6qbi3BC51ZRFqCHKg0_1768390249","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 | 31 +++++++++++++++----------------\n src/ipa/simple/algorithms/ccm.h   |  2 ++\n src/ipa/simple/soft_simple.cpp    |  2 ++\n 3 files changed, 19 insertions(+), 16 deletions(-)","diff":"diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp\nindex a3e8cd6c4..8992a8ee1 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,23 @@ 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 (!ccmAssigned_ ||\n+\t    utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold ||\n+\t    saturation != lastSaturation_) {\n+\t\tcurrentCcm_ = ccm_.getInterpolated(ct);\n+\t\tccmAssigned_ = true;\n+\t\tif (saturation)\n+\t\t\tapplySaturation(currentCcm_, 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_ * context.activeState.combinedMatrix;\n+\tcontext.activeState.ccm = currentCcm_;\n \tframeContext.saturation = saturation;\n-\tcontext.activeState.matrixChanged = true;\n-\tframeContext.ccm = ccm;\n+\tframeContext.ccm = currentCcm_;\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..19bf283af 100644\n--- a/src/ipa/simple/algorithms/ccm.h\n+++ b/src/ipa/simple/algorithms/ccm.h\n@@ -47,6 +47,8 @@ private:\n \tunsigned int lastCt_;\n \tstd::optional<float> lastSaturation_;\n \tInterpolator<Matrix<float, 3, 3>> ccm_;\n+\tMatrix<float, 3, 3> currentCcm_;\n+\tbool ccmAssigned_ = false;\n };\n \n } /* namespace ipa::soft::algorithms */\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":["v3","06/14"]}