{"id":26000,"url":"https://patchwork.libcamera.org/api/patches/26000/?format=json","web_url":"https://patchwork.libcamera.org/patch/26000/","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-7-mzamazal@redhat.com>","date":"2026-01-28T11:43:53","name":"[v5,06/15] libcamera: ipa: simple: Initialise the general correction matrix","commit_ref":"82ed6c19c2b362b268536ac123d8d03a3222a23d","pull_url":null,"state":"accepted","archived":false,"hash":"7be9c111b1ca4b300b8b2084767c80b7d3cd8761","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/26000/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/26000/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26000/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 50A5FC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 11:44:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B972861FE8;\n\tWed, 28 Jan 2026 12:44:35 +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 909F261FDA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 12:44:30 +0100 (CET)","from mx-prod-mc-03.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-15-mI6c1zOUO9K876D7D8iP2g-1;\n\tWed, 28 Jan 2026 06:44:24 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 1D1031955D8E; Wed, 28 Jan 2026 11:44:23 +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 6E54F19560B4; Wed, 28 Jan 2026 11:44:21 +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=\"IDf4NrLm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1769600669;\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=RbcfjV2aZVIq9RQLpoQQem6jLjKghnJI6DW2x5psyh8=;\n\tb=IDf4NrLm992vtVJyCfmD/0GS+aScrSWNkrRBaKlPiVKU45oCnDK1f0Oxu6AiG8PPldVPxb\n\tSB/jy7FFw387hhGAqOGb4eqRsRiPFZYhCxQHv7sgeof8NcIxjsR35V4j7O7mrOxAHx0sP6\n\tuF/2tslCAd6lhXUswUHgrXyTZLOUlm0=","X-MC-Unique":"mI6c1zOUO9K876D7D8iP2g-1","X-Mimecast-MFC-AGG-ID":"mI6c1zOUO9K876D7D8iP2g_1769600663","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 06/15] libcamera: ipa: simple: Initialise the general\n\tcorrection matrix","Date":"Wed, 28 Jan 2026 12:43:53 +0100","Message-ID":"<20260128114402.31570-7-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":"5R8jhOPgufvMmzo-baNTfy4JFYg8kszQ_jkmINLYOmM_1769600663","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\nReviewed-by: Robert Mader <robert.mader@collabora.com>\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":["v5","06/15"]}