From patchwork Tue Aug 2 10:09:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16895 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B0319C3275 for ; Tue, 2 Aug 2022 10:10:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E04A6330F; Tue, 2 Aug 2022 12:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659435004; bh=oWAkIFHOz/8cIGh+i21SzJWnGgMMwxg2/GO4mdnw/Vw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rsw6aKPS78LYa/V+N6EZVJoN6bDCpINunDetFOlKJptG5IFd153kAHH+kMo58ihzw P7XYENM4leJW0Ol1QP+JV0UwlCLhIST729z5shEuyfQghAWukTqDCUf2hJ+cDkWTPP 8G+EV6hoYLFGpx7OvzOMIvG3hXO/YjAje8r8R6Xrfz9BiXwosAzCTxbMh6JD00jKHX GcwaTX4ex+wzD1Lr+XPQrYhZ2xPVHivfMbU+POliylt8iCcmpjQbCybc5oOjscOv0Y Ryl63T8ZOLTS7yvd+QPVTPSVd/0kwMORJlQYLOQLNkl6UqeG9R0GWtPJ1PkfsO9jzl gB4+5J7e1l5aQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 07989603E6 for ; Tue, 2 Aug 2022 12:10:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uhD3/mRU"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 86B0825B for ; Tue, 2 Aug 2022 12:10:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659435001; bh=oWAkIFHOz/8cIGh+i21SzJWnGgMMwxg2/GO4mdnw/Vw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uhD3/mRU8+WUobM2wvzde6v9E4SN+74bLiVzYXjC5hQUTxy+AWuRM4GXPgWHPuaGQ oWTGcGyDwA7RWuEU/o6M5TYweI+WFc3pj9u6nd3ISgnv2sD0R2eeFu7lOcT/WPx84k O/oxB7IEuTpfEJ7jlWhJRpO+j4D/GhLhSwmLgk9o= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Aug 2022 13:09:52 +0300 Message-Id: <20220802100955.1546-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> References: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/4] pipeline: ipu3: Support IPA tuning file X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Pass the path name of the YAML IPA tuning file to the IPA module. The file name is derived from the sensor name ("${sensor_name}.yaml"), with a fallback to "uncalibrated.yaml". The tuning file name can be manually overridden with the LIBCAMERA_IPU3_TUNING_FILE environment variable. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/ipu3/ipu3.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 4fe52f74a68c..5c4a0a567ff2 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1243,8 +1243,26 @@ int IPU3CameraData::loadIPA() if (ret) return ret; - ret = ipa_->init(IPASettings{ "", sensor->model() }, sensorInfo, - sensor->controls(), &ipaControls_); + /* + * The API tuning file is made from the sensor name unless the + * environment variable overrides it. If + */ + std::string ipaTuningFile; + char const *configFromEnv = utils::secure_getenv("LIBCAMERA_IPU3_TUNING_FILE"); + if (!configFromEnv || *configFromEnv == '\0') { + ipaTuningFile = ipa_->configurationFile(sensor->model() + ".yaml"); + /* + * If the tuning file isn't found, fall back to the + * 'uncalibrated' configuration file. + */ + if (ipaTuningFile.empty()) + ipaTuningFile = ipa_->configurationFile("uncalibrated.yaml"); + } else { + ipaTuningFile = std::string(configFromEnv); + } + + ret = ipa_->init(IPASettings{ ipaTuningFile, sensor->model() }, + sensorInfo, sensor->controls(), &ipaControls_); if (ret) { LOG(IPU3, Error) << "Failed to initialise the IPU3 IPA"; return ret; From patchwork Tue Aug 2 10:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16896 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 59B5CC3276 for ; Tue, 2 Aug 2022 10:10:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C8F8F6330E; Tue, 2 Aug 2022 12:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659435004; bh=XgW+dssQb08ibpoHekz9gP16rDbAXVdXxFtU8PcTg5I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OW7FvXzDzvEPwviFKfzs6LIaB+Avw88LfSGmpfTP4dXFdPf6elSHekyWpN8ywCuHA gNTk2bNWXKCLP6YcbedpQ6Wu8kbL/L7REzzjpM4Rie7Hq/6SU3n+wfjGFn2JGrvq0y zK3yCBFRMmRpAuBLkvMLXWB1Z8pqXsHyLmwCeKUhH1/loZptE1OuM4ekgRp52iRdod FU51Vp3yr9j5w+3nu8Y4Mhrfgkk8/qENEt1zPnHvg7aUJ+HL6QU89P+Ah0J4uk/kGv lfDtyLkL/tHFMKDQkdOA9TCKPviJcx7KX5oS9Tufobj0/40IQ03fqnrIIkuKC0nEC8 bAuF3QkqTUgag== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 08FA66330E for ; Tue, 2 Aug 2022 12:10:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JdYqz2rc"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A6F025B for ; Tue, 2 Aug 2022 12:10:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659435002; bh=XgW+dssQb08ibpoHekz9gP16rDbAXVdXxFtU8PcTg5I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JdYqz2rcHxuqG24dFtRt6KLCfEZk0OOQMfXFUxUtmVGO5sB0Y0rhCJCoI2JVXIpNH dQgZMl8FXPyTwGA1mU9O7Dz8F0sWpPzjc3Rf737fES1jRxFJl95M06H7vevkfdunAK VZ161EfhJlozGb1KiW25oXvf5nVV1UP8MWnVwHdw= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Aug 2022 13:09:53 +0300 Message-Id: <20220802100955.1546-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> References: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/4] ipa: ipu3: Add an uncalibrated.yaml tuning data file X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a tuning data file for uncalibrated sensors, picked by the pipeline handler when no sensor-specific tuning file is available. The file lists the 5 algorithms currently instantiated by the IPA module. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipu3/data/meson.build | 8 ++++++++ src/ipa/ipu3/data/uncalibrated.yaml | 11 +++++++++++ src/ipa/ipu3/meson.build | 1 + 3 files changed, 20 insertions(+) create mode 100644 src/ipa/ipu3/data/meson.build create mode 100644 src/ipa/ipu3/data/uncalibrated.yaml diff --git a/src/ipa/ipu3/data/meson.build b/src/ipa/ipu3/data/meson.build new file mode 100644 index 000000000000..1f50b6301f77 --- /dev/null +++ b/src/ipa/ipu3/data/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 + +conf_files = files([ + 'uncalibrated.yaml', +]) + +install_data(conf_files, + install_dir : ipa_data_dir / 'ipu3') diff --git a/src/ipa/ipu3/data/uncalibrated.yaml b/src/ipa/ipu3/data/uncalibrated.yaml new file mode 100644 index 000000000000..d98f4445d0a9 --- /dev/null +++ b/src/ipa/ipu3/data/uncalibrated.yaml @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: CC0-1.0 +%YAML 1.2 +--- +version: 1 +algorithms: + - Af: + - Agc: + - Awb: + - BlackLevelCorrection: + - ToneMapping: +... diff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build index 3194111a5bad..658e7c9bc366 100644 --- a/src/ipa/ipu3/meson.build +++ b/src/ipa/ipu3/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 subdir('algorithms') +subdir('data') ipa_name = 'ipa_ipu3' From patchwork Tue Aug 2 10:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16897 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 12DECC3275 for ; Tue, 2 Aug 2022 10:10:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 36D8263315; Tue, 2 Aug 2022 12:10:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659435005; bh=AmB1e30hGxPfzVY3M6vh363cczc+bdNJ2fvani0M8Y4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tBGrgrnrDuO2IofvgK+UA1s587Hm6TYr4a7e+OVupRmbCMl9chhcmnqPRHg7lABDp JF+SU+1QAFed7m8NWDsZIUchw/r4Vz5/wrGnQvrU5bT/P+1V4Nxo40mLJkDUdEs/n/ 9rYpiLt0Rsne7IINk/jzJKbCaQMLRMJXsTWMdp++6iT4Vn7ORVDa4su3qto4lVh9VW o3KaMsbWRIVO0vpybGayGscTDPpchRgr27vtwoalYA0Yx2lsMDikK/HW3MkQvApbZg G+KQP1qi7gAq3YN8umErjqMpEA0/ZnVmuVorW5dCdlYG66TG2cLYN2k/7rm4Zh428k U2azBmxkqdeWA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FED2603E6 for ; Tue, 2 Aug 2022 12:10:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I9lPqiVx"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CDC1C25B for ; Tue, 2 Aug 2022 12:10:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659435004; bh=AmB1e30hGxPfzVY3M6vh363cczc+bdNJ2fvani0M8Y4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=I9lPqiVx+WjcbKd07sH6k+/8hvJ3zI0O5ihFhBS476GU1At51yzIEDmxONIG0PCPO 1aRqe+gV/ApTlF/m6jPPegOoPVBJtWKls2yI0XAKzAgkelq3A2XJpzZ7t5YphZhi10 UEOmk+W3VL288hNpMUL1P0I22qh0Ut/CQWJYPHsY= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Aug 2022 13:09:54 +0300 Message-Id: <20220802100955.1546-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> References: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 3/4] ipa: ipu3: Register algorithms X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for dynamic instantiation of algorithms from the tuning file, register the algorithms with the Module class. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/af.cpp | 2 ++ src/ipa/ipu3/algorithms/agc.cpp | 2 ++ src/ipa/ipu3/algorithms/awb.cpp | 2 ++ src/ipa/ipu3/algorithms/blc.cpp | 2 ++ src/ipa/ipu3/algorithms/tone_mapping.cpp | 2 ++ 5 files changed, 10 insertions(+) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index d07521a090ac..4835a0345931 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -450,6 +450,8 @@ void Af::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameCon } } +REGISTER_IPA_ALGORITHM(Af, "Af") + } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 5bc64ae52214..ed4809d98007 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -363,6 +363,8 @@ void Agc::process(IPAContext &context, [[maybe_unused]] IPAFrameContext *frameCo frameCount_++; } +REGISTER_IPA_ALGORITHM(Agc, "Agc") + } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index 704267222a31..b658ee546b87 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -483,6 +483,8 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) params->use.acc_ccm = 1; } +REGISTER_IPA_ALGORITHM(Awb, "Awb") + } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/ipu3/algorithms/blc.cpp b/src/ipa/ipu3/algorithms/blc.cpp index 78ab7bff549f..c561aa858b96 100644 --- a/src/ipa/ipu3/algorithms/blc.cpp +++ b/src/ipa/ipu3/algorithms/blc.cpp @@ -62,6 +62,8 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, params->use.obgrid_param = 1; } +REGISTER_IPA_ALGORITHM(BlackLevelCorrection, "BlackLevelCorrection") + } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */ diff --git a/src/ipa/ipu3/algorithms/tone_mapping.cpp b/src/ipa/ipu3/algorithms/tone_mapping.cpp index f86e79b24a67..49a5558b6faa 100644 --- a/src/ipa/ipu3/algorithms/tone_mapping.cpp +++ b/src/ipa/ipu3/algorithms/tone_mapping.cpp @@ -105,6 +105,8 @@ void ToneMapping::process(IPAContext &context, [[maybe_unused]] IPAFrameContext context.activeState.toneMapping.gamma = gamma_; } +REGISTER_IPA_ALGORITHM(ToneMapping, "ToneMapping") + } /* namespace ipa::ipu3::algorithms */ } /* namespace libcamera */ From patchwork Tue Aug 2 10:09:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16898 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0099DC3275 for ; Tue, 2 Aug 2022 10:10:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD8BF63316; Tue, 2 Aug 2022 12:10:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659435007; bh=OWPsTPLMftQoLOkE/haPFu6iSNWIM5Ejt0Oi70izDRc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KE4sLItaYHJia+c/HEC8amHQ6IRHG6BD7YKBCTVHT3zIye58DVl+nUgTT4MhXHf8+ OcvBfn9KghSbalUOP5bFXMgcC/QltuM1TzRdKGVORWbFbZOAiiPkh2Koql5cH0pyDF iJJ7gL7tbBCNqn3ysByjkxhwOKsNUNW+96luYHf5zwO+HXxAphWxWKY5I21VmLQsJk n2pra33fJzuDd66JvA4J0jiNIdi1bXm841uPHaUTG0IIi5FqGZ7AdW6AVpqegRUd1m qX6fWY15P4aw89zU6ZpU0NsghloV0MAIabnZbjLLLUgCDYgrKK2TZfEQZmlh1rOzas YSIaUzl+0skeg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 57EBA63319 for ; Tue, 2 Aug 2022 12:10:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gmoSfx+q"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 04FFA593 for ; Tue, 2 Aug 2022 12:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659435005; bh=OWPsTPLMftQoLOkE/haPFu6iSNWIM5Ejt0Oi70izDRc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gmoSfx+q39GuIvOKKPH1FQdZrhY7WH9btSYsksXrgbFb7B5IaueWvXsvnCG6Zndne eA4VirFGecjCC47QH4nRPAVVqZV2HlyAxDiwDSSchjzxU7BVTrrJb7JIdNrWTNWZsK 8/DwBDFVm2dCWZxVVFZbwLkg26nTBdXDA0Z9FC3Q= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Aug 2022 13:09:55 +0300 Message-Id: <20220802100955.1546-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> References: <20220802100955.1546-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 4/4] ipa: ipu3: Add YAML tuning file support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the manual instantiation of algorithms with an automatic mechanism based on a tuning data file, provided by the Module base class. This brings the IPU3 IPA module in line with the RkISP1 IPA module. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/ipu3/ipu3.cpp | 70 ++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 2f6bb672f7bb..e37b2fa0f30e 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -29,6 +30,7 @@ #include #include "libcamera/internal/mapped_framebuffer.h" +#include "libcamera/internal/yaml_parser.h" #include "algorithms/af.h" #include "algorithms/agc.h" @@ -71,7 +73,7 @@ namespace ipa::ipu3 { * * At initialisation time, a CameraSensorHelper is instantiated to support * camera-specific calculations, while the default controls are computed, and - * the algorithms are constructed and placed in an ordered list. + * the algorithms are instantiated from the tuning data file. * * The IPU3 ImgU operates with a grid layout to divide the overall frame into * rectangular cells of pixels. When the IPA is configured, we determine the @@ -92,12 +94,14 @@ namespace ipa::ipu3 { * fillParamsBuffer() call. * * The individual algorithms are split into modular components that are called - * iteratively to allow them to process statistics from the ImgU in a defined - * order. + * iteratively to allow them to process statistics from the ImgU in the order + * defined in the tuning data file. * - * The current implementation supports three core algorithms: - * - Automatic white balance (AWB) + * The current implementation supports five core algorithms: + * + * - Auto focus (AF) * - Automatic gain and exposure control (AGC) + * - Automatic white balance (AWB) * - Black level correction (BLC) * - Tone mapping (Gamma) * @@ -128,7 +132,7 @@ namespace ipa::ipu3 { * sensor-specific tuning to adapt for Black Level compensation (BLC), Lens * shading correction (SHD) and Color correction (CCM). */ -class IPAIPU3 : public IPAIPU3Interface +class IPAIPU3 : public IPAIPU3Interface, public Module { public: int init(const IPASettings &settings, @@ -150,6 +154,10 @@ public: void processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, const uint32_t bufferId, const ControlList &sensorControls) override; + +protected: + std::string logPrefix() const override; + private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, @@ -171,13 +179,15 @@ private: /* Interface to the Camera Helper */ std::unique_ptr camHelper_; - /* Maintain the algorithms used by the IPA */ - std::list> algorithms_; - /* Local parameter storage */ struct IPAContext context_; }; +std::string IPAIPU3::logPrefix() const +{ + return "ipu3"; +} + /** * \brief Compute IPASessionConfiguration using the sensor information and the * sensor V4L2 controls @@ -316,12 +326,36 @@ int IPAIPU3::init(const IPASettings &settings, context_.configuration = {}; context_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate; - /* Construct our Algorithms */ - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); - algorithms_.push_back(std::make_unique()); + /* Load the tuning data file. */ + File file(settings.configurationFile.c_str()); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + int ret = file.error(); + LOG(IPAIPU3, Error) + << "Failed to open configuration file " + << settings.configurationFile << ": " << strerror(-ret); + return ret; + } + + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + unsigned int version = (*data)["version"].get(0); + if (version != 1) { + LOG(IPAIPU3, Error) + << "Invalid tuning file version " << version; + return -EINVAL; + } + + if (!data->contains("algorithms")) { + LOG(IPAIPU3, Error) + << "Tuning file doesn't contain any algorithm"; + return -EINVAL; + } + + int ret = createAlgorithms(context_, (*data)["algorithms"]); + if (ret) + return ret; /* Initialize controls. */ updateControls(sensorInfo, sensorControls, ipaControls); @@ -470,7 +504,7 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, /* Update the IPASessionConfiguration using the sensor settings. */ updateSessionConfiguration(sensorCtrls_); - for (auto const &algo : algorithms_) { + for (auto const &algo : algorithms()) { int ret = algo->configure(context_, configInfo); if (ret) return ret; @@ -538,7 +572,7 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) */ params->use = {}; - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->prepare(context_, params); paramsBufferReady.emit(frame); @@ -581,7 +615,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, int32_t vBlank = context_.configuration.sensor.defVBlank; ControlList ctrls(controls::controls); - for (auto const &algo : algorithms_) + for (auto const &algo : algorithms()) algo->process(context_, &frameContext, stats); setControls(frame);