{"id":21570,"url":"https://patchwork.libcamera.org/api/patches/21570/?format=json","web_url":"https://patchwork.libcamera.org/patch/21570/","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":"<20241009193318.2394762-3-mzamazal@redhat.com>","date":"2024-10-09T19:33:17","name":"[v2,2/2] libcamera: software_isp: Add contrast control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"dd8d6ed283c03008ace50a9d7ec9cf4ce66e2dd3","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/21570/mbox/","series":[{"id":4677,"url":"https://patchwork.libcamera.org/api/series/4677/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4677","date":"2024-10-09T19:33:15","name":"Add contrast control to software ISP","version":2,"mbox":"https://patchwork.libcamera.org/series/4677/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21570/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21570/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 D7732C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Oct 2024 19:33:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 80BA365370;\n\tWed,  9 Oct 2024 21:33:42 +0200 (CEST)","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 0813A65369\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 21:33:38 +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-301-zt_a0tSlNV26mbWJ1aUnow-1;\n\tWed, 09 Oct 2024 15:33:34 -0400","from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\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 id E1EB31955F41; Wed,  9 Oct 2024 19:33:33 +0000 (UTC)","from nuthatch.redhat.com (unknown [10.45.224.78])\n\tby mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 78D07300018D; Wed,  9 Oct 2024 19:33:32 +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=\"ImCYfx/2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1728502418;\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=Wj8NCScrvNGUQPcZoBrVbd/ZyBzALfuB6ydcxuhkP6M=;\n\tb=ImCYfx/2pvOvglisgeYBM8EUGq+BR0dlZTbbRKmKG6de189QeV/MHuBkSXoLnYT5DT77Mb\n\ta2wEF1dKv4Nh+PTAVLx1s7KtpCPovrRigZ8B1Vw8Ltgk4T7K+zK20tfJCA4tmivjtvQ2eU\n\tPYW0AR+lBuyo1mLGaofRyTORcr2HdZ0=","X-MC-Unique":"zt_a0tSlNV26mbWJ1aUnow-1","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>","Subject":"[PATCH v2 2/2] libcamera: software_isp: Add contrast control","Date":"Wed,  9 Oct 2024 21:33:17 +0200","Message-ID":"<20241009193318.2394762-3-mzamazal@redhat.com>","In-Reply-To":"<20241009193318.2394762-1-mzamazal@redhat.com>","References":"<20241009193318.2394762-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.4","X-Mimecast-Spam-Score":"0","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":"This patch introduces support for applying runtime controls to software\nISP.  It enables the contrast algorithm as the first control that can be\nused.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../libcamera/internal/software_isp/software_isp.h    |  3 ++-\n include/libcamera/ipa/soft.mojom                      |  2 +-\n src/ipa/simple/algorithms/contrast.cpp                |  7 +++++++\n src/ipa/simple/algorithms/contrast.h                  |  2 ++\n src/ipa/simple/data/uncalibrated.yaml                 |  1 +\n src/ipa/simple/ipa_context.h                          |  1 +\n src/ipa/simple/soft_simple.cpp                        | 11 ++++++++---\n src/libcamera/pipeline/simple/simple.cpp              |  2 +-\n src/libcamera/software_isp/software_isp.cpp           |  8 ++++++--\n 9 files changed, 29 insertions(+), 8 deletions(-)","diff":"diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\nindex a3e3a9da4..d51b03fd6 100644\n--- a/include/libcamera/internal/software_isp/software_isp.h\n+++ b/include/libcamera/internal/software_isp/software_isp.h\n@@ -46,7 +46,8 @@ LOG_DECLARE_CATEGORY(SoftwareIsp)\n class SoftwareIsp\n {\n public:\n-\tSoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor);\n+\tSoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n+\t\t    ControlInfoMap *ipaControls);\n \t~SoftwareIsp();\n \n \tint loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }\ndiff --git a/include/libcamera/ipa/soft.mojom b/include/libcamera/ipa/soft.mojom\nindex 347fd69b4..16e6a7071 100644\n--- a/include/libcamera/ipa/soft.mojom\n+++ b/include/libcamera/ipa/soft.mojom\n@@ -17,7 +17,7 @@ interface IPASoftInterface {\n \t     libcamera.SharedFD fdStats,\n \t     libcamera.SharedFD fdParams,\n \t     libcamera.ControlInfoMap sensorCtrlInfoMap)\n-\t\t=> (int32 ret);\n+\t\t=> (int32 ret, libcamera.ControlInfoMap ipaControls);\n \tstart() => (int32 ret);\n \tstop();\n \tconfigure(IPAConfigInfo configInfo)\ndiff --git a/src/ipa/simple/algorithms/contrast.cpp b/src/ipa/simple/algorithms/contrast.cpp\nindex 1a2c14cf9..8d9997d81 100644\n--- a/src/ipa/simple/algorithms/contrast.cpp\n+++ b/src/ipa/simple/algorithms/contrast.cpp\n@@ -19,6 +19,13 @@ LOG_DEFINE_CATEGORY(IPASoftContrast)\n \n namespace ipa::soft::algorithms {\n \n+int Contrast::init(IPAContext &context,\n+\t\t   [[maybe_unused]] const YamlObject &tuningData)\n+{\n+\tcontext.ctrlMap[&controls::Contrast] = ControlInfo(0.0f, 10.0f, 1.0f);\n+\treturn 0;\n+}\n+\n int Contrast::configure(typename Module::Context &context,\n \t\t\t[[maybe_unused]] const typename Module::Config &configInfo)\n {\ndiff --git a/src/ipa/simple/algorithms/contrast.h b/src/ipa/simple/algorithms/contrast.h\nindex 0b3933099..405345acc 100644\n--- a/src/ipa/simple/algorithms/contrast.h\n+++ b/src/ipa/simple/algorithms/contrast.h\n@@ -21,6 +21,8 @@ public:\n \tContrast() = default;\n \t~Contrast() = default;\n \n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\n \tint configure(typename Module::Context &context,\n \t\t      const typename Module::Config &configInfo)\n \t\toverride;\ndiff --git a/src/ipa/simple/data/uncalibrated.yaml b/src/ipa/simple/data/uncalibrated.yaml\nindex 3f1471121..c091e30fd 100644\n--- a/src/ipa/simple/data/uncalibrated.yaml\n+++ b/src/ipa/simple/data/uncalibrated.yaml\n@@ -5,6 +5,7 @@ version: 1\n algorithms:\n   - BlackLevel:\n   - Awb:\n+  - Contrast:\n   - Lut:\n   - Agc:\n ...\ndiff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\nindex 5118d6abf..095c83800 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -65,6 +65,7 @@ struct IPAContext {\n \tIPASessionConfiguration configuration;\n \tIPAActiveState activeState;\n \tFCQueue<IPAFrameContext> frameContexts;\n+\tControlInfoMap::Map ctrlMap;\n };\n \n } /* namespace ipa::soft */\ndiff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp\nindex b28c7039f..eb027d754 100644\n--- a/src/ipa/simple/soft_simple.cpp\n+++ b/src/ipa/simple/soft_simple.cpp\n@@ -41,7 +41,7 @@ class IPASoftSimple : public ipa::soft::IPASoftInterface, public Module\n {\n public:\n \tIPASoftSimple()\n-\t\t: context_({ {}, {}, { kMaxFrameContexts } })\n+\t\t: context_({ {}, {}, { kMaxFrameContexts }, {} })\n \t{\n \t}\n \n@@ -50,7 +50,8 @@ public:\n \tint init(const IPASettings &settings,\n \t\t const SharedFD &fdStats,\n \t\t const SharedFD &fdParams,\n-\t\t const ControlInfoMap &sensorInfoMap) override;\n+\t\t const ControlInfoMap &sensorInfoMap,\n+\t\t ControlInfoMap *ipaControls) override;\n \tint configure(const IPAConfigInfo &configInfo) override;\n \n \tint start() override;\n@@ -87,7 +88,8 @@ IPASoftSimple::~IPASoftSimple()\n int IPASoftSimple::init(const IPASettings &settings,\n \t\t\tconst SharedFD &fdStats,\n \t\t\tconst SharedFD &fdParams,\n-\t\t\tconst ControlInfoMap &sensorInfoMap)\n+\t\t\tconst ControlInfoMap &sensorInfoMap,\n+\t\t\tControlInfoMap *ipaControls)\n {\n \tcamHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel);\n \tif (!camHelper_) {\n@@ -158,6 +160,9 @@ int IPASoftSimple::init(const IPASettings &settings,\n \t\tstats_ = static_cast<SwIspStats *>(mem);\n \t}\n \n+\tControlInfoMap::Map ctrlMap = context_.ctrlMap;\n+\t*ipaControls = ControlInfoMap(std::move(ctrlMap), controls::controls);\n+\n \t/*\n \t * Check if the sensor driver supports the controls required by the\n \t * Soft IPA.\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 3ddce71d3..38868df66 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -530,7 +530,7 @@ int SimpleCameraData::init()\n \t * Instantiate Soft ISP if this is enabled for the given driver and no converter is used.\n \t */\n \tif (!converter_ && pipe->swIspEnabled()) {\n-\t\tswIsp_ = std::make_unique<SoftwareIsp>(pipe, sensor_.get());\n+\t\tswIsp_ = std::make_unique<SoftwareIsp>(pipe, sensor_.get(), &controlInfo_);\n \t\tif (!swIsp_->isValid()) {\n \t\t\tLOG(SimplePipeline, Warning)\n \t\t\t\t<< \"Failed to create software ISP, disabling software debayering\";\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 47677784d..3d3f956cb 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -13,6 +13,7 @@\n #include <sys/types.h>\n #include <unistd.h>\n \n+#include <libcamera/controls.h>\n #include <libcamera/formats.h>\n #include <libcamera/stream.h>\n \n@@ -60,9 +61,11 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n  * \\brief Constructs SoftwareIsp object\n  * \\param[in] pipe The pipeline handler in use\n  * \\param[in] sensor Pointer to the CameraSensor instance owned by the pipeline\n+ * \\param[out] ipaControls The IPA controls to update\n  * handler\n  */\n-SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)\n+SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,\n+\t\t\t ControlInfoMap *ipaControls)\n \t: dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n \t\t   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |\n \t\t   DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)\n@@ -124,7 +127,8 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)\n \tint ret = ipa_->init(IPASettings{ ipaTuningFile, sensor->model() },\n \t\t\t     debayer_->getStatsFD(),\n \t\t\t     sharedParams_.fd(),\n-\t\t\t     sensor->controls());\n+\t\t\t     sensor->controls(),\n+\t\t\t     ipaControls);\n \tif (ret) {\n \t\tLOG(SoftwareIsp, Error) << \"IPA init failed\";\n \t\tdebayer_.reset();\n","prefixes":["v2","2/2"]}