[{"id":37988,"web_url":"https://patchwork.libcamera.org/comment/37988/","msgid":"<176960445863.3376561.12301446380254357604@ping.linuxembedded.co.uk>","date":"2026-01-28T12:47:38","subject":"Re: [PATCH v5 06/15] libcamera: ipa: simple: Initialise the general\n\tcorrection matrix","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2026-01-28 11:43:53)\n> The combined matrix must be reset to the initial value before each frame\n> is prepared.  This must be done outside algorithms because any of the\n> algorithms may be disabled while the matrix must be always initialised.\n> \n> Let's initialise the combined matrix to the identity matrix (which keeps\n> the pixel values unchanged) in software ISP just before calling\n> `prepare' on the algorithms.\n> \n> Matrix updates can no longer be skipped in ccm.cpp, otherwise the CCM\n> won't be applied if there is no temperature or saturation change.  We\n> explicitly track whether the CCM has been set up completely rather than\n> relying on the frame number, to avoid missing the initialisation in case\n> the first frame is skipped due to some error.\n> \n> Reviewed-by: Robert Mader <robert.mader@collabora.com>\n> Signed-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(-)\n> \n> diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp\n> index 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>         ccm = 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>                   IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)\n>  {\n>         auto &saturation = context.activeState.knobs.saturation;\n> @@ -91,24 +91,21 @@ void Ccm::prepare(IPAContext &context, const uint32_t frame,\n>         const unsigned int ct = context.activeState.awb.temperatureK;\n>  \n>         /* Change CCM only on saturation or bigger temperature changes. */\n> -       if (frame > 0 &&\n> -           utils::abs_diff(ct, lastCt_) < kTemperatureThreshold &&\n> -           saturation == lastSaturation_) {\n> -               frameContext.ccm = context.activeState.ccm;\n> -               return;\n> +       if (!currentCcm_ ||\n> +           utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold ||\n> +           saturation != lastSaturation_) {\n> +               currentCcm_ = ccm_.getInterpolated(ct);\n> +               if (saturation)\n> +                       applySaturation(currentCcm_.value(), saturation.value());\n> +               lastCt_ = ct;\n> +               lastSaturation_ = saturation;\n> +               context.activeState.matrixChanged = true;\n>         }\n>  \n> -       lastCt_ = ct;\n> -       lastSaturation_ = saturation;\n> -       Matrix<float, 3, 3> ccm = ccm_.getInterpolated(ct);\n> -       if (saturation)\n> -               applySaturation(ccm, saturation.value());\n> -\n> -       context.activeState.combinedMatrix = ccm;\n> -       context.activeState.ccm = ccm;\n> +       context.activeState.combinedMatrix =\n> +               currentCcm_.value() * context.activeState.combinedMatrix;\n>         frameContext.saturation = saturation;\n> -       context.activeState.matrixChanged = true;\n> -       frameContext.ccm = ccm;\n> +       frameContext.ccm = currentCcm_.value();\n>  }\n>  \n>  void Ccm::process([[maybe_unused]] IPAContext &context,\n> diff --git a/src/ipa/simple/algorithms/ccm.h b/src/ipa/simple/algorithms/ccm.h\n> index 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>         unsigned int lastCt_;\n>         std::optional<float> lastSaturation_;\n>         Interpolator<Matrix<float, 3, 3>> ccm_;\n> +       std::optional<Matrix<float, 3, 3>> currentCcm_;\n>  };\n>  \n>  } /* namespace ipa::soft::algorithms */\n> diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\n> index 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>                 double contrastExp;\n>         } gamma;\n>  \n> -       Matrix<float, 3, 3> ccm;\n>         Matrix<float, 3, 3> combinedMatrix;\n>         bool matrixChanged = false;\n>  \n> diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\n> index 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> +       context_.activeState.combinedMatrix = Matrix<float, 3, 3>::identity();\n\nthis is an interesting/different use case of activeState that we haven't\nseen yet as it's reset for each context.\n\nSomething which requires being reset for each frame ... sounds to me\nlike something that should go in the FrameContext... but there might\nstill be nuances there too.\n\nSo I'm tempted to say this is fine for now - but might be something to\nrevisit later...\n\nAcked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n>         IPAFrameContext &frameContext = context_.frameContexts.get(frame);\n>         for (auto const &algo : algorithms())\n>                 algo->prepare(context_, frame, frameContext, params_);\n> -- \n> 2.52.0\n>","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 3F570C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jan 2026 12:47:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 78A8061FC9;\n\tWed, 28 Jan 2026 13:47:42 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A92BD61FC4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jan 2026 13:47:41 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 838111E3F;\n\tWed, 28 Jan 2026 13:47:04 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VgmgVc/1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1769604424;\n\tbh=QtRjxskV5u/k+0UO6Vu0zyFIJooBxvBZH1xjM0IMASs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=VgmgVc/15qH8POOwIW+h9CI4KwqUfHv9sEjcD+oW9fUoVDazGnUi1P1SqNVzgS/XB\n\tTPstytLCTMzBw48Db4ZGdGtg2LBVebK+d0c3pUz5ubw8FdiX6UPaML3PwvBAFH2Dut\n\tzTPbsNaDmCMw9Hh/I2sGyLDxTzOKYUsTLQ6xEbRA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20260128114402.31570-7-mzamazal@redhat.com>","References":"<20260128114402.31570-1-mzamazal@redhat.com>\n\t<20260128114402.31570-7-mzamazal@redhat.com>","Subject":"Re: [PATCH v5 06/15] libcamera: ipa: simple: Initialise the general\n\tcorrection matrix","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>,\n\tRobert Mader <robert.mader@collabora.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Wed, 28 Jan 2026 12:47:38 +0000","Message-ID":"<176960445863.3376561.12301446380254357604@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]