[{"id":34342,"web_url":"https://patchwork.libcamera.org/comment/34342/","msgid":"<174795931752.778642.12291070918330210953@calcite>","date":"2025-05-23T00:15:17","subject":"Re: [PATCH v1] treewide: Do not use `*NameValueMap` for known values","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-05-22 23:29:21)\n> When the value is known, do not look it up via the control's `NameValueMap`,\n> instead, just refer to the value directly.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/ipa/libipa/agc_mean_luminance.cpp         |  5 ++---\n>  src/ipa/rkisp1/algorithms/agc.cpp             |  3 +--\n>  .../pipeline/virtual/config_parser.cpp        | 20 +++++++++++--------\n>  3 files changed, 15 insertions(+), 13 deletions(-)\n> \n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index f617fde81..d37a9b661 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.cpp\n> +++ b/src/ipa/libipa/agc_mean_luminance.cpp\n> @@ -218,8 +218,7 @@ int AgcMeanLuminance::parseConstraintModes(const YamlObject &tuningData)\n>                 constraintModes_[controls::ConstraintNormal].insert(\n>                         constraintModes_[controls::ConstraintNormal].begin(),\n>                         constraint);\n> -               availableConstraintModes.push_back(\n> -                       AeConstraintModeNameValueMap.at(\"ConstraintNormal\"));\n> +               availableConstraintModes.push_back(controls::ConstraintNormal);\n>         }\n>  \n>         controls_[&controls::AeConstraintMode] = ControlInfo(availableConstraintModes);\n> @@ -287,7 +286,7 @@ int AgcMeanLuminance::parseExposureModes(const YamlObject &tuningData)\n>          * possible before touching gain.\n>          */\n>         if (availableExposureModes.empty()) {\n> -               int32_t exposureModeId = AeExposureModeNameValueMap.at(\"ExposureNormal\");\n> +               int32_t exposureModeId = controls::ExposureNormal;\n>                 std::vector<std::pair<utils::Duration, double>> stages = { };\n>  \n>                 std::shared_ptr<ExposureModeHelper> helper =\n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index b3ac9400b..137a07500 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -68,10 +68,9 @@ int Agc::parseMeteringModes(IPAContext &context, const YamlObject &tuningData)\n>         if (meteringModes_.empty()) {\n>                 LOG(RkISP1Agc, Warning)\n>                         << \"No metering modes read from tuning file; defaulting to matrix\";\n> -               int32_t meteringModeId = controls::AeMeteringModeNameValueMap.at(\"MeteringMatrix\");\n>                 std::vector<uint8_t> weights(context.hw->numHistogramWeights, 1);\n>  \n> -               meteringModes_[meteringModeId] = weights;\n> +               meteringModes_[controls::MeteringMatrix] = weights;\n>         }\n>  \n>         std::vector<ControlValue> meteringModes;\n> diff --git a/src/libcamera/pipeline/virtual/config_parser.cpp b/src/libcamera/pipeline/virtual/config_parser.cpp\n> index d9900add6..1d3d9ba87 100644\n> --- a/src/libcamera/pipeline/virtual/config_parser.cpp\n> +++ b/src/libcamera/pipeline/virtual/config_parser.cpp\n> @@ -233,17 +233,21 @@ int ConfigParser::parseFrameGenerator(const YamlObject &cameraConfigData, Virtua\n>  \n>  int ConfigParser::parseLocation(const YamlObject &cameraConfigData, VirtualCameraData *data)\n>  {\n> -       std::string location = cameraConfigData[\"location\"].get<std::string>(\"CameraLocationFront\");\n> -\n>         /* Default value is properties::CameraLocationFront */\n> -       auto it = properties::LocationNameValueMap.find(location);\n> -       if (it == properties::LocationNameValueMap.end()) {\n> -               LOG(Virtual, Error)\n> -                       << \"location: \" << location << \" is not supported\";\n> -               return -EINVAL;\n> +       int32_t location = properties::CameraLocationFront;\n> +\n> +       if (auto l = cameraConfigData[\"location\"].get<std::string>()) {\n> +               auto it = properties::LocationNameValueMap.find(*l);\n> +               if (it == properties::LocationNameValueMap.end()) {\n> +                       LOG(Virtual, Error)\n> +                               << \"location: \" << *l << \" is not supported\";\n> +                       return -EINVAL;\n> +               }\n> +\n> +               location = it->second;\n>         }\n>  \n> -       data->properties_.set(properties::Location, it->second);\n> +       data->properties_.set(properties::Location, location);\n>  \n>         return 0;\n>  }\n> -- \n> 2.49.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 99B79C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 May 2025 00:15:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 92BD868D96;\n\tFri, 23 May 2025 02:15:32 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A16CD61679\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 May 2025 02:15:30 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2001:268:9879:bbe3:bc1e:1c74:c373:b287])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E61C6BE;\n\tFri, 23 May 2025 02:15:06 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vo/Ro8bm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1747959308;\n\tbh=64sbaaMFyhlPwJD979ZmYJDpan8NRs5ye8uscbCzsEw=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=vo/Ro8bmMB1GKNq3pVFQGoNzwddKY+6bSGxxjP8lBQQZL/1a+xg49daYF15gDG8JG\n\t4cqTInIFBbxOKCoEM6l3T/fWrpbKze1lhRAMfpCJjfnbB17c57rgH0s9n4zgvwX4TU\n\tyDxG7VjgppHuARbsDdsTRD80zBoVmeOW0d9Jo+8E=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250522142921.1378425-1-barnabas.pocze@ideasonboard.com>","References":"<20250522142921.1378425-1-barnabas.pocze@ideasonboard.com>","Subject":"Re: [PATCH v1] treewide: Do not use `*NameValueMap` for known values","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 23 May 2025 09:15:17 +0900","Message-ID":"<174795931752.778642.12291070918330210953@calcite>","User-Agent":"alot/0.10","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>"}},{"id":34353,"web_url":"https://patchwork.libcamera.org/comment/34353/","msgid":"<20250526154009.GT17743@pendragon.ideasonboard.com>","date":"2025-05-26T15:40:09","subject":"Re: [PATCH v1] treewide: Do not use `*NameValueMap` for known values","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Thu, May 22, 2025 at 04:29:21PM +0200, Barnabás Pőcze wrote:\n> When the value is known, do not look it up via the control's `NameValueMap`,\n> instead, just refer to the value directly.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> ---\n>  src/ipa/libipa/agc_mean_luminance.cpp         |  5 ++---\n>  src/ipa/rkisp1/algorithms/agc.cpp             |  3 +--\n>  .../pipeline/virtual/config_parser.cpp        | 20 +++++++++++--------\n>  3 files changed, 15 insertions(+), 13 deletions(-)\n> \n> diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\n> index f617fde81..d37a9b661 100644\n> --- a/src/ipa/libipa/agc_mean_luminance.cpp\n> +++ b/src/ipa/libipa/agc_mean_luminance.cpp\n> @@ -218,8 +218,7 @@ int AgcMeanLuminance::parseConstraintModes(const YamlObject &tuningData)\n>  \t\tconstraintModes_[controls::ConstraintNormal].insert(\n>  \t\t\tconstraintModes_[controls::ConstraintNormal].begin(),\n>  \t\t\tconstraint);\n> -\t\tavailableConstraintModes.push_back(\n> -\t\t\tAeConstraintModeNameValueMap.at(\"ConstraintNormal\"));\n> +\t\tavailableConstraintModes.push_back(controls::ConstraintNormal);\n\nI'm tempted to use controls::AeConstraintModeEnum::ConstraintNormal (and\nsimilarly below) already, but I suppose this should be a separate\ntree-wide change.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \t}\n>  \n>  \tcontrols_[&controls::AeConstraintMode] = ControlInfo(availableConstraintModes);\n> @@ -287,7 +286,7 @@ int AgcMeanLuminance::parseExposureModes(const YamlObject &tuningData)\n>  \t * possible before touching gain.\n>  \t */\n>  \tif (availableExposureModes.empty()) {\n> -\t\tint32_t exposureModeId = AeExposureModeNameValueMap.at(\"ExposureNormal\");\n> +\t\tint32_t exposureModeId = controls::ExposureNormal;\n>  \t\tstd::vector<std::pair<utils::Duration, double>> stages = { };\n>  \n>  \t\tstd::shared_ptr<ExposureModeHelper> helper =\n> diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\n> index b3ac9400b..137a07500 100644\n> --- a/src/ipa/rkisp1/algorithms/agc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/agc.cpp\n> @@ -68,10 +68,9 @@ int Agc::parseMeteringModes(IPAContext &context, const YamlObject &tuningData)\n>  \tif (meteringModes_.empty()) {\n>  \t\tLOG(RkISP1Agc, Warning)\n>  \t\t\t<< \"No metering modes read from tuning file; defaulting to matrix\";\n> -\t\tint32_t meteringModeId = controls::AeMeteringModeNameValueMap.at(\"MeteringMatrix\");\n>  \t\tstd::vector<uint8_t> weights(context.hw->numHistogramWeights, 1);\n>  \n> -\t\tmeteringModes_[meteringModeId] = weights;\n> +\t\tmeteringModes_[controls::MeteringMatrix] = weights;\n>  \t}\n>  \n>  \tstd::vector<ControlValue> meteringModes;\n> diff --git a/src/libcamera/pipeline/virtual/config_parser.cpp b/src/libcamera/pipeline/virtual/config_parser.cpp\n> index d9900add6..1d3d9ba87 100644\n> --- a/src/libcamera/pipeline/virtual/config_parser.cpp\n> +++ b/src/libcamera/pipeline/virtual/config_parser.cpp\n> @@ -233,17 +233,21 @@ int ConfigParser::parseFrameGenerator(const YamlObject &cameraConfigData, Virtua\n>  \n>  int ConfigParser::parseLocation(const YamlObject &cameraConfigData, VirtualCameraData *data)\n>  {\n> -\tstd::string location = cameraConfigData[\"location\"].get<std::string>(\"CameraLocationFront\");\n> -\n>  \t/* Default value is properties::CameraLocationFront */\n> -\tauto it = properties::LocationNameValueMap.find(location);\n> -\tif (it == properties::LocationNameValueMap.end()) {\n> -\t\tLOG(Virtual, Error)\n> -\t\t\t<< \"location: \" << location << \" is not supported\";\n> -\t\treturn -EINVAL;\n> +\tint32_t location = properties::CameraLocationFront;\n> +\n> +\tif (auto l = cameraConfigData[\"location\"].get<std::string>()) {\n> +\t\tauto it = properties::LocationNameValueMap.find(*l);\n> +\t\tif (it == properties::LocationNameValueMap.end()) {\n> +\t\t\tLOG(Virtual, Error)\n> +\t\t\t\t<< \"location: \" << *l << \" is not supported\";\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\n> +\t\tlocation = it->second;\n>  \t}\n>  \n> -\tdata->properties_.set(properties::Location, it->second);\n> +\tdata->properties_.set(properties::Location, location);\n>  \n>  \treturn 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 34F73C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 May 2025 15:40:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E44968D9D;\n\tMon, 26 May 2025 17:40:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C2703627DA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 May 2025 17:40:15 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(237.69-130-109.adsl-dyn.isp.belgacom.be [109.130.69.237])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8DFBB7E6;\n\tMon, 26 May 2025 17:39:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rOhV1x3B\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1748273990;\n\tbh=IqJN/rFdmrjGotrdiTt3lEiRJ1H7Gjfvx2GLJjatZC8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=rOhV1x3BxIoMWRPJjPq3C3aSz1amOHaNYgiiR7l8FZmpRKaRRCNiiBhoSb1Ip0M3L\n\tfRMat+FN87iev0fD35qGSNublEVHDcSMRTRpy6Yk1Yrva8/Har4hGktpbUKXZq3Yuv\n\td9nd+u+jPL1HQ6TWxg+OCUiAHKaOS0K70v7Ivlhw=","Date":"Mon, 26 May 2025 17:40:09 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] treewide: Do not use `*NameValueMap` for known values","Message-ID":"<20250526154009.GT17743@pendragon.ideasonboard.com>","References":"<20250522142921.1378425-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20250522142921.1378425-1-barnabas.pocze@ideasonboard.com>","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>"}}]