From c1597f989654618f782012104f547b367082fa3e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 18 Jul 2022 09:15:58 +0100 Subject: ipa: raspberrypi: Use YamlParser to replace dependency on boost The Raspberry Pi IPA module depends on boost only to parse the JSON tuning data files. As libcamera depends on libyaml, use the YamlParser class to parse those files and drop the dependency on boost. Signed-off-by: Laurent Pinchart Tested-by: Naushir Patuck Reviewed-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 134 ++++++++++++++++++----------- 1 file changed, 82 insertions(+), 52 deletions(-) (limited to 'src/ipa/raspberrypi/controller/rpi/awb.cpp') diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index d8c96654..a16e04a0 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -5,6 +5,8 @@ * awb.cpp - AWB control algorithm */ +#include + #include #include "../lux_status.h" @@ -26,62 +28,87 @@ static constexpr unsigned int AwbStatsSizeY = DEFAULT_AWB_REGIONS_Y; * elsewhere (ALSC and AGC). */ -int AwbMode::read(boost::property_tree::ptree const ¶ms) +int AwbMode::read(const libcamera::YamlObject ¶ms) { - ctLo = params.get("lo"); - ctHi = params.get("hi"); + auto value = params["lo"].get(); + if (!value) + return -EINVAL; + ctLo = *value; + + value = params["hi"].get(); + if (!value) + return -EINVAL; + ctHi = *value; + return 0; } -int AwbPrior::read(boost::property_tree::ptree const ¶ms) +int AwbPrior::read(const libcamera::YamlObject ¶ms) { - lux = params.get("lux"); - return prior.read(params.get_child("prior")); + auto value = params["lux"].get(); + if (!value) + return -EINVAL; + lux = *value; + + return prior.read(params["prior"]); } -static int readCtCurve(Pwl &ctR, Pwl &ctB, - boost::property_tree::ptree const ¶ms) +static int readCtCurve(Pwl &ctR, Pwl &ctB, const libcamera::YamlObject ¶ms) { - int num = 0; - for (auto it = params.begin(); it != params.end(); it++) { - double ct = it->second.get_value(); - assert(it == params.begin() || ct != ctR.domain().end); - if (++it == params.end()) { - LOG(RPiAwb, Error) << "AwbConfig: incomplete CT curve entry"; - return -EINVAL; - } - ctR.append(ct, it->second.get_value()); - if (++it == params.end()) { - LOG(RPiAwb, Error) << "AwbConfig: incomplete CT curve entry"; - return -EINVAL; - } - ctB.append(ct, it->second.get_value()); - num++; + if (params.size() % 3) { + LOG(RPiAwb, Error) << "AwbConfig: incomplete CT curve entry"; + return -EINVAL; } - if (num < 2) { + + if (params.size() < 6) { LOG(RPiAwb, Error) << "AwbConfig: insufficient points in CT curve"; return -EINVAL; } + + const auto &list = params.asList(); + + for (auto it = list.begin(); it != list.end(); it++) { + auto value = it->get(); + if (!value) + return -EINVAL; + double ct = *value; + + assert(it == list.begin() || ct != ctR.domain().end); + + value = (++it)->get(); + if (!value) + return -EINVAL; + ctR.append(ct, *value); + + value = (++it)->get(); + if (!value) + return -EINVAL; + ctB.append(ct, *value); + } + return 0; } -int AwbConfig::read(boost::property_tree::ptree const ¶ms) +int AwbConfig::read(const libcamera::YamlObject ¶ms) { int ret; - bayes = params.get("bayes", 1); - framePeriod = params.get("framePeriod", 10); - startupFrames = params.get("startupFrames", 10); - convergenceFrames = params.get("convergence_frames", 3); - speed = params.get("speed", 0.05); - if (params.get_child_optional("ct_curve")) { - ret = readCtCurve(ctR, ctB, params.get_child("ct_curve")); + + bayes = params["bayes"].get(1); + framePeriod = params["frame_period"].get(10); + startupFrames = params["startup_frames"].get(10); + 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 (ret) return ret; } - if (params.get_child_optional("priors")) { - for (auto &p : params.get_child("priors")) { + + if (params.contains("priors")) { + for (const auto &p : params["priors"].asList()) { AwbPrior prior; - ret = prior.read(p.second); + ret = prior.read(p); if (ret) return ret; if (!priors.empty() && prior.lux <= priors.back().lux) { @@ -95,32 +122,35 @@ int AwbConfig::read(boost::property_tree::ptree const ¶ms) return ret; } } - if (params.get_child_optional("modes")) { - for (auto &p : params.get_child("modes")) { - ret = modes[p.first].read(p.second); + if (params.contains("modes")) { + for (const auto &[key, value] : params["modes"].asDict()) { + ret = modes[key].read(value); if (ret) return ret; if (defaultMode == nullptr) - defaultMode = &modes[p.first]; + defaultMode = &modes[key]; } if (defaultMode == nullptr) { LOG(RPiAwb, Error) << "AwbConfig: no AWB modes configured"; return -EINVAL; } } - minPixels = params.get("min_pixels", 16.0); - minG = params.get("min_G", 32); - minRegions = params.get("min_regions", 10); - deltaLimit = params.get("delta_limit", 0.2); - coarseStep = params.get("coarse_step", 0.2); - transversePos = params.get("transverse_pos", 0.01); - transverseNeg = params.get("transverse_neg", 0.01); + + minPixels = params["min_pixels"].get(16.0); + minG = params["min_G"].get(32); + minRegions = params["min_regions"].get(10); + deltaLimit = params["delta_limit"].get(0.2); + coarseStep = params["coarse_step"].get(0.2); + transversePos = params["transverse_pos"].get(0.01); + transverseNeg = params["transverse_neg"].get(0.01); if (transversePos <= 0 || transverseNeg <= 0) { LOG(RPiAwb, Error) << "AwbConfig: transverse_pos/neg must be > 0"; return -EINVAL; } - sensitivityR = params.get("sensitivity_r", 1.0); - sensitivityB = params.get("sensitivity_b", 1.0); + + sensitivityR = params["sensitivity_r"].get(1.0); + sensitivityB = params["sensitivity_b"].get(1.0); + if (bayes) { if (ctR.empty() || ctB.empty() || priors.empty() || defaultMode == nullptr) { @@ -129,9 +159,9 @@ int AwbConfig::read(boost::property_tree::ptree const ¶ms) bayes = false; } } - fast = params.get("fast", bayes); /* default to fast for Bayesian, otherwise slow */ - whitepointR = params.get("whitepoint_r", 0.0); - whitepointB = params.get("whitepoint_b", 0.0); + fast = params[fast].get(bayes); /* default to fast for Bayesian, otherwise slow */ + whitepointR = params["whitepoint_r"].get(0.0); + whitepointB = params["whitepoint_b"].get(0.0); if (bayes == false) sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */ return 0; @@ -162,7 +192,7 @@ char const *Awb::name() const return NAME; } -int Awb::read(boost::property_tree::ptree const ¶ms) +int Awb::read(const libcamera::YamlObject ¶ms) { return config_.read(params); } -- cgit v1.2.1