From f357b1bf6ea39d8118e90f8a371974d29bd054e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jul 2022 02:36:38 +0300 Subject: ipa: raspberrypi: Return an error code from Algorithm::read() When encountering errors, the Algorithm::read() function either uses LOG(Fatal) or throws exceptions from the boost property_tree functions. To prepare for replacing boost JSON parse with the YamlParser class, give the Algorithm::read() function the ability to return an error code, and propagate it all the way to the IPA module init() function. All algorithm classes return a hardcoded 0 value for now, subsequent commits will change that. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 35 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 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 6c2b627d..cd97d9f4 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -26,20 +26,21 @@ static constexpr unsigned int AwbStatsSizeY = DEFAULT_AWB_REGIONS_Y; * elsewhere (ALSC and AGC). */ -void AwbMode::read(boost::property_tree::ptree const ¶ms) +int AwbMode::read(boost::property_tree::ptree const ¶ms) { ctLo = params.get("lo"); ctHi = params.get("hi"); + return 0; } -void AwbPrior::read(boost::property_tree::ptree const ¶ms) +int AwbPrior::read(boost::property_tree::ptree const ¶ms) { lux = params.get("lux"); - prior.read(params.get_child("prior")); + return prior.read(params.get_child("prior")); } -static void readCtCurve(Pwl &ctR, Pwl &ctB, - boost::property_tree::ptree const ¶ms) +static int readCtCurve(Pwl &ctR, Pwl &ctB, + boost::property_tree::ptree const ¶ms) { int num = 0; for (auto it = params.begin(); it != params.end(); it++) { @@ -55,21 +56,28 @@ static void readCtCurve(Pwl &ctR, Pwl &ctB, } if (num < 2) LOG(RPiAwb, Fatal) << "AwbConfig: insufficient points in CT curve"; + return 0; } -void AwbConfig::read(boost::property_tree::ptree const ¶ms) +int AwbConfig::read(boost::property_tree::ptree const ¶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")) - readCtCurve(ctR, ctB, params.get_child("ct_curve")); + if (params.get_child_optional("ct_curve")) { + ret = readCtCurve(ctR, ctB, params.get_child("ct_curve")); + if (ret) + return ret; + } if (params.get_child_optional("priors")) { for (auto &p : params.get_child("priors")) { AwbPrior prior; - prior.read(p.second); + ret = prior.read(p.second); + if (ret) + return ret; if (!priors.empty() && prior.lux <= priors.back().lux) LOG(RPiAwb, Fatal) << "AwbConfig: Prior must be ordered in increasing lux value"; priors.push_back(prior); @@ -79,7 +87,9 @@ void AwbConfig::read(boost::property_tree::ptree const ¶ms) } if (params.get_child_optional("modes")) { for (auto &p : params.get_child("modes")) { - modes[p.first].read(p.second); + ret = modes[p.first].read(p.second); + if (ret) + return ret; if (defaultMode == nullptr) defaultMode = &modes[p.first]; } @@ -110,6 +120,7 @@ void AwbConfig::read(boost::property_tree::ptree const ¶ms) whitepointB = params.get("whitepoint_b", 0.0); if (bayes == false) sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */ + return 0; } Awb::Awb(Controller *controller) @@ -137,9 +148,9 @@ char const *Awb::name() const return NAME; } -void Awb::read(boost::property_tree::ptree const ¶ms) +int Awb::read(boost::property_tree::ptree const ¶ms) { - config_.read(params); + return config_.read(params); } void Awb::initialise() -- cgit v1.2.1