Show a patch.

GET /api/1.1/patches/23154/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23154,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/23154/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23154/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20250407085802.16269-1-mzamazal@redhat.com>",
    "date": "2025-04-07T08:58:02",
    "name": "libcamera: software_isp: Add saturation control",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "32b55f4a0aa9e9b1e61d05261c4bcdbd13ab3fd9",
    "submitter": {
        "id": 177,
        "url": "https://patchwork.libcamera.org/api/1.1/people/177/?format=api",
        "name": "Milan Zamazal",
        "email": "mzamazal@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23154/mbox/",
    "series": [
        {
            "id": 5118,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5118/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5118",
            "date": "2025-04-07T08:58:02",
            "name": "libcamera: software_isp: Add saturation control",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5118/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23154/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23154/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 8C94EC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Apr 2025 08:58:13 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 369C468A54;\n\tMon,  7 Apr 2025 10:58:13 +0200 (CEST)",
            "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 E8316689A8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Apr 2025 10:58:10 +0200 (CEST)",
            "from mx-prod-mc-02.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-628-a_5XSCVfOjqZVpmoav635A-1;\n\tMon, 07 Apr 2025 04:58:08 -0400",
            "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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS\n\tid A371E19560AB for <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Apr 2025 08:58:07 +0000 (UTC)",
            "from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.45.224.129])\n\tby mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 7736E180A803; Mon,  7 Apr 2025 08:58:06 +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=\"W94KqSDY\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1744016290;\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\tbh=vU/wIqwfm1co2AE+x5OlG+iqbSHfl5NlTF4KIJlDUos=;\n\tb=W94KqSDYbMfyGIxeFAyXKY7JbER4EfYXkblZvy0tvqU4A/KbA05Gr+aXlZXkHNfpA0cwUE\n\tp/bKUlZSx6tr0nsjHQCD9ViQy1DJu2Y0fEv/ApweEN9qZrYTeLlTCJo0sIeJyfVVAg2hih\n\tKyNbiyXLyb7GgkwVgii42KCKU8Q/Esw=",
        "X-MC-Unique": "a_5XSCVfOjqZVpmoav635A-1",
        "X-Mimecast-MFC-AGG-ID": "a_5XSCVfOjqZVpmoav635A_1744016287",
        "From": "Milan Zamazal <mzamazal@redhat.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Milan Zamazal <mzamazal@redhat.com>",
        "Subject": "[PATCH] libcamera: software_isp: Add saturation control",
        "Date": "Mon,  7 Apr 2025 10:58:02 +0200",
        "Message-ID": "<20250407085802.16269-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": "7c1ZrCax0UWVUcEglVFbLxuB2Kocl0i_Hc7KuUJDY9M_1744016287",
        "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": "Saturation control is added on top of the colour correction matrix.  A\nway of saturation adjustment that can be fully integrated into the\ncolour correction matrix is used.  The control is available only if Ccm\nalgorithm is enabled.\n\nThe control uses 0.0-2.0 value range, with 1.0 being unmodified\nsaturation, 0.0 full desaturation and 2.0 quite saturated.\n\nThe matrix for saturation adjustment is taken from\nhttps://www.graficaobscura.com/matrix/index.html.  The colour correction\nmatrix is applied before gamma and the given matrix is suitable for such\na case.  Alternatively, the transformation used in libcamera rpi ccm.cpp\ncould be used.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/ipa/simple/algorithms/ccm.cpp | 57 +++++++++++++++++++++++++++++--\n src/ipa/simple/algorithms/ccm.h   | 11 ++++++\n src/ipa/simple/ipa_context.h      |  4 +++\n 3 files changed, 69 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp\nindex d5ba928d..2700a247 100644\n--- a/src/ipa/simple/algorithms/ccm.cpp\n+++ b/src/ipa/simple/algorithms/ccm.cpp\n@@ -3,7 +3,7 @@\n  * Copyright (C) 2024, Ideas On Board\n  * Copyright (C) 2024-2025, Red Hat Inc.\n  *\n- * Color correction matrix\n+ * Color correction matrix + saturation\n  */\n \n #include \"ccm.h\"\n@@ -13,6 +13,8 @@\n \n #include <libcamera/control_ids.h>\n \n+#include \"libcamera/internal/matrix.h\"\n+\n namespace {\n \n constexpr unsigned int kTemperatureThreshold = 100;\n@@ -35,28 +37,73 @@ int Ccm::init([[maybe_unused]] IPAContext &context, const YamlObject &tuningData\n \t}\n \n \tcontext.ccmEnabled = true;\n+\tcontext.ctrlMap[&controls::Saturation] = ControlInfo(0.0f, 2.0f, 1.0f);\n+\n+\treturn 0;\n+}\n+\n+int Ccm::configure(IPAContext &context,\n+\t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n+{\n+\tcontext.activeState.knobs.saturation = std::optional<double>();\n \n \treturn 0;\n }\n \n+void Ccm::queueRequest(typename Module::Context &context,\n+\t\t       [[maybe_unused]] const uint32_t frame,\n+\t\t       [[maybe_unused]] typename Module::FrameContext &frameContext,\n+\t\t       const ControlList &controls)\n+{\n+\tconst auto &saturation = controls.get(controls::Saturation);\n+\tif (saturation.has_value()) {\n+\t\tcontext.activeState.knobs.saturation = saturation;\n+\t\tLOG(IPASoftCcm, Debug) << \"Setting saturation to \" << saturation.value();\n+\t}\n+}\n+\n+void Ccm::updateSaturation(Matrix<float, 3, 3> &ccm, float saturation)\n+{\n+\t/*\n+\t * See https://www.graficaobscura.com/matrix/index.html.\n+\t * This is applied before gamma thus a matrix for linear RGB must be used.\n+\t * The saturation range is 0..2, with 1 being an unchanged saturation and 0\n+\t * no saturation (monochrome).\n+\t */\n+\tconstexpr float r = 0.3086;\n+\tconstexpr float g = 0.6094;\n+\tconstexpr float b = 0.0820;\n+\tconst float s1 = 1.0 - saturation;\n+\tccm = ccm * Matrix<float, 3, 3>{ { s1 * r + saturation, s1 * g, s1 * b,\n+\t\t\t\t\t   s1 * r, s1 * g + saturation, s1 * b,\n+\t\t\t\t\t   s1 * r, s1 * g, s1 * b + saturation } };\n+}\n+\n void Ccm::prepare(IPAContext &context, const uint32_t frame,\n \t\t  IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)\n {\n+\tauto &saturation = context.activeState.knobs.saturation;\n+\n \tconst unsigned int ct = context.activeState.awb.temperatureK;\n \n-\t/* Change CCM only on bigger temperature changes. */\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    utils::abs_diff(ct, lastCt_) < kTemperatureThreshold &&\n+\t    saturation == lastSaturation_) {\n \t\tframeContext.ccm.ccm = context.activeState.ccm.ccm;\n \t\tcontext.activeState.ccm.changed = false;\n \t\treturn;\n \t}\n \n \tlastCt_ = ct;\n+\tlastSaturation_ = saturation;\n \tMatrix<float, 3, 3> ccm = ccm_.getInterpolated(ct);\n+\tif (saturation)\n+\t\tupdateSaturation(ccm, saturation.value());\n \n \tcontext.activeState.ccm.ccm = ccm;\n \tframeContext.ccm.ccm = ccm;\n+\tframeContext.saturation = saturation;\n \tcontext.activeState.ccm.changed = true;\n }\n \n@@ -67,6 +114,10 @@ void Ccm::process([[maybe_unused]] IPAContext &context,\n \t\t  ControlList &metadata)\n {\n \tmetadata.set(controls::ColourCorrectionMatrix, frameContext.ccm.ccm.data());\n+\n+\tconst auto &saturation = frameContext.saturation;\n+\tif (saturation)\n+\t\tmetadata.set(controls::Saturation, saturation.value());\n }\n \n REGISTER_IPA_ALGORITHM(Ccm, \"Ccm\")\ndiff --git a/src/ipa/simple/algorithms/ccm.h b/src/ipa/simple/algorithms/ccm.h\nindex f4e2b85b..2c5d2170 100644\n--- a/src/ipa/simple/algorithms/ccm.h\n+++ b/src/ipa/simple/algorithms/ccm.h\n@@ -7,6 +7,8 @@\n \n #pragma once\n \n+#include <optional>\n+\n #include \"libcamera/internal/matrix.h\"\n \n #include <libipa/interpolator.h>\n@@ -24,6 +26,12 @@ public:\n \t~Ccm() = default;\n \n \tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tint configure(IPAContext &context,\n+\t\t      const IPAConfigInfo &configInfo) override;\n+\tvoid queueRequest(typename Module::Context &context,\n+\t\t\t  const uint32_t frame,\n+\t\t\t  typename Module::FrameContext &frameContext,\n+\t\t\t  const ControlList &controls) override;\n \tvoid prepare(IPAContext &context,\n \t\t     const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n@@ -34,7 +42,10 @@ public:\n \t\t     ControlList &metadata) override;\n \n private:\n+\tvoid updateSaturation(Matrix<float, 3, 3> &ccm, float saturation);\n+\n \tunsigned int lastCt_;\n+\tstd::optional<float> lastSaturation_;\n \tInterpolator<Matrix<float, 3, 3>> ccm_;\n };\n \ndiff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\nindex 88cc6c35..56792981 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -63,6 +63,7 @@ struct IPAActiveState {\n \tstruct {\n \t\t/* 0..2 range, 1.0 = normal */\n \t\tstd::optional<double> contrast;\n+\t\tstd::optional<double> saturation;\n \t} knobs;\n };\n \n@@ -75,11 +76,14 @@ struct IPAFrameContext : public FrameContext {\n \t\tint32_t exposure;\n \t\tdouble gain;\n \t} sensor;\n+\n \tstruct {\n \t\tdouble red;\n \t\tdouble blue;\n \t} gains;\n+\n \tstd::optional<double> contrast;\n+\tstd::optional<double> saturation;\n };\n \n struct IPAContext {\n",
    "prefixes": []
}