From patchwork Thu Dec 5 16:34:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22183 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 686E4C323E for ; Thu, 5 Dec 2024 16:37:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A26CA6608C; Thu, 5 Dec 2024 17:37:22 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="g9xFj6m8"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A76926608C for ; Thu, 5 Dec 2024 17:37:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733416640; x=1733675840; bh=HhTjhbMk2safotm4T9XMUDnMbUuHywURi1D29AvbZ6s=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=g9xFj6m8rRKKoUsxcFXqg7fTOhkOKP3xAR8nqkaD5VyauH5L5+Owq2ONy6yIN0MwR ByoVDGDKhByjOutU/5E+MpxKK/kNh3eTv3+hwn+SqrWbVEKyP7wZHyvVb4m7VtgJuU 5RS5fzPGOrB/zoHIYkV1trquMKhN1/J5tUPkhhA3Y85gaV0c2uHi+N2O09VvVFmJ3E MpssldJcaypGttEYOmO4wTQdRrnMp1+TYxms2D+ZALQY98fZ8HHKDkD9eBvUrWs28g 2xCG+GeXZP3/xulFZ0HPGSxf+kadA0bni4TPaP6KZ97lfqIjZjjWqwQzxRYJHy1605 5KFtlhGrAavTw== Date: Thu, 05 Dec 2024 16:34:14 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 1/3] libcamera: yaml_parser: Add `YamlObject::find(key)` Message-ID: <20241205163411.1160094-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: bd17c12cf3c838d95659c315085fb7c008f3bb89 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This function is meant to replace `YamlObject::contains()` as it can be easily used for the same purpose, i.e. determining if a certain key exists in a dictionary, but it has the advantage that the result, if any, is immediately available for use without having to do a second lookup. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 1 + src/libcamera/yaml_parser.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 8c791656..796e3e90 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -209,6 +209,7 @@ public: bool contains(std::string_view key) const; const YamlObject &operator[](std::string_view key) const; + const YamlObject *find(std::string_view key) const; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index db256ec5..da8cb61f 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -397,6 +397,29 @@ const YamlObject &YamlObject::operator[](std::string_view key) const return *iter->second; } +/** + * \fn YamlObject::find(std::string_view key) const + * \brief Retrieve a member by name from the dictionary + * + * This function retrieves a member of a YamlObject by name. Only YamlObject + * instances of Dictionary type associate elements with names, calling this + * function on other types of instances or with a nonexistent key results in + * \a nullptr being returned. + * + * \return The YamlObject corresponding to the \a key member + */ +const YamlObject *YamlObject::find(std::string_view key) const +{ + if (type_ != Type::Dictionary) + return nullptr; + + auto iter = dictionary_.find(key); + if (iter == dictionary_.end()) + return nullptr; + + return iter->second; +} + #ifndef __DOXYGEN__ class YamlParserContext From patchwork Thu Dec 5 16:34:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22185 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 A20A7C323E for ; Thu, 5 Dec 2024 16:37:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DD0C66110; Thu, 5 Dec 2024 17:37:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="vy4QpQ2+"; dkim-atps=neutral Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C6F166109 for ; Thu, 5 Dec 2024 17:37:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733416669; x=1733675869; bh=k41wX0pTfTUz24Gge5OtHTMRJHSakj/sYzQQhfk2IAs=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=vy4QpQ2+rAoqF8wL2H05bgWFX2muq/8E2V3gfGgpPgHtTA9kXZvpbasQ0isQ1lkKs 13PfHU5YoqTmnoSSFGlEd3Z66UrF8ZRBMtaevQC/aBwBZ7rUmeX7rcWKzUw3ucyJXF iJka772NLKhaEhgUWY4vKapVUf+WsNYPoXzRvq05lE4+e9Ak25Hd2VeuExadDhv1OW 8qGoz+95plYZ2Ya5PVGdvViyhltH6uKuZ94LQNK/jybZgmBfjAb0A7PiktWcqdYMZv EcbLoAb3pfNw546JoLSzB16FpRNVApkOaK9t0+JlcnmEu9KHNYTw2Ad5XFPelE4iG/ cRhnN8Jv8LmsA== Date: Thu, 05 Dec 2024 16:34:19 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 2/3] treewide: Use `YamlObject::find()` Message-ID: <20241205163411.1160094-2-pobrn@protonmail.com> In-Reply-To: <20241205163411.1160094-1-pobrn@protonmail.com> References: <20241205163411.1160094-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 2257a0d355a1be23ed45d4d0179ecd3ff5dd8f7a MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace some uses of `contains()` + `operator[]` with `find()`. Using `find()` avoids the double lookup, as well as does away with the need for specifying the key twice. Signed-off-by: Barnabás Pőcze --- src/android/camera_hal_config.cpp | 19 ++++---- src/ipa/ipu3/ipu3.cpp | 5 +- src/ipa/rkisp1/algorithms/dpcc.cpp | 56 +++++++++++----------- src/ipa/rkisp1/rkisp1.cpp | 5 +- src/ipa/rpi/controller/controller.cpp | 5 +- src/ipa/rpi/controller/rpi/af.cpp | 32 ++++++------- src/ipa/rpi/controller/rpi/agc.cpp | 8 ++-- src/ipa/rpi/controller/rpi/agc_channel.cpp | 4 +- src/ipa/rpi/controller/rpi/alsc.cpp | 10 ++-- src/ipa/rpi/controller/rpi/awb.cpp | 12 ++--- src/ipa/rpi/controller/rpi/ccm.cpp | 4 +- src/ipa/rpi/controller/rpi/geq.cpp | 4 +- src/ipa/rpi/controller/rpi/hdr.cpp | 27 ++++++----- src/ipa/simple/soft_simple.cpp | 5 +- 14 files changed, 99 insertions(+), 97 deletions(-) diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp index 7ef451ef..6fde953d 100644 --- a/src/android/camera_hal_config.cpp +++ b/src/android/camera_hal_config.cpp @@ -73,15 +73,14 @@ int CameraHalConfig::Private::parseConfigFile(File &file, return -EINVAL; /* Parse property "cameras" */ - if (!root->contains("cameras")) + auto *yamlObjectCameras = root->find("cameras"); + if (!yamlObjectCameras) return -EINVAL; - const YamlObject &yamlObjectCameras = (*root)["cameras"]; - - if (!yamlObjectCameras.isDictionary()) + if (!yamlObjectCameras->isDictionary()) return -EINVAL; - for (const auto &[cameraId, configData] : yamlObjectCameras.asDict()) { + for (const auto &[cameraId, configData] : yamlObjectCameras->asDict()) { if (parseCameraConfigData(cameraId, configData)) return -EINVAL; } @@ -112,10 +111,11 @@ int CameraHalConfig::Private::parseCameraConfigData(const std::string &cameraId, int CameraHalConfig::Private::parseLocation(const YamlObject &cameraObject, CameraConfigData &cameraConfigData) { - if (!cameraObject.contains("location")) + auto *loc = cameraObject.find("location"); + if (!loc) return -EINVAL; - std::string location = cameraObject["location"].get(""); + std::string location = loc->get(""); if (location == "front") cameraConfigData.facing = CAMERA_FACING_FRONT; @@ -130,10 +130,11 @@ int CameraHalConfig::Private::parseLocation(const YamlObject &cameraObject, int CameraHalConfig::Private::parseRotation(const YamlObject &cameraObject, CameraConfigData &cameraConfigData) { - if (!cameraObject.contains("rotation")) + auto *rot = cameraObject.find("rotation"); + if (!rot) return -EINVAL; - int32_t rotation = cameraObject["rotation"].get(-1); + int32_t rotation = rot->get(-1); if (rotation < 0 || rotation >= 360) { LOG(HALConfig, Error) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 44c98cbf..88b1bb81 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -335,13 +335,14 @@ int IPAIPU3::init(const IPASettings &settings, return -EINVAL; } - if (!data->contains("algorithms")) { + auto *algos = data->find("algorithms"); + if (!algos) { LOG(IPAIPU3, Error) << "Tuning file doesn't contain any algorithm"; return -EINVAL; } - int ret = createAlgorithms(context_, (*data)["algorithms"]); + int ret = createAlgorithms(context_, *algos); if (ret) return ret; diff --git a/src/ipa/rkisp1/algorithms/dpcc.cpp b/src/ipa/rkisp1/algorithms/dpcc.cpp index 78946281..8946c1a7 100644 --- a/src/ipa/rkisp1/algorithms/dpcc.cpp +++ b/src/ipa/rkisp1/algorithms/dpcc.cpp @@ -80,39 +80,39 @@ int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, /* PG Method */ const YamlObject &pgObject = set["pg-factor"]; - if (pgObject.contains("green")) { + if (auto *green = pgObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE; - value = pgObject["green"].get(0); + value = green->get(0); method.pg_fac |= RKISP1_CIF_ISP_DPCC_PG_FAC_G(value); } - if (pgObject.contains("red-blue")) { + if (auto *redBlue = pgObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE; - value = pgObject["red-blue"].get(0); + value = redBlue->get(0); method.pg_fac |= RKISP1_CIF_ISP_DPCC_PG_FAC_RB(value); } /* RO Method */ const YamlObject &roObject = set["ro-limits"]; - if (roObject.contains("green")) { + if (auto *green = roObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE; - value = roObject["green"].get(0); + value = green->get(0); config_.ro_limits |= RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(i, value); } - if (roObject.contains("red-blue")) { + if (auto *redBlue = roObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE; - value = roObject["red-blue"].get(0); + value = redBlue->get(0); config_.ro_limits |= RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(i, value); } @@ -121,39 +121,39 @@ int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &rgObject = set["rg-factor"]; method.rg_fac = 0; - if (rgObject.contains("green")) { + if (auto *green = rgObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE; - value = rgObject["green"].get(0); + value = green->get(0); method.rg_fac |= RKISP1_CIF_ISP_DPCC_RG_FAC_G(value); } - if (rgObject.contains("red-blue")) { + if (auto *redBlue = rgObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE; - value = rgObject["red-blue"].get(0); + value = redBlue->get(0); method.rg_fac |= RKISP1_CIF_ISP_DPCC_RG_FAC_RB(value); } /* RND Method */ const YamlObject &rndOffsetsObject = set["rnd-offsets"]; - if (rndOffsetsObject.contains("green")) { + if (auto *green = rndOffsetsObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; - value = rndOffsetsObject["green"].get(0); + value = green->get(0); config_.rnd_offs |= RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(i, value); } - if (rndOffsetsObject.contains("red-blue")) { + if (auto *redBlue = rndOffsetsObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; - value = rndOffsetsObject["red-blue"].get(0); + value = redBlue->get(0); config_.rnd_offs |= RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(i, value); } @@ -161,20 +161,20 @@ int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &rndThresholdObject = set["rnd-threshold"]; method.rnd_thresh = 0; - if (rndThresholdObject.contains("green")) { + if (auto *green = rndThresholdObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE; - value = rndThresholdObject["green"].get(0); + value = green->get(0); method.rnd_thresh |= RKISP1_CIF_ISP_DPCC_RND_THRESH_G(value); } - if (rndThresholdObject.contains("red-blue")) { + if (auto *redBlue = rndThresholdObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE; - value = rndThresholdObject["red-blue"].get(0); + value = redBlue->get(0); method.rnd_thresh |= RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(value); } @@ -183,20 +183,20 @@ int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &lcThresholdObject = set["line-threshold"]; method.line_thresh = 0; - if (lcThresholdObject.contains("green")) { + if (auto *green = lcThresholdObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; - value = lcThresholdObject["green"].get(0); + value = green->get(0); method.line_thresh |= RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(value); } - if (lcThresholdObject.contains("red-blue")) { + if (auto *redBlue = lcThresholdObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; - value = lcThresholdObject["red-blue"].get(0); + value = redBlue->get(0); method.line_thresh |= RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(value); } @@ -204,20 +204,20 @@ int DefectPixelClusterCorrection::init([[maybe_unused]] IPAContext &context, const YamlObject &lcTMadFactorObject = set["line-mad-factor"]; method.line_mad_fac = 0; - if (lcTMadFactorObject.contains("green")) { + if (auto *green = lcTMadFactorObject.find("green")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE; - value = lcTMadFactorObject["green"].get(0); + value = green->get(0); method.line_mad_fac |= RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(value); } - if (lcTMadFactorObject.contains("red-blue")) { + if (auto *redBlue = lcTMadFactorObject.find("red-blue")) { method.method |= RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE; - value = lcTMadFactorObject["red-blue"].get(0); + value = redBlue->get(0); method.line_mad_fac |= RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(value); } diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 2ffdd99b..202b53b7 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -193,13 +193,14 @@ int IPARkISP1::init(const IPASettings &settings, unsigned int hwRevision, return -EINVAL; } - if (!data->contains("algorithms")) { + auto *algos = data->find("algorithms"); + if (!algos) { LOG(IPARkISP1, Error) << "Tuning file doesn't contain any algorithm"; return -EINVAL; } - int ret = createAlgorithms(context_, (*data)["algorithms"]); + int ret = createAlgorithms(context_, *algos); if (ret) return ret; diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index e0131018..fbf31f23 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -109,14 +109,15 @@ int Controller::read(char const *filename) return ret; } } else if (version < 3.0) { - if (!root->contains("algorithms")) { + auto *algos = root->find("algorithms"); + if (!algos) { LOG(RPiController, Error) << "Tuning file " << filename << " does not have an \"algorithms\" list!"; return -EINVAL; } - for (auto const &rootAlgo : (*root)["algorithms"].asList()) + for (auto const &rootAlgo : algos->asList()) for (auto const &[key, value] : rootAlgo.asDict()) { int ret = createAlgorithm(key, value); if (ret) diff --git a/src/ipa/rpi/controller/rpi/af.cpp b/src/ipa/rpi/controller/rpi/af.cpp index 2157eb94..c29bbaeb 100644 --- a/src/ipa/rpi/controller/rpi/af.cpp +++ b/src/ipa/rpi/controller/rpi/af.cpp @@ -97,39 +97,35 @@ void Af::SpeedDependentParams::read(const libcamera::YamlObject ¶ms) int Af::CfgParams::read(const libcamera::YamlObject ¶ms) { - if (params.contains("ranges")) { - auto &rr = params["ranges"]; - - if (rr.contains("normal")) - ranges[AfRangeNormal].read(rr["normal"]); + if (auto *rs = params.find("ranges")) { + if (auto *normal = rs->find("normal")) + ranges[AfRangeNormal].read(*normal); else LOG(RPiAf, Warning) << "Missing range \"normal\""; ranges[AfRangeMacro] = ranges[AfRangeNormal]; - if (rr.contains("macro")) - ranges[AfRangeMacro].read(rr["macro"]); + if (auto *macro = rs->find("macro")) + ranges[AfRangeMacro].read(*macro); ranges[AfRangeFull].focusMin = std::min(ranges[AfRangeNormal].focusMin, ranges[AfRangeMacro].focusMin); ranges[AfRangeFull].focusMax = std::max(ranges[AfRangeNormal].focusMax, ranges[AfRangeMacro].focusMax); ranges[AfRangeFull].focusDefault = ranges[AfRangeNormal].focusDefault; - if (rr.contains("full")) - ranges[AfRangeFull].read(rr["full"]); + if (auto *full = rs->find("full")) + ranges[AfRangeFull].read(*full); } else LOG(RPiAf, Warning) << "No ranges defined"; - if (params.contains("speeds")) { - auto &ss = params["speeds"]; - - if (ss.contains("normal")) - speeds[AfSpeedNormal].read(ss["normal"]); + if (auto *ss = params.find("speeds")) { + if (auto *normal = ss->find("normal")) + speeds[AfSpeedNormal].read(*normal); else LOG(RPiAf, Warning) << "Missing speed \"normal\""; speeds[AfSpeedFast] = speeds[AfSpeedNormal]; - if (ss.contains("fast")) - speeds[AfSpeedFast].read(ss["fast"]); + if (auto *fast = ss->find("fast")) + speeds[AfSpeedFast].read(*fast); } else LOG(RPiAf, Warning) << "No speeds defined"; @@ -138,8 +134,8 @@ int Af::CfgParams::read(const libcamera::YamlObject ¶ms) readNumber(confClip, params, "conf_clip"); readNumber(skipFrames, params, "skip_frames"); - if (params.contains("map")) - map = params["map"].get(ipa::Pwl{}); + if (auto *m = params.find("map")) + map = m->get(ipa::Pwl{}); else LOG(RPiAf, Warning) << "No map defined"; diff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp index c48fdf15..5d924ebf 100644 --- a/src/ipa/rpi/controller/rpi/agc.cpp +++ b/src/ipa/rpi/controller/rpi/agc.cpp @@ -37,18 +37,18 @@ int Agc::read(const libcamera::YamlObject ¶ms) * When there is only a single channel we can read the old style syntax. * Otherwise we expect a "channels" keyword followed by a list of configurations. */ - if (!params.contains("channels")) { + auto *channels = params.find("channels"); + if (!channels) { LOG(RPiAgc, Debug) << "Single channel only"; channelTotalExposures_.resize(1, 0s); channelData_.emplace_back(); return channelData_.back().channel.read(params, getHardwareConfig()); } - const auto &channels = params["channels"].asList(); - for (auto ch = channels.begin(); ch != channels.end(); ch++) { + for (const auto &ch : channels->asList()) { LOG(RPiAgc, Debug) << "Read AGC channel"; channelData_.emplace_back(); - int ret = channelData_.back().channel.read(*ch, getHardwareConfig()); + int ret = channelData_.back().channel.read(ch, getHardwareConfig()); if (ret) return ret; } diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp index 79c45973..50b9efd2 100644 --- a/src/ipa/rpi/controller/rpi/agc_channel.cpp +++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp @@ -235,8 +235,8 @@ int AgcConfig::read(const libcamera::YamlObject ¶ms) if (ret) return ret; - if (params.contains("channel_constraints")) { - ret = readChannelConstraints(channelConstraints, params["channel_constraints"]); + if (auto *cc = params.find("channel_constraints")) { + ret = readChannelConstraints(channelConstraints, *cc); if (ret) return ret; } diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp index 21edb819..5a1a702b 100644 --- a/src/ipa/rpi/controller/rpi/alsc.cpp +++ b/src/ipa/rpi/controller/rpi/alsc.cpp @@ -104,9 +104,9 @@ static int readCalibrations(std::vector &calibrations, const libcamera::YamlObject ¶ms, std::string const &name, const Size &size) { - if (params.contains(name)) { + if (auto *param = params.find(name)) { double lastCt = 0; - for (const auto &p : params[name].asList()) { + for (const auto &p : param->asList()) { auto value = p["ct"].get(); if (!value) return -EINVAL; @@ -163,10 +163,10 @@ int Alsc::read(const libcamera::YamlObject ¶ms) config_.luminanceLut.resize(config_.tableSize, 1.0); int ret = 0; - if (params.contains("corner_strength")) + if (params.find("corner_strength")) ret = generateLut(config_.luminanceLut, params); - else if (params.contains("luminance_lut")) - ret = readLut(config_.luminanceLut, params["luminance_lut"]); + else if (auto *ll = params.find("luminance_lut")) + ret = readLut(config_.luminanceLut, *ll); else LOG(RPiAlsc, Warning) << "no luminance table - assume unity everywhere"; diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp index c277a176..2e6e295c 100644 --- a/src/ipa/rpi/controller/rpi/awb.cpp +++ b/src/ipa/rpi/controller/rpi/awb.cpp @@ -102,8 +102,8 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) convergenceFrames = params["convergence_frames"].get(3); speed = params["speed"].get(0.05); - if (params.contains("ct_curve")) { - ret = readCtCurve(ctR, ctB, params["ct_curve"]); + if (auto *ct_curve = params.find("ct_curve")) { + ret = readCtCurve(ctR, ctB, *ct_curve); if (ret) return ret; /* We will want the inverse functions of these too. */ @@ -111,8 +111,8 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) ctBInverse = ctB.inverse().first; } - if (params.contains("priors")) { - for (const auto &p : params["priors"].asList()) { + if (auto *ps = params.find("priors")) { + for (const auto &p : ps->asList()) { AwbPrior prior; ret = prior.read(p); if (ret) @@ -128,8 +128,8 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms) return -EINVAL; } } - if (params.contains("modes")) { - for (const auto &[key, value] : params["modes"].asDict()) { + if (auto *ms = params.find("modes")) { + for (const auto &[key, value] : ms->asDict()) { ret = modes[key].read(value); if (ret) return ret; diff --git a/src/ipa/rpi/controller/rpi/ccm.cpp b/src/ipa/rpi/controller/rpi/ccm.cpp index 8607f152..5616e5f4 100644 --- a/src/ipa/rpi/controller/rpi/ccm.cpp +++ b/src/ipa/rpi/controller/rpi/ccm.cpp @@ -41,8 +41,8 @@ char const *Ccm::name() const int Ccm::read(const libcamera::YamlObject ¶ms) { - if (params.contains("saturation")) { - config_.saturation = params["saturation"].get(ipa::Pwl{}); + if (auto *s = params.find("saturation")) { + config_.saturation = s->get(ipa::Pwl{}); if (config_.saturation.empty()) return -EINVAL; } diff --git a/src/ipa/rpi/controller/rpi/geq.cpp b/src/ipa/rpi/controller/rpi/geq.cpp index 40e7191b..6935f726 100644 --- a/src/ipa/rpi/controller/rpi/geq.cpp +++ b/src/ipa/rpi/controller/rpi/geq.cpp @@ -43,8 +43,8 @@ int Geq::read(const libcamera::YamlObject ¶ms) return -EINVAL; } - if (params.contains("strength")) { - config_.strength = params["strength"].get(ipa::Pwl{}); + if (auto *strength = params.find("strength")) { + config_.strength = strength->get(ipa::Pwl{}); if (config_.strength.empty()) return -EINVAL; } diff --git a/src/ipa/rpi/controller/rpi/hdr.cpp b/src/ipa/rpi/controller/rpi/hdr.cpp index f3da8291..20b1ff4b 100644 --- a/src/ipa/rpi/controller/rpi/hdr.cpp +++ b/src/ipa/rpi/controller/rpi/hdr.cpp @@ -27,9 +27,10 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod { name = modeName; - if (!params.contains("cadence")) + auto *c = params.find("cadence"); + if (!c) LOG(RPiHdr, Fatal) << "No cadence for HDR mode " << name; - cadence = params["cadence"].getList().value(); + cadence = c->getList().value(); if (cadence.empty()) LOG(RPiHdr, Fatal) << "Empty cadence in HDR mode " << name; @@ -41,10 +42,10 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod channelMap[v.get().value()] = k; /* Lens shading related parameters. */ - if (params.contains("spatial_gain_curve")) { - spatialGainCurve = params["spatial_gain_curve"].get(ipa::Pwl{}); - } else if (params.contains("spatial_gain")) { - double spatialGain = params["spatial_gain"].get(2.0); + if (auto *sgc = params.find("spatial_gain_curve")) { + spatialGainCurve = sgc->get(ipa::Pwl{}); + } else if (auto *sg = params.find("spatial_gain")) { + double spatialGain = sg->get(2.0); spatialGainCurve.append(0.0, spatialGain); spatialGainCurve.append(0.01, spatialGain); spatialGainCurve.append(0.06, 1.0); /* maybe make this programmable? */ @@ -68,24 +69,24 @@ void HdrConfig::read(const libcamera::YamlObject ¶ms, const std::string &mod if (tonemapEnable) tonemap = params["tonemap"].get(ipa::Pwl{}); speed = params["speed"].get(1.0); - if (params.contains("hi_quantile_targets")) { - hiQuantileTargets = params["hi_quantile_targets"].getList().value(); + if (auto *hqt = params.find("hi_quantile_targets")) { + hiQuantileTargets = hqt->getList().value(); if (hiQuantileTargets.empty() || hiQuantileTargets.size() % 2) LOG(RPiHdr, Fatal) << "hi_quantile_targets much be even and non-empty"; } else hiQuantileTargets = { 0.95, 0.65, 0.5, 0.28, 0.3, 0.25 }; hiQuantileMaxGain = params["hi_quantile_max_gain"].get(1.6); - if (params.contains("quantile_targets")) { - quantileTargets = params["quantile_targets"].getList().value(); + if (auto *qt = params.find("quantile_targets")) { + quantileTargets = qt->getList().value(); if (quantileTargets.empty() || quantileTargets.size() % 2) LOG(RPiHdr, Fatal) << "quantile_targets much be even and non-empty"; } else quantileTargets = { 0.2, 0.03, 1.0, 0.15 }; powerMin = params["power_min"].get(0.65); powerMax = params["power_max"].get(1.0); - if (params.contains("contrast_adjustments")) { - contrastAdjustments = params["contrast_adjustments"].getList().value(); - } else + if (auto *ca = params.find("contrast_adjustments")) + contrastAdjustments = ca->getList().value(); + else contrastAdjustments = { 0.5, 0.75 }; /* Read any stitch parameters. */ diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp index e1b6d3af..ca3fe487 100644 --- a/src/ipa/simple/soft_simple.cpp +++ b/src/ipa/simple/soft_simple.cpp @@ -114,12 +114,13 @@ int IPASoftSimple::init(const IPASettings &settings, unsigned int version = (*data)["version"].get(0); LOG(IPASoft, Debug) << "Tuning file version " << version; - if (!data->contains("algorithms")) { + auto *algos = data->find("algorithms"); + if (!algos) { LOG(IPASoft, Error) << "Tuning file doesn't contain algorithms"; return -EINVAL; } - int ret = createAlgorithms(context_, (*data)["algorithms"]); + int ret = createAlgorithms(context_, *algos); if (ret) return ret; From patchwork Thu Dec 5 16:34:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22184 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 9B14DC323E for ; Thu, 5 Dec 2024 16:37:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CD946610A; Thu, 5 Dec 2024 17:37:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="nCvEtIcB"; dkim-atps=neutral Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D50E06608C for ; Thu, 5 Dec 2024 17:37:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733416641; x=1733675841; bh=t1h0h9GL4LKAg+YNzPdrr7QgYlXuCZ9t8j1zqNfJIuQ=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=nCvEtIcBJDxsM0XDLgQeXaZwYcWsXQ8WqSC2ydyaIOY3xa6cttenVe488qcE78cPg HAlKxQ6DTBzyDbVxjk7FXxo+ZIgfQomu3nHc4rcyfpCXazWlziaV7UoDodTIK1Fdbv tIQwMeBna5XEzd0ExdwERtKN6YEiqdRuUGrwTITOq6q1gI2IbPGGzX4JTX0oY5vI81 /0G+IZ7nFc3C1omggHa/P4NjQAKVK0M2EB1xQvk1SoENV7Y3u4gQHtEqvz2cZbCEaS 9dGoxD29ttAcyko+IIvbUwMiQ3cdZU2l8TNkw/en/h2XTkjwwWWdg2Cvkgsx2AwcoO Q96MK1Es4s7vA== Date: Thu, 05 Dec 2024 16:34:24 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 3/3] libcamera: yaml_parser: Use `YamlObject::find()` in contains/operator[] Message-ID: <20241205163411.1160094-3-pobrn@protonmail.com> In-Reply-To: <20241205163411.1160094-1-pobrn@protonmail.com> References: <20241205163411.1160094-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: b0c478d199faf3ed248621d9e6788bd138a266b3 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use `YamlObject::find()` to implement `YamlObject::{contains,operator[]}()`. This way there is a single source of truth for dictionary lookups. Furthermore, inline `YamlObject::contains()` as it can trivially be expressed as a call to `find()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 6 +++++- src/libcamera/yaml_parser.cpp | 14 ++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 796e3e90..20dab2f3 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -207,7 +207,11 @@ public: const YamlObject &operator[](std::size_t index) const; - bool contains(std::string_view key) const; + bool contains(std::string_view key) const + { + return find(key); + } + const YamlObject &operator[](std::string_view key) const; const YamlObject *find(std::string_view key) const; diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index da8cb61f..72483ef3 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -369,10 +369,6 @@ const YamlObject &YamlObject::operator[](std::size_t index) const * * \return True if an element exists, false otherwise */ -bool YamlObject::contains(std::string_view key) const -{ - return dictionary_.find(key) != dictionary_.end(); -} /** * \fn YamlObject::operator[](std::string_view key) const @@ -387,14 +383,8 @@ bool YamlObject::contains(std::string_view key) const */ const YamlObject &YamlObject::operator[](std::string_view key) const { - if (type_ != Type::Dictionary) - return empty; - - auto iter = dictionary_.find(key); - if (iter == dictionary_.end()) - return empty; - - return *iter->second; + auto *child = find(key); + return child ? *child : empty; } /**